SevenSignsFestival.java 78 KB

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