SevenSignsFestival.java 74 KB

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