SevenSignsFestival.java 79 KB

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