TvTEvent.java 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  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.model.entity;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.logging.Level;
  20. import java.util.logging.Logger;
  21. import javolution.util.FastList;
  22. import javolution.util.FastMap;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.cache.HtmCache;
  25. import com.l2jserver.gameserver.datatables.DoorTable;
  26. import com.l2jserver.gameserver.datatables.ItemTable;
  27. import com.l2jserver.gameserver.datatables.NpcTable;
  28. import com.l2jserver.gameserver.datatables.SkillTable;
  29. import com.l2jserver.gameserver.datatables.SpawnTable;
  30. import com.l2jserver.gameserver.instancemanager.AntiFeedManager;
  31. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  32. import com.l2jserver.gameserver.model.L2Spawn;
  33. import com.l2jserver.gameserver.model.actor.L2Character;
  34. import com.l2jserver.gameserver.model.actor.L2Npc;
  35. import com.l2jserver.gameserver.model.actor.L2Summon;
  36. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  37. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  38. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  39. import com.l2jserver.gameserver.model.actor.instance.L2ServitorInstance;
  40. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  41. import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
  42. import com.l2jserver.gameserver.model.olympiad.OlympiadManager;
  43. import com.l2jserver.gameserver.model.skills.L2Skill;
  44. import com.l2jserver.gameserver.network.SystemMessageId;
  45. import com.l2jserver.gameserver.network.clientpackets.Say2;
  46. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  47. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  48. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  49. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  50. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  51. import com.l2jserver.gameserver.scripting.scriptengine.events.TvtKillEvent;
  52. import com.l2jserver.gameserver.scripting.scriptengine.impl.L2Script.EventStage;
  53. import com.l2jserver.gameserver.scripting.scriptengine.listeners.events.TvTListener;
  54. import com.l2jserver.util.Rnd;
  55. import com.l2jserver.util.StringUtil;
  56. /**
  57. * @author FBIagent
  58. */
  59. public class TvTEvent
  60. {
  61. enum EventState
  62. {
  63. INACTIVE,
  64. INACTIVATING,
  65. PARTICIPATING,
  66. STARTING,
  67. STARTED,
  68. REWARDING
  69. }
  70. protected static final Logger _log = Logger.getLogger(TvTEvent.class.getName());
  71. /** html path **/
  72. private static final String htmlPath = "data/html/mods/TvTEvent/";
  73. /** The teams of the TvTEvent<br> */
  74. private static TvTEventTeam[] _teams = new TvTEventTeam[2];
  75. /** The state of the TvTEvent<br> */
  76. private static EventState _state = EventState.INACTIVE;
  77. /** The spawn of the participation npc<br> */
  78. private static L2Spawn _npcSpawn = null;
  79. /** the npc instance of the participation npc<br> */
  80. private static L2Npc _lastNpcSpawn = null;
  81. /** Instance id<br> */
  82. private static int _TvTEventInstance = 0;
  83. private static FastList<TvTListener> tvtListeners = new FastList<TvTListener>().shared();
  84. /**
  85. * No instance of this class!<br>
  86. */
  87. private TvTEvent()
  88. {
  89. }
  90. /**
  91. * Teams initializing<br>
  92. */
  93. public static void init()
  94. {
  95. AntiFeedManager.getInstance().registerEvent(AntiFeedManager.TVT_ID);
  96. _teams[0] = new TvTEventTeam(Config.TVT_EVENT_TEAM_1_NAME, Config.TVT_EVENT_TEAM_1_COORDINATES);
  97. _teams[1] = new TvTEventTeam(Config.TVT_EVENT_TEAM_2_NAME, Config.TVT_EVENT_TEAM_2_COORDINATES);
  98. }
  99. /**
  100. * Starts the participation of the TvTEvent<br>
  101. * 1. Get L2NpcTemplate by Config.TVT_EVENT_PARTICIPATION_NPC_ID<br>
  102. * 2. Try to spawn a new npc of it<br>
  103. * <br>
  104. * @return boolean: true if success, otherwise false<br>
  105. */
  106. public static boolean startParticipation()
  107. {
  108. L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(Config.TVT_EVENT_PARTICIPATION_NPC_ID);
  109. if (tmpl == null)
  110. {
  111. _log.warning("TvTEventEngine[TvTEvent.startParticipation()]: L2NpcTemplate is a NullPointer -> Invalid npc id in configs?");
  112. return false;
  113. }
  114. try
  115. {
  116. _npcSpawn = new L2Spawn(tmpl);
  117. _npcSpawn.setLocx(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[0]);
  118. _npcSpawn.setLocy(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[1]);
  119. _npcSpawn.setLocz(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[2]);
  120. _npcSpawn.setAmount(1);
  121. _npcSpawn.setHeading(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[3]);
  122. _npcSpawn.setRespawnDelay(1);
  123. // later no need to delete spawn from db, we don't store it (false)
  124. SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  125. _npcSpawn.init();
  126. _lastNpcSpawn = _npcSpawn.getLastSpawn();
  127. _lastNpcSpawn.setCurrentHp(_lastNpcSpawn.getMaxHp());
  128. _lastNpcSpawn.setTitle("TvT Event Participation");
  129. _lastNpcSpawn.isAggressive();
  130. _lastNpcSpawn.decayMe();
  131. _lastNpcSpawn.spawnMe(_npcSpawn.getLastSpawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ());
  132. _lastNpcSpawn.broadcastPacket(new MagicSkillUse(_lastNpcSpawn, _lastNpcSpawn, 1034, 1, 1, 1));
  133. }
  134. catch (Exception e)
  135. {
  136. _log.log(Level.WARNING, "TvTEventEngine[TvTEvent.startParticipation()]: exception: " + e.getMessage(), e);
  137. return false;
  138. }
  139. setState(EventState.PARTICIPATING);
  140. fireTvtEventListeners(EventStage.REGISTRATION_BEGIN);
  141. return true;
  142. }
  143. private static int highestLevelPcInstanceOf(Map<Integer, L2PcInstance> players)
  144. {
  145. int maxLevel = Integer.MIN_VALUE, maxLevelId = -1;
  146. for (L2PcInstance player : players.values())
  147. {
  148. if (player.getLevel() >= maxLevel)
  149. {
  150. maxLevel = player.getLevel();
  151. maxLevelId = player.getObjectId();
  152. }
  153. }
  154. return maxLevelId;
  155. }
  156. /**
  157. * Starts the TvTEvent fight<br>
  158. * 1. Set state EventState.STARTING<br>
  159. * 2. Close doors specified in configs<br>
  160. * 3. Abort if not enought participants(return false)<br>
  161. * 4. Set state EventState.STARTED<br>
  162. * 5. Teleport all participants to team spot<br>
  163. * <br>
  164. * @return boolean: true if success, otherwise false<br>
  165. */
  166. public static boolean startFight()
  167. {
  168. // Set state to STARTING
  169. setState(EventState.STARTING);
  170. // Randomize and balance team distribution
  171. Map<Integer, L2PcInstance> allParticipants = new FastMap<>();
  172. allParticipants.putAll(_teams[0].getParticipatedPlayers());
  173. allParticipants.putAll(_teams[1].getParticipatedPlayers());
  174. _teams[0].cleanMe();
  175. _teams[1].cleanMe();
  176. L2PcInstance player;
  177. Iterator<L2PcInstance> iter;
  178. if (needParticipationFee())
  179. {
  180. iter = allParticipants.values().iterator();
  181. while (iter.hasNext())
  182. {
  183. player = iter.next();
  184. if (!hasParticipationFee(player))
  185. {
  186. iter.remove();
  187. }
  188. }
  189. }
  190. int balance[] =
  191. {
  192. 0,
  193. 0
  194. }, priority = 0, highestLevelPlayerId;
  195. L2PcInstance highestLevelPlayer;
  196. // XXX: allParticipants should be sorted by level instead of using highestLevelPcInstanceOf for every fetch
  197. while (!allParticipants.isEmpty())
  198. {
  199. // Priority team gets one player
  200. highestLevelPlayerId = highestLevelPcInstanceOf(allParticipants);
  201. highestLevelPlayer = allParticipants.get(highestLevelPlayerId);
  202. allParticipants.remove(highestLevelPlayerId);
  203. _teams[priority].addPlayer(highestLevelPlayer);
  204. balance[priority] += highestLevelPlayer.getLevel();
  205. // Exiting if no more players
  206. if (allParticipants.isEmpty())
  207. {
  208. break;
  209. }
  210. // The other team gets one player
  211. // XXX: Code not dry
  212. priority = 1 - priority;
  213. highestLevelPlayerId = highestLevelPcInstanceOf(allParticipants);
  214. highestLevelPlayer = allParticipants.get(highestLevelPlayerId);
  215. allParticipants.remove(highestLevelPlayerId);
  216. _teams[priority].addPlayer(highestLevelPlayer);
  217. balance[priority] += highestLevelPlayer.getLevel();
  218. // Recalculating priority
  219. priority = balance[0] > balance[1] ? 1 : 0;
  220. }
  221. // Check for enought participants
  222. if ((_teams[0].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS) || (_teams[1].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS))
  223. {
  224. // Set state INACTIVE
  225. setState(EventState.INACTIVE);
  226. // Cleanup of teams
  227. _teams[0].cleanMe();
  228. _teams[1].cleanMe();
  229. // Unspawn the event NPC
  230. unSpawnNpc();
  231. AntiFeedManager.getInstance().clear(AntiFeedManager.TVT_ID);
  232. return false;
  233. }
  234. if (needParticipationFee())
  235. {
  236. iter = _teams[0].getParticipatedPlayers().values().iterator();
  237. while (iter.hasNext())
  238. {
  239. player = iter.next();
  240. if (!payParticipationFee(player))
  241. {
  242. iter.remove();
  243. }
  244. }
  245. iter = _teams[1].getParticipatedPlayers().values().iterator();
  246. while (iter.hasNext())
  247. {
  248. player = iter.next();
  249. if (!payParticipationFee(player))
  250. {
  251. iter.remove();
  252. }
  253. }
  254. }
  255. if (Config.TVT_EVENT_IN_INSTANCE)
  256. {
  257. try
  258. {
  259. _TvTEventInstance = InstanceManager.getInstance().createDynamicInstance(Config.TVT_EVENT_INSTANCE_FILE);
  260. InstanceManager.getInstance().getInstance(_TvTEventInstance).setAllowSummon(false);
  261. InstanceManager.getInstance().getInstance(_TvTEventInstance).setPvPInstance(true);
  262. InstanceManager.getInstance().getInstance(_TvTEventInstance).setEmptyDestroyTime((Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY * 1000) + 60000L);
  263. }
  264. catch (Exception e)
  265. {
  266. _TvTEventInstance = 0;
  267. _log.log(Level.WARNING, "TvTEventEngine[TvTEvent.createDynamicInstance]: exception: " + e.getMessage(), e);
  268. }
  269. }
  270. // Opens all doors specified in configs for tvt
  271. openDoors(Config.TVT_DOORS_IDS_TO_OPEN);
  272. // Closes all doors specified in configs for tvt
  273. closeDoors(Config.TVT_DOORS_IDS_TO_CLOSE);
  274. // Set state STARTED
  275. setState(EventState.STARTED);
  276. // Iterate over all teams
  277. for (TvTEventTeam team : _teams)
  278. {
  279. // Iterate over all participated player instances in this team
  280. for (L2PcInstance playerInstance : team.getParticipatedPlayers().values())
  281. {
  282. if (playerInstance != null)
  283. {
  284. // Teleporter implements Runnable and starts itself
  285. new TvTEventTeleporter(playerInstance, team.getCoordinates(), false, false);
  286. }
  287. }
  288. }
  289. fireTvtEventListeners(EventStage.START);
  290. return true;
  291. }
  292. /**
  293. * Calculates the TvTEvent reward<br>
  294. * 1. If both teams are at a tie(points equals), send it as system message to all participants, if one of the teams have 0 participants left online abort rewarding<br>
  295. * 2. Wait till teams are not at a tie anymore<br>
  296. * 3. Set state EvcentState.REWARDING<br>
  297. * 4. Reward team with more points<br>
  298. * 5. Show win html to wining team participants<br>
  299. * <br>
  300. * @return String: winning team name<br>
  301. */
  302. public static String calculateRewards()
  303. {
  304. if (_teams[0].getPoints() == _teams[1].getPoints())
  305. {
  306. // Check if one of the teams have no more players left
  307. if ((_teams[0].getParticipatedPlayerCount() == 0) || (_teams[1].getParticipatedPlayerCount() == 0))
  308. {
  309. // set state to rewarding
  310. setState(EventState.REWARDING);
  311. // return here, the fight can't be completed
  312. return "TvT Event: Event has ended. No team won due to inactivity!";
  313. }
  314. // Both teams have equals points
  315. sysMsgToAllParticipants("TvT Event: Event has ended, both teams have tied.");
  316. if (Config.TVT_REWARD_TEAM_TIE)
  317. {
  318. rewardTeam(_teams[0]);
  319. rewardTeam(_teams[1]);
  320. return "TvT Event: Event has ended with both teams tying.";
  321. }
  322. return "TvT Event: Event has ended with both teams tying.";
  323. }
  324. // Set state REWARDING so nobody can point anymore
  325. setState(EventState.REWARDING);
  326. // Get team which has more points
  327. TvTEventTeam team = _teams[_teams[0].getPoints() > _teams[1].getPoints() ? 0 : 1];
  328. rewardTeam(team);
  329. fireTvtEventListeners(EventStage.END);
  330. return "TvT Event: Event finish. Team " + team.getName() + " won with " + team.getPoints() + " kills.";
  331. }
  332. private static void rewardTeam(TvTEventTeam team)
  333. {
  334. // Iterate over all participated player instances of the winning team
  335. for (L2PcInstance playerInstance : team.getParticipatedPlayers().values())
  336. {
  337. // Check for nullpointer
  338. if (playerInstance == null)
  339. {
  340. continue;
  341. }
  342. SystemMessage systemMessage = null;
  343. // Iterate over all tvt event rewards
  344. for (int[] reward : Config.TVT_EVENT_REWARDS)
  345. {
  346. PcInventory inv = playerInstance.getInventory();
  347. // Check for stackable item, non stackabe items need to be added one by one
  348. if (ItemTable.getInstance().createDummyItem(reward[0]).isStackable())
  349. {
  350. inv.addItem("TvT Event", reward[0], reward[1], playerInstance, playerInstance);
  351. if (reward[1] > 1)
  352. {
  353. systemMessage = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S);
  354. systemMessage.addItemName(reward[0]);
  355. systemMessage.addItemNumber(reward[1]);
  356. }
  357. else
  358. {
  359. systemMessage = SystemMessage.getSystemMessage(SystemMessageId.EARNED_ITEM_S1);
  360. systemMessage.addItemName(reward[0]);
  361. }
  362. playerInstance.sendPacket(systemMessage);
  363. }
  364. else
  365. {
  366. for (int i = 0; i < reward[1]; ++i)
  367. {
  368. inv.addItem("TvT Event", reward[0], 1, playerInstance, playerInstance);
  369. systemMessage = SystemMessage.getSystemMessage(SystemMessageId.EARNED_ITEM_S1);
  370. systemMessage.addItemName(reward[0]);
  371. playerInstance.sendPacket(systemMessage);
  372. }
  373. }
  374. }
  375. StatusUpdate statusUpdate = new StatusUpdate(playerInstance);
  376. NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  377. statusUpdate.addAttribute(StatusUpdate.CUR_LOAD, playerInstance.getCurrentLoad());
  378. npcHtmlMessage.setHtml(HtmCache.getInstance().getHtm(playerInstance.getHtmlPrefix(), htmlPath + "Reward.htm"));
  379. playerInstance.sendPacket(statusUpdate);
  380. playerInstance.sendPacket(npcHtmlMessage);
  381. }
  382. }
  383. /**
  384. * Stops the TvTEvent fight<br>
  385. * 1. Set state EventState.INACTIVATING<br>
  386. * 2. Remove tvt npc from world<br>
  387. * 3. Open doors specified in configs<br>
  388. * 4. Teleport all participants back to participation npc location<br>
  389. * 5. Teams cleaning<br>
  390. * 6. Set state EventState.INACTIVE<br>
  391. */
  392. public static void stopFight()
  393. {
  394. // Set state INACTIVATING
  395. setState(EventState.INACTIVATING);
  396. // Unspawn event npc
  397. unSpawnNpc();
  398. // Opens all doors specified in configs for tvt
  399. openDoors(Config.TVT_DOORS_IDS_TO_CLOSE);
  400. // Closes all doors specified in Configs for tvt
  401. closeDoors(Config.TVT_DOORS_IDS_TO_OPEN);
  402. // Iterate over all teams
  403. for (TvTEventTeam team : _teams)
  404. {
  405. for (L2PcInstance playerInstance : team.getParticipatedPlayers().values())
  406. {
  407. // Check for nullpointer
  408. if (playerInstance != null)
  409. {
  410. new TvTEventTeleporter(playerInstance, Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES, false, false);
  411. }
  412. }
  413. }
  414. // Cleanup of teams
  415. _teams[0].cleanMe();
  416. _teams[1].cleanMe();
  417. // Set state INACTIVE
  418. setState(EventState.INACTIVE);
  419. AntiFeedManager.getInstance().clear(AntiFeedManager.TVT_ID);
  420. }
  421. /**
  422. * Adds a player to a TvTEvent team<br>
  423. * 1. Calculate the id of the team in which the player should be added<br>
  424. * 2. Add the player to the calculated team<br>
  425. * <br>
  426. * @param playerInstance as L2PcInstance<br>
  427. * @return boolean: true if success, otherwise false<br>
  428. */
  429. public static synchronized boolean addParticipant(L2PcInstance playerInstance)
  430. {
  431. // Check for nullpoitner
  432. if (playerInstance == null)
  433. {
  434. return false;
  435. }
  436. byte teamId = 0;
  437. // Check to which team the player should be added
  438. if (_teams[0].getParticipatedPlayerCount() == _teams[1].getParticipatedPlayerCount())
  439. {
  440. teamId = (byte) (Rnd.get(2));
  441. }
  442. else
  443. {
  444. teamId = (byte) (_teams[0].getParticipatedPlayerCount() > _teams[1].getParticipatedPlayerCount() ? 1 : 0);
  445. }
  446. return _teams[teamId].addPlayer(playerInstance);
  447. }
  448. /**
  449. * Removes a TvTEvent player from it's team<br>
  450. * 1. Get team id of the player<br>
  451. * 2. Remove player from it's team<br>
  452. * <br>
  453. * @param playerObjectId
  454. * @return boolean: true if success, otherwise false
  455. */
  456. public static boolean removeParticipant(int playerObjectId)
  457. {
  458. // Get the teamId of the player
  459. byte teamId = getParticipantTeamId(playerObjectId);
  460. // Check if the player is participant
  461. if (teamId != -1)
  462. {
  463. // Remove the player from team
  464. _teams[teamId].removePlayer(playerObjectId);
  465. return true;
  466. }
  467. return false;
  468. }
  469. public static boolean needParticipationFee()
  470. {
  471. return (Config.TVT_EVENT_PARTICIPATION_FEE[0] != 0) && (Config.TVT_EVENT_PARTICIPATION_FEE[1] != 0);
  472. }
  473. public static boolean hasParticipationFee(L2PcInstance playerInstance)
  474. {
  475. return playerInstance.getInventory().getInventoryItemCount(Config.TVT_EVENT_PARTICIPATION_FEE[0], -1) >= Config.TVT_EVENT_PARTICIPATION_FEE[1];
  476. }
  477. public static boolean payParticipationFee(L2PcInstance playerInstance)
  478. {
  479. return playerInstance.destroyItemByItemId("TvT Participation Fee", Config.TVT_EVENT_PARTICIPATION_FEE[0], Config.TVT_EVENT_PARTICIPATION_FEE[1], _lastNpcSpawn, true);
  480. }
  481. public static String getParticipationFee()
  482. {
  483. int itemId = Config.TVT_EVENT_PARTICIPATION_FEE[0];
  484. int itemNum = Config.TVT_EVENT_PARTICIPATION_FEE[1];
  485. if ((itemId == 0) || (itemNum == 0))
  486. {
  487. return "-";
  488. }
  489. return StringUtil.concat(String.valueOf(itemNum), " ", ItemTable.getInstance().getTemplate(itemId).getName());
  490. }
  491. /**
  492. * Send a SystemMessage to all participated players<br>
  493. * 1. Send the message to all players of team number one<br>
  494. * 2. Send the message to all players of team number two<br>
  495. * <br>
  496. * @param message as String<br>
  497. */
  498. public static void sysMsgToAllParticipants(String message)
  499. {
  500. for (L2PcInstance playerInstance : _teams[0].getParticipatedPlayers().values())
  501. {
  502. if (playerInstance != null)
  503. {
  504. playerInstance.sendMessage(message);
  505. }
  506. }
  507. for (L2PcInstance playerInstance : _teams[1].getParticipatedPlayers().values())
  508. {
  509. if (playerInstance != null)
  510. {
  511. playerInstance.sendMessage(message);
  512. }
  513. }
  514. }
  515. /**
  516. * Close doors specified in configs
  517. * @param doors
  518. */
  519. private static void closeDoors(List<Integer> doors)
  520. {
  521. for (int doorId : doors)
  522. {
  523. L2DoorInstance doorInstance = DoorTable.getInstance().getDoor(doorId);
  524. if (doorInstance != null)
  525. {
  526. doorInstance.closeMe();
  527. }
  528. }
  529. }
  530. /**
  531. * Open doors specified in configs
  532. * @param doors
  533. */
  534. private static void openDoors(List<Integer> doors)
  535. {
  536. for (int doorId : doors)
  537. {
  538. L2DoorInstance doorInstance = DoorTable.getInstance().getDoor(doorId);
  539. if (doorInstance != null)
  540. {
  541. doorInstance.openMe();
  542. }
  543. }
  544. }
  545. /**
  546. * UnSpawns the TvTEvent npc
  547. */
  548. private static void unSpawnNpc()
  549. {
  550. // Delete the npc
  551. _lastNpcSpawn.deleteMe();
  552. SpawnTable.getInstance().deleteSpawn(_lastNpcSpawn.getSpawn(), false);
  553. // Stop respawning of the npc
  554. _npcSpawn.stopRespawn();
  555. _npcSpawn = null;
  556. _lastNpcSpawn = null;
  557. }
  558. /**
  559. * Called when a player logs in<br>
  560. * <br>
  561. * @param playerInstance as L2PcInstance<br>
  562. */
  563. public static void onLogin(L2PcInstance playerInstance)
  564. {
  565. if ((playerInstance == null) || (!isStarting() && !isStarted()))
  566. {
  567. return;
  568. }
  569. byte teamId = getParticipantTeamId(playerInstance.getObjectId());
  570. if (teamId == -1)
  571. {
  572. return;
  573. }
  574. _teams[teamId].addPlayer(playerInstance);
  575. new TvTEventTeleporter(playerInstance, _teams[teamId].getCoordinates(), true, false);
  576. }
  577. /**
  578. * Called when a player logs out<br>
  579. * <br>
  580. * @param playerInstance as L2PcInstance<br>
  581. */
  582. public static void onLogout(L2PcInstance playerInstance)
  583. {
  584. if ((playerInstance != null) && (isStarting() || isStarted() || isParticipating()))
  585. {
  586. if (removeParticipant(playerInstance.getObjectId()))
  587. {
  588. playerInstance.setXYZInvisible((Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[0] + Rnd.get(101)) - 50, (Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[1] + Rnd.get(101)) - 50, Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[2]);
  589. }
  590. }
  591. }
  592. /**
  593. * Called on every bypass by npc of type L2TvTEventNpc<br>
  594. * Needs synchronization cause of the max player check<br>
  595. * <br>
  596. * @param command as String<br>
  597. * @param playerInstance as L2PcInstance<br>
  598. */
  599. public static synchronized void onBypass(String command, L2PcInstance playerInstance)
  600. {
  601. if ((playerInstance == null) || !isParticipating())
  602. {
  603. return;
  604. }
  605. final String htmContent;
  606. if (command.equals("tvt_event_participation"))
  607. {
  608. NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  609. int playerLevel = playerInstance.getLevel();
  610. if (playerInstance.isCursedWeaponEquipped())
  611. {
  612. htmContent = HtmCache.getInstance().getHtm(playerInstance.getHtmlPrefix(), htmlPath + "CursedWeaponEquipped.htm");
  613. if (htmContent != null)
  614. {
  615. npcHtmlMessage.setHtml(htmContent);
  616. }
  617. }
  618. else if (OlympiadManager.getInstance().isRegistered(playerInstance))
  619. {
  620. htmContent = HtmCache.getInstance().getHtm(playerInstance.getHtmlPrefix(), htmlPath + "Olympiad.htm");
  621. if (htmContent != null)
  622. {
  623. npcHtmlMessage.setHtml(htmContent);
  624. }
  625. }
  626. else if (playerInstance.getKarma() > 0)
  627. {
  628. htmContent = HtmCache.getInstance().getHtm(playerInstance.getHtmlPrefix(), htmlPath + "Karma.htm");
  629. if (htmContent != null)
  630. {
  631. npcHtmlMessage.setHtml(htmContent);
  632. }
  633. }
  634. else if ((playerLevel < Config.TVT_EVENT_MIN_LVL) || (playerLevel > Config.TVT_EVENT_MAX_LVL))
  635. {
  636. htmContent = HtmCache.getInstance().getHtm(playerInstance.getHtmlPrefix(), htmlPath + "Level.htm");
  637. if (htmContent != null)
  638. {
  639. npcHtmlMessage.setHtml(htmContent);
  640. npcHtmlMessage.replace("%min%", String.valueOf(Config.TVT_EVENT_MIN_LVL));
  641. npcHtmlMessage.replace("%max%", String.valueOf(Config.TVT_EVENT_MAX_LVL));
  642. }
  643. }
  644. else if ((_teams[0].getParticipatedPlayerCount() == Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS) && (_teams[1].getParticipatedPlayerCount() == Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS))
  645. {
  646. htmContent = HtmCache.getInstance().getHtm(playerInstance.getHtmlPrefix(), htmlPath + "TeamsFull.htm");
  647. if (htmContent != null)
  648. {
  649. npcHtmlMessage.setHtml(htmContent);
  650. npcHtmlMessage.replace("%max%", String.valueOf(Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS));
  651. }
  652. }
  653. else if ((Config.TVT_EVENT_MAX_PARTICIPANTS_PER_IP > 0) && !AntiFeedManager.getInstance().tryAddPlayer(AntiFeedManager.TVT_ID, playerInstance, Config.TVT_EVENT_MAX_PARTICIPANTS_PER_IP))
  654. {
  655. htmContent = HtmCache.getInstance().getHtm(playerInstance.getHtmlPrefix(), htmlPath + "IPRestriction.htm");
  656. if (htmContent != null)
  657. {
  658. npcHtmlMessage.setHtml(htmContent);
  659. npcHtmlMessage.replace("%max%", String.valueOf(AntiFeedManager.getInstance().getLimit(playerInstance, Config.TVT_EVENT_MAX_PARTICIPANTS_PER_IP)));
  660. }
  661. }
  662. else if (needParticipationFee() && !hasParticipationFee(playerInstance))
  663. {
  664. htmContent = HtmCache.getInstance().getHtm(playerInstance.getHtmlPrefix(), htmlPath + "ParticipationFee.htm");
  665. if (htmContent != null)
  666. {
  667. npcHtmlMessage.setHtml(htmContent);
  668. npcHtmlMessage.replace("%fee%", getParticipationFee());
  669. }
  670. }
  671. else if (addParticipant(playerInstance))
  672. {
  673. npcHtmlMessage.setHtml(HtmCache.getInstance().getHtm(playerInstance.getHtmlPrefix(), htmlPath + "Registered.htm"));
  674. }
  675. else
  676. {
  677. return;
  678. }
  679. playerInstance.sendPacket(npcHtmlMessage);
  680. }
  681. else if (command.equals("tvt_event_remove_participation"))
  682. {
  683. removeParticipant(playerInstance.getObjectId());
  684. if (Config.TVT_EVENT_MAX_PARTICIPANTS_PER_IP > 0)
  685. {
  686. AntiFeedManager.getInstance().removePlayer(AntiFeedManager.TVT_ID, playerInstance);
  687. }
  688. NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  689. npcHtmlMessage.setHtml(HtmCache.getInstance().getHtm(playerInstance.getHtmlPrefix(), htmlPath + "Unregistered.htm"));
  690. playerInstance.sendPacket(npcHtmlMessage);
  691. }
  692. }
  693. /**
  694. * Called on every onAction in L2PcIstance<br>
  695. * <br>
  696. * @param playerInstance
  697. * @param targetedPlayerObjectId
  698. * @return boolean: true if player is allowed to target, otherwise false
  699. */
  700. public static boolean onAction(L2PcInstance playerInstance, int targetedPlayerObjectId)
  701. {
  702. if ((playerInstance == null) || !isStarted())
  703. {
  704. return true;
  705. }
  706. if (playerInstance.isGM())
  707. {
  708. return true;
  709. }
  710. byte playerTeamId = getParticipantTeamId(playerInstance.getObjectId());
  711. byte targetedPlayerTeamId = getParticipantTeamId(targetedPlayerObjectId);
  712. if (((playerTeamId != -1) && (targetedPlayerTeamId == -1)) || ((playerTeamId == -1) && (targetedPlayerTeamId != -1)))
  713. {
  714. return false;
  715. }
  716. if ((playerTeamId != -1) && (targetedPlayerTeamId != -1) && (playerTeamId == targetedPlayerTeamId) && (playerInstance.getObjectId() != targetedPlayerObjectId) && !Config.TVT_EVENT_TARGET_TEAM_MEMBERS_ALLOWED)
  717. {
  718. return false;
  719. }
  720. return true;
  721. }
  722. /**
  723. * Called on every scroll use<br>
  724. * <br>
  725. * @param playerObjectId
  726. * @return boolean: true if player is allowed to use scroll, otherwise false
  727. */
  728. public static boolean onScrollUse(int playerObjectId)
  729. {
  730. if (!isStarted())
  731. {
  732. return true;
  733. }
  734. if (isPlayerParticipant(playerObjectId) && !Config.TVT_EVENT_SCROLL_ALLOWED)
  735. {
  736. return false;
  737. }
  738. return true;
  739. }
  740. /**
  741. * Called on every potion use
  742. * @param playerObjectId
  743. * @return boolean: true if player is allowed to use potions, otherwise false
  744. */
  745. public static boolean onPotionUse(int playerObjectId)
  746. {
  747. if (!isStarted())
  748. {
  749. return true;
  750. }
  751. if (isPlayerParticipant(playerObjectId) && !Config.TVT_EVENT_POTIONS_ALLOWED)
  752. {
  753. return false;
  754. }
  755. return true;
  756. }
  757. /**
  758. * Called on every escape use(thanks to nbd)
  759. * @param playerObjectId
  760. * @return boolean: true if player is not in tvt event, otherwise false
  761. */
  762. public static boolean onEscapeUse(int playerObjectId)
  763. {
  764. if (!isStarted())
  765. {
  766. return true;
  767. }
  768. if (isPlayerParticipant(playerObjectId))
  769. {
  770. return false;
  771. }
  772. return true;
  773. }
  774. /**
  775. * Called on every summon item use
  776. * @param playerObjectId
  777. * @return boolean: true if player is allowed to summon by item, otherwise false
  778. */
  779. public static boolean onItemSummon(int playerObjectId)
  780. {
  781. if (!isStarted())
  782. {
  783. return true;
  784. }
  785. if (isPlayerParticipant(playerObjectId) && !Config.TVT_EVENT_SUMMON_BY_ITEM_ALLOWED)
  786. {
  787. return false;
  788. }
  789. return true;
  790. }
  791. /**
  792. * Is called when a player is killed<br>
  793. * <br>
  794. * @param killerCharacter as L2Character<br>
  795. * @param killedPlayerInstance as L2PcInstance<br>
  796. */
  797. public static void onKill(L2Character killerCharacter, L2PcInstance killedPlayerInstance)
  798. {
  799. if ((killedPlayerInstance == null) || !isStarted())
  800. {
  801. return;
  802. }
  803. byte killedTeamId = getParticipantTeamId(killedPlayerInstance.getObjectId());
  804. if (killedTeamId == -1)
  805. {
  806. return;
  807. }
  808. new TvTEventTeleporter(killedPlayerInstance, _teams[killedTeamId].getCoordinates(), false, false);
  809. if (killerCharacter == null)
  810. {
  811. return;
  812. }
  813. L2PcInstance killerPlayerInstance = null;
  814. if ((killerCharacter instanceof L2PetInstance) || (killerCharacter instanceof L2ServitorInstance))
  815. {
  816. killerPlayerInstance = ((L2Summon) killerCharacter).getOwner();
  817. if (killerPlayerInstance == null)
  818. {
  819. return;
  820. }
  821. }
  822. else if (killerCharacter instanceof L2PcInstance)
  823. {
  824. killerPlayerInstance = (L2PcInstance) killerCharacter;
  825. }
  826. else
  827. {
  828. return;
  829. }
  830. byte killerTeamId = getParticipantTeamId(killerPlayerInstance.getObjectId());
  831. if ((killerTeamId != -1) && (killedTeamId != -1) && (killerTeamId != killedTeamId))
  832. {
  833. TvTEventTeam killerTeam = _teams[killerTeamId];
  834. killerTeam.increasePoints();
  835. CreatureSay cs = new CreatureSay(killerPlayerInstance.getObjectId(), Say2.TELL, killerPlayerInstance.getName(), "I have killed " + killedPlayerInstance.getName() + "!");
  836. for (L2PcInstance playerInstance : _teams[killerTeamId].getParticipatedPlayers().values())
  837. {
  838. if (playerInstance != null)
  839. {
  840. playerInstance.sendPacket(cs);
  841. }
  842. }
  843. fireTvtKillListeners(killerPlayerInstance, killedPlayerInstance, killerTeam);
  844. }
  845. }
  846. /**
  847. * Called on Appearing packet received (player finished teleporting)
  848. * @param playerInstance
  849. */
  850. public static void onTeleported(L2PcInstance playerInstance)
  851. {
  852. if (!isStarted() || (playerInstance == null) || !isPlayerParticipant(playerInstance.getObjectId()))
  853. {
  854. return;
  855. }
  856. if (playerInstance.isMageClass())
  857. {
  858. if ((Config.TVT_EVENT_MAGE_BUFFS != null) && !Config.TVT_EVENT_MAGE_BUFFS.isEmpty())
  859. {
  860. for (int i : Config.TVT_EVENT_MAGE_BUFFS.keySet())
  861. {
  862. L2Skill skill = SkillTable.getInstance().getInfo(i, Config.TVT_EVENT_MAGE_BUFFS.get(i));
  863. if (skill != null)
  864. {
  865. skill.getEffects(playerInstance, playerInstance);
  866. }
  867. }
  868. }
  869. }
  870. else
  871. {
  872. if ((Config.TVT_EVENT_FIGHTER_BUFFS != null) && !Config.TVT_EVENT_FIGHTER_BUFFS.isEmpty())
  873. {
  874. for (int i : Config.TVT_EVENT_FIGHTER_BUFFS.keySet())
  875. {
  876. L2Skill skill = SkillTable.getInstance().getInfo(i, Config.TVT_EVENT_FIGHTER_BUFFS.get(i));
  877. if (skill != null)
  878. {
  879. skill.getEffects(playerInstance, playerInstance);
  880. }
  881. }
  882. }
  883. }
  884. }
  885. /**
  886. * @param source
  887. * @param target
  888. * @param skill
  889. * @return true if player valid for skill
  890. */
  891. public static final boolean checkForTvTSkill(L2PcInstance source, L2PcInstance target, L2Skill skill)
  892. {
  893. if (!isStarted())
  894. {
  895. return true;
  896. }
  897. // TvT is started
  898. final int sourcePlayerId = source.getObjectId();
  899. final int targetPlayerId = target.getObjectId();
  900. final boolean isSourceParticipant = isPlayerParticipant(sourcePlayerId);
  901. final boolean isTargetParticipant = isPlayerParticipant(targetPlayerId);
  902. // both players not participating
  903. if (!isSourceParticipant && !isTargetParticipant)
  904. {
  905. return true;
  906. }
  907. // one player not participating
  908. if (!(isSourceParticipant && isTargetParticipant))
  909. {
  910. return false;
  911. }
  912. // players in the different teams ?
  913. if (getParticipantTeamId(sourcePlayerId) != getParticipantTeamId(targetPlayerId))
  914. {
  915. if (!skill.isOffensive())
  916. {
  917. return false;
  918. }
  919. }
  920. return true;
  921. }
  922. /**
  923. * Sets the TvTEvent state<br>
  924. * <br>
  925. * @param state as EventState<br>
  926. */
  927. private static void setState(EventState state)
  928. {
  929. synchronized (_state)
  930. {
  931. _state = state;
  932. }
  933. }
  934. /**
  935. * Is TvTEvent inactive?<br>
  936. * <br>
  937. * @return boolean: true if event is inactive(waiting for next event cycle), otherwise false<br>
  938. */
  939. public static boolean isInactive()
  940. {
  941. boolean isInactive;
  942. synchronized (_state)
  943. {
  944. isInactive = _state == EventState.INACTIVE;
  945. }
  946. return isInactive;
  947. }
  948. /**
  949. * Is TvTEvent in inactivating?<br>
  950. * <br>
  951. * @return boolean: true if event is in inactivating progress, otherwise false<br>
  952. */
  953. public static boolean isInactivating()
  954. {
  955. boolean isInactivating;
  956. synchronized (_state)
  957. {
  958. isInactivating = _state == EventState.INACTIVATING;
  959. }
  960. return isInactivating;
  961. }
  962. /**
  963. * Is TvTEvent in participation?<br>
  964. * <br>
  965. * @return boolean: true if event is in participation progress, otherwise false<br>
  966. */
  967. public static boolean isParticipating()
  968. {
  969. boolean isParticipating;
  970. synchronized (_state)
  971. {
  972. isParticipating = _state == EventState.PARTICIPATING;
  973. }
  974. return isParticipating;
  975. }
  976. /**
  977. * Is TvTEvent starting?<br>
  978. * <br>
  979. * @return boolean: true if event is starting up(setting up fighting spot, teleport players etc.), otherwise false<br>
  980. */
  981. public static boolean isStarting()
  982. {
  983. boolean isStarting;
  984. synchronized (_state)
  985. {
  986. isStarting = _state == EventState.STARTING;
  987. }
  988. return isStarting;
  989. }
  990. /**
  991. * Is TvTEvent started?<br>
  992. * <br>
  993. * @return boolean: true if event is started, otherwise false<br>
  994. */
  995. public static boolean isStarted()
  996. {
  997. boolean isStarted;
  998. synchronized (_state)
  999. {
  1000. isStarted = _state == EventState.STARTED;
  1001. }
  1002. return isStarted;
  1003. }
  1004. /**
  1005. * Is TvTEvent rewarding?<br>
  1006. * <br>
  1007. * @return boolean: true if event is currently rewarding, otherwise false<br>
  1008. */
  1009. public static boolean isRewarding()
  1010. {
  1011. boolean isRewarding;
  1012. synchronized (_state)
  1013. {
  1014. isRewarding = _state == EventState.REWARDING;
  1015. }
  1016. return isRewarding;
  1017. }
  1018. /**
  1019. * Returns the team id of a player, if player is not participant it returns -1
  1020. * @param playerObjectId
  1021. * @return byte: team name of the given playerName, if not in event -1
  1022. */
  1023. public static byte getParticipantTeamId(int playerObjectId)
  1024. {
  1025. return (byte) (_teams[0].containsPlayer(playerObjectId) ? 0 : (_teams[1].containsPlayer(playerObjectId) ? 1 : -1));
  1026. }
  1027. /**
  1028. * Returns the team of a player, if player is not participant it returns null
  1029. * @param playerObjectId
  1030. * @return TvTEventTeam: team of the given playerObjectId, if not in event null
  1031. */
  1032. public static TvTEventTeam getParticipantTeam(int playerObjectId)
  1033. {
  1034. return (_teams[0].containsPlayer(playerObjectId) ? _teams[0] : (_teams[1].containsPlayer(playerObjectId) ? _teams[1] : null));
  1035. }
  1036. /**
  1037. * Returns the enemy team of a player, if player is not participant it returns null
  1038. * @param playerObjectId
  1039. * @return TvTEventTeam: enemy team of the given playerObjectId, if not in event null
  1040. */
  1041. public static TvTEventTeam getParticipantEnemyTeam(int playerObjectId)
  1042. {
  1043. return (_teams[0].containsPlayer(playerObjectId) ? _teams[1] : (_teams[1].containsPlayer(playerObjectId) ? _teams[0] : null));
  1044. }
  1045. /**
  1046. * Returns the team coordinates in which the player is in, if player is not in a team return null
  1047. * @param playerObjectId
  1048. * @return int[]: coordinates of teams, 2 elements, index 0 for team 1 and index 1 for team 2
  1049. */
  1050. public static int[] getParticipantTeamCoordinates(int playerObjectId)
  1051. {
  1052. return _teams[0].containsPlayer(playerObjectId) ? _teams[0].getCoordinates() : (_teams[1].containsPlayer(playerObjectId) ? _teams[1].getCoordinates() : null);
  1053. }
  1054. /**
  1055. * Is given player participant of the event?
  1056. * @param playerObjectId
  1057. * @return boolean: true if player is participant, ohterwise false
  1058. */
  1059. public static boolean isPlayerParticipant(int playerObjectId)
  1060. {
  1061. if (!isParticipating() && !isStarting() && !isStarted())
  1062. {
  1063. return false;
  1064. }
  1065. return _teams[0].containsPlayer(playerObjectId) || _teams[1].containsPlayer(playerObjectId);
  1066. }
  1067. /**
  1068. * Returns participated player count<br>
  1069. * <br>
  1070. * @return int: amount of players registered in the event<br>
  1071. */
  1072. public static int getParticipatedPlayersCount()
  1073. {
  1074. if (!isParticipating() && !isStarting() && !isStarted())
  1075. {
  1076. return 0;
  1077. }
  1078. return _teams[0].getParticipatedPlayerCount() + _teams[1].getParticipatedPlayerCount();
  1079. }
  1080. /**
  1081. * Returns teams names<br>
  1082. * <br>
  1083. * @return String[]: names of teams, 2 elements, index 0 for team 1 and index 1 for team 2<br>
  1084. */
  1085. public static String[] getTeamNames()
  1086. {
  1087. return new String[]
  1088. {
  1089. _teams[0].getName(),
  1090. _teams[1].getName()
  1091. };
  1092. }
  1093. /**
  1094. * Returns player count of both teams<br>
  1095. * <br>
  1096. * @return int[]: player count of teams, 2 elements, index 0 for team 1 and index 1 for team 2<br>
  1097. */
  1098. public static int[] getTeamsPlayerCounts()
  1099. {
  1100. return new int[]
  1101. {
  1102. _teams[0].getParticipatedPlayerCount(),
  1103. _teams[1].getParticipatedPlayerCount()
  1104. };
  1105. }
  1106. /**
  1107. * Returns points count of both teams
  1108. * @return int[]: points of teams, 2 elements, index 0 for team 1 and index 1 for team 2<br>
  1109. */
  1110. public static int[] getTeamsPoints()
  1111. {
  1112. return new int[]
  1113. {
  1114. _teams[0].getPoints(),
  1115. _teams[1].getPoints()
  1116. };
  1117. }
  1118. public static int getTvTEventInstance()
  1119. {
  1120. return _TvTEventInstance;
  1121. }
  1122. // Listeners
  1123. /**
  1124. * Fires all the TvTListener.onKill() methods, if any
  1125. * @param killer
  1126. * @param victim
  1127. * @param killerTeam
  1128. */
  1129. private static void fireTvtKillListeners(L2PcInstance killer, L2PcInstance victim, TvTEventTeam killerTeam)
  1130. {
  1131. if (!tvtListeners.isEmpty() && (killer != null) && (victim != null) && (killerTeam != null))
  1132. {
  1133. TvtKillEvent event = new TvtKillEvent();
  1134. event.setKiller(killer);
  1135. event.setVictim(victim);
  1136. event.setKillerTeam(killerTeam);
  1137. for (TvTListener listener : tvtListeners)
  1138. {
  1139. listener.onKill(event);
  1140. }
  1141. }
  1142. }
  1143. /**
  1144. * Fires the appropriate TvtEventListeners, if any
  1145. * @param stage
  1146. */
  1147. private static void fireTvtEventListeners(EventStage stage)
  1148. {
  1149. if (!tvtListeners.isEmpty())
  1150. {
  1151. switch (stage)
  1152. {
  1153. case REGISTRATION_BEGIN:
  1154. {
  1155. for (TvTListener listener : tvtListeners)
  1156. {
  1157. listener.onRegistrationStart();
  1158. }
  1159. break;
  1160. }
  1161. case START:
  1162. {
  1163. for (TvTListener listener : tvtListeners)
  1164. {
  1165. listener.onBegin();
  1166. }
  1167. break;
  1168. }
  1169. case END:
  1170. {
  1171. for (TvTListener listener : tvtListeners)
  1172. {
  1173. listener.onEnd();
  1174. }
  1175. break;
  1176. }
  1177. }
  1178. }
  1179. }
  1180. /**
  1181. * Adds a TvT listener
  1182. * @param listener
  1183. */
  1184. public static void addTvTListener(TvTListener listener)
  1185. {
  1186. if (!tvtListeners.contains(listener))
  1187. {
  1188. tvtListeners.add(listener);
  1189. }
  1190. }
  1191. /**
  1192. * Removes a TvT listener
  1193. * @param listener
  1194. */
  1195. public static void removeTvtListener(TvTListener listener)
  1196. {
  1197. tvtListeners.remove(listener);
  1198. }
  1199. }