Esempio n. 1
0
        void HandleAttack(IAgent attackingAgent)
        {
            attackingAgent.Description = "(HP: " + TraitsUtil.GetHealth(attackingAgent) + ") Attacking " + agent.DisplayName;

            agent.TargetMapElement = attackingAgent;

            int health = TraitsUtil.GetHealth(agent);

            int attackStrength  = TraitsUtil.GetRandomAttackStrength(attackingAgent);
            int defenseStrength = TraitsUtil.GetRandomDefenseStrength(agent);

            int healthDecrement = attackStrength - defenseStrength;

            if (healthDecrement > 0)
            {
                health -= healthDecrement;
                TraitsUtil.SetHealth(agent, health);
            }


            if (health <= 0)
            {
                agent.Description = "Killed by " + attackingAgent.DisplayName;
                agent.HandleTransition(onDeathTransition);
            }
            else
            {
                agent.Description = "(HP: " + health + ") Attacked by " + attackingAgent.DisplayName;// + "\nattackStrength = "+attackStrength+", defenseStrength = "+defenseStrength+", remaining health = " + health;
                agent.HandleTransition(onAttackedTransition);
            }

            //Debug.Log("HandleAttack health = " + health+", "+ agent.Description);
        }
        void AttackTarget()
        {
            if (agent.TargetMapElement == null)
            {
                CallTargetKilledTransition();
                return;
            }

            IAttackReceiver attackReceiver = agent.TargetMapElement as IAttackReceiver;

            if (attackReceiver == null)
            {
                CallTargetKilledTransition();
                return;
            }

            int targetHealth = TraitsUtil.GetHealth(agent.TargetMapElement);

            if (targetHealth <= 0)
            {
                CallTargetKilledTransition();
            }
            else
            {
                attackReceiver.ReceiveAttack(agent);
            }
        }