diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 821506723..2e2b34c7d 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -531,14 +531,14 @@ public class Scene { public List playerMeetGroups(Player player, SceneBlock block){ int RANGE = 100; - var sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPos(), RANGE); + List sceneGroups = SceneIndexManager.queryNeighbors(block.sceneGroupIndex, player.getPos(), RANGE); - var groups = new ArrayList<>(sceneGroups.stream() - .filter(group -> !scriptManager.getLoadedGroupSetPerBlock().get(block.id).contains(group) && group.getBusinessType() == 0) + List groups = sceneGroups.stream() + .filter(group -> !scriptManager.getLoadedGroupSetPerBlock().get(block.id).contains(group)) .peek(group -> scriptManager.getLoadedGroupSetPerBlock().get(block.id).add(group)) - .toList()); + .toList(); - if(groups.size() == 0){ + if (groups.size() == 0) { return List.of(); } diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index 539fef5b2..2bc42bace 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -353,6 +353,9 @@ public class SceneScriptManager { entity.setState(g.state); entity.setPointType(g.point_type); entity.buildContent(); + + // Lua event + this.callEvent(EventType.EVENT_GADGET_CREATE, new ScriptArgs(entity.getConfigId())); return entity; } @@ -390,32 +393,23 @@ public class SceneScriptManager { this.getScriptMonsterSpawnService() .onMonsterCreatedListener.forEach(action -> action.onNotify(entity)); + + // Lua event + callEvent(EventType.EVENT_ANY_MONSTER_LIVE, new ScriptArgs(entity.getConfigId())); return entity; } public void addEntity(GameEntity gameEntity){ getScene().addEntity(gameEntity); - callCreateEvent(gameEntity); } + public void meetEntities(List gameEntity){ getScene().addEntities(gameEntity, VisionTypeOuterClass.VisionType.VISION_MEET); - gameEntity.forEach(this::callCreateEvent); } + public void addEntities(List gameEntity){ getScene().addEntities(gameEntity); - gameEntity.forEach(this::callCreateEvent); - } - public void callCreateEvent(GameEntity gameEntity){ - if(!isInit){ - return; - } - if(gameEntity instanceof EntityMonster entityMonster){ - callEvent(EventType.EVENT_ANY_MONSTER_LIVE, new ScriptArgs(entityMonster.getConfigId())); - } - if(gameEntity instanceof EntityGadget entityGadget){ - this.callEvent(EventType.EVENT_GADGET_CREATE, new ScriptArgs(entityGadget.getConfigId())); - } } public PhTree getBlocksIndex() { diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLib.java b/src/main/java/emu/grasscutter/scripts/ScriptLib.java index 7b2aefdc7..bea84d8b3 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLib.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLib.java @@ -376,11 +376,14 @@ public class ScriptLib { var configId = table.get("config_id").toint(); var group = getCurrentGroup(); - if(group.isEmpty()){ + + if (group.isEmpty()) { return 1; } + var gadget = group.get().gadgets.get(configId); var entity = getSceneScriptManager().createGadget(group.get().id, group.get().block_id, gadget); + getSceneScriptManager().addEntity(entity); return 0;