2
0

SevenSignsFestival.java 89 KB

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