RainbowSpringsChateau.java 24 KB

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