Advertisement
Guest User

TvT Event

a guest
Aug 8th, 2016
1,981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 84.58 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2WeddingManagerInstance.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/model/actor/instance/L2WeddingManagerInstance.java   (revision 5)
  6. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2WeddingManagerInstance.java   (working copy)
  7. @@ -137,7 +137,7 @@
  8.             }
  9.            
  10.             // Simple checks to avoid exploits
  11. -           if (partner.isInJail() || partner.isInOlympiadMode() || partner.isInDuel() || partner.isFestivalParticipant() || (partner.isInParty() && partner.getParty().isInDimensionalRift()) || partner.inObserverMode())
  12. +           if (partner.isInFunEvent() || partner.isInJail() || partner.isInOlympiadMode() || partner.isInDuel() || partner.isFestivalParticipant() || (partner.isInParty() && partner.getParty().isInDimensionalRift()) || partner.inObserverMode())
  13.             {
  14.                 player.sendMessage("Due to the current partner's status, the teleportation failed.");
  15.                 return;
  16. Index: java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/TvTEventCommand.java
  17. ===================================================================
  18. --- java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/TvTEventCommand.java   (revision 0)
  19. +++ java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/TvTEventCommand.java   (working copy)
  20. @@ -0,0 +1,137 @@
  21. +/*
  22. + * This program is free software: you can redistribute it and/or modify it under
  23. + * the terms of the GNU General Public License as published by the Free Software
  24. + * Foundation, either version 3 of the License, or (at your option) any later
  25. + * version.
  26. + *
  27. + * This program is distributed in the hope that it will be useful, but WITHOUT
  28. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  29. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  30. + * details.
  31. + *
  32. + * You should have received a copy of the GNU General Public License along with
  33. + * this program. If not, see <http://www.gnu.org/licenses/>.
  34. + */
  35. +
  36. +package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
  37. +
  38. +import net.sf.l2j.Config;
  39. +import net.sf.l2j.gameserver.cache.HtmCache;
  40. +import net.sf.l2j.gameserver.events.TvTEvent;
  41. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  42. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  43. +import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
  44. +import net.sf.l2j.gameserver.network.clientpackets.Say2;
  45. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  46. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  47. +
  48. +/**
  49. + * @author Baggos
  50. + */
  51. +
  52. +public class TvTEventCommand implements IVoicedCommandHandler
  53. +{
  54. +   private static final String[] VOICED_COMMANDS =
  55. +   {
  56. +       "tvtjoin",
  57. +       "tvtleave",
  58. +       "tvtstatus"
  59. +   };
  60. +  
  61. +   @Override
  62. +   public boolean useVoicedCommand(final String command, final L2PcInstance activeChar, final String target)
  63. +   {
  64. +       if (command.startsWith("tvtjoin"))
  65. +           JoinTvT(target, activeChar);
  66. +      
  67. +       else if (command.startsWith("tvtleave"))
  68. +           LeaveTvT(activeChar);
  69. +      
  70. +       else if (command.startsWith("tvtstatus"))
  71. +           TvTStatus(activeChar);
  72. +      
  73. +       return true;
  74. +   }
  75. +  
  76. +   public static boolean JoinTvT(final String command, L2PcInstance activeChar)
  77. +   {
  78. +       int playerLevel = activeChar.getLevel();
  79. +       if (!TvTEvent.isParticipating())
  80. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "Hey " + activeChar.getName() + "", "There is no TvT Event in progress."));
  81. +       else if (TvTEvent.isPlayerParticipant(activeChar.getName()))
  82. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "TvT Event", "You are already on the list."));
  83. +       else if (activeChar.isCursedWeaponEquipped())
  84. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "TvT Event", "Cursed weapon owners are not allowed to participate."));
  85. +       else if (activeChar.isInJail())
  86. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "TvT Event", "Nothing for you!."));
  87. +       else if (OlympiadManager.getInstance().isRegisteredInComp(activeChar))
  88. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "TvT Event", "Olympiad participants can't register."));
  89. +       else if (activeChar.getKarma() > 0)
  90. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "TvT Event", "Chaotic players are not allowed to participate."));
  91. +       else if (TvTEvent._teams[0].getParticipatedPlayerCount() >= Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS && TvTEvent._teams[1].getParticipatedPlayerCount() >= Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS)
  92. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "TvT Event", "Sorry the event is full!"));
  93. +       else if (playerLevel < Config.TVT_EVENT_MIN_LVL || playerLevel > Config.TVT_EVENT_MAX_LVL)
  94. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "TvT Event", "Only players from level " + Config.TVT_EVENT_MIN_LVL + " until level " + Config.TVT_EVENT_MAX_LVL + " are allowed to participate."));
  95. +       else if (TvTEvent._teams[0].getParticipatedPlayerCount() > 19 && TvTEvent._teams[1].getParticipatedPlayerCount() > 19)
  96. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "TvT Event", "The event is full! Maximum of " + Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS + "  player are allowed in one team."));
  97. +       else
  98. +       {
  99. +           TvTEvent.addParticipant(activeChar);
  100. +           NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  101. +           npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>You are on the registration list now.</body></html>");
  102. +           activeChar.sendPacket(npcHtmlMessage);
  103. +       }
  104. +       return false;
  105. +   }
  106. +  
  107. +   public boolean LeaveTvT(final L2PcInstance activeChar)
  108. +   {
  109. +       if (!TvTEvent.isParticipating())
  110. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "Hey " + activeChar.getName() + "", "There is no TvT Event in progress."));
  111. +       else if (!TvTEvent.isInactive() && !TvTEvent.isPlayerParticipant(activeChar.getName()))
  112. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "TvT Event", "You aren't registered in the TvT Event."));
  113. +       else
  114. +       {
  115. +           TvTEvent.removeParticipant(activeChar.getName());
  116. +           NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  117. +           npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>You are not longer on the registration list.</body></html>");
  118. +           activeChar.sendPacket(npcHtmlMessage);
  119. +       }
  120. +       return false;
  121. +   }
  122. +  
  123. +   public boolean TvTStatus(final L2PcInstance activeChar)
  124. +   {
  125. +       if (!TvTEvent.isStarted())
  126. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "TvT Event", "TvT Event is not in progress yet."));
  127. +       else
  128. +       {
  129. +           String htmFile = "data/html/mods/TvTEventStatus.htm";
  130. +           String htmContent = HtmCache.getInstance().getHtm(htmFile);
  131. +          
  132. +           if (htmContent != null)
  133. +           {
  134. +               int[] teamsPlayerCounts = TvTEvent.getTeamsPlayerCounts();
  135. +               int[] teamsPointsCounts = TvTEvent.getTeamsPoints();
  136. +               NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(5);
  137. +              
  138. +               npcHtmlMessage.setHtml(htmContent);
  139. +               // npcHtmlMessage.replace("%objectId%", String.valueOf(getObjectId()));
  140. +               npcHtmlMessage.replace("%team1name%", Config.TVT_EVENT_TEAM_1_NAME);
  141. +               npcHtmlMessage.replace("%team1playercount%", String.valueOf(teamsPlayerCounts[0]));
  142. +               npcHtmlMessage.replace("%team1points%", String.valueOf(teamsPointsCounts[0]));
  143. +               npcHtmlMessage.replace("%team2name%", Config.TVT_EVENT_TEAM_2_NAME);
  144. +               npcHtmlMessage.replace("%team2playercount%", String.valueOf(teamsPlayerCounts[1]));
  145. +               npcHtmlMessage.replace("%team2points%", String.valueOf(teamsPointsCounts[1])); // <---- array index from 0 to 1 thx DaRkRaGe
  146. +               activeChar.sendPacket(npcHtmlMessage);
  147. +           }
  148. +       }
  149. +       return false;
  150. +   }
  151. +  
  152. +   @Override
  153. +   public String[] getVoicedCommandList()
  154. +   {
  155. +       return VOICED_COMMANDS;
  156. +   }
  157. +}
  158. Index: java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java
  159. ===================================================================
  160. --- java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java    (revision 5)
  161. +++ java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java    (working copy)
  162. @@ -25,6 +25,7 @@
  163.  import net.sf.l2j.gameserver.ThreadPoolManager;
  164.  import net.sf.l2j.gameserver.datatables.NpcTable;
  165.  import net.sf.l2j.gameserver.datatables.SummonItemsData;
  166. +import net.sf.l2j.gameserver.events.TvTEvent;
  167.  import net.sf.l2j.gameserver.handler.IItemHandler;
  168.  import net.sf.l2j.gameserver.model.L2Object;
  169.  import net.sf.l2j.gameserver.model.L2Spawn;
  170. @@ -66,6 +67,9 @@
  171.         if (activeChar.isAllSkillsDisabled() || activeChar.isCastingNow())
  172.             return;
  173.        
  174. +       if (!TvTEvent.onItemSummon(playable.getName()))
  175. +           return;
  176. +      
  177.         final SummonItem sitem = SummonItemsData.getInstance().getSummonItem(item.getItemId());
  178.        
  179.         if ((activeChar.getPet() != null || activeChar.isMounted()) && sitem.isPetSummon())
  180. Index: java/net/sf/l2j/gameserver/events/TvTEventTeams.java
  181. ===================================================================
  182. --- java/net/sf/l2j/gameserver/events/TvTEventTeams.java    (revision 0)
  183. +++ java/net/sf/l2j/gameserver/events/TvTEventTeams.java    (working copy)
  184. @@ -0,0 +1,209 @@
  185. +/*
  186. + * This program is free software: you can redistribute it and/or modify it under
  187. + * the terms of the GNU General Public License as published by the Free Software
  188. + * Foundation, either version 3 of the License, or (at your option) any later
  189. + * version.
  190. + *
  191. + * This program is distributed in the hope that it will be useful, but WITHOUT
  192. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  193. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  194. + * details.
  195. + *
  196. + * You should have received a copy of the GNU General Public License along with
  197. + * this program. If not, see <http://www.gnu.org/licenses/>.
  198. + */
  199. +package net.sf.l2j.gameserver.events;
  200. +
  201. +
  202. +import java.util.HashMap;
  203. +import java.util.Map;
  204. +import java.util.Vector;
  205. +
  206. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  207. +
  208. +/**
  209. + * @author FBIagent
  210. + */
  211. +public class TvTEventTeams
  212. +{
  213. +   /**
  214. +    * The name of the team<br>
  215. +    */
  216. +   private String _name;
  217. +   /**
  218. +    * The team spot coordinated<br>
  219. +    */
  220. +   private int[] _coordinates = new int[3];
  221. +   /**
  222. +    * The points of the team<br>
  223. +    */
  224. +   private short _points;
  225. +   /**
  226. +    * Name and instance of all participated players in FastMap<br>
  227. +    */
  228. +   private Map<String, L2PcInstance> _participatedPlayers = new HashMap<>();
  229. +   /**
  230. +    * Name of all participated players in Vector<br>
  231. +    */
  232. +   private Vector<String> _participatedPlayerNames = new Vector<>();
  233. +  
  234. +   /**
  235. +    * C'tor initialize the team
  236. +    * @param name
  237. +    * @param coordinates
  238. +    */
  239. +   public TvTEventTeams(String name, int[] coordinates)
  240. +   {
  241. +       _name = name;
  242. +       _coordinates = coordinates;
  243. +       _points = 0;
  244. +   }
  245. +  
  246. +   /**
  247. +    * Adds a player to the team
  248. +    * @param playerInstance
  249. +    * @return boolean
  250. +    */
  251. +   public boolean addPlayer(L2PcInstance playerInstance)
  252. +   {
  253. +       if (playerInstance == null)
  254. +           return false;
  255. +      
  256. +       synchronized (_participatedPlayers)
  257. +       {
  258. +           String playerName = playerInstance.getName();
  259. +          
  260. +           _participatedPlayers.put(playerName, playerInstance);
  261. +          
  262. +           if (!_participatedPlayerNames.contains(playerName))
  263. +               _participatedPlayerNames.add(playerName);
  264. +       }
  265. +      
  266. +       return true;
  267. +   }
  268. +  
  269. +   /**
  270. +    * Removes a player from the team
  271. +    * @param playerName
  272. +    */
  273. +   public void removePlayer(String playerName)
  274. +   {
  275. +       synchronized (_participatedPlayers)
  276. +       {
  277. +           _participatedPlayers.remove(playerName);
  278. +           _participatedPlayerNames.remove(playerName);
  279. +       }
  280. +   }
  281. +  
  282. +   /**
  283. +    * Increases the points of the team<br>
  284. +    */
  285. +   public void increasePoints()
  286. +   {
  287. +       _points++;
  288. +   }
  289. +  
  290. +   /**
  291. +    * Cleanup the team and make it ready for adding players again<br>
  292. +    */
  293. +   public void cleanMe()
  294. +   {
  295. +       _participatedPlayers.clear();
  296. +       _participatedPlayerNames.clear();
  297. +       _participatedPlayers = new HashMap<>();
  298. +       _participatedPlayerNames = new Vector<>();
  299. +       _points = 0;
  300. +   }
  301. +  
  302. +   /**
  303. +    * Is given player in this team?
  304. +    * @param playerName
  305. +    * @return boolean
  306. +    */
  307. +   public boolean containsPlayer(String playerName)
  308. +   {
  309. +       boolean containsPlayer;
  310. +      
  311. +       synchronized (_participatedPlayers)
  312. +       {
  313. +           containsPlayer = _participatedPlayerNames.contains(playerName);
  314. +       }
  315. +      
  316. +       return containsPlayer;
  317. +   }
  318. +  
  319. +   /**
  320. +    * Returns the name of the team
  321. +    * @return String
  322. +    */
  323. +   public String getName()
  324. +   {
  325. +       return _name;
  326. +   }
  327. +  
  328. +   /**
  329. +    * Returns the coordinates of the team spot
  330. +    * @return int[]
  331. +    */
  332. +   public int[] getCoordinates()
  333. +   {
  334. +       return _coordinates;
  335. +   }
  336. +  
  337. +   /**
  338. +    * Returns the points of the team
  339. +    * @return short
  340. +    */
  341. +   public short getPoints()
  342. +   {
  343. +       return _points;
  344. +   }
  345. +  
  346. +   /**
  347. +    * Returns name and instance of all participated players in FastMap
  348. +    * @return Map<String, L2PcInstance>
  349. +    */
  350. +   public Map<String, L2PcInstance> getParticipatedPlayers()
  351. +   {
  352. +       Map<String, L2PcInstance> participatedPlayers = null;
  353. +      
  354. +       synchronized (_participatedPlayers)
  355. +       {
  356. +           participatedPlayers = _participatedPlayers;
  357. +       }
  358. +      
  359. +       return participatedPlayers;
  360. +   }
  361. +  
  362. +   /**
  363. +    * Returns name of all participated players in Vector
  364. +    * @return Vector<String>
  365. +    */
  366. +   public Vector<String> getParticipatedPlayerNames()
  367. +   {
  368. +       Vector<String> participatedPlayerNames = null;
  369. +      
  370. +       synchronized (_participatedPlayers)
  371. +       {
  372. +           participatedPlayerNames = _participatedPlayerNames;
  373. +       }
  374. +      
  375. +       return participatedPlayerNames;
  376. +   }
  377. +  
  378. +   /**
  379. +    * Returns player count of this team
  380. +    * @return int
  381. +    */
  382. +   public int getParticipatedPlayerCount()
  383. +   {
  384. +       int participatedPlayerCount;
  385. +      
  386. +       synchronized (_participatedPlayers)
  387. +       {
  388. +           participatedPlayerCount = _participatedPlayers.size();
  389. +       }
  390. +      
  391. +       return participatedPlayerCount;
  392. +   }
  393. +}
  394. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminTvTEvent.java
  395. ===================================================================
  396. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminTvTEvent.java  (revision 0)
  397. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminTvTEvent.java  (working copy)
  398. @@ -0,0 +1,91 @@
  399. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  400. +
  401. +import net.sf.l2j.Config;
  402. +import net.sf.l2j.gameserver.events.TvTEvent;
  403. +import net.sf.l2j.gameserver.events.TvTEventTeleport;
  404. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  405. +import net.sf.l2j.gameserver.model.L2Object;
  406. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  407. +import net.sf.l2j.gameserver.util.GMAudit;
  408. +
  409. +/**
  410. + * @author FBIagent The class handles administrator commands for the TvT Engine which was first implemented by FBIagent
  411. + */
  412. +public class AdminTvTEvent implements IAdminCommandHandler
  413. +{
  414. +   private static final String[] ADMIN_COMMANDS =
  415. +   {
  416. +       "admin_tvt_add",
  417. +       "admin_tvt_remove"
  418. +   };
  419. +  
  420. +   @Override
  421. +   public boolean useAdminCommand(String command, L2PcInstance adminInstance)
  422. +   {
  423. +      
  424. +       GMAudit.auditGMAction(adminInstance.getName(), command, (adminInstance.getTarget() != null ? adminInstance.getTarget().getName() : "no-target"), "");
  425. +      
  426. +       if (command.equals("admin_tvt_add"))
  427. +       {
  428. +           L2Object target = adminInstance.getTarget();
  429. +          
  430. +           if (target == null || !(target instanceof L2PcInstance))
  431. +           {
  432. +               adminInstance.sendMessage("You should select a player!");
  433. +               return true;
  434. +           }
  435. +          
  436. +           add(adminInstance, (L2PcInstance) target);
  437. +       }
  438. +       else if (command.equals("admin_tvt_remove"))
  439. +       {
  440. +           L2Object target = adminInstance.getTarget();
  441. +          
  442. +           if (target == null || !(target instanceof L2PcInstance))
  443. +           {
  444. +               adminInstance.sendMessage("You should select a player!");
  445. +               return true;
  446. +           }
  447. +          
  448. +           remove(adminInstance, (L2PcInstance) target);
  449. +       }
  450. +      
  451. +       return true;
  452. +   }
  453. +  
  454. +   @Override
  455. +   public String[] getAdminCommandList()
  456. +   {
  457. +       return ADMIN_COMMANDS;
  458. +   }
  459. +  
  460. +   private static void add(L2PcInstance adminInstance, L2PcInstance playerInstance)
  461. +   {
  462. +       if (TvTEvent.isPlayerParticipant(playerInstance.getName()))
  463. +       {
  464. +           adminInstance.sendMessage("Player already participated in the event!");
  465. +           return;
  466. +       }
  467. +      
  468. +       if (!TvTEvent.addParticipant(playerInstance))
  469. +       {
  470. +           adminInstance.sendMessage("Player instance could not be added, it seems to be null!");
  471. +           return;
  472. +       }
  473. +      
  474. +       if (TvTEvent.isStarted())
  475. +           // we don't need to check return value of TvTEvent.getParticipantTeamCoordinates() for null, TvTEvent.addParticipant() returned true so target is in event
  476. +           new TvTEventTeleport(playerInstance, TvTEvent.getParticipantTeamCoordinates(playerInstance.getName()), true, false);
  477. +   }
  478. +  
  479. +   private static void remove(L2PcInstance adminInstance, L2PcInstance playerInstance)
  480. +   {
  481. +       if (!TvTEvent.removeParticipant(playerInstance.getName()))
  482. +       {
  483. +           adminInstance.sendMessage("Player is not part of the event!");
  484. +           return;
  485. +       }
  486. +      
  487. +       new TvTEventTeleport(playerInstance, Config.TVT_EVENT_BACK_COORDINATES, true, true);
  488. +   }
  489. +}
  490. \ No newline at end of file
  491. Index: java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java
  492. ===================================================================
  493. --- java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java   (revision 0)
  494. +++ java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java   (working copy)
  495. @@ -0,0 +1,10 @@
  496. +package net.sf.l2j.gameserver.handler;
  497. +
  498. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  499. +
  500. +public interface IVoicedCommandHandler
  501. +{
  502. +       public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params);
  503. +
  504. +       public String[] getVoicedCommandList();
  505. +}
  506. \ No newline at end of file
  507. Index: java/net/sf/l2j/gameserver/events/TvTEventTeleport.java
  508. ===================================================================
  509. --- java/net/sf/l2j/gameserver/events/TvTEventTeleport.java (revision 0)
  510. +++ java/net/sf/l2j/gameserver/events/TvTEventTeleport.java (working copy)
  511. @@ -0,0 +1,102 @@
  512. +/*
  513. + * This program is free software: you can redistribute it and/or modify it under
  514. + * the terms of the GNU General Public License as published by the Free Software
  515. + * Foundation, either version 3 of the License, or (at your option) any later
  516. + * version.
  517. + *
  518. + * This program is distributed in the hope that it will be useful, but WITHOUT
  519. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  520. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  521. + * details.
  522. + *
  523. + * You should have received a copy of the GNU General Public License along with
  524. + * this program. If not, see <http://www.gnu.org/licenses/>.
  525. + */
  526. +package net.sf.l2j.gameserver.events;
  527. +
  528. +import net.sf.l2j.Config;
  529. +import net.sf.l2j.gameserver.ThreadPoolManager;
  530. +import net.sf.l2j.gameserver.datatables.SkillTable;
  531. +import net.sf.l2j.gameserver.model.L2Effect;
  532. +import net.sf.l2j.gameserver.model.L2Skill;
  533. +import net.sf.l2j.gameserver.model.actor.L2Summon;
  534. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  535. +
  536. +public class TvTEventTeleport implements Runnable
  537. +{
  538. +   /** Gives Noblesse to players */
  539. +   static L2Skill noblesse = SkillTable.getInstance().getInfo(1323, 1);
  540. +   /** The instance of the player to teleport */
  541. +   public L2PcInstance _playerInstance;
  542. +   /** Coordinates of the spot to teleport to */
  543. +   public int[] _coordinates = new int[3];
  544. +   /** Admin removed this player from event */
  545. +   private boolean _adminRemove;
  546. +  
  547. +   /**
  548. +    * Initialize the teleporter and start the delayed task
  549. +    * @param playerInstance
  550. +    * @param coordinates
  551. +    * @param fastSchedule
  552. +    * @param adminRemove
  553. +    */
  554. +   public TvTEventTeleport(L2PcInstance playerInstance, int[] coordinates, boolean fastSchedule, boolean adminRemove)
  555. +   {
  556. +       _playerInstance = playerInstance;
  557. +       _coordinates = coordinates;
  558. +       _adminRemove = adminRemove;
  559. +      
  560. +       // in config as seconds
  561. +       long delay = (TvTEvent.isStarted() ? Config.TVT_EVENT_RESPAWN_TELEPORT_DELAY : Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY) * 1000;
  562. +      
  563. +       if (fastSchedule)
  564. +           delay = 0;
  565. +      
  566. +       ThreadPoolManager.getInstance().scheduleGeneral(this, delay);
  567. +   }
  568. +  
  569. +   /**
  570. +    * The task method to teleport the player<br>
  571. +    * 1. Unsummon pet if there is one 2. Remove all effects 3. Revive and full heal the player 4. Teleport the player 5. Broadcast status and user info
  572. +    * @see java.lang.Runnable#run()
  573. +    */
  574. +   @Override
  575. +   public void run()
  576. +   {
  577. +       if (_playerInstance == null)
  578. +           return;
  579. +      
  580. +       L2Summon summon = _playerInstance.getPet();
  581. +      
  582. +       if (summon != null)
  583. +           summon.unSummon(_playerInstance);
  584. +      
  585. +       for (L2Effect effect : _playerInstance.getAllEffects())
  586. +       {
  587. +           if (Config.TVT_EVENT_REMOVE_BUFFS && effect != null)
  588. +               effect.exit();
  589. +       }
  590. +      
  591. +       ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  592. +       {
  593. +           @Override
  594. +           public void run()
  595. +           {
  596. +               _playerInstance.doRevive();
  597. +               _playerInstance.setCurrentHp(_playerInstance.getMaxHp());
  598. +               _playerInstance.setCurrentCp(_playerInstance.getMaxCp());
  599. +               _playerInstance.setCurrentMp(_playerInstance.getMaxMp());
  600. +               noblesse.getEffects(_playerInstance, _playerInstance);
  601. +               _playerInstance.teleToLocation(_coordinates[0], _coordinates[1], _coordinates[2], 0);
  602. +           }
  603. +       }, 4000);
  604. +      
  605. +       if (TvTEvent.isStarted() && !_adminRemove)
  606. +           _playerInstance.setTeam(TvTEvent.getParticipantTeamId(_playerInstance.getName()) + 1);
  607. +       else
  608. +           _playerInstance.setTeam(0);
  609. +      
  610. +       _playerInstance.broadcastStatusUpdate();
  611. +       _playerInstance.broadcastUserInfo();
  612. +   }
  613. +}
  614. Index: java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
  615. ===================================================================
  616. --- java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java    (revision 0)
  617. +++ java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java    (working copy)
  618. @@ -0,0 +1,67 @@
  619. +/*
  620. + * This program is free software: you can redistribute it and/or modify it under
  621. + * the terms of the GNU General Public License as published by the Free Software
  622. + * Foundation, either version 3 of the License, or (at your option) any later
  623. + * version.
  624. + *
  625. + * This program is distributed in the hope that it will be useful, but WITHOUT
  626. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  627. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  628. + * details.
  629. + *
  630. + * You should have received a copy of the GNU General Public License along with
  631. + * this program. If not, see <http://www.gnu.org/licenses/>.
  632. + */
  633. +package net.sf.l2j.gameserver.handler;
  634. +
  635. +import java.util.HashMap;
  636. +import java.util.Map;
  637. +
  638. +import net.sf.l2j.gameserver.handler.voicedcommandhandlers.TvTEventCommand;
  639. +
  640. +
  641. +
  642. +
  643. +public class VoicedCommandHandler
  644. +{
  645. +       private final Map<Integer, IVoicedCommandHandler> _datatable = new HashMap<>();
  646. +      
  647. +       public static VoicedCommandHandler getInstance()
  648. +       {
  649. +               return SingletonHolder._instance;
  650. +       }
  651. +      
  652. +       protected VoicedCommandHandler()
  653. +       {
  654. +               // coloque aqui os comandos
  655. +               registerHandler(new TvTEventCommand());
  656. +       }
  657. +      
  658. +       public void registerHandler(IVoicedCommandHandler handler)
  659. +       {
  660. +               String[] ids = handler.getVoicedCommandList();
  661. +              
  662. +               for (int i = 0; i < ids.length; i++)          
  663. +                       _datatable.put(ids[i].hashCode(), handler);
  664. +       }
  665. +              
  666. +       public IVoicedCommandHandler getHandler(String voicedCommand)
  667. +       {
  668. +               String command = voicedCommand;
  669. +              
  670. +               if (voicedCommand.indexOf(" ") != -1)          
  671. +                       command = voicedCommand.substring(0, voicedCommand.indexOf(" "));              
  672. +
  673. +               return _datatable.get(command.hashCode());            
  674. +       }
  675. +      
  676. +       public int size()
  677. +       {
  678. +               return _datatable.size();
  679. +       }
  680. +      
  681. +       private static class SingletonHolder
  682. +       {
  683. +               protected static final VoicedCommandHandler _instance = new VoicedCommandHandler();
  684. +       }
  685. +}
  686. Index: java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java
  687. ===================================================================
  688. --- java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java    (revision 5)
  689. +++ java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java    (working copy)
  690. @@ -14,7 +14,11 @@
  691.   */
  692.  package net.sf.l2j.gameserver.handler.chathandlers;
  693.  
  694. +import java.util.StringTokenizer;
  695. +
  696.  import net.sf.l2j.gameserver.handler.IChatHandler;
  697. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  698. +import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
  699.  import net.sf.l2j.gameserver.model.BlockList;
  700.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  701.  import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  702. @@ -34,13 +38,42 @@
  703.         if (!FloodProtectors.performAction(activeChar.getClient(), Action.GLOBAL_CHAT))
  704.             return;
  705.        
  706. -       final CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  707. -       for (L2PcInstance player : activeChar.getKnownList().getKnownTypeInRadius(L2PcInstance.class, 1250))
  708. +       boolean vcd_used = false;
  709. +       if (text.startsWith("."))
  710.         {
  711. -           if (!BlockList.isBlocked(player, activeChar))
  712. -               player.sendPacket(cs);
  713. +           StringTokenizer st = new StringTokenizer(text);
  714. +           IVoicedCommandHandler vch;
  715. +           String command = "";
  716. +           if (st.countTokens() > 1)
  717. +           {
  718. +               command = st.nextToken().substring(1);
  719. +               params = text.substring(command.length() + 2);
  720. +               vch = VoicedCommandHandler.getInstance().getHandler(command);
  721. +           }
  722. +           else
  723. +           {
  724. +               command = text.substring(1);
  725. +               vch = VoicedCommandHandler.getInstance().getHandler(command);
  726. +           }
  727. +          
  728. +           if (vch != null)
  729. +           {
  730. +               vch.useVoicedCommand(command, activeChar, params);
  731. +               vcd_used = true;
  732. +           }
  733.         }
  734. -       activeChar.sendPacket(cs);
  735. +       if (!vcd_used)
  736. +       {
  737. +           CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  738. +          
  739. +           for (L2PcInstance player : activeChar.getKnownList().getKnownTypeInRadius(L2PcInstance.class, 1250))
  740. +           {
  741. +               if (!BlockList.isBlocked(player, activeChar))
  742. +                   player.sendPacket(cs);
  743. +           }
  744. +          
  745. +           activeChar.sendPacket(cs);
  746. +       }
  747.     }
  748.    
  749.     @Override
  750. Index: java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
  751. ===================================================================
  752. --- java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java    (revision 5)
  753. +++ java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java    (working copy)
  754. @@ -21,6 +21,7 @@
  755.  import net.sf.l2j.gameserver.datatables.GmListTable;
  756.  import net.sf.l2j.gameserver.datatables.MapRegionTable;
  757.  import net.sf.l2j.gameserver.datatables.SkillTable.FrequentSkill;
  758. +import net.sf.l2j.gameserver.events.TvTEvent;
  759.  import net.sf.l2j.gameserver.instancemanager.ClanHallManager;
  760.  import net.sf.l2j.gameserver.instancemanager.CoupleManager;
  761.  import net.sf.l2j.gameserver.instancemanager.DimensionalRiftManager;
  762. @@ -226,6 +227,7 @@
  763.             sendPacket(new Die(activeChar));
  764.        
  765.         activeChar.onPlayerEnter();
  766. +       TvTEvent.onLogin(activeChar, activeChar);
  767.        
  768.         sendPacket(new SkillCoolTime(activeChar));
  769.        
  770. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java
  771. ===================================================================
  772. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java    (revision 5)
  773. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java    (working copy)
  774. @@ -14,6 +14,7 @@
  775.   */
  776.  package net.sf.l2j.gameserver.network.clientpackets;
  777.  
  778. +import net.sf.l2j.gameserver.events.TvTEvent;
  779.  import net.sf.l2j.gameserver.instancemanager.SevenSignsFestival;
  780.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  781.  import net.sf.l2j.gameserver.model.zone.ZoneId;
  782. @@ -59,6 +60,13 @@
  783.             return;
  784.         }
  785.        
  786. +       if (!TvTEvent.isInactive() && TvTEvent.isPlayerParticipant(player.getName()))
  787. +       {
  788. +           player.sendMessage("You can not restart when you registering in TvTEvent.");
  789. +           sendPacket(RestartResponse.valueOf(false));
  790. +           return;
  791. +       }
  792. +      
  793.         if (player.isFestivalParticipant())
  794.         {
  795.             if (SevenSignsFestival.getInstance().isFestivalInitialized())
  796. Index: java/net/sf/l2j/gameserver/network/serverpackets/Die.java
  797. ===================================================================
  798. --- java/net/sf/l2j/gameserver/network/serverpackets/Die.java   (revision 5)
  799. +++ java/net/sf/l2j/gameserver/network/serverpackets/Die.java   (working copy)
  800. @@ -31,6 +31,7 @@
  801.     private boolean _allowFixedRes;
  802.     private L2Clan _clan;
  803.     L2Character _activeChar;
  804. +   private boolean _funEvent;
  805.    
  806.     public Die(L2Character cha)
  807.     {
  808. @@ -43,6 +44,7 @@
  809.             L2PcInstance player = (L2PcInstance) cha;
  810.             _allowFixedRes = player.getAccessLevel().allowFixedRes();
  811.             _clan = player.getClan();
  812. +           _funEvent = !player.isInFunEvent();
  813.            
  814.         }
  815.         else if (cha instanceof L2Attackable)
  816. @@ -57,9 +59,9 @@
  817.        
  818.         writeC(0x06);
  819.         writeD(_charObjId);
  820. -       writeD(0x01); // to nearest village
  821. +       writeD(_funEvent ? 0x01 : 0); // to nearest village
  822.        
  823. -       if (_clan != null)
  824. +       if (_funEvent && _clan != null)
  825.         {
  826.             L2SiegeClan siegeClan = null;
  827.             boolean isInDefense = false;
  828. Index: java/net/sf/l2j/gameserver/handler/skillhandlers/Resurrect.java
  829. ===================================================================
  830. --- java/net/sf/l2j/gameserver/handler/skillhandlers/Resurrect.java (revision 5)
  831. +++ java/net/sf/l2j/gameserver/handler/skillhandlers/Resurrect.java (working copy)
  832. @@ -14,6 +14,7 @@
  833.   */
  834.  package net.sf.l2j.gameserver.handler.skillhandlers;
  835.  
  836. +import net.sf.l2j.gameserver.events.TvTEvent;
  837.  import net.sf.l2j.gameserver.handler.ISkillHandler;
  838.  import net.sf.l2j.gameserver.model.L2Object;
  839.  import net.sf.l2j.gameserver.model.L2Skill;
  840. @@ -35,6 +36,11 @@
  841.     @Override
  842.     public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  843.     {
  844. +       if (!TvTEvent.isInactive() && TvTEvent.isPlayerParticipant(activeChar.getName()))
  845. +       {
  846. +           activeChar.sendMessage("You can not use this action when it is participating in this event.");
  847. +           return;
  848. +       }
  849.         for (L2Object cha : targets)
  850.         {
  851.             final L2Character target = (L2Character) cha;
  852. Index: java/net/sf/l2j/gameserver/model/olympiad/OlympiadManager.java
  853. ===================================================================
  854. --- java/net/sf/l2j/gameserver/model/olympiad/OlympiadManager.java  (revision 5)
  855. +++ java/net/sf/l2j/gameserver/model/olympiad/OlympiadManager.java  (working copy)
  856. @@ -21,6 +21,7 @@
  857.  import java.util.concurrent.CopyOnWriteArrayList;
  858.  
  859.  import net.sf.l2j.Config;
  860. +import net.sf.l2j.gameserver.events.TvTEvent;
  861.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  862.  import net.sf.l2j.gameserver.network.SystemMessageId;
  863.  import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  864. @@ -257,6 +258,12 @@
  865.             return false;
  866.         }
  867.        
  868. +       if (!TvTEvent.isInactive() && TvTEvent.isPlayerParticipant(player.getName()))
  869. +       {
  870. +           player.sendMessage("You can not register in olympiad while registered at TvT.");
  871. +           return false;
  872. +       }
  873. +      
  874.         if (player.isSubClassActive())
  875.         {
  876.             player.sendPacket(SystemMessageId.YOU_CANT_JOIN_THE_OLYMPIAD_WITH_A_SUB_JOB_CHARACTER);
  877. Index: java/net/sf/l2j/gameserver/handler/skillhandlers/SummonFriend.java
  878. ===================================================================
  879. --- java/net/sf/l2j/gameserver/handler/skillhandlers/SummonFriend.java  (revision 5)
  880. +++ java/net/sf/l2j/gameserver/handler/skillhandlers/SummonFriend.java  (working copy)
  881. @@ -14,6 +14,7 @@
  882.   */
  883.  package net.sf.l2j.gameserver.handler.skillhandlers;
  884.  
  885. +import net.sf.l2j.gameserver.events.TvTEvent;
  886.  import net.sf.l2j.gameserver.handler.ISkillHandler;
  887.  import net.sf.l2j.gameserver.model.L2Object;
  888.  import net.sf.l2j.gameserver.model.L2Skill;
  889. @@ -47,6 +48,13 @@
  890.         if (!L2PcInstance.checkSummonerStatus(player))
  891.             return;
  892.        
  893. +       // Players can't summon anyone on event
  894. +       if (!TvTEvent.isInactive() && TvTEvent.isPlayerParticipant(player.getName()))
  895. +       {
  896. +           player.sendMessage("You can not use this action when it is participating in this event.");
  897. +           return;
  898. +       }
  899. +      
  900.         for (L2Object obj : targets)
  901.         {
  902.             // The target must be a player.
  903. Index: java/net/sf/l2j/gameserver/skills/l2skills/L2SkillTeleport.java
  904. ===================================================================
  905. --- java/net/sf/l2j/gameserver/skills/l2skills/L2SkillTeleport.java (revision 5)
  906. +++ java/net/sf/l2j/gameserver/skills/l2skills/L2SkillTeleport.java (working copy)
  907. @@ -51,7 +51,7 @@
  908.         if (activeChar instanceof L2PcInstance)
  909.         {
  910.             // Check invalid states.
  911. -           if (activeChar.isAfraid() || ((L2PcInstance) activeChar).isInOlympiadMode() || GrandBossManager.getInstance().isInBossZone(activeChar))
  912. +           if (activeChar.isAfraid() || ((L2PcInstance) activeChar).isInOlympiadMode() || GrandBossManager.getInstance().isInBossZone(activeChar) || ((L2PcInstance) activeChar).isInFunEvent())
  913.                 return;
  914.         }
  915.        
  916. Index: java/net/sf/l2j/Config.java
  917. ===================================================================
  918. --- java/net/sf/l2j/Config.java (revision 5)
  919. +++ java/net/sf/l2j/Config.java (working copy)
  920. @@ -223,6 +223,34 @@
  921.     public static int ALT_FISH_CHAMPIONSHIP_REWARD_5;
  922.    
  923.     // --------------------------------------------------
  924. +   // Events settings
  925. +   // --------------------------------------------------
  926. +   public static boolean TVT_EVENT_ENABLED;
  927. +   public static int TVT_EVENT_INTERVAL;
  928. +   public static int TVT_EVENT_PARTICIPATION_TIME;
  929. +   public static int TVT_EVENT_RUNNING_TIME;
  930. +   public static int TVT_EVENT_PARTICIPATION_NPC_ID;
  931. +   public static int TVT_EVENT_MIN_PLAYERS_IN_TEAMS;
  932. +   public static int TVT_EVENT_MAX_PLAYERS_IN_TEAMS;
  933. +   public static int TVT_EVENT_RESPAWN_TELEPORT_DELAY;
  934. +   public static int TVT_EVENT_START_LEAVE_TELEPORT_DELAY;
  935. +   public static String TVT_EVENT_TEAM_1_NAME;
  936. +   public static int[] TVT_EVENT_BACK_COORDINATES = new int[3];
  937. +   public static int[] TVT_EVENT_TEAM_1_COORDINATES = new int[3];
  938. +   public static String TVT_EVENT_TEAM_2_NAME;
  939. +   public static int[] TVT_EVENT_TEAM_2_COORDINATES = new int[3];
  940. +   public static List<int[]> TVT_EVENT_REWARDS = new ArrayList<>();
  941. +   public static boolean TVT_EVENT_TARGET_TEAM_MEMBERS_ALLOWED;
  942. +   public static boolean TVT_EVENT_POTIONS_ALLOWED;
  943. +   public static boolean TVT_EVENT_SUMMON_BY_ITEM_ALLOWED;
  944. +   public static List<Integer> TVT_EVENT_DOOR_IDS = new ArrayList<>();
  945. +   public static byte TVT_EVENT_MIN_LVL;
  946. +   public static byte TVT_EVENT_MAX_LVL;
  947. +   public static boolean TVT_EVENT_REMOVE_BUFFS;
  948. +   public static boolean TVT_EVENT_HEAL_PLAYERS;
  949. +   public static boolean TVT_KILLS_REWARD_ENABLED;
  950. +   public static List<int[]> TVT_KILLS_REWARD = new ArrayList<>();
  951. +  
  952. +   // --------------------------------------------------
  953.     // GeoEngine
  954.     // --------------------------------------------------
  955.    
  956. @@ -843,6 +871,142 @@
  957.             ALT_FISH_CHAMPIONSHIP_REWARD_4 = events.getProperty("AltFishChampionshipReward4", 200000);
  958.             ALT_FISH_CHAMPIONSHIP_REWARD_5 = events.getProperty("AltFishChampionshipReward5", 100000);
  959.            
  960. +           TVT_EVENT_ENABLED = events.getProperty("TvTEventEnabled", false);
  961. +           TVT_EVENT_INTERVAL = events.getProperty("TvTEventInterval", 18000);
  962. +           TVT_EVENT_PARTICIPATION_TIME = events.getProperty("TvTEventParticipationTime", 3600);
  963. +           TVT_EVENT_RUNNING_TIME = events.getProperty("TvTEventRunningTime", 1800);
  964. +           TVT_EVENT_PARTICIPATION_NPC_ID = events.getProperty("TvTEventParticipationNpcId", 0);
  965. +           TVT_EVENT_REMOVE_BUFFS = events.getProperty("TvTEventRemoveBuffs", false);
  966. +           TVT_KILLS_REWARD_ENABLED = events.getProperty("TvTKillsRewardEnable", false);
  967. +           TVT_EVENT_HEAL_PLAYERS = events.getProperty("TvTHealPlayersEnable", false);
  968. +          
  969. +           if (TVT_EVENT_PARTICIPATION_NPC_ID == 0)
  970. +           {
  971. +               TVT_EVENT_ENABLED = false;
  972. +               System.out.println("TvTEventEngine[Config.load()]: invalid config property -> TvTEventParticipationNpcId");
  973. +           }
  974. +           else
  975. +           {
  976. +               String[] propertySplit = events.getProperty("TvTEventParticipationNpcCoordinates", "0,0,0").split(",");
  977. +              
  978. +               if (propertySplit.length < 3)
  979. +               {
  980. +                   TVT_EVENT_ENABLED = false;
  981. +                   System.out.println("TvTEventEngine[Config.load()]: invalid config property -> TvTEventParticipationNpcCoordinates");
  982. +               }
  983. +               else
  984. +               {
  985. +                   TVT_EVENT_BACK_COORDINATES[0] = Integer.parseInt(propertySplit[0]);
  986. +                   TVT_EVENT_BACK_COORDINATES[1] = Integer.parseInt(propertySplit[1]);
  987. +                   TVT_EVENT_BACK_COORDINATES[2] = Integer.parseInt(propertySplit[2]);
  988. +                  
  989. +                   TVT_EVENT_MIN_PLAYERS_IN_TEAMS = Integer.parseInt(events.getProperty("TvTEventMinPlayersInTeams", "1"));
  990. +                   TVT_EVENT_MAX_PLAYERS_IN_TEAMS = Integer.parseInt(events.getProperty("TvTEventMaxPlayersInTeams", "20"));
  991. +                   TVT_EVENT_MIN_LVL = (byte) Integer.parseInt(events.getProperty("TvTEventMinPlayerLevel", "1"));
  992. +                   TVT_EVENT_MAX_LVL = (byte) Integer.parseInt(events.getProperty("TvTEventMaxPlayerLevel", "80"));
  993. +                   TVT_EVENT_RESPAWN_TELEPORT_DELAY = Integer.parseInt(events.getProperty("TvTEventRespawnTeleportDelay", "20"));
  994. +                   TVT_EVENT_START_LEAVE_TELEPORT_DELAY = Integer.parseInt(events.getProperty("TvTEventStartLeaveTeleportDelay", "20"));
  995. +                  
  996. +                   TVT_EVENT_TEAM_1_NAME = events.getProperty("TvTEventTeam1Name", "Team1");
  997. +                   propertySplit = events.getProperty("TvTEventTeam1Coordinates", "0,0,0").split(",");
  998. +                  
  999. +                   if (propertySplit.length < 3)
  1000. +                   {
  1001. +                       TVT_EVENT_ENABLED = false;
  1002. +                       System.out.println("TvTEventEngine[Config.load()]: invalid config property -> TvTEventTeam1Coordinates");
  1003. +                   }
  1004. +                   else
  1005. +                   {
  1006. +                       TVT_EVENT_TEAM_1_COORDINATES[0] = Integer.parseInt(propertySplit[0]);
  1007. +                       TVT_EVENT_TEAM_1_COORDINATES[1] = Integer.parseInt(propertySplit[1]);
  1008. +                       TVT_EVENT_TEAM_1_COORDINATES[2] = Integer.parseInt(propertySplit[2]);
  1009. +                      
  1010. +                       TVT_EVENT_TEAM_2_NAME = events.getProperty("TvTEventTeam2Name", "Team2");
  1011. +                       propertySplit = events.getProperty("TvTEventTeam2Coordinates", "0,0,0").split(",");
  1012. +                      
  1013. +                       if (propertySplit.length < 3)
  1014. +                       {
  1015. +                           TVT_EVENT_ENABLED = false;
  1016. +                           System.out.println("TvTEventEngine[Config.load()]: invalid config property -> TvTEventTeam2Coordinates");
  1017. +                       }
  1018. +                       else
  1019. +                       {
  1020. +                           TVT_EVENT_TEAM_2_COORDINATES[0] = Integer.parseInt(propertySplit[0]);
  1021. +                           TVT_EVENT_TEAM_2_COORDINATES[1] = Integer.parseInt(propertySplit[1]);
  1022. +                           TVT_EVENT_TEAM_2_COORDINATES[2] = Integer.parseInt(propertySplit[2]);
  1023. +                           propertySplit = events.getProperty("TvTEventReward", "57,100000").split(";");
  1024. +                          
  1025. +                           for (String reward : propertySplit)
  1026. +                           {
  1027. +                               String[] rewardSplit = reward.split(",");
  1028. +                              
  1029. +                               if (rewardSplit.length != 2)
  1030. +                                   System.out.println("TvTEventEngine[Config.load()]: invalid config property -> TvTEventReward \"" + reward + "\"");
  1031. +                               else
  1032. +                               {
  1033. +                                   try
  1034. +                                   {
  1035. +                                       TVT_EVENT_REWARDS.add(new int[]
  1036. +                                       {
  1037. +                                           Integer.valueOf(rewardSplit[0]),
  1038. +                                           Integer.valueOf(rewardSplit[1])
  1039. +                                       });
  1040. +                                   }
  1041. +                                   catch (NumberFormatException nfe)
  1042. +                                   {
  1043. +                                       if (!reward.equals(""))
  1044. +                                           System.out.println("TvTEventEngine[Config.load()]: invalid config property -> TvTEventReward \"" + reward + "\"");
  1045. +                                   }
  1046. +                               }
  1047. +                           }
  1048. +                          
  1049. +                           propertySplit = events.getProperty("TvTKillsReward", "57,100000").split(";");
  1050. +                          
  1051. +                           for (String rewardKills : propertySplit)
  1052. +                           {
  1053. +                               String[] rewardSplit = rewardKills.split(",");
  1054. +                              
  1055. +                               if (rewardSplit.length != 2)
  1056. +                                   System.out.println("TvTEventEngine[Config.load()]: invalid config property -> TvTEventReward \"" + rewardKills + "\"");
  1057. +                               else
  1058. +                               {
  1059. +                                   try
  1060. +                                   {
  1061. +                                       TVT_KILLS_REWARD.add(new int[]
  1062. +                                       {
  1063. +                                           Integer.valueOf(rewardSplit[0]),
  1064. +                                           Integer.valueOf(rewardSplit[1])
  1065. +                                       });
  1066. +                                   }
  1067. +                                   catch (NumberFormatException nfe)
  1068. +                                   {
  1069. +                                       if (!rewardKills.equals(""))
  1070. +                                           System.out.println("TvTEventEngine[Config.load()]: invalid config property -> TvTEventReward \"" + rewardKills + "\"");
  1071. +                                   }
  1072. +                               }
  1073. +                           }
  1074. +                          
  1075. +                           TVT_EVENT_TARGET_TEAM_MEMBERS_ALLOWED = Boolean.parseBoolean(events.getProperty("TvTEventTargetTeamMembersAllowed", "true"));
  1076. +                           TVT_EVENT_POTIONS_ALLOWED = Boolean.parseBoolean(events.getProperty("TvTEventPotionsAllowed", "false"));
  1077. +                           TVT_EVENT_SUMMON_BY_ITEM_ALLOWED = Boolean.parseBoolean(events.getProperty("TvTEventSummonByItemAllowed", "false"));
  1078. +                           propertySplit = events.getProperty("TvTEventDoorsCloseOpenOnStartEnd", "").split(";");
  1079. +                          
  1080. +                           for (String door : propertySplit)
  1081. +                           {
  1082. +                               try
  1083. +                               {
  1084. +                                   TVT_EVENT_DOOR_IDS.add(Integer.valueOf(door));
  1085. +                               }
  1086. +                               catch (NumberFormatException nfe)
  1087. +                               {
  1088. +                                   if (!door.equals(""))
  1089. +                                       System.out.println("TvTEventEngine[Config.load()]: invalid config property -> TvTEventDoorsCloseOpenOnStartEnd \"" + door + "\"");
  1090. +                               }
  1091. +                           }
  1092. +                       }
  1093. +                   }
  1094. +               }
  1095. +           }
  1096. +          
  1097.             // Geoengine
  1098.             ExProperties geoengine = load(GEOENGINE_FILE);
  1099.             GEODATA = geoengine.getProperty("GeoData", 0);     
  1100. Index: java/net/sf/l2j/gameserver/GameServer.java
  1101. ===================================================================
  1102. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 5)
  1103. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  1104. @@ -67,6 +67,7 @@
  1105.  import net.sf.l2j.gameserver.datatables.StaticObjects;
  1106.  import net.sf.l2j.gameserver.datatables.SummonItemsData;
  1107.  import net.sf.l2j.gameserver.datatables.TeleportLocationTable;
  1108. +import net.sf.l2j.gameserver.events.TvTEventManager;
  1109.  import net.sf.l2j.gameserver.geoengine.GeoData;
  1110.  import net.sf.l2j.gameserver.geoengine.PathFinding;
  1111.  import net.sf.l2j.gameserver.handler.AdminCommandHandler;
  1112. @@ -74,6 +75,7 @@
  1113.  import net.sf.l2j.gameserver.handler.ItemHandler;
  1114.  import net.sf.l2j.gameserver.handler.SkillHandler;
  1115.  import net.sf.l2j.gameserver.handler.UserCommandHandler;
  1116. +import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
  1117.  import net.sf.l2j.gameserver.idfactory.IdFactory;
  1118.  import net.sf.l2j.gameserver.instancemanager.AuctionManager;
  1119.  import net.sf.l2j.gameserver.instancemanager.AutoSpawnManager;
  1120. @@ -295,6 +297,7 @@
  1121.         _log.config("ItemHandler: Loaded " + ItemHandler.getInstance().size() + " handlers.");
  1122.         _log.config("SkillHandler: Loaded " + SkillHandler.getInstance().size() + " handlers.");
  1123.         _log.config("UserCommandHandler: Loaded " + UserCommandHandler.getInstance().size() + " handlers.");
  1124. +       _log.config("VoicedCommandHandler: Loaded " + VoicedCommandHandler.getInstance().size() + " handlers.");
  1125.        
  1126.         if (Config.ALLOW_WEDDING)
  1127.             CoupleManager.getInstance();
  1128. @@ -302,6 +305,9 @@
  1129.         if (Config.ALT_FISH_CHAMPIONSHIP_ENABLED)
  1130.             FishingChampionshipManager.getInstance();
  1131.        
  1132. +        StringUtil.printSection("TvT Event");
  1133. +        TvTEventManager.getInstance();
  1134. +        
  1135.         StringUtil.printSection("System");
  1136.         TaskManager.getInstance();
  1137.         Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
  1138. Index: java/net/sf/l2j/gameserver/handler/skillhandlers/Heal.java
  1139. ===================================================================
  1140. --- java/net/sf/l2j/gameserver/handler/skillhandlers/Heal.java  (revision 5)
  1141. +++ java/net/sf/l2j/gameserver/handler/skillhandlers/Heal.java  (working copy)
  1142. @@ -14,6 +14,7 @@
  1143.   */
  1144.  package net.sf.l2j.gameserver.handler.skillhandlers;
  1145.  
  1146. +import net.sf.l2j.Config;
  1147.  import net.sf.l2j.gameserver.handler.ISkillHandler;
  1148.  import net.sf.l2j.gameserver.handler.SkillHandler;
  1149.  import net.sf.l2j.gameserver.model.L2Object;
  1150. @@ -111,6 +112,8 @@
  1151.                     continue;
  1152.                 else if (activeChar instanceof L2PcInstance && ((L2PcInstance) activeChar).isCursedWeaponEquipped())
  1153.                     continue;
  1154. +               else if (((L2PcInstance) activeChar).isInFunEvent() && !Config.TVT_EVENT_HEAL_PLAYERS)
  1155. +                   continue;
  1156.             }
  1157.            
  1158.             switch (skill.getSkillType())
  1159. Index: java/net/sf/l2j/gameserver/handler/skillhandlers/HealPercent.java
  1160. ===================================================================
  1161. --- java/net/sf/l2j/gameserver/handler/skillhandlers/HealPercent.java   (revision 5)
  1162. +++ java/net/sf/l2j/gameserver/handler/skillhandlers/HealPercent.java   (working copy)
  1163. @@ -14,6 +14,7 @@
  1164.   */
  1165.  package net.sf.l2j.gameserver.handler.skillhandlers;
  1166.  
  1167. +import net.sf.l2j.Config;
  1168.  import net.sf.l2j.gameserver.handler.ISkillHandler;
  1169.  import net.sf.l2j.gameserver.handler.SkillHandler;
  1170.  import net.sf.l2j.gameserver.model.L2Object;
  1171. @@ -82,6 +83,20 @@
  1172.             if (target instanceof L2DoorInstance || target instanceof L2SiegeFlagInstance)
  1173.                 continue;
  1174.            
  1175. +           // Mana potions can't be used on event
  1176. +           if (((L2PcInstance) activeChar).isInFunEvent() && !Config.TVT_EVENT_POTIONS_ALLOWED)
  1177. +           {
  1178. +               if (skill.getSkillType() == L2SkillType.MANAHEAL_PERCENT)
  1179. +                   continue;
  1180. +           }
  1181. +          
  1182. +           // Players can't be healed on event
  1183. +           if (((L2PcInstance) activeChar).isInFunEvent() && !Config.TVT_EVENT_HEAL_PLAYERS)
  1184. +           {
  1185. +               if (skill.getSkillType() == L2SkillType.HEAL_PERCENT)
  1186. +                   continue;
  1187. +           }
  1188. +          
  1189.             targetPlayer = target instanceof L2PcInstance;
  1190.            
  1191.             // Cursed weapon owner can't heal or be healed
  1192. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2TvTEventNpcInstance.java
  1193. ===================================================================
  1194. --- java/net/sf/l2j/gameserver/model/actor/instance/L2TvTEventNpcInstance.java  (revision 0)
  1195. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2TvTEventNpcInstance.java  (working copy)
  1196. @@ -0,0 +1,81 @@
  1197. +package net.sf.l2j.gameserver.model.actor.instance;
  1198. +
  1199. +import net.sf.l2j.Config;
  1200. +import net.sf.l2j.gameserver.cache.HtmCache;
  1201. +import net.sf.l2j.gameserver.events.TvTEvent;
  1202. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  1203. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  1204. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  1205. +
  1206. +public class L2TvTEventNpcInstance extends L2NpcInstance
  1207. +{
  1208. +   public L2TvTEventNpcInstance(int objectId, NpcTemplate template)
  1209. +   {
  1210. +       super(objectId, template);
  1211. +   }
  1212. +  
  1213. +   @Override
  1214. +   public void onBypassFeedback(L2PcInstance playerInstance, String command)
  1215. +   {
  1216. +       TvTEvent.onBypass(command, playerInstance);
  1217. +   }
  1218. +  
  1219. +   @Override
  1220. +   public void showChatWindow(L2PcInstance playerInstance, int val)
  1221. +   {
  1222. +       if (playerInstance == null)
  1223. +           return;
  1224. +      
  1225. +       if (TvTEvent.isParticipating())
  1226. +       {
  1227. +           String htmFile = "data/html/mods/";
  1228. +          
  1229. +           if (!TvTEvent.isPlayerParticipant(playerInstance.getName()))
  1230. +               htmFile += "TvTEventParticipation";
  1231. +           else
  1232. +               htmFile += "TvTEventRemoveParticipation";
  1233. +          
  1234. +           htmFile += ".htm";
  1235. +          
  1236. +           String htmContent = HtmCache.getInstance().getHtm(htmFile);
  1237. +          
  1238. +           if (htmContent != null)
  1239. +           {
  1240. +               int[] teamsPlayerCounts = TvTEvent.getTeamsPlayerCounts();
  1241. +               NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(getObjectId());
  1242. +              
  1243. +               npcHtmlMessage.setHtml(htmContent);
  1244. +               npcHtmlMessage.replace("%objectId%", String.valueOf(getObjectId()));
  1245. +               npcHtmlMessage.replace("%team1name%", Config.TVT_EVENT_TEAM_1_NAME);
  1246. +               npcHtmlMessage.replace("%team1playercount%", String.valueOf(teamsPlayerCounts[0]));
  1247. +               npcHtmlMessage.replace("%team2name%", Config.TVT_EVENT_TEAM_2_NAME);
  1248. +               npcHtmlMessage.replace("%team2playercount%", String.valueOf(teamsPlayerCounts[1]));
  1249. +               playerInstance.sendPacket(npcHtmlMessage);
  1250. +           }
  1251. +       }
  1252. +       else if (TvTEvent.isStarting() || TvTEvent.isStarted())
  1253. +       {
  1254. +           String htmFile = "data/html/mods/TvTEventStatus.htm";
  1255. +           String htmContent = HtmCache.getInstance().getHtm(htmFile);
  1256. +          
  1257. +           if (htmContent != null)
  1258. +           {
  1259. +               int[] teamsPlayerCounts = TvTEvent.getTeamsPlayerCounts();
  1260. +               int[] teamsPointsCounts = TvTEvent.getTeamsPoints();
  1261. +               NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(getObjectId());
  1262. +              
  1263. +               npcHtmlMessage.setHtml(htmContent);
  1264. +               // npcHtmlMessage.replace("%objectId%", String.valueOf(getObjectId()));
  1265. +               npcHtmlMessage.replace("%team1name%", Config.TVT_EVENT_TEAM_1_NAME);
  1266. +               npcHtmlMessage.replace("%team1playercount%", String.valueOf(teamsPlayerCounts[0]));
  1267. +               npcHtmlMessage.replace("%team1points%", String.valueOf(teamsPointsCounts[0]));
  1268. +               npcHtmlMessage.replace("%team2name%", Config.TVT_EVENT_TEAM_2_NAME);
  1269. +               npcHtmlMessage.replace("%team2playercount%", String.valueOf(teamsPlayerCounts[1]));
  1270. +               npcHtmlMessage.replace("%team2points%", String.valueOf(teamsPointsCounts[1])); // <---- array index from 0 to 1 thx DaRkRaGe
  1271. +               playerInstance.sendPacket(npcHtmlMessage);
  1272. +           }
  1273. +       }
  1274. +      
  1275. +       playerInstance.sendPacket(ActionFailed.STATIC_PACKET);
  1276. +   }
  1277. +}
  1278. \ No newline at end of file
  1279. Index: java/net/sf/l2j/gameserver/network/clientpackets/Logout.java
  1280. ===================================================================
  1281. --- java/net/sf/l2j/gameserver/network/clientpackets/Logout.java    (revision 5)
  1282. +++ java/net/sf/l2j/gameserver/network/clientpackets/Logout.java    (working copy)
  1283. @@ -14,6 +14,7 @@
  1284.   */
  1285.  package net.sf.l2j.gameserver.network.clientpackets;
  1286.  
  1287. +import net.sf.l2j.gameserver.events.TvTEvent;
  1288.  import net.sf.l2j.gameserver.instancemanager.SevenSignsFestival;
  1289.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1290.  import net.sf.l2j.gameserver.model.zone.ZoneId;
  1291. @@ -42,6 +43,12 @@
  1292.             return;
  1293.         }
  1294.        
  1295. +       if (!TvTEvent.isInactive() && TvTEvent.isPlayerParticipant(player.getName()))
  1296. +       {
  1297. +           player.sendMessage("You can not leave the game while attending an event.");
  1298. +           return;
  1299. +       }
  1300. +      
  1301.         if (player.isInsideZone(ZoneId.NO_RESTART))
  1302.         {
  1303.             player.sendPacket(SystemMessageId.NO_LOGOUT_HERE);
  1304. Index: java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java
  1305. ===================================================================
  1306. --- java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java  (revision 5)
  1307. +++ java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java  (working copy)
  1308. @@ -31,7 +31,7 @@
  1309.     @Override
  1310.     public boolean useUserCommand(int id, L2PcInstance activeChar)
  1311.     {
  1312. -       if (activeChar.isCastingNow() || activeChar.isSitting() || activeChar.isMovementDisabled() || activeChar.isOutOfControl() || activeChar.isInOlympiadMode() || activeChar.inObserverMode() || activeChar.isFestivalParticipant() || activeChar.isInJail() || GrandBossManager.getInstance().isInBossZone(activeChar))
  1313. +       if (activeChar.isCastingNow() || activeChar.isSitting() || activeChar.isMovementDisabled() || activeChar.isOutOfControl() || activeChar.isInOlympiadMode() || activeChar.inObserverMode() || activeChar.isFestivalParticipant() || activeChar.isInJail() || GrandBossManager.getInstance().isInBossZone(activeChar) || activeChar.isInFunEvent())
  1314.         {
  1315.             activeChar.sendMessage("Your current state doesn't allow you to use the /unstuck command.");
  1316.             return false;
  1317. Index: java/net/sf/l2j/gameserver/events/TvTEvent.java
  1318. ===================================================================
  1319. --- java/net/sf/l2j/gameserver/events/TvTEvent.java (revision 0)
  1320. +++ java/net/sf/l2j/gameserver/events/TvTEvent.java (working copy)
  1321. @@ -0,0 +1,792 @@
  1322. +/*
  1323. +  This program is free software: you can redistribute it and/or modify it under
  1324. + * the terms of the GNU General Public License as published by the Free Software
  1325. + * Foundation, either version 3 of the License, or (at your option) any later
  1326. + * version.
  1327. + *
  1328. + * This program is distributed in the hope that it will be useful, but WITHOUT
  1329. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1330. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1331. + * details.
  1332. + *
  1333. + * You should have received a copy of the GNU General Public License along with
  1334. + * this program. If not, see <http://www.gnu.org/licenses/>.
  1335. + */
  1336. +package net.sf.l2j.gameserver.events;
  1337. +
  1338. +import net.sf.l2j.Config;
  1339. +import net.sf.l2j.commons.random.Rnd;
  1340. +import net.sf.l2j.gameserver.datatables.DoorTable;
  1341. +import net.sf.l2j.gameserver.datatables.ItemTable;
  1342. +import net.sf.l2j.gameserver.datatables.NpcTable;
  1343. +import net.sf.l2j.gameserver.datatables.SkillTable;
  1344. +import net.sf.l2j.gameserver.datatables.SpawnTable;
  1345. +import net.sf.l2j.gameserver.model.L2Skill;
  1346. +import net.sf.l2j.gameserver.model.L2Spawn;
  1347. +import net.sf.l2j.gameserver.model.L2World;
  1348. +import net.sf.l2j.gameserver.model.actor.L2Character;
  1349. +import net.sf.l2j.gameserver.model.actor.L2Summon;
  1350. +import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  1351. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  1352. +import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  1353. +import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
  1354. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  1355. +import net.sf.l2j.gameserver.model.itemcontainer.PcInventory;
  1356. +import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
  1357. +import net.sf.l2j.gameserver.network.SystemMessageId;
  1358. +import net.sf.l2j.gameserver.network.clientpackets.Say2;
  1359. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  1360. +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  1361. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  1362. +import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  1363. +import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  1364. +import net.sf.l2j.gameserver.util.Broadcast;
  1365. +
  1366. +/**
  1367. + * @author Baggos
  1368. + */
  1369. +public class TvTEvent
  1370. +{
  1371. +   enum EventState
  1372. +   {
  1373. +       INACTIVE,
  1374. +       INACTIVATING,
  1375. +       PARTICIPATING,
  1376. +       STARTING,
  1377. +       STARTED,
  1378. +       REWARDING
  1379. +   }
  1380. +  
  1381. +   /** Gives Noblesse to players */
  1382. +   static L2Skill noblesse = SkillTable.getInstance().getInfo(1323, 1);
  1383. +   /**
  1384. +    * The teams of the TvTEvent<br>
  1385. +    */
  1386. +   public static TvTEventTeams[] _teams = new TvTEventTeams[2]; // event only allow max 2 teams
  1387. +   private static L2Spawn _npcSpawn = null;
  1388. +   /**
  1389. +    * The state of the TvTEvent<br>
  1390. +    */
  1391. +   public static EventState _state = EventState.INACTIVE;
  1392. +  
  1393. +   /**
  1394. +    * No instance of this class!<br>
  1395. +    */
  1396. +   private TvTEvent()
  1397. +   {
  1398. +   }
  1399. +  
  1400. +   /**
  1401. +    * Teams initializing<br>
  1402. +    */
  1403. +   public static void init()
  1404. +   {
  1405. +       _teams[0] = new TvTEventTeams(Config.TVT_EVENT_TEAM_1_NAME, Config.TVT_EVENT_TEAM_1_COORDINATES);
  1406. +       _teams[1] = new TvTEventTeams(Config.TVT_EVENT_TEAM_2_NAME, Config.TVT_EVENT_TEAM_2_COORDINATES);
  1407. +   }
  1408. +  
  1409. +   /**
  1410. +    * Starts the participation of the TvTEvent<br>
  1411. +    * 1. Get NpcTemplate by Config.TVT_EVENT_PARTICIPATION_NPC_ID<br>
  1412. +    * 2. Try to spawn a new npc of it<br>
  1413. +    * <br>
  1414. +    * @return boolean<br>
  1415. +    */
  1416. +   public static boolean startParticipation()
  1417. +   {
  1418. +       NpcTemplate tmpl = NpcTable.getInstance().getTemplate(Config.TVT_EVENT_PARTICIPATION_NPC_ID);
  1419. +      
  1420. +       if (tmpl == null)
  1421. +       {
  1422. +           System.out.println("TvTEventEngine[TvTEvent.startParticipation()]: L2NpcTemplate is a NullPointer -> Invalid npc id in configs?");
  1423. +           return false;
  1424. +       }
  1425. +      
  1426. +       try
  1427. +       {
  1428. +           _npcSpawn = new L2Spawn(tmpl);
  1429. +          
  1430. +           _npcSpawn.setLocx(Config.TVT_EVENT_BACK_COORDINATES[0]);
  1431. +           _npcSpawn.setLocy(Config.TVT_EVENT_BACK_COORDINATES[1]);
  1432. +           _npcSpawn.setLocz(Config.TVT_EVENT_BACK_COORDINATES[2]);
  1433. +           _npcSpawn.getAmount();
  1434. +           _npcSpawn.getHeading();
  1435. +           _npcSpawn.setRespawnDelay(1);
  1436. +          
  1437. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  1438. +          
  1439. +           _npcSpawn.init();
  1440. +           _npcSpawn.getLastSpawn().isAggressive();
  1441. +           _npcSpawn.getLastSpawn().decayMe();
  1442. +           _npcSpawn.getLastSpawn().spawnMe(_npcSpawn.getLastSpawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ());
  1443. +          
  1444. +           _npcSpawn.getLastSpawn().broadcastPacket(new MagicSkillUse(_npcSpawn.getLastSpawn(), _npcSpawn.getLastSpawn(), 1034, 1, 1, 1));
  1445. +       }
  1446. +       catch (Exception e)
  1447. +       {
  1448. +           System.out.println("TvTEventEngine[TvTEvent.startParticipation()]: exception: " + e);
  1449. +           return false;
  1450. +       }
  1451. +      
  1452. +       setState(EventState.PARTICIPATING);
  1453. +       return true;
  1454. +   }
  1455. +  
  1456. +   /**
  1457. +    * Unspawn event npc.
  1458. +    */
  1459. +   public static void unspawnEventNpc()
  1460. +   {
  1461. +       if (_npcSpawn == null || _npcSpawn.getLastSpawn() == null)
  1462. +           return;
  1463. +      
  1464. +       _npcSpawn.getLastSpawn().deleteMe();
  1465. +       _npcSpawn.stopRespawn();
  1466. +       SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
  1467. +   }
  1468. +  
  1469. +   /**
  1470. +    * Starts the TvTEvent fight<br>
  1471. +    * 1. Set state EventState.STARTING<br>
  1472. +    * 2. Close doors specified in configs<br>
  1473. +    * 3. Abort if not enought participants(return false)<br>
  1474. +    * 4. Set state EventState.STARTED<br>
  1475. +    * 5. Teleport all participants to team spot<br>
  1476. +    * <br>
  1477. +    * @return boolean<br>
  1478. +    */
  1479. +   public static boolean startFight()
  1480. +   {
  1481. +       setState(EventState.STARTING);
  1482. +      
  1483. +       // not enought participants
  1484. +       if (_teams[0].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS || _teams[1].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS)
  1485. +       {
  1486. +           setState(EventState.INACTIVE);
  1487. +           unspawnEventNpc();
  1488. +           _teams[0].cleanMe();
  1489. +           _teams[1].cleanMe();
  1490. +           return false;
  1491. +       }
  1492. +      
  1493. +       closeDoors();
  1494. +       setState(EventState.STARTED); // set state to STARTED here, so TvTEventTeleporter know to teleport to team spot
  1495. +      
  1496. +       // teleport all participants to there team spot
  1497. +       for (TvTEventTeams team : _teams)
  1498. +       {
  1499. +           for (String playerName : team.getParticipatedPlayerNames())
  1500. +           {
  1501. +               L2PcInstance playerInstance = team.getParticipatedPlayers().get(playerName);
  1502. +              
  1503. +               if (playerInstance == null)
  1504. +                   continue;
  1505. +              
  1506. +               // leave party
  1507. +               playerInstance.leaveParty();
  1508. +              
  1509. +               // Get Noblesse effect
  1510. +               noblesse.getEffects(playerInstance, playerInstance);
  1511. +              
  1512. +               // implements Runnable and starts itself in constructor
  1513. +               new TvTEventTeleport(playerInstance, team.getCoordinates(), false, false);
  1514. +           }
  1515. +       }
  1516. +      
  1517. +       return true;
  1518. +   }
  1519. +  
  1520. +   /**
  1521. +    * Calculates the TvTEvent reward<br>
  1522. +    * 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>
  1523. +    * 2. Wait till teams are not at a tie anymore<br>
  1524. +    * 3. Set state EvcentState.REWARDING<br>
  1525. +    * 4. Reward team with more points<br>
  1526. +    * 5. Show win html to wining team participants<br>
  1527. +    * <br>
  1528. +    * @return String<br>
  1529. +    */
  1530. +   public static String calculateRewards()
  1531. +   {
  1532. +       if (_teams[0].getPoints() == _teams[1].getPoints())
  1533. +       {
  1534. +           if (_teams[0].getParticipatedPlayerCount() == 0 || _teams[1].getParticipatedPlayerCount() == 0)
  1535. +           {
  1536. +               // the fight cannot be completed
  1537. +               setState(EventState.REWARDING);
  1538. +               return "TvT Event: Event finish. No team won, cause of inactivity!";
  1539. +           }
  1540. +          
  1541. +           sysMsgToAllParticipants("TvT Event: Both teams are at a tie, next team to get a kill wins!");
  1542. +       }
  1543. +      
  1544. +       while (_teams[0].getPoints() == _teams[1].getPoints())
  1545. +       {
  1546. +           waiter(1);
  1547. +       }
  1548. +      
  1549. +       setState(EventState.REWARDING); // after state REWARDING is set, nobody can point anymore
  1550. +      
  1551. +       byte teamId = (byte) (_teams[0].getPoints() > _teams[1].getPoints() ? 0 : 1); // which team wins?
  1552. +       TvTEventTeams team = _teams[teamId];
  1553. +      
  1554. +       for (String playerName : team.getParticipatedPlayerNames())
  1555. +       {
  1556. +           for (int[] reward : Config.TVT_EVENT_REWARDS)
  1557. +           {
  1558. +               if (team.getParticipatedPlayers().get(playerName) == null)
  1559. +                   continue;
  1560. +              
  1561. +               PcInventory inv = team.getParticipatedPlayers().get(playerName).getInventory();
  1562. +              
  1563. +               if (ItemTable.getInstance().createDummyItem(reward[0]).isStackable())
  1564. +                   inv.addItem("TvT Event", reward[0], reward[1], team.getParticipatedPlayers().get(playerName), team.getParticipatedPlayers().get(playerName));
  1565. +               else
  1566. +               {
  1567. +                   for (int i = 0; i < reward[1]; i++)
  1568. +                       inv.addItem("TvT Event", reward[0], 1, team.getParticipatedPlayers().get(playerName), team.getParticipatedPlayers().get(playerName));
  1569. +               }
  1570. +              
  1571. +               SystemMessage systemMessage = null;
  1572. +              
  1573. +               if (reward[1] > 1)
  1574. +               {
  1575. +                   systemMessage = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  1576. +                   systemMessage.addItemName(reward[0]);
  1577. +                   systemMessage.addNumber(reward[1]);
  1578. +               }
  1579. +               else
  1580. +               {
  1581. +                   systemMessage = new SystemMessage(SystemMessageId.EARNED_ITEM_S1);
  1582. +                   systemMessage.addItemName(reward[0]);
  1583. +               }
  1584. +              
  1585. +               team.getParticipatedPlayers().get(playerName).sendPacket(systemMessage);
  1586. +           }
  1587. +          
  1588. +           StatusUpdate statusUpdate = new StatusUpdate(team.getParticipatedPlayers().get(playerName));
  1589. +          
  1590. +           statusUpdate.addAttribute(StatusUpdate.CUR_LOAD, team.getParticipatedPlayers().get(playerName).getCurrentLoad());
  1591. +           team.getParticipatedPlayers().get(playerName).sendPacket(statusUpdate);
  1592. +          
  1593. +           NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  1594. +          
  1595. +           npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Your team won the event. Look in your inventory, there should be your reward.</body></html>");
  1596. +           team.getParticipatedPlayers().get(playerName).sendPacket(npcHtmlMessage);
  1597. +       }
  1598. +      
  1599. +       return "TvT Event: Event finish. Team " + team.getName() + " won with " + team.getPoints() + " kills.";
  1600. +   }
  1601. +  
  1602. +   /**
  1603. +    * Stops the TvTEvent fight<br>
  1604. +    * 1. Set state EventState.INACTIVATING<br>
  1605. +    * 2. Remove tvt npc from world<br>
  1606. +    * 3. Open doors specified in configs<br>
  1607. +    * 4. Teleport all participants back to participation npc location<br>
  1608. +    * 5. Teams cleaning<br>
  1609. +    * 6. Set state EventState.INACTIVE<br>
  1610. +    */
  1611. +   public static void stopFight()
  1612. +   {
  1613. +       setState(EventState.INACTIVATING);
  1614. +       openDoors();
  1615. +       unspawnEventNpc();
  1616. +      
  1617. +       for (TvTEventTeams team : _teams)
  1618. +       {
  1619. +           for (String playerName : team.getParticipatedPlayerNames())
  1620. +           {
  1621. +               L2PcInstance playerInstance = team.getParticipatedPlayers().get(playerName);
  1622. +              
  1623. +               if (playerInstance == null)
  1624. +                   continue;
  1625. +              
  1626. +               new TvTEventTeleport(playerInstance, Config.TVT_EVENT_BACK_COORDINATES, false, false);
  1627. +           }
  1628. +       }
  1629. +      
  1630. +       _teams[0].cleanMe();
  1631. +       _teams[1].cleanMe();
  1632. +      
  1633. +       setState(EventState.INACTIVE);
  1634. +      
  1635. +   }
  1636. +  
  1637. +   /**
  1638. +    * Adds a player to a TvTEvent team<br>
  1639. +    * 1. Calculate the id of the team in which the player should be added<br>
  1640. +    * 2. Add the player to the calculated team
  1641. +    * @param playerInstance
  1642. +    * @return boolean
  1643. +    */
  1644. +   public static synchronized boolean addParticipant(L2PcInstance playerInstance)
  1645. +   {
  1646. +       if (playerInstance == null)
  1647. +           return false;
  1648. +      
  1649. +       byte teamId = 0;
  1650. +      
  1651. +       if (_teams[0].getParticipatedPlayerCount() == _teams[1].getParticipatedPlayerCount())
  1652. +           teamId = (byte) (Rnd.get(2));
  1653. +       else
  1654. +           teamId = (byte) (_teams[0].getParticipatedPlayerCount() > _teams[1].getParticipatedPlayerCount() ? 1 : 0);
  1655. +      
  1656. +       return _teams[teamId].addPlayer(playerInstance);
  1657. +   }
  1658. +  
  1659. +   /**
  1660. +    * Removes a TvTEvent player from it's team<br>
  1661. +    * 1. Get team id of the player<br>
  1662. +    * 2. Remove player from it's team
  1663. +    * @param playerName
  1664. +    * @return boolean
  1665. +    */
  1666. +   public static boolean removeParticipant(String playerName)
  1667. +   {
  1668. +       byte teamId = getParticipantTeamId(playerName);
  1669. +      
  1670. +       if (teamId == -1)
  1671. +           return false;
  1672. +      
  1673. +       _teams[teamId].removePlayer(playerName);
  1674. +       return true;
  1675. +   }
  1676. +  
  1677. +   /**
  1678. +    * Send a SystemMessage to all participated players<br>
  1679. +    * 1. Send the message to all players of team number one<br>
  1680. +    * 2. Send the message to all players of team number two
  1681. +    * @param message
  1682. +    */
  1683. +   public static void sysMsgToAllParticipants(String message)
  1684. +   {
  1685. +       for (L2PcInstance playerInstance : _teams[0].getParticipatedPlayers().values())
  1686. +       {
  1687. +           if (playerInstance != null)
  1688. +               playerInstance.sendMessage(message);
  1689. +       }
  1690. +      
  1691. +       for (L2PcInstance playerInstance : _teams[1].getParticipatedPlayers().values())
  1692. +       {
  1693. +           if (playerInstance != null)
  1694. +               playerInstance.sendMessage(message);
  1695. +       }
  1696. +   }
  1697. +  
  1698. +   /**
  1699. +    * Close doors specified in configs
  1700. +    */
  1701. +   public static void closeDoors()
  1702. +   {
  1703. +       for (int doorId : Config.TVT_EVENT_DOOR_IDS)
  1704. +       {
  1705. +           L2DoorInstance doorInstance = DoorTable.getInstance().getDoor(doorId);
  1706. +          
  1707. +           if (doorInstance != null)
  1708. +               doorInstance.closeMe();
  1709. +       }
  1710. +   }
  1711. +  
  1712. +   /**
  1713. +    * Open doors specified in configs
  1714. +    */
  1715. +   public static void openDoors()
  1716. +   {
  1717. +       for (int doorId : Config.TVT_EVENT_DOOR_IDS)
  1718. +       {
  1719. +           L2DoorInstance doorInstance = DoorTable.getInstance().getDoor(doorId);
  1720. +          
  1721. +           if (doorInstance != null)
  1722. +               doorInstance.openMe();
  1723. +       }
  1724. +   }
  1725. +  
  1726. +   public static void waiter(int seconds)
  1727. +   {
  1728. +       try
  1729. +       {
  1730. +           Thread.sleep(seconds * 1000);
  1731. +       }
  1732. +       catch (InterruptedException e)
  1733. +       {
  1734. +           e.printStackTrace();
  1735. +       }
  1736. +   }
  1737. +  
  1738. +   /**
  1739. +    * Called when a player logs in
  1740. +    * @param playerInstance
  1741. +    * @param player
  1742. +    */
  1743. +   public static void onLogin(L2PcInstance playerInstance, L2PcInstance player)
  1744. +   {
  1745. +       if (playerInstance == null || (!isStarting() && !isStarted()))
  1746. +           return;
  1747. +      
  1748. +       byte teamId = getParticipantTeamId(playerInstance.getName());
  1749. +      
  1750. +       if (teamId == -1)
  1751. +           return;
  1752. +      
  1753. +       _teams[teamId].addPlayer(playerInstance);
  1754. +       new TvTEventTeleport(playerInstance, _teams[teamId].getCoordinates(), true, false);
  1755. +   }
  1756. +  
  1757. +   /**
  1758. +    * Called when a player logs out
  1759. +    * @param playerInstance
  1760. +    * @param player
  1761. +    */
  1762. +   public static void onLogout(L2PcInstance playerInstance, L2PcInstance player)
  1763. +   {
  1764. +       if (playerInstance == null || (!isStarting() && !isStarted()))
  1765. +           return;
  1766. +      
  1767. +       removeParticipant(playerInstance.getName());
  1768. +   }
  1769. +  
  1770. +   /**
  1771. +    * Called on every bypass by npc of type L2TvTEventNpc<br>
  1772. +    * Needs synchronization cause of the max player check
  1773. +    * @param command
  1774. +    * @param playerInstance
  1775. +    */
  1776. +   public static synchronized void onBypass(String command, L2PcInstance playerInstance)
  1777. +   {
  1778. +       if (playerInstance == null || !isParticipating())
  1779. +           return;
  1780. +      
  1781. +       if (command.equals("tvt_event_participation"))
  1782. +       {
  1783. +           NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  1784. +           int playerLevel = playerInstance.getLevel();
  1785. +          
  1786. +           if (playerInstance.isCursedWeaponEquipped())
  1787. +               npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Cursed weapon owners are not allowed to participate.</body></html>");
  1788. +           else if (OlympiadManager.getInstance().isRegisteredInComp(playerInstance))
  1789. +               npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Olympiad participants can't register.</body></html>");
  1790. +           else if (playerInstance.getKarma() > 0)
  1791. +               npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Chaotic players are not allowed to participate.</body></html>");
  1792. +           else if (_teams[0].getParticipatedPlayerCount() >= Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS && _teams[1].getParticipatedPlayerCount() >= Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS)
  1793. +               npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Sorry the event is full!</body></html>");
  1794. +           else if (playerLevel < Config.TVT_EVENT_MIN_LVL || playerLevel > Config.TVT_EVENT_MAX_LVL)
  1795. +               npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Only players from level " + Config.TVT_EVENT_MIN_LVL + " to level " + Config.TVT_EVENT_MAX_LVL + " are allowed tro participate.</body></html>");
  1796. +           else if (_teams[0].getParticipatedPlayerCount() > 19 && _teams[1].getParticipatedPlayerCount() > 19)
  1797. +               npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>The event is full! Maximum of " + Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS + "  player are allowed in one team.</body></html>");
  1798. +           else if (addParticipant(playerInstance))
  1799. +               npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>You are on the registration list now.</body></html>");
  1800. +           else // addParticipant returned false cause playerInstance == null
  1801. +               return;
  1802. +          
  1803. +           playerInstance.sendPacket(npcHtmlMessage);
  1804. +       }
  1805. +       else if (command.equals("tvt_event_remove_participation"))
  1806. +       {
  1807. +           removeParticipant(playerInstance.getName());
  1808. +          
  1809. +           NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  1810. +          
  1811. +           npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>You are not longer on the registration list.</body></html>");
  1812. +           playerInstance.sendPacket(npcHtmlMessage);
  1813. +       }
  1814. +   }
  1815. +  
  1816. +   /**
  1817. +    * Called on every onAction in L2PcIstance
  1818. +    * @param playerName
  1819. +    * @param targetPlayerName
  1820. +    * @return boolean
  1821. +    */
  1822. +   public static boolean onAction(String playerName, String targetPlayerName)
  1823. +   {
  1824. +       if (!isStarted())
  1825. +           return true;
  1826. +      
  1827. +       L2PcInstance playerInstance = L2World.getInstance().getPlayer(playerName);
  1828. +      
  1829. +       if (playerInstance == null)
  1830. +           return false;
  1831. +      
  1832. +       if (playerInstance.isGM())
  1833. +           return true;
  1834. +      
  1835. +       byte playerTeamId = getParticipantTeamId(playerName);
  1836. +       byte targetPlayerTeamId = getParticipantTeamId(targetPlayerName);
  1837. +      
  1838. +       if ((playerTeamId != -1 && targetPlayerTeamId == -1) || (playerTeamId == -1 && targetPlayerTeamId != -1))
  1839. +           return false;
  1840. +      
  1841. +       if (playerTeamId != -1 && targetPlayerTeamId != -1 && playerTeamId == targetPlayerTeamId && !Config.TVT_EVENT_TARGET_TEAM_MEMBERS_ALLOWED)
  1842. +           return false;
  1843. +      
  1844. +       return true;
  1845. +   }
  1846. +  
  1847. +   /**
  1848. +    * Called on every summon item use
  1849. +    * @param playerName
  1850. +    * @return boolean
  1851. +    */
  1852. +   public static boolean onItemSummon(String playerName)
  1853. +   {
  1854. +       if (!isStarted())
  1855. +           return true;
  1856. +      
  1857. +       if (isPlayerParticipant(playerName) && !Config.TVT_EVENT_SUMMON_BY_ITEM_ALLOWED)
  1858. +           return false;
  1859. +      
  1860. +       return true;
  1861. +   }
  1862. +  
  1863. +   /**
  1864. +    * Is called when a player is killed
  1865. +    * @param killerCharacter
  1866. +    * @param killedPlayerInstance
  1867. +    */
  1868. +   public static void onKill(L2Character killerCharacter, L2PcInstance killedPlayerInstance)
  1869. +   {
  1870. +       if (killerCharacter == null || killedPlayerInstance == null || (!(killerCharacter instanceof L2PcInstance) && !(killerCharacter instanceof L2PetInstance) && !(killerCharacter instanceof L2SummonInstance)) || !isStarted())
  1871. +           return;
  1872. +      
  1873. +       L2PcInstance killerPlayerInstance = null;
  1874. +      
  1875. +       if (killerCharacter instanceof L2PetInstance || killerCharacter instanceof L2SummonInstance)
  1876. +       {
  1877. +           killerPlayerInstance = ((L2Summon) killerCharacter).getOwner();
  1878. +          
  1879. +           if (killerPlayerInstance == null)
  1880. +               return;
  1881. +       }
  1882. +       else
  1883. +           killerPlayerInstance = (L2PcInstance) killerCharacter;
  1884. +      
  1885. +       if (Config.TVT_KILLS_REWARD_ENABLED)
  1886. +           for (int[] rewardKills : Config.TVT_KILLS_REWARD)
  1887. +           {
  1888. +               SystemMessage systemMessage = null;
  1889. +               // Count the kill
  1890. +               killerPlayerInstance._tvtkills++;
  1891. +               switch (killerPlayerInstance._tvtkills)
  1892. +               {
  1893. +                   case 5: // Reward after 5 kills without die
  1894. +                   case 8: // Reward after 8 kills without die
  1895. +                   case 12: // Reward after 12 kills without die
  1896. +                   case 15: // Reward after 15 kills without die
  1897. +                   case 20: // Reward after 20 kills without die
  1898. +                      
  1899. +                       systemMessage = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  1900. +                       systemMessage.addItemName(rewardKills[0]);
  1901. +                       systemMessage.addNumber(rewardKills[1]);
  1902. +                      
  1903. +                       Broadcast.announceToOnlinePlayers("TvT Event: Player " + killerPlayerInstance.getName() + " has " + killerPlayerInstance._tvtkills + " kills without die.", true);
  1904. +                       killerPlayerInstance.getInventory().addItem("TvT Event", rewardKills[0], rewardKills[1], killerPlayerInstance, killerPlayerInstance);
  1905. +                       killerPlayerInstance.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "Amazing", +killerPlayerInstance._tvtkills + " kills without die. You has been rewarded!"));
  1906. +                       killerPlayerInstance.sendPacket(systemMessage);
  1907. +                       break;
  1908. +               }
  1909. +           }
  1910. +      
  1911. +       String playerName = killerPlayerInstance.getName();
  1912. +       byte killerTeamId = getParticipantTeamId(playerName);
  1913. +      
  1914. +       playerName = killedPlayerInstance.getName();
  1915. +      
  1916. +       byte killedTeamId = getParticipantTeamId(playerName);
  1917. +      
  1918. +       if (killerTeamId != -1 && killedTeamId != -1 && killerTeamId != killedTeamId)
  1919. +           _teams[killerTeamId].increasePoints();
  1920. +
  1921. +       if (killedTeamId != -1)
  1922. +           new TvTEventTeleport(killedPlayerInstance, _teams[killedTeamId].getCoordinates(), false, false);
  1923. +   }
  1924. +  
  1925. +   /**
  1926. +    * Sets the TvTEvent state
  1927. +    * @param state
  1928. +    */
  1929. +   private static void setState(EventState state)
  1930. +   {
  1931. +       synchronized (_state)
  1932. +       {
  1933. +           _state = state;
  1934. +       }
  1935. +   }
  1936. +  
  1937. +   /**
  1938. +    * Is TvTEvent inactive?
  1939. +    * @return boolean
  1940. +    */
  1941. +   public static boolean isInactive()
  1942. +   {
  1943. +       boolean isInactive;
  1944. +      
  1945. +       synchronized (_state)
  1946. +       {
  1947. +           isInactive = _state == EventState.INACTIVE;
  1948. +       }
  1949. +      
  1950. +       return isInactive;
  1951. +   }
  1952. +  
  1953. +   /**
  1954. +    * Is TvTEvent in inactivating?
  1955. +    * @return boolean
  1956. +    */
  1957. +   public static boolean isInactivating()
  1958. +   {
  1959. +       boolean isInactivating;
  1960. +      
  1961. +       synchronized (_state)
  1962. +       {
  1963. +           isInactivating = _state == EventState.INACTIVATING;
  1964. +       }
  1965. +      
  1966. +       return isInactivating;
  1967. +   }
  1968. +  
  1969. +   /**
  1970. +    * Is TvTEvent in participation?
  1971. +    * @return boolean
  1972. +    */
  1973. +   public static boolean isParticipating()
  1974. +   {
  1975. +       boolean isParticipating;
  1976. +      
  1977. +       synchronized (_state)
  1978. +       {
  1979. +           isParticipating = _state == EventState.PARTICIPATING;
  1980. +       }
  1981. +      
  1982. +       return isParticipating;
  1983. +   }
  1984. +  
  1985. +   /**
  1986. +    * Is TvTEvent starting?
  1987. +    * @return boolean
  1988. +    */
  1989. +   public static boolean isStarting()
  1990. +   {
  1991. +       boolean isStarting;
  1992. +      
  1993. +       synchronized (_state)
  1994. +       {
  1995. +           isStarting = _state == EventState.STARTING;
  1996. +       }
  1997. +      
  1998. +       return isStarting;
  1999. +   }
  2000. +  
  2001. +   /**
  2002. +    * Is TvTEvent started?
  2003. +    * @return boolean
  2004. +    */
  2005. +   public static boolean isStarted()
  2006. +   {
  2007. +       boolean isStarted;
  2008. +      
  2009. +       synchronized (_state)
  2010. +       {
  2011. +           isStarted = _state == EventState.STARTED;
  2012. +       }
  2013. +      
  2014. +       return isStarted;
  2015. +   }
  2016. +  
  2017. +   /**
  2018. +    * Is TvTEvent rewarding?
  2019. +    * @return boolean
  2020. +    */
  2021. +   public static boolean isRewarding()
  2022. +   {
  2023. +       boolean isRewarding;
  2024. +      
  2025. +       synchronized (_state)
  2026. +       {
  2027. +           isRewarding = _state == EventState.REWARDING;
  2028. +       }
  2029. +      
  2030. +       return isRewarding;
  2031. +   }
  2032. +  
  2033. +   /**
  2034. +    * Returns the team id of a player, if player is not participant it returns -1
  2035. +    * @param playerName
  2036. +    * @return byte
  2037. +    */
  2038. +   public static byte getParticipantTeamId(String playerName)
  2039. +   {
  2040. +       return (byte) (_teams[0].containsPlayer(playerName) ? 0 : (_teams[1].containsPlayer(playerName) ? 1 : -1));
  2041. +   }
  2042. +  
  2043. +   /**
  2044. +    * Returns the team coordinates in which the player is in, if player is not in a team return null
  2045. +    * @param playerName
  2046. +    * @return int[]
  2047. +    */
  2048. +   public static int[] getParticipantTeamCoordinates(String playerName)
  2049. +   {
  2050. +       return _teams[0].containsPlayer(playerName) ? _teams[0].getCoordinates() : (_teams[1].containsPlayer(playerName) ? _teams[1].getCoordinates() : null);
  2051. +   }
  2052. +  
  2053. +   /**
  2054. +    * Is given player participant of the event?
  2055. +    * @param playerName
  2056. +    * @return boolean
  2057. +    */
  2058. +   public static boolean isPlayerParticipant(String playerName)
  2059. +   {
  2060. +       return _teams[0].containsPlayer(playerName) || _teams[1].containsPlayer(playerName);
  2061. +   }
  2062. +  
  2063. +   /**
  2064. +    * Returns participated player count<br>
  2065. +    * <br>
  2066. +    * @return int<br>
  2067. +    */
  2068. +   public static int getParticipatedPlayersCount()
  2069. +   {
  2070. +       return _teams[0].getParticipatedPlayerCount() + _teams[1].getParticipatedPlayerCount();
  2071. +   }
  2072. +  
  2073. +   /**
  2074. +    * Returns teams names<br>
  2075. +    * <br>
  2076. +    * @return String[]<br>
  2077. +    */
  2078. +   public static String[] getTeamNames()
  2079. +   {
  2080. +       return new String[]
  2081. +       {
  2082. +           _teams[0].getName(),
  2083. +           _teams[1].getName()
  2084. +       };
  2085. +   }
  2086. +      
  2087. +   /**
  2088. +    * Returns player count of both teams<br>
  2089. +    * <br>
  2090. +    * @return int[]<br>
  2091. +    */
  2092. +   public static int[] getTeamsPlayerCounts()
  2093. +   {
  2094. +       return new int[]
  2095. +       {
  2096. +           _teams[0].getParticipatedPlayerCount(),
  2097. +           _teams[1].getParticipatedPlayerCount()
  2098. +       };
  2099. +   }
  2100. +  
  2101. +   /**
  2102. +    * Returns points count of both teams
  2103. +    * @return int[]
  2104. +    */
  2105. +   public static int[] getTeamsPoints()
  2106. +   {
  2107. +       return new int[]
  2108. +       {
  2109. +           _teams[0].getPoints(),
  2110. +           _teams[1].getPoints()
  2111. +       };
  2112. +   }
  2113. +}
  2114. \ No newline at end of file
  2115. Index: java/net/sf/l2j/gameserver/events/TvTEventManager.java
  2116. ===================================================================
  2117. --- java/net/sf/l2j/gameserver/events/TvTEventManager.java  (revision 0)
  2118. +++ java/net/sf/l2j/gameserver/events/TvTEventManager.java  (working copy)
  2119. @@ -0,0 +1,152 @@
  2120. +/*
  2121. + * This program is free software: you can redistribute it and/or modify it under
  2122. + * the terms of the GNU General Public License as published by the Free Software
  2123. + * Foundation, either version 3 of the License, or (at your option) any later
  2124. + * version.
  2125. + *
  2126. + * This program is distributed in the hope that it will be useful, but WITHOUT
  2127. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  2128. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  2129. + * details.
  2130. + *
  2131. + * You should have received a copy of the GNU General Public License along with
  2132. + * this program. If not, see <http://www.gnu.org/licenses/>.
  2133. + */
  2134. +package net.sf.l2j.gameserver.events;
  2135. +
  2136. +import net.sf.l2j.Config;
  2137. +import net.sf.l2j.gameserver.ThreadPoolManager;
  2138. +import net.sf.l2j.gameserver.util.Broadcast;
  2139. +
  2140. +/**
  2141. + * @author FBIagent
  2142. + */
  2143. +public class TvTEventManager implements Runnable
  2144. +{
  2145. +   /**
  2146. +    * The one and only instance of this class<br>
  2147. +    */
  2148. +   private static TvTEventManager _instance = null;
  2149. +  
  2150. +   /**
  2151. +    * New instance only by getInstance()<br>
  2152. +    */
  2153. +   private TvTEventManager()
  2154. +   {
  2155. +       if (Config.TVT_EVENT_ENABLED)
  2156. +       {
  2157. +           ThreadPoolManager.getInstance().scheduleGeneral(this, 0);
  2158. +           System.out.println("TvTEventEngine[TvTManager.TvTManager()]: Started.");
  2159. +       }
  2160. +       else
  2161. +           System.out.println("TvTEventEngine[TvTManager.TvTManager()]: Engine is disabled.");
  2162. +   }
  2163. +  
  2164. +   /**
  2165. +    * Initialize new/Returns the one and only instance<br>
  2166. +    * <br>
  2167. +    * @return TvTManager<br>
  2168. +    */
  2169. +   public static TvTEventManager getInstance()
  2170. +   {
  2171. +       if (_instance == null)
  2172. +           _instance = new TvTEventManager();
  2173. +      
  2174. +       return _instance;
  2175. +   }
  2176. +  
  2177. +   /**
  2178. +    * The task method to handle cycles of the event
  2179. +    * @see java.lang.Runnable#run()
  2180. +    */
  2181. +   @Override
  2182. +   public void run()
  2183. +   {
  2184. +       TvTEvent.init();
  2185. +      
  2186. +       for (;;)
  2187. +       {
  2188. +           waiter(Config.TVT_EVENT_INTERVAL * 60); // in config given as minutes
  2189. +          
  2190. +           if (!TvTEvent.startParticipation())
  2191. +           {
  2192. +               Broadcast.announceToOnlinePlayers("TvT Event: Event was canceled.", true);
  2193. +               System.out.println("TvTEventEngine[TvTManager.run()]: Error spawning event npc for participation.");
  2194. +               continue;
  2195. +           }
  2196. +           Broadcast.announceToOnlinePlayers("TvT Event: Registration opened for " + Config.TVT_EVENT_PARTICIPATION_TIME + " minute(s). Type .tvtjoin or .tvtleave", true);
  2197. +          
  2198. +           waiter(Config.TVT_EVENT_PARTICIPATION_TIME * 60); // in config given as minutes
  2199. +          
  2200. +           if (!TvTEvent.startFight())
  2201. +           {
  2202. +               Broadcast.announceToOnlinePlayers("TvT Event: Event canceled due to lack of Participation.", true);
  2203. +               System.out.println("TvTEventEngine[TvTManager.run()]: Lack of registration, abort event.");
  2204. +               continue;
  2205. +           }
  2206. +           Broadcast.announceToOnlinePlayers("TvT Event: Registration closed!", true);
  2207. +           TvTEvent.sysMsgToAllParticipants("TvT Event: Teleporting participants to an arena in " + Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");
  2208. +          
  2209. +           waiter(Config.TVT_EVENT_RUNNING_TIME * 60); // in config given as minutes
  2210. +           Broadcast.announceToOnlinePlayers(TvTEvent.calculateRewards(), true);
  2211. +           TvTEvent.sysMsgToAllParticipants("TvT Event: Teleporting back to the registration npc in " + Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");
  2212. +           TvTEvent.stopFight();
  2213. +       }
  2214. +   }
  2215. +  
  2216. +   /**
  2217. +    * This method waits for a period time delay
  2218. +    * @param seconds
  2219. +    */
  2220. +   void waiter(int seconds)
  2221. +   {
  2222. +       while (seconds > 1)
  2223. +       {
  2224. +           seconds--; // here because we don't want to see two time announce at the same time
  2225. +          
  2226. +           if (TvTEvent.isParticipating() || TvTEvent.isStarted())
  2227. +           {
  2228. +               switch (seconds)
  2229. +               {
  2230. +                   case 3600: // 1 hour left
  2231. +                       if (TvTEvent.isParticipating())
  2232. +                           Broadcast.announceToOnlinePlayers("TvT Event: " + seconds / 60 / 60 + " hour(s) umtil registration is closed!", true);
  2233. +                       else if (TvTEvent.isStarted())
  2234. +                           TvTEvent.sysMsgToAllParticipants("TvT Event: " + seconds / 60 / 60 + " hour(s) until event is finished!");
  2235. +                      
  2236. +                       break;
  2237. +                   case 1800: // 30 minutes left
  2238. +                   case 900: // 15 minutes left
  2239. +                   case 600: // 10 minutes left
  2240. +                   case 300: // 5 minutes left
  2241. +                   case 240: // 4 minutes left
  2242. +                   case 180: // 3 minutes left
  2243. +                   case 120: // 2 minutes left
  2244. +                   case 60: // 1 minute left
  2245. +                       if (TvTEvent.isParticipating())
  2246. +                           Broadcast.announceToOnlinePlayers("TvT Event: " + seconds / 60 + " minute(s) until registration is closed!", true);
  2247. +                       else if (TvTEvent.isStarted())
  2248. +                           TvTEvent.sysMsgToAllParticipants("TvT Event: " + seconds / 60 + " minute(s) until the event is finished!");
  2249. +                      
  2250. +                       break;
  2251. +                   case 30: // 30 seconds left
  2252. +                       /**
  2253. +                        * case 15: // 15 seconds left case 10: // 10 seconds left
  2254. +                        */
  2255. +                   case 5: // 5 seconds left
  2256. +                      
  2257. +                       /**
  2258. +                        * case 4: // 4 seconds left case 3: // 3 seconds left case 2: // 2 seconds left case 1: // 1 seconds left
  2259. +                        */
  2260. +                       if (TvTEvent.isParticipating())
  2261. +                           Broadcast.announceToOnlinePlayers("TvT Event: " + seconds + " second(s) until registration is closed!", true);
  2262. +                       else if (TvTEvent.isStarted())
  2263. +                           TvTEvent.sysMsgToAllParticipants("TvT Event: " + seconds + " second(s) until the event is finished!");
  2264. +                      
  2265. +                       break;
  2266. +               }
  2267. +           }
  2268. +           TvTEvent.waiter(1);
  2269. +       }
  2270. +   }
  2271. +}
  2272. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  2273. ===================================================================
  2274. --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java   (revision 5)
  2275. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java   (working copy)
  2276. @@ -62,6 +62,7 @@
  2277.  import net.sf.l2j.gameserver.datatables.SkillTable;
  2278.  import net.sf.l2j.gameserver.datatables.SkillTable.FrequentSkill;
  2279.  import net.sf.l2j.gameserver.datatables.SkillTreeTable;
  2280. +import net.sf.l2j.gameserver.events.TvTEvent;
  2281.  import net.sf.l2j.gameserver.geoengine.PathFinding;
  2282.  import net.sf.l2j.gameserver.handler.IItemHandler;
  2283.  import net.sf.l2j.gameserver.handler.ItemHandler;
  2284. @@ -377,6 +378,7 @@
  2285.     private PcAppearance _appearance;
  2286.    
  2287.     private long _expBeforeDeath;
  2288. +   public int _tvtkills;
  2289.     private int _karma;
  2290.     private int _pvpKills;
  2291.     private int _pkKills;
  2292. @@ -388,6 +390,7 @@
  2293.    
  2294.     private boolean _isInWater;
  2295.     private boolean _isIn7sDungeon = false;
  2296. +   public boolean atEvent = false;
  2297.    
  2298.     private PunishLevel _punishLevel = PunishLevel.NONE;
  2299.     private long _punishTimer = 0;
  2300. @@ -3208,6 +3211,11 @@
  2301.     @Override
  2302.     public void onAction(L2PcInstance player)
  2303.     {
  2304. +       if (!TvTEvent.onAction(player.getName(), getName()))
  2305. +       {
  2306. +           player.sendPacket(ActionFailed.STATIC_PACKET);
  2307. +           return;
  2308. +       }
  2309.         // Set the target of the player
  2310.         if (player.getTarget() != this)
  2311.             player.setTarget(this);
  2312. @@ -4019,6 +4027,8 @@
  2313.         if (isMounted())
  2314.             stopFeed();
  2315.        
  2316. +       _tvtkills = 0;
  2317. +      
  2318.         synchronized (this)
  2319.         {
  2320.             if (isFakeDeath())
  2321. @@ -4025,6 +4035,8 @@
  2322.                 stopFakeDeath(true);
  2323.         }
  2324.        
  2325. +       TvTEvent.onKill(killer, this);
  2326. +      
  2327.         if (killer != null)
  2328.         {
  2329.             L2PcInstance pk = killer.getActingPlayer();
  2330. @@ -4102,6 +4114,11 @@
  2331.         return true;
  2332.     }
  2333.    
  2334. +   public boolean isInFunEvent()
  2335. +   {
  2336. +       return (atEvent || (TvTEvent.isStarted() && TvTEvent.isPlayerParticipant(getName())) && !isGM());
  2337. +   }
  2338. +  
  2339.     private void onDieDropItem(L2Character killer)
  2340.     {
  2341.         if (killer == null)
  2342. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2OlympiadManagerInstance.java
  2343. ===================================================================
  2344. --- java/net/sf/l2j/gameserver/model/actor/instance/L2OlympiadManagerInstance.java  (revision 5)
  2345. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2OlympiadManagerInstance.java  (working copy)
  2346. @@ -18,6 +18,7 @@
  2347.  
  2348.  import net.sf.l2j.commons.lang.StringUtil;
  2349.  import net.sf.l2j.gameserver.datatables.MultisellData;
  2350. +import net.sf.l2j.gameserver.events.TvTEvent;
  2351.  import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  2352.  import net.sf.l2j.gameserver.model.entity.Hero;
  2353.  import net.sf.l2j.gameserver.model.olympiad.CompetitionType;
  2354. @@ -182,6 +183,11 @@
  2355.         }
  2356.         else if (command.startsWith("Olympiad"))
  2357.         {
  2358. +           if (TvTEvent.isParticipating())
  2359. +           {
  2360. +               player.sendMessage("You can't do that while in a event");
  2361. +               return;
  2362. +           }
  2363.             int val = Integer.parseInt(command.substring(9, 10));
  2364.            
  2365.             final NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  2366. @@ -217,6 +223,12 @@
  2367.                     break;
  2368.                
  2369.                 case 3: // Spectator overview
  2370. +                   if (TvTEvent.isParticipating() || TvTEvent.isStarting() || TvTEvent.isStarted())
  2371. +                   {
  2372. +                       player.sendMessage("You can't do that while in a event");
  2373. +                       return;
  2374. +                   }
  2375. +
  2376.                     html.setFile(Olympiad.OLYMPIAD_HTML_PATH + "olympiad_observe_list.htm");
  2377.                    
  2378.                     int i = 0;
  2379. Index: java/net/sf/l2j/gameserver/network/serverpackets/SystemMessage.java
  2380. ===================================================================
  2381. --- java/net/sf/l2j/gameserver/network/serverpackets/SystemMessage.java (revision 5)
  2382. +++ java/net/sf/l2j/gameserver/network/serverpackets/SystemMessage.java (working copy)
  2383. @@ -110,7 +110,7 @@
  2384.     private SMParam[] _params;
  2385.     private int _paramIndex;
  2386.    
  2387. -   private SystemMessage(final SystemMessageId smId)
  2388. +   public SystemMessage(final SystemMessageId smId)
  2389.     {
  2390.         final int paramCount = smId.getParamCount();
  2391.         _smId = smId;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement