RainbowSpringsChateau.java 24 KB

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