RainbowSpringsChateau.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  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. // TODO(Zoey76): Rewrite this to prevent exploits...
  524. // else if (event.startsWith("getItem"))
  525. // {
  526. // if (!_pendingItemToGet.containsKey(clan))
  527. // {
  528. // html = "yeti_cannot_exchange.htm";
  529. // }
  530. //
  531. // int left = _pendingItemToGet.get(clan);
  532. // if (left > 0)
  533. // {
  534. // int itemId = Integer.parseInt(event.split("_")[1]);
  535. // player.addItem("Rainbow Spring Chateau Siege", itemId, 1, npc, true);
  536. // --left;
  537. // _pendingItemToGet.put(clan, left);
  538. // html = "yeti_main.htm";
  539. // }
  540. // else
  541. // {
  542. // html = "yeti_cannot_exchange.htm";
  543. // }
  544. // }
  545. return html;
  546. }
  547. @Override
  548. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  549. {
  550. if (!_rainbow.isInSiege())
  551. {
  552. return null;
  553. }
  554. final L2Clan clan = killer.getClan();
  555. if ((clan == null) || !_acceptedClans.contains(clan))
  556. {
  557. return null;
  558. }
  559. final int npcId = npc.getId();
  560. final int index = _acceptedClans.indexOf(clan);
  561. if (npcId == CHEST)
  562. {
  563. shoutRandomText(npc);
  564. }
  565. else if (npcId == GOURDS[index])
  566. {
  567. synchronized (this)
  568. {
  569. if (_siegeEnd != null)
  570. {
  571. _siegeEnd.cancel(false);
  572. }
  573. ThreadPoolManager.getInstance().executeGeneral(new SiegeEnd(clan));
  574. }
  575. }
  576. return null;
  577. }
  578. @Override
  579. public String onItemUse(L2Item item, L2PcInstance player)
  580. {
  581. if (!_rainbow.isInSiege())
  582. {
  583. return null;
  584. }
  585. L2Object target = player.getTarget();
  586. if ((target == null) || !(target instanceof L2Npc))
  587. {
  588. return null;
  589. }
  590. int yeti = target.getId();
  591. if (!isYetiTarget(yeti))
  592. {
  593. return null;
  594. }
  595. final L2Clan clan = player.getClan();
  596. if ((clan == null) || !_acceptedClans.contains(clan))
  597. {
  598. return null;
  599. }
  600. // Nectar must spawn the enraged yeti. Dunno if it makes any other thing
  601. // Also, the items must execute:
  602. // - Reduce gourd hpb ( reduceGourdHp(int, L2PcInstance) )
  603. // - Cast debuffs on enemy clans ( castDebuffsOnEnemies(int) )
  604. // - Change arena gourds ( moveGourds() )
  605. // - Increase gourd hp ( increaseGourdHp(int) )
  606. final int itemId = item.getId();
  607. if (itemId == RAINBOW_NECTAR)
  608. {
  609. // Spawn enraged (where?)
  610. reduceGourdHp(_acceptedClans.indexOf(clan), player);
  611. }
  612. else if (itemId == RAINBOW_MWATER)
  613. {
  614. increaseGourdHp(_acceptedClans.indexOf(clan));
  615. }
  616. else if (itemId == RAINBOW_WATER)
  617. {
  618. moveGourds();
  619. }
  620. else if (itemId == RAINBOW_SULFUR)
  621. {
  622. castDebuffsOnEnemies(_acceptedClans.indexOf(clan));
  623. }
  624. return null;
  625. }
  626. private void portToArena(L2PcInstance leader, int arena)
  627. {
  628. if ((arena < 0) || (arena > 3))
  629. {
  630. _log.warning("RainbowSptringChateau siege: Wrong arena id passed: " + arena);
  631. return;
  632. }
  633. for (L2PcInstance pc : leader.getParty().getMembers())
  634. {
  635. if (pc != null)
  636. {
  637. pc.stopAllEffects();
  638. if (pc.hasSummon())
  639. {
  640. pc.getSummon().unSummon(pc);
  641. }
  642. pc.teleToLocation(ARENAS[arena]);
  643. }
  644. }
  645. }
  646. protected static void spawnGourds()
  647. {
  648. for (int i = 0; i < _acceptedClans.size(); i++)
  649. {
  650. if (_gourds[i] == null)
  651. {
  652. try
  653. {
  654. _gourds[i] = new L2Spawn(GOURDS[i]);
  655. _gourds[i].setX(ARENAS[i].getX() + 150);
  656. _gourds[i].setY(ARENAS[i].getY() + 150);
  657. _gourds[i].setZ(ARENAS[i].getZ());
  658. _gourds[i].setHeading(1);
  659. _gourds[i].setAmount(1);
  660. }
  661. catch (Exception e)
  662. {
  663. e.printStackTrace();
  664. }
  665. }
  666. SpawnTable.getInstance().addNewSpawn(_gourds[i], false);
  667. _gourds[i].init();
  668. }
  669. }
  670. protected static void unSpawnGourds()
  671. {
  672. for (int i = 0; i < _acceptedClans.size(); i++)
  673. {
  674. _gourds[i].getLastSpawn().deleteMe();
  675. SpawnTable.getInstance().deleteSpawn(_gourds[i], false);
  676. }
  677. }
  678. private static void moveGourds()
  679. {
  680. L2Spawn[] tempArray = _gourds;
  681. int iterator = _acceptedClans.size();
  682. for (int i = 0; i < iterator; i++)
  683. {
  684. L2Spawn oldSpawn = _gourds[(iterator - 1) - i];
  685. L2Spawn curSpawn = tempArray[i];
  686. _gourds[(iterator - 1) - i] = curSpawn;
  687. curSpawn.getLastSpawn().teleToLocation(oldSpawn.getLocation());
  688. }
  689. }
  690. private static void reduceGourdHp(int index, L2PcInstance player)
  691. {
  692. L2Spawn gourd = _gourds[index];
  693. gourd.getLastSpawn().reduceCurrentHp(1000, player, null);
  694. }
  695. private static void increaseGourdHp(int index)
  696. {
  697. L2Spawn gourd = _gourds[index];
  698. L2Npc gourdNpc = gourd.getLastSpawn();
  699. gourdNpc.setCurrentHp(gourdNpc.getCurrentHp() + 1000);
  700. }
  701. private static void castDebuffsOnEnemies(int myArena)
  702. {
  703. for (int id : ARENA_ZONES)
  704. {
  705. if (id == myArena)
  706. {
  707. continue;
  708. }
  709. final Collection<L2Character> chars = ZoneManager.getInstance().getZoneById(id).getCharactersInside();
  710. for (L2Character chr : chars)
  711. {
  712. if (chr != null)
  713. {
  714. for (Skill sk : DEBUFFS)
  715. {
  716. sk.applyEffects(chr, chr);
  717. }
  718. }
  719. }
  720. }
  721. }
  722. private static void shoutRandomText(L2Npc npc)
  723. {
  724. int length = _textPassages.length;
  725. if (_usedTextPassages.size() >= length)
  726. {
  727. return;
  728. }
  729. int randomPos = getRandom(length);
  730. String message = _textPassages[randomPos];
  731. if (_usedTextPassages.containsKey(message))
  732. {
  733. shoutRandomText(npc);
  734. }
  735. else
  736. {
  737. _usedTextPassages.put(message, new ArrayList<L2Clan>());
  738. int shout = Say2.NPC_SHOUT;
  739. int objId = npc.getObjectId();
  740. NpcSay say = new NpcSay(objId, shout, npc.getId(), message);
  741. npc.broadcastPacket(say);
  742. }
  743. }
  744. private static boolean isValidPassage(String text)
  745. {
  746. for (String st : _textPassages)
  747. {
  748. if (st.equalsIgnoreCase(text))
  749. {
  750. return true;
  751. }
  752. }
  753. return false;
  754. }
  755. private static boolean isYetiTarget(int npcId)
  756. {
  757. for (int yeti : YETIS)
  758. {
  759. if (yeti == npcId)
  760. {
  761. return true;
  762. }
  763. }
  764. return false;
  765. }
  766. private static void updateAttacker(int clanId, long count, boolean remove)
  767. {
  768. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  769. {
  770. PreparedStatement statement;
  771. if (remove)
  772. {
  773. statement = con.prepareStatement("DELETE FROM rainbowsprings_attacker_list WHERE clanId = ?");
  774. statement.setInt(1, clanId);
  775. }
  776. else
  777. {
  778. statement = con.prepareStatement("INSERT INTO rainbowsprings_attacker_list VALUES (?,?)");
  779. statement.setInt(1, clanId);
  780. statement.setLong(2, count);
  781. }
  782. statement.execute();
  783. statement.close();
  784. }
  785. catch (Exception e)
  786. {
  787. e.printStackTrace();
  788. }
  789. }
  790. @Override
  791. public void loadAttackers()
  792. {
  793. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  794. {
  795. PreparedStatement statement = con.prepareStatement("SELECT * FROM rainbowsprings_attacker_list");
  796. ResultSet rset = statement.executeQuery();
  797. while (rset.next())
  798. {
  799. int clanId = rset.getInt("clan_id");
  800. long count = rset.getLong("decrees_count");
  801. _warDecreesCount.put(clanId, count);
  802. }
  803. rset.close();
  804. statement.close();
  805. }
  806. catch (Exception e)
  807. {
  808. e.printStackTrace();
  809. }
  810. }
  811. protected static void setRegistrationEndString(long time)
  812. {
  813. Calendar c = Calendar.getInstance();
  814. c.setTime(new Date(time));
  815. int year = c.get(Calendar.YEAR);
  816. int month = c.get(Calendar.MONTH) + 1;
  817. int day = c.get(Calendar.DAY_OF_MONTH);
  818. int hour = c.get(Calendar.HOUR);
  819. int mins = c.get(Calendar.MINUTE);
  820. _registrationEnds = year + "-" + month + "-" + day + " " + hour + (mins < 10 ? ":0" : ":") + mins;
  821. }
  822. public static void launchSiege()
  823. {
  824. _nextSiege.cancel(false);
  825. ThreadPoolManager.getInstance().executeGeneral(new SiegeStart());
  826. }
  827. @Override
  828. public void endSiege()
  829. {
  830. if (_siegeEnd != null)
  831. {
  832. _siegeEnd.cancel(false);
  833. }
  834. ThreadPoolManager.getInstance().executeGeneral(new SiegeEnd(null));
  835. }
  836. public static void updateAdminDate(long date)
  837. {
  838. if (_rainbow == null)
  839. {
  840. _rainbow = CHSiegeManager.getInstance().getSiegableHall(RAINBOW_SPRINGS);
  841. }
  842. _rainbow.setNextSiegeDate(date);
  843. if (_nextSiege != null)
  844. {
  845. _nextSiege.cancel(true);
  846. }
  847. date -= 3600000;
  848. setRegistrationEndString(date);
  849. _nextSiege = ThreadPoolManager.getInstance().scheduleGeneral(new SetFinalAttackers(), _rainbow.getNextSiegeTime());
  850. }
  851. public static void main(String[] args)
  852. {
  853. new RainbowSpringsChateau();
  854. }
  855. }