SevenSignsFestival.java 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493
  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 com.l2jserver.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 com.l2jserver.Config;
  26. import com.l2jserver.L2DatabaseFactory;
  27. import com.l2jserver.gameserver.ai.CtrlIntention;
  28. import com.l2jserver.gameserver.datatables.ClanTable;
  29. import com.l2jserver.gameserver.datatables.MapRegionTable;
  30. import com.l2jserver.gameserver.datatables.NpcTable;
  31. import com.l2jserver.gameserver.datatables.SpawnTable;
  32. import com.l2jserver.gameserver.model.L2CharPosition;
  33. import com.l2jserver.gameserver.model.L2Clan;
  34. import com.l2jserver.gameserver.model.L2ItemInstance;
  35. import com.l2jserver.gameserver.model.L2Party;
  36. import com.l2jserver.gameserver.model.L2Spawn;
  37. import com.l2jserver.gameserver.model.L2World;
  38. import com.l2jserver.gameserver.model.SpawnListener;
  39. import com.l2jserver.gameserver.model.actor.L2Npc;
  40. import com.l2jserver.gameserver.model.actor.instance.L2FestivalMonsterInstance;
  41. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  42. import com.l2jserver.gameserver.model.base.Experience;
  43. import com.l2jserver.gameserver.network.SystemMessageId;
  44. import com.l2jserver.gameserver.network.clientpackets.Say2;
  45. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  46. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  47. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  48. import com.l2jserver.gameserver.templates.StatsSet;
  49. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  50. import com.l2jserver.gameserver.util.Util;
  51. import com.l2jserver.util.Rnd;
  52. import javolution.util.FastList;
  53. import javolution.util.FastMap;
  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().addReputationScore(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.addReputationScore(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.stopAllEffectsExceptThoseThatLastThroughDeath();
  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. }