/// <summary>
        /// This function will perform the Attack Action.
        /// </summary>
        /// <returns>true if the action is completed, false if it is not.</returns>
        public override bool work()
        {
            // target is dead, return true.
            if (target.getState().getPrimaryState() == State.PrimaryState.Dead)
            {
                return true;
            }

            // unit cannot attack, return true.
            if (!unit.stats.canAttack)
            {
                return true;
            }

            // Target is in range attack target.
            if (targetIsInRange())
            {
                // Create a SimpleAttackAction if it is needed.
                if (this.attackAction == null)
                {
                    attackAction = new SimpleAttackAction(unit, target);
                }

                // Call the SimpleAttackAction
                attackAction.work();

                // Set the MoveAction to null.
                moveAction = null;
            }
            // Target is not in range, move to it.
            else
            {
                // Create a MoveAction if it is needed.
                if (moveAction == null)
                {
                    if (target.getEntityType() == Entity.EntityType.Unit)
                    {
                        Unit temp = (Unit)target;
                        moveAction = new MoveAction(temp.x, temp.y, gw, unit);
                    }
                    else
                    {
                        StaticEntity temp = (StaticEntity)target;
                        moveAction = new MoveAction(temp.orginCell.Xcoord, temp.orginCell.Ycoord, gw, unit);
                    }
                }
                // Set the SimpleAttackAction to null.
                attackAction = null;

                // Call the MoveAction.
                moveAction.work();
            }

            return false;
        }
Beispiel #2
0
        /// <summary>
        /// This function will perform the Attack Action.
        /// </summary>
        /// <returns>true if the action is completed, false if it is not.</returns>
        public override bool work()
        {
            // target is dead, return true.
            if (target.getState().getPrimaryState() == State.PrimaryState.Dead)
            {
                return(true);
            }

            // unit cannot attack, return true.
            if (!unit.stats.canAttack)
            {
                return(true);
            }

            // Target is in range attack target.
            if (targetIsInRange())
            {
                // Create a SimpleAttackAction if it is needed.
                if (this.attackAction == null)
                {
                    attackAction = new SimpleAttackAction(unit, target);
                }

                // Call the SimpleAttackAction
                attackAction.work();

                // Set the MoveAction to null.
                moveAction = null;
            }
            // Target is not in range, move to it.
            else
            {
                // Create a MoveAction if it is needed.
                if (moveAction == null)
                {
                    if (target.getEntityType() == Entity.EntityType.Unit)
                    {
                        Unit temp = (Unit)target;
                        moveAction = new MoveAction(temp.x, temp.y, gw, unit);
                    }
                    else
                    {
                        StaticEntity temp = (StaticEntity)target;
                        moveAction = new MoveAction(temp.orginCell.Xcoord, temp.orginCell.Ycoord, gw, unit);
                    }
                }
                // Set the SimpleAttackAction to null.
                attackAction = null;

                // Call the MoveAction.
                moveAction.work();
            }

            return(false);
        }