SevenSignsFestival.java 78 KB

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