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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attack the target attack receiever and then call the relevant transition.
        /// </summary>
        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)
            {
                int targetSize = TraitsUtil.GetSize(agent.TargetMapElement);
                if (targetSize > 1)
                {
                    CallTargetKilledTransition();
                }
                else
                {
                    float hunger   = 1.0f;
                    bool  isEating = Random.value <= hunger;
                    if (isEating)
                    {
                        agent.Description = "Ate " + agent.TargetMapElement.DisplayName;
                        agent.TargetMapElement.Description = "Eaten by " + agent.DisplayName;
                        CallTargetEatenTransition();
                    }
                    else
                    {
                        CallTargetKilledTransition();
                    }
                }
            }
            else
            {
                attackReceiver.ReceiveAttack(agent);
            }
        }