Advertisement
Guest User

TvTEvent 360+ Rev

a guest
Nov 11th, 2016
1,335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 31.29 KB | None | 0 0
  1. --- java/net/sf/l2j/gameserver/events/TvTEvent.java (revision 0)
  2. +++ java/net/sf/l2j/gameserver/events/TvTEvent.java (working copy)
  3. @@ -0,0 +1,792 @@
  4. * This program is free software: you can redistribute it and/or modify it under
  5.  * the terms of the GNU General Public License as published by the Free Software
  6.  * Foundation, either version 3 of the License, or (at your option) any later
  7.  * version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful, but WITHOUT
  10.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12.  * details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License along with
  15.  * this program. If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17. package net.sf.l2j.gameserver.events;
  18.  
  19. import net.sf.l2j.commons.random.Rnd;
  20.  
  21. import net.sf.l2j.Config;
  22. import net.sf.l2j.gameserver.datatables.DoorTable;
  23. import net.sf.l2j.gameserver.datatables.ItemTable;
  24. import net.sf.l2j.gameserver.datatables.NpcTable;
  25. import net.sf.l2j.gameserver.datatables.SkillTable;
  26. import net.sf.l2j.gameserver.datatables.SpawnTable;
  27. import net.sf.l2j.gameserver.model.L2Skill;
  28. import net.sf.l2j.gameserver.model.L2Spawn;
  29. import net.sf.l2j.gameserver.model.L2World;
  30. import net.sf.l2j.gameserver.model.actor.L2Character;
  31. import net.sf.l2j.gameserver.model.actor.L2Npc;
  32. import net.sf.l2j.gameserver.model.actor.L2Summon;
  33. import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
  34. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  35. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  36. import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
  37. import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  38. import net.sf.l2j.gameserver.model.itemcontainer.PcInventory;
  39. import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
  40. import net.sf.l2j.gameserver.network.SystemMessageId;
  41. import net.sf.l2j.gameserver.network.clientpackets.Say2;
  42. import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  43. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  44. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  45. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  46. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  47.  
  48. /**
  49.  * @author Baggos
  50.  */
  51. public class TvTEvent
  52. {
  53.     enum EventState
  54.     {
  55.         INACTIVE,
  56.         INACTIVATING,
  57.         PARTICIPATING,
  58.         STARTING,
  59.         STARTED,
  60.         REWARDING
  61.     }
  62.    
  63.     /** Gives Noblesse to players */
  64.     static L2Skill noblesse = SkillTable.getInstance().getInfo(1323, 1);
  65.     /**
  66.      * The teams of the TvTEvent<br>
  67.      */
  68.     public static TvTEventTeams[] _teams = new TvTEventTeams[2]; // event only allow max 2 teams
  69.     /**
  70.      * The state of the TvTEvent<br>
  71.      */
  72.     public static EventState _state = EventState.INACTIVE;
  73.    
  74.     /**
  75.      * No instance of this class!<br>
  76.      */
  77.     private TvTEvent()
  78.     {
  79.     }
  80.    
  81.     /**
  82.      * Teams initializing<br>
  83.      */
  84.     public static void init()
  85.     {
  86.         _teams[0] = new TvTEventTeams(Config.TVT_EVENT_TEAM_1_NAME, Config.TVT_EVENT_TEAM_1_COORDINATES);
  87.         _teams[1] = new TvTEventTeams(Config.TVT_EVENT_TEAM_2_NAME, Config.TVT_EVENT_TEAM_2_COORDINATES);
  88.     }
  89.    
  90.     /**
  91.      * Starts the participation of the TvTEvent<br>
  92.      * 1. Get NpcTemplate by Config.TVT_EVENT_PARTICIPATION_NPC_ID<br>
  93.      * 2. Try to spawn a new npc of it<br>
  94.      * <br>
  95.      * @return boolean<br>
  96.      */
  97.     public static boolean startParticipation()
  98.     {
  99.         final int npcc = Config.TVT_EVENT_PARTICIPATION_TIME * 1000 * 60;
  100.         try
  101.         {
  102.             final NpcTemplate template = NpcTable.getInstance().getTemplate(Config.TVT_EVENT_PARTICIPATION_NPC_ID);
  103.             final L2Spawn spawn = new L2Spawn(template);
  104.             spawn.setLoc(Config.TVT_EVENT_BACK_COORDINATES[0], Config.TVT_EVENT_BACK_COORDINATES[1], Config.TVT_EVENT_BACK_COORDINATES[2], 0);
  105.            
  106.             SpawnTable.getInstance().addNewSpawn(spawn, false);
  107.             final L2Npc npc = spawn.doSpawn(true);
  108.             npc.scheduleDespawn(npcc);
  109.             npc.broadcastPacket(new MagicSkillUse(npc, npc, 1034, 1, 1, 1));
  110.         }
  111.         catch (Exception e)
  112.         {
  113.             System.out.println("TvTEventEngine[TvTEvent.startParticipation()]: exception: " + e);
  114.             return false;
  115.         }
  116.         setState(EventState.PARTICIPATING);
  117.         return true;
  118.     }
  119.     /**
  120.      * Starts the TvTEvent fight<br>
  121.      * 1. Set state EventState.STARTING<br>
  122.      * 2. Close doors specified in configs<br>
  123.      * 3. Abort if not enought participants(return false)<br>
  124.      * 4. Set state EventState.STARTED<br>
  125.      * 5. Teleport all participants to team spot<br>
  126.      * <br>
  127.      * @return boolean<br>
  128.      */
  129.     public static boolean startFight()
  130.     {
  131.         setState(EventState.STARTING);
  132.        
  133.         // not enought participants
  134.         if (_teams[0].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS || _teams[1].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS)
  135.         {
  136.             setState(EventState.INACTIVE);
  137.             _teams[0].cleanMe();
  138.             _teams[1].cleanMe();
  139.             return false;
  140.         }
  141.        
  142.         closeDoors();
  143.         setState(EventState.STARTED); // set state to STARTED here, so TvTEventTeleporter know to teleport to team spot
  144.        
  145.         // teleport all participants to there team spot
  146.         for (TvTEventTeams team : _teams)
  147.         {
  148.             for (String playerName : team.getParticipatedPlayerNames())
  149.             {
  150.                 L2PcInstance playerInstance = team.getParticipatedPlayers().get(playerName);
  151.                
  152.                 if (playerInstance == null)
  153.                     continue;
  154.                
  155.                 // leave party
  156.                 playerInstance.leaveParty();
  157.                
  158.                 // Get Noblesse effect
  159.                 noblesse.getEffects(playerInstance, playerInstance);
  160.                
  161.                 // implements Runnable and starts itself in constructor
  162.                 new TvTEventTeleport(playerInstance, team.getCoordinates(), false, false);
  163.             }
  164.         }
  165.        
  166.         return true;
  167.     }
  168.    
  169.     /**
  170.      * Calculates the TvTEvent reward<br>
  171.      * 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>
  172.      * 2. Wait till teams are not at a tie anymore<br>
  173.      * 3. Set state EvcentState.REWARDING<br>
  174.      * 4. Reward team with more points<br>
  175.      * 5. Show win html to wining team participants<br>
  176.      * <br>
  177.      * @return String<br>
  178.      */
  179.     public static String calculateRewards()
  180.     {
  181.         if (_teams[0].getPoints() == _teams[1].getPoints())
  182.         {
  183.             if (_teams[0].getParticipatedPlayerCount() == 0 || _teams[1].getParticipatedPlayerCount() == 0)
  184.             {
  185.                 // the fight cannot be completed
  186.                 setState(EventState.REWARDING);
  187.                 return "TvT Event: Event finish. No team won, cause of inactivity!";
  188.             }
  189.            
  190.             sysMsgToAllParticipants("TvT Event: Both teams are at a tie, next team to get a kill wins!");
  191.         }
  192.        
  193.         while (_teams[0].getPoints() == _teams[1].getPoints())
  194.         {
  195.             waiter(1);
  196.         }
  197.        
  198.         setState(EventState.REWARDING); // after state REWARDING is set, nobody can point anymore
  199.        
  200.         byte teamId = (byte) (_teams[0].getPoints() > _teams[1].getPoints() ? 0 : 1); // which team wins?
  201.         TvTEventTeams team = _teams[teamId];
  202.        
  203.         for (String playerName : team.getParticipatedPlayerNames())
  204.         {
  205.             for (int[] reward : Config.TVT_EVENT_REWARDS)
  206.             {
  207.                 if (team.getParticipatedPlayers().get(playerName) == null)
  208.                     continue;
  209.                
  210.                 PcInventory inv = team.getParticipatedPlayers().get(playerName).getInventory();
  211.                
  212.                 if (ItemTable.getInstance().createDummyItem(reward[0]).isStackable())
  213.                     inv.addItem("TvT Event", reward[0], reward[1], team.getParticipatedPlayers().get(playerName), team.getParticipatedPlayers().get(playerName));
  214.                 else
  215.                 {
  216.                     for (int i = 0; i < reward[1]; i++)
  217.                         inv.addItem("TvT Event", reward[0], 1, team.getParticipatedPlayers().get(playerName), team.getParticipatedPlayers().get(playerName));
  218.                 }
  219.                
  220.                 SystemMessage systemMessage = null;
  221.                
  222.                 if (reward[1] > 1)
  223.                 {
  224.                     systemMessage = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  225.                     systemMessage.addItemName(reward[0]);
  226.                     systemMessage.addNumber(reward[1]);
  227.                 }
  228.                 else
  229.                 {
  230.                     systemMessage = new SystemMessage(SystemMessageId.EARNED_ITEM_S1);
  231.                     systemMessage.addItemName(reward[0]);
  232.                 }
  233.                
  234.                 team.getParticipatedPlayers().get(playerName).sendPacket(systemMessage);
  235.             }
  236.            
  237.             StatusUpdate statusUpdate = new StatusUpdate(team.getParticipatedPlayers().get(playerName));
  238.            
  239.             statusUpdate.addAttribute(StatusUpdate.CUR_LOAD, team.getParticipatedPlayers().get(playerName).getCurrentLoad());
  240.             team.getParticipatedPlayers().get(playerName).sendPacket(statusUpdate);
  241.            
  242.             NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  243.            
  244.             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>");
  245.             team.getParticipatedPlayers().get(playerName).sendPacket(npcHtmlMessage);
  246.         }
  247.        
  248.         return "TvT Event: Event finish. Team " + team.getName() + " won with " + team.getPoints() + " kills.";
  249.     }
  250.    
  251.     /**
  252.      * Stops the TvTEvent fight<br>
  253.      * 1. Set state EventState.INACTIVATING<br>
  254.      * 2. Remove tvt npc from world<br>
  255.      * 3. Open doors specified in configs<br>
  256.      * 4. Teleport all participants back to participation npc location<br>
  257.      * 5. Teams cleaning<br>
  258.      * 6. Set state EventState.INACTIVE<br>
  259.      */
  260.     public static void stopFight()
  261.     {
  262.         setState(EventState.INACTIVATING);
  263.         openDoors();
  264.        
  265.         for (TvTEventTeams team : _teams)
  266.         {
  267.             for (String playerName : team.getParticipatedPlayerNames())
  268.             {
  269.                 L2PcInstance playerInstance = team.getParticipatedPlayers().get(playerName);
  270.                
  271.                 if (playerInstance == null)
  272.                     continue;
  273.                
  274.                 new TvTEventTeleport(playerInstance, Config.TVT_EVENT_BACK_COORDINATES, false, false);
  275.             }
  276.         }
  277.        
  278.         _teams[0].cleanMe();
  279.         _teams[1].cleanMe();
  280.        
  281.         setState(EventState.INACTIVE);
  282.        
  283.     }
  284.    
  285.     /**
  286.      * Adds a player to a TvTEvent team<br>
  287.      * 1. Calculate the id of the team in which the player should be added<br>
  288.      * 2. Add the player to the calculated team
  289.      * @param playerInstance
  290.      * @return boolean
  291.      */
  292.     public static synchronized boolean addParticipant(L2PcInstance playerInstance)
  293.     {
  294.         if (playerInstance == null)
  295.             return false;
  296.        
  297.         byte teamId = 0;
  298.        
  299.         if (_teams[0].getParticipatedPlayerCount() == _teams[1].getParticipatedPlayerCount())
  300.             teamId = (byte) (Rnd.get(2));
  301.         else
  302.             teamId = (byte) (_teams[0].getParticipatedPlayerCount() > _teams[1].getParticipatedPlayerCount() ? 1 : 0);
  303.        
  304.         return _teams[teamId].addPlayer(playerInstance);
  305.     }
  306.    
  307.     /**
  308.      * Removes a TvTEvent player from it's team<br>
  309.      * 1. Get team id of the player<br>
  310.      * 2. Remove player from it's team
  311.      * @param playerName
  312.      * @return boolean
  313.      */
  314.     public static boolean removeParticipant(String playerName)
  315.     {
  316.         byte teamId = getParticipantTeamId(playerName);
  317.        
  318.         if (teamId == -1)
  319.             return false;
  320.        
  321.         _teams[teamId].removePlayer(playerName);
  322.         return true;
  323.     }
  324.    
  325.     /**
  326.      * Send a SystemMessage to all participated players<br>
  327.      * 1. Send the message to all players of team number one<br>
  328.      * 2. Send the message to all players of team number two
  329.      * @param message
  330.      */
  331.     public static void sysMsgToAllParticipants(String message)
  332.     {
  333.         for (L2PcInstance playerInstance : _teams[0].getParticipatedPlayers().values())
  334.         {
  335.             if (playerInstance != null)
  336.                 playerInstance.sendMessage(message);
  337.         }
  338.        
  339.         for (L2PcInstance playerInstance : _teams[1].getParticipatedPlayers().values())
  340.         {
  341.             if (playerInstance != null)
  342.                 playerInstance.sendMessage(message);
  343.         }
  344.     }
  345.    
  346.     /**
  347.      * Close doors specified in configs
  348.      */
  349.     public static void closeDoors()
  350.     {
  351.         for (int doorId : Config.TVT_EVENT_DOOR_IDS)
  352.         {
  353.             L2DoorInstance doorInstance = DoorTable.getInstance().getDoor(doorId);
  354.            
  355.             if (doorInstance != null)
  356.                 doorInstance.closeMe();
  357.         }
  358.     }
  359.    
  360.     /**
  361.      * Open doors specified in configs
  362.      */
  363.     public static void openDoors()
  364.     {
  365.         for (int doorId : Config.TVT_EVENT_DOOR_IDS)
  366.         {
  367.             L2DoorInstance doorInstance = DoorTable.getInstance().getDoor(doorId);
  368.            
  369.             if (doorInstance != null)
  370.                 doorInstance.openMe();
  371.         }
  372.     }
  373.    
  374.     public static void waiter(int seconds)
  375.     {
  376.         try
  377.         {
  378.             Thread.sleep(seconds * 1000);
  379.         }
  380.         catch (InterruptedException e)
  381.         {
  382.             e.printStackTrace();
  383.         }
  384.     }
  385.    
  386.     /**
  387.      * Called when a player logs in
  388.      * @param playerInstance
  389.      * @param player
  390.      */
  391.     public static void onLogin(L2PcInstance playerInstance, L2PcInstance player)
  392.     {
  393.         if (playerInstance == null || (!isStarting() && !isStarted()))
  394.             return;
  395.        
  396.         byte teamId = getParticipantTeamId(playerInstance.getName());
  397.        
  398.         if (teamId == -1)
  399.             return;
  400.        
  401.         _teams[teamId].addPlayer(playerInstance);
  402.         new TvTEventTeleport(playerInstance, _teams[teamId].getCoordinates(), true, false);
  403.     }
  404.    
  405.     /**
  406.      * Called when a player logs out
  407.      * @param playerInstance
  408.      * @param player
  409.      */
  410.     public static void onLogout(L2PcInstance playerInstance, L2PcInstance player)
  411.     {
  412.         if (playerInstance == null || (!isStarting() && !isStarted()))
  413.             return;
  414.        
  415.         removeParticipant(playerInstance.getName());
  416.     }
  417.    
  418.     /**
  419.      * Called on every bypass by npc of type L2TvTEventNpc<br>
  420.      * Needs synchronization cause of the max player check
  421.      * @param command
  422.      * @param playerInstance
  423.      */
  424.     public static synchronized void onBypass(String command, L2PcInstance playerInstance)
  425.     {
  426.         if (playerInstance == null || !isParticipating())
  427.             return;
  428.        
  429.         if (command.equals("tvt_event_participation"))
  430.         {
  431.             NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  432.             int playerLevel = playerInstance.getLevel();
  433.            
  434.             if (playerInstance.isCursedWeaponEquipped())
  435.                 npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Cursed weapon owners are not allowed to participate.</body></html>");
  436.             else if (OlympiadManager.getInstance().isRegisteredInComp(playerInstance))
  437.                 npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Olympiad participants can't register.</body></html>");
  438.             else if (playerInstance.getKarma() > 0)
  439.                 npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Chaotic players are not allowed to participate.</body></html>");
  440.             else if (_teams[0].getParticipatedPlayerCount() >= Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS && _teams[1].getParticipatedPlayerCount() >= Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS)
  441.                 npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Sorry the event is full!</body></html>");
  442.             else if (playerLevel < Config.TVT_EVENT_MIN_LVL || playerLevel > Config.TVT_EVENT_MAX_LVL)
  443.                 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>");
  444.             else if (_teams[0].getParticipatedPlayerCount() > 19 && _teams[1].getParticipatedPlayerCount() > 19)
  445.                 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>");
  446.             else if (addParticipant(playerInstance))
  447.                 npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>You are on the registration list now.</body></html>");
  448.             else
  449.                 // addParticipant returned false cause playerInstance == null
  450.                 return;
  451.            
  452.             playerInstance.sendPacket(npcHtmlMessage);
  453.         }
  454.         else if (command.equals("tvt_event_remove_participation"))
  455.         {
  456.             removeParticipant(playerInstance.getName());
  457.            
  458.             NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  459.            
  460.             npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>You are not longer on the registration list.</body></html>");
  461.             playerInstance.sendPacket(npcHtmlMessage);
  462.         }
  463.     }
  464.    
  465.     /**
  466.      * Called on every onAction in L2PcIstance
  467.      * @param playerName
  468.      * @param targetPlayerName
  469.      * @return boolean
  470.      */
  471.     public static boolean onAction(String playerName, String targetPlayerName)
  472.     {
  473.         if (!isStarted())
  474.             return true;
  475.        
  476.         L2PcInstance playerInstance = L2World.getInstance().getPlayer(playerName);
  477.        
  478.         if (playerInstance == null)
  479.             return false;
  480.        
  481.         if (playerInstance.isGM())
  482.             return true;
  483.        
  484.         byte playerTeamId = getParticipantTeamId(playerName);
  485.         byte targetPlayerTeamId = getParticipantTeamId(targetPlayerName);
  486.        
  487.         if ((playerTeamId != -1 && targetPlayerTeamId == -1) || (playerTeamId == -1 && targetPlayerTeamId != -1))
  488.             return false;
  489.        
  490.         if (playerTeamId != -1 && targetPlayerTeamId != -1 && playerTeamId == targetPlayerTeamId && !Config.TVT_EVENT_TARGET_TEAM_MEMBERS_ALLOWED)
  491.             return false;
  492.        
  493.         return true;
  494.     }
  495.    
  496.     /**
  497.      * Called on every summon item use
  498.      * @param playerName
  499.      * @return boolean
  500.      */
  501.     public static boolean onItemSummon(String playerName)
  502.     {
  503.         if (!isStarted())
  504.             return true;
  505.        
  506.         if (isPlayerParticipant(playerName) && !Config.TVT_EVENT_SUMMON_BY_ITEM_ALLOWED)
  507.             return false;
  508.        
  509.         return true;
  510.     }
  511.    
  512.     /**
  513.      * Is called when a player is killed
  514.      * @param killerCharacter
  515.      * @param killedPlayerInstance
  516.      */
  517.     public static void onKill(L2Character killerCharacter, L2PcInstance killedPlayerInstance)
  518.     {
  519.         if (killerCharacter == null || killedPlayerInstance == null || (!(killerCharacter instanceof L2PcInstance) && !(killerCharacter instanceof L2PetInstance) && !(killerCharacter instanceof L2SummonInstance)) || !isStarted())
  520.             return;
  521.        
  522.         L2PcInstance killerPlayerInstance = null;
  523.        
  524.         if (killerCharacter instanceof L2PetInstance || killerCharacter instanceof L2SummonInstance)
  525.         {
  526.             killerPlayerInstance = ((L2Summon) killerCharacter).getOwner();
  527.            
  528.             if (killerPlayerInstance == null)
  529.                 return;
  530.         }
  531.         else
  532.             killerPlayerInstance = (L2PcInstance) killerCharacter;
  533.        
  534.         if (Config.TVT_KILLS_REWARD_ENABLED)
  535.             for (int[] rewardKills : Config.TVT_KILLS_REWARD)
  536.             {
  537.                 SystemMessage systemMessage = null;
  538.                 // Count the kill
  539.                 killerPlayerInstance._tvtkills++;
  540.                 switch (killerPlayerInstance._tvtkills)
  541.                 {
  542.                     case 5: // Reward after 5 kills without die
  543.                     case 8: // Reward after 8 kills without die
  544.                     case 12: // Reward after 12 kills without die
  545.                     case 15: // Reward after 15 kills without die
  546.                     case 20: // Reward after 20 kills without die
  547.                        
  548.                         systemMessage = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  549.                         systemMessage.addItemName(rewardKills[0]);
  550.                         systemMessage.addNumber(rewardKills[1]);
  551.                        
  552.                         killerPlayerInstance.getInventory().addItem("TvT Event", rewardKills[0], rewardKills[1], killerPlayerInstance, killerPlayerInstance);
  553.                         killerPlayerInstance.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "Amazing", +killerPlayerInstance._tvtkills + " kills without die. You has been rewarded!"));
  554.                         killerPlayerInstance.sendPacket(systemMessage);
  555.                         break;
  556.                 }
  557.             }
  558.        
  559.         String playerName = killerPlayerInstance.getName();
  560.         byte killerTeamId = getParticipantTeamId(playerName);
  561.        
  562.         playerName = killedPlayerInstance.getName();
  563.        
  564.         byte killedTeamId = getParticipantTeamId(playerName);
  565.        
  566.         if (killerTeamId != -1 && killedTeamId != -1 && killerTeamId != killedTeamId)
  567.             _teams[killerTeamId].increasePoints();
  568.        
  569.         if (killedTeamId != -1)
  570.             new TvTEventTeleport(killedPlayerInstance, _teams[killedTeamId].getCoordinates(), false, false);
  571.     }
  572.    
  573.     /**
  574.      * Sets the TvTEvent state
  575.      * @param state
  576.      */
  577.     private static void setState(EventState state)
  578.     {
  579.         synchronized (_state)
  580.         {
  581.             _state = state;
  582.         }
  583.     }
  584.    
  585.     /**
  586.      * Is TvTEvent inactive?
  587.      * @return boolean
  588.      */
  589.     public static boolean isInactive()
  590.     {
  591.         boolean isInactive;
  592.        
  593.         synchronized (_state)
  594.         {
  595.             isInactive = _state == EventState.INACTIVE;
  596.         }
  597.        
  598.         return isInactive;
  599.     }
  600.    
  601.     /**
  602.      * Is TvTEvent in inactivating?
  603.      * @return boolean
  604.      */
  605.     public static boolean isInactivating()
  606.     {
  607.         boolean isInactivating;
  608.        
  609.         synchronized (_state)
  610.         {
  611.             isInactivating = _state == EventState.INACTIVATING;
  612.         }
  613.        
  614.         return isInactivating;
  615.     }
  616.    
  617.     /**
  618.      * Is TvTEvent in participation?
  619.      * @return boolean
  620.      */
  621.     public static boolean isParticipating()
  622.     {
  623.         boolean isParticipating;
  624.        
  625.         synchronized (_state)
  626.         {
  627.             isParticipating = _state == EventState.PARTICIPATING;
  628.         }
  629.        
  630.         return isParticipating;
  631.     }
  632.    
  633.     /**
  634.      * Is TvTEvent starting?
  635.      * @return boolean
  636.      */
  637.     public static boolean isStarting()
  638.     {
  639.         boolean isStarting;
  640.        
  641.         synchronized (_state)
  642.         {
  643.             isStarting = _state == EventState.STARTING;
  644.         }
  645.        
  646.         return isStarting;
  647.     }
  648.    
  649.     /**
  650.      * Is TvTEvent started?
  651.      * @return boolean
  652.      */
  653.     public static boolean isStarted()
  654.     {
  655.         boolean isStarted;
  656.        
  657.         synchronized (_state)
  658.         {
  659.             isStarted = _state == EventState.STARTED;
  660.         }
  661.        
  662.         return isStarted;
  663.     }
  664.    
  665.     /**
  666.      * Is TvTEvent rewarding?
  667.      * @return boolean
  668.      */
  669.     public static boolean isRewarding()
  670.     {
  671.         boolean isRewarding;
  672.        
  673.         synchronized (_state)
  674.         {
  675.             isRewarding = _state == EventState.REWARDING;
  676.         }
  677.        
  678.         return isRewarding;
  679.     }
  680.    
  681.     /**
  682.      * Returns the team id of a player, if player is not participant it returns -1
  683.      * @param playerName
  684.      * @return byte
  685.      */
  686.     public static byte getParticipantTeamId(String playerName)
  687.     {
  688.         return (byte) (_teams[0].containsPlayer(playerName) ? 0 : (_teams[1].containsPlayer(playerName) ? 1 : -1));
  689.     }
  690.    
  691.     /**
  692.      * Returns the team coordinates in which the player is in, if player is not in a team return null
  693.      * @param playerName
  694.      * @return int[]
  695.      */
  696.     public static int[] getParticipantTeamCoordinates(String playerName)
  697.     {
  698.         return _teams[0].containsPlayer(playerName) ? _teams[0].getCoordinates() : (_teams[1].containsPlayer(playerName) ? _teams[1].getCoordinates() : null);
  699.     }
  700.    
  701.     /**
  702.      * Is given player participant of the event?
  703.      * @param playerName
  704.      * @return boolean
  705.      */
  706.     public static boolean isPlayerParticipant(String playerName)
  707.     {
  708.         return _teams[0].containsPlayer(playerName) || _teams[1].containsPlayer(playerName);
  709.     }
  710.    
  711.     /**
  712.      * Returns participated player count<br>
  713.      * <br>
  714.      * @return int<br>
  715.      */
  716.     public static int getParticipatedPlayersCount()
  717.     {
  718.         return _teams[0].getParticipatedPlayerCount() + _teams[1].getParticipatedPlayerCount();
  719.     }
  720.    
  721.     /**
  722.      * Returns teams names<br>
  723.      * <br>
  724.      * @return String[]<br>
  725.      */
  726.     public static String[] getTeamNames()
  727.     {
  728.         return new String[]
  729.         {
  730.             _teams[0].getName(),
  731.             _teams[1].getName()
  732.         };
  733.     }
  734.    
  735.     /**
  736.      * Returns player count of both teams<br>
  737.      * <br>
  738.      * @return int[]<br>
  739.      */
  740.     public static int[] getTeamsPlayerCounts()
  741.     {
  742.         return new int[]
  743.         {
  744.             _teams[0].getParticipatedPlayerCount(),
  745.             _teams[1].getParticipatedPlayerCount()
  746.         };
  747.     }
  748.    
  749.     /**
  750.      * Returns points count of both teams
  751.      * @return int[]
  752.      */
  753.     public static int[] getTeamsPoints()
  754.     {
  755.         return new int[]
  756.         {
  757.             _teams[0].getPoints(),
  758.             _teams[1].getPoints()
  759.         };
  760.     }
  761. }
  762.  
  763. --- java/net/sf/l2j/gameserver/events/TvTEventManager.java  (revision 0)
  764. +++ java/net/sf/l2j/gameserver/events/TvTEventManager.java  (working copy)
  765. @@ -0,0 +1,152 @@
  766. * This program is free software: you can redistribute it and/or modify it under
  767.  * the terms of the GNU General Public License as published by the Free Software
  768.  * Foundation, either version 3 of the License, or (at your option) any later
  769.  * version.
  770.  *
  771.  * This program is distributed in the hope that it will be useful, but WITHOUT
  772.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  773.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  774.  * details.
  775.  *
  776.  * You should have received a copy of the GNU General Public License along with
  777.  * this program. If not, see <http://www.gnu.org/licenses/>.
  778.  */
  779. package net.sf.l2j.gameserver.events;
  780.  
  781. import net.sf.l2j.commons.concurrent.ThreadPool;
  782.  
  783. import net.sf.l2j.Config;
  784. import net.sf.l2j.gameserver.util.Broadcast;
  785.  
  786. /**
  787.  * @author FBIagent
  788.  */
  789. public class TvTEventManager implements Runnable
  790. {
  791.     /**
  792.      * The one and only instance of this class<br>
  793.      */
  794.     private static TvTEventManager _instance = null;
  795.    
  796.     /**
  797.      * New instance only by getInstance()<br>
  798.      */
  799.     private TvTEventManager()
  800.     {
  801.         if (Config.TVT_EVENT_ENABLED)
  802.         {
  803.             ThreadPool.schedule(this, 0);
  804.             System.out.println("TvTEventEngine[TvTManager.TvTManager()]: Started.");
  805.         }
  806.         else
  807.             System.out.println("TvTEventEngine[TvTManager.TvTManager()]: Engine is disabled.");
  808.     }
  809.    
  810.     /**
  811.      * Initialize new/Returns the one and only instance<br>
  812.      * <br>
  813.      * @return TvTManager<br>
  814.      */
  815.     public static TvTEventManager getInstance()
  816.     {
  817.         if (_instance == null)
  818.             _instance = new TvTEventManager();
  819.        
  820.         return _instance;
  821.     }
  822.    
  823.     /**
  824.      * The task method to handle cycles of the event
  825.      * @see java.lang.Runnable#run()
  826.      */
  827.     @Override
  828.     public void run()
  829.     {
  830.         TvTEvent.init();
  831.        
  832.         for (;;)
  833.         {
  834.             waiter(Config.TVT_EVENT_INTERVAL * 60); // in config given as minutes
  835.            
  836.             if (!TvTEvent.startParticipation())
  837.             {
  838.                 Broadcast.announceToOnlinePlayers("TvT: Event was canceled.", true);
  839.                 System.out.println("TvTEventEngine[TvTManager.run()]: Error spawning event npc for participation.");
  840.                 continue;
  841.             }
  842.             Broadcast.announceToOnlinePlayers("TvT: Registration opened for " + Config.TVT_EVENT_PARTICIPATION_TIME + " minute(s). Type .tvtjoin or .tvtleave", true);
  843.            
  844.             waiter(Config.TVT_EVENT_PARTICIPATION_TIME * 60); // in config given as minutes
  845.            
  846.             if (!TvTEvent.startFight())
  847.             {
  848.                 Broadcast.announceToOnlinePlayers("TvT: Event canceled due to lack of Participation.", true);
  849.                 System.out.println("TvTEventEngine[TvTManager.run()]: Lack of registration, abort event.");
  850.                 continue;
  851.             }
  852.             Broadcast.announceToOnlinePlayers("TvT: Registration closed!", true);
  853.             TvTEvent.sysMsgToAllParticipants("TvT: Teleporting participants to an arena in " + Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");
  854.            
  855.             waiter(Config.TVT_EVENT_RUNNING_TIME * 60); // in config given as minutes
  856.             Broadcast.announceToOnlinePlayers(TvTEvent.calculateRewards(), true);
  857.             TvTEvent.sysMsgToAllParticipants("TvT: Teleporting back to the registration npc in " + Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");
  858.             TvTEvent.stopFight();
  859.         }
  860.     }
  861.    
  862.     /**
  863.      * This method waits for a period time delay
  864.      * @param seconds
  865.      */
  866.     void waiter(int seconds)
  867.     {
  868.         while (seconds > 1)
  869.         {
  870.             seconds--; // here because we don't want to see two time announce at the same time
  871.            
  872.             if (TvTEvent.isParticipating() || TvTEvent.isStarted())
  873.             {
  874.                 switch (seconds)
  875.                 {
  876.                     case 3600: // 1 hour left
  877.                         if (TvTEvent.isParticipating())
  878.                             Broadcast.announceToOnlinePlayers("TvT: " + seconds / 60 / 60 + " hour(s) umtil registration is closed!", true);
  879.                         else if (TvTEvent.isStarted())
  880.                             TvTEvent.sysMsgToAllParticipants("TvT: " + seconds / 60 / 60 + " hour(s) until event is finished!");
  881.                        
  882.                         break;
  883.                     case 1800: // 30 minutes left
  884.                     case 900: // 15 minutes left
  885.                     case 600: // 10 minutes left
  886.                     case 300: // 5 minutes left
  887.                     case 240: // 4 minutes left
  888.                     case 180: // 3 minutes left
  889.                     case 120: // 2 minutes left
  890.                     case 60: // 1 minute left
  891.                         if (TvTEvent.isParticipating())
  892.                             Broadcast.announceToOnlinePlayers("TvT: " + seconds / 60 + " minute(s) until registration is closed!", true);
  893.                         else if (TvTEvent.isStarted())
  894.                             TvTEvent.sysMsgToAllParticipants("TvT: " + seconds / 60 + " minute(s) until the event is finished!");
  895.                        
  896.                         break;
  897.                     case 30: // 30 seconds left
  898.                         /**
  899.                          * case 15: // 15 seconds left case 10: // 10 seconds left
  900.                          */
  901.                     case 5: // 5 seconds left
  902.                        
  903.                         /**
  904.                          * case 4: // 4 seconds left case 3: // 3 seconds left case 2: // 2 seconds left case 1: // 1 seconds left
  905.                          */
  906.                         if (TvTEvent.isParticipating())
  907.                             Broadcast.announceToOnlinePlayers("TvT: " + seconds + " second(s) until registration is closed!", true);
  908.                         else if (TvTEvent.isStarted())
  909.                             TvTEvent.sysMsgToAllParticipants("TvT: " + seconds + " second(s) until the event is finished!");
  910.                        
  911.                         break;
  912.                 }
  913.             }
  914.             TvTEvent.waiter(1);
  915.         }
  916.     }
  917. }
  918.  
  919. --- java/net/sf/l2j/gameserver/events/TvTEventTeleport.java (revision 0)
  920. +++ java/net/sf/l2j/gameserver/events/TvTEventTeleport.java (working copy)
  921. @@ -0,0 +1,102 @@
  922. * This program is free software: you can redistribute it and/or modify it under
  923.  * the terms of the GNU General Public License as published by the Free Software
  924.  * Foundation, either version 3 of the License, or (at your option) any later
  925.  * version.
  926.  *
  927.  * This program is distributed in the hope that it will be useful, but WITHOUT
  928.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  929.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  930.  * details.
  931.  *
  932.  * You should have received a copy of the GNU General Public License along with
  933.  * this program. If not, see <http://www.gnu.org/licenses/>.
  934.  */
  935. package net.sf.l2j.gameserver.events;
  936.  
  937. import net.sf.l2j.commons.concurrent.ThreadPool;
  938.  
  939. import net.sf.l2j.Config;
  940. import net.sf.l2j.gameserver.datatables.SkillTable;
  941. import net.sf.l2j.gameserver.model.L2Effect;
  942. import net.sf.l2j.gameserver.model.L2Skill;
  943. import net.sf.l2j.gameserver.model.actor.L2Summon;
  944. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  945.  
  946. public class TvTEventTeleport implements Runnable
  947. {
  948.     /** Gives Noblesse to players */
  949.     static L2Skill noblesse = SkillTable.getInstance().getInfo(1323, 1);
  950.     /** The instance of the player to teleport */
  951.     public L2PcInstance _playerInstance;
  952.     /** Coordinates of the spot to teleport to */
  953.     public int[] _coordinates = new int[3];
  954.     /** Admin removed this player from event */
  955.     private boolean _adminRemove;
  956.    
  957.     /**
  958.      * Initialize the teleporter and start the delayed task
  959.      * @param playerInstance
  960.      * @param coordinates
  961.      * @param fastSchedule
  962.      * @param adminRemove
  963.      */
  964.     public TvTEventTeleport(L2PcInstance playerInstance, int[] coordinates, boolean fastSchedule, boolean adminRemove)
  965.     {
  966.         _playerInstance = playerInstance;
  967.         _coordinates = coordinates;
  968.         _adminRemove = adminRemove;
  969.        
  970.         // in config as seconds
  971.         long delay = (TvTEvent.isStarted() ? Config.TVT_EVENT_RESPAWN_TELEPORT_DELAY : Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY) * 1000;
  972.        
  973.         if (fastSchedule)
  974.             delay = 0;
  975.        
  976.         ThreadPool.schedule(this, delay);
  977.     }
  978.    
  979.     /**
  980.      * The task method to teleport the player<br>
  981.      * 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
  982.      * @see java.lang.Runnable#run()
  983.      */
  984.     @Override
  985.     public void run()
  986.     {
  987.         if (_playerInstance == null)
  988.             return;
  989.        
  990.         L2Summon summon = _playerInstance.getPet();
  991.        
  992.         if (summon != null)
  993.             summon.unSummon(_playerInstance);
  994.        
  995.         for (L2Effect effect : _playerInstance.getAllEffects())
  996.         {
  997.             if (Config.TVT_EVENT_REMOVE_BUFFS && effect != null)
  998.                 effect.exit();
  999.         }
  1000.        
  1001.         ThreadPool.schedule(new Runnable()
  1002.         {
  1003.             @Override
  1004.             public void run()
  1005.             {
  1006.                 _playerInstance.doRevive();
  1007.                 _playerInstance.setCurrentHp(_playerInstance.getMaxHp());
  1008.                 _playerInstance.setCurrentCp(_playerInstance.getMaxCp());
  1009.                 _playerInstance.setCurrentMp(_playerInstance.getMaxMp());
  1010.                 noblesse.getEffects(_playerInstance, _playerInstance);
  1011.                 _playerInstance.teleToLocation(_coordinates[0], _coordinates[1], _coordinates[2], 0);
  1012.             }
  1013.         }, 4000);
  1014.        
  1015.         if (TvTEvent.isStarted() && !_adminRemove)
  1016.             _playerInstance.setTeam(TvTEvent.getParticipantTeamId(_playerInstance.getName()) + 1);
  1017.         else
  1018.             _playerInstance.setTeam(0);
  1019.        
  1020.         _playerInstance.broadcastStatusUpdate();
  1021.         _playerInstance.broadcastUserInfo();
  1022.     }
  1023. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement