SevenSignsFestival.java 89 KB

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