Jump to content
  • 0

HighRate Event


xfx4Mighty

Question

Greetings to all, I moved the HighRate event, the mobs spawn, but the mobs do not appear after death

/*
 * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
 */
package net.sf.l2j.highrate.event;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Properties;
import java.util.concurrent.Future;
import java.util.logging.Logger;

import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.datatables.NpcTable;
import net.sf.l2j.gameserver.model.L2Spawn;
import net.sf.l2j.gameserver.model.Location;
import net.sf.l2j.gameserver.model.actor.L2Npc;
import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
import net.sf.l2j.gameserver.util.Broadcast;
import net.sf.l2j.highrate.config.ConfigExtender;
import net.sf.l2j.highrate.instance.Instance;
import net.sf.l2j.highrate.instance.InstanceManager;
import net.sf.l2j.highrate.instance.InstanceMap;

/**
 * @author Trance
 * @skype chr.trance
 */
public class HighRate
{
	private static final Logger log = Logger.getLogger(HighRate.class.getName());
	
	private boolean active;
	
	private String start, end;
	private Calendar scheduledStart, scheduledEnd;
	private Future<?> startAt, endAt;
	private Instance world;
//	private Period _state;
	
	public static boolean Enabled;
	
	private static final HighRate instance = new HighRate();
	
	private final ArrayList<HighRateNpcInfo> npcs = new ArrayList<>();
	
//	private static enum Period
//	{
//		BEGIN,
//		END,
//		CANCELLED
//	}
	
	public static HighRate getInstance()
	{
		return instance;
	}
	
	public static void startUp()
	{
		if (Enabled)
		{
			instance.onLoad();
			log.info("HighRate event has been loaded.");
		}
	}
	
	protected void onLoad()
	{
		ThreadPoolManager tp = ThreadPoolManager.getInstance();
		
		startAt = tp.scheduleGeneral(new Runnable()
		{
			@Override
			public void run()
			{
				onStart();
			};
		}, scheduledStart.getTimeInMillis() - System.currentTimeMillis());
		
		endAt = tp.scheduleGeneral(new Runnable()
		{
			@Override
			public void run()
			{
				onEnd();
			}
		}, scheduledEnd.getTimeInMillis() - System.currentTimeMillis());
	}
	
