diff --git a/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java b/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java index 228534f19..c254e2cd2 100644 --- a/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java +++ b/src/main/java/emu/grasscutter/game/dungeons/DungeonSystem.java @@ -131,7 +131,9 @@ public final class DungeonSystem extends BaseGameSystem { dungeonId); if (player.getWorld().transferPlayerToScene(player, data.getSceneId(), data)) { - dungeonSettleListeners.forEach(player.getScene()::addDungeonSettleObserver); + var scene = player.getScene(); + scene.setDungeonManager(new DungeonManager(scene, data)); + dungeonSettleListeners.forEach(scene::addDungeonSettleObserver); } return true; } diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index 5ca90345d..868208c2d 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -774,9 +774,9 @@ public class SceneScriptManager { } public void startMonsterTideInGroup( - SceneGroup group, Integer[] ordersConfigId, int tideCount, int sceneLimit) { + String source, SceneGroup group, Integer[] ordersConfigId, int tideCount, int sceneLimit) { this.scriptMonsterTideService = - new ScriptMonsterTideService(this, group, tideCount, sceneLimit, ordersConfigId); + new ScriptMonsterTideService(this, source, group, tideCount, sceneLimit, ordersConfigId); } public void unloadCurrentMonsterTide() { diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLib.java b/src/main/java/emu/grasscutter/scripts/ScriptLib.java index e3785b739..0209c8c9f 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLib.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLib.java @@ -310,14 +310,14 @@ public class ScriptLib { // TODO: AttachGalleryAbilityGroup // TODO: AttachGalleryTeamAbilityGroup - public int AutoMonsterTide(int challengeIndex, int groupId, Integer[] ordersConfigId, int tideCount, int sceneLimit, int param6) { - logger.debug("[LUA] Call AutoMonsterTide with {},{},{},{},{},{}", challengeIndex, groupId, ordersConfigId, tideCount, sceneLimit, param6); + public int AutoMonsterTide(int sourceId, int groupId, Integer[] ordersConfigId, int tideCount, int sceneLimit, int param6) { + logger.debug("[LUA] Call AutoMonsterTide with {},{},{},{},{},{}", sourceId, groupId, ordersConfigId, tideCount, sceneLimit, param6); // Some fields are guessed SceneGroup group = getSceneScriptManager().getGroupById(groupId); if (group == null || group.monsters == null) { return 1; } - this.getSceneScriptManager().startMonsterTideInGroup(group, ordersConfigId, tideCount, sceneLimit); + this.getSceneScriptManager().startMonsterTideInGroup(Integer.toString(sourceId), group, ordersConfigId, tideCount, sceneLimit); return 0; } diff --git a/src/main/java/emu/grasscutter/scripts/service/ScriptMonsterTideService.java b/src/main/java/emu/grasscutter/scripts/service/ScriptMonsterTideService.java index ad784c4a1..44e2b9862 100644 --- a/src/main/java/emu/grasscutter/scripts/service/ScriptMonsterTideService.java +++ b/src/main/java/emu/grasscutter/scripts/service/ScriptMonsterTideService.java @@ -20,9 +20,11 @@ public final class ScriptMonsterTideService { private final List monsterConfigIds; private final OnMonsterCreated onMonsterCreated = new OnMonsterCreated(); private final OnMonsterDead onMonsterDead = new OnMonsterDead(); + private final String source; public ScriptMonsterTideService( SceneScriptManager sceneScriptManager, + String source, SceneGroup group, int tideCount, int monsterSceneLimit, @@ -35,6 +37,7 @@ public final class ScriptMonsterTideService { this.monsterAlive = new AtomicInteger(0); this.monsterConfigOrders = new ConcurrentLinkedQueue<>(List.of(ordersConfigId)); this.monsterConfigIds = List.of(ordersConfigId); + this.source = source; this.sceneScriptManager .getScriptMonsterSpawnService() @@ -83,11 +86,10 @@ public final class ScriptMonsterTideService { sceneScriptManager.createMonster( currentGroup.id, currentGroup.block_id, getNextMonster())); } - // spawn the last turn of monsters - // fix the 5-2 - sceneScriptManager.callEvent( - new ScriptArgs( - currentGroup.id, EventType.EVENT_MONSTER_TIDE_DIE, monsterKillCount.get())); + // call registered events that may spawn in more monsters + var scriptArgs = new ScriptArgs(currentGroup.id, EventType.EVENT_MONSTER_TIDE_DIE, monsterKillCount.get()); + scriptArgs.setEventSource(source); + sceneScriptManager.callEvent(scriptArgs); } }