RainbowSpringsChateau.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. /*
  2. * Copyright (C) 2004-2014 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.NpcData;
  39. import com.l2jserver.gameserver.datatables.SkillData;
  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.Skill;
  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 final 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 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 Location[] ARENAS = new Location[]
  212. {
  213. new Location(151562, -127080, -2214), // Arena 1
  214. new Location(153141, -125335, -2214), // Arena 2
  215. new Location(153892, -127530, -2214), // Arena 3
  216. new Location(155657, -125752, -2214), // Arena 4
  217. };
  218. protected static final int[] ARENA_ZONES =
  219. {
  220. 112081,
  221. 112082,
  222. 112083,
  223. 112084
  224. };
  225. private static final String[] _textPassages =
  226. {
  227. "Text Passage 1",
  228. "Passage Text 2",
  229. "Im getting out of ideas",
  230. "But i can write few more",
  231. "Are five sentences",
  232. "enough for this f*** siege?",
  233. "i think ill add few more",
  234. "like this one",
  235. "Please, if you know the true passages",
  236. "Contact me at L2JForum =)"
  237. };
  238. private static final Skill[] DEBUFFS =
  239. {
  240. SkillData.getInstance().getSkill(0, 1)
  241. };
  242. protected static Map<Integer, Long> _warDecreesCount = new HashMap<>();
  243. protected static List<L2Clan> _acceptedClans = new ArrayList<>(4);
  244. private static Map<String, ArrayList<L2Clan>> _usedTextPassages = new HashMap<>();
  245. private static Map<L2Clan, Integer> _pendingItemToGet = new HashMap<>();
  246. protected static SiegableHall _rainbow;
  247. protected static ScheduledFuture<?> _nextSiege, _siegeEnd;
  248. private static String _registrationEnds;
  249. private RainbowSpringsChateau()
  250. {
  251. super(-1, RainbowSpringsChateau.class.getSimpleName(), "conquerablehalls");
  252. addFirstTalkId(MESSENGER);
  253. addTalkId(MESSENGER);
  254. addFirstTalkId(CARETAKER);
  255. addTalkId(CARETAKER);
  256. addFirstTalkId(YETIS);
  257. addTalkId(YETIS);
  258. loadAttackers();
  259. _rainbow = CHSiegeManager.getInstance().getSiegableHall(RAINBOW_SPRINGS);
  260. if (_rainbow != null)
  261. {
  262. long delay = _rainbow.getNextSiegeTime();
  263. if (delay > -1)
  264. {
  265. setRegistrationEndString(delay - 3600000);
  266. _nextSiege = ThreadPoolManager.getInstance().scheduleGeneral(new SetFinalAttackers(), delay);
  267. }
  268. else
  269. {
  270. _log.warning("CHSiegeManager: No Date setted for RainBow Springs Chateau Clan hall siege!. SIEGE CANCELED!");
  271. }
  272. }
  273. }
  274. @Override
  275. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  276. {
  277. String html = "";
  278. final int npcId = npc.getId();
  279. if (npcId == MESSENGER)
  280. {
  281. final String main = (_rainbow.getOwnerId() > 0) ? "messenger_yetti001.htm" : "messenger_yetti001a.htm";
  282. html = HtmCache.getInstance().getHtm(player.getHtmlPrefix(), "data/scripts/conquerablehalls/RainbowSpringsChateau/" + main);
  283. html = html.replace("%time%", _registrationEnds);
  284. if (_rainbow.getOwnerId() > 0)
  285. {
  286. html = html.replace("%owner%", ClanTable.getInstance().getClan(_rainbow.getOwnerId()).getName());
  287. }
  288. }
  289. else if (npcId == CARETAKER)
  290. {
  291. if (_rainbow.isInSiege())
  292. {
  293. html = "game_manager003.htm";
  294. }
  295. else
  296. {
  297. html = "game_manager001.htm";
  298. }
  299. }
  300. else if (Util.contains(YETIS, npcId))
  301. {
  302. // TODO: Review.
  303. if (_rainbow.isInSiege())
  304. {
  305. if (!player.isClanLeader())
  306. {
  307. html = "no_clan_leader.htm";
  308. }
  309. else
  310. {
  311. L2Clan clan = player.getClan();
  312. if (_acceptedClans.contains(clan))
  313. {
  314. int index = _acceptedClans.indexOf(clan);
  315. if (npcId == YETIS[index])
  316. {
  317. html = "yeti_main.htm";
  318. }
  319. }
  320. }
  321. }
  322. }
  323. player.setLastQuestNpcObject(npc.getObjectId());
  324. return html;
  325. }
  326. @Override
  327. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  328. {
  329. String html = event;
  330. final L2Clan clan = player.getClan();
  331. switch (npc.getId())
  332. {
  333. case MESSENGER:
  334. switch (event)
  335. {
  336. case "register":
  337. if (!player.isClanLeader())
  338. {
  339. html = "messenger_yetti010.htm";
  340. }
  341. else if ((clan.getCastleId() > 0) || (clan.getFortId() > 0) || (clan.getHideoutId() > 0))
  342. {
  343. html = "messenger_yetti012.htm";
  344. }
  345. else if (!_rainbow.isRegistering())
  346. {
  347. html = "messenger_yetti014.htm";
  348. }
  349. else if (_warDecreesCount.containsKey(clan.getId()))
  350. {
  351. html = "messenger_yetti013.htm";
  352. }
  353. else if ((clan.getLevel() < 3) || (clan.getMembersCount() < 5))
  354. {
  355. html = "messenger_yetti011.htm";
  356. }
  357. else
  358. {
  359. final L2ItemInstance warDecrees = player.getInventory().getItemByItemId(WAR_DECREES);
  360. if (warDecrees == null)
  361. {
  362. html = "messenger_yetti008.htm";
  363. }
  364. else
  365. {
  366. long count = warDecrees.getCount();
  367. _warDecreesCount.put(clan.getId(), count);
  368. player.destroyItem("Rainbow Springs Registration", warDecrees, npc, true);
  369. updateAttacker(clan.getId(), count, false);
  370. html = "messenger_yetti009.htm";
  371. }
  372. }
  373. break;
  374. case "cancel":
  375. if (!player.isClanLeader())
  376. {
  377. html = "messenger_yetti010.htm";
  378. }
  379. else if (!_warDecreesCount.containsKey(clan.getId()))
  380. {
  381. html = "messenger_yetti016.htm";
  382. }
  383. else if (!_rainbow.isRegistering())
  384. {
  385. html = "messenger_yetti017.htm";
  386. }
  387. else
  388. {
  389. updateAttacker(clan.getId(), 0, true);
  390. html = "messenger_yetti018.htm";
  391. }
  392. break;
  393. case "unregister":
  394. if (_rainbow.isRegistering())
  395. {
  396. if (_warDecreesCount.containsKey(clan.getId()))
  397. {
  398. player.addItem("Rainbow Spring unregister", WAR_DECREES, _warDecreesCount.get(clan.getId()) / 2, npc, true);
  399. _warDecreesCount.remove(clan.getId());
  400. html = "messenger_yetti019.htm";
  401. }
  402. else
  403. {
  404. html = "messenger_yetti020.htm";
  405. }
  406. }
  407. else if (_rainbow.isWaitingBattle())
  408. {
  409. _acceptedClans.remove(clan);
  410. html = "messenger_yetti020.htm";
  411. }
  412. break;
  413. }
  414. break;
  415. case CARETAKER:
  416. if (event.equals("portToArena"))
  417. {
  418. final L2Party party = player.getParty();
  419. if (clan == null)
  420. {
  421. html = "game_manager009.htm";
  422. }
  423. else if (!player.isClanLeader())
  424. {
  425. html = "game_manager004.htm";
  426. }
  427. else if (!player.isInParty())
  428. {
  429. html = "game_manager005.htm";
  430. }
  431. else if (party.getLeaderObjectId() != player.getObjectId())
  432. {
  433. html = "game_manager006.htm";
  434. }
  435. else
  436. {
  437. final int clanId = player.getClanId();
  438. boolean nonClanMemberInParty = false;
  439. for (L2PcInstance member : party.getMembers())
  440. {
  441. if (member.getClanId() != clanId)
  442. {
  443. nonClanMemberInParty = true;
  444. break;
  445. }
  446. }
  447. if (nonClanMemberInParty)
  448. {
  449. html = "game_manager007.htm";
  450. }
  451. else if (party.getMemberCount() < 5)
  452. {
  453. html = "game_manager008.htm";
  454. }
  455. else if ((clan.getCastleId() > 0) || (clan.getFortId() > 0) || (clan.getHideoutId() > 0))
  456. {
  457. html = "game_manager010.htm";
  458. }
  459. else if (clan.getLevel() < Config.CHS_CLAN_MINLEVEL)
  460. {
  461. html = "game_manager011.htm";
  462. }
  463. // else if () // Something about the rules.
  464. // {
  465. // html = "game_manager012.htm";
  466. // }
  467. // else if () // Already registered.
  468. // {
  469. // html = "game_manager013.htm";
  470. // }
  471. else if (!_acceptedClans.contains(clan))
  472. {
  473. html = "game_manager014.htm";
  474. }
  475. // else if () // Not have enough cards to register.
  476. // {
  477. // html = "game_manager015.htm";
  478. // }
  479. else
  480. {
  481. portToArena(player, _acceptedClans.indexOf(clan));
  482. }
  483. }
  484. }
  485. break;
  486. }
  487. if (event.startsWith("enterText"))
  488. {
  489. // Shouldn't happen
  490. if (!_acceptedClans.contains(clan))
  491. {
  492. return null;
  493. }
  494. String[] split = event.split("_ ");
  495. if (split.length < 2)
  496. {
  497. return null;
  498. }
  499. final String passage = split[1];
  500. if (!isValidPassage(passage))
  501. {
  502. return null;
  503. }
  504. if (_usedTextPassages.containsKey(passage))
  505. {
  506. ArrayList<L2Clan> list = _usedTextPassages.get(passage);
  507. if (list.contains(clan))
  508. {
  509. html = "yeti_passage_used.htm";
  510. }
  511. else
  512. {
  513. list.add(clan);
  514. synchronized (_pendingItemToGet)
  515. {
  516. if (_pendingItemToGet.containsKey(clan))
  517. {
  518. int left = _pendingItemToGet.get(clan);
  519. ++left;
  520. _pendingItemToGet.put(clan, left);
  521. }
  522. else
  523. {
  524. _pendingItemToGet.put(clan, 1);
  525. }
  526. }
  527. html = "yeti_item_exchange.htm";
  528. }
  529. }
  530. }
  531. else if (event.startsWith("getItem"))
  532. {
  533. if (!_pendingItemToGet.containsKey(clan))
  534. {
  535. html = "yeti_cannot_exchange.htm";
  536. }
  537. int left = _pendingItemToGet.get(clan);
  538. if (left > 0)
  539. {
  540. int itemId = Integer.parseInt(event.split("_")[1]);
  541. player.addItem("Rainbow Spring Chateau Siege", itemId, 1, npc, true);
  542. --left;
  543. _pendingItemToGet.put(clan, left);
  544. html = "yeti_main.htm";
  545. }
  546. else
  547. {
  548. html = "yeti_cannot_exchange.htm";
  549. }
  550. }
  551. return html;
  552. }
  553. @Override
  554. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  555. {
  556. if (!_rainbow.isInSiege())
  557. {
  558. return null;
  559. }
  560. final L2Clan clan = killer.getClan();
  561. if ((clan == null) || !_acceptedClans.contains(clan))
  562. {
  563. return null;
  564. }
  565. final int npcId = npc.getId();
  566. final int index = _acceptedClans.indexOf(clan);
  567. if (npcId == CHEST)
  568. {
  569. shoutRandomText(npc);
  570. }
  571. else if (npcId == GOURDS[index])
  572. {
  573. synchronized (this)
  574. {
  575. if (_siegeEnd != null)
  576. {
  577. _siegeEnd.cancel(false);
  578. }
  579. ThreadPoolManager.getInstance().executeTask(new SiegeEnd(clan));
  580. }
  581. }
  582. return null;
  583. }
  584. @Override
  585. public String onItemUse(L2Item item, L2PcInstance player)
  586. {
  587. if (!_rainbow.isInSiege())
  588. {
  589. return null;
  590. }
  591. L2Object target = player.getTarget();
  592. if ((target == null) || !(target instanceof L2Npc))
  593. {
  594. return null;
  595. }
  596. int yeti = target.getId();
  597. if (!isYetiTarget(yeti))
  598. {
  599. return null;
  600. }
  601. final L2Clan clan = player.getClan();
  602. if ((clan == null) || !_acceptedClans.contains(clan))
  603. {
  604. return null;
  605. }
  606. // Nectar must spawn the enraged yeti. Dunno if it makes any other thing
  607. // Also, the items must execute:
  608. // - Reduce gourd hpb ( reduceGourdHp(int, L2PcInstance) )
  609. // - Cast debuffs on enemy clans ( castDebuffsOnEnemies(int) )
  610. // - Change arena gourds ( moveGourds() )
  611. // - Increase gourd hp ( increaseGourdHp(int) )
  612. final int itemId = item.getId();
  613. if (itemId == RAINBOW_NECTAR)
  614. {
  615. // Spawn enraged (where?)
  616. reduceGourdHp(_acceptedClans.indexOf(clan), player);
  617. }
  618. else if (itemId == RAINBOW_MWATER)
  619. {
  620. increaseGourdHp(_acceptedClans.indexOf(clan));
  621. }
  622. else if (itemId == RAINBOW_WATER)
  623. {
  624. moveGourds();
  625. }
  626. else if (itemId == RAINBOW_SULFUR)
  627. {
  628. castDebuffsOnEnemies(_acceptedClans.indexOf(clan));
  629. }
  630. return null;
  631. }
  632. private static void portToArena(L2PcInstance leader, int arena)
  633. {
  634. if ((arena < 0) || (arena > 3))
  635. {
  636. _log.warning("RainbowSptringChateau siege: Wrong arena id passed: " + arena);
  637. return;
  638. }
  639. for (L2PcInstance pc : leader.getParty().getMembers())
  640. {
  641. if (pc != null)
  642. {
  643. pc.stopAllEffects();
  644. if (pc.hasSummon())
  645. {
  646. pc.getSummon().unSummon(pc);
  647. }
  648. pc.teleToLocation(ARENAS[arena]);
  649. }
  650. }
  651. }
  652. protected static void spawnGourds()
  653. {
  654. for (int i = 0; i < _acceptedClans.size(); i++)
  655. {
  656. if (_gourds[i] == null)
  657. {
  658. try
  659. {
  660. _gourds[i] = new L2Spawn(NpcData.getInstance().getTemplate(GOURDS[i]));
  661. _gourds[i].setX(ARENAS[i].getX() + 150);
  662. _gourds[i].setY(ARENAS[i].getY() + 150);
  663. _gourds[i].setZ(ARENAS[i].getZ());
  664. _gourds[i].setHeading(1);
  665. _gourds[i].setAmount(1);
  666. }
  667. catch (Exception e)
  668. {
  669. e.printStackTrace();
  670. }
  671. }
  672. SpawnTable.getInstance().addNewSpawn(_gourds[i], false);
  673. _gourds[i].init();
  674. }
  675. }
  676. protected static void unSpawnGourds()
  677. {
  678. for (int i = 0; i < _acceptedClans.size(); i++)
  679. {
  680. _gourds[i].getLastSpawn().deleteMe();
  681. SpawnTable.getInstance().deleteSpawn(_gourds[i], false);
  682. }
  683. }
  684. private static void moveGourds()
  685. {
  686. L2Spawn[] tempArray = _gourds;
  687. int iterator = _acceptedClans.size();
  688. for (int i = 0; i < iterator; i++)
  689. {
  690. L2Spawn oldSpawn = _gourds[(iterator - 1) - i];
  691. L2Spawn curSpawn = tempArray[i];
  692. _gourds[(iterator - 1) - i] = curSpawn;
  693. curSpawn.getLastSpawn().teleToLocation(oldSpawn.getLocation());
  694. }
  695. }
  696. private static void reduceGourdHp(int index, L2PcInstance player)
  697. {
  698. L2Spawn gourd = _gourds[index];
  699. gourd.getLastSpawn().reduceCurrentHp(1000, player, null);
  700. }
  701. private static void increaseGourdHp(int index)
  702. {
  703. L2Spawn gourd = _gourds[index];
  704. L2Npc gourdNpc = gourd.getLastSpawn();
  705. gourdNpc.setCurrentHp(gourdNpc.getCurrentHp() + 1000);
  706. }
  707. private static void castDebuffsOnEnemies(int myArena)
  708. {
  709. for (int id : ARENA_ZONES)
  710. {
  711. if (id == myArena)
  712. {
  713. continue;
  714. }
  715. final Collection<L2Character> chars = ZoneManager.getInstance().getZoneById(id).getCharactersInside();
  716. for (L2Character chr : chars)
  717. {
  718. if (chr != null)
  719. {
  720. for (Skill sk : DEBUFFS)
  721. {
  722. sk.applyEffects(chr, chr);
  723. }
  724. }
  725. }
  726. }
  727. }
  728. private static void shoutRandomText(L2Npc npc)
  729. {
  730. int length = _textPassages.length;
  731. if (_usedTextPassages.size() >= length)
  732. {
  733. return;
  734. }
  735. int randomPos = getRandom(length);
  736. String message = _textPassages[randomPos];
  737. if (_usedTextPassages.containsKey(message))
  738. {
  739. shoutRandomText(npc);
  740. }
  741. else
  742. {
  743. _usedTextPassages.put(message, new ArrayList<L2Clan>());
  744. int shout = Say2.NPC_SHOUT;
  745. int objId = npc.getObjectId();
  746. NpcSay say = new NpcSay(objId, shout, npc.getId(), message);
  747. npc.broadcastPacket(say);
  748. }
  749. }
  750. private static boolean isValidPassage(String text)
  751. {
  752. for (String st : _textPassages)
  753. {
  754. if (st.equalsIgnoreCase(text))
  755. {
  756. return true;
  757. }
  758. }
  759. return false;
  760. }
  761. private static boolean isYetiTarget(int npcId)
  762. {
  763. for (int yeti : YETIS)
  764. {
  765. if (yeti == npcId)
  766. {
  767. return true;
  768. }
  769. }
  770. return false;
  771. }
  772. private static void updateAttacker(int clanId, long count, boolean remove)
  773. {
  774. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  775. {
  776. PreparedStatement statement;
  777. if (remove)
  778. {
  779. statement = con.prepareStatement("DELETE FROM rainbowsprings_attacker_list WHERE clanId = ?");
  780. statement.setInt(1, clanId);
  781. }
  782. else
  783. {
  784. statement = con.prepareStatement("INSERT INTO rainbowsprings_attacker_list VALUES (?,?)");
  785. statement.setInt(1, clanId);
  786. statement.setLong(2, count);
  787. }
  788. statement.execute();
  789. statement.close();
  790. }
  791. catch (Exception e)
  792. {
  793. e.printStackTrace();
  794. }
  795. }
  796. private static void loadAttackers()
  797. {
  798. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  799. {
  800. PreparedStatement statement = con.prepareStatement("SELECT * FROM rainbowsprings_attacker_list");
  801. ResultSet rset = statement.executeQuery();
  802. while (rset.next())
  803. {
  804. int clanId = rset.getInt("clan_id");
  805. long count = rset.getLong("decrees_count");
  806. _warDecreesCount.put(clanId, count);
  807. }
  808. rset.close();
  809. statement.close();
  810. }
  811. catch (Exception e)
  812. {
  813. e.printStackTrace();
  814. }
  815. }
  816. protected static void setRegistrationEndString(long time)
  817. {
  818. Calendar c = Calendar.getInstance();
  819. c.setTime(new Date(time));
  820. int year = c.get(Calendar.YEAR);
  821. int month = c.get(Calendar.MONTH) + 1;
  822. int day = c.get(Calendar.DAY_OF_MONTH);
  823. int hour = c.get(Calendar.HOUR);
  824. int mins = c.get(Calendar.MINUTE);
  825. _registrationEnds = year + "-" + month + "-" + day + " " + hour + ":" + mins;
  826. }
  827. public static void launchSiege()
  828. {
  829. _nextSiege.cancel(false);
  830. ThreadPoolManager.getInstance().executeTask(new SiegeStart());
  831. }
  832. public static void endSiege()
  833. {
  834. if (_siegeEnd != null)
  835. {
  836. _siegeEnd.cancel(false);
  837. }
  838. ThreadPoolManager.getInstance().executeTask(new SiegeEnd(null));
  839. }
  840. public static void updateAdminDate(long date)
  841. {
  842. if (_rainbow == null)
  843. {
  844. _rainbow = CHSiegeManager.getInstance().getSiegableHall(RAINBOW_SPRINGS);
  845. }
  846. _rainbow.setNextSiegeDate(date);
  847. if (_nextSiege != null)
  848. {
  849. _nextSiege.cancel(true);
  850. }
  851. date -= 3600000;
  852. setRegistrationEndString(date);
  853. _nextSiege = ThreadPoolManager.getInstance().scheduleGeneral(new SetFinalAttackers(), _rainbow.getNextSiegeTime());
  854. }
  855. public static void main(String[] args)
  856. {
  857. new RainbowSpringsChateau();
  858. }
  859. }