Advertisement
horato

2v2 korean event

May 24th, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.45 KB | None | 0 0
  1. /*
  2.  * This program is free software: you can redistribute it and/or modify it under
  3.  * the terms of the GNU General Public License as published by the Free Software
  4.  * Foundation, either version 3 of the License, or (at your option) any later
  5.  * version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful, but WITHOUT
  8.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10.  * details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License along with
  13.  * this program. If not, see <http://www.gnu.org/licenses/>.
  14.  */
  15. package mods.eventmodKorea;
  16.  
  17. /**************************************************************************************************************
  18.  *                                                                                                            *
  19.  *                                      @author horato                                                        *
  20.  *                                       Made for L2world.org                                                 *
  21.  *                                                                                                            *
  22.  **************************************************************************************************************/
  23. import java.util.List;
  24. import java.util.Random;
  25. import java.util.concurrent.ScheduledFuture;
  26.  
  27. import javolution.util.FastList;
  28.  
  29. import com.l2jserver.Config;
  30. import com.l2jserver.gameserver.Announcements;
  31. import com.l2jserver.gameserver.ThreadPoolManager;
  32. import com.l2jserver.gameserver.datatables.SkillTable;
  33. import com.l2jserver.gameserver.instancemanager.QuestManager;
  34. import com.l2jserver.gameserver.model.L2Party;
  35. import com.l2jserver.gameserver.model.actor.L2Character;
  36. import com.l2jserver.gameserver.model.actor.L2Npc;
  37. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  38. import com.l2jserver.gameserver.model.quest.Event;
  39. import com.l2jserver.gameserver.model.quest.Quest;
  40. import com.l2jserver.gameserver.model.quest.QuestState;
  41. import com.l2jserver.gameserver.skills.AbnormalEffect;
  42.  
  43. public class eventmodKorea extends Event
  44. {
  45.     // Event state
  46.     enum EventState
  47.     {
  48.         INACTIVE, ACTIVE, FIGHT, WAIT
  49.     }
  50.    
  51.     public static EventState _state = EventState.INACTIVE;
  52.     // Start npc ID
  53.     private static final int _npc_id = 900105;
  54.     // Initialize team list
  55.     private List<L2Party> _teams = new FastList<L2Party>();
  56.     private List<L2Party> _allteams = new FastList<L2Party>();
  57.     // Event Task
  58.     ScheduledFuture<?> _eventTask = null;
  59.     // Npc
  60.     private L2Npc _npc;
  61.     // 2 Currently fighting party
  62.     private L2Party _team1;
  63.     private L2Party _team2;
  64.     // Random for chosing teams
  65.     Random rnd = new Random();
  66.     // Winners and losers from matches
  67.     private List<L2Party> _winners = new FastList<L2Party>();
  68.     private List<L2Party> _losers = new FastList<L2Party>();
  69.    
  70.     public static void main(String[] args)
  71.     {
  72.         new eventmodKorea(-1, "eventmodKorea", "mods");
  73.     }
  74.    
  75.     public eventmodKorea(int questId, String name, String descr)
  76.     {
  77.         super(questId, name, descr);
  78.        
  79.         addStartNpc(_npc_id);
  80.         addFirstTalkId(_npc_id);
  81.         addTalkId(_npc_id);
  82.     }
  83.    
  84.     @Override
  85.     public boolean eventStart()
  86.     {
  87.         // Don't start event if its active
  88.         if (_state == EventState.ACTIVE)
  89.             return false;
  90.         if (!Config.CUSTOM_NPC_TABLE)
  91.             return false;
  92.         // Set active
  93.         _state = EventState.ACTIVE;
  94.         //Clear player list, npc lists and score
  95.         _npc = null;
  96.         if (!_teams.isEmpty())
  97.             _teams.clear();
  98.        
  99.         // Spawn event manager
  100.         _npc = addSpawn(_npc_id, 82798, 148650, -3464, 0, false, 0);
  101.        
  102.         Announcements.getInstance().announceToAll("Korean 2v2 event started");
  103.        
  104.         _eventTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  105.         {
  106.             public void run()
  107.             {
  108.                 Announcements.getInstance().announceToAll("Korean 2v2 Event: 10 minutes left");
  109.                 try
  110.                 {
  111.                     Thread.sleep(/*5*/1 * 60 * 1000); //1 min
  112.                     /*Announcements.getInstance().announceToAll("Korean 2v2 Event: 5 minutes left");
  113.                     Thread.sleep(2 * 60 * 1000); //1 min
  114.                     Announcements.getInstance().announceToAll("Korean 2v2 Event: 3 minutes left");
  115.                     Thread.sleep(2 * 60 * 1000); //1 min
  116.                     Announcements.getInstance().announceToAll("Korean 2v2 Event: 1 minutes left");
  117.                     Thread.sleep(1 * 60 * 1000); //1 min*/
  118.                     StartEvent();
  119.                 }
  120.                 catch (InterruptedException e)
  121.                 {
  122.                     Announcements.getInstance().announceToAll("Event error");
  123.                     eventStop();
  124.                 }
  125.             }
  126.         }, 1);
  127.        
  128.         return true;
  129.     }
  130.    
  131.     @Override
  132.     public boolean eventStop()
  133.     {
  134.         // Don't stop inactive event
  135.         if (_state == EventState.INACTIVE)
  136.             return false;
  137.         // Thread stop
  138.         if (!_eventTask.isDone())
  139.             _eventTask.cancel(true);
  140.         // Set inactive
  141.         _state = EventState.INACTIVE;
  142.         //TODO: event end
  143.        
  144.         for (L2Party party : _allteams)
  145.         {
  146.             for (L2PcInstance player : party.getPartyMembers())
  147.             {
  148.                 player.removeNotifyQuestOfDeath(player.getQuestState(getName()));
  149.                 player.stopAbnormalEffect(AbnormalEffect.HOLD_2);
  150.                 player.setIsParalyzed(false);
  151.                 player.stopParalyze(false);
  152.                 player.teleToLocation(83478, 148628, -3405);
  153.             }
  154.         }
  155.        
  156.         for (L2Party party : _teams)
  157.         {
  158.             for (L2PcInstance player : party.getPartyMembers())
  159.             {
  160.                 player.addItem("eventmodSubclassTvT", 4037, 10, _npc, true);
  161.             }
  162.         }
  163.        
  164.         // Remove NPC
  165.         if (_npc != null)
  166.             _npc.deleteMe();
  167.         // Clear teams
  168.         if (!_teams.isEmpty())
  169.             _teams.clear();
  170.         if (!_losers.isEmpty())
  171.             _losers.clear();
  172.         if (!_winners.isEmpty())
  173.             _winners.clear();
  174.        
  175.         Announcements.getInstance().announceToAll("Korean 2v2 event finished");
  176.        
  177.         return true;
  178.     }
  179.    
  180.     @Override
  181.     public boolean eventBypass(L2PcInstance activeChar, String bypass)
  182.     {
  183.         return false;
  184.     }
  185.    
  186.     @Override
  187.     public String onFirstTalk(L2Npc npc, L2PcInstance player)
  188.     {
  189.         QuestState st = player.getQuestState(getName());
  190.         if (st == null)
  191.         {
  192.             Quest q = QuestManager.getInstance().getQuest(getName());
  193.             st = q.newQuestState(player);
  194.         }
  195.         if (npc.getNpcId() == _npc_id)
  196.         {
  197.             return "korean.htm";
  198.         }
  199.         return npc.getNpcId() + ".htm";
  200.     }
  201.    
  202.     @Override
  203.     public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  204.     {
  205.         // Registering
  206.         if (event.startsWith("signup"))
  207.         {
  208.             if (!player.isInParty())
  209.                 return "korean-fail.htm";
  210.             if (_teams.contains(player.getParty()))
  211.                 return "korean-onlist.htm";
  212.             if (player.getParty().getMemberCount() != 2)
  213.                 return "korean-fail.htm";
  214.             if (player.getParty().getLeader() != player)
  215.                 return "korean-notleader.htm";
  216.            
  217.             _teams.add(player.getParty());
  218.             return "korean-signed.htm";
  219.         }
  220.        
  221.         // Unregistering
  222.         if (event.startsWith("signdown"))
  223.         {
  224.             if (!_teams.contains(player.getParty()))
  225.                 return "korean-notreg.htm";
  226.             if (player.getParty().getLeader() != player)
  227.                 return "korean-notleader.htm";
  228.             if (player.getParty().getLeader() == player)
  229.             {
  230.                 _teams.remove(player.getParty());
  231.                 return "korean-unsigned.htm";
  232.             }
  233.         }
  234.        
  235.         return "";
  236.     }
  237.    
  238.     private void StartEvent()
  239.     {
  240.         // Remove registration NPC
  241.         if (_npc != null)
  242.             _npc.deleteMe();
  243.        
  244.         for (L2Party party : _teams)
  245.         {
  246.             if (party.getMemberCount() < 2)
  247.             {
  248.                 _teams.remove(party);
  249.             }
  250.         }
  251.         if(_teams.size() < 2)
  252.         {
  253.             Announcements.getInstance().announceToAll("Not enough players to start event");
  254.             eventStop();
  255.            
  256.         }
  257.         // Teleport players to wait location.
  258.         for (L2Party party : _teams)
  259.         {
  260.              _allteams.add(party);
  261.             for (L2PcInstance player : party.getPartyMembers())
  262.             {
  263.                 player.addNotifyQuestOfDeath(player.getQuestState(getName()));
  264.                 player.stopAllEffectsExceptThoseThatLastThroughDeath();
  265.                 player.setCurrentCp(player.getMaxCp());
  266.                 player.setCurrentMp(player.getMaxMp());
  267.                 player.setCurrentHp(player.getMaxHp());
  268.                 player.startAbnormalEffect(AbnormalEffect.HOLD_2);
  269.                 player.setIsParalyzed(true);
  270.                 player.startParalyze();
  271.                 player.teleToLocation(149375, 47544, -3413);
  272.             }
  273.         }
  274.        
  275.         // Chose 2 teams and start fight
  276.         while (_teams.size() > 1)
  277.         {
  278.             while (_teams.size() > 1)
  279.             {
  280.                 choseTeamsAndStartFight();
  281.                
  282.                 if (_teams.size() == 1)
  283.                 {
  284.                     _winners.add(_teams.get(0));
  285.                 }
  286.             }
  287.            
  288.             _teams.removeAll(_teams);
  289.             for (L2Party _party : _winners)
  290.                 _teams.add(_party);
  291.             _winners.clear();
  292.         }
  293.         Announcements.getInstance().announceToAll("Winner is " + _teams.get(0).getLeader().getName() + "'s party");
  294.        
  295.         eventStop();
  296.     }
  297.    
  298.     private void choseTeamsAndStartFight()
  299.     {
  300.        
  301.         while (_team1 == null || _team2 == null)
  302.         {
  303.             _team1 = _teams.get(rnd.nextInt(_teams.size()));
  304.             _team2 = _teams.get(rnd.nextInt(_teams.size()));
  305.             if (_team2 == _team1)
  306.                 _team2 = null;
  307.             if (_winners.contains(_team1) || _losers.contains(_team1))
  308.                 _team1 = null;
  309.             if (_winners.contains(_team2) || _losers.contains(_team2))
  310.                 _team2 = null;
  311.         }
  312.        
  313.         for (L2PcInstance player : _team1.getPartyMembers())
  314.         {
  315.             player.stopAllEffectsExceptThoseThatLastThroughDeath();
  316.             player.teleToLocation(148839 + rnd.nextInt(5), 46741 + rnd.nextInt(5), -3413);
  317.            
  318.         }
  319.         for (L2PcInstance player : _team2.getPartyMembers())
  320.         {
  321.             player.stopAllEffectsExceptThoseThatLastThroughDeath();
  322.             player.teleToLocation(149847 + rnd.nextInt(5), 46684 + rnd.nextInt(5), -3413);
  323.            
  324.         }
  325.         _team1.getPartyMembers().get(0).stopAbnormalEffect(AbnormalEffect.HOLD_2);
  326.         _team2.getPartyMembers().get(0).stopAbnormalEffect(AbnormalEffect.HOLD_2);
  327.        
  328.         _state = EventState.FIGHT;
  329.        
  330.         while (_state == EventState.FIGHT)
  331.         {
  332.            
  333.         }
  334.        
  335.     }
  336.    
  337.     @Override
  338.     public String onDeath(L2Character killer, L2Character victim, QuestState qs)
  339.     {
  340.         whoWon(killer, victim);
  341.        
  342.         _state = EventState.WAIT;
  343.         return super.onDeath(killer, victim, qs);
  344.     }
  345.    
  346.     private String whoWon(L2Character killer, L2Character victim)
  347.     {
  348.         // Team 1 win
  349.         if (_team1.getPartyMembers().contains(killer))
  350.         {
  351.             for (final L2Character _char : _team2.getPartyMembers())
  352.             {
  353.                 if (!_char.isDead())
  354.                 {
  355.                     _team2.getPartyMembers().get(1).stopAbnormalEffect(AbnormalEffect.HOLD_2);
  356.                     return "";
  357.                 }
  358.             }
  359.            
  360.             ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  361.             {
  362.                 public void run()
  363.                 {
  364.                     for (final L2Character _char : _team1.getPartyMembers())
  365.                     {
  366.                        
  367.                         if (_char.isDead())
  368.                             _char.doRevive();
  369.                        
  370.                         _char.startAbnormalEffect(AbnormalEffect.HOLD_2);
  371.                         _char.setIsParalyzed(true);
  372.                         _char.startParalyze();
  373.                         _char.teleToLocation(149375, 47544, -3413);
  374.                         SkillTable.getInstance().getInfo(1323, 1).getEffects(null, _char);
  375.                        
  376.                     }
  377.                     _teams.remove(_team2);
  378.                     _teams.remove(_team1);
  379.                     _losers.add(_team2);
  380.                     _winners.add(_team1);
  381.                 }
  382.             }, 2 * 1000);
  383.            
  384.         }
  385.        
  386.         // Team 2 win
  387.         if (_team2.getPartyMembers().contains(killer))
  388.         {
  389.             for (final L2Character _char : _team1.getPartyMembers())
  390.             {
  391.                 if (!_char.isDead())
  392.                 {
  393.                     _team1.getPartyMembers().get(1).stopAbnormalEffect(AbnormalEffect.HOLD_2);
  394.                     return "";
  395.                 }
  396.             }
  397.            
  398.             ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  399.             {
  400.                 public void run()
  401.                 {
  402.                     for (final L2Character _char : _team2.getPartyMembers())
  403.                     {
  404.                        
  405.                         if (_char.isDead())
  406.                             _char.doRevive();
  407.                        
  408.                         _char.startAbnormalEffect(AbnormalEffect.HOLD_2);
  409.                         _char.setIsParalyzed(true);
  410.                         _char.startParalyze();
  411.                         _char.teleToLocation(149375, 47544, -3413);
  412.                         SkillTable.getInstance().getInfo(1323, 1).getEffects(null, _char);
  413.                        
  414.                     }
  415.                     _teams.remove(_team1);
  416.                     _teams.remove(_team2);
  417.                     _losers.add(_team1);
  418.                     _winners.add(_team2);
  419.                 }
  420.             }, 2 * 1000);
  421.            
  422.         }
  423.        
  424.         return "";
  425.     }
  426.    
  427. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement