2
0

TvTEvent.java 38 KB

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