- Хроники
- Scions of Destiny
- Исходники
- Присутствуют
- Сборка
- l2jlisvus
Приветствую всех, перенес евент HighRate евент запускается мобы спавнятся вот только мобы после смерти не появляются
Java:
/*
* 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);
if (tp != null)
{
L2Spawn spawn = new L2Spawn(tp);
spawn.setLocx(locX);
spawn.setLocy(locY);
spawn.setLocz(locZ);
spawn.setHeading(heading);
spawn.setRespawnDelay(respawn_delay);
spawn.startRespawn();
L2Npc npc = spawn.doSpawn();
if (npc instanceof L2MonsterInstance)
npc.setInstanceId(world.getInstanceId(), false);
else
{
// err
}
}
else
{
// err
}
}
}
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;
}
}