Esempio n. 1
0
    void TradeBlows(Weapon otherW)
    {
        // Both are attacking, so trade blows
        Entity entity = GetEntity();
        Entity enemy  = otherW.GetEntity();

        if (otherW.CanDamage(entity))
        {
            otherW.DealDamage(entity);
            otherW.AddToDamaged(entity);
        }
        if (CanDamage(enemy))
        {
            DealDamage(enemy);
            AddToDamaged(enemy);
        }
    }
Esempio n. 2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        // If weapon isn't being used by an entity, it shouldn't do anything
        if (owner == null)
        {
            return;
        }

        // If interactive tile
        if (((1 << other.gameObject.layer) & LayerMask.GetMask(new string[] { "InteractiveBlock", "InteractivePass" })) > 0)
        {
            Tile tile = other.GetComponentInParent <Tile> ();
            if (tile != null && tile.CanUseItem(this))
            {
                GetEntity().TriggerItemUse(tile);
            }
        }

        // If collided with opponent's hitbox (weapon)
        if (other.gameObject.tag.Equals("Hitbox"))
        {
            Weapon otherW = other.GetComponent <Weapon> ();
            if (IsAttacking() && !otherW.IsAttacking())
            {
                Entity entity = GetEntity();
                if (otherW.CanDamage(entity))
                {
                    otherW.DealDamage(entity);                     //entity.Damage (otherW.DamageToInflict ());
                    otherW.AddToDamaged(entity);
                    //print ("Damaging: " + entity.name);
                }
            }
            else if (!IsAttacking() && otherW.IsAttacking())
            {
                Entity enemy = otherW.GetEntity();
                if (!targetsHit.Contains(enemy))
                {
                    DealDamage(enemy);                     //enemy.Damage (DamageToInflict ());
                    targetsHit.Add(enemy);
                    //print ("Damaging: " + enemy.name);
                }
            }
            else if (!otherW.IsBlocking())
            {
                TradeBlows(otherW);
            }
        }
        else if (other.gameObject.tag.Equals("Character"))
        {
            // If collided with opponent
            if (IsAttacking())
            {
                Entity enemy = other.GetComponentInParent <Entity>();
                // Don't hurt ourselves
                if (enemy.Equals(GetEntity()))
                {
                    return;
                }
                if (!CanDamage(enemy))
                {
                    return;
                }
                if (!enemy.InAttack() || enemy.IsIdleAttack())
                {
                    // Enemy but they are in lingering attack state, so still hit them
                    DealDamage(enemy);
                    AddToDamaged(enemy);
                }
            }
        }
    }