SevenSignsFestival.java 87 KB

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