Ejemplo n.º 1
0
        public override FSMStates CheckTransitions()
        {
            if (controller.AttackTarget == null)
            {
                if (controller.AttackMoving)
                {
                    controller.AttackMove(controller.AttackMoveDestination);
                    return(FSMStates.AttackMove);
                }
                return(FSMStates.Idle);
            }


            float distance = AttackableHelper.Distance(controller.ControlledUnit, controller.AttackTarget);

            if (distance <= controller.ControlledUnit.AttackRange)
            {
                return(FSMStates.Attack);
            }
            else if (gm.IsInSightRange(controller.AttackTarget, controller.ControlledUnit.Faction))
            {
                return(FSMStates.Chase);
            }
            else //Shouldn't happen unless vision range is lower than attack range
            {
                if (controller.AttackMoving)
                {
                    controller.AttackMove(controller.AttackMoveDestination);
                    return(FSMStates.AttackMove);
                }

                return(FSMStates.Idle);
            }
        }
 public override void Update(GameTime gameTime)
 {
     controller.ControlledUnit.SetVelocity(Vector2.Zero);
     if (controller.AttackTarget != null)
     {
         if (controller.AttackTarget.IsDead() || AttackableHelper.Distance(controller.AttackTarget, controller.ControlledUnit) > controller.ControlledUnit.AttackRange)
         {
             controller.AttackTarget = null;
             return;
         }
         controller.ControlledUnit.Attack(controller.AttackTarget);
     }
     else
     {
         Attackable nearestTarget = controller.ControlledUnit.GetNearestTargetInAttackRange();
         if (nearestTarget != null)
         {
             controller.AttackTarget = nearestTarget;
             controller.ControlledUnit.Attack(controller.AttackTarget);
         }
     }
 }