Package org.freerealm.executor

Examples of org.freerealm.executor.CommandResult


            unitsToRemove.add(unitIterator.next());
        }
        Executor.getInstance().execute(new RemoveUnitsCommand(player, unitsToRemove));
        player.setStatus(Player.STATUS_REMOVED);
        realm.getPlayerManager().removePlayer(player);
        CommandResult commandResult = new CommandResult(CommandResult.RESULT_OK, "", CommandResult.PLAYER_REMOVED_UPDATE);
        commandResult.addParameter(player);
        return commandResult;
    }
View Full Code Here


     * @param realm Realm to execute the command
     * @return CommandResult
     */
    public CommandResult execute(Realm realm) {
        if (unit.getType().getAbility("Fight") == null) {
            return new CommandResult(CommandResult.RESULT_ERROR, "No attack ability");
        }
        if (unit.getMovementPoints() <= 0) {
            return new CommandResult(CommandResult.RESULT_ERROR, "Unit can not move");
        }
        if (tile.getNumberOfUnits() > 0) {
            Unit defendingUnit = tile.getUnits().get(tile.getUnits().firstKey());
            if (!unit.getPlayer().equals(defendingUnit.getPlayer())) {
                Tile defenceTile = realm.getTile(defendingUnit.getCoordinate());
                int defencePercentage = defenceTile.getType().getDefencePercentage();
                if ((tile.getSettlement() != null) && tile.getSettlement().getDefenceModifier() > 0) {
                    defencePercentage = (defencePercentage * tile.getSettlement().getDefenceModifier()) / 100;
                }
                Executor.getInstance().execute(new AttackUnitCommand(unit, defendingUnit));
            }
        }
        return new CommandResult(CommandResult.RESULT_OK, "");
    }
View Full Code Here

     * @param realm Realm to execute the command
     * @return CommandResult
     */
    public CommandResult execute(Realm realm) {
        if ((unit != null) && (!player.hasUnit(unit))) {
            return new CommandResult(CommandResult.RESULT_ERROR, "Unit does not belong to active user");
        }
        player.setActiveUnit(unit);
        return new CommandResult(CommandResult.RESULT_OK, "", CommandResult.ACTIVE_UNIT_UPDATE);
    }
View Full Code Here

     * @param realm Realm to execute the command
     * @return CommandResult
     */
    public CommandResult execute(Realm realm) {
        if (unit == null) {
            return new CommandResult(CommandResult.RESULT_ERROR, "Unit is null");
        } else {
            unit.setMovementPoints(0);
            unit.setSkippedForCurrentTurn(true);
            return new CommandResult(CommandResult.RESULT_OK, "");
        }
    }
View Full Code Here

     * @param realm Realm to execute the command
     * @return CommandResult
     */
    public CommandResult execute(Realm realm) {
        if (!Utility.isTileAvailable(realm, settlement, coordinate)) {
            return new CommandResult(CommandResult.RESULT_ERROR, "Tile is not available for settlement");
        }
        if (workforce.getNumberOfWorkers() > settlement.getMaxWorkersPerTile()) {
            return new CommandResult(CommandResult.RESULT_ERROR, "Number of workers can not exceed " + settlement.getMaxWorkersPerTile());
        }
        int numberOfWorkersForTile = 0;
        if (settlement.getWorkForceManager().getAssignedWorkforceForTile(coordinate) != null) {
            numberOfWorkersForTile = settlement.getWorkForceManager().getAssignedWorkforceForTile(coordinate).getNumberOfWorkers();
        }
        if (workforce.getNumberOfWorkers() - numberOfWorkersForTile <= settlement.getProductionWorkforce()) {
            settlement.getWorkForceManager().addWorkForce(coordinate, workforce);
            return new CommandResult(CommandResult.RESULT_OK, "");
        } else {
            return new CommandResult(CommandResult.RESULT_ERROR, "Not enough free workforce");
        }
    }
View Full Code Here

     * @param realm Realm to execute the command
     * @return CommandResult
     */
    public CommandResult execute(Realm realm) {
        realm.getWorldMap().getTile(coordinate).setVegetation(vegetation);
        CommandResult commandResult = new CommandResult(CommandResult.RESULT_OK, "", CommandResult.VEGETATION_CHANGED_UPDATE);
        commandResult.addParameter(coordinate);
        return commandResult;
    }
View Full Code Here

     * @param realm Realm to execute the command
     * @return CommandResult
     */
    public CommandResult execute(Realm realm) {
        if (unit.getCoordinate().equals(coordinate)) {
            return new CommandResult(CommandResult.RESULT_OK, "");
        }
        PathFinder pathFinder = realm.getPathFinder();
        if (pathFinder == null) {
            return new CommandResult(CommandResult.RESULT_ERROR, "PathFinder for realm is null.");
        }
        Path path = pathFinder.findPath(unit, coordinate, true);
        if (path == null) {
            String errorMessage = "There is not any path from unit's current location to target tile\n";
            errorMessage = errorMessage + "Units location : " + unit.getCoordinate();
            errorMessage = errorMessage + " Target coordinate :" + coordinate;
            return new CommandResult(CommandResult.RESULT_ERROR, errorMessage);
        }
        int i = 0;
        while ((unit.getMovementPoints() > 0) && (i < path.getLength())) {
            Coordinate pathCoordinate = path.getStep(i);
            Tile tile = realm.getTile(pathCoordinate);
            ICommand command = null;
            if (tile.getNumberOfUnits() > 0) {
                Unit tileUnit = tile.getUnits().get(tile.getUnits().firstKey());
                if (!unit.getPlayer().equals(tileUnit.getPlayer())) {
                    command = new AttackTileCommand(unit, tile);
                } else {
                    command = new MoveUnitCommand(unit, pathCoordinate);
                }
            } else {
                if (tile.getSettlement() != null) {
                    Settlement settlement = tile.getSettlement();
                    if (!unit.getPlayer().equals(settlement.getPlayer())) {
                        command = new CaptureSettlementCommand(unit, settlement);
                    } else {
                        command = new MoveUnitCommand(unit, pathCoordinate);
                    }
                } else {
                    command = new MoveUnitCommand(unit, pathCoordinate);
                }
            }
            CommandResult commandResult = Executor.getInstance().execute(command);
            i++;
            if (commandResult.getCode() == CommandResult.RESULT_ERROR) {
                return new CommandResult(CommandResult.RESULT_ERROR, "A command returned an error. Error : " + commandResult.getText());
            }
        }
        return new CommandResult(CommandResult.RESULT_OK, "");
    }
View Full Code Here

     * @param realm Realm to execute the command
     * @return CommandResult
     */
    public CommandResult execute(Realm realm) {
        if (player.getWealth() < amount) {
            return new CommandResult(CommandResult.RESULT_ERROR, "");
        }
        player.setWealth(player.getWealth() - amount);
        return new CommandResult(CommandResult.RESULT_OK, "");
    }
View Full Code Here

        this.population = population;
    }

    public CommandResult execute(Realm realm) {
        settlement.setPopulation(population);
        return new CommandResult(CommandResult.RESULT_OK, "");
    }
View Full Code Here

                        unit.getNextOrder().setTurnGiven(realm.getNumberOfTurns());
                    }
                }
                //    unit.setMovementPoints(0);
            }
            return new CommandResult(CommandResult.RESULT_OK, "");
        } else {
            return new CommandResult(CommandResult.RESULT_ERROR, "Unit can not be null");
        }
    }
View Full Code Here

TOP

Related Classes of org.freerealm.executor.CommandResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.