Package ch.fusun.baron.unit

Examples of ch.fusun.baron.unit.Unit


  @Override
  public Collection<TileChild> getChildren(Tile model) {
    Collection<Unit> units = unitService.getUnits(model);
    Collection<TileChild> children = new ArrayList<TileChild>();
    if (units != null && !units.isEmpty()) {
      Unit unit = units.iterator().next();
      Dynasty dynasty = (Dynasty) propertyService.getOwnership(unit);
      if (unit != null) {
        children.add(new UnitDynastyTileChild(dynasty));
      }
    }
View Full Code Here


  @Override
  public boolean isAllowedImpl() {
    Collection<Unit> units = unitService.getUnits(destination);
    boolean destinationOccupied = false;
    if (!units.isEmpty()) {
      Unit otherUnit = units.iterator().next();
      destinationOccupied = dynasty.equals(propertyService
          .getOwnership(otherUnit));
    }
    return dynasty.equals(propertyService.getOwnership(unit))
        && tileIsReachable() && unitService.unitExists(unit)
View Full Code Here

    return !(unitService.getLocation(unit).absoluteDistanceTo(destination) > 1f);
  }

  @Override
  public void executeImpl() {
    Unit movingUnit = unitService.getUnits(unitService.getLocation(unit))
        .iterator().next();
    Collection<Unit> units = unitService.getUnits(destination);
    if (units.isEmpty()) {
      unitService.moveUnit(movingUnit, destination);
      if (calculateAnnectionFrom()) {
        messagingService
            .addMessage(
                userService.getUser(),
                "City of " //$NON-NLS-1$
                    + ((Dynasty) propertyService
                        .getOwnership(unit)).getName()
                    + " is lost because no one defended it."); //$NON-NLS-1$
      }
    } else {
      Unit otherUnit = units.iterator().next();
      if (!dynasty.equals(propertyService.getOwnership(otherUnit))) {
        int numberOfUnits = movingUnit.getNumberOfUnits();
        int otherNumberOfUnits = otherUnit.getNumberOfUnits();
        int casualties = 0;
        int otherCasualties = 0;
        for (int i = 1; i <= Math
            .max(numberOfUnits, otherNumberOfUnits); i++) {
          if (i > numberOfUnits) {
            casualties += (Math.random() < 0.5f) ? 1 : 0;
          } else if (i > otherNumberOfUnits) {
            otherCasualties += (Math.random() < 0.5f) ? 1 : 0;
          } else if (Math.random() < 0.5f) {
            casualties += 1;
          } else {
            otherCasualties += 1;
          }
        }
        messagingService
            .addMessage(
                userService.getUser(),
                "Battle between " //$NON-NLS-1$
                    + ((Dynasty) propertyService
                        .getOwnership(unit)).getName()
                    + "(" + casualties + " casualties) and " //$NON-NLS-1$ //$NON-NLS-2$
                    + ((Dynasty) propertyService
                        .getOwnership(otherUnit))
                        .getName() + "(" //$NON-NLS-1$
                    + otherCasualties + " casualties)"); //$NON-NLS-1$
        movingUnit.kill(casualties);
        if (movingUnit.isDead()) {
          unitService.removeUnit(movingUnit);
          messagingService.addMessage(
              userService.getUser(),
              "Attacking unit of " //$NON-NLS-1$
                  + ((Dynasty) propertyService
                      .getOwnership(unit)).getName()
                  + " exploded in a fireball"); //$NON-NLS-1$
        }
        otherUnit.kill(otherCasualties);
        if (otherUnit.isDead()) {
          messagingService.addMessage(
              userService.getUser(),
              "Defending unit of " //$NON-NLS-1$
                  + ((Dynasty) propertyService
                      .getOwnership(unit)).getName()
View Full Code Here

            .getLocation(city)))));
  }

  @Override
  public void executeImpl() {
    Unit unit = unitService.createUnit(cityService.getLocation(city),
        numberOfUnits);
    propertyService.setOwnership(dynasty, unit);
  }
View Full Code Here

  }

  @Override
  public void execute(Object object) {
    if (object instanceof Unit) {
      Unit unit = (Unit) object;
      Tile location = unitService.getLocation(unit);
      Dynasty dynasty = playerService.getDynasty(userService.getUser());
      int width = mapService.getWidth();
      int height = mapService.getHeight();
      clientService.execute(new MoveUnitCommand(dynasty, unit, new Tile(
View Full Code Here

    return tileUnitMap.get(tile);
  }

  @Override
  public Unit createUnit(Tile location, int numberOfUnits) {
    Unit unit = new Unit(getNextId(), numberOfUnits);
    addUnitToLocation(location, unit);
    return unit;
  }
View Full Code Here

TOP

Related Classes of ch.fusun.baron.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.