示例#1
0
        // Attack execution.
        public override bool Execute(List <Cell> targets, Map map)
        {
            // If no damage.
            if (Damage == null)
            {
                return(false);
            }

            // If no target.
            if (targets == null)
            {
                return(false);
            }

            // If more than one target.
            if (targets.Count != 1)
            {
                return(false);
            }

            Cell cell = targets[0];

            // If no executer or cell to attack.
            if (Executer == null || cell == null)
            {
                return(false);
            }

            // If no target to attack.
            IDamageable target = cell.Unit;

            if (target == null)
            {
                return(false);
            }

            BasicUnit unit = Executer as BasicUnit;

            // If cell is not in range.
            if (!InRange(cell, map))
            {
                return(false);
            }

            // If not enough action points.
            if (!unit.UseActionPoints(Cost))
            {
                return(false);
            }

            unit.UpdateFacing(cell);

            unit.DealDamage(target, Damage);

            return(true);
        }
示例#2
0
        // Attack execution.
        public override bool Execute(List <Cell> targets, Map map)
        {
            // If no damage.
            if (Damage == null)
            {
                return(false);
            }

            // If no target.
            if (targets == null)
            {
                return(false);
            }

            // If more than one target.
            if (targets.Count != 1)
            {
                return(false);
            }

            Cell cell = targets[0];

            // If no executer or cell to attack.
            if (Executer == null || cell == null)
            {
                return(false);
            }

            // If no target to attack.
            BasicUnit target = cell.Unit;

            if (target == null)
            {
                return(false);
            }

            BasicUnit unit = Executer as BasicUnit;

            // If cell is not in range.
            if (!InRange(cell, map))
            {
                return(false);
            }

            // If not enough action points.
            if (!unit.UseActionPoints(Cost))
            {
                return(false);
            }

            var translation      = Coordinates.GetVectorByDirection(unit.Cell.GetDirection(cell));
            var targetCellCoords = new Coordinates(unit.Cell.Position.X + (int)translation.x, unit.Cell.Position.Y + (int)translation.y);
            var targetCell       = map.Cells[targetCellCoords];

            target.Cell.Unit = null;
            target.Cell      = targetCell;
            targetCell.Unit  = target;

            unit.UpdateFacing(targetCell);
            target.UpdateFacing(unit.Cell);

            unit.DealDamage(target, Damage);

            return(true);
        }