SevenSignsFestival.java 79 KB

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