RainbowSpringsChateau.java 23 KB

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