コード例 #1
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
 private void initNpcs() {
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       PreparedStatement ps =
           con.prepareStatement(
               "SELECT * FROM fort_spawnlist WHERE fortId = ? AND spawnType = ?")) {
     ps.setInt(1, getResidenceId());
     ps.setInt(2, 0);
     try (ResultSet rs = ps.executeQuery()) {
       while (rs.next()) {
         L2Spawn spawnDat = new L2Spawn(rs.getInt("npcId"));
         spawnDat.setAmount(1);
         spawnDat.setX(rs.getInt("x"));
         spawnDat.setY(rs.getInt("y"));
         spawnDat.setZ(rs.getInt("z"));
         spawnDat.setHeading(rs.getInt("heading"));
         spawnDat.setRespawnDelay(60);
         SpawnTable.getInstance().addNewSpawn(spawnDat, false);
         spawnDat.doSpawn();
         spawnDat.startRespawn();
       }
     }
   } catch (Exception e) {
     _log.log(
         Level.WARNING,
         "Fort "
             + getResidenceId()
             + " initNpcs: Spawn could not be initialized: "
             + e.getMessage(),
         e);
   }
 }
コード例 #2
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
 private void initNpcCommanders() {
   _npcCommanders.clear();
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       PreparedStatement ps =
           con.prepareStatement(
               "SELECT id, npcId, x, y, z, heading FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ORDER BY id")) {
     ps.setInt(1, getResidenceId());
     ps.setInt(2, 1);
     try (ResultSet rs = ps.executeQuery()) {
       while (rs.next()) {
         final L2Spawn spawnDat = new L2Spawn(rs.getInt("npcId"));
         spawnDat.setAmount(1);
         spawnDat.setX(rs.getInt("x"));
         spawnDat.setY(rs.getInt("y"));
         spawnDat.setZ(rs.getInt("z"));
         spawnDat.setHeading(rs.getInt("heading"));
         spawnDat.setRespawnDelay(60);
         _npcCommanders.add(spawnDat);
       }
     }
   } catch (Exception e) {
     // problem with initializing spawn, go to next one
     _log.log(
         Level.WARNING,
         "Fort "
             + getResidenceId()
             + " initNpcCommanders: Spawn could not be initialized: "
             + e.getMessage(),
         e);
   }
 }
コード例 #3
0
  public void load() {
    _skillTrees.clear();
    int count = 0;
    try (Connection con = ConnectionFactory.getInstance().getConnection();
        Statement s = con.createStatement();
        ResultSet rs =
            s.executeQuery("SELECT templateId, minLvl, skillId, skillLvl FROM pets_skills")) {
      while (rs.next()) {
        final int npcId = rs.getInt("templateId");
        Map<Integer, L2PetSkillLearn> skillTree = _skillTrees.get(npcId);
        if (skillTree == null) {
          skillTree = new HashMap<>();
          _skillTrees.put(npcId, skillTree);
        }

        int id = rs.getInt("skillId");
        int lvl = rs.getInt("skillLvl");
        skillTree.put(
            SkillData.getSkillHashCode(id, lvl + 1),
            new L2PetSkillLearn(id, lvl, rs.getInt("minLvl")));
        count++;
      }
    } catch (Exception e) {
      LOGGER.log(
          Level.SEVERE, getClass().getSimpleName() + ": Error while loading pet skill tree:", e);
    }
    LOGGER.info(getClass().getSimpleName() + ": Loaded " + count + " skills.");
  }
コード例 #4
0
ファイル: L2ContactList.java プロジェクト: ailian8415/l2mx
  public void restore() {
    _contacts.clear();

    try (Connection con = ConnectionFactory.getInstance().getConnection();
        PreparedStatement ps = con.prepareStatement(QUERY_LOAD)) {
      ps.setInt(1, activeChar.getObjectId());
      try (ResultSet rs = ps.executeQuery()) {
        int contactId;
        String contactName;
        while (rs.next()) {
          contactId = rs.getInt(1);
          contactName = CharNameTable.getInstance().getNameById(contactId);
          if ((contactName == null)
              || contactName.equals(activeChar.getName())
              || (contactId == activeChar.getObjectId())) {
            continue;
          }

          _contacts.add(contactName);
        }
      }
    } catch (Exception e) {
      _log.log(
          Level.WARNING,
          "Error found in " + activeChar.getName() + "'s ContactsList: " + e.getMessage(),
          e);
    }
  }
コード例 #5
0
ファイル: L2ContactList.java プロジェクト: ailian8415/l2mx
  public void remove(String name) {
    int contactId = CharNameTable.getInstance().getIdByName(name);

    if (!_contacts.contains(name)) {
      activeChar.sendPacket(SystemMessageId.NAME_NOT_REGISTERED_ON_CONTACT_LIST);
      return;
    } else if (contactId < 1) {
      // TODO: Message?
      return;
    }

    _contacts.remove(name);

    try (Connection con = ConnectionFactory.getInstance().getConnection();
        PreparedStatement ps = con.prepareStatement(QUERY_REMOVE)) {
      ps.setInt(1, activeChar.getObjectId());
      ps.setInt(2, contactId);
      ps.execute();

      SystemMessage sm =
          SystemMessage.getSystemMessage(SystemMessageId.S1_SUCCESFULLY_DELETED_FROM_CONTACT_LIST);
      sm.addString(name);
      activeChar.sendPacket(sm);
    } catch (Exception e) {
      _log.log(
          Level.WARNING,
          "Error found in " + activeChar.getName() + "'s ContactsList: " + e.getMessage(),
          e);
    }
  }
コード例 #6
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
 public void saveFortVariables() {
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       PreparedStatement ps = con.prepareStatement("UPDATE fort SET supplyLvL=? WHERE id = ?")) {
     ps.setInt(1, _supplyLvL);
     ps.setInt(2, getResidenceId());
     ps.execute();
   } catch (Exception e) {
     _log.log(Level.WARNING, "Exception: saveFortVariables(): " + e.getMessage(), e);
   }
 }
コード例 #7
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
 private void removeDoorUpgrade() {
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       PreparedStatement ps =
           con.prepareStatement("DELETE FROM fort_doorupgrade WHERE fortId = ?")) {
     ps.setInt(1, getResidenceId());
     ps.execute();
   } catch (Exception e) {
     _log.log(Level.WARNING, "Exception: removeDoorUpgrade(): " + e.getMessage(), e);
   }
 }
コード例 #8
0
 private final void load() {
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       Statement ps = con.createStatement();
       ResultSet rs = ps.executeQuery("SELECT id FROM mods_wedding ORDER BY id")) {
     while (rs.next()) {
       getCouples().add(new Couple(rs.getInt("id")));
     }
     _log.info(getClass().getSimpleName() + ": Loaded: " + getCouples().size() + " couples(s)");
   } catch (Exception e) {
     _log.log(Level.SEVERE, "Exception: CoupleManager.load(): " + e.getMessage(), e);
   }
 }
コード例 #9
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
 /**
  * Remove function In List and in DB
  *
  * @param functionType
  */
 public void removeFunction(int functionType) {
   _function.remove(functionType);
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       PreparedStatement ps =
           con.prepareStatement("DELETE FROM fort_functions WHERE fort_id=? AND type=?")) {
     ps.setInt(1, getResidenceId());
     ps.setInt(2, functionType);
     ps.execute();
   } catch (Exception e) {
     _log.log(
         Level.SEVERE, "Exception: Fort.removeFunctions(int functionType): " + e.getMessage(), e);
   }
 }
コード例 #10
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
 // This method loads fort door upgrade data from database
 private void loadDoorUpgrade() {
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       PreparedStatement ps =
           con.prepareStatement("SELECT * FROM fort_doorupgrade WHERE fortId = ?")) {
     ps.setInt(1, getResidenceId());
     try (ResultSet rs = ps.executeQuery()) {
       while (rs.next()) {
         upgradeDoor(rs.getInt("id"), rs.getInt("hp"), rs.getInt("pDef"), rs.getInt("mDef"));
       }
     }
   } catch (Exception e) {
     _log.log(Level.WARNING, "Exception: loadFortDoorUpgrade(): " + e.getMessage(), e);
   }
 }
