Exemplo n.º 1
0
  @Override
  protected String execute(Player player, Map<String, Object> params, Session session)
      throws Exception {
    long lastUpdate = (Long) params.get("update");

    Ally ally = player.getAlly();

    if (ally == null) throw new IllegalOperationException("Vous n'appartanez à aucune alliance.");

    Player kicked = DataAccess.getPlayerById((Integer) params.get("id"));

    if (kicked == null) throw new IllegalOperationException("Ce joueur n'existe pas");

    if (kicked.getIdAlly() != player.getIdAlly())
      throw new IllegalOperationException("Ce joueur ne fait pas partie de votre alliance.");

    if (player.getAllyRank() < ally.getRequiredRank(Ally.RIGHT_KICK, kicked.getAllyRank()))
      throw new IllegalOperationException(
          "Vous n'avez pas les droits nécessaires pour éjecter ce membre.");

    List<Player> members = ally.getMembers();

    // Quitte les canaux de discussion de l'alliance
    ChatManager.getInstance().leaveAllyChannels(kicked);

    synchronized (kicked.getLock()) {
      kicked = DataAccess.getEditable(kicked);
      kicked.setAllyRank(0);
      kicked.setIdAlly(0);
      kicked.setLastAllyIn(Utilities.now());
      kicked.save();
    }

    // Vérifie les liens entre flottes des membres de l'alliance
    synchronized (members) {
      for (Player member : members) FleetTools.checkLinks(member);
    }

    // TODO bmoyet Event : Ajoutez un événement pour le kick
    // DataAccess.save(new Event());

    // Met à jour l'influence de l'alliance
    ally.updateInfluences();

    // Mise à jour des secteurs consultés pour les joueurs de l'alliance,
    // afin que le membre éjecté soit pris en compte, au besoin
    UpdateTools.queueAreaUpdate(ally.getMembers());

    UpdateTools.queueAllyUpdate(kicked.getId(), 0, false);
    UpdateTools.queueChatChannelsUpdate(kicked.getId(), false);
    UpdateTools.queueAreaUpdate(kicked);

    return UpdateTools.formatUpdates(
        player, Update.getAllyUpdate(lastUpdate), Update.getAreaUpdate());
  }
  public SpaceshipYardUpdater() {
    List<StructureSpaceshipYard> spaceshipYards =
        new ArrayList<StructureSpaceshipYard>(DataAccess.getAllSpaceshipYards());

    for (StructureSpaceshipYard spaceshipYard : spaceshipYards)
      updateAndQueueUpdate(spaceshipYard, false);

    GameEventsDispatcher.addGameEventListener(this, BuildSlotChangeEvent.class);
  }
Exemplo n.º 3
0
  public void run() {
    this.setName("OrganizeElection (daily)");
    List<Ally> allies = new ArrayList<Ally>(DataAccess.getAllAllies());

    for (Ally ally : allies) {
      if (!ally.getOrganization().equals(Ally.ORGANIZATION_DEMOCRACY)
          && !ally.getOrganization().equals(Ally.ORGANIZATION_WARMONGER)) continue;

      if (ally.getDaysFromCreation() % Election.FREQUENCY == 0
          && ally.getDaysFromCreation() != 0
          && DataAccess.getElectionByAlly(ally.getId()) == null) {
        DataAccess.save(new Election(Utilities.now(), ally.getId()));

        // TODO bmoyet Event : Avertir l'alliance du démarrage du vote
        Event event =
            new Event(Event.EVENT_ELECTION_START, Event.TARGET_ALLY, ally.getId(), 0, -1, -1);
        event.save();

        UpdateTools.queueNewEventUpdate(ally.getMembers(), false);
      }
    }
  }
  private void updateAndQueueUpdate(StructureSpaceshipYard spaceshipYard, boolean update) {
    synchronized (spaceshipYard.getLock()) {
      spaceshipYard = DataAccess.getEditable(spaceshipYard);
      spaceshipYard.update();
      spaceshipYard.save();
    }

    if (update) {
      Structure structure = spaceshipYard.getStructure();
      Player owner = structure.getOwner();
      if (owner.getIdCurrentArea() == structure.getIdArea()) UpdateTools.queueAreaUpdate(owner);
    }

    queueUpdate(spaceshipYard);
  }
Exemplo n.º 5
0
  public static JSONStringer getPlayerProducts(JSONStringer json, Player player) {
    if (json == null) json = new JSONStringer();

    json.array();

    if (player.getIdAlly() != 0) {
      Ally ally = player.getAlly();
      List<Area> areas = DataAccess.getAllAreas();

      synchronized (areas) {
        for (Area area : areas)
          if (area.getIdDominatingAlly() == ally.getId() && area.getProduct() != 0)
            json.value(area.getProduct());
      }
    }

    json.endArray();

    return json;
  }
Exemplo n.º 6
0
  @Override
  protected String execute(Player player, Map<String, Object> params, Session session)
      throws Exception {

    AllyNews news = DataAccess.getAllyNewsById((Integer) params.get("news"));
    if (news == null) throw new IllegalOperationException("Cette news n'existe pas.");

    Ally ally = player.getAlly();
    if (ally == null) throw new IllegalOperationException("Vous n'appartenez à aucune alliance.");

    if (news.getIdAlly() != player.getIdAlly())
      throw new IllegalOperationException("Vous ne pouvez pas supprimer cette news.");

    if (player.getAllyRank() < ally.getRequiredRank(Ally.RIGHT_MANAGE_NEWS))
      throw new IllegalOperationException(
          "Vous n'avez pas les droits nécessaires pour effectuer cette action.");

    if (news.getIdApplicant() != 0)
      throw new IllegalOperationException(
          "Impossible de supprimer une news concernant la candidature d'un joueur.");

    JSONStringer json = new JSONStringer();

    news.delete();
    Event event =
        new Event(
            Event.EVENT_ALLY_REMOVED_NEWS,
            Event.TARGET_ALLY,
            ally.getId(),
            0,
            -1,
            -1,
            player.getLogin());
    event.save();
    UpdateTools.queueNewEventUpdate(ally.getMembers(), false);

    return json.object().key("id").value(news.getId()).endObject().toString();
  }
  @Override
  public void process(Long idStructure, long time) {
    StructureSpaceshipYard spaceshipYard = DataAccess.getSpaceshipYardByStructure(idStructure);

    updateAndQueueUpdate(spaceshipYard, true);
  }
  @Override
  protected String execute(Player player, Map<String, Object> params, Session session)
      throws Exception {
    // Flotte qui construit la balise
    Fleet fleet = FleetTools.getFleetByIdWithChecks((Integer) params.get("fleet"), player.getId());
    String password = (String) params.get("password");

    // Vérifie que la flotte a du mouvement
    if (fleet.getMovement() == 0)
      throw new IllegalOperationException("La flotte n'a pas " + "suffisament de mouvement.");

    // Cherche la station spatiale construite sur la case de la flotte
    List<SpaceStation> spaceStations = DataAccess.getSpaceStationsByArea(fleet.getIdCurrentArea());

    int fleetX = fleet.getCurrentX();
    int fleetY = fleet.getCurrentY();

    synchronized (spaceStations) {
      for (SpaceStation spaceStation : spaceStations) {
        int dx = spaceStation.getX() - fleetX;
        int dy = spaceStation.getY() - fleetY;
        double radius = GameConstants.SPACE_STATION_RADIUS;

        if (dx * dx + dy * dy <= radius * radius) {
          String treaty = Treaty.NEUTRAL;
          if (player.getIdAlly() != 0)
            treaty = spaceStation.getAlly().getTreatyWithAlly(player.getIdAlly());

          if (treaty.equals(Treaty.ENEMY)
              || (treaty.equals(Treaty.ALLY)
                  && player.getAllyRank()
                      >= player.getAlly().getRequiredRank(Ally.RIGHT_MANAGE_STATIONS))
              || (treaty.equals(Treaty.NEUTRAL) && fleet.getSkillLevel(Skill.SKILL_PIRATE) >= 0)) {

            boolean newEvent = false;

            List<Update> updates = new ArrayList<Update>();

            // Endommage ou détruit la station
            if (treaty.equals(Treaty.ALLY) || spaceStation.getHull() <= fleet.getPowerLevel()) {
              if (treaty.equals(Treaty.ALLY)
                  && (password == null
                      || !player.getPassword().equals(Utilities.encryptPassword(password))))
                throw new IllegalOperationException("Mot de passe invalide.");

              spaceStation.delete();

              spaceStation.getArea().getSector().updateInfluences();

              newEvent = true;

              if (treaty.equals(Treaty.ALLY)) {
                Event event =
                    new Event(
                        Event.EVENT_STATION_SELF_DESTRUCT,
                        Event.TARGET_ALLY,
                        spaceStation.getIdAlly(),
                        spaceStation.getIdArea(),
                        spaceStation.getX(),
                        spaceStation.getY(),
                        spaceStation.getName(),
                        String.valueOf(player.getLogin()));
                event.save();
              } else {
                Event event =
                    new Event(
                        Event.EVENT_STATION_LOST,
                        Event.TARGET_ALLY,
                        spaceStation.getIdAlly(),
                        spaceStation.getIdArea(),
                        spaceStation.getX(),
                        spaceStation.getY(),
                        spaceStation.getName());
                event.save();
              }

              Effect effect =
                  new Effect(
                      Effect.TYPE_STATION_DESTRUCTION,
                      fleet.getCurrentX(),
                      fleet.getCurrentY(),
                      fleet.getIdCurrentArea());

              UpdateTools.queueEffectUpdate(effect, player.getId(), false);

              updates.add(Update.getEffectUpdate(effect));
            } else {
              double coefBefore =
                  spaceStation.getHull()
                      / (double) SpaceStation.HULL_LEVELS[spaceStation.getLevel()];

              synchronized (spaceStation.getLock()) {
                spaceStation = DataAccess.getEditable(spaceStation);
                spaceStation.setHull(spaceStation.getHull() - fleet.getPowerLevel());
                spaceStation.save();
              }

              double coefAfter =
                  spaceStation.getHull()
                      / (double) SpaceStation.HULL_LEVELS[spaceStation.getLevel()];

              if (coefBefore != 1 && (int) (coefBefore * 5) != (int) (coefAfter * 5)) {
                newEvent = true;

                Event event =
                    new Event(
                        Event.EVENT_STATION_UNDER_ATTACK,
                        Event.TARGET_ALLY,
                        spaceStation.getIdAlly(),
                        spaceStation.getIdArea(),
                        spaceStation.getX(),
                        spaceStation.getY(),
                        spaceStation.getName(),
                        String.valueOf(coefAfter));
                event.save();
              }
            }

            synchronized (fleet.getLock()) {
              fleet = DataAccess.getEditable(fleet);
              fleet.doAction(
                  Fleet.CURRENT_ACTION_ATTACK_STRUCTURE,
                  Utilities.now() + GameConstants.DESTROY_SPACE_STATION_MOVEMENT_RELOAD);
              fleet.save();
            }

            // Mises à jour
            if (newEvent)
              UpdateTools.queueNewEventUpdate(spaceStation.getAlly().getMembers(), false);
            UpdateTools.queueAreaUpdate(fleet.getIdCurrentArea(), player.getId());

            updates.add(Update.getPlayerFleetUpdate(fleet.getId()));
            updates.add(Update.getAreaUpdate());

            return UpdateTools.formatUpdates(player, updates);
          } else {
            throw new IllegalOperationException(
                "Vous ne pouvez pas saboter cette station spatiale.");
          }
        }
      }
    }

    throw new IllegalOperationException("Pas de station spatiale à cet endroit.");
  }