Пример #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 boolean isAdmissible(Ally ally) {
      long points = 0;
      if (ally != null) points = ally.getPoints();

      if (minPoints != -1 && points < minPoints) return false;
      if (maxPoints != -1 && points > minPoints) return false;

      int level = ally.getMediumLevel();

      if (minLevel != -1 && level < minLevel) return false;
      if (maxLevel != -1 && level > minLevel) return false;

      return true;
    }
Пример #3
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;
  }
Пример #4
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();
  }
Пример #5
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);
      }
    }
  }