Advertisement
warc222

LastHero Event By Ventic

Sep 17th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.76 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. }
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335. ### Eclipse Workspace Patch 1.0
  336. #P L2jFrozen_GameServer
  337. Index: head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/event.java
  338. ===================================================================
  339. --- head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/event.java (revision 0)
  340. +++ head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/event.java (revision 0)
  341. @@ -0,0 +1,27 @@
  342. +package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;
  343. +
  344. +import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
  345. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  346. +import com.l2jfrozen.gameserver.model.entity.LHE;
  347. +
  348. +public class event implements IVoicedCommandHandler
  349. +{
  350. + private static final String[] _voicedCommands = { "register", "leave" };
  351. + private LHE lhe;
  352. +
  353. + @Override
  354. + public boolean useVoicedCommand(String command, L2PcInstance activeChar,String target)
  355. + {
  356. + if (command.equals("register"))
  357. + lhe.register(activeChar);
  358. + if (command.equals("leave"))
  359. + lhe.unregister(activeChar);
  360. + return true;
  361. + }
  362. +
  363. + @Override
  364. + public String[] getVoicedCommandList()
  365. + {
  366. + return _voicedCommands;
  367. + }
  368. +}
  369. \ No newline at end of file
  370. Index: head-src/com/l2jfrozen/gameserver/model/entity/LHE.java
  371. ===================================================================
  372. --- head-src/com/l2jfrozen/gameserver/model/entity/LHE.java (revision 0)
  373. +++ head-src/com/l2jfrozen/gameserver/model/entity/LHE.java (revision 0)
  374. @@ -0,0 +1,264 @@
  375. +/* This program is free software; you can redistribute it and/or modify
  376. + * it under the terms of the GNU General Public License as published by
  377. + * the Free Software Foundation; either version 2, or (at your option)
  378. + * any later version.
  379. + *
  380. + * This program is distributed in the hope that it will be useful,
  381. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  382. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  383. + * GNU General Public License for more details.
  384. + *
  385. + * You should have received a copy of the GNU General Public License
  386. + * along with this program; if not, write to the Free Software
  387. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  388. + * 02111-1307, USA.
  389. + *
  390. + * http://www.gnu.org/copyleft/gpl.html
  391. + */
  392. +package com.l2jfrozen.gameserver.model.entity;
  393. +
  394. +import java.util.Collection;
  395. +
  396. +import javolution.util.FastList;
  397. +
  398. +import com.l2jfrozen.gameserver.model.L2World;
  399. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  400. +import com.l2jfrozen.gameserver.network.clientpackets.Say2;
  401. +import com.l2jfrozen.gameserver.network.serverpackets.CreatureSay;
  402. +import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
  403. +
  404. +/**
  405. + *
  406. + * @author Ventic
  407. + */
  408. +public class LHE
  409. +{
  410. + public static FastList<L2PcInstance> _players = new FastList<L2PcInstance>();
  411. + public L2PcInstance winner = null,loser = null, player1 = null, player2 = null;
  412. + public static State state = State.INACTIVE;
  413. + public static enum State { INACTIVE, REGISTERING, TELEPORTING, REWARDING, FIGHTING }
  414. +
  415. + public class Task implements Runnable
  416. + {
  417. + public void run()
  418. + {
  419. + if (state != State.INACTIVE)
  420. + {
  421. + return;
  422. + }
  423. + handle();
  424. + }
  425. + }
  426. +
  427. + public void handle()
  428. + {
  429. + GlobalMessage("Registrations opened for 5 minutes");
  430. + state = State.REGISTERING;
  431. + wait(5);
  432. + GlobalMessage("You will be moved to coliseum in 2 minutes");
  433. + wait(2);
  434. + state = State.TELEPORTING;
  435. + teleport(false);
  436. + GlobalMessage("You have 45 seconds to get prepared");
  437. + waitSecs(45);
  438. + prepare();
  439. + GlobalMessage("Match started");
  440. + start();
  441. + if (!(state == State.INACTIVE))
  442. + {
  443. + while (state == State.REWARDING)
  444. + {
  445. + endAndReward();
  446. + teleport(true);
  447. + }
  448. + }
  449. + clear();
  450. + }
  451. +
  452. + public void teleport(boolean back)
  453. + {
  454. + if (!back)
  455. + {
  456. + for (L2PcInstance p : _players)
  457. + {
  458. + p.teleToLocation(0, 0, 0);
  459. + p.sendMessage("You have been moved to coliseum");
  460. + }
  461. + }
  462. + else
  463. + {
  464. + for (L2PcInstance p : _players)
  465. + {
  466. + p.teleToLocation(0, 0, 0);
  467. + p.sendMessage("You have been moved to giran");
  468. + }
  469. + }
  470. + }
  471. +
  472. + public void register(L2PcInstance p)
  473. + {
  474. + state = State.REGISTERING;
  475. +
  476. + if (!p.isHero())
  477. + {
  478. + p.sendMessage("Only heroes can register");
  479. + return;
  480. + }
  481. + if (_players.contains(p))
  482. + {
  483. + p.sendMessage("You have already register");
  484. + return;
  485. + }
  486. + if (state != State.REGISTERING)
  487. + {
  488. + p.sendMessage("Can't register now");
  489. + return;
  490. + }
  491. + if (p.isInOlympiadMode())
  492. + {
  493. + p.sendMessage("You can't register while you have register for olympiad match");
  494. + return;
  495. + }
  496. + if (_players.size() == 2)
  497. + {
  498. + p.sendMessage("Event is full");
  499. + return;
  500. + }
  501. +
  502. + _players.add(p);
  503. + p.sendMessage("Succesfully registered");
  504. + p.inLHE = true;
  505. + }
  506. +
  507. + public void unregister(L2PcInstance p)
  508. + {
  509. + if (!_players.contains(p))
  510. + {
  511. + p.sendMessage("You have already unregister");
  512. + return;
  513. + }
  514. + if (state != State.REGISTERING)
  515. + {
  516. + p.sendMessage("You can't unregister while match is about to begin");
  517. + return;
  518. + }
  519. +
  520. + _players.remove(p);
  521. + p.sendMessage("Succesfully unregistered");
  522. + p.inLHE = false;
  523. + }
  524. +
  525. + public void prepare()
  526. + {
  527. + for (L2PcInstance p : _players)
  528. + {
  529. + p.setTitle("LHE");
  530. + p.stopAllEffects();
  531. + p.setIsRooted(true);
  532. + p.sendMessage("You have 45 seconds to get prepared");
  533. + }
  534. + }
  535. +
  536. + public void start()
  537. + {
  538. + state = State.FIGHTING;
  539. +
  540. + for (L2PcInstance p : _players)
  541. + {
  542. + p.stopRooting(null);
  543. + p.sendMessage("Go go go,start fighting");
  544. + }
  545. + }
  546. +
  547. + public void endAndReward()
  548. + {
  549. + state = State.REWARDING;
  550. +
  551. + int i = 0;
  552. + while (i < _players.size())
  553. + {
  554. + player1 = _players.getFirst();
  555. + player2 = _players.getLast();
  556. + i++;
  557. + }
  558. + if (player1.isDead())
  559. + {
  560. + winner = player2;
  561. + loser = player1;
  562. + if (winner != null)
  563. + {
  564. + winner.getInventory().addItem("Event", 3470, 1, winner, null);
  565. + }
  566. + }
  567. + if (player2.isDead())
  568. + {
  569. + winner = player1;
  570. + loser = player2;
  571. + if (winner != null)
  572. + {
  573. + winner.getInventory().addItem("Event", 3470, 1, winner, null);
  574. + }
  575. + }
  576. + }
  577. +
  578. + public void clear()
  579. + {
  580. + _players.clear();
  581. + player1 = null;
  582. + player2 = null;
  583. + winner = null;
  584. + loser = null;
  585. + state = State.INACTIVE;
  586. + }
  587. +
  588. + public void GlobalMessage(String msg)
  589. + {
  590. + Collection<L2PcInstance> plrs = L2World.getInstance().getAllPlayers();
  591. + CreatureSay cs = new CreatureSay(1, Say2.ANNOUNCEMENT, "LastHero Event:", msg);
  592. +
  593. + for (L2PcInstance p : plrs)
  594. + {
  595. + p.sendPacket(cs);
  596. + }
  597. + }
  598. +
  599. + private LHE()
  600. + {
  601. + ThreadPoolManager.getInstance().scheduleGeneral(new Task(), 7200000);
  602. + }
  603. +
  604. + public void waitSecs(int i)
  605. + {
  606. + try
  607. + {
  608. + Thread.sleep(i * 1000);
  609. + }
  610. + catch (InterruptedException ie)
  611. + {
  612. + ie.printStackTrace();
  613. + }
  614. + }
  615. +
  616. + public void wait(int i)
  617. + {
  618. + try
  619. + {
  620. + Thread.sleep(i * 60000);
  621. + }
  622. + catch (InterruptedException ie)
  623. + {
  624. + ie.printStackTrace();
  625. + }
  626. + }
  627. +
  628. + public static LHE getInstance()
  629. + {
  630. + return SingletonHolder._instance;
  631. + }
  632. +
  633. + private static class SingletonHolder
  634. + {
  635. + @SuppressWarnings("synthetic-access")
  636. + protected static final LHE _instance = new LHE();
  637. + }
  638. +}
  639. \ No newline at end of file
  640. Index: head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java
  641. ===================================================================
  642. --- head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java (revision 986)
  643. +++ head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java (working copy)
  644. @@ -37,6 +37,7 @@
  645. import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.VersionCmd;
  646. import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.Voting;
  647. import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.Wedding;
  648. +import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.event;
  649.  
  650. /**
  651. * This class ...
  652. @@ -89,6 +90,7 @@
  653. if (Config.L2JMOD_ALLOW_WEDDING)
  654. {
  655. registerVoicedCommandHandler(new Wedding());
  656. + registerVoicedCommandHandler(new event());
  657. }
  658.  
  659. registerVoicedCommandHandler(new StatsCmd());
  660. Index: head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java
  661. ===================================================================
  662. --- head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java (revision 986)
  663. +++ head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java (working copy)
  664. @@ -246,6 +246,8 @@
  665. */
  666. public final class L2PcInstance extends L2PlayableInstance
  667. {
  668. + public boolean inLHE = false;
  669. +
  670. /** The Constant RESTORE_SKILLS_FOR_CHAR. */
  671. private static final String RESTORE_SKILLS_FOR_CHAR = "SELECT skill_id,skill_level FROM character_skills WHERE char_obj_id=? AND class_index=?";
  672.  
  673. @@ -15636,12 +15638,12 @@
  674. revalidateZone(true);
  675.  
  676. notifyFriends(false);
  677. -
  678. +
  679. // Fix against exploit on anti-target on login
  680. decayMe();
  681. spawnMe();
  682. broadcastUserInfo();
  683. -
  684. +
  685. }
  686.  
  687. /**
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement