コード例 #1
0
        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);
            }
        }
コード例 #2
0
 public static ICommand Create(IAgent agent, IAttackReceiver attackReceiver, string onAttackedTransition = "", string onDeathTransition = "")
 {
     return(new AttackHandler
     {
         agent = agent,
         attackReceiver = attackReceiver,
         onAttackedTransition = onAttackedTransition,
         onDeathTransition = onDeathTransition
     });
 }
コード例 #3
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);
            }
        }