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

    • IMPORTANT INFO: In a few days, I will switch to completely new code, written from scratch with a new download system, patch building and management system. The Updater will become true 2026 code with "foolproof systems". I'm going to create a Discord server for customers to request new ideas and features. FIRST CUSTOMERS ARE ALREADY USING THE NEW UPDATER ON LIVE SERVERS! Watch this topic for upcoming info because the new updater is around the corner! Yes, you can still use self-update on the previous updater! No, the new updater won't be compatible with the old patch system! A new build is required, but players who already have game files won't have to download the entire patch again! New templates and updates to existing templates are coming soon! Sneak peek:  
    • i used guytis IL project and source. i found in his project there are 3 Client version source... 1,CliExt_H5   --->this one cant be compiled in VS2005,i did know why..is it for H5 client? 2,CliExtNew  --->this one is IL version ,but when i compiled it and use it.player cant login game,MD5Checksum wrong.i check the source code,but not found any hints. 3,L2Server    --->this one for HB client?im not sure...   so my question is what are the differences between these three versions of cliext.dll?how can i fix the issue of the MD5Checksum not matching problem?   01/29/2026 21:04:11.366, [CCliExt::HandleCheckSum] Invalid Checksum[1130415144] vs [-721420287] packet[dd] len[29] sum[2698] key[30] HWID[] Account[]! 01/29/2026 21:04:11.366, SocketLimiter::UserSocketBadunknownprotocol 11111111111 01/29/2026 21:04:11.366, [usersocket]unknown protocol from ip[113.137.149.115]!      
    • ## [1.4.1] - 2026-01-29   ### ✨ New Features - **Short Description**: Server owners can add a short tagline (up to 240 characters) on the server info page, under the "Online" status. It appears in the server list (By Votes) for VIP, Gold VIP, and Pinned servers so players see a brief summary at a glance.   ### 🔄 Improvements - **Server Info Page**: Description field is limited to 3000 characters with a character counter; the textarea is vertically resizable. A second **Save Changes** button was added at the bottom (after the description) for easier saving. - **Server Name**: In My Servers → Edit, the server name is read-only and can no longer be changed (avoids accidental changes and naming conflicts). - **Server Rows (By Votes)**: Short descriptions wrap correctly and no longer affect row height; long text is clipped to two lines so the list stays tidy and consistent.   ---
    • @Celestine  sorry for mu question , and post it's to old but i want to ask  ?   do you have uncrypted interface x dat of this interface? i want to add custom autofarm button but when i open it with xdat say file seems  to be  encrypted. thanks!
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..