	protected void onStart()
	{
//		_state = Period.BEGIN;
//		announceHighRate();
		Broadcast.announceToOnlinePlayers("HighRate: The event has began.", true);
		
		world = InstanceManager.getInstance().create(InstanceMap.HighRateInstanceId);
		
		// when this hits, npcs get spawned
		for (HighRateNpcInfo info : npcs)
			info.spawn();
		
		NpcTable table = NpcTable.getInstance();
		
		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			PreparedStatement st = con.prepareStatement("SELECT npc_templateid, locx, locy, locz, heading, respawn_delay FROM spawnlist_highrate");
			
			ResultSet rs = st.executeQuery();
			
			while (rs.next())
			{
				int pointer = 1;
				
				int npcId = rs.getInt(pointer++);
				int locX = rs.getInt(pointer++);
				int locY = rs.getInt(pointer++);
				int locZ = rs.getInt(pointer++);
				int heading = rs.getInt("heading");
				int respawn_delay = rs.getInt("respawn_delay");
				
				L2NpcTemplate tp = table.getTemplate(npcId);
				//L2NpcTemplate tp = NpcTable.getInstance().getTemplate(npcId);
				
				try
				{
					L2Spawn spawn = new L2Spawn(tp);
					spawn.setLocx(locX);
					spawn.setLocy(locY);
					spawn.setLocz(locZ);
					spawn.setHeading(0);
					spawn.setRespawnDelay(20);
					
					spawn.startRespawn();
					
					L2Npc npc = spawn.doSpawn();
					
					if (npc instanceof L2MonsterInstance)
						npc.setInstanceId(world.getInstanceId(), false);
					else
					{
						log.warning("Not work Spawn");
					}
				}
				else
				{
					log.warning("Notwork all spawn");
				}
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
		// flag it true, so we know its running
		active = true;
	}

	protected void onEnd()
	{
//		_state = Period.END;
//		announceHighRate();
		Broadcast.announceToOnlinePlayers("HighRate: The event has ended.", true);
		
		// unspawn everything
		if (active)
		{
			for (HighRateNpcInfo info : npcs)
				info.unSpawn();
			
			active = false;
			
			// teleport players back, cleanup everything else
			world.destroy();
			world = null;
		}
		
		// reschedule
		reschedule();
	}

	public void reload()
	{
		// reload the event, stop it if active
		stopEvent();
		
		ConfigExtender.processHighRate();
	}
	
	public void stopEvent()
	{
//		_state = Period.CANCELLED;
//		announceHighRate();
		Broadcast.announceToOnlinePlayers("HighRate: The event has been cancelled.", true);
		
		startAt.cancel(false);
		endAt.cancel(false);
		
		if (active)
			onEnd();
	}
	
	protected void reschedule()
	{
		String[] data = start.split("\\:");
		Calendar nc = Calendar.getInstance();
		nc.set(Calendar.HOUR_OF_DAY, Integer.parseInt(data[0]));
		nc.set(Calendar.MINUTE, Integer.parseInt(data[1]));
		
		data = end.split("\\:");
		Calendar ncEnd = Calendar.getInstance();
		ncEnd.set(Calendar.HOUR_OF_DAY, Integer.parseInt(data[0]));
		ncEnd.set(Calendar.MINUTE, Integer.parseInt(data[1]));
		
		if (nc.getTimeInMillis() < System.currentTimeMillis())
		{
			nc.set(Calendar.DAY_OF_MONTH, nc.get(Calendar.DAY_OF_MONTH) + 1);
			ncEnd.set(Calendar.DAY_OF_MONTH, nc.get(Calendar.DAY_OF_MONTH) + 1);
		}
		
		scheduledStart = nc;
		scheduledEnd = ncEnd;
		
		// If startAt is not set, that means the startup function has not been invoked yet.
		if (startAt != null)
		{
			if (!startAt.isDone())
				startAt.cancel(false);
			
			if (!endAt.isDone())
				startAt.cancel(false);
			
			onLoad();
		}
	}
	
	public static void parseConfig(Properties prop)
	{
		Enabled = Boolean.parseBoolean(prop.getProperty("HighRate", "false"));
		
		if (!Enabled)
			return;
		
		String start = prop.getProperty("HighRateLaunch");
		String end = prop.getProperty("HighRateEnd");
		
		if (start == null)
		{
			Enabled = false;
			log.warning("Failed configurating HighRate event, start time is invalid!");
		}
		
		instance.start = start;
		instance.end = end;
		
		instance.reschedule();
		
		// Spawns.
		String p = prop.getProperty("HighRateSpawns");
		p = p.trim();
		
		String[] hash = p.split("];");
		for (String string : hash)
		{
			string = string.replace('[', ' ');
			string = string.trim();
			
			String[] h = string.split("\\,");
			
			for (int i = 0; i < h.length; i++)
				h[i] = h[i].trim();
			
			int npcId = Integer.parseInt(h[0]);
			int x = Integer.parseInt(h[1]);
			int y = Integer.parseInt(h[2]);
			int z = Integer.parseInt(h[3]);
			int heading = Integer.parseInt(h[4]);
			
			L2NpcTemplate template = NpcTable.getInstance().getTemplate(npcId);
			
			if (template != null)
			{
				HighRateNpcInfo ni = new HighRateNpcInfo(template, new Location(x, y, z, heading));
				instance.npcs.add(ni);
			}
			else 
				log.warning("Cannot find npc template with id[" + npcId + "]. Skippng spawn!");
		}
	}
	
//	public final void announceHighRate()
//	{
//		switch (_state)
//		{
//			case BEGIN:
//				Broadcast.announceToOnlinePlayers("HighRate: The event has began.", true);
//				break;
//				
//			case END:
//				Broadcast.announceToOnlinePlayers("HighRate: The event has ended.", true);
//				break;
//				
//			case CANCELLED:
//				Broadcast.announceToOnlinePlayers("HighRate: The event has been cancelled.", true);
//				break;
//				
//			default:
//				log.warning("Something wrong with announceHighRate.");
//				break;
//		}
//	}
	
	public boolean isActive()
	{
		return active;
	}
}

L2jLisvus

Edited by xfx4Mighty
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • God gifted lost Lover Spells Caster Prof. Joseph to reunite you with your ex within a short period of time with too much love and respect than ever before. Many people still question whether love spells work or not, permanent or effective? This can be based from past experiences where they tried some spell casters but not fully satisfied with their results or the love spells worked for just a short period and sometimes even never saw any results. To avoid such situations you have to be careful with spell casters you approach, some are limited with certain Spiritual powers to cast good love spells to help people in their relationships or marriages. Many good love spell casters are out there in the world (Africa, Asia and so on) Yes, I Guarantee love spells really work, whether you are in a situation where you want to bring back your lost lover (lost lover spell), you want to get married to someone in a relationship(marriage spells),to increase love in your relationship (love affection spells) and many other related love spells, you will get HELP. It does not matter where you are or where your partner is, you don't have to be unhappy of a situation you can solve IMMEDIATELY, it is all about finding a GOOD, TRUE and REAL love spell caster with super natural powers in spell castings to change your love life forever. PROF. JOSEPH is a Celebrated AWARD WINNING Love Spell Caster with 50years of Casting Experience whose works have won HIM friendship all over the world from the people HE met and changed their lives. To know more about spells and his wonderful works. For reading world wide!. N.B. ALL HEART BROKEN PEOPLE & THOSE WHO HAVE BEEN SCAMMED ALOT BY FAKE ONLINE CASTERS ALL OVER THE WORLD PLEASE DON'T LOOSE HOPE,FEEL FREE TO CONSULT ME FOR INSTANT READING AND REUNION WITH YOUR EX LOVER NO MATTER THE SITUATION IN 12 HOURS ONLY. Call/WhatsApp: +27630699577 Email: babajoseph473@gmail. com Website: https://traditional-herbalist-healer.webnode.com
    • God gifted lost Lover Spells Caster Prof. Joseph to reunite you with your ex within a short period of time with too much love and respect than ever before. Many people still question whether love spells work or not, permanent or effective? This can be based from past experiences where they tried some spell casters but not fully satisfied with their results or the love spells worked for just a short period and sometimes even never saw any results. To avoid such situations you have to be careful with spell casters you approach, some are limited with certain Spiritual powers to cast good love spells to help people in their relationships or marriages. Many good love spell casters are out there in the world (Africa, Asia and so on) Yes, I Guarantee love spells really work, whether you are in a situation where you want to bring back your lost lover (lost lover spell), you want to get married to someone in a relationship(marriage spells),to increase love in your relationship (love affection spells) and many other related love spells, you will get HELP. It does not matter where you are or where your partner is, you don't have to be unhappy of a situation you can solve IMMEDIATELY, it is all about finding a GOOD, TRUE and REAL love spell caster with super natural powers in spell castings to change your love life forever. PROF. JOSEPH is a Celebrated AWARD WINNING Love Spell Caster with 50years of Casting Experience whose works have won HIM friendship all over the world from the people HE met and changed their lives. To know more about spells and his wonderful works. For reading world wide!. N.B. ALL HEART BROKEN PEOPLE & THOSE WHO HAVE BEEN SCAMMED ALOT BY FAKE ONLINE CASTERS ALL OVER THE WORLD PLEASE DON'T LOOSE HOPE,FEEL FREE TO CONSULT ME FOR INSTANT READING AND REUNION WITH YOUR EX LOVER NO MATTER THE SITUATION IN 12 HOURS ONLY. Call/WhatsApp: +27630699577 Email: babajoseph473@gmail. com Website: https://traditional-herbalist-healer.webnode.com
    • I would like to know if anyone has an interface for H5 that shows the debuff's in TargetStatusWnd or if they have the code for TargetStatusWnd.uc and TargetStatusWnd in interface.xdat with that future. I'm trying to implement this function in my interface, but I can't find any interface that has it to view the code. Thank you very much to this excellent community.
    • DISCORD : utchiha_market telegram  https://t.me/utchiha_market SELLIX STORE : https://utchiha-market.mysellix.io/ Join our server for more products : https://discord.gg/hoodservices
  • Topics

×
×
  • Create New...