Esempio n. 1
0
        void Attack(Transform target)
        {
            IAttackable targetBody = target.GetComponent <IAttackable>();

            if (targetBody == null)
            {
                throw new ArgumentException("Target cannot be attacked.");
            }
            Attack       attack        = BuildAttack();
            Defense      targetDefense = targetBody.GetDefense();
            AttackResult result        = AttackResolver.ResolvePhysicalAttack(attack, targetDefense);

            targetBody.Attack(result);
        }
 void TryMoveTo(Coord coord)
 {
     if (Map.IsWalkable(coord))
     {
         Collider2D collision = CustomRaycast.GetMapEntityColliderAt(coord);
         if (collision != null) // something is in the way
         {
             IAttackable target = collision.GetComponent <IAttackable>();
             if (target != null) // that something can be attacked
             {
                 Defense      defense = target.GetDefense();
                 Attack       attack  = attacker.BuildAttack();
                 AttackResult result  = attackResolver.ResolvePhysicalAttack(attack, defense);
                 target.Attack(result);
                 time.IncreaseBasedOnSpeed(AttackSpeed);
             }
         }
         else
         {
             transform.position = (Vector2)coord;
             time.IncreaseBasedOnSpeed(MoveSpeed);
         }
     }
 }