TvTEvent.java 39 KB

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