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

@@ -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

@@ -43,7 +43,39 @@ public class AdminDelete implements IAdminCommandHandler
{
if (command.equals("admin_delete"))
{
handleDelete(activeChar);
final WorldObject obj = activeChar.getTarget();
if (obj instanceof NpcInstance)
{
final NpcInstance target = (NpcInstance) obj;
target.deleteMe();
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()))
{
RaidBossSpawnManager.getInstance().deleteSpawn(spawn, true);
}
else
{
SpawnTable.getInstance().deleteSpawn(spawn, true);
}
}
BuilderUtil.sendSysMessage(activeChar, "Deleted " + target.getName() + " from " + target.getObjectId() + ".");
}
else
{
activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
}
}
return true;
@@ -54,43 +86,4 @@ public class AdminDelete implements IAdminCommandHandler
{
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;
target.deleteMe();
final Spawn spawn = target.getSpawn();
if (spawn != null)
{
spawn.stopRespawn();
if (RaidBossSpawnManager.getInstance().isDefined(spawn.getNpcId()) && !spawn.isCustomBossInstance())
{
RaidBossSpawnManager.getInstance().deleteSpawn(spawn, true);
}
else
{
boolean update = true;
if (GrandBossManager.getInstance().isDefined(spawn.getNpcId()) && spawn.isCustomBossInstance())
{
update = false;
}
SpawnTable.getInstance().deleteSpawn(spawn, update);
}
}
BuilderUtil.sendSysMessage(activeChar, "Deleted " + target.getName() + " from " + target.getObjectId() + ".");
}
else
{
activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
}
}
}

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,10 +85,7 @@ public class GrandBossInstance extends MonsterInstance
public void onSpawn()
{
super.onSpawn();
if (!getSpawn().isCustomBossInstance())
{
GrandBossManager.getInstance().addBoss(this);
}
GrandBossManager.getInstance().addBoss(this);
}
@Override

View File

@@ -95,10 +95,7 @@ public class RaidBossInstance extends MonsterInstance
}
}
if (!getSpawn().isCustomBossInstance())
{
RaidBossSpawnManager.getInstance().updateStatus(this, true);
}
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>