RainbowSpringsChateau.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package conquerablehalls.RainbowSpringsChateau;
  20. import java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.sql.ResultSet;
  23. import java.sql.Statement;
  24. import java.util.ArrayList;
  25. import java.util.Calendar;
  26. import java.util.Collection;
  27. import java.util.Date;
  28. import java.util.HashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. import java.util.concurrent.ScheduledFuture;
  32. import com.l2jserver.Config;
  33. import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
  34. import com.l2jserver.gameserver.ThreadPoolManager;
  35. import com.l2jserver.gameserver.cache.HtmCache;
  36. import com.l2jserver.gameserver.data.sql.impl.ClanTable;
  37. import com.l2jserver.gameserver.datatables.SpawnTable;
  38. import com.l2jserver.gameserver.instancemanager.CHSiegeManager;
  39. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  40. import com.l2jserver.gameserver.model.L2Clan;
  41. import com.l2jserver.gameserver.model.L2Object;
  42. import com.l2jserver.gameserver.model.L2Party;
  43. import com.l2jserver.gameserver.model.L2Spawn;
  44. import com.l2jserver.gameserver.model.Location;
  45. import com.l2jserver.gameserver.model.TeleportWhereType;
  46. import com.l2jserver.gameserver.model.actor.L2Character;
  47. import com.l2jserver.gameserver.model.actor.L2Npc;
  48. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  49. import com.l2jserver.gameserver.model.entity.clanhall.ClanHallSiegeEngine;
  50. import com.l2jserver.gameserver.model.entity.clanhall.SiegableHall;
  51. import com.l2jserver.gameserver.model.entity.clanhall.SiegeStatus;
  52. import com.l2jserver.gameserver.model.items.L2Item;
  53. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  54. import com.l2jserver.gameserver.model.skills.Skill;
  55. import com.l2jserver.gameserver.network.clientpackets.Say2;
  56. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  57. import com.l2jserver.gameserver.util.Broadcast;
  58. import com.l2jserver.gameserver.util.Util;
  59. /**
  60. * Rainbow Springs Chateau clan hall siege script.
  61. * @author BiggBoss
  62. */
  63. public final class RainbowSpringsChateau extends ClanHallSiegeEngine
  64. {
  65. protected static class SetFinalAttackers implements Runnable
  66. {
  67. @Override
  68. public void run()
  69. {
  70. if (_rainbow == null)
  71. {
  72. _rainbow = CHSiegeManager.getInstance().getSiegableHall(RAINBOW_SPRINGS);
  73. }
  74. int spotLeft = 4;
  75. if (_rainbow.getOwnerId() > 0)
  76. {
  77. L2Clan owner = ClanTable.getInstance().getClan(_rainbow.getOwnerId());
  78. if (owner != null)
  79. {
  80. _rainbow.free();
  81. owner.setHideoutId(0);
  82. _acceptedClans.add(owner);
  83. --spotLeft;
  84. }
  85. for (int i = 0; i < spotLeft; i++)
  86. {
  87. long counter = 0;
  88. L2Clan clan = null;
  89. for (int clanId : _warDecreesCount.keySet())
  90. {
  91. L2Clan actingClan = ClanTable.getInstance().getClan(clanId);
  92. if ((actingClan == null) || (actingClan.getDissolvingExpiryTime() > 0))
  93. {
  94. _warDecreesCount.remove(clanId);
  95. continue;
  96. }
  97. final long count = _warDecreesCount.get(clanId);
  98. if (count > counter)
  99. {
  100. counter = count;
  101. clan = actingClan;
  102. }
  103. }
  104. if ((clan != null) && (_acceptedClans.size() < 4))
  105. {
  106. _acceptedClans.add(clan);
  107. L2PcInstance leader = clan.getLeader().getPlayerInstance();
  108. if (leader != null)
  109. {
  110. leader.sendMessage("Your clan has been accepted to join the RainBow Srpings Chateau siege!");
  111. }
  112. }
  113. }
  114. if (_acceptedClans.size() >= 2)
  115. {
  116. _nextSiege = ThreadPoolManager.getInstance().scheduleGeneral(new SiegeStart(), 3600000);
  117. _rainbow.updateSiegeStatus(SiegeStatus.WAITING_BATTLE);
  118. }
  119. else
  120. {
  121. Broadcast.toAllOnlinePlayers("Rainbow Springs Chateau siege aborted due lack of population");
  122. }
  123. }
  124. }
  125. }
  126. protected static class SiegeStart implements Runnable
  127. {
  128. @Override
  129. public void run()
  130. {
  131. if (_rainbow == null)
  132. {
  133. _rainbow = CHSiegeManager.getInstance().getSiegableHall(RAINBOW_SPRINGS);
  134. }
  135. // XXX _rainbow.siegeStarts();
  136. spawnGourds();
  137. _siegeEnd = ThreadPoolManager.getInstance().scheduleGeneral(new SiegeEnd(null), _rainbow.getSiegeLenght() - 120000);
  138. }
  139. }
  140. public static L2Clan _winner;
  141. @Override
  142. public L2Clan getWinner()
  143. {
  144. return _winner;
  145. }
  146. private static class SiegeEnd implements Runnable
  147. {
  148. private final L2Clan _winner;
  149. protected SiegeEnd(L2Clan winner)
  150. {
  151. _winner = winner;
  152. }
  153. @Override
  154. public void run()
  155. {
  156. if (_rainbow == null)
  157. {
  158. _rainbow = CHSiegeManager.getInstance().getSiegableHall(RAINBOW_SPRINGS);
  159. }
  160. unSpawnGourds();
  161. if (_winner != null)
  162. {
  163. _rainbow.setOwner(_winner);
  164. }
  165. // XXX _rainbow.siegeEnds();
  166. ThreadPoolManager.getInstance().scheduleGeneral(new SetFinalAttackers(), _rainbow.getNextSiegeTime());
  167. setRegistrationEndString((_rainbow.getNextSiegeTime() + System.currentTimeMillis()) - 3600000);
  168. // Teleport out of the arenas is made 2 mins after game ends
  169. ThreadPoolManager.getInstance().scheduleGeneral(new TeleportBack(), 120000);
  170. }
  171. }
  172. protected static class TeleportBack implements Runnable
  173. {
  174. @Override
  175. public void run()
  176. {
  177. for (int arenaId : ARENA_ZONES)
  178. {
  179. final Collection<L2Character> chars = ZoneManager.getInstance().getZoneById(arenaId).getCharactersInside();
  180. for (L2Character chr : chars)
  181. {
  182. if (chr != null)
  183. {
  184. chr.teleToLocation(TeleportWhereType.TOWN);
  185. }
  186. }
  187. }
  188. }
  189. }
  190. private static final int RAINBOW_SPRINGS = 62;
  191. private static final int WAR_DECREES = 8034;
  192. private static final int RAINBOW_NECTAR = 8030;
  193. private static final int RAINBOW_MWATER = 8031;
  194. private static final int RAINBOW_WATER = 8032;
  195. private static final int RAINBOW_SULFUR = 8033;
  196. private static final int MESSENGER = 35604;
  197. private static final int CARETAKER = 35603;
  198. private static final int CHEST = 35593;
  199. private static final int[] GOURDS =
  200. {
  201. 35588,
  202. 35589,
  203. 35590,
  204. 35591
  205. };
  206. private static L2Spawn[] _gourds = new L2Spawn[4];
  207. private static final int[] YETIS =
  208. {
  209. 35596,
  210. 35597,
  211. 35598,
  212. 35599
  213. };
  214. private static final Location[] ARENAS = new Location[]
  215. {
  216. new Location(151562, -127080, -2214), // Arena 1
  217. new Location(153141, -125335, -2214), // Arena 2
  218. new Location(153892, -127530, -2214), // Arena 3
  219. new Location(155657, -125752, -2214), // Arena 4
  220. };
  221. protected static final int[] ARENA_ZONES =
  222. {
  223. 112081,
  224. 112082,
  225. 112083,
  226. 112084
  227. };
  228. private static final String[] _textPassages =
  229. {
  230. "Fight for Rainbow Springs!",
  231. "Are you a match for the Yetti?",
  232. "Did somebody order a knuckle sandwich?"
  233. };
  234. private static final Skill[] DEBUFFS = {};
  235. protected static Map<Integer, Long> _warDecreesCount = new HashMap<>();
  236. protected static List<L2Clan> _acceptedClans = new ArrayList<>(4);
  237. private static Map<String, ArrayList<L2Clan>> _usedTextPassages = new HashMap<>();
  238. private static Map<L2Clan, Integer> _pendingItemToGet = new HashMap<>();
  239. protected static SiegableHall _rainbow;
  240. protected static ScheduledFuture<?> _nextSiege, _siegeEnd;
  241. private static String _registrationEnds;
  242. public RainbowSpringsChateau()
  243. {
  244. super(RainbowSpringsChateau.class.getSimpleName(), "conquerablehalls", RAINBOW_SPRINGS);
  245. addFirstTalkId(MESSENGER);
  246. addTalkId(MESSENGER);
  247. addFirstTalkId(CARETAKER);
  248. addTalkId(CARETAKER);
  249. addFirstTalkId(YETIS);
  250. addTalkId(YETIS);
  251. loadAttackers();
  252. _rainbow = CHSiegeManager.getInstance().getSiegableHall(RAINBOW_SPRINGS);
  253. if (_rainbow != null)
  254. {
  255. long delay = _rainbow.getNextSiegeTime();
  256. if (delay > -1)
  257. {
  258. setRegistrationEndString(delay - 3600000);
  259. _nextSiege = ThreadPoolManager.getInstance().scheduleGeneral(new SetFinalAttackers(), delay);
  260. }
  261. else
  262. {
  263. _log.warning("CHSiegeManager: No Date setted for RainBow Springs Chateau Clan hall siege!. SIEGE CANCELED!");
  264. }
  265. }
  266. }
  267. @Override
  268. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  269. {
  270. String html = "";
  271. final int npcId = npc.getId();
  272. if (npcId == MESSENGER)
  273. {
  274. final String main = (_rainbow.getOwnerId() > 0) ? "messenger_yetti001.htm" : "messenger_yetti001a.htm";
  275. html = HtmCache.getInstance().getHtm(player.getHtmlPrefix(), "data/scripts/conquerablehalls/RainbowSpringsChateau/" + main);
  276. html = html.replace("%time%", _registrationEnds);
  277. if (_rainbow.getOwnerId() > 0)
  278. {
  279. html = html.replace("%owner%", ClanTable.getInstance().getClan(_rainbow.getOwnerId()).getName());
  280. }
  281. }
  282. else if (npcId == CARETAKER)
  283. {
  284. if (_rainbow.isInSiege())
  285. {
  286. html = "game_manager003.htm";
  287. }
  288. else
  289. {
  290. html = "game_manager001.htm";
  291. }
  292. }
  293. else if (Util.contains(YETIS, npcId))
  294. {
  295. // TODO: Review.
  296. if (_rainbow.isInSiege())
  297. {
  298. if (!player.isClanLeader())
  299. {
  300. html = "no_clan_leader.htm";
  301. }
  302. else
  303. {
  304. L2Clan clan = player.getClan();
  305. if (_acceptedClans.contains(clan))
  306. {
  307. int index = _acceptedClans.indexOf(clan);
  308. if (npcId == YETIS[index])
  309. {
  310. html = "yeti_main.htm";
  311. }
  312. }
  313. }
  314. }
  315. }
  316. player.setLastQuestNpcObject(npc.getObjectId());
  317. return html;
  318. }
  319. @Override
  320. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  321. {
  322. String html = event;
  323. final L2Clan clan = player.getClan();
  324. switch (npc.getId())
  325. {
  326. case MESSENGER:
  327. switch (event)
  328. {
  329. case "register":
  330. if (!player.isClanLeader())
  331. {
  332. html = "messenger_yetti010.htm";
  333. }
  334. else if ((clan.getCastleId() > 0) || (clan.getFortId() > 0) || (clan.getHideoutId() > 0))
  335. {
  336. html = "messenger_yetti012.htm";
  337. }
  338. else if (!_rainbow.isRegistering())
  339. {
  340. html = "messenger_yetti014.htm";
  341. }
  342. else if (_warDecreesCount.containsKey(clan.getId()))
  343. {
  344. html = "messenger_yetti013.htm";
  345. }
  346. else if ((clan.getLevel() < 3) || (clan.getMembersCount() < 5))
  347. {
  348. html = "messenger_yetti011.htm";
  349. }
  350. else
  351. {
  352. final L2ItemInstance warDecrees = player.getInventory().getItemByItemId(WAR_DECREES);
  353. if (warDecrees == null)
  354. {
  355. html = "messenger_yetti008.htm";
  356. }
  357. else
  358. {
  359. long count = warDecrees.getCount();
  360. _warDecreesCount.put(clan.getId(), count);
  361. player.destroyItem("Rainbow Springs Registration", warDecrees, npc, true);
  362. addAttacker(clan.getId(), count);
  363. html = "messenger_yetti009.htm";
  364. }
  365. }
  366. break;
  367. case "cancel":
  368. if (!player.isClanLeader())
  369. {
  370. html = "messenger_yetti010.htm";
  371. }
  372. else if (!_warDecreesCount.containsKey(clan.getId()))
  373. {
  374. html = "messenger_yetti016.htm";
  375. }
  376. else if (!_rainbow.isRegistering())
  377. {
  378. html = "messenger_yetti017.htm";
  379. }
  380. else
  381. {
  382. removeAttacker(clan.getId());
  383. html = "messenger_yetti018.htm";
  384. }
  385. break;
  386. case "unregister":
  387. if (_rainbow.isRegistering())
  388. {
  389. if (_warDecreesCount.containsKey(clan.getId()))
  390. {
  391. player.addItem("Rainbow Spring unregister", WAR_DECREES, _warDecreesCount.get(clan.getId()) / 2, npc, true);
  392. _warDecreesCount.remove(clan.getId());
  393. html = "messenger_yetti019.htm";
  394. }
  395. else
  396. {
  397. html = "messenger_yetti020.htm";
  398. }
  399. }
  400. else if (_rainbow.isWaitingBattle())
  401. {
  402. _acceptedClans.remove(clan);
  403. html = "messenger_yetti020.htm";
  404. }
  405. break;
  406. }
  407. break;
  408. case CARETAKER:
  409. if (event.equals("portToArena"))
  410. {
  411. final L2Party party = player.getParty();
  412. if (clan == null)
  413. {
  414. html = "game_manager009.htm";
  415. }
  416. else if (!player.isClanLeader())
  417. {
  418. html = "game_manager004.htm";
  419. }
  420. else if (!player.isInParty())
  421. {
  422. html = "game_manager005.htm";
  423. }
  424. else if (party.getLeaderObjectId() != player.getObjectId())
  425. {
  426. html = "game_manager006.htm";
  427. }
  428. else
  429. {
  430. final int clanId = player.getClanId();
  431. boolean nonClanMemberInParty = false;
  432. for (L2PcInstance member : party.getMembers())
  433. {
  434. if (member.getClanId() != clanId)
  435. {
  436. nonClanMemberInParty = true;
  437. break;
  438. }
  439. }
  440. if (nonClanMemberInParty)
  441. {
  442. html = "game_manager007.htm";
  443. }
  444. else if (party.getMemberCount() < 5)
  445. {
  446. html = "game_manager008.htm";
  447. }
  448. else if ((clan.getCastleId() > 0) || (clan.getFortId() > 0) || (clan.getHideoutId() > 0))
  449. {
  450. html = "game_manager010.htm";
  451. }
  452. else if (clan.getLevel() < Config.CHS_CLAN_MINLEVEL)
  453. {
  454. html = "game_manager011.htm";
  455. }
  456. // else if () // Something about the rules.
  457. // {
  458. // html = "game_manager012.htm";
  459. // }
  460. // else if () // Already registered.
  461. // {
  462. // html = "game_manager013.htm";
  463. // }
  464. else if (!_acceptedClans.contains(clan))
  465. {
  466. html = "game_manager014.htm";
  467. }
  468. // else if () // Not have enough cards to register.
  469. // {
  470. // html = "game_manager015.htm";
  471. // }
  472. else
  473. {
  474. portToArena(player, _acceptedClans.indexOf(clan));
  475. }
  476. }
  477. }
  478. break;
  479. }
  480. if (event.startsWith("enterText"))
  481. {
  482. // Shouldn't happen
  483. if (!_acceptedClans.contains(clan))
  484. {
  485. return null;
  486. }
  487. String[] split = event.split("_ ");
  488. if (split.length < 2)
  489. {
  490. return null;
  491. }
  492. final String passage = split[1];
  493. if (!isValidPassage(passage))
  494. {
  495. return null;
  496. }
  497. if (_usedTextPassages.containsKey(passage))
  498. {
  499. ArrayList<L2Clan> list = _usedTextPassages.get(passage);
  500. if (list.contains(clan))
  501. {
  502. html = "yeti_passage_used.htm";
  503. }
  504. else
  505. {
  506. list.add(clan);
  507. synchronized (_pendingItemToGet)
  508. {
  509. if (_pendingItemToGet.containsKey(clan))
  510. {
  511. int left = _pendingItemToGet.get(clan);
  512. ++left;
  513. _pendingItemToGet.put(clan, left);
  514. }
  515. else
  516. {
  517. _pendingItemToGet.put(clan, 1);
  518. }
  519. }
  520. html = "yeti_item_exchange.htm";
  521. }
  522. }
  523. }
  524. // TODO(Zoey76): Rewrite this to prevent exploits...
  525. // else if (event.startsWith("getItem"))
  526. // {
  527. // if (!_pendingItemToGet.containsKey(clan))
  528. // {
  529. // html = "yeti_cannot_exchange.htm";
  530. // }
  531. //
  532. // int left = _pendingItemToGet.get(clan);
  533. // if (left > 0)
  534. // {
  535. // int itemId = Integer.parseInt(event.split("_")[1]);
  536. // player.addItem("Rainbow Spring Chateau Siege", itemId, 1, npc, true);
  537. // --left;
  538. // _pendingItemToGet.put(clan, left);
  539. // html = "yeti_main.htm";
  540. // }
  541. // else
  542. // {
  543. // html = "yeti_cannot_exchange.htm";
  544. // }
  545. // }
  546. return html;
  547. }
  548. @Override
  549. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  550. {
  551. if (!_rainbow.isInSiege())
  552. {
  553. return null;
  554. }
  555. final L2Clan clan = killer.getClan();
  556. if ((clan == null) || !_acceptedClans.contains(clan))
  557. {
  558. return null;
  559. }
  560. final int npcId = npc.getId();
  561. final int index = _acceptedClans.indexOf(clan);
  562. if (npcId == CHEST)
  563. {
  564. shoutRandomText(npc);
  565. }
  566. else if (npcId == GOURDS[index])
  567. {
  568. synchronized (this)
  569. {
  570. if (_siegeEnd != null)
  571. {
  572. _siegeEnd.cancel(false);
  573. }
  574. ThreadPoolManager.getInstance().executeGeneral(new SiegeEnd(clan));
  575. }
  576. }
  577. return null;
  578. }
  579. @Override
  580. public String onItemUse(L2Item item, L2PcInstance player)
  581. {
  582. if (!_rainbow.isInSiege())
  583. {
  584. return null;
  585. }
  586. L2Object target = player.getTarget();
  587. if ((target == null) || !(target instanceof L2Npc))
  588. {
  589. return null;
  590. }
  591. int yeti = target.getId();
  592. if (!isYetiTarget(yeti))
  593. {
  594. return null;
  595. }
  596. final L2Clan clan = player.getClan();
  597. if ((clan == null) || !_acceptedClans.contains(clan))
  598. {
  599. return null;
  600. }
  601. // Nectar must spawn the enraged yeti. Dunno if it makes any other thing
  602. // Also, the items must execute:
  603. // - Reduce gourd hpb ( reduceGourdHp(int, L2PcInstance) )
  604. // - Cast debuffs on enemy clans ( castDebuffsOnEnemies(int) )
  605. // - Change arena gourds ( moveGourds() )
  606. // - Increase gourd hp ( increaseGourdHp(int) )
  607. final int itemId = item.getId();
  608. if (itemId == RAINBOW_NECTAR)
  609. {
  610. // Spawn enraged (where?)
  611. reduceGourdHp(_acceptedClans.indexOf(clan), player);
  612. }
  613. else if (itemId == RAINBOW_MWATER)
  614. {
  615. increaseGourdHp(_acceptedClans.indexOf(clan));
  616. }
  617. else if (itemId == RAINBOW_WATER)
  618. {
  619. moveGourds();
  620. }
  621. else if (itemId == RAINBOW_SULFUR)
  622. {
  623. castDebuffsOnEnemies(_acceptedClans.indexOf(clan));
  624. }
  625. return null;
  626. }
  627. private void portToArena(L2PcInstance leader, int arena)
  628. {
  629. if ((arena < 0) || (arena > 3))
  630. {
  631. _log.warning("RainbowSptringChateau siege: Wrong arena id passed: " + arena);
  632. return;
  633. }
  634. for (L2PcInstance pc : leader.getParty().getMembers())
  635. {
  636. if (pc != null)
  637. {
  638. pc.stopAllEffects();
  639. if (pc.hasSummon())
  640. {
  641. pc.getSummon().unSummon(pc);
  642. }
  643. pc.teleToLocation(ARENAS[arena]);
  644. }
  645. }
  646. }
  647. protected static void spawnGourds()
  648. {
  649. for (int i = 0; i < _acceptedClans.size(); i++)
  650. {
  651. if (_gourds[i] == null)
  652. {
  653. try
  654. {
  655. _gourds[i] = new L2Spawn(GOURDS[i]);
  656. _gourds[i].setX(ARENAS[i].getX() + 150);
  657. _gourds[i].setY(ARENAS[i].getY() + 150);
  658. _gourds[i].setZ(ARENAS[i].getZ());
  659. _gourds[i].setHeading(1);
  660. _gourds[i].setAmount(1);
  661. }
  662. catch (Exception e)
  663. {
  664. e.printStackTrace();
  665. }
  666. }
  667. SpawnTable.getInstance().addNewSpawn(_gourds[i], false);
  668. _gourds[i].init();
  669. }
  670. }
  671. protected static void unSpawnGourds()
  672. {
  673. for (int i = 0; i < _acceptedClans.size(); i++)
  674. {
  675. _gourds[i].getLastSpawn().deleteMe();
  676. SpawnTable.getInstance().deleteSpawn(_gourds[i], false);
  677. }
  678. }
  679. private static void moveGourds()
  680. {
  681. L2Spawn[] tempArray = _gourds;
  682. int iterator = _acceptedClans.size();
  683. for (int i = 0; i < iterator; i++)
  684. {
  685. L2Spawn oldSpawn = _gourds[(iterator - 1) - i];
  686. L2Spawn curSpawn = tempArray[i];
  687. _gourds[(iterator - 1) - i] = curSpawn;
  688. curSpawn.getLastSpawn().teleToLocation(oldSpawn.getLocation());
  689. }
  690. }
  691. private static void reduceGourdHp(int index, L2PcInstance player)
  692. {
  693. L2Spawn gourd = _gourds[index];
  694. gourd.getLastSpawn().reduceCurrentHp(1000, player, null);
  695. }
  696. private static void increaseGourdHp(int index)
  697. {
  698. L2Spawn gourd = _gourds[index];
  699. L2Npc gourdNpc = gourd.getLastSpawn();
  700. gourdNpc.setCurrentHp(gourdNpc.getCurrentHp() + 1000);
  701. }
  702. private static void castDebuffsOnEnemies(int myArena)
  703. {
  704. for (int id : ARENA_ZONES)
  705. {
  706. if (id == myArena)
  707. {
  708. continue;
  709. }
  710. final Collection<L2Character> chars = ZoneManager.getInstance().getZoneById(id).getCharactersInside();
  711. for (L2Character chr : chars)
  712. {
  713. if (chr != null)
  714. {
  715. for (Skill sk : DEBUFFS)
  716. {
  717. sk.applyEffects(chr, chr);
  718. }
  719. }
  720. }
  721. }
  722. }
  723. private static void shoutRandomText(L2Npc npc)
  724. {
  725. int length = _textPassages.length;
  726. if (_usedTextPassages.size() >= length)
  727. {
  728. return;
  729. }
  730. int randomPos = getRandom(length);
  731. String message = _textPassages[randomPos];
  732. if (_usedTextPassages.containsKey(message))
  733. {
  734. shoutRandomText(npc);
  735. }
  736. else
  737. {
  738. _usedTextPassages.put(message, new ArrayList<L2Clan>());
  739. int shout = Say2.NPC_SHOUT;
  740. int objId = npc.getObjectId();
  741. NpcSay say = new NpcSay(objId, shout, npc.getId(), message);
  742. npc.broadcastPacket(say);
  743. }
  744. }
  745. private static boolean isValidPassage(String text)
  746. {
  747. for (String st : _textPassages)
  748. {
  749. if (st.equalsIgnoreCase(text))
  750. {
  751. return true;
  752. }
  753. }
  754. return false;
  755. }
  756. private static boolean isYetiTarget(int npcId)
  757. {
  758. return Util.contains(YETIS, npcId);
  759. }
  760. private static void removeAttacker(int clanId)
  761. {
  762. try (Connection con = ConnectionFactory.getInstance().getConnection();
  763. PreparedStatement ps = con.prepareStatement("DELETE FROM rainbowsprings_attacker_list WHERE clanId = ?"))
  764. {
  765. ps.setInt(1, clanId);
  766. ps.execute();
  767. }
  768. catch (Exception e)
  769. {
  770. e.printStackTrace();
  771. }
  772. }
  773. private static void addAttacker(int clanId, long count)
  774. {
  775. try (Connection con = ConnectionFactory.getInstance().getConnection();
  776. PreparedStatement ps = con.prepareStatement("INSERT INTO rainbowsprings_attacker_list VALUES (?,?)"))
  777. {
  778. ps.setInt(1, clanId);
  779. ps.setLong(2, count);
  780. ps.execute();
  781. }
  782. catch (Exception e)
  783. {
  784. e.printStackTrace();
  785. }
  786. }
  787. @Override
  788. public void loadAttackers()
  789. {
  790. try (Connection con = ConnectionFactory.getInstance().getConnection();
  791. Statement s = con.createStatement())
  792. {
  793. try (ResultSet rset = s.executeQuery("SELECT * FROM rainbowsprings_attacker_list"))
  794. {
  795. while (rset.next())
  796. {
  797. _warDecreesCount.put(rset.getInt("clan_id"), rset.getLong("decrees_count"));
  798. }
  799. }
  800. }
  801. catch (Exception e)
  802. {
  803. e.printStackTrace();
  804. }
  805. }
  806. protected static void setRegistrationEndString(long time)
  807. {
  808. Calendar c = Calendar.getInstance();
  809. c.setTime(new Date(time));
  810. int year = c.get(Calendar.YEAR);
  811. int month = c.get(Calendar.MONTH) + 1;
  812. int day = c.get(Calendar.DAY_OF_MONTH);
  813. int hour = c.get(Calendar.HOUR);
  814. int mins = c.get(Calendar.MINUTE);
  815. _registrationEnds = year + "-" + month + "-" + day + " " + hour + (mins < 10 ? ":0" : ":") + mins;
  816. }
  817. public static void launchSiege()
  818. {
  819. _nextSiege.cancel(false);
  820. ThreadPoolManager.getInstance().executeGeneral(new SiegeStart());
  821. }
  822. @Override
  823. public void endSiege()
  824. {
  825. if (_siegeEnd != null)
  826. {
  827. _siegeEnd.cancel(false);
  828. }
  829. ThreadPoolManager.getInstance().executeGeneral(new SiegeEnd(null));
  830. }
  831. public static void updateAdminDate(long date)
  832. {
  833. if (_rainbow == null)
  834. {
  835. _rainbow = CHSiegeManager.getInstance().getSiegableHall(RAINBOW_SPRINGS);
  836. }
  837. _rainbow.setNextSiegeDate(date);
  838. if (_nextSiege != null)
  839. {
  840. _nextSiege.cancel(true);
  841. }
  842. date -= 3600000;
  843. setRegistrationEndString(date);
  844. _nextSiege = ThreadPoolManager.getInstance().scheduleGeneral(new SetFinalAttackers(), _rainbow.getNextSiegeTime());
  845. }
  846. public static void main(String[] args)
  847. {
  848. new RainbowSpringsChateau();
  849. }
  850. }