Noticias:

No tienes permiso para ver los enlaces. Para poder verlos Registrate o Conectate.

Menú Principal

Evento Last Hero

Iniciado por Swarlog, Jul 15, 2025, 12:16 AM

Tema anterior - Siguiente tema

Swarlog

Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java	(revision 72)
+++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java	(working copy)
@@ -206,6 +206,8 @@
  */
 public final class L2PcInstance extends L2Playable
 {
+	public boolean inLHE = false;
+	
 	private static final String RESTORE_SKILLS_FOR_CHAR = "SELECT skill_id,skill_level FROM character_skills WHERE char_obj_id=? AND class_index=?";
 	private static final String ADD_NEW_SKILL = "INSERT INTO character_skills (char_obj_id,skill_id,skill_level,skill_name,class_index) VALUES (?,?,?,?,?)";
 	private static final String UPDATE_CHARACTER_SKILL_LEVEL = "UPDATE character_skills SET skill_level=? WHERE skill_id=? AND char_obj_id=? AND class_index=?";
Index: java/net/sf/l2j/gameserver/model/entity/LHE.java
===================================================================
--- java/net/sf/l2j/gameserver/model/entity/LHE.java	(revision 0)
+++ java/net/sf/l2j/gameserver/model/entity/LHE.java	(revision 0)
@@ -0,0 +1,263 @@
+/* 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 javolution.util.FastList;
+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;
+
+/**
+ *
+ * @author  Ventic
+ */
+public class LHE
+{
+	public static FastList<L2PcInstance> _players = new FastList<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);
+		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 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;
+		
+		int i = 0;
+		while (i < _players.size())
+		{
+			player1 = _players.getFirst();
+			player2 = _players.getLast();
+			i++;
+		}
+		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 LHE()
+	{
+		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 LHE getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
+	private static class SingletonHolder
+	{
+		@SuppressWarnings("synthetic-access")
+		protected static final LHE _instance = new LHE();
+	}
+}
Index: data/scripts/handlers/voicedcommandhandlers/event.java
===================================================================
--- data/scripts/handlers/voicedcommandhandlers/event.java	(revision 0)
+++ data/scripts/handlers/voicedcommandhandlers/event.java	(revision 0)
@@ -0,0 +1,27 @@
+package handlers.voicedcommandhandlers;
+
+import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.model.entity.LHE;
+
+public class event implements IVoicedCommandHandler
+{
+	private static final String[] _voicedCommands = { "register", "leave" };
+	private LHE lhe;
+
+	@Override
+	public boolean useVoicedCommand(String command, L2PcInstance activeChar,String target) 
+	{
+		if (command.equals("register"))
+			lhe.register(activeChar);
+		if (command.equals("leave"))
+			lhe.unregister(activeChar);
+		return true;
+	}
+
+	@Override
+	public String[] getVoicedCommandList() 
+	{
+		return _voicedCommands;
+	}
+}
\ No newline at end of file
Index: data/scripts/handlers/MasterHandler.java
===================================================================
--- data/scripts/handlers/MasterHandler.java	(revision 72)
+++ data/scripts/handlers/MasterHandler.java	(working copy)
@@ -110,6 +110,7 @@
 	{
 		if (Config.L2JMOD_ALLOW_WEDDING)
 			VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new Wedding());
+			VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new event());
 		_log.config("Loaded " + VoicedCommandHandler.getInstance().size() + " VoicedCommandHandlers");
 	}