protected OlympiadGameTeams(int id, Participant[] teamOne, Participant[] teamTwo) {
    super(id);

    _teamOneSize = Math.min(teamOne.length, MAX_TEAM_SIZE);
    _teamTwoSize = Math.min(teamTwo.length, MAX_TEAM_SIZE);
    _teamOne = new Participant[MAX_TEAM_SIZE];
    _teamTwo = new Participant[MAX_TEAM_SIZE];

    Participant par;
    for (int i = 0; i < MAX_TEAM_SIZE; i++) {
      if (i < _teamOneSize) {
        par = teamOne[i];
        _teamOne[i] = par;
        if (par.getPlayer() != null) {
          par.getPlayer().setOlympiadGameId(id);
        }
      } else {
        _teamOne[i] = new Participant(IdFactory.getInstance().getNextId(), 1);
      }

      if (i < _teamTwoSize) {
        par = teamTwo[i];
        _teamTwo[i] = par;
        if (par.getPlayer() != null) {
          par.getPlayer().setOlympiadGameId(id);
        }
      } else {
        _teamTwo[i] = new Participant(IdFactory.getInstance().getNextId(), 2);
      }
    }
  }
  public void newRace() {
    int random = 0;

    for (int i = 0; i < 8; i++) {
      int id = 31003;
      random = Rnd.get(24);
      while (true) {
        for (int j = i - 1; j >= 0; j--) {
          if (_monsters[j].getTemplate().getId() == (id + random)) {
            random = Rnd.get(24);
            continue;
          }
        }
        break;
      }
      try {
        L2NpcTemplate template = NpcData.getInstance().getTemplate(id + random);
        _constructor =
            Class.forName(
                    "com.l2jserver.gameserver.model.actor.instance."
                        + template.getType()
                        + "Instance")
                .getConstructors()[0];
        int objectId = IdFactory.getInstance().getNextId();
        _monsters[i] = (L2Npc) _constructor.newInstance(objectId, template);
      } catch (Exception e) {
        _log.log(Level.WARNING, "", e);
      }
      // _log.info("Monster "+i+" is id: "+(id+random));
    }
    newSpeeds();
  }
  @Override
  protected final void clearPlayers() {
    for (int i = 0; i < MAX_TEAM_SIZE; i++) {
      if (i < _teamOneSize) {
        _teamOne[i].setPlayer(null);
      } else {
        IdFactory.getInstance().releaseId(_teamOne[i].getObjectId());
      }

      if (i < _teamTwoSize) {
        _teamTwo[i].setPlayer(null);
      } else {
        IdFactory.getInstance().releaseId(_teamTwo[i].getObjectId());
      }

      _teamOne[i] = null;
      _teamTwo[i] = null;
    }
  }
Esempio n. 4
0
  public void convertOldPedgeFiles() {
    File dir = new File(Config.DATAPACK_ROOT, "data/crests/");

    File[] files = dir.listFiles(new OldPledgeFilter());

    for (File file : files) {
      int clanId = Integer.parseInt(file.getName().substring(7, file.getName().length() - 4));

      _log.info("Found old crest file \"" + file.getName() + "\" for clanId " + clanId);

      int newId = IdFactory.getInstance().getNextId();

      L2Clan clan = ClanTable.getInstance().getClan(clanId);

      if (clan != null) {
        removeOldPledgeCrest(clan.getCrestId());

        file.renameTo(new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + newId + ".bmp"));
        _log.info("Renamed Clan crest to new format: Crest_" + newId + ".bmp");

        Connection con = null;

        try {
          con = L2DatabaseFactory.getInstance().getConnection();
          PreparedStatement statement =
              con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
          statement.setInt(1, newId);
          statement.setInt(2, clan.getClanId());
          statement.executeUpdate();
          statement.close();
        } catch (SQLException e) {
          _log.log(Level.WARNING, "Could not update the crest id:" + e.getMessage(), e);
        } finally {
          L2DatabaseFactory.close(con);
        }

        clan.setCrestId(newId);
      } else {
        _log.info("Clan Id: " + clanId + " does not exist in table.. deleting.");
        file.delete();
      }
    }
  }
