RainbowSpringsChateau.java 24 KB

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