RainbowSpringsChateau.java 24 KB

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