Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * http://www.gnu.org/copyleft/gpl.html
- */
- package net.sf.l2j.gameserver.model.entity;
- import java.util.Collection;
- import java.util.Vector;
- import net.sf.l2j.gameserver.ThreadPoolManager;
- import net.sf.l2j.gameserver.clientpackets.Say2;
- import net.sf.l2j.gameserver.model.L2World;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.serverpackets.CreatureSay;
- import net.sf.l2j.util.Rnd;
- /**
- *
- * @author Ventic
- */
- public class LastHero
- {
- public static Vector<L2PcInstance> _players = new Vector<L2PcInstance>();
- public L2PcInstance winner = null,loser = null, player1 = null, player2 = null;
- public static State state = State.INACTIVE;
- public static enum State { INACTIVE, REGISTERING, TELEPORTING, REWARDING, FIGHTING }
- public class Task implements Runnable
- {
- public void run()
- {
- if (state != State.INACTIVE)
- {
- return;
- }
- handle();
- }
- }
- public void handle()
- {
- GlobalMessage("Registrations opened for 5 minutes");
- state = State.REGISTERING;
- wait(5);
- getPlayers();
- GlobalMessage("You will be moved to coliseum in 2 minutes");
- wait(2);
- state = State.TELEPORTING;
- teleport(false);
- GlobalMessage("You have 45 seconds to get prepared");
- waitSecs(45);
- prepare();
- GlobalMessage("Match started");
- start();
- if (!(state == State.INACTIVE))
- {
- while (state == State.REWARDING)
- {
- endAndReward();
- teleport(true);
- }
- }
- clear();
- }
- public void getPlayers()
- {
- if (_players.size() >= 2)
- {
- player1 = _players.elementAt(Rnd.get(_players.size()-1));
- _players.remove(player1);
- player2 = _players.elementAt(Rnd.get(_players.size()-1));
- _players.clear();
- _players.add(player1);
- _players.add(player2);
- player1.sendMessage("You have been chosen for the next LastHero match. Your enemy: "+player2.getName()+".");
- player1.sendMessage("You will be teleported to Coliseum in 2 minutes.");
- player2.sendMessage("You have been chosen for the next LastHero match. Your enemy: "+player1.getName()+".");
- player2.sendMessage("You will be teleported to Coliseum in 2 minutes.");
- }
- else
- {
- if (_players.size() >= 0)
- {
- for (L2PcInstance p : _players)
- {
- p.sendMessage("The match was cancelled due to lack of participation.");
- p.inLHE = false;
- }
- }
- state = State.INACTIVE;
- _players.clear();
- }
- }
- public void teleport(boolean back)
- {
- if (!back)
- {
- for (L2PcInstance p : _players)
- {
- p.teleToLocation(0, 0, 0);
- p.sendMessage("You have been moved to coliseum");
- }
- }
- else
- {
- for (L2PcInstance p : _players)
- {
- p.teleToLocation(0, 0, 0);
- p.sendMessage("You have been moved to giran");
- }
- }
- }
- public void register(L2PcInstance p)
- {
- state = State.REGISTERING;
- if (!p.isHero())
- {
- p.sendMessage("Only heroes can register");
- return;
- }
- if (_players.contains(p))
- {
- p.sendMessage("You have already register");
- return;
- }
- if (state != State.REGISTERING)
- {
- p.sendMessage("Can't register now");
- return;
- }
- if (p.isInOlympiadMode())
- {
- p.sendMessage("You can't register while you have register for olympiad match");
- return;
- }
- if (_players.size() == 2)
- {
- p.sendMessage("Event is full");
- return;
- }
- _players.add(p);
- p.sendMessage("Succesfully registered");
- p.inLHE = true;
- }
- public void unregister(L2PcInstance p)
- {
- if (!_players.contains(p))
- {
- p.sendMessage("You have already unregister");
- return;
- }
- if (state != State.REGISTERING)
- {
- p.sendMessage("You can't unregister while match is about to begin");
- return;
- }
- _players.remove(p);
- p.sendMessage("Succesfully unregistered");
- p.inLHE = false;
- }
- public void prepare()
- {
- for (L2PcInstance p : _players)
- {
- p.setTitle("LHE");
- p.stopAllEffects();
- p.setIsRooted(true);
- p.sendMessage("You have 45 seconds to get prepared");
- }
- }
- public void start()
- {
- state = State.FIGHTING;
- for (L2PcInstance p : _players)
- {
- p.stopRooting(null);
- p.sendMessage("Go go go,start fighting");
- }
- }
- public void endAndReward()
- {
- state = State.REWARDING;
- if (player1.isDead())
- {
- winner = player2;
- loser = player1;
- if (winner != null)
- {
- winner.getInventory().addItem("Event", 3470, 1, winner, null);
- }
- }
- if (player2.isDead())
- {
- winner = player1;
- loser = player2;
- if (winner != null)
- {
- winner.getInventory().addItem("Event", 3470, 1, winner, null);
- }
- }
- }
- public void clear()
- {
- _players.clear();
- player1 = null;
- player2 = null;
- winner = null;
- loser = null;
- state = State.INACTIVE;
- }
- public void GlobalMessage(String msg)
- {
- Collection<L2PcInstance> plrs = L2World.getInstance().getAllPlayers().values();
- CreatureSay cs = new CreatureSay(1, Say2.ANNOUNCEMENT, "LastHero Event:", msg);
- for (L2PcInstance p : plrs)
- {
- p.sendPacket(cs);
- }
- }
- private LastHero()
- {
- ThreadPoolManager.getInstance().scheduleGeneral(new Task(), 7200000);
- }
- public void waitSecs(int i)
- {
- try
- {
- Thread.sleep(i * 1000);
- }
- catch (InterruptedException ie)
- {
- ie.printStackTrace();
- }
- }
- public void wait(int i)
- {
- try
- {
- Thread.sleep(i * 60000);
- }
- catch (InterruptedException ie)
- {
- ie.printStackTrace();
- }
- }
- public static LastHero getInstance()
- {
- return SingletonHolder._instance;
- }
- private static class SingletonHolder
- {
- @SuppressWarnings("synthetic-access")
- protected static final LastHero _instance = new LastHero();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement