Package org.freerealm.unit

Examples of org.freerealm.unit.Unit


    public CommandResult execute(Realm realm) {

        System.out.println(attacker + " attacks " + defender);
        CommandResult commandResult = null;
        if (attacker.canAttack()) {
            Unit winner = null;
            Unit loser = null;
            int attackPoints = attacker.getAttackPoints();
            System.out.println("Attack points : " + attackPoints);
            int defencePoints = defender.getDefencePoints();
            System.out.println("Defense points : " + defencePoints);
            attackPoints = Utility.increaseByPercent(attackPoints, attackBonusPercentage);
            System.out.println("Actual attack points : " + attackPoints);
            defenceBonusPercentage = Utility.getCoordinateDefenceBonus(realm, defender.getCoordinate());
            defencePoints = Utility.increaseByPercent(defencePoints, defenceBonusPercentage);
            System.out.println("Actual defense points : " + defencePoints);
            int total = attackPoints + defencePoints;
            Random random = new Random(System.currentTimeMillis());
            int randomInt = random.nextInt(total);
            System.out.println("Total : " + total + " Random : " + randomInt);
            if (randomInt < attackPoints) {
                System.out.println("Attacker won!");
                loser = defender;
                winner = attacker;
            } else {
                System.out.println("Defender won!");
                loser = attacker;
                winner = defender;
            }
            winner.setMovementPoints(0);
            Executor.getInstance().execute(new RemoveUnitCommand(loser.getPlayer(), loser));
            commandResult = new CommandResult(CommandResult.RESULT_OK, "", CommandResult.UNIT_ATTACKED_UPDATE);
            commandResult.addParameter(attacker);
            commandResult.addParameter(defender);
            commandResult.addParameter(winner);
            commandResult.addParameter(defender.getCoordinate());
View Full Code Here


                Settlement settlement = settlementsIterator.next();
                worldMap.addSettlement(settlement);
            }
            Iterator<Unit> unitsIterator = player.getUnitsIterator();
            while (unitsIterator.hasNext()) {
                Unit unit = unitsIterator.next();
                if (unit.getCoordinate() != null) {
                    worldMap.addUnit(unit);
                }
            }
        }
        realm.setWorldMap(worldMap);
View Full Code Here

        if (unitManager.getActiveUnit() != null) {
            xml.append("<activeUnit>" + unitManager.getActiveUnit().getId() + "</activeUnit>\n");
        }
        Iterator<Unit> unitIterator = unitManager.getUnitsIterator();
        while (unitIterator.hasNext()) {
            Unit unit = unitIterator.next();
            UnitXMLWrapper unitXMLWrapper = new UnitXMLWrapper(unit);
            xml.append(unitXMLWrapper.toXML());
        }
        xml.append("</units>");
        return xml.toString();
View Full Code Here

    public void initializeFromNode(Realm realm, Node node) {
        int activeUnitId = -1;
        for (Node subNode = node.getFirstChild(); subNode != null; subNode = subNode.getNextSibling()) {
            if (subNode.getNodeType() == Node.ELEMENT_NODE) {
                if (subNode.getNodeName().equals("Unit")) {
                    Unit unit = new Unit(realm);
                    UnitXMLWrapper unitXMLWrapper = new UnitXMLWrapper(unit);
                    unit.setPlayer(unitManager.getPlayer());
                    unitXMLWrapper.initializeFromNode(realm, subNode);
                    unitManager.addUnit(unit);
                } else if (subNode.getNodeName().equals("activeUnit")) {
                    activeUnitId = Integer.parseInt(subNode.getFirstChild().getNodeValue());
                }
View Full Code Here

        }
        if (unit.getMovementPoints() > 0 && unit.getMovementPoints() < 1 && toTile.getMovementCost() >= 1) {
            return new CommandResult(CommandResult.RESULT_ERROR, "");
        }
        if (toTile.getNumberOfUnits() > 0) {
            Unit defendingUnit = toTile.getUnits().get(toTile.getUnits().firstKey());
            if (!unit.getPlayer().equals(defendingUnit.getPlayer())) {
                return new CommandResult(CommandResult.RESULT_ERROR, "Tile contains a unit that does not belong to player. Use AttackTileCommand.");
            }
        }

        if ((toTile.getSettlement() != null) && (!unit.getPlayer().equals((toTile.getSettlement().getPlayer())))) {
View Full Code Here

                Player neighborTileCityPlayer = checkTile.getSettlement().getPlayer();
                setDiplomaticStatusToPeaceIfNeeded(realm, movingUnitsPlayer, neighborTileCityPlayer);
            }
            Iterator<Unit> unitIterator = checkTile.getUnitsIterator();
            while (unitIterator.hasNext()) {
                Unit checkUnit = unitIterator.next();
                Player movingUnitsPlayer = unit.getPlayer();
                Player neighborTileUnitPlayer = checkUnit.getPlayer();
                setDiplomaticStatusToPeaceIfNeeded(realm, movingUnitsPlayer, neighborTileUnitPlayer);
            }
        }
    }
View Full Code Here

     * @return CommandResult
     */
    public CommandResult execute(Realm realm) {
        Iterator<Unit> unitsIterator = units.iterator();
        while (unitsIterator.hasNext()) {
            Unit unit = unitsIterator.next();
            Executor.getInstance().execute(new RemoveUnitCommand(player, unit));
        }
        return new CommandResult(CommandResult.RESULT_OK, "");
    }
View Full Code Here

        }
        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));
View Full Code Here

        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 {
View Full Code Here

    public UnitGroupDefinition getUnitGroupDefinition() {
        DefaultUnitGroupDefinition unitGroupDefinition = new DefaultUnitGroupDefinition();
        Iterator<Unit> iterator = getUnitsIterator();
        while (iterator.hasNext()) {
            Unit unit = iterator.next();
            unitGroupDefinition.setQuantityForUnitType(unit.getType(), unitGroupDefinition.getQuantityForUnitType(unit.getType()) + 1);
        }
        return unitGroupDefinition;
    }
View Full Code Here

TOP

Related Classes of org.freerealm.unit.Unit

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.