Advertisement
Guest User

LastHero Event By Ventic

a guest
Jul 27th, 2011
1,563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.53 KB | None | 0 0
  1. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  2. ===================================================================
  3. --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java   (revision 72)
  4. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java   (working copy)
  5. @@ -206,6 +206,8 @@
  6.   */
  7.  public final class L2PcInstance extends L2Playable
  8.  {
  9. +   public boolean inLHE = false;
  10. +  
  11.     private static final String RESTORE_SKILLS_FOR_CHAR = "SELECT skill_id,skill_level FROM character_skills WHERE char_obj_id=? AND class_index=?";
  12.     private static final String ADD_NEW_SKILL = "INSERT INTO character_skills (char_obj_id,skill_id,skill_level,skill_name,class_index) VALUES (?,?,?,?,?)";
  13.     private static final String UPDATE_CHARACTER_SKILL_LEVEL = "UPDATE character_skills SET skill_level=? WHERE skill_id=? AND char_obj_id=? AND class_index=?";
  14. Index: java/net/sf/l2j/gameserver/model/entity/LHE.java
  15. ===================================================================
  16. --- java/net/sf/l2j/gameserver/model/entity/LHE.java    (revision 0)
  17. +++ java/net/sf/l2j/gameserver/model/entity/LHE.java    (revision 0)
  18. @@ -0,0 +1,263 @@
  19. +/* This program is free software; you can redistribute it and/or modify
  20. + * it under the terms of the GNU General Public License as published by
  21. + * the Free Software Foundation; either version 2, or (at your option)
  22. + * any later version.
  23. + *
  24. + * This program is distributed in the hope that it will be useful,
  25. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27. + * GNU General Public License for more details.
  28. + *
  29. + * You should have received a copy of the GNU General Public License
  30. + * along with this program; if not, write to the Free Software
  31. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  32. + * 02111-1307, USA.
  33. + *
  34. + * http://www.gnu.org/copyleft/gpl.html
  35. + */
  36. +package net.sf.l2j.gameserver.model.entity;
  37. +
  38. +import java.util.Collection;
  39. +
  40. +import javolution.util.FastList;
  41. +import net.sf.l2j.gameserver.ThreadPoolManager;
  42. +import net.sf.l2j.gameserver.clientpackets.Say2;
  43. +import net.sf.l2j.gameserver.model.L2World;
  44. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  45. +import net.sf.l2j.gameserver.serverpackets.CreatureSay;
  46. +
  47. +/**
  48. + *
  49. + * @author  Ventic
  50. + */
  51. +public class LHE
  52. +{
  53. +   public static FastList<L2PcInstance> _players = new FastList<L2PcInstance>();
  54. +   public L2PcInstance winner = null,loser = null, player1 = null, player2 = null;
  55. +   public static State state = State.INACTIVE;
  56. +   public static enum State  { INACTIVE, REGISTERING, TELEPORTING, REWARDING, FIGHTING }
  57. +  
  58. +   public class Task implements Runnable
  59. +   {
  60. +       public void run()
  61. +       {
  62. +           if (state != State.INACTIVE)
  63. +           {
  64. +               return;
  65. +           }
  66. +           handle();
  67. +       }
  68. +   }
  69. +  
  70. +   public void handle()
  71. +   {
  72. +       GlobalMessage("Registrations opened for 5 minutes");
  73. +       state = State.REGISTERING;
  74. +       wait(5);
  75. +       GlobalMessage("You will be moved to coliseum in 2 minutes");
  76. +       wait(2);
  77. +       state = State.TELEPORTING;
  78. +       teleport(false);
  79. +       GlobalMessage("You have 45 seconds to get prepared");
  80. +       waitSecs(45);
  81. +       prepare();
  82. +       GlobalMessage("Match started");
  83. +       start();
  84. +       if (!(state == State.INACTIVE))
  85. +       {
  86. +           while (state == State.REWARDING)
  87. +           {
  88. +               endAndReward();
  89. +               teleport(true);
  90. +           }
  91. +       }
  92. +       clear();
  93. +   }
  94. +  
  95. +   public void teleport(boolean back)
  96. +   {
  97. +       if (!back)
  98. +       {
  99. +           for (L2PcInstance p : _players)
  100. +           {
  101. +               p.teleToLocation(0, 0, 0);
  102. +               p.sendMessage("You have been moved to coliseum");
  103. +           }
  104. +       }
  105. +       else
  106. +       {
  107. +           for (L2PcInstance p : _players)
  108. +           {
  109. +               p.teleToLocation(0, 0, 0);
  110. +               p.sendMessage("You have been moved to giran");
  111. +           }
  112. +       }
  113. +   }
  114. +  
  115. +   public void register(L2PcInstance p)
  116. +   {
  117. +       state = State.REGISTERING;
  118. +      
  119. +       if (!p.isHero())
  120. +       {
  121. +           p.sendMessage("Only heroes can register");
  122. +           return;
  123. +       }
  124. +       if (_players.contains(p))
  125. +       {
  126. +           p.sendMessage("You have already register");
  127. +           return;
  128. +       }
  129. +       if (state != State.REGISTERING)
  130. +       {
  131. +           p.sendMessage("Can't register now");
  132. +           return;
  133. +       }
  134. +       if (p.isInOlympiadMode())
  135. +       {
  136. +           p.sendMessage("You can't register while you have register for olympiad match");
  137. +           return;
  138. +       }
  139. +       if (_players.size() == 2)
  140. +       {
  141. +           p.sendMessage("Event is full");
  142. +           return;
  143. +       }
  144. +      
  145. +       _players.add(p);
  146. +       p.sendMessage("Succesfully registered");
  147. +       p.inLHE = true;
  148. +   }
  149. +  
  150. +   public void unregister(L2PcInstance p)
  151. +   {
  152. +       if (!_players.contains(p))
  153. +       {
  154. +           p.sendMessage("You have already unregister");
  155. +           return;
  156. +       }
  157. +       if (state != State.REGISTERING)
  158. +       {
  159. +           p.sendMessage("You can't unregister while match is about to begin");
  160. +           return;
  161. +       }
  162. +      
  163. +       _players.remove(p);
  164. +       p.sendMessage("Succesfully unregistered");
  165. +       p.inLHE = false;
  166. +   }
  167. +  
  168. +   public void prepare()
  169. +   {
  170. +       for (L2PcInstance p : _players)
  171. +       {
  172. +           p.setTitle("LHE");
  173. +           p.stopAllEffects();
  174. +           p.setIsRooted(true);
  175. +           p.sendMessage("You have 45 seconds to get prepared");
  176. +       }
  177. +   }
  178. +  
  179. +   public void start()
  180. +   {
  181. +       state = State.FIGHTING;
  182. +      
  183. +       for (L2PcInstance p : _players)
  184. +       {
  185. +           p.stopRooting(null);
  186. +           p.sendMessage("Go go go,start fighting");
  187. +       }
  188. +   }
  189. +  
  190. +   public void endAndReward()
  191. +   {
  192. +       state = State.REWARDING;
  193. +      
  194. +       int i = 0;
  195. +       while (i < _players.size())
  196. +       {
  197. +           player1 = _players.getFirst();
  198. +           player2 = _players.getLast();
  199. +           i++;
  200. +       }
  201. +       if (player1.isDead())
  202. +       {
  203. +           winner = player2;
  204. +           loser = player1;
  205. +           if (winner != null)
  206. +           {
  207. +               winner.getInventory().addItem("Event", 3470, 1, winner, null);
  208. +           }
  209. +       }
  210. +       if (player2.isDead())
  211. +       {
  212. +           winner = player1;
  213. +           loser = player2;
  214. +           if (winner != null)
  215. +           {
  216. +               winner.getInventory().addItem("Event", 3470, 1, winner, null);
  217. +           }
  218. +       }
  219. +   }
  220. +  
  221. +   public void clear()
  222. +   {
  223. +       _players.clear();
  224. +       player1 = null;
  225. +       player2 = null;
  226. +       winner = null;
  227. +       loser = null;
  228. +       state = State.INACTIVE;
  229. +   }
  230. +  
  231. +   public void GlobalMessage(String msg)
  232. +   {
  233. +       Collection<L2PcInstance> plrs = L2World.getInstance().getAllPlayers().values();
  234. +       CreatureSay cs = new CreatureSay(1, Say2.ANNOUNCEMENT, "LastHero Event:", msg);
  235. +      
  236. +       for (L2PcInstance p : plrs)
  237. +       {
  238. +           p.sendPacket(cs);
  239. +       }
  240. +   }
  241. +  
  242. +   private LHE()
  243. +   {
  244. +       ThreadPoolManager.getInstance().scheduleGeneral(new Task(), 7200000);
  245. +   }
  246. +  
  247. +   public void waitSecs(int i)
  248. +   {
  249. +       try
  250. +       {
  251. +           Thread.sleep(i * 1000);
  252. +       }
  253. +       catch (InterruptedException ie)
  254. +       {
  255. +           ie.printStackTrace();
  256. +       }
  257. +   }
  258. +  
  259. +   public void wait(int i)
  260. +   {
  261. +       try
  262. +       {
  263. +           Thread.sleep(i * 60000);
  264. +       }
  265. +       catch (InterruptedException ie)
  266. +       {
  267. +           ie.printStackTrace();
  268. +       }
  269. +   }
  270. +  
  271. +   public static LHE getInstance()
  272. +   {
  273. +       return SingletonHolder._instance;
  274. +   }
  275. +  
  276. +   private static class SingletonHolder
  277. +   {
  278. +       @SuppressWarnings("synthetic-access")
  279. +       protected static final LHE _instance = new LHE();
  280. +   }
  281. +}
  282. Index: data/scripts/handlers/voicedcommandhandlers/event.java
  283. ===================================================================
  284. --- data/scripts/handlers/voicedcommandhandlers/event.java  (revision 0)
  285. +++ data/scripts/handlers/voicedcommandhandlers/event.java  (revision 0)
  286. @@ -0,0 +1,27 @@
  287. +package handlers.voicedcommandhandlers;
  288. +
  289. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  290. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  291. +import net.sf.l2j.gameserver.model.entity.LHE;
  292. +
  293. +public class event implements IVoicedCommandHandler
  294. +{
  295. +   private static final String[] _voicedCommands = { "register", "leave" };
  296. +   private LHE lhe;
  297. +
  298. +   @Override
  299. +   public boolean useVoicedCommand(String command, L2PcInstance activeChar,String target)
  300. +   {
  301. +       if (command.equals("register"))
  302. +           lhe.register(activeChar);
  303. +       if (command.equals("leave"))
  304. +           lhe.unregister(activeChar);
  305. +       return true;
  306. +   }
  307. +
  308. +   @Override
  309. +   public String[] getVoicedCommandList()
  310. +   {
  311. +       return _voicedCommands;
  312. +   }
  313. +}
  314. \ No newline at end of file
  315. Index: data/scripts/handlers/MasterHandler.java
  316. ===================================================================
  317. --- data/scripts/handlers/MasterHandler.java    (revision 72)
  318. +++ data/scripts/handlers/MasterHandler.java    (working copy)
  319. @@ -110,6 +110,7 @@
  320.     {
  321.         if (Config.L2JMOD_ALLOW_WEDDING)
  322.             VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new Wedding());
  323. +           VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new event());
  324.         _log.config("Loaded " + VoicedCommandHandler.getInstance().size() + " VoicedCommandHandlers");
  325.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement