Castle.java 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  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 net.sf.l2j.gameserver.model.entity;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.util.Calendar;
  19. import java.util.List;
  20. import java.util.Map;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23. import javolution.util.FastList;
  24. import javolution.util.FastMap;
  25. import net.sf.l2j.Config;
  26. import net.sf.l2j.L2DatabaseFactory;
  27. import net.sf.l2j.gameserver.Announcements;
  28. import net.sf.l2j.gameserver.CastleUpdater;
  29. import net.sf.l2j.gameserver.SevenSigns;
  30. import net.sf.l2j.gameserver.ThreadPoolManager;
  31. import net.sf.l2j.gameserver.datatables.ClanTable;
  32. import net.sf.l2j.gameserver.datatables.DoorTable;
  33. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  34. import net.sf.l2j.gameserver.instancemanager.CastleManorManager;
  35. import net.sf.l2j.gameserver.instancemanager.FortManager;
  36. import net.sf.l2j.gameserver.instancemanager.CastleManorManager.CropProcure;
  37. import net.sf.l2j.gameserver.instancemanager.CastleManorManager.SeedProduction;
  38. import net.sf.l2j.gameserver.model.L2Clan;
  39. import net.sf.l2j.gameserver.model.L2Manor;
  40. import net.sf.l2j.gameserver.model.L2Object;
  41. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  42. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  43. import net.sf.l2j.gameserver.model.zone.type.L2CastleTeleportZone;
  44. import net.sf.l2j.gameserver.model.zone.type.L2CastleZone;
  45. import net.sf.l2j.gameserver.serverpackets.PlaySound;
  46. import net.sf.l2j.gameserver.serverpackets.PledgeShowInfoUpdate;
  47. public class Castle
  48. {
  49. protected static final Logger _log = Logger.getLogger(Castle.class.getName());
  50. // =========================================================
  51. // Data Field
  52. private FastList<CropProcure> _procure = new FastList<CropProcure>();
  53. private FastList<SeedProduction> _production = new FastList<SeedProduction>();
  54. private FastList<CropProcure> _procureNext = new FastList<CropProcure>();
  55. private FastList<SeedProduction> _productionNext = new FastList<SeedProduction>();
  56. private boolean _isNextPeriodApproved = false;
  57. private static final String CASTLE_MANOR_DELETE_PRODUCTION =
  58. "DELETE FROM castle_manor_production WHERE castle_id=?;";
  59. private static final String CASTLE_MANOR_DELETE_PRODUCTION_PERIOD =
  60. "DELETE FROM castle_manor_production WHERE castle_id=? AND period=?;";
  61. private static final String CASTLE_MANOR_DELETE_PROCURE =
  62. "DELETE FROM castle_manor_procure WHERE castle_id=?;";
  63. private static final String CASTLE_MANOR_DELETE_PROCURE_PERIOD =
  64. "DELETE FROM castle_manor_procure WHERE castle_id=? AND period=?;";
  65. private static final String CASTLE_UPDATE_CROP =
  66. "UPDATE castle_manor_procure SET can_buy=? WHERE crop_id=? AND castle_id=? AND period=?";
  67. private static final String CASTLE_UPDATE_SEED =
  68. "UPDATE castle_manor_production SET can_produce=? WHERE seed_id=? AND castle_id=? AND period=?";
  69. // =========================================================
  70. // Data Field
  71. private int _castleId = 0;
  72. private List<L2DoorInstance> _doors = new FastList<L2DoorInstance>();
  73. private List<String> _doorDefault = new FastList<String>();
  74. private String _name = "";
  75. private int _ownerId = 0;
  76. private Siege _siege = null;
  77. private Calendar _siegeDate;
  78. private int _siegeDayOfWeek = 7; // Default to saturday
  79. private int _siegeHourOfDay = 20; // Default to 8 pm server time
  80. private int _taxPercent = 0;
  81. private double _taxRate = 0;
  82. private int _treasury = 0;
  83. private L2CastleZone _zone;
  84. private L2CastleTeleportZone _teleZone;
  85. private L2Clan _formerOwner = null;
  86. private int _nbArtifact = 1;
  87. private Map<Integer, Integer> _engrave = new FastMap<Integer, Integer>();
  88. private Map<Integer,CastleFunction> _function;
  89. /** Castle Functions */
  90. public static final int FUNC_TELEPORT = 1;
  91. public static final int FUNC_RESTORE_HP = 2;
  92. public static final int FUNC_RESTORE_MP = 3;
  93. public static final int FUNC_RESTORE_EXP = 4;
  94. public static final int FUNC_SUPPORT = 5;
  95. public class CastleFunction
  96. {
  97. private int _type;
  98. private int _lvl;
  99. protected int _fee;
  100. protected int _tempFee;
  101. private long _rate;
  102. private long _endDate;
  103. protected boolean _inDebt;
  104. public boolean _cwh;
  105. public CastleFunction(int type, int lvl, int lease, int tempLease, long rate, long time, boolean cwh)
  106. {
  107. _type = type;
  108. _lvl = lvl;
  109. _fee = lease;
  110. _tempFee = tempLease;
  111. _rate = rate;
  112. _endDate = time;
  113. initializeTask(cwh);
  114. }
  115. public int getType(){ return _type;}
  116. public int getLvl(){ return _lvl;}
  117. public int getLease(){return _fee;}
  118. public long getRate(){return _rate;}
  119. public long getEndTime(){ return _endDate;}
  120. public void setLvl(int lvl){_lvl = lvl;}
  121. public void setLease(int lease){_fee = lease;}
  122. public void setEndTime(long time){_endDate = time;}
  123. private void initializeTask(boolean cwh)
  124. {
  125. if (getOwnerId() <= 0)
  126. return;
  127. long currentTime = System.currentTimeMillis();
  128. if(_endDate>currentTime)
  129. ThreadPoolManager.getInstance().scheduleGeneral(new FunctionTask(cwh), _endDate-currentTime);
  130. else
  131. ThreadPoolManager.getInstance().scheduleGeneral(new FunctionTask(cwh), 0);
  132. }
  133. private class FunctionTask implements Runnable
  134. {
  135. public FunctionTask(boolean cwh)
  136. {
  137. _cwh = cwh;
  138. }
  139. public void run()
  140. {
  141. try
  142. {
  143. if (getOwnerId() <= 0)
  144. return;
  145. if(ClanTable.getInstance().getClan(getOwnerId()).getWarehouse().getAdena() >= _fee || !_cwh)
  146. {
  147. int fee = _fee;
  148. boolean newfc = true;
  149. if(getEndTime() == 0 || getEndTime() == -1)
  150. {
  151. if(getEndTime() == -1)
  152. {
  153. newfc = false;
  154. fee = _tempFee;
  155. }
  156. }else
  157. newfc = false;
  158. setEndTime(System.currentTimeMillis()+getRate());
  159. dbSave(newfc);
  160. if (_cwh)
  161. {
  162. ClanTable.getInstance().getClan(getOwnerId()).getWarehouse().destroyItemByItemId("CS_function_fee", 57, fee, null, null);
  163. if (Config.DEBUG)
  164. _log.warning("deducted "+fee+" adena from "+getName()+" owner's cwh for function id : "+getType());
  165. }
  166. ThreadPoolManager.getInstance().scheduleGeneral(new FunctionTask(true), getRate());
  167. }else
  168. removeFunction(getType());
  169. } catch (Throwable t) { }
  170. }
  171. }
  172. public void dbSave(boolean newFunction)
  173. {
  174. java.sql.Connection con = null;
  175. try
  176. {
  177. PreparedStatement statement;
  178. con = L2DatabaseFactory.getInstance().getConnection();
  179. if (newFunction)
  180. {
  181. statement = con.prepareStatement("INSERT INTO castle_functions (castle_id, type, lvl, lease, rate, endTime) VALUES (?,?,?,?,?,?)");
  182. statement.setInt(1, getCastleId());
  183. statement.setInt(2, getType());
  184. statement.setInt(3, getLvl());
  185. statement.setInt(4, getLease());
  186. statement.setLong(5, getRate());
  187. statement.setLong(6, getEndTime());
  188. }
  189. else
  190. {
  191. statement = con.prepareStatement("UPDATE castle_functions SET lvl=?, lease=?, endTime=? WHERE castle_id=? AND type=?");
  192. statement.setInt(1, getLvl());
  193. statement.setInt(2, getLease());
  194. statement.setLong(3, getEndTime());
  195. statement.setInt(4, getCastleId());
  196. statement.setInt(5, getType());
  197. }
  198. statement.execute();
  199. statement.close();
  200. }
  201. catch (Exception e)
  202. {
  203. _log.log(Level.SEVERE, "Exception: Castle.updateFunctions(int type, int lvl, int lease, long rate, long time, boolean addNew): " + e.getMessage(),e);
  204. }
  205. finally {try { con.close(); } catch (Exception e) {}}
  206. }
  207. }
  208. // =========================================================
  209. // Constructor
  210. public Castle(int castleId)
  211. {
  212. _castleId = castleId;
  213. if(_castleId == 7 || castleId == 9) // Goddard and Schuttgart
  214. _nbArtifact = 2;
  215. load();
  216. loadDoor();
  217. _function = new FastMap<Integer,CastleFunction>();
  218. if (getOwnerId() != 0)
  219. {
  220. loadFunctions();
  221. }
  222. }
  223. // =========================================================
  224. // Method - Public
  225. /** Return function with id */
  226. public CastleFunction getFunction(int type)
  227. {
  228. if(_function.get(type) != null)
  229. return _function.get(type);
  230. return null;
  231. }
  232. public void Engrave(L2Clan clan, int objId)
  233. {
  234. _engrave.put(objId, clan.getClanId());
  235. if (_engrave.size() == _nbArtifact)
  236. {
  237. boolean rst = true;
  238. for (int id : _engrave.values())
  239. {
  240. if (id != clan.getClanId())
  241. rst = false;
  242. }
  243. if(rst)
  244. {
  245. _engrave.clear();
  246. setOwner(clan);
  247. }
  248. else
  249. getSiege().announceToPlayer("Clan " + clan.getName() + " has finished to engrave one of the rulers.", true);
  250. }
  251. else
  252. getSiege().announceToPlayer("Clan " + clan.getName() + " has finished to engrave one of the rulers.", true);
  253. }
  254. // This method add to the treasury
  255. /** Add amount to castle instance's treasury (warehouse). */
  256. public void addToTreasury(int amount)
  257. {
  258. // check if owned
  259. if (getOwnerId() <= 0)
  260. {
  261. return;
  262. }
  263. if (_name.equalsIgnoreCase("Schuttgart") || _name.equalsIgnoreCase("Goddard"))
  264. {
  265. Castle rune = CastleManager.getInstance().getCastle("rune");
  266. if (rune != null )
  267. {
  268. int runeTax = (int)(amount * rune.getTaxRate());
  269. if (rune.getOwnerId() > 0 ) rune.addToTreasury(runeTax);
  270. amount -= runeTax;
  271. }
  272. }
  273. if (!_name.equalsIgnoreCase("aden") && !_name.equalsIgnoreCase("Rune") && !_name.equalsIgnoreCase("Schuttgart") && !_name.equalsIgnoreCase("Goddard")) // If current castle instance is not Aden, Rune, Goddard or Schuttgart.
  274. {
  275. Castle aden = CastleManager.getInstance().getCastle("aden");
  276. if (aden != null)
  277. {
  278. int adenTax = (int)(amount * aden.getTaxRate()); // Find out what Aden gets from the current castle instance's income
  279. if (aden.getOwnerId() > 0) aden.addToTreasury(adenTax); // Only bother to really add the tax to the treasury if not npc owned
  280. amount -= adenTax; // Subtract Aden's income from current castle instance's income
  281. }
  282. }
  283. addToTreasuryNoTax(amount);
  284. }
  285. /** Add amount to castle instance's treasury (warehouse), no tax paying. */
  286. public boolean addToTreasuryNoTax(int amount)
  287. {
  288. if (getOwnerId() <= 0) return false;
  289. if (amount < 0) {
  290. amount *= -1;
  291. if (_treasury < amount) return false;
  292. _treasury -= amount;
  293. } else {
  294. if ((long)_treasury + amount > Integer.MAX_VALUE) _treasury = Integer.MAX_VALUE;
  295. else _treasury += amount;
  296. }
  297. java.sql.Connection con = null;
  298. try
  299. {
  300. con = L2DatabaseFactory.getInstance().getConnection();
  301. PreparedStatement statement = con.prepareStatement("Update castle set treasury = ? where id = ?");
  302. statement.setInt(1, getTreasury());
  303. statement.setInt(2, getCastleId());
  304. statement.execute();
  305. statement.close();
  306. }
  307. catch (Exception e) {}
  308. finally {try { con.close(); } catch (Exception e) {}}
  309. return true;
  310. }
  311. /**
  312. * Move non clan members off castle area and to nearest town.<BR><BR>
  313. */
  314. public void banishForeigners()
  315. {
  316. _zone.banishForeigners(getOwnerId());
  317. }
  318. /**
  319. * Return true if object is inside the zone
  320. */
  321. public boolean checkIfInZone(int x, int y, int z)
  322. {
  323. return _zone.isInsideZone(x, y, z);
  324. }
  325. /**
  326. * Sets this castles zone
  327. * @param zone
  328. */
  329. public void setZone(L2CastleZone zone)
  330. {
  331. _zone = zone;
  332. }
  333. public L2CastleZone getZone()
  334. {
  335. return _zone;
  336. }
  337. public void setTeleZone(L2CastleTeleportZone zone)
  338. {
  339. _teleZone = zone;
  340. }
  341. public L2CastleTeleportZone getTeleZone()
  342. {
  343. return _teleZone;
  344. }
  345. public void oustAllPlayers()
  346. {
  347. _teleZone.oustAllPlayers();
  348. }
  349. /**
  350. * Get the objects distance to this castle
  351. * @param obj
  352. * @return
  353. */
  354. public double getDistance(L2Object obj)
  355. {
  356. return _zone.getDistanceToZone(obj);
  357. }
  358. public void closeDoor(L2PcInstance activeChar, int doorId)
  359. {
  360. openCloseDoor(activeChar, doorId, false);
  361. }
  362. public void openDoor(L2PcInstance activeChar, int doorId)
  363. {
  364. openCloseDoor(activeChar, doorId, true);
  365. }
  366. public void openCloseDoor(L2PcInstance activeChar, int doorId, boolean open)
  367. {
  368. if (activeChar.getClanId() != getOwnerId())
  369. return;
  370. L2DoorInstance door = getDoor(doorId);
  371. if (door != null)
  372. {
  373. if (open)
  374. door.openMe();
  375. else
  376. door.closeMe();
  377. }
  378. }
  379. // This method is used to begin removing all castle upgrades
  380. public void removeUpgrade()
  381. {
  382. removeDoorUpgrade();
  383. for (Map.Entry<Integer, CastleFunction> fc : _function.entrySet())
  384. removeFunction(fc.getKey());
  385. _function.clear();
  386. }
  387. // This method updates the castle tax rate
  388. public void setOwner(L2Clan clan)
  389. {
  390. // Remove old owner
  391. if (getOwnerId() > 0 && (clan == null || clan.getClanId() != getOwnerId()))
  392. {
  393. L2Clan oldOwner = ClanTable.getInstance().getClan(getOwnerId()); // Try to find clan instance
  394. if (oldOwner != null)
  395. {
  396. if (_formerOwner == null)
  397. {
  398. _formerOwner = oldOwner;
  399. if (Config.REMOVE_CASTLE_CIRCLETS)
  400. {
  401. CastleManager.getInstance().removeCirclet(_formerOwner,getCastleId());
  402. }
  403. }
  404. oldOwner.setHasCastle(0); // Unset has castle flag for old owner
  405. Announcements.getInstance().announceToAll(oldOwner.getName() + " has lost " + getName() + " castle!");
  406. }
  407. }
  408. updateOwnerInDB(clan); // Update in database
  409. // if clan have fortress, remove it
  410. if (clan.getHasFort() > 0)
  411. FortManager.getInstance().getFortByOwner(clan).removeOwner(clan);
  412. if (getSiege().getIsInProgress()) // If siege in progress
  413. getSiege().midVictory(); // Mid victory phase of siege
  414. updateClansReputation();
  415. }
  416. public void removeOwner(L2Clan clan)
  417. {
  418. if (clan != null)
  419. {
  420. _formerOwner = clan;
  421. if (Config.REMOVE_CASTLE_CIRCLETS)
  422. {
  423. CastleManager.getInstance().removeCirclet(_formerOwner,getCastleId());
  424. }
  425. clan.setHasCastle(0);
  426. Announcements.getInstance().announceToAll(clan.getName() + " has lost " +getName() + " castle");
  427. clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
  428. }
  429. updateOwnerInDB(null);
  430. if (getSiege().getIsInProgress())
  431. getSiege().midVictory();
  432. updateClansReputation();
  433. for (Map.Entry<Integer, CastleFunction> fc : _function.entrySet())
  434. removeFunction(fc.getKey());
  435. _function.clear();
  436. }
  437. // This method updates the castle tax rate
  438. public void setTaxPercent(L2PcInstance activeChar, int taxPercent)
  439. {
  440. int maxTax;
  441. switch(SevenSigns.getInstance().getSealOwner(SevenSigns.SEAL_STRIFE))
  442. {
  443. case SevenSigns.CABAL_DAWN:
  444. maxTax = 25;
  445. break;
  446. case SevenSigns.CABAL_DUSK:
  447. maxTax = 5;
  448. break;
  449. default: // no owner
  450. maxTax = 15;
  451. }
  452. if (taxPercent < 0 || taxPercent > maxTax)
  453. {
  454. activeChar.sendMessage("Tax value must be between 0 and "+maxTax+".");
  455. return;
  456. }
  457. setTaxPercent(taxPercent);
  458. activeChar.sendMessage(getName() + " castle tax changed to " + taxPercent + "%.");
  459. }
  460. public void setTaxPercent(int taxPercent)
  461. {
  462. _taxPercent = taxPercent;
  463. _taxRate = _taxPercent / 100.0;
  464. java.sql.Connection con = null;
  465. try
  466. {
  467. con = L2DatabaseFactory.getInstance().getConnection();
  468. PreparedStatement statement = con.prepareStatement("Update castle set taxPercent = ? where id = ?");
  469. statement.setInt(1, taxPercent);
  470. statement.setInt(2, getCastleId());
  471. statement.execute();
  472. statement.close();
  473. }
  474. catch (Exception e) {}
  475. finally {try { con.close(); } catch (Exception e) {}}
  476. }
  477. /**
  478. * Respawn all doors on castle grounds<BR><BR>
  479. */
  480. public void spawnDoor()
  481. {
  482. spawnDoor(false);
  483. }
  484. /**
  485. * Respawn all doors on castle grounds<BR><BR>
  486. */
  487. public void spawnDoor(boolean isDoorWeak)
  488. {
  489. for (int i = 0; i < getDoors().size(); i++)
  490. {
  491. L2DoorInstance door = getDoors().get(i);
  492. if (door.getCurrentHp() <= 0)
  493. {
  494. door.decayMe(); // Kill current if not killed already
  495. door = DoorTable.parseList(_doorDefault.get(i));
  496. if (isDoorWeak)
  497. door.setCurrentHp(door.getMaxHp() / 2);
  498. door.spawnMe(door.getX(), door.getY(),door.getZ());
  499. getDoors().set(i, door);
  500. }
  501. else if (door.getOpen() == 0)
  502. door.closeMe();
  503. }
  504. loadDoorUpgrade(); // Check for any upgrade the doors may have
  505. }
  506. // This method upgrade door
  507. public void upgradeDoor(int doorId, int hp, int pDef, int mDef)
  508. {
  509. L2DoorInstance door = getDoor(doorId);
  510. if (door == null)
  511. return;
  512. if (door != null && door.getDoorId() == doorId)
  513. {
  514. door.setCurrentHp(door.getMaxHp() + hp);
  515. saveDoorUpgrade(doorId, hp, pDef, mDef);
  516. return;
  517. }
  518. }
  519. // =========================================================
  520. // Method - Private
  521. // This method loads castle
  522. private void load()
  523. {
  524. java.sql.Connection con = null;
  525. try
  526. {
  527. PreparedStatement statement;
  528. ResultSet rs;
  529. con = L2DatabaseFactory.getInstance().getConnection();
  530. statement = con.prepareStatement("Select * from castle where id = ?");
  531. statement.setInt(1, getCastleId());
  532. rs = statement.executeQuery();
  533. while (rs.next())
  534. {
  535. _name = rs.getString("name");
  536. //_OwnerId = rs.getInt("ownerId");
  537. _siegeDate = Calendar.getInstance();
  538. _siegeDate.setTimeInMillis(rs.getLong("siegeDate"));
  539. _siegeDayOfWeek = rs.getInt("siegeDayOfWeek");
  540. if (_siegeDayOfWeek < 1 || _siegeDayOfWeek > 7)
  541. _siegeDayOfWeek = 7;
  542. _siegeHourOfDay = rs.getInt("siegeHourOfDay");
  543. if (_siegeHourOfDay < 0 || _siegeHourOfDay > 23)
  544. _siegeHourOfDay = 20;
  545. _taxPercent = rs.getInt("taxPercent");
  546. _treasury = rs.getInt("treasury");
  547. }
  548. statement.close();
  549. _taxRate = _taxPercent / 100.0;
  550. statement = con.prepareStatement("Select clan_id from clan_data where hasCastle = ?");
  551. statement.setInt(1, getCastleId());
  552. rs = statement.executeQuery();
  553. while (rs.next())
  554. {
  555. _ownerId = rs.getInt("clan_id");
  556. }
  557. if (getOwnerId() > 0)
  558. {
  559. L2Clan clan = ClanTable.getInstance().getClan(getOwnerId()); // Try to find clan instance
  560. ThreadPoolManager.getInstance().scheduleGeneral(new CastleUpdater(clan, 1), 3600000); // Schedule owner tasks to start running
  561. }
  562. statement.close();
  563. }
  564. catch (Exception e)
  565. {
  566. _log.warning("Exception: loadCastleData(): " + e.getMessage());
  567. e.printStackTrace();
  568. }
  569. finally {try { con.close(); } catch (Exception e) {}}
  570. }
  571. /** Load All Functions */
  572. private void loadFunctions()
  573. {
  574. java.sql.Connection con = null;
  575. try
  576. {
  577. PreparedStatement statement;
  578. ResultSet rs;
  579. con = L2DatabaseFactory.getInstance().getConnection();
  580. statement = con.prepareStatement("Select * from castle_functions where castle_id = ?");
  581. statement.setInt(1, getCastleId());
  582. rs = statement.executeQuery();
  583. while (rs.next())
  584. {
  585. _function.put(rs.getInt("type"), new CastleFunction(rs.getInt("type"), rs.getInt("lvl"), rs.getInt("lease"),0, rs.getLong("rate"), rs.getLong("endTime"), true));
  586. }
  587. statement.close();
  588. }
  589. catch (Exception e)
  590. {
  591. _log.log(Level.SEVERE, "Exception: Castle.loadFunctions(): " + e.getMessage(),e);
  592. }
  593. finally {try { con.close(); } catch (Exception e) {}}
  594. }
  595. /** Remove function In List and in DB */
  596. public void removeFunction(int functionType)
  597. {
  598. _function.remove(functionType);
  599. java.sql.Connection con = null;
  600. try
  601. {
  602. PreparedStatement statement;
  603. con = L2DatabaseFactory.getInstance().getConnection();
  604. statement = con.prepareStatement("DELETE FROM castle_functions WHERE castle_id=? AND type=?");
  605. statement.setInt(1, getCastleId());
  606. statement.setInt(2, functionType);
  607. statement.execute();
  608. statement.close();
  609. }
  610. catch (Exception e)
  611. {
  612. _log.log(Level.SEVERE, "Exception: Castle.removeFunctions(int functionType): " + e.getMessage(),e);
  613. }
  614. finally {try { con.close(); } catch (Exception e) {}}
  615. }
  616. public boolean updateFunctions(L2PcInstance player,int type, int lvl, int lease, long rate, boolean addNew)
  617. {
  618. if (player == null)
  619. return false;
  620. if (Config.DEBUG)
  621. _log.warning("Called Castle.updateFunctions(int type, int lvl, int lease, long rate, boolean addNew) Owner : "+getOwnerId());
  622. if (lease > 0)
  623. if (!player.destroyItemByItemId("Consume", 57, lease, null, true))
  624. return false;
  625. if (addNew)
  626. {
  627. _function.put(type,new CastleFunction(type, lvl, lease,0, rate, 0, false));
  628. }
  629. else
  630. {
  631. if(lvl == 0 && lease == 0)
  632. removeFunction(type);
  633. else
  634. {
  635. int diffLease = lease-_function.get(type).getLease();
  636. if (Config.DEBUG)
  637. _log.warning("Called Castle.updateFunctions diffLease : "+diffLease);
  638. if(diffLease>0)
  639. {
  640. _function.remove(type);
  641. _function.put(type,new CastleFunction(type, lvl, lease,0, rate, -1,false));
  642. }
  643. else
  644. {
  645. _function.get(type).setLease(lease);
  646. _function.get(type).setLvl(lvl);
  647. _function.get(type).dbSave(false);
  648. }
  649. }
  650. }
  651. return true;
  652. }
  653. // This method loads castle door data from database
  654. private void loadDoor()
  655. {
  656. java.sql.Connection con = null;
  657. try
  658. {
  659. con = L2DatabaseFactory.getInstance().getConnection();
  660. PreparedStatement statement = con.prepareStatement("Select * from castle_door where castleId = ?");
  661. statement.setInt(1, getCastleId());
  662. ResultSet rs = statement.executeQuery();
  663. while (rs.next())
  664. {
  665. // Create list of the door default for use when respawning dead doors
  666. _doorDefault.add(rs.getString("name")
  667. + ";" + rs.getInt("id")
  668. + ";" + rs.getInt("x")
  669. + ";" + rs.getInt("y")
  670. + ";" + rs.getInt("z")
  671. + ";" + rs.getInt("range_xmin")
  672. + ";" + rs.getInt("range_ymin")
  673. + ";" + rs.getInt("range_zmin")
  674. + ";" + rs.getInt("range_xmax")
  675. + ";" + rs.getInt("range_ymax")
  676. + ";" + rs.getInt("range_zmax")
  677. + ";" + rs.getInt("hp")
  678. + ";" + rs.getInt("pDef")
  679. + ";" + rs.getInt("mDef"));
  680. L2DoorInstance door = DoorTable.parseList(_doorDefault.get(_doorDefault.size() - 1));
  681. door.spawnMe(door.getX(), door.getY(),door.getZ());
  682. _doors.add(door);
  683. DoorTable.getInstance().putDoor(door);
  684. }
  685. statement.close();
  686. }
  687. catch (Exception e)
  688. {
  689. _log.warning("Exception: loadCastleDoor(): " + e.getMessage());
  690. e.printStackTrace();
  691. }
  692. finally {try { con.close(); } catch (Exception e) {}}
  693. }
  694. // This method loads castle door upgrade data from database
  695. private void loadDoorUpgrade()
  696. {
  697. java.sql.Connection con = null;
  698. try
  699. {
  700. con = L2DatabaseFactory.getInstance().getConnection();
  701. PreparedStatement statement = con.prepareStatement("Select * from castle_doorupgrade where doorId in (Select Id from castle_door where castleId = ?)");
  702. statement.setInt(1, getCastleId());
  703. ResultSet rs = statement.executeQuery();
  704. while (rs.next())
  705. {
  706. upgradeDoor(rs.getInt("id"), rs.getInt("hp"), rs.getInt("pDef"), rs.getInt("mDef"));
  707. }
  708. statement.close();
  709. }
  710. catch (Exception e)
  711. {
  712. _log.warning("Exception: loadCastleDoorUpgrade(): " + e.getMessage());
  713. e.printStackTrace();
  714. }
  715. finally {try { con.close(); } catch (Exception e) {}}
  716. }
  717. private void removeDoorUpgrade()
  718. {
  719. java.sql.Connection con = null;
  720. try
  721. {
  722. con = L2DatabaseFactory.getInstance().getConnection();
  723. PreparedStatement statement = con.prepareStatement("delete from castle_doorupgrade where doorId in (select id from castle_door where castleId=?)");
  724. statement.setInt(1, getCastleId());
  725. statement.execute();
  726. statement.close();
  727. }
  728. catch (Exception e)
  729. {
  730. _log.warning("Exception: removeDoorUpgrade(): " + e.getMessage());
  731. e.printStackTrace();
  732. }
  733. finally {try { con.close(); } catch (Exception e) {}}
  734. }
  735. private void saveDoorUpgrade(int doorId, int hp, int pDef, int mDef)
  736. {
  737. java.sql.Connection con = null;
  738. try
  739. {
  740. con = L2DatabaseFactory.getInstance().getConnection();
  741. PreparedStatement statement = con.prepareStatement("INSERT INTO castle_doorupgrade (doorId, hp, pDef, mDef) values (?,?,?,?)");
  742. statement.setInt(1, doorId);
  743. statement.setInt(2, hp);
  744. statement.setInt(3, pDef);
  745. statement.setInt(4, mDef);
  746. statement.execute();
  747. statement.close();
  748. }
  749. catch (Exception e)
  750. {
  751. _log.warning("Exception: saveDoorUpgrade(int doorId, int hp, int pDef, int mDef): " + e.getMessage());
  752. e.printStackTrace();
  753. }
  754. finally
  755. {
  756. try { con.close(); } catch (Exception e) {}
  757. }
  758. }
  759. private void updateOwnerInDB(L2Clan clan)
  760. {
  761. if (clan != null)
  762. _ownerId = clan.getClanId(); // Update owner id property
  763. else
  764. _ownerId = 0; // Remove owner
  765. java.sql.Connection con = null;
  766. try
  767. {
  768. con = L2DatabaseFactory.getInstance().getConnection();
  769. PreparedStatement statement;
  770. // ============================================================================
  771. // NEED TO REMOVE HAS CASTLE FLAG FROM CLAN_DATA
  772. // SHOULD BE CHECKED FROM CASTLE TABLE
  773. statement = con.prepareStatement("UPDATE clan_data SET hasCastle=0 WHERE hasCastle=?");
  774. statement.setInt(1, getCastleId());
  775. statement.execute();
  776. statement.close();
  777. statement = con.prepareStatement("UPDATE clan_data SET hasCastle=? WHERE clan_id=?");
  778. statement.setInt(1, getCastleId());
  779. statement.setInt(2, getOwnerId());
  780. statement.execute();
  781. statement.close();
  782. // ============================================================================
  783. // Announce to clan memebers
  784. if (clan != null)
  785. {
  786. clan.setHasCastle(getCastleId()); // Set has castle flag for new owner
  787. Announcements.getInstance().announceToAll(clan.getName() + " has taken " + getName() + " castle!");
  788. clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
  789. clan.broadcastToOnlineMembers(new PlaySound(1, "Siege_Victory", 0, 0, 0, 0, 0));
  790. ThreadPoolManager.getInstance().scheduleGeneral(new CastleUpdater(clan, 1), 3600000); // Schedule owner tasks to start running
  791. }
  792. }
  793. catch (Exception e)
  794. {
  795. _log.warning("Exception: updateOwnerInDB(L2Clan clan): " + e.getMessage());
  796. e.printStackTrace();
  797. }
  798. finally
  799. {
  800. try { con.close(); } catch (Exception e) {}
  801. }
  802. }
  803. // =========================================================
  804. // Property
  805. public final int getCastleId()
  806. {
  807. return _castleId;
  808. }
  809. public final L2DoorInstance getDoor(int doorId)
  810. {
  811. if (doorId <= 0)
  812. return null;
  813. for (int i = 0; i < getDoors().size(); i++)
  814. {
  815. L2DoorInstance door = getDoors().get(i);
  816. if (door.getDoorId() == doorId)
  817. return door;
  818. }
  819. return null;
  820. }
  821. public final List<L2DoorInstance> getDoors()
  822. {
  823. return _doors;
  824. }
  825. public final String getName()
  826. {
  827. return _name;
  828. }
  829. public final int getOwnerId()
  830. {
  831. return _ownerId;
  832. }
  833. public final Siege getSiege()
  834. {
  835. if (_siege == null) _siege = new Siege(new Castle[] {this});
  836. return _siege;
  837. }
  838. public final Calendar getSiegeDate() { return _siegeDate; }
  839. public final int getSiegeDayOfWeek() { return _siegeDayOfWeek; }
  840. public final int getSiegeHourOfDay() { return _siegeHourOfDay; }
  841. public final int getTaxPercent()
  842. {
  843. return _taxPercent;
  844. }
  845. public final double getTaxRate()
  846. {
  847. return _taxRate;
  848. }
  849. public final int getTreasury()
  850. {
  851. return _treasury;
  852. }
  853. public FastList<SeedProduction> getSeedProduction(int period)
  854. {
  855. return (period == CastleManorManager.PERIOD_CURRENT ? _production : _productionNext);
  856. }
  857. public FastList<CropProcure> getCropProcure(int period)
  858. {
  859. return (period == CastleManorManager.PERIOD_CURRENT ? _procure : _procureNext);
  860. }
  861. public void setSeedProduction(FastList<SeedProduction> seed, int period)
  862. {
  863. if (period == CastleManorManager.PERIOD_CURRENT)
  864. _production = seed;
  865. else
  866. _productionNext = seed;
  867. }
  868. public void setCropProcure(FastList<CropProcure> crop, int period)
  869. {
  870. if (period == CastleManorManager.PERIOD_CURRENT)
  871. _procure = crop;
  872. else
  873. _procureNext = crop;
  874. }
  875. public synchronized SeedProduction getSeed(int seedId, int period)
  876. {
  877. for (SeedProduction seed : getSeedProduction(period))
  878. {
  879. if (seed.getId() == seedId)
  880. {
  881. return seed;
  882. }
  883. }
  884. return null;
  885. }
  886. public synchronized CropProcure getCrop(int cropId, int period)
  887. {
  888. for (CropProcure crop : getCropProcure(period) )
  889. {
  890. if (crop.getId() == cropId)
  891. {
  892. return crop;
  893. }
  894. }
  895. return null;
  896. }
  897. public int getManorCost (int period)
  898. {
  899. FastList<CropProcure> procure;
  900. FastList<SeedProduction> production;
  901. if (period == CastleManorManager.PERIOD_CURRENT)
  902. {
  903. procure = _procure;
  904. production = _production;
  905. } else {
  906. procure = _procureNext;
  907. production = _productionNext;
  908. }
  909. int total = 0;
  910. if (production != null)
  911. {
  912. for (SeedProduction seed : production)
  913. {
  914. total += L2Manor.getInstance().getSeedBuyPrice(seed.getId()) * seed.getStartProduce();
  915. }
  916. }
  917. if (procure != null)
  918. {
  919. for (CropProcure crop: procure)
  920. {
  921. total += crop.getPrice() * crop.getStartAmount();
  922. }
  923. }
  924. return total;
  925. }
  926. //save manor production data
  927. public void saveSeedData()
  928. {
  929. java.sql.Connection con = null;
  930. PreparedStatement statement;
  931. try
  932. {
  933. con = L2DatabaseFactory.getInstance().getConnection();
  934. statement = con.prepareStatement(CASTLE_MANOR_DELETE_PRODUCTION);
  935. statement.setInt(1, getCastleId());
  936. statement.execute();
  937. statement.close();
  938. if (_production != null)
  939. {
  940. int count = 0;
  941. String query = "INSERT INTO castle_manor_production VALUES ";
  942. String values[] = new String[_production.size()];
  943. for(SeedProduction s : _production)
  944. {
  945. values[count] = "("+getCastleId()+","+s.getId()+","+s.getCanProduce()+","+s.getStartProduce()+","+s.getPrice()+","+CastleManorManager.PERIOD_CURRENT+")";
  946. count++;
  947. }
  948. if (values.length > 0)
  949. {
  950. query += values[0];
  951. for (int i=1; i<values.length; i++)
  952. {
  953. query += "," + values[i];
  954. }
  955. statement = con.prepareStatement(query);
  956. statement.execute();
  957. statement.close();
  958. }
  959. }
  960. if (_productionNext != null)
  961. {
  962. int count = 0;
  963. String query = "INSERT INTO castle_manor_production VALUES ";
  964. String values[] = new String[_productionNext.size()];
  965. for(SeedProduction s : _productionNext)
  966. {
  967. values[count] = "("+getCastleId()+","+s.getId()+","+s.getCanProduce()+","+s.getStartProduce()+","+s.getPrice()+","+CastleManorManager.PERIOD_NEXT+")";
  968. count++;
  969. }
  970. if (values.length > 0)
  971. {
  972. query += values[0];
  973. for (int i=1;i<values.length;i++)
  974. {
  975. query += "," + values[i];
  976. }
  977. statement = con.prepareStatement(query);
  978. statement.execute();
  979. statement.close();
  980. }
  981. }
  982. } catch (Exception e)
  983. {
  984. _log.info("Error adding seed production data for castle " + getName() +": " + e.getMessage());
  985. } finally {
  986. try { con.close(); } catch (Exception e) {}
  987. }
  988. }
  989. //save manor production data for specified period
  990. public void saveSeedData(int period)
  991. {
  992. java.sql.Connection con = null;
  993. PreparedStatement statement;
  994. try
  995. {
  996. con = L2DatabaseFactory.getInstance().getConnection();
  997. statement = con.prepareStatement(CASTLE_MANOR_DELETE_PRODUCTION_PERIOD);
  998. statement.setInt(1, getCastleId());
  999. statement.setInt(2, period);
  1000. statement.execute();
  1001. statement.close();
  1002. FastList<SeedProduction> prod = null;
  1003. prod = getSeedProduction(period);
  1004. if (prod != null)
  1005. {
  1006. int count = 0;
  1007. String query = "INSERT INTO castle_manor_production VALUES ";
  1008. String values[] = new String[prod.size()];
  1009. for(SeedProduction s : prod)
  1010. {
  1011. values[count] = "("+getCastleId()+","+s.getId()+","+s.getCanProduce()+","+s.getStartProduce()+","+s.getPrice()+","+period+")";
  1012. count++;
  1013. }
  1014. if (values.length > 0)
  1015. {
  1016. query += values[0];
  1017. for (int i=1;i<values.length;i++)
  1018. {
  1019. query += "," + values[i];
  1020. }
  1021. statement = con.prepareStatement(query);
  1022. statement.execute();
  1023. statement.close();
  1024. }
  1025. }
  1026. } catch (Exception e)
  1027. {
  1028. _log.info("Error adding seed production data for castle " + getName() +": " + e.getMessage());
  1029. } finally {
  1030. try { con.close(); } catch (Exception e) {}
  1031. }
  1032. }
  1033. //save crop procure data
  1034. public void saveCropData()
  1035. {
  1036. java.sql.Connection con = null;
  1037. PreparedStatement statement;
  1038. try
  1039. {
  1040. con = L2DatabaseFactory.getInstance().getConnection();
  1041. statement = con.prepareStatement(CASTLE_MANOR_DELETE_PROCURE);
  1042. statement.setInt(1, getCastleId());
  1043. statement.execute();
  1044. statement.close();
  1045. if (_procure != null)
  1046. {
  1047. int count = 0;
  1048. String query = "INSERT INTO castle_manor_procure VALUES ";
  1049. String values[] = new String[_procure.size()];
  1050. for (CropProcure cp : _procure)
  1051. {
  1052. values[count] = "("+getCastleId()+","+cp.getId()+","+cp.getAmount()+","+cp.getStartAmount()+","+cp.getPrice()+","+cp.getReward()+","+CastleManorManager.PERIOD_CURRENT+")";
  1053. count++;
  1054. }
  1055. if (values.length > 0)
  1056. {
  1057. query += values[0];
  1058. for (int i=1;i<values.length;i++)
  1059. {
  1060. query += "," + values[i];
  1061. }
  1062. statement = con.prepareStatement(query);
  1063. statement.execute();
  1064. statement.close();
  1065. }
  1066. }
  1067. if (_procureNext != null)
  1068. {
  1069. int count = 0;
  1070. String query = "INSERT INTO castle_manor_procure VALUES ";
  1071. String values[] = new String[_procureNext.size()];
  1072. for (CropProcure cp : _procureNext)
  1073. {
  1074. values[count] = "("+getCastleId()+","+cp.getId()+","+cp.getAmount()+","+cp.getStartAmount()+","+cp.getPrice()+","+cp.getReward()+","+CastleManorManager.PERIOD_NEXT+")";
  1075. count++;
  1076. }
  1077. if (values.length > 0)
  1078. {
  1079. query += values[0];
  1080. for (int i=1;i<values.length;i++)
  1081. {
  1082. query += "," + values[i];
  1083. }
  1084. statement = con.prepareStatement(query);
  1085. statement.execute();
  1086. statement.close();
  1087. }
  1088. }
  1089. } catch (Exception e) {
  1090. _log.info("Error adding crop data for castle " + getName() +": " + e.getMessage());
  1091. } finally {
  1092. try {
  1093. con.close();
  1094. } catch (Exception e) { }
  1095. }
  1096. }
  1097. // save crop procure data for specified period
  1098. public void saveCropData(int period) {
  1099. java.sql.Connection con = null;
  1100. PreparedStatement statement;
  1101. try
  1102. {
  1103. con = L2DatabaseFactory.getInstance().getConnection();
  1104. statement = con.prepareStatement(CASTLE_MANOR_DELETE_PROCURE_PERIOD);
  1105. statement.setInt(1, getCastleId());
  1106. statement.setInt(2, period);
  1107. statement.execute();
  1108. statement.close();
  1109. FastList<CropProcure> proc = null;
  1110. proc = getCropProcure(period);
  1111. if (proc != null)
  1112. {
  1113. int count = 0;
  1114. String query = "INSERT INTO castle_manor_procure VALUES ";
  1115. String values[] = new String[proc.size()];
  1116. for (CropProcure cp : proc)
  1117. {
  1118. values[count] = "("+getCastleId()+","+cp.getId()+","+cp.getAmount()+","+cp.getStartAmount()+","+cp.getPrice()+","+cp.getReward()+","+period+")";
  1119. count++;
  1120. }
  1121. if (values.length > 0)
  1122. {
  1123. query += values[0];
  1124. for (int i=1;i<values.length;i++)
  1125. {
  1126. query += "," + values[i];
  1127. }
  1128. statement = con.prepareStatement(query);
  1129. statement.execute();
  1130. statement.close();
  1131. }
  1132. }
  1133. } catch (Exception e) {
  1134. _log.info("Error adding crop data for castle " + getName() +": " + e.getMessage());
  1135. } finally {
  1136. try {
  1137. con.close();
  1138. } catch (Exception e) { }
  1139. }
  1140. }
  1141. public void updateCrop (int cropId, int amount, int period)
  1142. {
  1143. java.sql.Connection con = null;
  1144. PreparedStatement statement;
  1145. try
  1146. {
  1147. con = L2DatabaseFactory.getInstance().getConnection();
  1148. statement = con.prepareStatement(CASTLE_UPDATE_CROP);
  1149. statement.setInt(1, amount);
  1150. statement.setInt(2, cropId);
  1151. statement.setInt(3, getCastleId());
  1152. statement.setInt(4, period);
  1153. statement.execute();
  1154. statement.close();
  1155. } catch (Exception e) {
  1156. _log.info("Error adding crop data for castle " + getName() +": " + e.getMessage());
  1157. } finally {
  1158. try {
  1159. con.close();
  1160. } catch (Exception e) { }
  1161. }
  1162. }
  1163. public void updateSeed (int seedId, int amount, int period)
  1164. {
  1165. java.sql.Connection con = null;
  1166. PreparedStatement statement;
  1167. try
  1168. {
  1169. con = L2DatabaseFactory.getInstance().getConnection();
  1170. statement = con.prepareStatement(CASTLE_UPDATE_SEED);
  1171. statement.setInt(1, amount);
  1172. statement.setInt(2, seedId);
  1173. statement.setInt(3, getCastleId());
  1174. statement.setInt(4, period);
  1175. statement.execute();
  1176. statement.close();
  1177. } catch (Exception e) {
  1178. _log.info("Error adding seed production data for castle " + getName() +": " + e.getMessage());
  1179. } finally {
  1180. try {
  1181. con.close();
  1182. } catch (Exception e) { }
  1183. }
  1184. }
  1185. public boolean isNextPeriodApproved()
  1186. {
  1187. return _isNextPeriodApproved;
  1188. }
  1189. public void setNextPeriodApproved(boolean val)
  1190. {
  1191. _isNextPeriodApproved = val;
  1192. }
  1193. public void updateClansReputation()
  1194. {
  1195. if (_formerOwner != null )
  1196. {
  1197. if (_formerOwner != ClanTable.getInstance().getClan(getOwnerId()))
  1198. {
  1199. int maxreward = Math.max(0,_formerOwner.getReputationScore());
  1200. _formerOwner.setReputationScore(_formerOwner.getReputationScore()-1000, true);
  1201. L2Clan owner = ClanTable.getInstance().getClan(getOwnerId());
  1202. if (owner != null)
  1203. {
  1204. owner.setReputationScore(owner.getReputationScore()+Math.min(1000,maxreward), true);
  1205. owner.broadcastToOnlineMembers(new PledgeShowInfoUpdate(owner));
  1206. }
  1207. }
  1208. else
  1209. _formerOwner.setReputationScore(_formerOwner.getReputationScore()+500, true);
  1210. _formerOwner.broadcastToOnlineMembers(new PledgeShowInfoUpdate(_formerOwner));
  1211. }
  1212. else
  1213. {
  1214. L2Clan owner = ClanTable.getInstance().getClan(getOwnerId());
  1215. if (owner != null)
  1216. {
  1217. owner.setReputationScore(owner.getReputationScore()+1000, true);
  1218. owner.broadcastToOnlineMembers(new PledgeShowInfoUpdate(owner));
  1219. }
  1220. }
  1221. }
  1222. }