Esempio n. 5
0
 public void refreshID() {
   L2World.getInstance().removeObject(this);
   IdFactory.getInstance().releaseId(getObjectId());
   _objectId = IdFactory.getInstance().getNextId();
 }
  @Override
  protected void runImpl() {
    // Last Verified: May 30, 2009 - Gracia Final - Players are able to create characters with names
    // consisting of as little as 1,2,3 letter/number combinations.
    if ((_name.length() < 1) || (_name.length() > 16)) {
      if (Config.DEBUG)
        _log.fine(
            "Character Creation Failure: Character name "
                + _name
                + " is invalid. Message generated: Your title cannot exceed 16 characters in length. Please try again.");

      sendPacket(new CharCreateFail(CharCreateFail.REASON_16_ENG_CHARS));
      return;
    }

    if (Config.FORBIDDEN_NAMES.length > 1) {
      for (String st : Config.FORBIDDEN_NAMES) {
        if (_name.toLowerCase().contains(st.toLowerCase())) {
          sendPacket(new CharCreateFail(CharCreateFail.REASON_INCORRECT_NAME));
          return;
        }
      }
    }

    // Last Verified: May 30, 2009 - Gracia Final
    if (!Util.isAlphaNumeric(_name) || !isValidName(_name)) {
      if (Config.DEBUG)
        _log.fine(
            "Character Creation Failure: Character name "
                + _name
                + " is invalid. Message generated: Incorrect name. Please try again.");

      sendPacket(new CharCreateFail(CharCreateFail.REASON_INCORRECT_NAME));
      return;
    }

    if (_face > 2 || _face < 0) {
      _log.warning(
          "Character Creation Failure: Character face "
              + _face
              + " is invalid. Possible client hack. "
              + getClient());

      sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
      return;
    }

    if (_hairStyle < 0 || (_sex == 0 && _hairStyle > 4) || (_sex != 0 && _hairStyle > 6)) {
      _log.warning(
          "Character Creation Failure: Character hair style "
              + _hairStyle
              + " is invalid. Possible client hack. "
              + getClient());

      sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
      return;
    }

    if (_hairColor > 3 || _hairColor < 0) {
      _log.warning(
          "Character Creation Failure: Character hair color "
              + _hairColor
              + " is invalid. Possible client hack. "
              + getClient());

      sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
      return;
    }

    L2PcInstance newChar = null;
    L2PcTemplate template = null;

    /*
     * DrHouse: Since checks for duplicate names are done using SQL, lock must be held until data is written to DB as well.
     */
    synchronized (CharNameTable.getInstance()) {
      if (CharNameTable.getInstance().accountCharNumber(getClient().getAccountName())
              >= Config.MAX_CHARACTERS_NUMBER_PER_ACCOUNT
          && Config.MAX_CHARACTERS_NUMBER_PER_ACCOUNT != 0) {
        if (Config.DEBUG) _log.fine("Max number of characters reached. Creation failed.");

        sendPacket(new CharCreateFail(CharCreateFail.REASON_TOO_MANY_CHARACTERS));
        return;
      } else if (CharNameTable.getInstance().doesCharNameExist(_name)) {
        if (Config.DEBUG)
          _log.fine(
              "Character Creation Failure: Message generated: You cannot create another character. Please delete the existing character and try again.");

        sendPacket(new CharCreateFail(CharCreateFail.REASON_NAME_ALREADY_EXISTS));
        return;
      }

      template = CharTemplateTable.getInstance().getTemplate(_classId);

      if (template == null || template.classBaseLevel > 1) {
        if (Config.DEBUG)
          _log.fine(
              "Character Creation Failure: "
                  + _name
                  + " classId: "
                  + _classId
                  + " Template: "
                  + template
                  + " Message generated: Your character creation has failed.");

        sendPacket(new CharCreateFail(CharCreateFail.REASON_CREATION_FAILED));
        return;
      }

      int objectId = IdFactory.getInstance().getNextId();
      newChar =
          L2PcInstance.create(
              objectId,
              template,
              getClient().getAccountName(),
              _name,
              _hairStyle,
              _hairColor,
              _face,
              _sex != 0);
    }

    newChar.setCurrentHp(template.baseHpMax);
    newChar.setCurrentCp(template.baseCpMax);
    newChar.setCurrentMp(template.baseMpMax);
    // newChar.setMaxLoad(template.baseLoad);

    CharCreateOk cco = new CharCreateOk();
    sendPacket(cco);

    initNewChar(getClient(), newChar);

    LogRecord record = new LogRecord(Level.INFO, "Created new character");
    record.setParameters(new Object[] {newChar, this.getClient()});
    _logAccounting.log(record);
  }