Jump to content
  • 0

Question

Posted (edited)

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

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Hello everyone, we are one of the top gaming currency stores. We work exclusively with top projects. If you are interested in anything like Adena, Coins, Equip, write to us Discord - pchelacoin Telegram - https://t.me/ipchelacoin BOHPTS, KETRAWARS, EURO-PVP, L2REBORN, E-GLOBAL, LA2DREAM TOP PRICE !!!!!!!
    • L2Elixir – Patch 4 Is Live!   We’re working non-stop, day and night, to deliver the best possible quality and bring back what made L2Elixir special. This project is built with passion, not shortcuts — for the old-school players who remember, and the new ones who want to experience it properly. Thank you for being part of the journey. Together, we’re making L2Elixir great again ❤️ The legends never fade.    ⚙️ General Enabled Class Change service (same class type only) ALT + B → Services → Character Development Enabled Shift + Click on Treasure Chests Players can now identify real chests (Adena, scroll drops) and use Key / Unlock Event deaths now cancel only debuffs, All self buffs are preserved, fixes issues with Root and similar effects Bladedancer class can now log in even when Max Clients (2) is reached. Since an active Bladedancer is not available for every damage dealer and some players tried to abuse this via VPN or a second PC, this feature was added to keep things fair. protections applies, requires testing!    🎒 Items Crystallizing enchanted items now gives the correct increased crystal amount (retail-like behavior) Removed Agathion Seal Bracelet: Rudolph from Santa rewards (Gracia Final item) Added Dualsword Craft Stamp into Milestone Exchange list    🧙 Skills Fixed Banish Undead lethal chance Hot Springs Malaria and similar effects now level up faster while being attacked
    • thats new SEO level tricks you know nothing of noob - bottom line: exposed.
    • Warning: This guy is a big scammer, trying to sell everything, advertising for servers etc. That's his mail address evgesha.nrnr@gmail.com , stay away!   @Atom @Celestine
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock