Fort.java 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model.entity;
  16. import gnu.trove.TIntIntHashMap;
  17. import java.sql.Connection;
  18. import java.sql.PreparedStatement;
  19. import java.sql.ResultSet;
  20. import java.util.Calendar;
  21. import java.util.Collection;
  22. import java.util.List;
  23. import java.util.concurrent.ScheduledFuture;
  24. import java.util.logging.Level;
  25. import java.util.logging.Logger;
  26. import com.l2jserver.Config;
  27. import com.l2jserver.L2DatabaseFactory;
  28. import com.l2jserver.gameserver.FortUpdater;
  29. import com.l2jserver.gameserver.ThreadPoolManager;
  30. import com.l2jserver.gameserver.datatables.ClanTable;
  31. import com.l2jserver.gameserver.datatables.DoorTable;
  32. import com.l2jserver.gameserver.datatables.NpcTable;
  33. import com.l2jserver.gameserver.datatables.ResidentialSkillTable;
  34. import com.l2jserver.gameserver.datatables.SpawnTable;
  35. import com.l2jserver.gameserver.datatables.StaticObjects;
  36. import com.l2jserver.gameserver.instancemanager.FortManager;
  37. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  38. import com.l2jserver.gameserver.model.L2Clan;
  39. import com.l2jserver.gameserver.model.L2Object;
  40. import com.l2jserver.gameserver.model.L2Skill;
  41. import com.l2jserver.gameserver.model.L2Spawn;
  42. import com.l2jserver.gameserver.model.L2World;
  43. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  44. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  45. import com.l2jserver.gameserver.model.actor.instance.L2StaticObjectInstance;
  46. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  47. import com.l2jserver.gameserver.model.zone.type.L2FortZone;
  48. import com.l2jserver.gameserver.network.SystemMessageId;
  49. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  50. import com.l2jserver.gameserver.network.serverpackets.PledgeShowInfoUpdate;
  51. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  52. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  53. import javolution.util.FastList;
  54. import javolution.util.FastMap;
  55. public class Fort
  56. {
  57. protected static final Logger _log = Logger.getLogger(Fort.class.getName());
  58. // =========================================================
  59. // Data Field
  60. private int _fortId = 0;
  61. private List<L2DoorInstance> _doors = new FastList<L2DoorInstance>();
  62. private L2StaticObjectInstance _flagPole = null;
  63. private List<String> _doorDefault = new FastList<String>();
  64. private List<String> _flagPoleStats = new FastList<String>();
  65. private String _name = "";
  66. private FortSiege _siege = null;
  67. private Calendar _siegeDate;
  68. private Calendar _lastOwnedTime;
  69. private L2FortZone _zone;
  70. private L2Clan _fortOwner = null;
  71. private int _fortType = 0;
  72. private int _state = 0;
  73. private int _castleId = 0;
  74. private int _blood = 0;
  75. private FastMap<Integer, FortFunction> _function;
  76. private FastList<L2Skill> _residentialSkills = new FastList<L2Skill>();
  77. private ScheduledFuture<?> _FortUpdater;
  78. // Spawn Data
  79. private boolean _isSuspiciousMerchantSpawned = false;
  80. private FastList<L2Spawn> _siegeNpcs = new FastList<L2Spawn>();
  81. private FastList<L2Spawn> _npcCommanders = new FastList<L2Spawn>();
  82. private FastList<L2Spawn> _specialEnvoys = new FastList<L2Spawn>();
  83. private TIntIntHashMap _envoyCastles = new TIntIntHashMap(2);
  84. /** Fortress Functions */
  85. public static final int FUNC_TELEPORT = 1;
  86. public static final int FUNC_RESTORE_HP = 2;
  87. public static final int FUNC_RESTORE_MP = 3;
  88. public static final int FUNC_RESTORE_EXP = 4;
  89. public static final int FUNC_SUPPORT = 5;
  90. public class FortFunction
  91. {
  92. private int _type;
  93. private int _lvl;
  94. protected int _fee;
  95. protected int _tempFee;
  96. private long _rate;
  97. private long _endDate;
  98. protected boolean _inDebt;
  99. public boolean _cwh;
  100. public FortFunction(int type, int lvl, int lease, int tempLease, long rate, long time, boolean cwh)
  101. {
  102. _type = type;
  103. _lvl = lvl;
  104. _fee = lease;
  105. _tempFee = tempLease;
  106. _rate = rate;
  107. _endDate = time;
  108. initializeTask(cwh);
  109. }
  110. public int getType()
  111. {
  112. return _type;
  113. }
  114. public int getLvl()
  115. {
  116. return _lvl;
  117. }
  118. public int getLease()
  119. {
  120. return _fee;
  121. }
  122. public long getRate()
  123. {
  124. return _rate;
  125. }
  126. public long getEndTime()
  127. {
  128. return _endDate;
  129. }
  130. public void setLvl(int lvl)
  131. {
  132. _lvl = lvl;
  133. }
  134. public void setLease(int lease)
  135. {
  136. _fee = lease;
  137. }
  138. public void setEndTime(long time)
  139. {
  140. _endDate = time;
  141. }
  142. private void initializeTask(boolean cwh)
  143. {
  144. if (getOwnerClan() == null)
  145. return;
  146. long currentTime = System.currentTimeMillis();
  147. if (_endDate > currentTime)
  148. ThreadPoolManager.getInstance().scheduleGeneral(new FunctionTask(cwh), _endDate - currentTime);
  149. else
  150. ThreadPoolManager.getInstance().scheduleGeneral(new FunctionTask(cwh), 0);
  151. }
  152. private class FunctionTask implements Runnable
  153. {
  154. public FunctionTask(boolean cwh)
  155. {
  156. _cwh = cwh;
  157. }
  158. public void run()
  159. {
  160. try
  161. {
  162. if (getOwnerClan() == null)
  163. return;
  164. if (getOwnerClan().getWarehouse().getAdena() >= _fee || !_cwh)
  165. {
  166. int fee = _fee;
  167. if (getEndTime() == -1)
  168. fee = _tempFee;
  169. setEndTime(System.currentTimeMillis() + getRate());
  170. dbSave();
  171. if (_cwh)
  172. {
  173. getOwnerClan().getWarehouse().destroyItemByItemId("CS_function_fee", 57, fee, null, null);
  174. if (Config.DEBUG)
  175. _log.warning("Deducted " + fee + " adena from " + getName() + " owner's cwh for function id : " + getType());
  176. }
  177. ThreadPoolManager.getInstance().scheduleGeneral(new FunctionTask(true), getRate());
  178. }
  179. else
  180. removeFunction(getType());
  181. }
  182. catch (Throwable t)
  183. {
  184. }
  185. }
  186. }
  187. public void dbSave()
  188. {
  189. Connection con = null;
  190. try
  191. {
  192. PreparedStatement statement;
  193. con = L2DatabaseFactory.getInstance().getConnection();
  194. statement = con.prepareStatement("REPLACE INTO fort_functions (fort_id, type, lvl, lease, rate, endTime) VALUES (?,?,?,?,?,?)");
  195. statement.setInt(1, getFortId());
  196. statement.setInt(2, getType());
  197. statement.setInt(3, getLvl());
  198. statement.setInt(4, getLease());
  199. statement.setLong(5, getRate());
  200. statement.setLong(6, getEndTime());
  201. statement.execute();
  202. statement.close();
  203. }
  204. catch (Exception e)
  205. {
  206. _log.log(Level.SEVERE, "Exception: Fort.updateFunctions(int type, int lvl, int lease, long rate, long time, boolean addNew): " + e.getMessage(), e);
  207. }
  208. finally
  209. {
  210. L2DatabaseFactory.close(con);
  211. }
  212. }
  213. }
  214. // =========================================================
  215. // Constructor
  216. public Fort(int fortId)
  217. {
  218. _fortId = fortId;
  219. load();
  220. loadDoor();
  221. loadFlagPoles();
  222. _function = new FastMap<Integer, FortFunction>();
  223. _residentialSkills = ResidentialSkillTable.getInstance().getSkills(fortId);
  224. if (getOwnerClan() != null)
  225. {
  226. setVisibleFlag(true);
  227. loadFunctions();
  228. }
  229. initNpcs(); // load and spawn npcs (Always spawned)
  230. initSiegeNpcs(); // load suspicious merchants (Despawned 10mins before siege)
  231. //spawnSuspiciousMerchant();// spawn suspicious merchants
  232. initNpcCommanders(); // npc Commanders (not monsters) (Spawned during siege)
  233. spawnNpcCommanders(); // spawn npc Commanders
  234. initSpecialEnvoys(); // envoys from castles (Spawned after fort taken)
  235. if (getOwnerClan() != null && getFortState() == 0)
  236. {
  237. spawnSpecialEnvoys();
  238. ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleSpecialEnvoysDeSpawn(this), 1 * 60 * 60 * 1000); // Prepare 1hr task for special envoys despawn
  239. }
  240. }
  241. /** Return function with id */
  242. public FortFunction getFunction(int type)
  243. {
  244. if (_function.get(type) != null)
  245. return _function.get(type);
  246. return null;
  247. }
  248. public class ScheduleSpecialEnvoysDeSpawn implements Runnable
  249. {
  250. private Fort _fortInst;
  251. public ScheduleSpecialEnvoysDeSpawn(Fort pFort)
  252. {
  253. _fortInst = pFort;
  254. }
  255. public void run()
  256. {
  257. try
  258. {
  259. // if state not decided, change state to indenpendent
  260. if (_fortInst.getFortState() == 0)
  261. _fortInst.setFortState(1, 0);
  262. _fortInst.despawnSpecialEnvoys();
  263. }
  264. catch (Exception e)
  265. {
  266. _log.log(Level.WARNING, "Exception: ScheduleSpecialEnvoysSpawn() for Fort " + _fortInst.getName() + ": " + e.getMessage(), e);
  267. }
  268. }
  269. }
  270. // =========================================================
  271. // Method - Public
  272. public void endOfSiege(L2Clan clan)
  273. {
  274. ThreadPoolManager.getInstance().scheduleGeneral(new endFortressSiege(this, clan), 1000);
  275. }
  276. public void engrave(L2Clan clan)
  277. {
  278. setOwner(clan, true);
  279. }
  280. /**
  281. * Move non clan members off fort area and to nearest town.<BR><BR>
  282. */
  283. public void banishForeigners()
  284. {
  285. getZone().banishForeigners(getOwnerClan());
  286. }
  287. /**
  288. * Return true if object is inside the zone
  289. */
  290. public boolean checkIfInZone(int x, int y, int z)
  291. {
  292. return getZone().isInsideZone(x, y, z);
  293. }
  294. public L2FortZone getZone()
  295. {
  296. if (_zone == null)
  297. {
  298. for (L2ZoneType zone : ZoneManager.getInstance().getAllZones())
  299. {
  300. if (zone instanceof L2FortZone && ((L2FortZone) zone).getFortId() == getFortId())
  301. {
  302. _zone = (L2FortZone) zone;
  303. break;
  304. }
  305. }
  306. }
  307. return _zone;
  308. }
  309. /**
  310. * Get the objects distance to this fort
  311. * @param object
  312. * @return
  313. */
  314. public double getDistance(L2Object obj)
  315. {
  316. return getZone().getDistanceToZone(obj);
  317. }
  318. public void closeDoor(L2PcInstance activeChar, int doorId)
  319. {
  320. openCloseDoor(activeChar, doorId, false);
  321. }
  322. public void openDoor(L2PcInstance activeChar, int doorId)
  323. {
  324. openCloseDoor(activeChar, doorId, true);
  325. }
  326. public void openCloseDoor(L2PcInstance activeChar, int doorId, boolean open)
  327. {
  328. if (activeChar.getClan() != getOwnerClan())
  329. return;
  330. L2DoorInstance door = getDoor(doorId);
  331. if (door != null)
  332. {
  333. if (open)
  334. door.openMe();
  335. else
  336. door.closeMe();
  337. }
  338. }
  339. // This method is used to begin removing all fort upgrades
  340. public void removeUpgrade()
  341. {
  342. removeDoorUpgrade();
  343. }
  344. /**
  345. * This method will set owner for Fort
  346. * @param clan
  347. * @param updateClanPoints
  348. */
  349. public boolean setOwner(L2Clan clan, boolean updateClansReputation)
  350. {
  351. L2Clan oldowner = getOwnerClan();
  352. // Remove old owner
  353. if (oldowner != null && clan != null && clan != oldowner)
  354. {
  355. // Remove points from old owner
  356. updateClansReputation(oldowner, true);
  357. try
  358. {
  359. L2PcInstance oldleader = oldowner.getLeader().getPlayerInstance();
  360. if (oldleader != null)
  361. {
  362. if (oldleader.getMountType() == 2)
  363. oldleader.dismount();
  364. }
  365. }
  366. catch (Exception e)
  367. {
  368. _log.log(Level.WARNING, "Exception in setOwner: " + e.getMessage(), e);
  369. }
  370. removeOwner(true);
  371. }
  372. setFortState(0, 0); // initialize fort state
  373. // if clan already have castle, don't store him in fortress
  374. if (clan.getHasCastle() > 0)
  375. {
  376. getSiege().announceToPlayer(new SystemMessage(SystemMessageId.NPCS_RECAPTURED_FORTRESS));
  377. return false;
  378. }
  379. else
  380. {
  381. // Give points to new owner
  382. if (updateClansReputation)
  383. updateClansReputation(clan, false);
  384. spawnSpecialEnvoys();
  385. ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleSpecialEnvoysDeSpawn(this), 1 * 60 * 60 * 1000); // Prepare 1hr task for special envoys despawn
  386. // if clan have already fortress, remove it
  387. if (clan.getHasFort() > 0)
  388. FortManager.getInstance().getFortByOwner(clan).removeOwner(true);
  389. setBloodOathReward(0);
  390. setOwnerClan(clan);
  391. updateOwnerInDB(); // Update in database
  392. if (getSiege().getIsInProgress()) // If siege in progress
  393. getSiege().endSiege();
  394. for (L2PcInstance member : clan.getOnlineMembers(0))
  395. {
  396. giveResidentialSkills(member);
  397. member.sendSkillList();
  398. }
  399. return true;
  400. }
  401. }
  402. public void removeOwner(boolean updateDB)
  403. {
  404. L2Clan clan = getOwnerClan();
  405. if (clan != null)
  406. {
  407. for (L2PcInstance member : clan.getOnlineMembers(0))
  408. {
  409. removeResidentialSkills(member);
  410. member.sendSkillList();
  411. }
  412. clan.setHasFort(0);
  413. clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
  414. setOwnerClan(null);
  415. setBloodOathReward(0);
  416. if (updateDB)
  417. updateOwnerInDB();
  418. }
  419. }
  420. public void setBloodOathReward(int val)
  421. {
  422. _blood = val;
  423. Connection con = null;
  424. try
  425. {
  426. con = L2DatabaseFactory.getInstance().getConnection();
  427. PreparedStatement statement;
  428. statement = con.prepareStatement("UPDATE fort SET blood=? WHERE id = ?");
  429. statement.setInt(1, _blood);
  430. statement.setInt(2, getFortId());
  431. statement.execute();
  432. statement.close();
  433. }
  434. catch (Exception e)
  435. {
  436. _log.log(Level.WARNING, "Exception: setBloodOathReward(int val): " + e.getMessage(), e);
  437. }
  438. finally
  439. {
  440. L2DatabaseFactory.close(con);
  441. }
  442. }
  443. public int getBloodOathReward()
  444. {
  445. return _blood;
  446. }
  447. /**
  448. * Show or hide flag inside flagpole<BR><BR>
  449. */
  450. public void setVisibleFlag(boolean val)
  451. {
  452. L2StaticObjectInstance flagPole = getFlagPole();
  453. if (flagPole != null)
  454. flagPole.setMeshIndex(val ? 1 : 0);
  455. }
  456. /**
  457. * Respawn all doors on fort grounds<BR><BR>
  458. */
  459. public void resetDoors()
  460. {
  461. for (int i = 0; i < getDoors().size(); i++)
  462. {
  463. L2DoorInstance door = getDoors().get(i);
  464. if (door.getOpen())
  465. door.closeMe();
  466. if (door.getCurrentHp() <= 0)
  467. door.doRevive();
  468. if (door.getCurrentHp() < door.getMaxHp())
  469. door.setCurrentHp(door.getMaxHp());
  470. }
  471. loadDoorUpgrade(); // Check for any upgrade the doors may have
  472. }
  473. // This method upgrade door
  474. public void upgradeDoor(int doorId, int hp, int pDef, int mDef)
  475. {
  476. L2DoorInstance door = getDoor(doorId);
  477. if (door != null && door.getDoorId() == doorId)
  478. {
  479. door.setCurrentHp(door.getMaxHp() + hp);
  480. saveDoorUpgrade(doorId, hp, pDef, mDef);
  481. return;
  482. }
  483. }
  484. // =========================================================
  485. // Method - Private
  486. // This method loads fort
  487. private void load()
  488. {
  489. Connection con = null;
  490. try
  491. {
  492. PreparedStatement statement;
  493. ResultSet rs;
  494. con = L2DatabaseFactory.getInstance().getConnection();
  495. statement = con.prepareStatement("SELECT * FROM fort WHERE id = ?");
  496. statement.setInt(1, getFortId());
  497. rs = statement.executeQuery();
  498. int ownerId = 0;
  499. while (rs.next())
  500. {
  501. _name = rs.getString("name");
  502. _siegeDate = Calendar.getInstance();
  503. _lastOwnedTime = Calendar.getInstance();
  504. _siegeDate.setTimeInMillis(rs.getLong("siegeDate"));
  505. _lastOwnedTime.setTimeInMillis(rs.getLong("lastOwnedTime"));
  506. ownerId = rs.getInt("owner");
  507. _fortType = rs.getInt("fortType");
  508. _state = rs.getInt("state");
  509. _castleId = rs.getInt("castleId");
  510. _blood = rs.getInt("blood");
  511. }
  512. rs.close();
  513. statement.close();
  514. if (ownerId > 0)
  515. {
  516. L2Clan clan = ClanTable.getInstance().getClan(ownerId); // Try to find clan instance
  517. clan.setHasFort(getFortId());
  518. setOwnerClan(clan);
  519. int runCount = getOwnedTime() / (Config.FS_BLOOD_OATH_FRQ * 60);
  520. long initial = System.currentTimeMillis() - _lastOwnedTime.getTimeInMillis();
  521. while (initial > (Config.FS_BLOOD_OATH_FRQ * 60000))
  522. initial -= (Config.FS_BLOOD_OATH_FRQ * 60000);
  523. initial = (Config.FS_BLOOD_OATH_FRQ * 60000) - initial;
  524. _FortUpdater = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new FortUpdater(this, clan, runCount), initial, Config.FS_BLOOD_OATH_FRQ * 60000); // Schedule owner tasks to start running
  525. }
  526. else
  527. setOwnerClan(null);
  528. }
  529. catch (Exception e)
  530. {
  531. _log.log(Level.WARNING, "Exception: loadFortData(): " + e.getMessage(), e);
  532. }
  533. finally
  534. {
  535. L2DatabaseFactory.close(con);
  536. }
  537. }
  538. /** Load All Functions */
  539. private void loadFunctions()
  540. {
  541. Connection con = null;
  542. try
  543. {
  544. PreparedStatement statement;
  545. ResultSet rs;
  546. con = L2DatabaseFactory.getInstance().getConnection();
  547. statement = con.prepareStatement("SELECT * FROM fort_functions WHERE fort_id = ?");
  548. statement.setInt(1, getFortId());
  549. rs = statement.executeQuery();
  550. while (rs.next())
  551. {
  552. _function.put(rs.getInt("type"), new FortFunction(rs.getInt("type"), rs.getInt("lvl"), rs.getInt("lease"), 0, rs.getLong("rate"), rs.getLong("endTime"), true));
  553. }
  554. statement.close();
  555. }
  556. catch (Exception e)
  557. {
  558. _log.log(Level.SEVERE, "Exception: Fort.loadFunctions(): " + e.getMessage(), e);
  559. }
  560. finally
  561. {
  562. L2DatabaseFactory.close(con);
  563. }
  564. }
  565. /** Remove function In List and in DB */
  566. public void removeFunction(int functionType)
  567. {
  568. _function.remove(functionType);
  569. Connection con = null;
  570. try
  571. {
  572. PreparedStatement statement;
  573. con = L2DatabaseFactory.getInstance().getConnection();
  574. statement = con.prepareStatement("DELETE FROM fort_functions WHERE fort_id=? AND type=?");
  575. statement.setInt(1, getFortId());
  576. statement.setInt(2, functionType);
  577. statement.execute();
  578. statement.close();
  579. }
  580. catch (Exception e)
  581. {
  582. _log.log(Level.SEVERE, "Exception: Fort.removeFunctions(int functionType): " + e.getMessage(), e);
  583. }
  584. finally
  585. {
  586. L2DatabaseFactory.close(con);
  587. }
  588. }
  589. public boolean updateFunctions(L2PcInstance player, int type, int lvl, int lease, long rate, boolean addNew)
  590. {
  591. if (player == null)
  592. return false;
  593. if (Config.DEBUG)
  594. _log.warning("Called Fort.updateFunctions(int type, int lvl, int lease, long rate, boolean addNew) Owner : " + getOwnerClan());
  595. if (lease > 0)
  596. if (!player.destroyItemByItemId("Consume", 57, lease, null, true))
  597. return false;
  598. if (addNew)
  599. {
  600. _function.put(type, new FortFunction(type, lvl, lease, 0, rate, 0, false));
  601. }
  602. else
  603. {
  604. if (lvl == 0 && lease == 0)
  605. removeFunction(type);
  606. else
  607. {
  608. int diffLease = lease - _function.get(type).getLease();
  609. if (Config.DEBUG)
  610. _log.warning("Called Fort.updateFunctions diffLease : " + diffLease);
  611. if (diffLease > 0)
  612. {
  613. _function.remove(type);
  614. _function.put(type, new FortFunction(type, lvl, lease, 0, rate, -1, false));
  615. }
  616. else
  617. {
  618. _function.get(type).setLease(lease);
  619. _function.get(type).setLvl(lvl);
  620. _function.get(type).dbSave();
  621. }
  622. }
  623. }
  624. return true;
  625. }
  626. public void activateInstance()
  627. {
  628. for (final L2DoorInstance door : _doors)
  629. {
  630. door.spawnMe(door.getX(), door.getY(), door.getZ());
  631. }
  632. }
  633. // This method loads fort door data from database
  634. private void loadDoor()
  635. {
  636. Connection con = null;
  637. try
  638. {
  639. con = L2DatabaseFactory.getInstance().getConnection();
  640. PreparedStatement statement = con.prepareStatement("SELECT * FROM fort_staticobjects WHERE fortId = ? AND objectType = ?");
  641. statement.setInt(1, getFortId());
  642. statement.setInt(2, 0);
  643. ResultSet rs = statement.executeQuery();
  644. while (rs.next())
  645. {
  646. // Create list of the door default for use when respawning dead doors
  647. _doorDefault.add(rs.getString("name") + ";" + rs.getInt("id") + ";" + rs.getInt("x") + ";" + rs.getInt("y") + ";"
  648. + rs.getInt("z") + ";" + rs.getInt("range_xmin") + ";" + rs.getInt("range_ymin") + ";" + rs.getInt("range_zmin")
  649. + ";" + rs.getInt("range_xmax") + ";" + rs.getInt("range_ymax") + ";" + rs.getInt("range_zmax") + ";"
  650. + rs.getInt("hp") + ";" + rs.getInt("pDef") + ";" + rs.getInt("mDef") + ";" + rs.getBoolean("openType") + ";"
  651. + rs.getBoolean("commanderDoor"));
  652. L2DoorInstance door;
  653. _doors.add(door = DoorTable.parseList(_doorDefault.get(_doorDefault.size() - 1), true));
  654. DoorTable.getInstance().putDoor(door);
  655. }
  656. rs.close();
  657. statement.close();
  658. }
  659. catch (Exception e)
  660. {
  661. _log.log(Level.WARNING, "Exception: loadFortDoor(): " + e.getMessage(), e);
  662. }
  663. finally
  664. {
  665. L2DatabaseFactory.close(con);
  666. }
  667. }
  668. // This method loads fort flagpoles data from database
  669. private void loadFlagPoles()
  670. {
  671. Connection con = null;
  672. try
  673. {
  674. con = L2DatabaseFactory.getInstance().getConnection();
  675. PreparedStatement statement = con.prepareStatement("SELECT * FROM fort_staticobjects WHERE fortId = ? AND objectType = ?");
  676. statement.setInt(1, getFortId());
  677. statement.setInt(2, 1);
  678. ResultSet rs = statement.executeQuery();
  679. while (rs.next())
  680. {
  681. //Create list of the door default for use when respawning dead doors
  682. _flagPoleStats.add(rs.getString("name") + ";" + rs.getInt("id") + ";" + rs.getInt("x") + ";" + rs.getInt("y") + ";"
  683. + rs.getInt("z") + ";3;none;0;0");
  684. _flagPole = StaticObjects.parse(_flagPoleStats.get(_flagPoleStats.size() - 1));
  685. StaticObjects.getInstance().putObject(_flagPole);
  686. }
  687. rs.close();
  688. statement.close();
  689. }
  690. catch (Exception e)
  691. {
  692. _log.log(Level.WARNING, "Exception: loadFlagPoles(): " + e.getMessage(), e);
  693. }
  694. finally
  695. {
  696. L2DatabaseFactory.close(con);
  697. }
  698. }
  699. // This method loads fort door upgrade data from database
  700. private void loadDoorUpgrade()
  701. {
  702. Connection con = null;
  703. try
  704. {
  705. con = L2DatabaseFactory.getInstance().getConnection();
  706. PreparedStatement statement = con.prepareStatement("SELECT * FROM fort_doorupgrade WHERE doorId IN (SELECT Id FROM fort_staticobjects WHERE fortId = ? AND objectType = ?)");
  707. statement.setInt(1, getFortId());
  708. statement.setInt(2, 0);
  709. ResultSet rs = statement.executeQuery();
  710. while (rs.next())
  711. {
  712. upgradeDoor(rs.getInt("id"), rs.getInt("hp"), rs.getInt("pDef"), rs.getInt("mDef"));
  713. }
  714. rs.close();
  715. statement.close();
  716. }
  717. catch (Exception e)
  718. {
  719. _log.log(Level.WARNING, "Exception: loadFortDoorUpgrade(): " + e.getMessage(), e);
  720. }
  721. finally
  722. {
  723. L2DatabaseFactory.close(con);
  724. }
  725. }
  726. private void removeDoorUpgrade()
  727. {
  728. Connection con = null;
  729. try
  730. {
  731. con = L2DatabaseFactory.getInstance().getConnection();
  732. PreparedStatement statement = con.prepareStatement("DELETE FROM fort_doorupgrade WHERE doorId IN (SELECT id FROM fort_staticobjects WHERE fortId=? AND objectType = ?)");
  733. statement.setInt(1, getFortId());
  734. statement.setInt(2, 0);
  735. statement.execute();
  736. statement.close();
  737. }
  738. catch (Exception e)
  739. {
  740. _log.log(Level.WARNING, "Exception: removeDoorUpgrade(): " + e.getMessage(), e);
  741. }
  742. finally
  743. {
  744. L2DatabaseFactory.close(con);
  745. }
  746. }
  747. private void saveDoorUpgrade(int doorId, int hp, int pDef, int mDef)
  748. {
  749. Connection con = null;
  750. try
  751. {
  752. con = L2DatabaseFactory.getInstance().getConnection();
  753. PreparedStatement statement = con.prepareStatement("INSERT INTO fort_doorupgrade (doorId, hp, pDef, mDef) VALUES (?,?,?,?)");
  754. statement.setInt(1, doorId);
  755. statement.setInt(2, hp);
  756. statement.setInt(3, pDef);
  757. statement.setInt(4, mDef);
  758. statement.execute();
  759. statement.close();
  760. }
  761. catch (Exception e)
  762. {
  763. _log.log(Level.WARNING, "Exception: saveDoorUpgrade(int doorId, int hp, int pDef, int mDef): " + e.getMessage(), e);
  764. }
  765. finally
  766. {
  767. L2DatabaseFactory.close(con);
  768. }
  769. }
  770. private void updateOwnerInDB()
  771. {
  772. L2Clan clan = getOwnerClan();
  773. int clanId = 0;
  774. if (clan != null)
  775. {
  776. clanId = clan.getClanId();
  777. _lastOwnedTime.setTimeInMillis(System.currentTimeMillis());
  778. }
  779. else
  780. _lastOwnedTime.setTimeInMillis(0);
  781. Connection con = null;
  782. try
  783. {
  784. con = L2DatabaseFactory.getInstance().getConnection();
  785. PreparedStatement statement;
  786. statement = con.prepareStatement("UPDATE fort SET owner=?,lastOwnedTime=?,state=?,castleId=?,blood=? WHERE id = ?");
  787. statement.setInt(1, clanId);
  788. statement.setLong(2, _lastOwnedTime.getTimeInMillis());
  789. statement.setInt(3, 0);
  790. statement.setInt(4, 0);
  791. statement.setInt(5, getBloodOathReward());
  792. statement.setInt(6, getFortId());
  793. statement.execute();
  794. statement.close();
  795. // ============================================================================
  796. // Announce to clan memebers
  797. if (clan != null)
  798. {
  799. clan.setHasFort(getFortId()); // Set has fort flag for new owner
  800. SystemMessage sm;
  801. sm = new SystemMessage(SystemMessageId.S1_CLAN_IS_VICTORIOUS_IN_THE_FORTRESS_BATTLE_OF_S2);
  802. sm.addString(clan.getName());
  803. sm.addFortId(getFortId());
  804. Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
  805. for (L2PcInstance player : pls)
  806. {
  807. player.sendPacket(sm);
  808. }
  809. clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
  810. clan.broadcastToOnlineMembers(new PlaySound(1, "Siege_Victory", 0, 0, 0, 0, 0));
  811. if (_FortUpdater != null)
  812. _FortUpdater.cancel(false);
  813. _FortUpdater = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new FortUpdater(this, clan, 0), Config.FS_BLOOD_OATH_FRQ * 60000, Config.FS_BLOOD_OATH_FRQ * 60000); // Schedule owner tasks to start running
  814. }
  815. else
  816. {
  817. _FortUpdater.cancel(false);
  818. _FortUpdater = null;
  819. }
  820. }
  821. catch (Exception e)
  822. {
  823. _log.log(Level.WARNING, "Exception: updateOwnerInDB(L2Clan clan): " + e.getMessage(), e);
  824. }
  825. finally
  826. {
  827. L2DatabaseFactory.close(con);
  828. }
  829. }
  830. public final int getFortId()
  831. {
  832. return _fortId;
  833. }
  834. public final L2Clan getOwnerClan()
  835. {
  836. return _fortOwner;
  837. }
  838. public final void setOwnerClan(L2Clan clan)
  839. {
  840. setVisibleFlag(clan != null ? true : false);
  841. _fortOwner = clan;
  842. }
  843. public final L2DoorInstance getDoor(int doorId)
  844. {
  845. if (doorId <= 0)
  846. return null;
  847. for (L2DoorInstance door : getDoors())
  848. {
  849. if (door.getDoorId() == doorId)
  850. return door;
  851. }
  852. return null;
  853. }
  854. public final List<L2DoorInstance> getDoors()
  855. {
  856. return _doors;
  857. }
  858. public final L2StaticObjectInstance getFlagPole()
  859. {
  860. return _flagPole;
  861. }
  862. public final FortSiege getSiege()
  863. {
  864. if (_siege == null)
  865. _siege = new FortSiege(new Fort[] { this });
  866. return _siege;
  867. }
  868. public final Calendar getSiegeDate()
  869. {
  870. return _siegeDate;
  871. }
  872. public final void setSiegeDate(Calendar siegeDate)
  873. {
  874. _siegeDate = siegeDate;
  875. }
  876. public final int getOwnedTime()
  877. {
  878. if (_lastOwnedTime.getTimeInMillis() == 0)
  879. return 0;
  880. return (int) ((System.currentTimeMillis() - _lastOwnedTime.getTimeInMillis()) / 1000);
  881. }
  882. public final String getName()
  883. {
  884. return _name;
  885. }
  886. public void updateClansReputation(L2Clan owner, boolean removePoints)
  887. {
  888. if (owner != null)
  889. {
  890. if (removePoints)
  891. owner.takeReputationScore(Config.LOOSE_FORT_POINTS, true);
  892. else
  893. owner.addReputationScore(Config.TAKE_FORT_POINTS, true);
  894. }
  895. }
  896. private class endFortressSiege implements Runnable
  897. {
  898. private Fort _f;
  899. private L2Clan _clan;
  900. public endFortressSiege(Fort f, L2Clan clan)
  901. {
  902. _f = f;
  903. _clan = clan;
  904. }
  905. public void run()
  906. {
  907. try
  908. {
  909. _f.engrave(_clan);
  910. }
  911. catch (Exception e)
  912. {
  913. _log.log(Level.WARNING, "Exception in endFortressSiege " + e.getMessage(), e);
  914. }
  915. }
  916. }
  917. /**
  918. * @return Returns state of fortress.<BR><BR>
  919. * 0 - not decided yet<BR>
  920. * 1 - independent<BR>
  921. * 2 - contracted with castle<BR>
  922. */
  923. public final int getFortState()
  924. {
  925. return _state;
  926. }
  927. /**
  928. * @param State.<BR>
  929. * 0 - not decided yet<BR>
  930. * 1 - independent<BR>
  931. * 2 - contracted with castle<BR><BR>
  932. * @param CastleId.<BR>
  933. * set Castle Id for contracted fort
  934. */
  935. public final void setFortState(int state, int castleId)
  936. {
  937. _state = state;
  938. _castleId = castleId;
  939. Connection con = null;
  940. try
  941. {
  942. con = L2DatabaseFactory.getInstance().getConnection();
  943. PreparedStatement statement;
  944. statement = con.prepareStatement("UPDATE fort SET state=?,castleId=? WHERE id = ?");
  945. statement.setInt(1, getFortState());
  946. statement.setInt(2, getCastleId());
  947. statement.setInt(3, getFortId());
  948. statement.execute();
  949. statement.close();
  950. }
  951. catch (Exception e)
  952. {
  953. _log.log(Level.WARNING, "Exception: setFortState(int state, int castleId): " + e.getMessage(), e);
  954. }
  955. finally
  956. {
  957. L2DatabaseFactory.close(con);
  958. }
  959. }
  960. /**
  961. * @return Returns Castle Id of fortress contracted with castle.
  962. */
  963. public final int getCastleId()
  964. {
  965. return _castleId;
  966. }
  967. /**
  968. * @return Returns fortress type.<BR><BR>
  969. * 0 - small (3 commanders) <BR>
  970. * 1 - big (4 commanders + control room)
  971. */
  972. public final int getFortType()
  973. {
  974. return _fortType;
  975. }
  976. public final int getCastleIdFromEnvoy(int npcId)
  977. {
  978. return _envoyCastles.get(npcId);
  979. }
  980. /**
  981. * @return Returns amount of barracks.
  982. */
  983. public final int getFortSize()
  984. {
  985. return getFortType() == 0 ? 3 : 5;
  986. }
  987. public void spawnSuspiciousMerchant()
  988. {
  989. if (_isSuspiciousMerchantSpawned)
  990. return;
  991. _isSuspiciousMerchantSpawned = true;
  992. for (L2Spawn spawnDat : _siegeNpcs)
  993. {
  994. spawnDat.doSpawn();
  995. spawnDat.startRespawn();
  996. }
  997. }
  998. public void despawnSuspiciousMerchant()
  999. {
  1000. if (!_isSuspiciousMerchantSpawned)
  1001. return;
  1002. _isSuspiciousMerchantSpawned = false;
  1003. for (L2Spawn spawnDat : _siegeNpcs)
  1004. {
  1005. spawnDat.stopRespawn();
  1006. spawnDat.getLastSpawn().deleteMe();
  1007. }
  1008. }
  1009. public void spawnNpcCommanders()
  1010. {
  1011. for (L2Spawn spawnDat : _npcCommanders)
  1012. {
  1013. spawnDat.doSpawn();
  1014. spawnDat.startRespawn();
  1015. }
  1016. }
  1017. public void despawnNpcCommanders()
  1018. {
  1019. for (L2Spawn spawnDat : _npcCommanders)
  1020. {
  1021. spawnDat.stopRespawn();
  1022. spawnDat.getLastSpawn().deleteMe();
  1023. }
  1024. }
  1025. public void spawnSpecialEnvoys()
  1026. {
  1027. for (L2Spawn spawnDat : _specialEnvoys)
  1028. {
  1029. spawnDat.doSpawn();
  1030. spawnDat.startRespawn();
  1031. }
  1032. }
  1033. public void despawnSpecialEnvoys()
  1034. {
  1035. for (L2Spawn spawnDat : _specialEnvoys)
  1036. {
  1037. spawnDat.stopRespawn();
  1038. spawnDat.getLastSpawn().deleteMe();
  1039. }
  1040. }
  1041. private void initNpcs()
  1042. {
  1043. Connection con = null;
  1044. try
  1045. {
  1046. con = L2DatabaseFactory.getInstance().getConnection();
  1047. PreparedStatement statement = con.prepareStatement("SELECT * FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ");
  1048. statement.setInt(1, getFortId());
  1049. statement.setInt(2, 0);
  1050. ResultSet rset = statement.executeQuery();
  1051. L2Spawn spawnDat;
  1052. L2NpcTemplate template;
  1053. while (rset.next())
  1054. {
  1055. template = NpcTable.getInstance().getTemplate(rset.getInt("npcId"));
  1056. if (template != null)
  1057. {
  1058. spawnDat = new L2Spawn(template);
  1059. spawnDat.setAmount(1);
  1060. spawnDat.setLocx(rset.getInt("x"));
  1061. spawnDat.setLocy(rset.getInt("y"));
  1062. spawnDat.setLocz(rset.getInt("z"));
  1063. spawnDat.setHeading(rset.getInt("heading"));
  1064. spawnDat.setRespawnDelay(60);
  1065. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  1066. spawnDat.doSpawn();
  1067. spawnDat.startRespawn();
  1068. }
  1069. else
  1070. {
  1071. _log.warning("Fort " + getFortId() + " initNpcs: Data missing in NPC table for ID: " + rset.getInt("npcId") + ".");
  1072. }
  1073. }
  1074. rset.close();
  1075. statement.close();
  1076. }
  1077. catch (Exception e)
  1078. {
  1079. // problem with initializing spawn, go to next one
  1080. _log.log(Level.WARNING, "Fort " + getFortId() + " initNpcs: Spawn could not be initialized: " + e.getMessage(), e);
  1081. }
  1082. finally
  1083. {
  1084. L2DatabaseFactory.close(con);
  1085. }
  1086. }
  1087. private void initSiegeNpcs()
  1088. {
  1089. Connection con = null;
  1090. _siegeNpcs.clear();
  1091. try
  1092. {
  1093. con = L2DatabaseFactory.getInstance().getConnection();
  1094. PreparedStatement statement = con.prepareStatement("SELECT id, npcId, x, y, z, heading FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ORDER BY id");
  1095. statement.setInt(1, getFortId());
  1096. statement.setInt(2, 2);
  1097. ResultSet rset = statement.executeQuery();
  1098. L2Spawn spawnDat;
  1099. L2NpcTemplate template;
  1100. while (rset.next())
  1101. {
  1102. template = NpcTable.getInstance().getTemplate(rset.getInt("npcId"));
  1103. if (template != null)
  1104. {
  1105. spawnDat = new L2Spawn(template);
  1106. spawnDat.setAmount(1);
  1107. spawnDat.setLocx(rset.getInt("x"));
  1108. spawnDat.setLocy(rset.getInt("y"));
  1109. spawnDat.setLocz(rset.getInt("z"));
  1110. spawnDat.setHeading(rset.getInt("heading"));
  1111. spawnDat.setRespawnDelay(60);
  1112. _siegeNpcs.add(spawnDat);
  1113. }
  1114. else
  1115. {
  1116. _log.warning("Fort " + getFortId() + " initSiegeNpcs: Data missing in NPC table for ID: " + rset.getInt("npcId") + ".");
  1117. }
  1118. }
  1119. rset.close();
  1120. statement.close();
  1121. }
  1122. catch (Exception e)
  1123. {
  1124. // problem with initializing spawn, go to next one
  1125. _log.log(Level.WARNING, "Fort " + getFortId() + " initSiegeNpcs: Spawn could not be initialized: " + e.getMessage(), e);
  1126. }
  1127. finally
  1128. {
  1129. L2DatabaseFactory.close(con);
  1130. }
  1131. }
  1132. private void initNpcCommanders()
  1133. {
  1134. Connection con = null;
  1135. _npcCommanders.clear();
  1136. try
  1137. {
  1138. con = L2DatabaseFactory.getInstance().getConnection();
  1139. PreparedStatement statement = con.prepareStatement("SELECT id, npcId, x, y, z, heading FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ORDER BY id");
  1140. statement.setInt(1, getFortId());
  1141. statement.setInt(2, 1);
  1142. ResultSet rset = statement.executeQuery();
  1143. L2Spawn spawnDat;
  1144. L2NpcTemplate template;
  1145. while (rset.next())
  1146. {
  1147. template = NpcTable.getInstance().getTemplate(rset.getInt("npcId"));
  1148. if (template != null)
  1149. {
  1150. spawnDat = new L2Spawn(template);
  1151. spawnDat.setAmount(1);
  1152. spawnDat.setLocx(rset.getInt("x"));
  1153. spawnDat.setLocy(rset.getInt("y"));
  1154. spawnDat.setLocz(rset.getInt("z"));
  1155. spawnDat.setHeading(rset.getInt("heading"));
  1156. spawnDat.setRespawnDelay(60);
  1157. _npcCommanders.add(spawnDat);
  1158. }
  1159. else
  1160. {
  1161. _log.warning("Fort " + getFortId() + " initNpcCommanders: Data missing in NPC table for ID: " + rset.getInt("npcId")
  1162. + ".");
  1163. }
  1164. }
  1165. rset.close();
  1166. statement.close();
  1167. }
  1168. catch (Exception e)
  1169. {
  1170. // problem with initializing spawn, go to next one
  1171. _log.log(Level.WARNING, "Fort " + getFortId() + " initNpcCommanders: Spawn could not be initialized: " + e.getMessage(), e);
  1172. }
  1173. finally
  1174. {
  1175. L2DatabaseFactory.close(con);
  1176. }
  1177. }
  1178. private void initSpecialEnvoys()
  1179. {
  1180. Connection con = null;
  1181. _specialEnvoys.clear();
  1182. _envoyCastles.clear();
  1183. try
  1184. {
  1185. con = L2DatabaseFactory.getInstance().getConnection();
  1186. PreparedStatement statement = con.prepareStatement("SELECT id, npcId, x, y, z, heading, castleId FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ORDER BY id");
  1187. statement.setInt(1, getFortId());
  1188. statement.setInt(2, 3);
  1189. ResultSet rset = statement.executeQuery();
  1190. L2Spawn spawnDat;
  1191. L2NpcTemplate template;
  1192. while (rset.next())
  1193. {
  1194. int castleId = rset.getInt("castleId");
  1195. int npcId = rset.getInt("npcId");
  1196. template = NpcTable.getInstance().getTemplate(npcId);
  1197. if (template != null)
  1198. {
  1199. spawnDat = new L2Spawn(template);
  1200. spawnDat.setAmount(1);
  1201. spawnDat.setLocx(rset.getInt("x"));
  1202. spawnDat.setLocy(rset.getInt("y"));
  1203. spawnDat.setLocz(rset.getInt("z"));
  1204. spawnDat.setHeading(rset.getInt("heading"));
  1205. spawnDat.setRespawnDelay(60);
  1206. _specialEnvoys.add(spawnDat);
  1207. _envoyCastles.put(npcId, castleId);
  1208. }
  1209. else
  1210. {
  1211. _log.warning("Fort " + getFortId() + " initSpecialEnvoys: Data missing in NPC table for ID: " + rset.getInt("npcId")
  1212. + ".");
  1213. }
  1214. }
  1215. rset.close();
  1216. statement.close();
  1217. }
  1218. catch (Exception e)
  1219. {
  1220. // problem with initializing spawn, go to next one
  1221. _log.log(Level.WARNING, "Fort " + getFortId() + " initSpecialEnvoys: Spawn could not be initialized: " + e.getMessage(), e);
  1222. }
  1223. finally
  1224. {
  1225. L2DatabaseFactory.close(con);
  1226. }
  1227. }
  1228. public FastList<L2Skill> getResidentialSkills()
  1229. {
  1230. return _residentialSkills;
  1231. }
  1232. public void giveResidentialSkills(L2PcInstance player)
  1233. {
  1234. if (_residentialSkills != null && !_residentialSkills.isEmpty())
  1235. {
  1236. for (L2Skill sk : _residentialSkills)
  1237. player.addSkill(sk, false);
  1238. }
  1239. }
  1240. public void removeResidentialSkills(L2PcInstance player)
  1241. {
  1242. if (_residentialSkills != null && !_residentialSkills.isEmpty())
  1243. {
  1244. for (L2Skill sk : _residentialSkills)
  1245. player.removeSkill(sk, false);
  1246. }
  1247. }
  1248. }