/// <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()
        {
            if (target == null)
            {
                return true;
            }

            // target is dead, return true.
            if (target.CurrentHealth <=0)
            {
                return true;
            }

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

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

                // Call the SimpleAttackAction
                attackAction.Work();

                // Set the MoveAction to null.
                moveAction = null;
            }
            // Target is not in range, move to it.
            else
            {
                if(moveAction != null && !targetIsInRange(target.PointLocation.X, target.PointLocation.Y, moveAction.targetX, moveAction.targetY))
                {
                    moveAction = null;
                }

                // Create a MoveAction if it is needed.
                if (moveAction == null)
                {
                    if (target is UnitComponent)
                    {
                        UnitComponent temp = (UnitComponent)target;
                        moveAction = new MoveAction(temp.PointLocation.X, temp.PointLocation.Y, gw.GetMap(), unit);
                    }
                    else if (target is Building)
                    {
                        //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;
        }
示例#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()
        {
            if (target == null)
            {
                return(true);
            }

            // target is dead, return true.
            if (target.CurrentHealth <= 0)
            {
                return(true);
            }

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

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

                // Call the SimpleAttackAction
                attackAction.Work();

                // Set the MoveAction to null.
                moveAction = null;
            }
            // Target is not in range, move to it.
            else
            {
                if (moveAction != null && !targetIsInRange(target.PointLocation.X, target.PointLocation.Y, moveAction.targetX, moveAction.targetY))
                {
                    moveAction = null;
                }


                // Create a MoveAction if it is needed.
                if (moveAction == null)
                {
                    if (target is UnitComponent)
                    {
                        UnitComponent temp = (UnitComponent)target;
                        moveAction = new MoveAction(temp.PointLocation.X, temp.PointLocation.Y, gw.GetMap(), unit);
                    }
                    else if (target is Building)
                    {
                        //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);
        }