コード例 #11
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
 /**
  * @param state
  *     <ul>
  *       <li>0 - not decided yet
  *       <li>1 - independent
  *       <li>2 - contracted with castle
  *     </ul>
  *
  * @param castleId the Id of the contracted castle (0 if no contract with any castle)
  */
 public final void setFortState(int state, int castleId) {
   _state = state;
   _castleId = castleId;
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       PreparedStatement ps =
           con.prepareStatement("UPDATE fort SET state=?,castleId=? WHERE id = ?")) {
     ps.setInt(1, getFortState());
     ps.setInt(2, getContractedCastleId());
     ps.setInt(3, getResidenceId());
     ps.execute();
   } catch (Exception e) {
     _log.log(
         Level.WARNING, "Exception: setFortState(int state, int castleId): " + e.getMessage(), e);
   }
 }
コード例 #12
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
 private void saveDoorUpgrade(int doorId, int hp, int pDef, int mDef) {
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       PreparedStatement ps =
           con.prepareStatement(
               "INSERT INTO fort_doorupgrade (doorId, hp, pDef, mDef) VALUES (?,?,?,?)")) {
     ps.setInt(1, doorId);
     ps.setInt(2, hp);
     ps.setInt(3, pDef);
     ps.setInt(4, mDef);
     ps.execute();
   } catch (Exception e) {
     _log.log(
         Level.WARNING,
         "Exception: saveDoorUpgrade(int doorId, int hp, int pDef, int mDef): " + e.getMessage(),
         e);
   }
 }
コード例 #13
0
ファイル: L2ContactList.java プロジェクト: ailian8415/l2mx
  public boolean add(String name) {
    SystemMessage sm;

    int contactId = CharNameTable.getInstance().getIdByName(name);
    if (_contacts.contains(name)) {
      activeChar.sendPacket(SystemMessageId.NAME_ALREADY_EXIST_ON_CONTACT_LIST);
      return false;
    } else if (activeChar.getName().equals(name)) {
      activeChar.sendPacket(SystemMessageId.CANNOT_ADD_YOUR_NAME_ON_CONTACT_LIST);
      return false;
    } else if (_contacts.size() >= 100) {
      activeChar.sendPacket(SystemMessageId.CONTACT_LIST_LIMIT_REACHED);
      return false;
    } else if (contactId < 1) {
      sm = SystemMessage.getSystemMessage(SystemMessageId.NAME_S1_NOT_EXIST_TRY_ANOTHER_NAME);
      sm.addString(name);
      activeChar.sendPacket(sm);
      return false;
    } else {
      for (String contactName : _contacts) {
        if (contactName.equalsIgnoreCase(name)) {
          activeChar.sendPacket(SystemMessageId.NAME_ALREADY_EXIST_ON_CONTACT_LIST);
          return false;
        }
      }
    }

    try (Connection con = ConnectionFactory.getInstance().getConnection();
        PreparedStatement ps = con.prepareStatement(QUERY_ADD)) {
      ps.setInt(1, activeChar.getObjectId());
      ps.setInt(2, contactId);
      ps.execute();

      _contacts.add(name);

      sm = SystemMessage.getSystemMessage(SystemMessageId.S1_SUCCESSFULLY_ADDED_TO_CONTACT_LIST);
      sm.addString(name);
      activeChar.sendPacket(sm);
    } catch (Exception e) {
      _log.log(
          Level.WARNING,
          "Error found in " + activeChar.getName() + "'s ContactsList: " + e.getMessage(),
          e);
    }
    return true;
  }
