diff --git a/src/main/java/emu/grasscutter/data/def/DungeonData.java b/src/main/java/emu/grasscutter/data/def/DungeonData.java index 3239d30fb..311286dca 100644 --- a/src/main/java/emu/grasscutter/data/def/DungeonData.java +++ b/src/main/java/emu/grasscutter/data/def/DungeonData.java @@ -10,6 +10,7 @@ import emu.grasscutter.game.props.SceneType; public class DungeonData extends GameResource { private int Id; private int SceneId; + private int ShowLevel; private String InvolveType; // TODO enum @Override @@ -21,6 +22,10 @@ public class DungeonData extends GameResource { return SceneId; } + public int getShowLevel() { + return ShowLevel; + } + @Override public void onLoad() { diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 93bfab9db..aa85e2b61 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -495,20 +495,7 @@ public class Scene { } for (SceneGroup group : block.groups) { - for (SceneGadget g : group.gadgets) { - EntityGadget entity = new EntityGadget(this, g.gadget_id, g.pos); - - if (entity.getGadgetData() == null) continue; - - entity.setBlockId(block.id); - entity.setConfigId(g.config_id); - entity.setGroupId(group.id); - entity.getRotation().set(g.rot); - entity.setState(g.state); - - this.addEntity(entity); - this.getScriptManager().callEvent(EventType.EVENT_GADGET_CREATE, new ScriptArgs(entity.getConfigId())); - } + this.getScriptManager().spawnGadgetsInGroup(block, group); } } diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index 09104f63d..33acf4f45 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -1,5 +1,6 @@ package emu.grasscutter.scripts; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -14,6 +15,9 @@ import org.luaj.vm2.LuaValue; import org.luaj.vm2.lib.jse.CoerceJavaToLua; import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.def.MonsterData; +import emu.grasscutter.data.def.WorldLevelData; import emu.grasscutter.game.entity.EntityGadget; import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.GameEntity; @@ -207,6 +211,64 @@ public class SceneScriptManager { } + public void spawnGadgetsInGroup(SceneBlock block, SceneGroup group) { + for (SceneGadget g : group.gadgets) { + EntityGadget entity = new EntityGadget(getScene(), g.gadget_id, g.pos); + + if (entity.getGadgetData() == null) continue; + + entity.setBlockId(block.id); + entity.setConfigId(g.config_id); + entity.setGroupId(group.id); + entity.getRotation().set(g.rot); + entity.setState(g.state); + + getScene().addEntity(entity); + this.callEvent(EventType.EVENT_GADGET_CREATE, new ScriptArgs(entity.getConfigId())); + } + } + + public void spawnMonstersInGroup(SceneGroup group) { + List toAdd = new ArrayList<>(); + + for (SceneMonster monster : group.monsters) { + MonsterData data = GameData.getMonsterDataMap().get(monster.monster_id); + + if (data == null) { + continue; + } + + // Calculate level + int level = monster.level; + + if (getScene().getDungeonData() != null) { + level = getScene().getDungeonData().getShowLevel(); + } else if (getScene().getWorld().getWorldLevel() > 0) { + WorldLevelData worldLevelData = GameData.getWorldLevelDataMap().get(getScene().getWorld().getWorldLevel()); + + if (worldLevelData != null) { + level = worldLevelData.getMonsterLevel(); + } + } + + // Spawn mob + EntityMonster entity = new EntityMonster(getScene(), data, monster.pos, level); + entity.getRotation().set(monster.rot); + entity.setGroupId(group.id); + entity.setConfigId(monster.config_id); + + toAdd.add(entity); + } + + if (toAdd.size() > 0) { + getScene().addEntities(toAdd); + + for (GameEntity entity : toAdd) { + callEvent(EventType.EVENT_ANY_MONSTER_LIVE, new ScriptArgs(entity.getConfigId())); + } + } + } + // Events public void callEvent(int eventType, ScriptArgs params) { diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLib.java b/src/main/java/emu/grasscutter/scripts/ScriptLib.java index 42649448f..a4559086c 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLib.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLib.java @@ -115,30 +115,7 @@ public class ScriptLib { } // TODO just spawn all from group for now - List toAdd = new ArrayList<>(); - - for (SceneMonster monster : group.monsters) { - MonsterData data = GameData.getMonsterDataMap().get(monster.monster_id); - - if (data == null) { - continue; - } - - EntityMonster entity = new EntityMonster(getSceneScriptManager().getScene(), data, monster.pos, monster.level); - entity.getRotation().set(monster.rot); - entity.setGroupId(group.id); - entity.setConfigId(monster.config_id); - - toAdd.add(entity); - } - - if (toAdd.size() > 0) { - getSceneScriptManager().getScene().addEntities(toAdd); - - for (GameEntity entity : toAdd) { - this.getSceneScriptManager().callEvent(EventType.EVENT_ANY_MONSTER_LIVE, new ScriptArgs(entity.getConfigId())); - } - } + this.getSceneScriptManager().spawnMonstersInGroup(group); return 0; } @@ -151,30 +128,7 @@ public class ScriptLib { } // TODO just spawn all from group for now - List toAdd = new ArrayList<>(); - - for (SceneMonster monster : group.monsters) { - MonsterData data = GameData.getMonsterDataMap().get(monster.monster_id); - - if (data == null) { - continue; - } - - EntityMonster entity = new EntityMonster(getSceneScriptManager().getScene(), data, monster.pos, monster.level); - entity.getRotation().set(monster.rot); - entity.setGroupId(group.id); - entity.setConfigId(monster.config_id); - - toAdd.add(entity); - } - - if (toAdd.size() > 0) { - getSceneScriptManager().getScene().addEntities(toAdd); - - for (GameEntity entity : toAdd) { - this.getSceneScriptManager().callEvent(EventType.EVENT_ANY_MONSTER_LIVE, new ScriptArgs(entity.getConfigId())); - } - } + this.getSceneScriptManager().spawnMonstersInGroup(group); return 0; }