2
0

SevenSignsFestival.java 77 KB

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