Corrected and simplified NPC spawning methods.

This commit is contained in:
MobiusDevelopment
2020-02-01 23:10:25 +00:00
parent cb8ea6b22e
commit 723e2d3ff3
15 changed files with 152 additions and 246 deletions

View File

@@ -916,12 +916,10 @@ public class Antharas extends Quest
@Override
public String onAttack(NpcInstance npc, PlayerInstance attacker, int damage, boolean isPet)
{
if (((npc.getSpawn() != null) && !npc.getSpawn().isCustomBossInstance() && (npc.getNpcId() == 29019)) || (npc.getNpcId() == 29066) || (npc.getNpcId() == 29067) || (npc.getNpcId() == 29068))
if ((npc.getNpcId() == 29019) || (npc.getNpcId() == 29066) || (npc.getNpcId() == 29067) || (npc.getNpcId() == 29068))
{
_LastAction = System.currentTimeMillis();
/*
* if (GrandBossManager.getInstance().getBossStatus(_antharas.getNpcId()) != FIGHTING) { _Zone.oustAllPlayers(); } else
*/if (!FWA_OLDANTHARAS && (_mobsSpawnTask == null))
if (!FWA_OLDANTHARAS && (_mobsSpawnTask == null))
{
startMinionSpawns(npc.getNpcId());
}
@@ -960,8 +958,6 @@ public class Antharas extends Quest
{
npc.broadcastPacket(new PlaySound(1, "BS01_D", npc));
if (!npc.getSpawn().isCustomBossInstance())
{
_cubeSpawnTask = ThreadPool.schedule(new CubeSpawn(0), 10000);
GrandBossManager.getInstance().setBossStatus(npc.getNpcId(), DEAD);
final long respawnTime = (Config.ANTHARAS_RESP_FIRST + Rnd.get(Config.ANTHARAS_RESP_SECOND)) * 3600000;
@@ -971,7 +967,6 @@ public class Antharas extends Quest
info.set("respawn_time", (System.currentTimeMillis() + respawnTime));
GrandBossManager.getInstance().setStatSet(npc.getNpcId(), info);
}
}
else if (npc.getNpcId() == 29069)
{
final int countHPHerb = Rnd.get(6, 18);

View File

@@ -206,10 +206,7 @@ public class Baium extends Quest
// start monitoring baium's inactivity
_lastAttackVsBaiumTime = System.currentTimeMillis();
if (!npc.getSpawn().isCustomBossInstance())
{
startQuestTimer("baium_despawn", 60000, npc, null, true);
}
if (player != null)
{
@@ -420,8 +417,6 @@ public class Baium extends Quest
{
npc.broadcastPacket(new PlaySound(1, "BS01_D", npc));
if (!npc.getSpawn().isCustomBossInstance())
{
cancelQuestTimer("baium_despawn", npc, null);
// spawn the "Teleportation Cubic" for 15 minutes (to allow players to exit the lair)
addSpawn(29055, 115203, 16620, 10078, 0, false, 900000); // //should we teleport everyone out if the cubic despawns??
@@ -433,7 +428,6 @@ public class Baium extends Quest
final StatSet info = GrandBossManager.getInstance().getStatSet(LIVE_BAIUM);
info.set("respawn_time", System.currentTimeMillis() + respawnTime);
GrandBossManager.getInstance().setStatSet(LIVE_BAIUM, info);
}
for (NpcInstance minion : _minions)
{

View File

@@ -230,8 +230,6 @@ public class Core extends Quest
npc.broadcastPacket(new CreatureSay(npc.getObjectId(), 0, name, "......"));
_firstAttacked = false;
if (!npc.getSpawn().isCustomBossInstance())
{
addSpawn(31842, 16502, 110165, -6394, 0, false, 900000);
addSpawn(31842, 18948, 110166, -6397, 0, false, 900000);
GrandBossManager.getInstance().setBossStatus(CORE, DEAD);
@@ -245,7 +243,6 @@ public class Core extends Quest
startQuestTimer("despawn_minions", 20000, null, null);
cancelQuestTimers("spawn_minion");
}
}
else if ((GrandBossManager.getInstance().getBossStatus(CORE) == ALIVE) && _minions.contains(npc))
{
_minions.remove(npc);

View File

@@ -1725,8 +1725,6 @@ public class Frintezza extends Quest
startQuestTimer("morph_16", 0, npc, null);
}
else if ((npc.getNpcId() == SCARLET2) && (_onCheck == 1) && (status == FIGHTING))
{
if (!npc.getSpawn().isCustomBossInstance())
{
// cancelQuestTimer("loc_check");
cancelQuestTimer("spawn_minion", npc, null);
@@ -1745,7 +1743,6 @@ public class Frintezza extends Quest
info.set("respawn_time", System.currentTimeMillis() + respawnTime);
GrandBossManager.getInstance().setStatSet(FRINTEZZA, info);
}
}
else if (npc.getNpcId() == 18328)
{
_killHallAlarmDevice++;

View File

@@ -150,7 +150,7 @@ public class Orfen extends Quest
break;
}
double hp = -1;
if ((npc.getNpcId() == ORFEN) && !npc.getSpawn().isCustomBossInstance())
if (npc.getNpcId() == ORFEN)
{
hp = GrandBossManager.getInstance().getStatSet(ORFEN).getDouble("currentHP");
if (hp < npc.getCurrentHp())
@@ -237,8 +237,6 @@ public class Orfen extends Quest
{
npc.broadcastPacket(new PlaySound(1, "BS02_D", npc));
if (!npc.getSpawn().isCustomBossInstance())
{
GrandBossManager.getInstance().setBossStatus(ORFEN, DEAD);
// time is 48hour +/- 20hour
final long respawnTime = (Config.ORFEN_RESP_FIRST + Rnd.get(Config.ORFEN_RESP_SECOND)) * 3600000;
@@ -249,7 +247,6 @@ public class Orfen extends Quest
info.set("respawn_time", System.currentTimeMillis() + respawnTime);
GrandBossManager.getInstance().setStatSet(ORFEN, info);
}
}
return super.onKill(npc, killer, isPet);
}

View File

@@ -368,8 +368,6 @@ public class QueenAnt extends Quest
{
npc.broadcastPacket(new PlaySound(1, "BS02_D", npc));
if (!npc.getSpawn().isCustomBossInstance())
{
GrandBossManager.getInstance().setBossStatus(QUEEN, DEAD);
// time is 36hour +/- 17hour
final long respawnTime = (Config.QA_RESP_FIRST + Rnd.get(Config.QA_RESP_SECOND)) * 3600000;
@@ -385,7 +383,6 @@ public class QueenAnt extends Quest
final StatSet info = GrandBossManager.getInstance().getStatSet(QUEEN);
info.set("respawn_time", System.currentTimeMillis() + respawnTime);
GrandBossManager.getInstance().setStatSet(QUEEN, info);
}
startQuestTimer("DESPAWN_MINIONS", 10000, null, null);
}

View File

@@ -178,8 +178,7 @@ public class Valakas extends Quest
temp = (System.currentTimeMillis() - lastAttackTime);
if ((status == FIGHTING) && !npc.getSpawn().isCustomBossInstance() // if it's a custom spawn, dnt despawn it for inactivity
&& (temp > (Config.VALAKAS_DESPAWN_TIME * 60000))) // 15 mins by default
if ((status == FIGHTING) && (temp > (Config.VALAKAS_DESPAWN_TIME * 60000))) // 15 mins by default
{
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
@@ -320,9 +319,6 @@ public class Valakas extends Quest
else if (event.equals("1117"))
{
npc.broadcastPacket(new SpecialCamera(npc.getObjectId(), 1700, 10, 0, 3000, 250));
if (!npc.getSpawn().isCustomBossInstance())
{
addSpawn(31759, 212852, -114842, -1632, 0, false, 900000);
final int radius = 1500;
for (int i = 0; i < 20; i++)
@@ -332,7 +328,6 @@ public class Valakas extends Quest
addSpawn(31759, 212852 + x, -114842 + y, -1632, 0, false, 900000);
}
startQuestTimer("remove_players", 900000, null, null);
}
cancelQuestTimer("check_activity_and_do_actions", npc, null);
}
}
@@ -602,18 +597,14 @@ public class Valakas extends Quest
npc.broadcastPacket(new PlaySound(1, "B03_D", npc));
startQuestTimer("1111", 500, npc, null);
if (!npc.getSpawn().isCustomBossInstance())
{
GrandBossManager.getInstance().setBossStatus(VALAKAS, DEAD);
final long respawnTime = (Config.VALAKAS_RESP_FIRST + Rnd.get(Config.VALAKAS_RESP_SECOND)) * 3600000;
startQuestTimer("valakas_unlock", respawnTime, null, null);
// also save the respawn time so that the info is maintained past reboots
final StatSet info = GrandBossManager.getInstance().getStatSet(VALAKAS);
info.set("respawn_time", (System.currentTimeMillis() + respawnTime));
GrandBossManager.getInstance().setStatSet(VALAKAS, info);
}
return super.onKill(npc, killer, isPet);
}
@@ -1016,8 +1007,7 @@ public class Valakas extends Quest
int i1 = 0;
final Integer status = GrandBossManager.getInstance().getBossStatus(VALAKAS);
if ((status == FIGHTING) || npc.getSpawn().isCustomBossInstance())
if (status == FIGHTING)
{
if (npc.getCurrentHp() > ((npc.getMaxHp() * 1) / 4))
{
@@ -1524,7 +1514,7 @@ public class Valakas extends Quest
i_quest4 = ((1 * 1000) + Rnd.get(3000));
c_quest4 = player;
}
if ((status == FIGHTING) || (npc.getSpawn().isCustomBossInstance() && !npc.isInvul()))
if (status == FIGHTING)
{
getRandomSkill(npc);
}

View File

@@ -860,8 +860,6 @@ public class Zaken extends Quest
{
npc.broadcastPacket(new PlaySound(1, "BS02_D", npc));
if (!npc.getSpawn().isCustomBossInstance())
{
GrandBossManager.getInstance().setBossStatus(ZAKEN, DEAD);
// time is 36hour +/- 17hour
final long respawnTime = (Config.ZAKEN_RESP_FIRST + Rnd.get(Config.ZAKEN_RESP_SECOND)) * 3600000;
@@ -873,7 +871,6 @@ public class Zaken extends Quest
info.set("respawn_time", System.currentTimeMillis() + respawnTime);
GrandBossManager.getInstance().setStatSet(ZAKEN, info);
}
}
else if (status == ALIVE)
{
startQuestTimer("CreateOnePrivateEx", ((30 + Rnd.get(60)) * 1000), npc, null);

View File

@@ -276,7 +276,7 @@ public class SpawnTable
{
try (Connection con = DatabaseFactory.getConnection())
{
final PreparedStatement statement = con.prepareStatement("INSERT INTO " + (spawn.isCustom() ? "custom_spawnlist" : "spawnlist") + "(id,count,npc_templateid,locx,locy,locz,heading,respawn_delay,loc_id) values(?,?,?,?,?,?,?,?,?)");
final PreparedStatement statement = con.prepareStatement("INSERT INTO " + (Config.SAVE_GMSPAWN_ON_CUSTOM ? "custom_spawnlist" : "spawnlist") + "(id,count,npc_templateid,locx,locy,locz,heading,respawn_delay,loc_id) values(?,?,?,?,?,?,?,?,?)");
statement.setInt(1, spawn.getId());
statement.setInt(2, spawn.getAmount());
statement.setInt(3, spawn.getNpcId());
@@ -324,7 +324,7 @@ public class SpawnTable
{
try (Connection con = DatabaseFactory.getConnection())
{
final PreparedStatement statement = con.prepareStatement("DELETE FROM " + (spawn.isCustom() ? "custom_spawnlist" : "spawnlist") + " WHERE id=?");
final PreparedStatement statement = con.prepareStatement("DELETE FROM " + (Config.SAVE_GMSPAWN_ON_CUSTOM ? "custom_spawnlist" : "spawnlist") + " WHERE id=?");
statement.setInt(1, spawn.getId());
statement.execute();
statement.close();

View File

@@ -42,24 +42,8 @@ public class AdminDelete implements IAdminCommandHandler
public boolean useAdminCommand(String command, PlayerInstance activeChar)
{
if (command.equals("admin_delete"))
{
handleDelete(activeChar);
}
return true;
}
@Override
public String[] getAdminCommandList()
{
return ADMIN_COMMANDS;
}
// TODO: add possibility to delete any WorldObject (except PlayerInstance)
private void handleDelete(PlayerInstance activeChar)
{
final WorldObject obj = activeChar.getTarget();
if (obj instanceof NpcInstance)
{
final NpcInstance target = (NpcInstance) obj;
@@ -68,21 +52,21 @@ public class AdminDelete implements IAdminCommandHandler
final Spawn spawn = target.getSpawn();
if (spawn != null)
{
if (GrandBossManager.getInstance().isDefined(spawn.getNpcId()))
{
BuilderUtil.sendSysMessage(activeChar, "You cannot delete a grandboss.");
return true;
}
spawn.stopRespawn();
if (RaidBossSpawnManager.getInstance().isDefined(spawn.getNpcId()) && !spawn.isCustomBossInstance())
if (RaidBossSpawnManager.getInstance().isDefined(spawn.getNpcId()))
{
RaidBossSpawnManager.getInstance().deleteSpawn(spawn, true);
}
else
{
boolean update = true;
if (GrandBossManager.getInstance().isDefined(spawn.getNpcId()) && spawn.isCustomBossInstance())
{
update = false;
}
SpawnTable.getInstance().deleteSpawn(spawn, update);
SpawnTable.getInstance().deleteSpawn(spawn, true);
}
}
@@ -93,4 +77,13 @@ public class AdminDelete implements IAdminCommandHandler
activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
}
}
return true;
}
@Override
public String[] getAdminCommandList()
{
return ADMIN_COMMANDS;
}
}

View File

@@ -23,7 +23,6 @@ import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.datatables.sql.NpcTable;
import org.l2jmobius.gameserver.datatables.sql.SpawnTable;
import org.l2jmobius.gameserver.datatables.sql.TeleportLocationTable;
@@ -297,10 +296,6 @@ public class AdminSpawn implements IAdminCommandHandler
try
{
final Spawn spawn = new Spawn(template1);
if (Config.SAVE_GMSPAWN_ON_CUSTOM)
{
spawn.setCustom(true);
}
spawn.setX(target.getX());
spawn.setY(target.getY());
spawn.setZ(target.getZ());
@@ -310,11 +305,8 @@ public class AdminSpawn implements IAdminCommandHandler
if (RaidBossSpawnManager.getInstance().isDefined(spawn.getNpcId()) || GrandBossManager.getInstance().isDefined(spawn.getNpcId()))
{
BuilderUtil.sendSysMessage(activeChar, "Another instance of " + template1.getName() + " already present into database:");
BuilderUtil.sendSysMessage(activeChar, "It will be spawned but not saved on Database");
BuilderUtil.sendSysMessage(activeChar, "After server restart or raid dead, the spawned npc will desappear");
permanent = false;
spawn.setCustomBossInstance(true); // for raids, this value is used in order to segnalate to not save respawn time - status for custom instance
BuilderUtil.sendSysMessage(activeChar, "Another spawn of " + template1.getName() + " is already present in the database.");
return;
}
if (RaidBossSpawnManager.getInstance().getValidTemplate(spawn.getNpcId()) != null)

View File

@@ -25,6 +25,8 @@ import org.l2jmobius.gameserver.datatables.sql.SpawnTable;
import org.l2jmobius.gameserver.datatables.xml.MapRegionData;
import org.l2jmobius.gameserver.enums.TeleportWhereType;
import org.l2jmobius.gameserver.handler.IAdminCommandHandler;
import org.l2jmobius.gameserver.instancemanager.GrandBossManager;
import org.l2jmobius.gameserver.instancemanager.RaidBossSpawnManager;
import org.l2jmobius.gameserver.model.Location;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
@@ -585,11 +587,8 @@ public class AdminTeleport implements IAdminCommandHandler
if (obj instanceof NpcInstance)
{
final NpcInstance target = (NpcInstance) obj;
final int monsterTemplate = target.getTemplate().getNpcId();
final NpcTemplate template1 = NpcTable.getInstance().getTemplate(monsterTemplate);
if (template1 == null)
{
BuilderUtil.sendSysMessage(activeChar, "Incorrect monster template.");
@@ -598,7 +597,6 @@ public class AdminTeleport implements IAdminCommandHandler
}
Spawn spawn = target.getSpawn();
if (spawn == null)
{
BuilderUtil.sendSysMessage(activeChar, "Incorrect monster spawn.");
@@ -606,14 +604,18 @@ public class AdminTeleport implements IAdminCommandHandler
return;
}
if (RaidBossSpawnManager.getInstance().isDefined(spawn.getNpcId()) || GrandBossManager.getInstance().isDefined(spawn.getNpcId()))
{
BuilderUtil.sendSysMessage(activeChar, "You cannot recall a boss instance.");
return;
}
final int respawnTime = spawn.getRespawnDelay() / 1000;
final boolean custom_boss_spawn = spawn.isCustomBossInstance();
target.deleteMe();
spawn.stopRespawn();
// check to avoid that recalling a custom raid it will be saved into database
SpawnTable.getInstance().deleteSpawn(spawn, !custom_boss_spawn);
SpawnTable.getInstance().deleteSpawn(spawn, true);
try
{
@@ -624,7 +626,7 @@ public class AdminTeleport implements IAdminCommandHandler
spawn.setAmount(1);
spawn.setHeading(activeChar.getHeading());
spawn.setRespawnDelay(respawnTime);
SpawnTable.getInstance().addNewSpawn(spawn, !custom_boss_spawn);
SpawnTable.getInstance().addNewSpawn(spawn, true);
spawn.init();
BuilderUtil.sendSysMessage(activeChar, "Created " + template1.getName() + " on " + target.getObjectId() + ".");

View File

@@ -85,11 +85,8 @@ public class GrandBossInstance extends MonsterInstance
public void onSpawn()
{
super.onSpawn();
if (!getSpawn().isCustomBossInstance())
{
GrandBossManager.getInstance().addBoss(this);
}
}
@Override
protected void manageMinions()

View File

@@ -95,10 +95,7 @@ public class RaidBossInstance extends MonsterInstance
}
}
if (!getSpawn().isCustomBossInstance())
{
RaidBossSpawnManager.getInstance().updateStatus(this, true);
}
return true;
}

View File

@@ -298,45 +298,6 @@ public class Spawn
_heading = heading;
}
/**
* Kidzor Set the spawn as custom.
* @param custom
*/
public void setCustom(boolean custom)
{
_customSpawn = custom;
}
/**
* Kidzor Return type of spawn.
* @return
*/
public boolean isCustom()
{
return _customSpawn;
}
/** If true then spawn is custom */
private boolean _customSpawn;
private boolean _customBossInstance = false;
/**
* @return the _customBossInstance
*/
public boolean isCustomBossInstance()
{
return _customBossInstance;
}
/**
* @param customBossInstance the _customBossInstance to set
*/
public void setCustomBossInstance(boolean customBossInstance)
{
_customBossInstance = customBossInstance;
}
/**
* Decrease the current number of NpcInstance of this Spawn and if necessary create a SpawnTask to launch after the respawn Delay.<BR>
* <BR>