コード例 #14
0
  @Override
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    String[] parts = command.split(" ");
    if (parts.length == 2) {
      try {
        int lvl = Integer.parseInt(parts[1]);
        if (activeChar.getTarget() instanceof L2PcInstance) {
          onlineChange(activeChar, (L2PcInstance) activeChar.getTarget(), lvl);
        } else {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
        }
      } catch (Exception e) {
        activeChar.sendMessage("Usage: //changelvl <target_new_level> | <player_name> <new_level>");
      }
    } else if (parts.length == 3) {
      String name = parts[1];
      int lvl = Integer.parseInt(parts[2]);
      L2PcInstance player = L2World.getInstance().getPlayer(name);
      if (player != null) {
        onlineChange(activeChar, player, lvl);
      } else {
        try (Connection con = ConnectionFactory.getInstance().getConnection();
            PreparedStatement ps =
                con.prepareStatement("UPDATE characters SET accesslevel=? WHERE char_name=?")) {
          ps.setInt(1, lvl);
          ps.setString(2, name);
          ps.execute();

          if (ps.getUpdateCount() == 0) {
            activeChar.sendMessage("角色不在线或者权限等级没有变化.");
          } else {
            activeChar.sendMessage("将角色的权限等级谁定为 " + lvl);
          }
        } catch (SQLException se) {
          activeChar.sendMessage("角色权限等级变化时SQL异常");
          if (Config.DEBUG) {
            se.printStackTrace();
          }
        }
      }
    }
    return true;
  }
コード例 #15
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
 public void dbSave() {
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       PreparedStatement ps =
           con.prepareStatement(
               "REPLACE INTO fort_functions (fort_id, type, lvl, lease, rate, endTime) VALUES (?,?,?,?,?,?)")) {
     ps.setInt(1, getResidenceId());
     ps.setInt(2, getType());
     ps.setInt(3, getLvl());
     ps.setInt(4, getLease());
     ps.setLong(5, getRate());
     ps.setLong(6, getEndTime());
     ps.execute();
   } catch (Exception e) {
     _log.log(
         Level.SEVERE,
         "Exception: Fort.updateFunctions(int type, int lvl, int lease, long rate, long time, boolean addNew): "
             + e.getMessage(),
         e);
   }
 }
コード例 #16
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
 /** Load All Functions */
 private void loadFunctions() {
   try (Connection con = ConnectionFactory.getInstance().getConnection();
       PreparedStatement ps =
           con.prepareStatement("SELECT * FROM fort_functions WHERE fort_id = ?")) {
     ps.setInt(1, getResidenceId());
     try (ResultSet rs = ps.executeQuery()) {
       while (rs.next()) {
         _function.put(
             rs.getInt("type"),
             new FortFunction(
                 rs.getInt("type"),
                 rs.getInt("lvl"),
                 rs.getInt("lease"),
                 0,
                 rs.getLong("rate"),
                 rs.getLong("endTime"),
                 true));
       }
     }
   } catch (Exception e) {
     _log.log(Level.SEVERE, "Exception: Fort.loadFunctions(): " + e.getMessage(), e);
   }
 }
コード例 #17
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
  private void updateOwnerInDB() {
    L2Clan clan = getOwnerClan();
    int clanId = 0;
    if (clan != null) {
      clanId = clan.getId();
      _lastOwnedTime.setTimeInMillis(System.currentTimeMillis());
    } else {
      _lastOwnedTime.setTimeInMillis(0);
    }

    try (Connection con = ConnectionFactory.getInstance().getConnection();
        PreparedStatement ps =
            con.prepareStatement(
                "UPDATE fort SET owner=?,lastOwnedTime=?,state=?,castleId=? WHERE id = ?")) {
      ps.setInt(1, clanId);
      ps.setLong(2, _lastOwnedTime.getTimeInMillis());
      ps.setInt(3, 0);
      ps.setInt(4, 0);
      ps.setInt(5, getResidenceId());
      ps.execute();

      // Announce to clan members
      if (clan != null) {
        clan.setFortId(getResidenceId()); // Set has fort flag for new owner
        SystemMessage sm;
        sm =
            SystemMessage.getSystemMessage(
                SystemMessageId.S1_IS_VICTORIOUS_IN_THE_FORTRESS_BATTLE_OF_S2);
        sm.addString(clan.getName());
        sm.addCastleId(getResidenceId());
        L2World.getInstance().getPlayers().forEach(p -> p.sendPacket(sm));
        clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
        clan.broadcastToOnlineMembers(new PlaySound(1, "Siege_Victory", 0, 0, 0, 0, 0));
        if (_FortUpdater[0] != null) {
          _FortUpdater[0].cancel(false);
        }
        if (_FortUpdater[1] != null) {
          _FortUpdater[1].cancel(false);
        }
        _FortUpdater[0] =
            ThreadPoolManager.getInstance()
                .scheduleGeneralAtFixedRate(
                    new FortUpdater(this, clan, 0, UpdaterType.PERIODIC_UPDATE),
                    Config.FS_UPDATE_FRQ * 60000L,
                    Config.FS_UPDATE_FRQ * 60000L); // Schedule owner tasks to start running
        if (Config.FS_MAX_OWN_TIME > 0) {
          _FortUpdater[1] =
              ThreadPoolManager.getInstance()
                  .scheduleGeneralAtFixedRate(
                      new FortUpdater(this, clan, 0, UpdaterType.MAX_OWN_TIME),
                      3600000,
                      3600000); // Schedule owner tasks to remove owener
        }
      } else {
        if (_FortUpdater[0] != null) {
          _FortUpdater[0].cancel(false);
        }
        _FortUpdater[0] = null;
        if (_FortUpdater[1] != null) {
          _FortUpdater[1].cancel(false);
        }
        _FortUpdater[1] = null;
      }
    } catch (Exception e) {
      _log.log(Level.WARNING, "Exception: updateOwnerInDB(L2Clan clan): " + e.getMessage(), e);
    }
  }
コード例 #18
0
ファイル: Fort.java プロジェクト: 3mRe/L2Java
  // This method loads fort
  @Override
  protected void load() {
    try (Connection con = ConnectionFactory.getInstance().getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT * FROM fort WHERE id = ?")) {
      ps.setInt(1, getResidenceId());
      int ownerId = 0;
      try (ResultSet rs = ps.executeQuery()) {
        while (rs.next()) {
          setName(rs.getString("name"));

          _siegeDate = Calendar.getInstance();
          _lastOwnedTime = Calendar.getInstance();
          _siegeDate.setTimeInMillis(rs.getLong("siegeDate"));
          _lastOwnedTime.setTimeInMillis(rs.getLong("lastOwnedTime"));
          ownerId = rs.getInt("owner");
          _fortType = rs.getInt("fortType");
          _state = rs.getInt("state");
          _castleId = rs.getInt("castleId");
          _supplyLvL = rs.getInt("supplyLvL");
        }
      }
      if (ownerId > 0) {
        L2Clan clan = ClanTable.getInstance().getClan(ownerId); // Try to find clan instance
        clan.setFortId(getResidenceId());
        setOwnerClan(clan);
        int runCount = getOwnedTime() / (Config.FS_UPDATE_FRQ * 60);
        long initial = System.currentTimeMillis() - _lastOwnedTime.getTimeInMillis();
        while (initial > (Config.FS_UPDATE_FRQ * 60000L)) {
          initial -= (Config.FS_UPDATE_FRQ * 60000L);
        }
        initial = (Config.FS_UPDATE_FRQ * 60000L) - initial;
        if ((Config.FS_MAX_OWN_TIME <= 0) || (getOwnedTime() < (Config.FS_MAX_OWN_TIME * 3600))) {
          _FortUpdater[0] =
              ThreadPoolManager.getInstance()
                  .scheduleGeneralAtFixedRate(
                      new FortUpdater(this, clan, runCount, UpdaterType.PERIODIC_UPDATE),
                      initial,
                      Config.FS_UPDATE_FRQ * 60000L); // Schedule owner tasks to start running
          if (Config.FS_MAX_OWN_TIME > 0) {
            _FortUpdater[1] =
                ThreadPoolManager.getInstance()
                    .scheduleGeneralAtFixedRate(
                        new FortUpdater(this, clan, runCount, UpdaterType.MAX_OWN_TIME),
                        3600000,
                        3600000); // Schedule owner tasks to remove owener
          }
        } else {
          _FortUpdater[1] =
              ThreadPoolManager.getInstance()
                  .scheduleGeneral(
                      new FortUpdater(this, clan, 0, UpdaterType.MAX_OWN_TIME),
                      60000); // Schedule owner tasks to remove owner
        }
      } else {
        setOwnerClan(null);
      }

    } catch (Exception e) {
      _log.log(Level.WARNING, "Exception: loadFortData(): " + e.getMessage(), e);
    }
  }