Hello everyone, I would like to know how this method can be applied in a new Instance "(setDungeon)"
private void spawnMob(int mobId, List<Location> locations)
{
NpcTemplate template = NpcTable.getInstance().getTemplate(mobId);
try
{
for (Location loc : locations)
{
Spawn spawn = new Spawn(template);
spawn.setLoc(loc.getX(), loc.getY(), loc.getZ(), 0);
spawn.setRespawnDelay(1);
spawn.doSpawn();
SpawnTable.getInstance().addNewSpawn(spawn, false);
((DungeonMobInstance) spawn.getNpc()).setDungeon(this);
spawn.getNpc().setInstance(instance, false); // Set instance first
spawn.getNpc().broadcastStatusUpdate();
mobs.add((DungeonMobInstance) spawn.getNpc());
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
The intance is for him to trigger that the monsters were killed and proceed to the next stage
public class DungeonMobInstance extends MonsterInstance
{
private Dungeon dungeon;
public DungeonMobInstance(int objectId, NpcTemplate template)
{
super(objectId, template);
}
@Override
public boolean doDie(Creature killer)
{
if (!super.doDie(killer))
{
return false;
}
if (dungeon != null)
{
ThreadPool.schedule(() -> dungeon.onMobKill(this), 1000 * 2);
}
return true;
}
public void setDungeon(Dungeon dungeon)
{
dungeon = this.dungeon;
}
that part of the problem, when I remove those lines.
he adds the spwan correctly but doesn’t go to the next stage
((DungeonMobInstance) spawn.getNpc()).setDungeon(this);
spawn.getNpc().setInstance(instance, false); // Set instance first
spawn.getNpc().broadcastStatusUpdate();
this and the part of onKill
public synchronized void onMobKill(DungeonMobInstance mob)
{
if (!mobs.contains(mob))
{
return;
}
deleteMob(mob);
if (mobs.isEmpty())
{
if (dungeonCancelTask != null)
{
dungeonCancelTask.cancel(false);
}
if (timerTask != null)
{
timerTask.cancel(true);
}
if (nextTask != null)
{
nextTask.cancel(true);
}
for (PlayerInstance player : players)
{
if (player.isDead())
{
player.doRevive();
}
}
getNextStage();
if (currentStage == null) // No more stages
{
rewardPlayers();
if (template.getRewardHtm().equals("NULL"))
{
broadcastScreenMessage("You have completed the dungeon!", 5);
teleToTown();
}
else
{
broadcastScreenMessage("You have completed the dungeon! Select your reward", 5);
// teleToTown();
}
InstanceManager.getInstance().deleteInstance(instance.getId());
DungeonManager.getInstance().removeDungeon(this);
}
else
{
broadcastScreenMessage("You have completed stage " + (currentStage.getOrder() - 1) + "! Next stage begins in 10 seconds.", 5);
ThreadPool.schedule(() -> teleToStage(), 5 * 1000);
nextTask = ThreadPool.schedule(() -> beginStage(), 10 * 1000);
}
}
}
translated by google chorme