public void removeOwner(boolean updateDB) { L2Clan clan = getOwnerClan(); if (clan != null) { for (L2PcInstance member : clan.getOnlineMembers(0)) { removeResidentialSkills(member); member.sendSkillList(); } clan.setFortId(0); clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan)); setOwnerClan(null); setSupplyLvL(0); saveFortVariables(); removeAllFunctions(); if (updateDB) { updateOwnerInDB(); } } }
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); } }
// 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); } }