SevenSignsFestival.java 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492
  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 net.sf.l2j.gameserver;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.sql.SQLException;
  20. import java.util.Collection;
  21. import java.util.List;
  22. import java.util.Map;
  23. import java.util.concurrent.ScheduledFuture;
  24. import java.util.logging.Logger;
  25. import javolution.util.FastList;
  26. import javolution.util.FastMap;
  27. import net.sf.l2j.Config;
  28. import net.sf.l2j.L2DatabaseFactory;
  29. import net.sf.l2j.gameserver.ai.CtrlIntention;
  30. import net.sf.l2j.gameserver.datatables.ClanTable;
  31. import net.sf.l2j.gameserver.datatables.MapRegionTable;
  32. import net.sf.l2j.gameserver.datatables.NpcTable;
  33. import net.sf.l2j.gameserver.datatables.SpawnTable;
  34. import net.sf.l2j.gameserver.model.L2CharPosition;
  35. import net.sf.l2j.gameserver.model.L2Clan;
  36. import net.sf.l2j.gameserver.model.L2ItemInstance;
  37. import net.sf.l2j.gameserver.model.L2Party;
  38. import net.sf.l2j.gameserver.model.L2Spawn;
  39. import net.sf.l2j.gameserver.model.L2World;
  40. import net.sf.l2j.gameserver.model.SpawnListener;
  41. import net.sf.l2j.gameserver.model.actor.L2Npc;
  42. import net.sf.l2j.gameserver.model.actor.instance.L2FestivalMonsterInstance;
  43. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  44. import net.sf.l2j.gameserver.model.base.Experience;
  45. import net.sf.l2j.gameserver.network.SystemMessageId;
  46. import net.sf.l2j.gameserver.network.clientpackets.Say2;
  47. import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  48. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  49. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  50. import net.sf.l2j.gameserver.templates.StatsSet;
  51. import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
  52. import net.sf.l2j.gameserver.util.Util;
  53. import net.sf.l2j.util.Rnd;
  54. /**
  55. *Seven Signs Festival of Darkness Engine
  56. *
  57. *TODO:
  58. *- Archer mobs should target healer characters over other party members.
  59. *- ADDED 29 Sep: Players that leave a party during the Seven Signs Festival will now take damage and cannot be healed.
  60. *
  61. *@author Tempy
  62. */
  63. public class SevenSignsFestival implements SpawnListener
  64. {
  65. protected static final Logger _log = Logger.getLogger(SevenSignsFestival.class.getName());
  66. private static final String GET_CLAN_NAME = "SELECT clan_name FROM clan_data WHERE clan_id = (SELECT clanid FROM characters WHERE char_name = ?)";
  67. /**
  68. * These length settings are important! :)
  69. * All times are relative to the ELAPSED time (in ms) since a festival begins.
  70. *
  71. * Festival manager start is the time after the server starts to begin the first
  72. * festival cycle.
  73. *
  74. * The cycle length should ideally be at least 2x longer than the festival length.
  75. * This allows ample time for players to sign-up to participate in the festival.
  76. *
  77. * The intermission is the time between the festival participants being moved
  78. * to the "arenas" and the spawning of the first set of mobs.
  79. *
  80. * The monster swarm time is the time before the monsters swarm to the center of the arena,
  81. * after they are spawned.
  82. *
  83. * The chest spawn time is for when the bonus festival chests spawn, usually
  84. * towards the end of the festival.
  85. */
  86. public static final long FESTIVAL_SIGNUP_TIME = Config.ALT_FESTIVAL_CYCLE_LENGTH - Config.ALT_FESTIVAL_LENGTH - 60000;
  87. // Key Constants \\
  88. private static final int FESTIVAL_MAX_OFFSET_X = 230;
  89. private static final int FESTIVAL_MAX_OFFSET_Y = 230;
  90. private static final int FESTIVAL_DEFAULT_RESPAWN = 60; // Specify in seconds!
  91. public static final int FESTIVAL_COUNT = 5;
  92. public static final int FESTIVAL_LEVEL_MAX_31 = 0;
  93. public static final int FESTIVAL_LEVEL_MAX_42 = 1;
  94. public static final int FESTIVAL_LEVEL_MAX_53 = 2;
  95. public static final int FESTIVAL_LEVEL_MAX_64 = 3;
  96. public static final int FESTIVAL_LEVEL_MAX_NONE = 4;
  97. public static final int[] FESTIVAL_LEVEL_SCORES = { 60, 70, 100, 120, 150 }; // 500 maximum possible score
  98. public static final int FESTIVAL_OFFERING_ID = 5901;
  99. public static final int FESTIVAL_OFFERING_VALUE = 5;
  100. //////////////////////// \\\\\\\\\\\\\\\\\\\\\\\\\\
  101. /*
  102. * The following contains all the necessary spawn data for:
  103. * - Player Start Locations
  104. * - Witches
  105. * - Monsters
  106. * - Chests
  107. *
  108. * All data is given by: X, Y, Z (coords), Heading, NPC ID (if necessary)
  109. * This may be moved externally in time, but the data should not change.
  110. */
  111. public static final int[][] FESTIVAL_DAWN_PLAYER_SPAWNS = { { -79187, 113186, -4895, 0 }, // 31 and below
  112. { -75918, 110137, -4895, 0 }, // 42 and below
  113. { -73835, 111969, -4895, 0 }, // 53 and below
  114. { -76170, 113804, -4895, 0 }, // 64 and below
  115. { -78927, 109528, -4895, 0 } // No level limit
  116. };
  117. public static final int[][] FESTIVAL_DUSK_PLAYER_SPAWNS = { { -77200, 88966, -5151, 0 }, // 31 and below
  118. { -76941, 85307, -5151, 0 }, // 42 and below
  119. { -74855, 87135, -5151, 0 }, // 53 and below
  120. { -80208, 88222, -5151, 0 }, // 64 and below
  121. { -79954, 84697, -5151, 0 } // No level limit
  122. };
  123. protected static final int[][] FESTIVAL_DAWN_WITCH_SPAWNS = { { -79183, 113052, -4891, 0, 31132 }, // 31 and below
  124. { -75916, 110270, -4891, 0, 31133 }, // 42 and below
  125. { -73979, 111970, -4891, 0, 31134 }, // 53 and below
  126. { -76174, 113663, -4891, 0, 31135 }, // 64 and below
  127. { -78930, 109664, -4891, 0, 31136 } // No level limit
  128. };
  129. protected static final int[][] FESTIVAL_DUSK_WITCH_SPAWNS = { { -77199, 88830, -5147, 0, 31142 }, // 31 and below
  130. { -76942, 85438, -5147, 0, 31143 }, // 42 and below
  131. { -74990, 87135, -5147, 0, 31144 }, // 53 and below
  132. { -80207, 88222, -5147, 0, 31145 }, // 64 and below
  133. { -79952, 84833, -5147, 0, 31146 } // No level limit
  134. };
  135. protected static final int[][][] FESTIVAL_DAWN_PRIMARY_SPAWNS = {
  136. {
  137. /* Level 31 and Below - Offering of the Branded */
  138. { -78537, 113839, -4895, -1, 18009 },
  139. { -78466, 113852, -4895, -1, 18010 },
  140. { -78509, 113899, -4895, -1, 18010 },
  141. { -78481, 112557, -4895, -1, 18009 },
  142. { -78559, 112504, -4895, -1, 18010 },
  143. { -78489, 112494, -4895, -1, 18010 },
  144. { -79803, 112543, -4895, -1, 18012 },
  145. { -79854, 112492, -4895, -1, 18013 },
  146. { -79886, 112557, -4895, -1, 18014 },
  147. { -79821, 113811, -4895, -1, 18015 },
  148. { -79857, 113896, -4895, -1, 18017 },
  149. { -79878, 113816, -4895, -1, 18018 },
  150. // Archers and Marksmen \\
  151. { -79190, 113660, -4895, -1, 18011 },
  152. { -78710, 113188, -4895, -1, 18011 },
  153. { -79190, 112730, -4895, -1, 18016 },
  154. { -79656, 113188, -4895, -1, 18016 }
  155. },
  156. {
  157. /* Level 42 and Below - Apostate Offering */
  158. { -76558, 110784, -4895, -1, 18019 },
  159. { -76607, 110815, -4895, -1, 18020 }, // South West
  160. { -76559, 110820, -4895, -1, 18020 },
  161. { -75277, 110792, -4895, -1, 18019 },
  162. { -75225, 110801, -4895, -1, 18020 }, // South East
  163. { -75262, 110832, -4895, -1, 18020 },
  164. { -75249, 109441, -4895, -1, 18022 },
  165. { -75278, 109495, -4895, -1, 18023 }, // North East
  166. { -75223, 109489, -4895, -1, 18024 },
  167. { -76556, 109490, -4895, -1, 18025 },
  168. { -76607, 109469, -4895, -1, 18027 }, // North West
  169. { -76561, 109450, -4895, -1, 18028 },
  170. // Archers and Marksmen \\
  171. { -76399, 110144, -4895, -1, 18021 },
  172. { -75912, 110606, -4895, -1, 18021 },
  173. { -75444, 110144, -4895, -1, 18026 },
  174. { -75930, 109665, -4895, -1, 18026 }
  175. },
  176. {
  177. /* Level 53 and Below - Witch's Offering */
  178. { -73184, 111319, -4895, -1, 18029 },
  179. { -73135, 111294, -4895, -1, 18030 }, // South West
  180. { -73185, 111281, -4895, -1, 18030 },
  181. { -74477, 111321, -4895, -1, 18029 },
  182. { -74523, 111293, -4895, -1, 18030 }, // South East
  183. { -74481, 111280, -4895, -1, 18030 },
  184. { -74489, 112604, -4895, -1, 18032 },
  185. { -74491, 112660, -4895, -1, 18033 }, // North East
  186. { -74527, 112629, -4895, -1, 18034 },
  187. { -73197, 112621, -4895, -1, 18035 },
  188. { -73142, 112631, -4895, -1, 18037 }, // North West
  189. { -73182, 112656, -4895, -1, 18038 },
  190. // Archers and Marksmen \\
  191. { -73834, 112430, -4895, -1, 18031 },
  192. { -74299, 111959, -4895, -1, 18031 },
  193. { -73841, 111491, -4895, -1, 18036 },
  194. { -73363, 111959, -4895, -1, 18036 }
  195. },
  196. {
  197. /* Level 64 and Below - Dark Omen Offering */
  198. { -75543, 114461, -4895, -1, 18039 },
  199. { -75514, 114493, -4895, -1, 18040 }, // South West
  200. { -75488, 114456, -4895, -1, 18040 },
  201. { -75521, 113158, -4895, -1, 18039 },
  202. { -75504, 113110, -4895, -1, 18040 }, // South East
  203. { -75489, 113142, -4895, -1, 18040 },
  204. { -76809, 113143, -4895, -1, 18042 },
  205. { -76860, 113138, -4895, -1, 18043 }, // North East
  206. { -76831, 113112, -4895, -1, 18044 },
  207. { -76831, 114441, -4895, -1, 18045 },
  208. { -76840, 114490, -4895, -1, 18047 }, // North West
  209. { -76864, 114455, -4895, -1, 18048 },
  210. // Archers and Marksmen \\
  211. { -75703, 113797, -4895, -1, 18041 },
  212. { -76180, 114263, -4895, -1, 18041 },
  213. { -76639, 113797, -4895, -1, 18046 },
  214. { -76180, 113337, -4895, -1, 18046 }
  215. },
  216. {
  217. /* No Level Limit - Offering of Forbidden Path */
  218. { -79576, 108881, -4895, -1, 18049 },
  219. { -79592, 108835, -4895, -1, 18050 }, // South West
  220. { -79614, 108871, -4895, -1, 18050 },
  221. { -79586, 110171, -4895, -1, 18049 },
  222. { -79589, 110216, -4895, -1, 18050 }, // South East
  223. { -79620, 110177, -4895, -1, 18050 },
  224. { -78825, 110182, -4895, -1, 18052 },
  225. { -78238, 110182, -4895, -1, 18053 }, // North East
  226. { -78266, 110218, -4895, -1, 18054 },
  227. { -78275, 108883, -4895, -1, 18055 },
  228. { -78267, 108839, -4895, -1, 18057 }, // North West
  229. { -78241, 108871, -4895, -1, 18058 },
  230. // Archers and Marksmen \\
  231. { -79394, 109538, -4895, -1, 18051 },
  232. { -78929, 109992, -4895, -1, 18051 },
  233. { -78454, 109538, -4895, -1, 18056 },
  234. { -78929, 109053, -4895, -1, 18056 }
  235. }
  236. };
  237. protected static final int[][][] FESTIVAL_DUSK_PRIMARY_SPAWNS = {
  238. {
  239. /* Level 31 and Below - Offering of the Branded */
  240. { -76542, 89653, -5151, -1, 18009 },
  241. { -76509, 89637, -5151, -1, 18010 },
  242. { -76548, 89614, -5151, -1, 18010 },
  243. { -76539, 88326, -5151, -1, 18009 },
  244. { -76512, 88289, -5151, -1, 18010 },
  245. { -76546, 88287, -5151, -1, 18010 },
  246. { -77879, 88308, -5151, -1, 18012 },
  247. { -77886, 88310, -5151, -1, 18013 },
  248. { -77879, 88278, -5151, -1, 18014 },
  249. { -77857, 89605, -5151, -1, 18015 },
  250. { -77858, 89658, -5151, -1, 18017 },
  251. { -77891, 89633, -5151, -1, 18018 },
  252. // Archers and Marksmen \\
  253. { -76728, 88962, -5151, -1, 18011 },
  254. { -77194, 88494, -5151, -1, 18011 },
  255. { -77660, 88896, -5151, -1, 18016 },
  256. { -77195, 89438, -5151, -1, 18016 }
  257. },
  258. {
  259. /* Level 42 and Below - Apostate's Offering */
  260. { -77585, 84650, -5151, -1, 18019 },
  261. { -77628, 84643, -5151, -1, 18020 },
  262. { -77607, 84613, -5151, -1, 18020 },
  263. { -76603, 85946, -5151, -1, 18019 },
  264. { -77606, 85994, -5151, -1, 18020 },
  265. { -77638, 85959, -5151, -1, 18020 },
  266. { -76301, 85960, -5151, -1, 18022 },
  267. { -76257, 85972, -5151, -1, 18023 },
  268. { -76286, 85992, -5151, -1, 18024 },
  269. { -76281, 84667, -5151, -1, 18025 },
  270. { -76291, 84611, -5151, -1, 18027 },
  271. { -76257, 84616, -5151, -1, 18028 },
  272. // Archers and Marksmen \\
  273. { -77419, 85307, -5151, -1, 18021 },
  274. { -76952, 85768, -5151, -1, 18021 },
  275. { -76477, 85312, -5151, -1, 18026 },
  276. { -76942, 84832, -5151, -1, 18026 }
  277. },
  278. {
  279. /* Level 53 and Below - Witch's Offering */
  280. { -74211, 86494, -5151, -1, 18029 },
  281. { -74200, 86449, -5151, -1, 18030 },
  282. { -74167, 86464, -5151, -1, 18030 },
  283. { -75495, 86482, -5151, -1, 18029 },
  284. { -75540, 86473, -5151, -1, 18030 },
  285. { -75509, 86445, -5151, -1, 18030 },
  286. { -75509, 87775, -5151, -1, 18032 },
  287. { -75518, 87826, -5151, -1, 18033 },
  288. { -75542, 87780, -5151, -1, 18034 },
  289. { -74214, 87789, -5151, -1, 18035 },
  290. { -74169, 87801, -5151, -1, 18037 },
  291. { -74198, 87827, -5151, -1, 18038 },
  292. // Archers and Marksmen \\
  293. { -75324, 87135, -5151, -1, 18031 },
  294. { -74852, 87606, -5151, -1, 18031 },
  295. { -74388, 87146, -5151, -1, 18036 },
  296. { -74856, 86663, -5151, -1, 18036 }
  297. },
  298. {
  299. /* Level 64 and Below - Dark Omen Offering */
  300. { -79560, 89007, -5151, -1, 18039 },
  301. { -79521, 89016, -5151, -1, 18040 },
  302. { -79544, 89047, -5151, -1, 18040 },
  303. { -79552, 87717, -5151, -1, 18039 },
  304. { -79552, 87673, -5151, -1, 18040 },
  305. { -79510, 87702, -5151, -1, 18040 },
  306. { -80866, 87719, -5151, -1, 18042 },
  307. { -80897, 87689, -5151, -1, 18043 },
  308. { -80850, 87685, -5151, -1, 18044 },
  309. { -80848, 89013, -5151, -1, 18045 },
  310. { -80887, 89051, -5151, -1, 18047 },
  311. { -80891, 89004, -5151, -1, 18048 },
  312. // Archers and Marksmen \\
  313. { -80205, 87895, -5151, -1, 18041 },
  314. { -80674, 88350, -5151, -1, 18041 },
  315. { -80209, 88833, -5151, -1, 18046 },
  316. { -79743, 88364, -5151, -1, 18046 }
  317. },
  318. {
  319. /* No Level Limit - Offering of Forbidden Path */
  320. { -80624, 84060, -5151, -1, 18049 },
  321. { -80621, 84007, -5151, -1, 18050 },
  322. { -80590, 84039, -5151, -1, 18050 },
  323. { -80605, 85349, -5151, -1, 18049 },
  324. { -80639, 85363, -5151, -1, 18050 },
  325. { -80611, 85385, -5151, -1, 18050 },
  326. { -79311, 85353, -5151, -1, 18052 },
  327. { -79277, 85384, -5151, -1, 18053 },
  328. { -79273, 85539, -5151, -1, 18054 },
  329. { -79297, 84054, -5151, -1, 18055 },
  330. { -79285, 84006, -5151, -1, 18057 },
  331. { -79260, 84040, -5151, -1, 18058 },
  332. // Archers and Marksmen \\
  333. { -79945, 85171, -5151, -1, 18051 },
  334. { -79489, 84707, -5151, -1, 18051 },
  335. { -79952, 84222, -5151, -1, 18056 },
  336. { -80423, 84703, -5151, -1, 18056 }
  337. }
  338. };
  339. protected static final int[][][] FESTIVAL_DAWN_SECONDARY_SPAWNS = {
  340. {
  341. /* 31 and Below */
  342. { -78757, 112834, -4895, -1, 18016 },
  343. { -78581, 112834, -4895, -1, 18016 },
  344. { -78822, 112526, -4895, -1, 18011 },
  345. { -78822, 113702, -4895, -1, 18011 },
  346. { -78822, 113874, -4895, -1, 18011 },
  347. { -79524, 113546, -4895, -1, 18011 },
  348. { -79693, 113546, -4895, -1, 18011 },
  349. { -79858, 113546, -4895, -1, 18011 },
  350. { -79545, 112757, -4895, -1, 18016 },
  351. { -79545, 112586, -4895, -1, 18016 },
  352. },
  353. {
  354. /* 42 and Below */
  355. { -75565, 110580, -4895, -1, 18026 },
  356. { -75565, 110740, -4895, -1, 18026 },
  357. { -75577, 109776, -4895, -1, 18021 },
  358. { -75413, 109776, -4895, -1, 18021 },
  359. { -75237, 109776, -4895, -1, 18021 },
  360. { -76274, 109468, -4895, -1, 18021 },
  361. { -76274, 109635, -4895, -1, 18021 },
  362. { -76274, 109795, -4895, -1, 18021 },
  363. { -76351, 110500, -4895, -1, 18056 },
  364. { -76528, 110500, -4895, -1, 18056 },
  365. },
  366. {
  367. /* 53 and Below */
  368. { -74191, 111527, -4895, -1, 18036 },
  369. { -74191, 111362, -4895, -1, 18036 },
  370. { -73495, 111611, -4895, -1, 18031 },
  371. { -73327, 111611, -4895, -1, 18031 },
  372. { -73154, 111611, -4895, -1, 18031 },
  373. { -73473, 112301, -4895, -1, 18031 },
  374. { -73473, 112475, -4895, -1, 18031 },
  375. { -73473, 112649, -4895, -1, 18031 },
  376. { -74270, 112326, -4895, -1, 18036 },
  377. { -74443, 112326, -4895, -1, 18036 },
  378. },
  379. {
  380. /* 64 and Below */
  381. { -75738, 113439, -4895, -1, 18046 },
  382. { -75571, 113439, -4895, -1, 18046 },
  383. { -75824, 114141, -4895, -1, 18041 },
  384. { -75824, 114309, -4895, -1, 18041 },
  385. { -75824, 114477, -4895, -1, 18041 },
  386. { -76513, 114158, -4895, -1, 18041 },
  387. { -76683, 114158, -4895, -1, 18041 },
  388. { -76857, 114158, -4895, -1, 18041 },
  389. { -76535, 113357, -4895, -1, 18056 },
  390. { -76535, 113190, -4895, -1, 18056 },
  391. },
  392. {
  393. /* No Level Limit */
  394. { -79350, 109894, -4895, -1, 18056 },
  395. { -79534, 109894, -4895, -1, 18056 },
  396. { -79285, 109187, -4895, -1, 18051 },
  397. { -79285, 109019, -4895, -1, 18051 },
  398. { -79285, 108860, -4895, -1, 18051 },
  399. { -78587, 109172, -4895, -1, 18051 },
  400. { -78415, 109172, -4895, -1, 18051 },
  401. { -78249, 109172, -4895, -1, 18051 },
  402. { -78575, 109961, -4895, -1, 18056 },
  403. { -78575, 110130, -4895, -1, 18056 },
  404. }
  405. };
  406. protected static final int[][][] FESTIVAL_DUSK_SECONDARY_SPAWNS = {
  407. {
  408. /* 31 and Below */
  409. { -76844, 89304, -5151, -1, 18011 },
  410. { -76844, 89479, -5151, -1, 18011 },
  411. { -76844, 89649, -5151, -1, 18011 },
  412. { -77544, 89326, -5151, -1, 18011 },
  413. { -77716, 89326, -5151, -1, 18011 },
  414. { -77881, 89326, -5151, -1, 18011 },
  415. { -77561, 88530, -5151, -1, 18016 },
  416. { -77561, 88364, -5151, -1, 18016 },
  417. { -76762, 88615, -5151, -1, 18016 },
  418. { -76594, 88615, -5151, -1, 18016 },
  419. },
  420. {
  421. /* 42 and Below */
  422. { -77307, 84969, -5151, -1, 18021 },
  423. { -77307, 84795, -5151, -1, 18021 },
  424. { -77307, 84623, -5151, -1, 18021 },
  425. { -76614, 84944, -5151, -1, 18021 },
  426. { -76433, 84944, -5151, -1, 18021 },
  427. { -76251, 84944, -5151, -1, 18021 },
  428. { -76594, 85745, -5151, -1, 18026 },
  429. { -76594, 85910, -5151, -1, 18026 },
  430. { -77384, 85660, -5151, -1, 18026 },
  431. { -77555, 85660, -5151, -1, 18026 },
  432. },
  433. {
  434. /* 53 and Below */
  435. { -74517, 86782, -5151, -1, 18031 },
  436. { -74344, 86782, -5151, -1, 18031 },
  437. { -74185, 86782, -5151, -1, 18031 },
  438. { -74496, 87464, -5151, -1, 18031 },
  439. { -74496, 87636, -5151, -1, 18031 },
  440. { -74496, 87815, -5151, -1, 18031 },
  441. { -75298, 87497, -5151, -1, 18036 },
  442. { -75460, 87497, -5151, -1, 18036 },
  443. { -75219, 86712, -5151, -1, 18036 },
  444. { -75219, 86531, -5151, -1, 18036 },
  445. },
  446. {
  447. /* 64 and Below */
  448. { -79851, 88703, -5151, -1, 18041 },
  449. { -79851, 88868, -5151, -1, 18041 },
  450. { -79851, 89040, -5151, -1, 18041 },
  451. { -80548, 88722, -5151, -1, 18041 },
  452. { -80711, 88722, -5151, -1, 18041 },
  453. { -80883, 88722, -5151, -1, 18041 },
  454. { -80565, 87916, -5151, -1, 18046 },
  455. { -80565, 87752, -5151, -1, 18046 },
  456. { -79779, 87996, -5151, -1, 18046 },
  457. { -79613, 87996, -5151, -1, 18046 },
  458. },
  459. {
  460. /* No Level Limit */
  461. { -79271, 84330, -5151, -1, 18051 },
  462. { -79448, 84330, -5151, -1, 18051 },
  463. { -79601, 84330, -5151, -1, 18051 },
  464. { -80311, 84367, -5151, -1, 18051 },
  465. { -80311, 84196, -5151, -1, 18051 },
  466. { -80311, 84015, -5151, -1, 18051 },
  467. { -80556, 85049, -5151, -1, 18056 },
  468. { -80384, 85049, -5151, -1, 18056 },
  469. { -79598, 85127, -5151, -1, 18056 },
  470. { -79598, 85303, -5151, -1, 18056 },
  471. }
  472. };
  473. protected static final int[][][] FESTIVAL_DAWN_CHEST_SPAWNS = {
  474. {
  475. /* Level 31 and Below */
  476. { -78999, 112957, -4927, -1, 18109 },
  477. { -79153, 112873, -4927, -1, 18109 },
  478. { -79256, 112873, -4927, -1, 18109 },
  479. { -79368, 112957, -4927, -1, 18109 },
  480. { -79481, 113124, -4927, -1, 18109 },
  481. { -79481, 113275, -4927, -1, 18109 },
  482. { -79364, 113398, -4927, -1, 18109 },
  483. { -79213, 113500, -4927, -1, 18109 },
  484. { -79099, 113500, -4927, -1, 18109 },
  485. { -78960, 113398, -4927, -1, 18109 },
  486. { -78882, 113235, -4927, -1, 18109 },
  487. { -78882, 113099, -4927, -1, 18109 },
  488. },
  489. {
  490. /* Level 42 and Below */
  491. { -76119, 110383, -4927, -1, 18110 },
  492. { -75980, 110442, -4927, -1, 18110 },
  493. { -75848, 110442, -4927, -1, 18110 },
  494. { -75720, 110383, -4927, -1, 18110 },
  495. { -75625, 110195, -4927, -1, 18110 },
  496. { -75625, 110063, -4927, -1, 18110 },
  497. { -75722, 109908, -4927, -1, 18110 },
  498. { -75863, 109832, -4927, -1, 18110 },
  499. { -75989, 109832, -4927, -1, 18110 },
  500. { -76130, 109908, -4927, -1, 18110 },
  501. { -76230, 110079, -4927, -1, 18110 },
  502. { -76230, 110215, -4927, -1, 18110 },
  503. },
  504. {
  505. /* Level 53 and Below */
  506. { -74055, 111781, -4927, -1, 18111 },
  507. { -74144, 111938, -4927, -1, 18111 },
  508. { -74144, 112075, -4927, -1, 18111 },
  509. { -74055, 112173, -4927, -1, 18111 },
  510. { -73885, 112289, -4927, -1, 18111 },
  511. { -73756, 112289, -4927, -1, 18111 },
  512. { -73574, 112141, -4927, -1, 18111 },
  513. { -73511, 112040, -4927, -1, 18111 },
  514. { -73511, 111912, -4927, -1, 18111 },
  515. { -73574, 111772, -4927, -1, 18111 },
  516. { -73767, 111669, -4927, -1, 18111 },
  517. { -73899, 111669, -4927, -1, 18111 },
  518. },
  519. {
  520. /* Level 64 and Below */
  521. { -76008, 113566, -4927, -1, 18112 },
  522. { -76159, 113485, -4927, -1, 18112 },
  523. { -76267, 113485, -4927, -1, 18112 },
  524. { -76386, 113566, -4927, -1, 18112 },
  525. { -76482, 113748, -4927, -1, 18112 },
  526. { -76482, 113885, -4927, -1, 18112 },
  527. { -76371, 114029, -4927, -1, 18112 },
  528. { -76220, 114118, -4927, -1, 18112 },
  529. { -76092, 114118, -4927, -1, 18112 },
  530. { -75975, 114029, -4927, -1, 18112 },
  531. { -75861, 113851, -4927, -1, 18112 },
  532. { -75861, 113713, -4927, -1, 18112 },
  533. },
  534. {
  535. /* No Level Limit */
  536. { -79100, 109782, -4927, -1, 18113 },
  537. { -78962, 109853, -4927, -1, 18113 },
  538. { -78851, 109853, -4927, -1, 18113 },
  539. { -78721, 109782, -4927, -1, 18113 },
  540. { -78615, 109596, -4927, -1, 18113 },
  541. { -78615, 109453, -4927, -1, 18113 },
  542. { -78746, 109300, -4927, -1, 18113 },
  543. { -78881, 109203, -4927, -1, 18113 },
  544. { -79027, 109203, -4927, -1, 18113 },
  545. { -79159, 109300, -4927, -1, 18113 },
  546. { -79240, 109480, -4927, -1, 18113 },
  547. { -79240, 109615, -4927, -1, 18113 },
  548. }
  549. };
  550. protected static final int[][][] FESTIVAL_DUSK_CHEST_SPAWNS = {
  551. {
  552. /* Level 31 and Below */
  553. { -77016, 88726, -5183, -1, 18114 },
  554. { -77136, 88646, -5183, -1, 18114 },
  555. { -77247, 88646, -5183, -1, 18114 },
  556. { -77380, 88726, -5183, -1, 18114 },
  557. { -77512, 88883, -5183, -1, 18114 },
  558. { -77512, 89053, -5183, -1, 18114 },
  559. { -77378, 89287, -5183, -1, 18114 },
  560. { -77254, 89238, -5183, -1, 18114 },
  561. { -77095, 89238, -5183, -1, 18114 },
  562. { -76996, 89287, -5183, -1, 18114 },
  563. { -76901, 89025, -5183, -1, 18114 },
  564. { -76901, 88891, -5183, -1, 18114 },
  565. },
  566. {
  567. /* Level 42 and Below */
  568. { -77128, 85553, -5183, -1, 18115 },
  569. { -77036, 85594, -5183, -1, 18115 },
  570. { -76919, 85594, -5183, -1, 18115 },
  571. { -76755, 85553, -5183, -1, 18115 },
  572. { -76635, 85392, -5183, -1, 18115 },
  573. { -76635, 85216, -5183, -1, 18115 },
  574. { -76761, 85025, -5183, -1, 18115 },
  575. { -76908, 85004, -5183, -1, 18115 },
  576. { -77041, 85004, -5183, -1, 18115 },
  577. { -77138, 85025, -5183, -1, 18115 },
  578. { -77268, 85219, -5183, -1, 18115 },
  579. { -77268, 85410, -5183, -1, 18115 },
  580. },
  581. {
  582. /* Level 53 and Below */
  583. { -75150, 87303, -5183, -1, 18116 },
  584. { -75150, 87175, -5183, -1, 18116 },
  585. { -75150, 87175, -5183, -1, 18116 },
  586. { -75150, 87303, -5183, -1, 18116 },
  587. { -74943, 87433, -5183, -1, 18116 },
  588. { -74767, 87433, -5183, -1, 18116 },
  589. { -74556, 87306, -5183, -1, 18116 },
  590. { -74556, 87184, -5183, -1, 18116 },
  591. { -74556, 87184, -5183, -1, 18116 },
  592. { -74556, 87306, -5183, -1, 18116 },
  593. { -74757, 86830, -5183, -1, 18116 },
  594. { -74927, 86830, -5183, -1, 18116 },
  595. },
  596. {
  597. /* Level 64 and Below */
  598. { -80010, 88128, -5183, -1, 18117 },
  599. { -80113, 88066, -5183, -1, 18117 },
  600. { -80220, 88066, -5183, -1, 18117 },
  601. { -80359, 88128, -5183, -1, 18117 },
  602. { -80467, 88267, -5183, -1, 18117 },
  603. { -80467, 88436, -5183, -1, 18117 },
  604. { -80381, 88639, -5183, -1, 18117 },
  605. { -80278, 88577, -5183, -1, 18117 },
  606. { -80142, 88577, -5183, -1, 18117 },
  607. { -80028, 88639, -5183, -1, 18117 },
  608. { -79915, 88466, -5183, -1, 18117 },
  609. { -79915, 88322, -5183, -1, 18117 },
  610. },
  611. {
  612. /* No Level Limit */
  613. { -80153, 84947, -5183, -1, 18118 },
  614. { -80003, 84962, -5183, -1, 18118 },
  615. { -79848, 84962, -5183, -1, 18118 },
  616. { -79742, 84947, -5183, -1, 18118 },
  617. { -79668, 84772, -5183, -1, 18118 },
  618. { -79668, 84619, -5183, -1, 18118 },
  619. { -79772, 84471, -5183, -1, 18118 },
  620. { -79888, 84414, -5183, -1, 18118 },
  621. { -80023, 84414, -5183, -1, 18118 },
  622. { -80166, 84471, -5183, -1, 18118 },
  623. { -80253, 84600, -5183, -1, 18118 },
  624. { -80253, 84780, -5183, -1, 18118 },
  625. }
  626. };
  627. //////////////////////// \\\\\\\\\\\\\\\\\\\\\\\\\\
  628. protected FestivalManager _managerInstance;
  629. protected ScheduledFuture<?> _managerScheduledTask;
  630. protected int _signsCycle = SevenSigns.getInstance().getCurrentCycle();
  631. protected int _festivalCycle;
  632. protected long _nextFestivalCycleStart;
  633. protected long _nextFestivalStart;
  634. protected boolean _festivalInitialized;
  635. protected boolean _festivalInProgress;
  636. protected List<Integer> _accumulatedBonuses; // The total bonus available (in Ancient Adena)
  637. boolean _noPartyRegister;
  638. private L2Npc _dawnChatGuide;
  639. private L2Npc _duskChatGuide;
  640. protected Map<Integer, List<L2PcInstance>> _dawnFestivalParticipants;
  641. protected Map<Integer, List<L2PcInstance>> _duskFestivalParticipants;
  642. protected Map<Integer, List<L2PcInstance>> _dawnPreviousParticipants;
  643. protected Map<Integer, List<L2PcInstance>> _duskPreviousParticipants;
  644. private Map<Integer, Long> _dawnFestivalScores;
  645. private Map<Integer, Long> _duskFestivalScores;
  646. /**
  647. * _festivalData is essentially an instance of the seven_signs_festival table and
  648. * should be treated as such.
  649. *
  650. * Data is initially accessed by the related Seven Signs cycle, with _signsCycle representing
  651. * data for the current round of Festivals.
  652. *
  653. * The actual table data is stored as a series of StatsSet constructs. These are accessed by
  654. * the use of an offset based on the number of festivals, thus:
  655. *
  656. *offset = FESTIVAL_COUNT + festivalId
  657. *(Data for Dawn is always accessed by offset > FESTIVAL_COUNT)
  658. */
  659. private Map<Integer, Map<Integer, StatsSet>> _festivalData;
  660. private SevenSignsFestival()
  661. {
  662. _accumulatedBonuses = new FastList<Integer>();
  663. _dawnFestivalParticipants = new FastMap<Integer, List<L2PcInstance>>();
  664. _dawnPreviousParticipants = new FastMap<Integer, List<L2PcInstance>>();
  665. _dawnFestivalScores = new FastMap<Integer, Long>();
  666. _duskFestivalParticipants = new FastMap<Integer, List<L2PcInstance>>();
  667. _duskPreviousParticipants = new FastMap<Integer, List<L2PcInstance>>();
  668. _duskFestivalScores = new FastMap<Integer, Long>();
  669. _festivalData = new FastMap<Integer, Map<Integer, StatsSet>>();
  670. restoreFestivalData();
  671. if (SevenSigns.getInstance().isSealValidationPeriod())
  672. {
  673. _log.info("SevenSignsFestival: Initialization bypassed due to Seal Validation in effect.");
  674. return;
  675. }
  676. L2Spawn.addSpawnListener(this);
  677. startFestivalManager();
  678. }
  679. public static SevenSignsFestival getInstance()
  680. {
  681. return SingletonHolder._instance;
  682. }
  683. /**
  684. * Returns the associated name (level range) to a given festival ID.
  685. *
  686. * @param int festivalID
  687. * @return String festivalName
  688. */
  689. public static final String getFestivalName(int festivalID)
  690. {
  691. String festivalName;
  692. switch (festivalID)
  693. {
  694. case FESTIVAL_LEVEL_MAX_31:
  695. festivalName = "Level 31 or lower";
  696. break;
  697. case FESTIVAL_LEVEL_MAX_42:
  698. festivalName = "Level 42 or lower";
  699. break;
  700. case FESTIVAL_LEVEL_MAX_53:
  701. festivalName = "Level 53 or lower";
  702. break;
  703. case FESTIVAL_LEVEL_MAX_64:
  704. festivalName = "Level 64 or lower";
  705. break;
  706. default:
  707. festivalName = "No Level Limit";
  708. break;
  709. }
  710. return festivalName;
  711. }
  712. /**
  713. * Returns the maximum allowed player level for the given festival type.
  714. *
  715. * @param festivalId
  716. * @return int maxLevel
  717. */
  718. public static final int getMaxLevelForFestival(int festivalId)
  719. {
  720. int maxLevel = (Experience.MAX_LEVEL - 1);
  721. switch (festivalId)
  722. {
  723. case SevenSignsFestival.FESTIVAL_LEVEL_MAX_31:
  724. maxLevel = 31;
  725. break;
  726. case SevenSignsFestival.FESTIVAL_LEVEL_MAX_42:
  727. maxLevel = 42;
  728. break;
  729. case SevenSignsFestival.FESTIVAL_LEVEL_MAX_53:
  730. maxLevel = 53;
  731. break;
  732. case SevenSignsFestival.FESTIVAL_LEVEL_MAX_64:
  733. maxLevel = 64;
  734. break;
  735. }
  736. return maxLevel;
  737. }
  738. /**
  739. * Returns true if the monster ID given is of an archer/marksman type.
  740. *
  741. * @param npcId
  742. * @return boolean isArcher
  743. */
  744. protected static final boolean isFestivalArcher(int npcId)
  745. {
  746. if (npcId < 18009 || npcId > 18108)
  747. return false;
  748. int identifier = npcId % 10;
  749. return (identifier == 4 || identifier == 9);
  750. }
  751. /**
  752. * Returns true if the monster ID given is a festival chest.
  753. *
  754. * @param npcId
  755. * @return boolean isChest
  756. */
  757. protected static final boolean isFestivalChest(int npcId)
  758. {
  759. return (npcId < 18109 || npcId > 18118);
  760. }
  761. /**
  762. * Primarily used to terminate the Festival Manager, when the Seven Signs period changes.
  763. *
  764. * @return ScheduledFuture festManagerScheduler
  765. */
  766. protected final ScheduledFuture<?> getFestivalManagerSchedule()
  767. {
  768. if (_managerScheduledTask == null)
  769. startFestivalManager();
  770. return _managerScheduledTask;
  771. }
  772. /**
  773. * Used to start the Festival Manager, if the current period is not Seal Validation.
  774. */
  775. protected void startFestivalManager()
  776. {
  777. // Start the Festival Manager for the first time after the server has started
  778. // at the specified time, then invoke it automatically after every cycle.
  779. FestivalManager fm = new FestivalManager();
  780. setNextFestivalStart(Config.ALT_FESTIVAL_MANAGER_START + FESTIVAL_SIGNUP_TIME);
  781. _managerScheduledTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(fm, Config.ALT_FESTIVAL_MANAGER_START, Config.ALT_FESTIVAL_CYCLE_LENGTH);
  782. _log.info("SevenSignsFestival: The first Festival of Darkness cycle begins in " + (Config.ALT_FESTIVAL_MANAGER_START / 60000)
  783. + " minute(s).");
  784. }
  785. /**
  786. * Restores saved festival data, basic settings from the properties file
  787. * and past high score data from the database.
  788. *
  789. * @throws Exception
  790. */
  791. protected void restoreFestivalData()
  792. {
  793. Connection con = null;
  794. PreparedStatement statement = null;
  795. ResultSet rset = null;
  796. if (Config.DEBUG)
  797. _log.info("SevenSignsFestival: Restoring festival data. Current SS Cycle: " + _signsCycle);
  798. try
  799. {
  800. con = L2DatabaseFactory.getInstance().getConnection();
  801. statement = con.prepareStatement("SELECT festivalId, cabal, cycle, date, score, members " + "FROM seven_signs_festival");
  802. rset = statement.executeQuery();
  803. while (rset.next())
  804. {
  805. int festivalCycle = rset.getInt("cycle");
  806. int festivalId = rset.getInt("festivalId");
  807. String cabal = rset.getString("cabal");
  808. StatsSet festivalDat = new StatsSet();
  809. festivalDat.set("festivalId", festivalId);
  810. festivalDat.set("cabal", cabal);
  811. festivalDat.set("cycle", festivalCycle);
  812. festivalDat.set("date", rset.getString("date"));
  813. festivalDat.set("score", rset.getInt("score"));
  814. festivalDat.set("members", rset.getString("members"));
  815. if (Config.DEBUG)
  816. _log.info("SevenSignsFestival: Loaded data from DB for (Cycle = " + festivalCycle + ", Oracle = " + cabal
  817. + ", Festival = " + getFestivalName(festivalId));
  818. if (cabal.equals("dawn"))
  819. festivalId += FESTIVAL_COUNT;
  820. Map<Integer, StatsSet> tempData = _festivalData.get(festivalCycle);
  821. if (tempData == null)
  822. tempData = new FastMap<Integer, StatsSet>();
  823. tempData.put(festivalId, festivalDat);
  824. _festivalData.put(festivalCycle, tempData);
  825. }
  826. rset.close();
  827. statement.close();
  828. String query = "SELECT festival_cycle, ";
  829. for (int i = 0; i < FESTIVAL_COUNT - 1; i++)
  830. query += "accumulated_bonus" + String.valueOf(i) + ", ";
  831. query += "accumulated_bonus" + String.valueOf(FESTIVAL_COUNT - 1) + " ";
  832. query += "FROM seven_signs_status WHERE id=0";
  833. statement = con.prepareStatement(query);
  834. rset = statement.executeQuery();
  835. while (rset.next())
  836. {
  837. _festivalCycle = rset.getInt("festival_cycle");
  838. for (int i = 0; i < FESTIVAL_COUNT; i++)
  839. _accumulatedBonuses.add(i, rset.getInt("accumulated_bonus" + String.valueOf(i)));
  840. }
  841. rset.close();
  842. statement.close();
  843. con.close();
  844. if (Config.DEBUG)
  845. _log.info("SevenSignsFestival: Loaded data from database.");
  846. }
  847. catch (SQLException e)
  848. {
  849. _log.severe("SevenSignsFestival: Failed to load configuration: " + e);
  850. }
  851. finally
  852. {
  853. try
  854. {
  855. rset.close();
  856. statement.close();
  857. con.close();
  858. }
  859. catch (SQLException e)
  860. {
  861. }
  862. }
  863. }
  864. /**
  865. * Stores current festival data, basic settings to the properties file
  866. * and past high score data to the database.
  867. *
  868. * If updateSettings = true, then all Seven Signs data is updated in the database.
  869. *
  870. * @param updateSettings
  871. * @throws Exception
  872. */
  873. public void saveFestivalData(boolean updateSettings)
  874. {
  875. Connection con = null;
  876. PreparedStatement statement = null;
  877. if (Config.DEBUG)
  878. _log.info("SevenSignsFestival: Saving festival data to disk.");
  879. try
  880. {
  881. con = L2DatabaseFactory.getInstance().getConnection();
  882. for (Map<Integer, StatsSet> currCycleData : _festivalData.values())
  883. {
  884. for (StatsSet festivalDat : currCycleData.values())
  885. {
  886. int festivalCycle = festivalDat.getInteger("cycle");
  887. int festivalId = festivalDat.getInteger("festivalId");
  888. String cabal = festivalDat.getString("cabal");
  889. // Try to update an existing record.
  890. statement = con.prepareStatement("UPDATE seven_signs_festival SET date=?, score=?, members=? WHERE cycle=? AND cabal=? AND festivalId=?");
  891. statement.setLong(1, Long.valueOf(festivalDat.getString("date")));
  892. statement.setInt(2, festivalDat.getInteger("score"));
  893. statement.setString(3, festivalDat.getString("members"));
  894. statement.setInt(4, festivalCycle);
  895. statement.setString(5, cabal);
  896. statement.setInt(6, festivalId);
  897. // If there was no record to update, assume it doesn't exist and add a new one,
  898. // otherwise continue with the next record to store.
  899. if (statement.executeUpdate() > 0)
  900. {
  901. if (Config.DEBUG)
  902. _log.info("SevenSignsFestival: Updated data in DB (Cycle = " + festivalCycle + ", Cabal = " + cabal
  903. + ", FestID = " + festivalId + ")");
  904. statement.close();
  905. continue;
  906. }
  907. statement.close();
  908. statement = con.prepareStatement("INSERT INTO seven_signs_festival (festivalId, cabal, cycle, date, score, members) VALUES (?,?,?,?,?,?)");
  909. statement.setInt(1, festivalId);
  910. statement.setString(2, cabal);
  911. statement.setInt(3, festivalCycle);
  912. statement.setLong(4, Long.valueOf(festivalDat.getString("date")));
  913. statement.setInt(5, festivalDat.getInteger("score"));
  914. statement.setString(6, festivalDat.getString("members"));
  915. statement.execute();
  916. statement.close();
  917. if (Config.DEBUG)
  918. _log.info("SevenSignsFestival: Inserted data in DB (Cycle = " + festivalCycle + ", Cabal = " + cabal
  919. + ", FestID = " + festivalId + ")");
  920. }
  921. }
  922. con.close();
  923. // Updates Seven Signs DB data also, so call only if really necessary.
  924. if (updateSettings)
  925. SevenSigns.getInstance().saveSevenSignsData(null, true);
  926. }
  927. catch (SQLException e)
  928. {
  929. _log.severe("SevenSignsFestival: Failed to save configuration: " + e);
  930. }
  931. finally
  932. {
  933. try
  934. {
  935. statement.close();
  936. con.close();
  937. }
  938. catch (Exception e)
  939. {
  940. }
  941. }
  942. }
  943. /**
  944. * If a clan member is a member of the highest-ranked party in the Festival of Darkness, 100 points are added per member
  945. */
  946. protected void rewardHighestRanked()
  947. {
  948. String[] partyMembers;
  949. StatsSet overallData = getOverallHighestScoreData(FESTIVAL_LEVEL_MAX_31);
  950. if (overallData != null)
  951. {
  952. partyMembers = overallData.getString("members").split(",");
  953. for (String partyMemberName : partyMembers)
  954. addReputationPointsForPartyMemberClan(partyMemberName);
  955. }
  956. overallData = getOverallHighestScoreData(FESTIVAL_LEVEL_MAX_42);
  957. if (overallData != null)
  958. {
  959. partyMembers = overallData.getString("members").split(",");
  960. for (String partyMemberName : partyMembers)
  961. addReputationPointsForPartyMemberClan(partyMemberName);
  962. }
  963. overallData = getOverallHighestScoreData(FESTIVAL_LEVEL_MAX_53);
  964. if (overallData != null)
  965. {
  966. partyMembers = overallData.getString("members").split(",");
  967. for (String partyMemberName : partyMembers)
  968. addReputationPointsForPartyMemberClan(partyMemberName);
  969. }
  970. overallData = getOverallHighestScoreData(FESTIVAL_LEVEL_MAX_64);
  971. if (overallData != null)
  972. {
  973. partyMembers = overallData.getString("members").split(",");
  974. for (String partyMemberName : partyMembers)
  975. addReputationPointsForPartyMemberClan(partyMemberName);
  976. }
  977. overallData = getOverallHighestScoreData(FESTIVAL_LEVEL_MAX_NONE);
  978. if (overallData != null)
  979. {
  980. partyMembers = overallData.getString("members").split(",");
  981. for (String partyMemberName : partyMembers)
  982. addReputationPointsForPartyMemberClan(partyMemberName);
  983. }
  984. }
  985. private void addReputationPointsForPartyMemberClan(String partyMemberName)
  986. {
  987. L2PcInstance player = L2World.getInstance().getPlayer(partyMemberName);
  988. if (player != null)
  989. {
  990. if (player.getClan() != null)
  991. {
  992. player.getClan().setReputationScore(player.getClan().getReputationScore() + Config.FESTIVAL_WIN_POINTS, true);
  993. SystemMessage sm = new SystemMessage(SystemMessageId.CLAN_MEMBER_C1_WAS_IN_HIGHEST_RANKED_PARTY_IN_FESTIVAL_OF_DARKNESS_AND_GAINED_S2_REPUTATION);
  994. sm.addString(partyMemberName);
  995. sm.addNumber(Config.FESTIVAL_WIN_POINTS);
  996. player.getClan().broadcastToOnlineMembers(sm);
  997. }
  998. }
  999. else
  1000. {
  1001. Connection con = null;
  1002. try
  1003. {
  1004. con = L2DatabaseFactory.getInstance().getConnection();
  1005. PreparedStatement statement = con.prepareStatement(GET_CLAN_NAME);
  1006. statement.setString(1, partyMemberName);
  1007. ResultSet rset = statement.executeQuery();
  1008. if (rset.next())
  1009. {
  1010. String clanName = rset.getString("clan_name");
  1011. if (clanName != null)
  1012. {
  1013. L2Clan clan = ClanTable.getInstance().getClanByName(clanName);
  1014. if (clan != null)
  1015. {
  1016. clan.setReputationScore(clan.getReputationScore() + Config.FESTIVAL_WIN_POINTS, true);
  1017. SystemMessage sm = new SystemMessage(SystemMessageId.CLAN_MEMBER_C1_WAS_IN_HIGHEST_RANKED_PARTY_IN_FESTIVAL_OF_DARKNESS_AND_GAINED_S2_REPUTATION);
  1018. sm.addString(partyMemberName);
  1019. sm.addNumber(Config.FESTIVAL_WIN_POINTS);
  1020. clan.broadcastToOnlineMembers(sm);
  1021. }
  1022. }
  1023. }
  1024. rset.close();
  1025. statement.close();
  1026. }
  1027. catch (Exception e)
  1028. {
  1029. _log.warning("could not get clan name of " + partyMemberName + ": " + e);
  1030. }
  1031. finally
  1032. {
  1033. try
  1034. {
  1035. con.close();
  1036. }
  1037. catch (Exception e)
  1038. {
  1039. }
  1040. }
  1041. }
  1042. }
  1043. /**
  1044. * Used to reset all festival data at the beginning of a new quest event period.
  1045. */
  1046. protected void resetFestivalData(boolean updateSettings)
  1047. {
  1048. _festivalCycle = 0;
  1049. _signsCycle = SevenSigns.getInstance().getCurrentCycle();
  1050. // Set all accumulated bonuses back to 0.
  1051. for (int i = 0; i < FESTIVAL_COUNT; i++)
  1052. _accumulatedBonuses.set(i, 0);
  1053. _dawnFestivalParticipants.clear();
  1054. _dawnPreviousParticipants.clear();
  1055. _dawnFestivalScores.clear();
  1056. _duskFestivalParticipants.clear();
  1057. _duskPreviousParticipants.clear();
  1058. _duskFestivalScores.clear();
  1059. // Set up a new data set for the current cycle of festivals
  1060. Map<Integer, StatsSet> newData = new FastMap<Integer, StatsSet>();
  1061. for (int i = 0; i < FESTIVAL_COUNT * 2; i++)
  1062. {
  1063. int festivalId = i;
  1064. if (i >= FESTIVAL_COUNT)
  1065. festivalId -= FESTIVAL_COUNT;
  1066. // Create a new StatsSet with "default" data for Dusk
  1067. StatsSet tempStats = new StatsSet();
  1068. tempStats.set("festivalId", festivalId);
  1069. tempStats.set("cycle", _signsCycle);
  1070. tempStats.set("date", "0");
  1071. tempStats.set("score", 0);
  1072. tempStats.set("members", "");
  1073. if (i >= FESTIVAL_COUNT)
  1074. tempStats.set("cabal", SevenSigns.getCabalShortName(SevenSigns.CABAL_DAWN));
  1075. else
  1076. tempStats.set("cabal", SevenSigns.getCabalShortName(SevenSigns.CABAL_DUSK));
  1077. newData.put(i, tempStats);
  1078. }
  1079. // Add the newly created cycle data to the existing festival data, and
  1080. // subsequently save it to the database.
  1081. _festivalData.put(_signsCycle, newData);
  1082. saveFestivalData(updateSettings);
  1083. // Remove any unused blood offerings from online players.
  1084. Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
  1085. //synchronized (L2World.getInstance().getAllPlayers())
  1086. {
  1087. for (L2PcInstance onlinePlayer : pls)
  1088. {
  1089. try
  1090. {
  1091. L2ItemInstance bloodOfferings = onlinePlayer.getInventory().getItemByItemId(FESTIVAL_OFFERING_ID);
  1092. if (bloodOfferings != null)
  1093. onlinePlayer.destroyItem("SevenSigns", bloodOfferings, null, false);
  1094. }
  1095. catch (NullPointerException e)
  1096. {
  1097. }
  1098. }
  1099. }
  1100. _log.info("SevenSignsFestival: Reinitialized engine for next competition period.");
  1101. }
  1102. public final int getCurrentFestivalCycle()
  1103. {
  1104. return _festivalCycle;
  1105. }
  1106. public final boolean isFestivalInitialized()
  1107. {
  1108. return _festivalInitialized;
  1109. }
  1110. public final boolean isFestivalInProgress()
  1111. {
  1112. return _festivalInProgress;
  1113. }
  1114. public void setNextCycleStart()
  1115. {
  1116. _nextFestivalCycleStart = System.currentTimeMillis() + Config.ALT_FESTIVAL_CYCLE_LENGTH;
  1117. }
  1118. public void setNextFestivalStart(long milliFromNow)
  1119. {
  1120. _nextFestivalStart = System.currentTimeMillis() + milliFromNow;
  1121. }
  1122. public final int getMinsToNextCycle()
  1123. {
  1124. if (SevenSigns.getInstance().isSealValidationPeriod())
  1125. return -1;
  1126. return Math.round((_nextFestivalCycleStart - System.currentTimeMillis()) / 60000);
  1127. }
  1128. public final int getMinsToNextFestival()
  1129. {
  1130. if (SevenSigns.getInstance().isSealValidationPeriod())
  1131. return -1;
  1132. return Math.round((_nextFestivalStart - System.currentTimeMillis()) / 60000) + 1;
  1133. }
  1134. public final String getTimeToNextFestivalStr()
  1135. {
  1136. if (SevenSigns.getInstance().isSealValidationPeriod())
  1137. return "<font color=\"FF0000\">This is the Seal Validation period. Festivals will resume next week.</font>";
  1138. return "<font color=\"FF0000\">The next festival will begin in " + getMinsToNextFestival() + " minute(s).</font>";
  1139. }
  1140. /**
  1141. * Returns the current festival ID and oracle ID that the specified player is in,
  1142. * but will return the default of {-1, -1} if the player is not found as a participant.
  1143. *
  1144. * @param player
  1145. * @return int[] playerFestivalInfo
  1146. */
  1147. public final int[] getFestivalForPlayer(L2PcInstance player)
  1148. {
  1149. int[] playerFestivalInfo = { -1, -1 };
  1150. int festivalId = 0;
  1151. while (festivalId < FESTIVAL_COUNT)
  1152. {
  1153. List<L2PcInstance> participants = _dawnFestivalParticipants.get(festivalId);
  1154. // If there are no participants in this festival, move on to the next.
  1155. if (participants != null && participants.contains(player))
  1156. {
  1157. playerFestivalInfo[0] = SevenSigns.CABAL_DAWN;
  1158. playerFestivalInfo[1] = festivalId;
  1159. return playerFestivalInfo;
  1160. }
  1161. participants = _duskFestivalParticipants.get(++festivalId);
  1162. if (participants != null && participants.contains(player))
  1163. {
  1164. playerFestivalInfo[0] = SevenSigns.CABAL_DUSK;
  1165. playerFestivalInfo[1] = festivalId;
  1166. return playerFestivalInfo;
  1167. }
  1168. festivalId++;
  1169. }
  1170. // Return default data if the player is not found as a participant.
  1171. return playerFestivalInfo;
  1172. }
  1173. public final boolean isParticipant(L2PcInstance player)
  1174. {
  1175. if (SevenSigns.getInstance().isSealValidationPeriod())
  1176. return false;
  1177. if (_managerInstance == null)
  1178. return false;
  1179. for (List<L2PcInstance> participants : _dawnFestivalParticipants.values())
  1180. if (participants.contains(player))
  1181. return true;
  1182. for (List<L2PcInstance> participants : _duskFestivalParticipants.values())
  1183. if (participants.contains(player))
  1184. return true;
  1185. return false;
  1186. }
  1187. public final List<L2PcInstance> getParticipants(int oracle, int festivalId)
  1188. {
  1189. if (oracle == SevenSigns.CABAL_DAWN)
  1190. return _dawnFestivalParticipants.get(festivalId);
  1191. return _duskFestivalParticipants.get(festivalId);
  1192. }
  1193. public final List<L2PcInstance> getPreviousParticipants(int oracle, int festivalId)
  1194. {
  1195. if (oracle == SevenSigns.CABAL_DAWN)
  1196. return _dawnPreviousParticipants.get(festivalId);
  1197. return _duskPreviousParticipants.get(festivalId);
  1198. }
  1199. public void setParticipants(int oracle, int festivalId, L2Party festivalParty)
  1200. {
  1201. List<L2PcInstance> participants = new FastList<L2PcInstance>();
  1202. if (festivalParty != null)
  1203. {
  1204. participants = festivalParty.getPartyMembers();
  1205. if (Config.DEBUG)
  1206. _log.info("SevenSignsFestival: " + festivalParty.getPartyMembers().toString() + " have signed up to the "
  1207. + SevenSigns.getCabalShortName(oracle) + " " + getFestivalName(festivalId) + " festival.");
  1208. }
  1209. if (oracle == SevenSigns.CABAL_DAWN)
  1210. _dawnFestivalParticipants.put(festivalId, participants);
  1211. else
  1212. _duskFestivalParticipants.put(festivalId, participants);
  1213. }
  1214. public void updateParticipants(L2PcInstance player, L2Party festivalParty)
  1215. {
  1216. if (!isParticipant(player))
  1217. return;
  1218. final int[] playerFestInfo = getFestivalForPlayer(player);
  1219. final int oracle = playerFestInfo[0];
  1220. final int festivalId = playerFestInfo[1];
  1221. if (festivalId > -1)
  1222. {
  1223. if (_festivalInitialized)
  1224. {
  1225. L2DarknessFestival festivalInst = _managerInstance.getFestivalInstance(oracle, festivalId);
  1226. if (festivalParty == null)// leader has left
  1227. for (L2PcInstance partyMember : getParticipants(oracle, festivalId))
  1228. festivalInst.relocatePlayer(partyMember, true);
  1229. else
  1230. festivalInst.relocatePlayer(player, true);
  1231. }
  1232. setParticipants(oracle, festivalId, festivalParty);
  1233. // Check on disconnect if min player in party
  1234. if (festivalParty != null && festivalParty.getMemberCount() < Config.ALT_FESTIVAL_MIN_PLAYER)
  1235. {
  1236. updateParticipants(player, null); // under minimum count
  1237. festivalParty.removePartyMember(player);
  1238. }
  1239. }
  1240. }
  1241. public final long getFinalScore(int oracle, int festivalId)
  1242. {
  1243. if (oracle == SevenSigns.CABAL_DAWN)
  1244. return _dawnFestivalScores.get(festivalId);
  1245. return _duskFestivalScores.get(festivalId);
  1246. }
  1247. public final int getHighestScore(int oracle, int festivalId)
  1248. {
  1249. return getHighestScoreData(oracle, festivalId).getInteger("score");
  1250. }
  1251. /**
  1252. * Returns a stats set containing the highest score <b>this cycle</b> for the
  1253. * the specified cabal and associated festival ID.
  1254. *
  1255. * @param oracle
  1256. * @param festivalId
  1257. * @return StatsSet festivalDat
  1258. */
  1259. public final StatsSet getHighestScoreData(int oracle, int festivalId)
  1260. {
  1261. int offsetId = festivalId;
  1262. if (oracle == SevenSigns.CABAL_DAWN)
  1263. offsetId += 5;
  1264. // Attempt to retrieve existing score data (if found), otherwise create a
  1265. // new blank data set and display a console warning.
  1266. StatsSet currData = null;
  1267. try
  1268. {
  1269. currData = _festivalData.get(_signsCycle).get(offsetId);
  1270. }
  1271. catch (Exception e)
  1272. {
  1273. currData = new StatsSet();
  1274. currData.set("score", 0);
  1275. currData.set("members", "");
  1276. if (Config.DEBUG)
  1277. _log.info("SevenSignsFestival: Data missing for " + SevenSigns.getCabalName(oracle) + ", FestivalID = " + festivalId
  1278. + " (Current Cycle " + _signsCycle + ")");
  1279. }
  1280. return currData;
  1281. }
  1282. /**
  1283. * Returns a stats set containing the highest ever recorded
  1284. * score data for the specified festival.
  1285. *
  1286. * @param festivalId
  1287. * @return StatsSet result
  1288. */
  1289. public final StatsSet getOverallHighestScoreData(int festivalId)
  1290. {
  1291. StatsSet result = null;
  1292. int highestScore = 0;
  1293. for (Map<Integer, StatsSet> currCycleData : _festivalData.values())
  1294. {
  1295. for (StatsSet currFestData : currCycleData.values())
  1296. {
  1297. int currFestID = currFestData.getInteger("festivalId");
  1298. int festivalScore = currFestData.getInteger("score");
  1299. if (currFestID != festivalId)
  1300. continue;
  1301. if (festivalScore > highestScore)
  1302. {
  1303. highestScore = festivalScore;
  1304. result = currFestData;
  1305. }
  1306. }
  1307. }
  1308. return result;
  1309. }
  1310. /**
  1311. * Set the final score details for the last participants of the specified festival data.
  1312. * Returns <b>true</b> if the score is higher than that previously recorded <b>this cycle</b>.
  1313. *
  1314. * @param player
  1315. * @param oracle
  1316. * @param festivalId
  1317. * @param offeringScore
  1318. * @return boolean isHighestScore
  1319. */
  1320. public boolean setFinalScore(L2PcInstance player, int oracle, int festivalId, long offeringScore)
  1321. {
  1322. List<String> partyMembers;
  1323. int currDawnHighScore = getHighestScore(SevenSigns.CABAL_DAWN, festivalId);
  1324. int currDuskHighScore = getHighestScore(SevenSigns.CABAL_DUSK, festivalId);
  1325. int thisCabalHighScore = 0;
  1326. int otherCabalHighScore = 0;
  1327. if (oracle == SevenSigns.CABAL_DAWN)
  1328. {
  1329. thisCabalHighScore = currDawnHighScore;
  1330. otherCabalHighScore = currDuskHighScore;
  1331. _dawnFestivalScores.put(festivalId, offeringScore);
  1332. }
  1333. else
  1334. {
  1335. thisCabalHighScore = currDuskHighScore;
  1336. otherCabalHighScore = currDawnHighScore;
  1337. _duskFestivalScores.put(festivalId, offeringScore);
  1338. }
  1339. StatsSet currFestData = getHighestScoreData(oracle, festivalId);
  1340. // Check if this is the highest score for this level range so far for the player's cabal.
  1341. if (offeringScore > thisCabalHighScore)
  1342. {
  1343. // If the current score is greater than that for the other cabal,
  1344. // then they already have the points from this festival.
  1345. if (thisCabalHighScore < otherCabalHighScore)
  1346. return false;
  1347. partyMembers = new FastList<String>();
  1348. List<L2PcInstance> prevParticipants = getPreviousParticipants(oracle, festivalId);
  1349. // Record a string list of the party members involved.
  1350. for (L2PcInstance partyMember : prevParticipants)
  1351. {
  1352. try
  1353. {
  1354. partyMembers.add(partyMember.getName());
  1355. }
  1356. catch (NullPointerException e)
  1357. {
  1358. }
  1359. }
  1360. // Update the highest scores and party list.
  1361. currFestData.set("date", String.valueOf(System.currentTimeMillis()));
  1362. currFestData.set("score", offeringScore);
  1363. currFestData.set("members", Util.implodeString(partyMembers, ","));
  1364. if (Config.DEBUG)
  1365. _log.info("SevenSignsFestival: " + player.getName() + "'s party has the highest score (" + offeringScore + ") so far for "
  1366. + SevenSigns.getCabalName(oracle) + " in " + getFestivalName(festivalId));
  1367. // Only add the score to the cabal's overall if it's higher than the other cabal's score.
  1368. if (offeringScore > otherCabalHighScore)
  1369. {
  1370. int contribPoints = FESTIVAL_LEVEL_SCORES[festivalId];
  1371. // Give this cabal the festival points, while deducting them from the other.
  1372. SevenSigns.getInstance().addFestivalScore(oracle, contribPoints);
  1373. if (Config.DEBUG)
  1374. _log.info("SevenSignsFestival: This is the highest score overall so far for the " + getFestivalName(festivalId)
  1375. + " festival!");
  1376. }
  1377. saveFestivalData(true);
  1378. return true;
  1379. }
  1380. return false;
  1381. }
  1382. public final int getAccumulatedBonus(int festivalId)
  1383. {
  1384. return _accumulatedBonuses.get(festivalId);
  1385. }
  1386. public final int getTotalAccumulatedBonus()
  1387. {
  1388. int totalAccumBonus = 0;
  1389. for (int accumBonus : _accumulatedBonuses)
  1390. totalAccumBonus += accumBonus;
  1391. return totalAccumBonus;
  1392. }
  1393. public void addAccumulatedBonus(int festivalId, int stoneType, int stoneAmount)
  1394. {
  1395. int eachStoneBonus = 0;
  1396. switch (stoneType)
  1397. {
  1398. case SevenSigns.SEAL_STONE_BLUE_ID:
  1399. eachStoneBonus = SevenSigns.SEAL_STONE_BLUE_VALUE;
  1400. break;
  1401. case SevenSigns.SEAL_STONE_GREEN_ID:
  1402. eachStoneBonus = SevenSigns.SEAL_STONE_GREEN_VALUE;
  1403. break;
  1404. case SevenSigns.SEAL_STONE_RED_ID:
  1405. eachStoneBonus = SevenSigns.SEAL_STONE_RED_VALUE;
  1406. break;
  1407. }
  1408. int newTotalBonus = _accumulatedBonuses.get(festivalId) + (stoneAmount * eachStoneBonus);
  1409. _accumulatedBonuses.set(festivalId, newTotalBonus);
  1410. }
  1411. /**
  1412. * Calculate and return the proportion of the accumulated bonus for the festival
  1413. * where the player was in the winning party, if the winning party's cabal won the event.
  1414. *
  1415. * The accumulated bonus is then updated, with the player's share deducted.
  1416. *
  1417. * @param player
  1418. * @return playerBonus (the share of the bonus for the party)
  1419. */
  1420. public final int distribAccumulatedBonus(L2PcInstance player)
  1421. {
  1422. int playerBonus = 0;
  1423. String playerName = player.getName();
  1424. int playerCabal = SevenSigns.getInstance().getPlayerCabal(player);
  1425. if (playerCabal != SevenSigns.getInstance().getCabalHighestScore())
  1426. return 0;
  1427. if (_festivalData.get(_signsCycle) != null)
  1428. for (StatsSet festivalData : _festivalData.get(_signsCycle).values())
  1429. {
  1430. if (festivalData.getString("members").indexOf(playerName) > -1)
  1431. {
  1432. int festivalId = festivalData.getInteger("festivalId");
  1433. int numPartyMembers = festivalData.getString("members").split(",").length;
  1434. int totalAccumBonus = _accumulatedBonuses.get(festivalId);
  1435. playerBonus = totalAccumBonus / numPartyMembers;
  1436. _accumulatedBonuses.set(festivalId, totalAccumBonus - playerBonus);
  1437. break;
  1438. }
  1439. }
  1440. return playerBonus;
  1441. }
  1442. /**
  1443. * Used to send a "shout" message to all players currently present in an Oracle.
  1444. * Primarily used for Festival Guide and Witch related speech.
  1445. *
  1446. * @param senderName
  1447. * @param message
  1448. */
  1449. public void sendMessageToAll(String senderName, String message)
  1450. {
  1451. if (_dawnChatGuide == null || _duskChatGuide == null)
  1452. return;
  1453. CreatureSay cs = new CreatureSay(_dawnChatGuide.getObjectId(), Say2.SHOUT, senderName, message);
  1454. _dawnChatGuide.broadcastPacket(cs);
  1455. cs = new CreatureSay(_duskChatGuide.getObjectId(), Say2.SHOUT, senderName, message);
  1456. _duskChatGuide.broadcastPacket(cs);
  1457. }
  1458. /**
  1459. * Basically a wrapper-call to signal to increase the challenge of the specified festival.
  1460. *
  1461. * @param oracle
  1462. * @param festivalId
  1463. * @return boolean isChalIncreased
  1464. */
  1465. public final boolean increaseChallenge(int oracle, int festivalId)
  1466. {
  1467. L2DarknessFestival festivalInst = _managerInstance.getFestivalInstance(oracle, festivalId);
  1468. return festivalInst.increaseChallenge();
  1469. }
  1470. /**
  1471. * Used with the SpawnListener, to update the required "chat guide" instances,
  1472. * for use with announcements in the oracles.
  1473. *
  1474. * @param npc
  1475. */
  1476. public void npcSpawned(L2Npc npc)
  1477. {
  1478. if (npc == null)
  1479. return;
  1480. int npcId = npc.getNpcId();
  1481. // If the spawned NPC ID matches the ones we need, assign their instances.
  1482. if (npcId == 31127)
  1483. {
  1484. if (Config.DEBUG)
  1485. _log.config("SevenSignsFestival: Instance found for NPC ID 31127 (" + npc.getObjectId() + ").");
  1486. _dawnChatGuide = npc;
  1487. }
  1488. if (npcId == 31137)
  1489. {
  1490. if (Config.DEBUG)
  1491. _log.config("SevenSignsFestival: Instance found for NPC ID 31137 (" + npc.getObjectId() + ").");
  1492. _duskChatGuide = npc;
  1493. }
  1494. }
  1495. /**
  1496. * The FestivalManager class is the main runner of all the festivals.
  1497. * It is used for easier integration and management of all running festivals.
  1498. *
  1499. * @author Tempy
  1500. */
  1501. private class FestivalManager implements Runnable
  1502. {
  1503. protected Map<Integer, L2DarknessFestival> _festivalInstances;
  1504. public FestivalManager()
  1505. {
  1506. _festivalInstances = new FastMap<Integer, L2DarknessFestival>();
  1507. _managerInstance = this;
  1508. // Increment the cycle counter.
  1509. _festivalCycle++;
  1510. // Set the next start timers.
  1511. setNextCycleStart();
  1512. setNextFestivalStart(Config.ALT_FESTIVAL_CYCLE_LENGTH - FESTIVAL_SIGNUP_TIME);
  1513. }
  1514. public synchronized void run()
  1515. {
  1516. // The manager shouldn't be running if Seal Validation is in effect.
  1517. if (SevenSigns.getInstance().isSealValidationPeriod())
  1518. return;
  1519. // If the next period is due to start before the end of this
  1520. // festival cycle, then don't run it.
  1521. if (SevenSigns.getInstance().getMilliToPeriodChange() < Config.ALT_FESTIVAL_CYCLE_LENGTH)
  1522. return;
  1523. if (Config.DEBUG)
  1524. _log.info("SevenSignsFestival: Festival manager initialized. Those wishing to participate have " + getMinsToNextFestival()
  1525. + " minute(s) to sign up.");
  1526. sendMessageToAll("Festival Guide", "The main event will start in " + getMinsToNextFestival() + " minutes. Please register now.");
  1527. // Stand by until the allowed signup period has elapsed.
  1528. try
  1529. {
  1530. wait(FESTIVAL_SIGNUP_TIME);
  1531. }
  1532. catch (InterruptedException e)
  1533. {
  1534. }
  1535. // Clear past participants, they can no longer register their score if not done so already.
  1536. _dawnPreviousParticipants.clear();
  1537. _duskPreviousParticipants.clear();
  1538. // Get rid of random monsters that avoided deletion after last festival
  1539. for (L2DarknessFestival festivalInst : _festivalInstances.values())
  1540. festivalInst.unspawnMobs();
  1541. // Start only if participants signed up
  1542. _noPartyRegister = true;
  1543. while (_noPartyRegister)
  1544. {
  1545. if ((_duskFestivalParticipants.isEmpty() && _dawnFestivalParticipants.isEmpty()))
  1546. {
  1547. try
  1548. {
  1549. setNextCycleStart();
  1550. setNextFestivalStart(Config.ALT_FESTIVAL_CYCLE_LENGTH - FESTIVAL_SIGNUP_TIME);
  1551. wait(Config.ALT_FESTIVAL_CYCLE_LENGTH - FESTIVAL_SIGNUP_TIME);
  1552. for (L2DarknessFestival festivalInst : _festivalInstances.values())
  1553. {
  1554. if (!festivalInst._npcInsts.isEmpty())
  1555. {
  1556. festivalInst.unspawnMobs();
  1557. }
  1558. }
  1559. }
  1560. catch (InterruptedException e)
  1561. {
  1562. }
  1563. }
  1564. else
  1565. {
  1566. _noPartyRegister = false;
  1567. }
  1568. }
  1569. /* INITIATION */
  1570. // Set the festival timer to 0, as it is just beginning.
  1571. long elapsedTime = 0;
  1572. // Create the instances for the festivals in both Oracles,
  1573. // but only if they have participants signed up for them.
  1574. for (int i = 0; i < FESTIVAL_COUNT; i++)
  1575. {
  1576. if (_duskFestivalParticipants.get(i) != null)
  1577. _festivalInstances.put(10 + i, new L2DarknessFestival(SevenSigns.CABAL_DUSK, i));
  1578. if (_dawnFestivalParticipants.get(i) != null)
  1579. _festivalInstances.put(20 + i, new L2DarknessFestival(SevenSigns.CABAL_DAWN, i));
  1580. }
  1581. // Prevent future signups while festival is in progress.
  1582. _festivalInitialized = true;
  1583. setNextFestivalStart(Config.ALT_FESTIVAL_CYCLE_LENGTH);
  1584. sendMessageToAll("Festival Guide", "The main event is now starting.");
  1585. if (Config.DEBUG)
  1586. _log.info("SevenSignsFestival: The current set of festivals will begin in " + (Config.ALT_FESTIVAL_FIRST_SPAWN / 60000)
  1587. + " minute(s).");
  1588. // Stand by for a short length of time before starting the festival.
  1589. try
  1590. {
  1591. wait(Config.ALT_FESTIVAL_FIRST_SPAWN);
  1592. }
  1593. catch (InterruptedException e)
  1594. {
  1595. }
  1596. elapsedTime = Config.ALT_FESTIVAL_FIRST_SPAWN;
  1597. // Participants can now opt to increase the challenge, if desired.
  1598. _festivalInProgress = true;
  1599. /* PROPOGATION */
  1600. // Sequentially set all festivals to begin, spawn the Festival Witch and notify participants.
  1601. for (L2DarknessFestival festivalInst : _festivalInstances.values())
  1602. {
  1603. festivalInst.festivalStart();
  1604. festivalInst.sendMessageToParticipants("The festival is about to begin!");
  1605. }
  1606. if (Config.DEBUG)
  1607. _log.info("SevenSignsFestival: Each of the festivals will end in " + (Config.ALT_FESTIVAL_LENGTH / 60000)
  1608. + " minutes. New participants can signup then.");
  1609. // After a short time period, move all idle spawns to the center of the arena.
  1610. try
  1611. {
  1612. wait(Config.ALT_FESTIVAL_FIRST_SWARM - Config.ALT_FESTIVAL_FIRST_SPAWN);
  1613. }
  1614. catch (InterruptedException e)
  1615. {
  1616. }
  1617. elapsedTime += Config.ALT_FESTIVAL_FIRST_SWARM - Config.ALT_FESTIVAL_FIRST_SPAWN;
  1618. for (L2DarknessFestival festivalInst : _festivalInstances.values())
  1619. festivalInst.moveMonstersToCenter();
  1620. // Stand by until the time comes for the second spawn.
  1621. try
  1622. {
  1623. wait(Config.ALT_FESTIVAL_SECOND_SPAWN - Config.ALT_FESTIVAL_FIRST_SWARM);
  1624. }
  1625. catch (InterruptedException e)
  1626. {
  1627. }
  1628. // Spawn an extra set of monsters (archers) on the free platforms with
  1629. // a faster respawn when killed.
  1630. for (L2DarknessFestival festivalInst : _festivalInstances.values())
  1631. {
  1632. festivalInst.spawnFestivalMonsters(FESTIVAL_DEFAULT_RESPAWN / 2, 2);
  1633. festivalInst.sendMessageToParticipants("The festival will end in "
  1634. + ((Config.ALT_FESTIVAL_LENGTH - Config.ALT_FESTIVAL_SECOND_SPAWN) / 60000) + " minute(s).");
  1635. }
  1636. elapsedTime += Config.ALT_FESTIVAL_SECOND_SPAWN - Config.ALT_FESTIVAL_FIRST_SWARM;
  1637. // After another short time period, again move all idle spawns to the center of the arena.
  1638. try
  1639. {
  1640. wait(Config.ALT_FESTIVAL_SECOND_SWARM - Config.ALT_FESTIVAL_SECOND_SPAWN);
  1641. }
  1642. catch (InterruptedException e)
  1643. {
  1644. }
  1645. for (L2DarknessFestival festivalInst : _festivalInstances.values())
  1646. festivalInst.moveMonstersToCenter();
  1647. elapsedTime += Config.ALT_FESTIVAL_SECOND_SWARM - Config.ALT_FESTIVAL_SECOND_SPAWN;
  1648. // Stand by until the time comes for the chests to be spawned.
  1649. try
  1650. {
  1651. wait(Config.ALT_FESTIVAL_CHEST_SPAWN - Config.ALT_FESTIVAL_SECOND_SWARM);
  1652. }
  1653. catch (InterruptedException e)
  1654. {
  1655. }
  1656. // Spawn the festival chests, which enable the team to gain greater rewards
  1657. // for each chest they kill.
  1658. for (L2DarknessFestival festivalInst : _festivalInstances.values())
  1659. {
  1660. festivalInst.spawnFestivalMonsters(FESTIVAL_DEFAULT_RESPAWN, 3);
  1661. festivalInst.sendMessageToParticipants("The chests have spawned! Be quick, the festival will end soon.");
  1662. }
  1663. elapsedTime += Config.ALT_FESTIVAL_CHEST_SPAWN - Config.ALT_FESTIVAL_SECOND_SWARM;
  1664. // Stand by and wait until it's time to end the festival.
  1665. try
  1666. {
  1667. wait(Config.ALT_FESTIVAL_LENGTH - elapsedTime);
  1668. }
  1669. catch (InterruptedException e)
  1670. {
  1671. }
  1672. // Participants can no longer opt to increase the challenge, as the festival will soon close.
  1673. _festivalInProgress = false;
  1674. /* TERMINATION */
  1675. // Sequentially begin the ending sequence for all running festivals.
  1676. for (L2DarknessFestival festivalInst : _festivalInstances.values())
  1677. festivalInst.festivalEnd();
  1678. // Clear the participants list for the next round of signups.
  1679. _dawnFestivalParticipants.clear();
  1680. _duskFestivalParticipants.clear();
  1681. // Allow signups for the next festival cycle.
  1682. _festivalInitialized = false;
  1683. sendMessageToAll("Festival Witch", "That will do! I'll move you to the outside soon.");
  1684. if (Config.DEBUG)
  1685. _log.info("SevenSignsFestival: The next set of festivals begin in " + getMinsToNextFestival() + " minute(s).");
  1686. }
  1687. /**
  1688. * Returns the running instance of a festival for the given Oracle and festivalID.
  1689. * <BR>
  1690. * A <B>null</B> value is returned if there are no participants in that festival.
  1691. *
  1692. * @param oracle
  1693. * @param festivalId
  1694. * @return L2DarknessFestival festivalInst
  1695. */
  1696. public final L2DarknessFestival getFestivalInstance(int oracle, int festivalId)
  1697. {
  1698. if (!isFestivalInitialized())
  1699. return null;
  1700. /* Compute the offset if a Dusk instance is required.
  1701. *
  1702. * ID: 0 1 2 3 4
  1703. * Dusk 1:1011121314
  1704. * Dawn 2:2021222324
  1705. */
  1706. festivalId += (oracle == SevenSigns.CABAL_DUSK) ? 10 : 20;
  1707. return _festivalInstances.get(festivalId);
  1708. }
  1709. /**
  1710. * Returns the number of currently running festivals <b>WITH</b> participants.
  1711. *
  1712. * @return int Count
  1713. */
  1714. public final int getInstanceCount()
  1715. {
  1716. return _festivalInstances.size();
  1717. }
  1718. }
  1719. /**
  1720. * Each running festival is represented by an L2DarknessFestival class.
  1721. * It contains all the spawn information and data for the running festival.
  1722. *
  1723. * All festivals are managed by the FestivalManager class, which must be initialized first.
  1724. *
  1725. * @author Tempy
  1726. */
  1727. private class L2DarknessFestival
  1728. {
  1729. protected final int _cabal;
  1730. protected final int _levelRange;
  1731. protected boolean _challengeIncreased;
  1732. private FestivalSpawn _startLocation;
  1733. private FestivalSpawn _witchSpawn;
  1734. private L2Npc _witchInst;
  1735. List<L2FestivalMonsterInstance> _npcInsts;
  1736. private List<L2PcInstance> _participants;
  1737. private Map<L2PcInstance, FestivalSpawn> _originalLocations;
  1738. protected L2DarknessFestival(int cabal, int levelRange)
  1739. {
  1740. _cabal = cabal;
  1741. _levelRange = levelRange;
  1742. _originalLocations = new FastMap<L2PcInstance, FestivalSpawn>();
  1743. _npcInsts = new FastList<L2FestivalMonsterInstance>();
  1744. if (cabal == SevenSigns.CABAL_DAWN)
  1745. {
  1746. _participants = _dawnFestivalParticipants.get(levelRange);
  1747. _witchSpawn = new FestivalSpawn(FESTIVAL_DAWN_WITCH_SPAWNS[levelRange]);
  1748. _startLocation = new FestivalSpawn(FESTIVAL_DAWN_PLAYER_SPAWNS[levelRange]);
  1749. }
  1750. else
  1751. {
  1752. _participants = _duskFestivalParticipants.get(levelRange);
  1753. _witchSpawn = new FestivalSpawn(FESTIVAL_DUSK_WITCH_SPAWNS[levelRange]);
  1754. _startLocation = new FestivalSpawn(FESTIVAL_DUSK_PLAYER_SPAWNS[levelRange]);
  1755. }
  1756. // FOR TESTING!
  1757. if (_participants == null)
  1758. _participants = new FastList<L2PcInstance>();
  1759. festivalInit();
  1760. }
  1761. protected void festivalInit()
  1762. {
  1763. boolean isPositive;
  1764. if (Config.DEBUG)
  1765. _log.info("SevenSignsFestival: Initializing festival for " + SevenSigns.getCabalShortName(_cabal) + " ("
  1766. + getFestivalName(_levelRange) + ")");
  1767. // Teleport all players to arena and notify them.
  1768. if (!_participants.isEmpty())
  1769. {
  1770. try
  1771. {
  1772. for (L2PcInstance participant : _participants)
  1773. {
  1774. _originalLocations.put(participant, new FestivalSpawn(participant.getX(), participant.getY(), participant.getZ(), participant.getHeading()));
  1775. // Randomize the spawn point around the specific centerpoint for each player.
  1776. int x = _startLocation._x;
  1777. int y = _startLocation._y;
  1778. isPositive = (Rnd.nextInt(2) == 1);
  1779. if (isPositive)
  1780. {
  1781. x += Rnd.nextInt(FESTIVAL_MAX_OFFSET_X);
  1782. y += Rnd.nextInt(FESTIVAL_MAX_OFFSET_Y);
  1783. }
  1784. else
  1785. {
  1786. x -= Rnd.nextInt(FESTIVAL_MAX_OFFSET_X);
  1787. y -= Rnd.nextInt(FESTIVAL_MAX_OFFSET_Y);
  1788. }
  1789. participant.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  1790. participant.teleToLocation(x, y, _startLocation._z, true);
  1791. // Remove all buffs from all participants on entry. Works like the skill Cancel.
  1792. participant.stopAllEffects();
  1793. // Remove any stray blood offerings in inventory
  1794. L2ItemInstance bloodOfferings = participant.getInventory().getItemByItemId(FESTIVAL_OFFERING_ID);
  1795. if (bloodOfferings != null)
  1796. participant.destroyItem("SevenSigns", bloodOfferings, null, true);
  1797. }
  1798. }
  1799. catch (NullPointerException e)
  1800. {
  1801. // deleteMe handling should teleport party out in case of disconnect
  1802. }
  1803. }
  1804. L2NpcTemplate witchTemplate = NpcTable.getInstance().getTemplate(_witchSpawn._npcId);
  1805. // Spawn the festival witch for this arena
  1806. try
  1807. {
  1808. L2Spawn npcSpawn = new L2Spawn(witchTemplate);
  1809. npcSpawn.setLocx(_witchSpawn._x);
  1810. npcSpawn.setLocy(_witchSpawn._y);
  1811. npcSpawn.setLocz(_witchSpawn._z);
  1812. npcSpawn.setHeading(_witchSpawn._heading);
  1813. npcSpawn.setAmount(1);
  1814. npcSpawn.setRespawnDelay(1);
  1815. // Needed as doSpawn() is required to be called also for the NpcInstance it returns.
  1816. npcSpawn.startRespawn();
  1817. SpawnTable.getInstance().addNewSpawn(npcSpawn, false);
  1818. _witchInst = npcSpawn.doSpawn();
  1819. if (Config.DEBUG)
  1820. _log.fine("SevenSignsFestival: Spawned the Festival Witch " + npcSpawn.getNpcid() + " at " + _witchSpawn._x + " "
  1821. + _witchSpawn._y + " " + _witchSpawn._z);
  1822. }
  1823. catch (Exception e)
  1824. {
  1825. _log.warning("SevenSignsFestival: Error while spawning Festival Witch ID " + _witchSpawn._npcId + ": " + e);
  1826. }
  1827. // Make it appear as though the Witch has apparated there.
  1828. MagicSkillUse msu = new MagicSkillUse(_witchInst, _witchInst, 2003, 1, 1, 0);
  1829. _witchInst.broadcastPacket(msu);
  1830. // And another one...:D
  1831. msu = new MagicSkillUse(_witchInst, _witchInst, 2133, 1, 1, 0);
  1832. _witchInst.broadcastPacket(msu);
  1833. // Send a message to all participants from the witch.
  1834. sendMessageToParticipants("The festival will begin in 2 minutes.");
  1835. }
  1836. protected void festivalStart()
  1837. {
  1838. if (Config.DEBUG)
  1839. _log.info("SevenSignsFestival: Starting festival for " + SevenSigns.getCabalShortName(_cabal) + " ("
  1840. + getFestivalName(_levelRange) + ")");
  1841. spawnFestivalMonsters(FESTIVAL_DEFAULT_RESPAWN, 0);
  1842. }
  1843. protected void moveMonstersToCenter()
  1844. {
  1845. boolean isPositive;
  1846. if (Config.DEBUG)
  1847. _log.info("SevenSignsFestival: Moving spawns to arena center for festival " + SevenSigns.getCabalShortName(_cabal) + " ("
  1848. + getFestivalName(_levelRange) + ")");
  1849. for (L2FestivalMonsterInstance festivalMob : _npcInsts)
  1850. {
  1851. if (festivalMob.isDead())
  1852. continue;
  1853. // Only move monsters that are idle or doing their usual functions.
  1854. CtrlIntention currIntention = festivalMob.getAI().getIntention();
  1855. if (currIntention != CtrlIntention.AI_INTENTION_IDLE && currIntention != CtrlIntention.AI_INTENTION_ACTIVE)
  1856. continue;
  1857. int x = _startLocation._x;
  1858. int y = _startLocation._y;
  1859. /*
  1860. * Random X and Y coords around the player start location, up to half of the
  1861. * maximum allowed offset are generated to prevent the mobs from all moving
  1862. * to the exact same place.
  1863. */
  1864. isPositive = (Rnd.nextInt(2) == 1);
  1865. if (isPositive)
  1866. {
  1867. x += Rnd.nextInt(FESTIVAL_MAX_OFFSET_X);
  1868. y += Rnd.nextInt(FESTIVAL_MAX_OFFSET_Y);
  1869. }
  1870. else
  1871. {
  1872. x -= Rnd.nextInt(FESTIVAL_MAX_OFFSET_X);
  1873. y -= Rnd.nextInt(FESTIVAL_MAX_OFFSET_Y);
  1874. }
  1875. L2CharPosition moveTo = new L2CharPosition(x, y, _startLocation._z, Rnd.nextInt(65536));
  1876. festivalMob.setRunning();
  1877. festivalMob.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, moveTo);
  1878. }
  1879. }
  1880. public void setSpawnRate(int respawnDelay)
  1881. {
  1882. if (Config.DEBUG)
  1883. _log.info("SevenSignsFestival: Modifying spawn rate of festival mobs to " + respawnDelay + " ms for festival "
  1884. + SevenSigns.getCabalShortName(_cabal) + " (" + getFestivalName(_levelRange) + ")");
  1885. for (L2FestivalMonsterInstance monsterInst : _npcInsts)
  1886. monsterInst.getSpawn().setRespawnDelay(respawnDelay);
  1887. }
  1888. /**
  1889. * Used to spawn monsters unique to the festival.
  1890. * <BR>
  1891. * Valid SpawnTypes:<BR>
  1892. * 0 - All Primary Monsters (starting monsters)
  1893. * <BR>
  1894. * 1 - Same as 0, but without archers/marksmen. (used for challenge increase)
  1895. * <BR>
  1896. * 2 - Secondary Monsters (archers)
  1897. * <BR>
  1898. * 3 - Festival Chests
  1899. *
  1900. * @param respawnDelay
  1901. * @param spawnType
  1902. */
  1903. protected void spawnFestivalMonsters(int respawnDelay, int spawnType)
  1904. {
  1905. int[][] _npcSpawns = null;
  1906. switch (spawnType)
  1907. {
  1908. case 0:
  1909. case 1:
  1910. _npcSpawns = (_cabal == SevenSigns.CABAL_DAWN) ? FESTIVAL_DAWN_PRIMARY_SPAWNS[_levelRange] : FESTIVAL_DUSK_PRIMARY_SPAWNS[_levelRange];
  1911. break;
  1912. case 2:
  1913. _npcSpawns = (_cabal == SevenSigns.CABAL_DAWN) ? FESTIVAL_DAWN_SECONDARY_SPAWNS[_levelRange] : FESTIVAL_DUSK_SECONDARY_SPAWNS[_levelRange];
  1914. break;
  1915. case 3:
  1916. _npcSpawns = (_cabal == SevenSigns.CABAL_DAWN) ? FESTIVAL_DAWN_CHEST_SPAWNS[_levelRange] : FESTIVAL_DUSK_CHEST_SPAWNS[_levelRange];
  1917. break;
  1918. }
  1919. for (int i = 0; i < _npcSpawns.length; i++)
  1920. {
  1921. FestivalSpawn currSpawn = new FestivalSpawn(_npcSpawns[i]);
  1922. // Only spawn archers/marksmen if specified to do so.
  1923. if (spawnType == 1 && isFestivalArcher(currSpawn._npcId))
  1924. continue;
  1925. L2NpcTemplate npcTemplate = NpcTable.getInstance().getTemplate(currSpawn._npcId);
  1926. try
  1927. {
  1928. L2Spawn npcSpawn = new L2Spawn(npcTemplate);
  1929. npcSpawn.setLocx(currSpawn._x);
  1930. npcSpawn.setLocy(currSpawn._y);
  1931. npcSpawn.setLocz(currSpawn._z);
  1932. npcSpawn.setHeading(Rnd.nextInt(65536));
  1933. npcSpawn.setAmount(1);
  1934. npcSpawn.setRespawnDelay(respawnDelay);
  1935. // Needed as doSpawn() is required to be called also for the NpcInstance it returns.
  1936. npcSpawn.startRespawn();
  1937. SpawnTable.getInstance().addNewSpawn(npcSpawn, false);
  1938. L2FestivalMonsterInstance festivalMob = (L2FestivalMonsterInstance) npcSpawn.doSpawn();
  1939. // Set the offering bonus to 2x or 5x the amount per kill,
  1940. // if this spawn is part of an increased challenge or is a festival chest.
  1941. if (spawnType == 1)
  1942. festivalMob.setOfferingBonus(2);
  1943. else if (spawnType == 3)
  1944. festivalMob.setOfferingBonus(5);
  1945. _npcInsts.add(festivalMob);
  1946. if (Config.DEBUG)
  1947. _log.fine("SevenSignsFestival: Spawned NPC ID " + currSpawn._npcId + " at " + currSpawn._x + " " + currSpawn._y
  1948. + " " + currSpawn._z);
  1949. }
  1950. catch (Exception e)
  1951. {
  1952. _log.warning("SevenSignsFestival: Error while spawning NPC ID " + currSpawn._npcId + ": " + e);
  1953. }
  1954. }
  1955. }
  1956. protected boolean increaseChallenge()
  1957. {
  1958. if (_challengeIncreased)
  1959. return false;
  1960. // Set this flag to true to make sure that this can only be done once.
  1961. _challengeIncreased = true;
  1962. if (Config.DEBUG)
  1963. _log.info("SevenSignsFestival: " + _participants.get(0).getName()
  1964. + "'s team have opted to increase the festival challenge!");
  1965. // Spawn more festival monsters, but this time with a twist.
  1966. spawnFestivalMonsters(FESTIVAL_DEFAULT_RESPAWN, 1);
  1967. return true;
  1968. }
  1969. public void sendMessageToParticipants(String message)
  1970. {
  1971. if (!_participants.isEmpty())
  1972. {
  1973. CreatureSay cs = new CreatureSay(_witchInst.getObjectId(), Say2.ALL, "Festival Witch", message);
  1974. for (L2PcInstance participant : _participants)
  1975. {
  1976. try
  1977. {
  1978. participant.sendPacket(cs);
  1979. }
  1980. catch (NullPointerException e)
  1981. {
  1982. }
  1983. }
  1984. }
  1985. }
  1986. protected void festivalEnd()
  1987. {
  1988. if (Config.DEBUG)
  1989. _log.info("SevenSignsFestival: Ending festival for " + SevenSigns.getCabalShortName(_cabal) + " ("
  1990. + getFestivalName(_levelRange) + ")");
  1991. if (!_participants.isEmpty())
  1992. {
  1993. for (L2PcInstance participant : _participants)
  1994. {
  1995. try
  1996. {
  1997. relocatePlayer(participant, false);
  1998. participant.sendMessage("The festival has ended. Your party leader must now register your score before the next festival takes place.");
  1999. }
  2000. catch (NullPointerException e)
  2001. {
  2002. }
  2003. }
  2004. if (_cabal == SevenSigns.CABAL_DAWN)
  2005. _dawnPreviousParticipants.put(_levelRange, _participants);
  2006. else
  2007. _duskPreviousParticipants.put(_levelRange, _participants);
  2008. }
  2009. _participants = null;
  2010. unspawnMobs();
  2011. }
  2012. protected void unspawnMobs()
  2013. {
  2014. // Delete all the NPCs in the current festival arena.
  2015. if (_witchInst != null)
  2016. {
  2017. _witchInst.getSpawn().stopRespawn();
  2018. _witchInst.deleteMe();
  2019. }
  2020. if (_npcInsts != null)
  2021. for (L2FestivalMonsterInstance monsterInst : _npcInsts)
  2022. if (monsterInst != null)
  2023. {
  2024. monsterInst.getSpawn().stopRespawn();
  2025. monsterInst.deleteMe();
  2026. }
  2027. }
  2028. public void relocatePlayer(L2PcInstance participant, boolean isRemoving)
  2029. {
  2030. try
  2031. {
  2032. FestivalSpawn origPosition = _originalLocations.get(participant);
  2033. if (isRemoving)
  2034. _originalLocations.remove(participant);
  2035. participant.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  2036. participant.teleToLocation(origPosition._x, origPosition._y, origPosition._z, true);
  2037. participant.sendMessage("You have been removed from the festival arena.");
  2038. }
  2039. catch (Exception e)
  2040. {
  2041. // If an exception occurs, just move the player to the nearest town.
  2042. try
  2043. {
  2044. participant.teleToLocation(MapRegionTable.TeleportWhereType.Town);
  2045. participant.sendMessage("You have been removed from the festival arena.");
  2046. }
  2047. catch (NullPointerException e2)
  2048. {
  2049. }
  2050. }
  2051. }
  2052. }
  2053. private class FestivalSpawn
  2054. {
  2055. protected final int _x;
  2056. protected final int _y;
  2057. protected final int _z;
  2058. protected final int _heading;
  2059. protected final int _npcId;
  2060. protected FestivalSpawn(int x, int y, int z, int heading)
  2061. {
  2062. _x = x;
  2063. _y = y;
  2064. _z = z;
  2065. // Generate a random heading if no positive one given.
  2066. _heading = (heading < 0) ? Rnd.nextInt(65536) : heading;
  2067. _npcId = -1;
  2068. }
  2069. protected FestivalSpawn(int[] spawnData)
  2070. {
  2071. _x = spawnData[0];
  2072. _y = spawnData[1];
  2073. _z = spawnData[2];
  2074. _heading = (spawnData[3] < 0) ? Rnd.nextInt(65536) : spawnData[3];
  2075. if (spawnData.length > 4)
  2076. _npcId = spawnData[4];
  2077. else
  2078. _npcId = -1;
  2079. }
  2080. }
  2081. @SuppressWarnings("synthetic-access")
  2082. private static class SingletonHolder
  2083. {
  2084. protected static final SevenSignsFestival _instance = new SevenSignsFestival();
  2085. }
  2086. }