Esempio n. 1
0
	protected void HealOnHit(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
	{
		Enemy e = target as Enemy;
		if (e == null) return;
		
		e.Heal(amt);
	}
Esempio n. 2
0
	protected virtual void AddToQueue(HittableObject h)
	{
		Enemy e = h as Enemy;
		if (e == null || to_repair.Contains(e)) return;
		
		to_repair.Enqueue(e);
	}
Esempio n. 3
0
    protected virtual void PassOnHit(HittableObject h, Bullet b)
    {
        Enemy target = null;

        foreach (Enemy e in turrets)
        {
            if (e == this)
            {
                continue;
            }
            if (e == null)
            {
                continue;
            }
            if (target == null || Vector3.Distance(target.transform.position, b.transform.position) >
                Vector3.Distance(e.transform.position, b.transform.position))
            {
                target = e;
            }
        }

        if (target == null)
        {
            DestroyInstant();
        }
        else
        {
            target.Damage(b);
        }
    }
Esempio n. 4
0
    protected virtual void Buckshot
        (HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
    {
        if (depth <= 0)
        {
            return;
        }

        for (int i = 0; i < (num_shots == 0 ? depth + 1 : num_shots); i++)
        {
            GameObject gobj = (GameObject)Instantiate(gameObject);
            gobj.transform.position = transform.position;
            gobj.transform.rotation = transform.rotation;
            gobj.transform.Rotate(Vector3.up,
                                  Random.Range(-max_degrees_delta, max_degrees_delta));
            BuckshotBullet bsb = gobj.GetComponent <BuckshotBullet>();
            bsb.exception = new Stack <Transform>();
            if (exception != null)
            {
                foreach (Transform t in exception)
                {
                    bsb.exception.Push(t);
                }
            }
            bsb.exception.Push(target.transform);
            bsb.depth = depth - 1;
        }
    }
Esempio n. 5
0
    protected virtual void GotHit(HittableObject hit)
    {
        repair_charge = 0f;

        health--;

        if (health <= 0)
        {
            DestroyInstant();
        }
        else if (max_health > 1)
        {
            // Lose armor
            float percent = 1f - (float)(health - 1) / (float)(max_health - 1);

            for (int i = 0; i < Mathf.RoundToInt(armor.Length * percent); i++)
            {
                if (armor[i].activeSelf)
                {
                    if (armor_explosion != null)
                    {
                        GameObject arexp = (GameObject)Instantiate(armor_explosion);
                        arexp.transform.position = armor[i].transform.position;
                        arexp.GetComponent <ExplosionController>().Init();
                    }

                    armor[i].SetActive(false);
                }
            }
        }
    }
Esempio n. 6
0
	protected static void DestroyOnHit(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
	{
		pierce = false;
		
		bullet.transform.position += Vector3.Project(rch.point - bullet.transform.position, bullet.transform.forward);
		
		bullet.Explode();
	}
Esempio n. 7
0
    protected static void DestroyOnHit(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
    {
        pierce = false;

        bullet.transform.position += Vector3.Project(rch.point - bullet.transform.position, bullet.transform.forward);

        bullet.Explode();
    }
Esempio n. 8
0
	public virtual void Damage(HittableObject h)
	{
		if (!Utilities.IsThisVisible(gameObject))
			return;
		
		if (dmgEnemy != null)
			dmgEnemy(this, h);
		if (dmgGeneric != null)
			dmgGeneric(this);
	}
Esempio n. 9
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "HittableObject")
        {
            HittableObject hittableObject = other.GetComponent <HittableObject>();

            controller.moveableObject.moveDirection.x = -knockback;
            hittableObject.GetHit(this.GetSwordDamage(), this.knockback);
        }
    }
Esempio n. 10
0
    protected virtual void AddToQueue(HittableObject h)
    {
        Enemy e = h as Enemy;

        if (e == null || to_repair.Contains(e))
        {
            return;
        }

        to_repair.Enqueue(e);
    }
Esempio n. 11
0
    protected void HealOnHit(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
    {
        Enemy e = target as Enemy;

        if (e == null)
        {
            return;
        }

        e.Heal(amt);
    }
Esempio n. 12
0
	public void TakeDamage(HittableObject h)
	{
		if (Fight.f == null || !Fight.f.fight_active)
			return;

		shield--;
		num_hits_taken++;
		
		if (shield < 0)
			StartCoroutine(Lose());
	}
Esempio n. 13
0
	protected virtual void DmgNoData(HittableObject h)
	{
		int r = Random.Range(0, turrets.Length);
		while (turrets[r] == this || turrets[r] == null)
		{
			r++;
			if (r == turrets.Length)
				r = 0;
		}
		
		turrets[r].Damage();
	}
Esempio n. 14
0
	protected virtual void PassOnHit(HittableObject h, HittableObject b)
	{
		Enemy target = null;
		foreach (Enemy e in turrets)
		{
			if (e == this) continue;
			if (e == null) continue;
			if (target == null || Vector3.Distance(target.transform.position, b.transform.position) >
				Vector3.Distance(e.transform.position, b.transform.position))
				target = e;
		}
		
		target.Damage(b);
	}
Esempio n. 15
0
    // Update is called once per frame
    protected override void _Update()
    {
        if (alive > 0)
        {
            // Cast for a hit and there is a hit,
            //	call our hit method and then theirs
            RaycastHit[] rch = CastForHits(transform.position + transform.forward * speed * Time.deltaTime);
            for (int i = 0; i < rch.Length; i++)
            {
                Transform      c = rch[i].transform;
                HittableObject h = c.GetComponent <HittableObject>();
                while (h == null)
                {
                    c = c.parent;
                    h = c.GetComponent <HittableObject>();
                }

                bool cont = true;
                if (Hit != null)
                {
                    Hit(h, this, rch[i], ref cont);
                }
                if (!cont)
                {
                    break;
                }
            }

            transform.position += transform.forward * speed * Time.deltaTime;
        }
        else
        {
            alive -= Time.deltaTime;
            if (alive < -length)
            {
                Destroy(gameObject);
            }
        }

        if (kill_when_invis)
        {
            // Check for offscreen
            if (!(new Rect(-200f, -200f, 400f, 300f)).Contains(
                    new Vector2(transform.position.x, transform.position.z)))
            {
                Destroy(gameObject);
            }
        }
    }
Esempio n. 16
0
    public void TakeDamage(HittableObject h)
    {
        if (Fight.f == null || !Fight.f.fight_active)
        {
            return;
        }

        shield--;
        num_hits_taken++;

        if (shield < 0)
        {
            StartCoroutine(Lose());
        }
    }
Esempio n. 17
0
    protected virtual void DmgNoData(HittableObject h)
    {
        int r = Random.Range(0, turrets.Length);

        while (turrets[r] == this || turrets[r] == null)
        {
            r++;
            if (r == turrets.Length)
            {
                r = 0;
            }
        }

        turrets[r].Damage();
    }
Esempio n. 18
0
    public virtual void Damage(HittableObject h)
    {
        if (!Utilities.IsThisVisible(gameObject))
        {
            return;
        }

        if (dmgEnemy != null)
        {
            dmgEnemy(this, h);
        }
        if (dmgGeneric != null)
        {
            dmgGeneric(this);
        }
    }
Esempio n. 19
0
        // Fired From Player Animation Event
        public void OnAttack()
        {
            if (weapon == null)
            {
                return;
            }

            if (weapon.itemType == Item.ItemTypes.MeleeWeapon)
            {
                // show a temp melee weapon spot
                if (tempWeapon != null)
                {
                    var ang = Vector2.Angle(player.mouseDirection, weaponArcPoint.transform.position);
                    Debug.Log(ang);
                    tempWeapon.SetActive(true);
                    tempWeapon.transform.position = (Vector2)weaponArcPoint.transform.position + player.mouseDirection;
                    //tempWeapon.transform.LookAt(player.mouseDirection);
                }

                var meleeWeapon = (ItemWeaponMelee)weapon;

                Combat.IHittable HittableObject;
                var rays = Physics2D.CircleCastAll((Vector2)weaponArcPoint.transform.position + player.mouseDirection, meleeWeapon.attackArc, player.mouseDirection, .01f, hittableLayers);
                if (rays != null)
                {
                    for (var i = 0; i < rays.Length; i++)
                    {
                        //Debug.Log("hit " + rays[i].collider.name);
                        HittableObject = (Combat.IHittable)rays[i].collider.gameObject.GetComponent(typeof(Combat.IHittable));

                        if (HittableObject != null && weapon != null)
                        {
                            Combat.DamageInfo damageInfo = meleeWeapon.damage.Copy();
                            // add damage bonuses from player stats here
                            HittableObject.Hit(new Combat.HitInfo(damageInfo, rays[i].collider.transform.position, false, Combat.HitInfo.HitSources.Player));
                        }
                    }
                }
            }
            else if (weapon.itemType == Item.ItemTypes.RangedWeapon)
            {
                var rangedWeapon = (ItemWeaponRanged)weapon;
                Instantiate(rangedWeapon.projectile, (Vector2)weaponHand.transform.position, Quaternion.identity);
            }
        }
Esempio n. 20
0
	protected void PierceAndDestroy(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
	{
		if (!hit_already.Contains(target))
		{
			Explode ();
			alive = 1;

			Enemy e = target as Enemy;
			if (e != null && e.Health <= 1)
			{
				destroyed++;
				if (destroyed >= 5)
					Utilities.u.UnlockAchievement("Railgun");
			}

			DamageOnHit(target, bullet, rch, ref pierce);
			hit_already.Push (target);
		}
	}
Esempio n. 21
0
    bool WireHitSomething()
    {
        Vector3 direction = WireTarget.transform.position - transform.position;

        RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, direction, direction.magnitude, layerMask);
        if (hits.Length > 0)
        {
            foreach (var hit in hits)
            {
                HittableObject obj = hit.collider.gameObject.GetComponent <HittableObject>();
                if (obj != null && obj.IsHitted(this, hit))
                {
                    //anim.SetTrigger("hit");
                    return(true);
                }
            }
        }

        return(false);
    }
Esempio n. 22
0
    protected void PierceAndDestroy(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
    {
        if (!hit_already.Contains(target))
        {
            Explode();
            alive = 1;

            Enemy e = target as Enemy;
            if (e != null && e.Health <= 1)
            {
                destroyed++;
                if (destroyed >= 5)
                {
                    Utilities.u.UnlockAchievement("Railgun");
                }
            }

            DamageOnHit(target, bullet, rch, ref pierce);
            hit_already.Push(target);
        }
    }
Esempio n. 23
0
        bool OnHittableObjectCollision(HittableObject _object)
        {
            bool stick = false;

            //destroy or stick the arrow
            switch (_object.ArrowEffect)
            {
            case ArrowEffect.StickArrow:
                stick = true;
                break;

            case ArrowEffect.DestroyArrow:
                Destroy(gameObject);
                break;
            }

            //call the hit function
            _object.OnArrowHit();

            return(stick);
        }
Esempio n. 24
0
	protected virtual void Buckshot 
		(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
	{
		if (depth <= 0)
			return;
		
		for (int i = 0; i < (num_shots == 0 ? depth + 1 : num_shots); i++)
		{
			GameObject gobj = (GameObject)Instantiate(gameObject);
			gobj.transform.position = transform.position;
			gobj.transform.rotation = transform.rotation;
			gobj.transform.Rotate(Vector3.up, 
				Random.Range (-max_degrees_delta, max_degrees_delta));
			BuckshotBullet bsb = gobj.GetComponent<BuckshotBullet>();
			bsb.exception = new Stack<Transform>();
			if (exception != null)
				foreach (Transform t in exception)
					bsb.exception.Push(t);
			bsb.exception.Push(target.transform);
			bsb.depth = depth - 1;
		}
	}
Esempio n. 25
0
	protected static void DamageOnHit(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
	{
		target.Damage(bullet);
	}
Esempio n. 26
0
	void DamageND(HittableObject hit)
	{
		Damage(transform.forward);
	}
Esempio n. 27
0
	protected virtual void LoseSpeedOnHit(HittableObject e)
	{
		speed *= speed_loss_mult;
	}
Esempio n. 28
0
 public Velocity DoHit(Velocity vel)
 {
     return(HittableObject.DoHit(vel, this));
 }
Esempio n. 29
0
	void DamageB(HittableObject hit, Bullet b)
	{
		Damage(b.transform.position - transform.position);
	}
Esempio n. 30
0
    protected void ChargeOnHit(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
    {
        CombinerEnemy c = target as CombinerEnemy;

        c.charges++;
    }
Esempio n. 31
0
 protected virtual void LoseSpeedOnHit(HittableObject e)
 {
     speed *= speed_loss_mult;
 }
Esempio n. 32
0
 void DamageND(HittableObject hit)
 {
     Damage(transform.forward);
 }
Esempio n. 33
0
 void DamageB(HittableObject hit, Bullet b)
 {
     Damage(b.transform.position - transform.position);
 }
Esempio n. 34
0
	void DamageE(HittableObject hit, HittableObject enemy)
	{
		Damage(enemy.transform.position - transform.position);
	}
Esempio n. 35
0
	protected virtual void GotHit(HittableObject hit)
	{
		repair_charge = 0f;
		
		health--;
		
		if (health <= 0)
		{
			DestroyInstant();
		}
		else if (max_health > 1)
		{
			// Lose armor
			float percent = 1f - (float)(health - 1) / (float)(max_health - 1);

			for (int i = 0; i < Mathf.RoundToInt(armor.Length * percent); i++)
			{
				if (armor[i].activeSelf)
				{
					if (armor_explosion != null)
					{
						GameObject arexp = (GameObject)Instantiate(armor_explosion);
						arexp.transform.position = armor[i].transform.position;
						arexp.GetComponent<ExplosionController>().Init();
					}
					
					armor[i].SetActive(false);
				}
			}
		}
	}
Esempio n. 36
0
	protected virtual void ChargedDamageOnHit(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
	{
		for (int i = 0; i < charged; i++)
			target.Damage(bullet);
	}
Esempio n. 37
0
 protected static void DamageOnHit(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
 {
     target.Damage(bullet);
 }
Esempio n. 38
0
	protected void ChargeOnHit(HittableObject target, Bullet bullet, RaycastHit rch, ref bool pierce)
	{
		CombinerEnemy c = target as CombinerEnemy;
		c.charges++;
	}
Esempio n. 39
0
 void DamageE(HittableObject hit, HittableObject enemy)
 {
     Damage(enemy.transform.position - transform.position);
 }
Esempio n. 40
0
	protected virtual void Collided(HittableObject away, HittableObject home)
	{
		away.Damage(this);
		Damage(away);
	}
Esempio n. 41
0
 protected virtual void Collided(HittableObject away, HittableObject home)
 {
     away.Damage(this);
     Damage(away);
 }