From e27eb82c95a1083002fa25ada320953044b4e352 Mon Sep 17 00:00:00 2001 From: hartie95 Date: Mon, 6 Nov 2023 02:53:59 +0100 Subject: [PATCH] [Refactoring] Moved the SceneBLocks group info into its own object and added some missing fields * Also cache the group and block data in the SceneMeta objects * Added the Position interface for working with Positions in Scriptlib --- .../gi_lua/models/DummyPoint.java | 10 +- .../gi_lua/models/Position.java | 51 ++----- .../gi_lua/models/PositionImpl.java | 41 ++++++ .../gi_lua/models/SceneConfig.java | 11 +- .../gi_lua/models/SceneMeta.java | 105 +++++++++----- .../gi_lua/models/scene/block/SceneBlock.java | 75 +++++----- .../models/scene/block/SceneBusiness.java | 1 + .../models/scene/block/SceneGroupInfo.java | 52 +++++++ .../gi_lua/models/scene/group/SceneGroup.java | 135 ++++++++---------- .../models/scene/group/SceneObject.java | 12 +- .../models/scene/group/SceneRegion.java | 9 +- .../models/scene/group/SceneTrigger.java | 5 +- .../gi_lua/utils/ScriptUtils.java | 5 +- 13 files changed, 304 insertions(+), 208 deletions(-) create mode 100644 GILua/src/main/java/org/anime_game_servers/gi_lua/models/PositionImpl.java create mode 100644 GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneGroupInfo.java diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/DummyPoint.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/DummyPoint.java index e5761ba..08ac207 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/DummyPoint.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/DummyPoint.java @@ -1,9 +1,11 @@ package org.anime_game_servers.gi_lua.models; -import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; -@Data +@Getter @EqualsAndHashCode @ToString public class DummyPoint { - private Position pos; - private Position rot; + private PositionImpl pos; + private PositionImpl rot; } diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/Position.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/Position.java index 35da73f..cc05012 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/Position.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/Position.java @@ -1,58 +1,27 @@ package org.anime_game_servers.gi_lua.models; import com.github.davidmoten.rtreemulti.geometry.Point; -import lombok.Getter; -import lombok.Setter; -import java.io.Serializable; -import java.util.List; +public interface Position { + float getX(); + float getY(); + float getZ(); -public class Position implements Serializable { - @Getter @Setter private float x; - @Getter @Setter private float y; - @Getter @Setter private float z; - public Position() {} - - public Position(float x, float y) { - this.x = x; - this.y = y; - } - - public Position(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Position(List xyz) { - switch (xyz.size()) { - default: // Might want to error on excess elements, but maybe we want to extend to 3+3 representation later. - case 3: - this.z = xyz.get(2); // Fall-through - case 2: - this.y = xyz.get(1); // Fall-through - case 1: - this.x = xyz.get(0); // pointless fall-through - case 0: - break; - } - } - - public Point toPoint() { - return Point.create(x,y,z); + default Point toPoint() { + return Point.create(getX(),getY(),getZ()); } /** * To XYZ array for Spatial Index */ - public double[] toDoubleArray() { - return new double[]{ x, y, z}; + default double[] toDoubleArray() { + return new double[]{ getX(),getY(),getZ()}; } /** * To XZ array for Spatial Index (Blocks) */ - public double[] toXZDoubleArray() { - return new double[]{x, z}; + default double[] toXZDoubleArray() { + return new double[]{getX(),getZ()}; } } diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/PositionImpl.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/PositionImpl.java new file mode 100644 index 0000000..f96fcf3 --- /dev/null +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/PositionImpl.java @@ -0,0 +1,41 @@ +package org.anime_game_servers.gi_lua.models; + +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.List; + +@Getter +public class PositionImpl implements Serializable, Position { + @Setter private float x; + @Setter private float y; + @Setter private float z; + + public PositionImpl() {} + + public PositionImpl(float x, float y) { + this.x = x; + this.y = y; + } + + public PositionImpl(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + public PositionImpl(List xyz) { + switch (xyz.size()) { + default: // Might want to error on excess elements, but maybe we want to extend to 3+3 representation later. + case 3: + this.z = xyz.get(2); // Fall-through + case 2: + this.y = xyz.get(1); // Fall-through + case 1: + this.x = xyz.get(0); // pointless fall-through + case 0: + break; + } + } +} diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/SceneConfig.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/SceneConfig.java index a39295d..32f7db1 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/SceneConfig.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/SceneConfig.java @@ -2,15 +2,14 @@ package org.anime_game_servers.gi_lua.models; import lombok.Getter; import lombok.ToString; -import org.anime_game_servers.gi_lua.models.Position; @ToString @Getter public class SceneConfig { - private Position vision_anchor; - private Position born_pos; - private Position born_rot; - private Position begin_pos; - private Position size; + private PositionImpl vision_anchor; + private PositionImpl born_pos; + private PositionImpl born_rot; + private PositionImpl begin_pos; + private PositionImpl size; private float die_y; } diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/SceneMeta.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/SceneMeta.java index 719428e..0218e29 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/SceneMeta.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/SceneMeta.java @@ -1,69 +1,106 @@ package org.anime_game_servers.gi_lua.models; -import com.github.davidmoten.rtreemulti.RTree; -import com.github.davidmoten.rtreemulti.geometry.Geometry; +import io.github.oshai.kotlinlogging.KLogger; +import io.github.oshai.kotlinlogging.KotlinLogging; import lombok.Getter; import lombok.ToString; import lombok.val; -import org.anime_game_servers.gi_lua.SceneIndexManager; import org.anime_game_servers.gi_lua.models.scene.block.SceneBlock; -import org.anime_game_servers.gi_lua.utils.GIScriptLoader; +import org.anime_game_servers.gi_lua.models.scene.block.SceneGroupInfo; +import org.anime_game_servers.gi_lua.models.scene.group.SceneGroup; +import org.anime_game_servers.gi_lua.models.loader.GIScriptLoader; import org.anime_game_servers.lua.engine.LuaScript; -import org.anime_game_servers.lua.models.ScriptType; -import javax.script.ScriptException; +import javax.annotation.Nullable; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; @ToString @Getter public class SceneMeta { + private static KLogger logger = KotlinLogging.INSTANCE.logger(SceneMeta.class.getName()); + private int sceneId; private SceneConfig config; + private List blockIds; private Map blocks; + private Map groupsInfos; + private Map groups; + private Map dummyPoints; private LuaScript context; - private RTree sceneBlockIndex; + //private RTree sceneBlockIndex; public static SceneMeta of(int sceneId, GIScriptLoader scriptLoader) { - return new SceneMeta().load(sceneId, scriptLoader); + return new SceneMeta(sceneId).load(scriptLoader); } - public SceneMeta load(int sceneId, GIScriptLoader scriptLoader) { - // Get compiled script if cached - val cs = scriptLoader.getSceneScript(sceneId, "scene"+sceneId+".lua", ScriptType.DATA_STORAGE); + private SceneMeta(int sceneId) { + this.sceneId = sceneId; + } - if (cs == null) { - //Grasscutter.getLogger().warn("No script found for scene " + sceneId); + public SceneMeta load(GIScriptLoader scriptLoader) { + if(!loadSceneMeta(scriptLoader)){ return null; } + loadDummyPoints(scriptLoader); + loadBlocks(scriptLoader); + prepareGroups(); + return this; + } - // Eval script - try { - cs.evaluate(); - + private boolean loadSceneMeta(GIScriptLoader scriptLoader){ + return scriptLoader.loadSceneMetaScript(sceneId, (cs -> { this.config = cs.getGlobalVariable("scene_config", SceneConfig.class); // TODO optimize later // Create blocks - List blockIds = cs.getGlobalVariableList("blocks", Integer.class); - List blocks = cs.getGlobalVariableList("block_rects", SceneBlock.class); + this.blockIds = cs.getGlobalVariableList("blocks", Integer.class); - for (int i = 0; i < blocks.size(); i++) { - SceneBlock block = blocks.get(i); - block.setId(blockIds.get(i)); - } - - this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.getId(), b -> b, (a, b) -> a)); - this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blocks, SceneBlock::toRectangle); - - } catch (ScriptException exception) { - //Grasscutter.getLogger().error("An error occurred while running a script.", exception); - return null; - } - //Grasscutter.getLogger().debug("Successfully loaded metadata in scene {}.", sceneId); - return this; + // block reckt is not really used, should we still load it? + //val blockList = cs.getGlobalVariableList("block_rects", SceneBlock.class); + //this.blocks = blockList.stream().collect(Collectors.toMap(b -> b.getId(), b -> b, (a, b) -> a)); + //this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blockList, SceneBlock::toRectangle); + })); } + + private void loadDummyPoints(GIScriptLoader scriptLoader){ + scriptLoader.loadSceneDummyPoints(sceneId, (cs -> { + this.dummyPoints = cs.getGlobalVariableMap("dummy_points", DummyPoint.class); + })); + } + private void loadBlocks(GIScriptLoader scriptLoader){ + this.blocks = new HashMap<>(blockIds.size()); + this.groupsInfos = new HashMap<>(); + for(val blockId : blockIds){ + val block = SceneBlock.of(this, 0, blockId, scriptLoader); + this.blocks.put(blockId, block); + } + } + + private void prepareGroups(){ + this.groups = new HashMap<>(groupsInfos.size()); + for(val groupInfo : groupsInfos.values()){ + val group = SceneGroup.of(groupInfo); + this.groups.put(groupInfo.getId(), group); + } + } + + @Nullable + public SceneGroup getGroup(int id) { + return groups.get(id); + } + + @Nullable + public SceneGroupInfo getGroupInfo(int id) { + return groupsInfos.get(id); + } + + @Nullable + public SceneBlock getBlock(int id) { + return blocks.get(id); + } + } diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneBlock.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneBlock.java index 2edd87c..6b22c98 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneBlock.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneBlock.java @@ -1,64 +1,71 @@ package org.anime_game_servers.gi_lua.models.scene.block; -import com.github.davidmoten.rtreemulti.RTree; -import com.github.davidmoten.rtreemulti.geometry.Geometry; import com.github.davidmoten.rtreemulti.geometry.Rectangle; +import io.github.oshai.kotlinlogging.KLogger; +import io.github.oshai.kotlinlogging.KotlinLogging; import lombok.*; -import org.anime_game_servers.gi_lua.SceneIndexManager; -import org.anime_game_servers.gi_lua.models.Position; -import org.anime_game_servers.gi_lua.models.scene.group.SceneGroup; -import org.anime_game_servers.gi_lua.utils.GIScriptLoader; -import org.anime_game_servers.lua.models.ScriptType; +import org.anime_game_servers.gi_lua.models.PositionImpl; +import org.anime_game_servers.gi_lua.models.SceneMeta; +import org.anime_game_servers.gi_lua.models.loader.GIScriptLoader; -import javax.script.ScriptException; import java.util.Map; import java.util.stream.Collectors; @ToString @Getter public class SceneBlock { - @Setter(AccessLevel.PUBLIC) - private int id; - private Position max; - private Position min; + private static KLogger logger = KotlinLogging.INSTANCE.logger(SceneBlock.class.getName()); - private int sceneId; - private Map groups; - private RTree sceneGroupIndex; + private PositionImpl max; + private PositionImpl min; + private Map groupInfo; + //private RTree sceneGroupIndex; + + // internal only private transient boolean loaded; // Not an actual variable in the scripts either + private transient SceneMeta meta; // Not an actual variable in the scripts either + private int sceneId; + private int activityId; + private int id; + + public static SceneBlock of(SceneMeta sceneMeta, int activityId, int blockId, GIScriptLoader scriptLoader) { + val block = new SceneBlock(sceneMeta.getSceneId(), activityId, blockId, sceneMeta); + block.load(scriptLoader); + return block; + } + private SceneBlock(int sceneId, int activityId, int blockId, SceneMeta meta) { + this.id = blockId; + this.sceneId = sceneId; + this.activityId = activityId; + this.meta = meta; + } public void setLoaded(boolean loaded) { this.loaded = loaded; } - public SceneBlock load(int sceneId, GIScriptLoader scriptLoader) { + public SceneBlock load(GIScriptLoader scriptLoader) { if (this.loaded) { return this; } - this.sceneId = sceneId; this.setLoaded(true); - - val cs = scriptLoader.getSceneScript(sceneId, "scene" + sceneId + "_block" + this.id + ".lua", ScriptType.DATA_STORAGE); - - if (cs == null) { - return null; - } - - // Eval script - try { - cs.evaluate(); - + if( !scriptLoader.loadSceneBlockScript(sceneId, id, (cs -> { // Set groups - this.groups = cs.getGlobalVariableList("groups", SceneGroup.class).stream() + this.groupInfo = cs.getGlobalVariableList("groups", SceneGroupInfo.class).stream() .collect(Collectors.toMap(x -> x.getId(), y -> y, (a, b) -> a)); - this.groups.values().forEach(g -> g.block_id = this.id); - this.sceneGroupIndex = SceneIndexManager.buildIndex(3, this.groups.values(), g -> g.getPos().toPoint()); - } catch (ScriptException exception) { - //Grasscutter.getLogger().error("An error occurred while loading block " + this.id + " in scene " + sceneId, exception); + this.groupInfo.values().forEach(g -> { + g.blockId = this.id; + g.sceneMeta = meta; + g.activityId = activityId; + }); + //this.sceneGroupIndex = SceneIndexManager.buildIndex(3, this.groupInfo.values(), g -> g.getPos().toPoint()); + }))){ + return null; } - //Grasscutter.getLogger().debug("Successfully loaded block {} in scene {}.", this.id, sceneId); + meta.getGroupsInfos().putAll(this.groupInfo); + logger.debug(() -> "Successfully loaded block " + this.id + " in scene "+sceneId+"."); return this; } diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneBusiness.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneBusiness.java index c376fb6..8b82fda 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneBusiness.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneBusiness.java @@ -7,4 +7,5 @@ import lombok.ToString; @Getter public class SceneBusiness { private int type; + private int sub_type; } diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneGroupInfo.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneGroupInfo.java new file mode 100644 index 0000000..63bae4d --- /dev/null +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/block/SceneGroupInfo.java @@ -0,0 +1,52 @@ +package org.anime_game_servers.gi_lua.models.scene.block; + +import lombok.Getter; +import org.anime_game_servers.gi_lua.models.PositionImpl; +import org.anime_game_servers.gi_lua.models.SceneMeta; + +import javax.annotation.Nullable; +import java.util.List; +import java.util.Set; + +@Getter +public class SceneGroupInfo { + private int id; + private int refresh_id; + private int area; + @Nullable + private PositionImpl pos; + @Nullable + private SceneReplaceable is_replaceable; + private final boolean dynamic_load = false; + @Nullable + private SceneBusiness business; + @Nullable + private GroupLifecycle life_cycle = GroupLifecycle.FULL_TIME__CYCLE; + private int activity_revise_level_grow_id; + private int rely_start_world_level_limit_activity_id; // SceneScriptConfig LuaConfigMgr + private int vision_type; + private boolean across_block = false; + private boolean unload_when_disconnect = false; + private boolean ignore_world_level_revise = false; + private boolean force_unload_nodelay = false; + private boolean force_clean_sub_entity = false; + private boolean is_load_by_vision_type = false; + private int load_strategy; + private Set forbid_monster_die; //todo find enum values + private List related_level_tag_series_list; + private List group_tag_list; + private List weathers; + + // internal variables + transient int blockId; + transient int activityId; + transient SceneMeta sceneMeta; + + public int getBusinessType() { + return this.business == null ? 0 : this.business.getType(); + } + + public boolean isReplaceable() { + return this.is_replaceable != null && this.is_replaceable.isValue(); + } +} diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneGroup.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneGroup.java index 1b16485..61f40cc 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneGroup.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneGroup.java @@ -1,16 +1,15 @@ package org.anime_game_servers.gi_lua.models.scene.group; +import io.github.oshai.kotlinlogging.KLogger; +import io.github.oshai.kotlinlogging.KotlinLogging; import lombok.Getter; -import lombok.Setter; import lombok.ToString; import lombok.val; -import org.anime_game_servers.gi_lua.models.*; -import org.anime_game_servers.gi_lua.models.scene.block.GroupLifecycle; -import org.anime_game_servers.gi_lua.models.scene.block.SceneBusiness; -import org.anime_game_servers.gi_lua.models.scene.block.SceneReplaceable; -import org.anime_game_servers.gi_lua.utils.GIScriptLoader; +import org.anime_game_servers.gi_lua.models.SceneMeta; +import org.anime_game_servers.gi_lua.models.loader.ScriptSource; +import org.anime_game_servers.gi_lua.models.scene.block.SceneGroupInfo; +import org.anime_game_servers.gi_lua.models.loader.GIScriptLoader; import org.anime_game_servers.lua.engine.LuaScript; -import org.anime_game_servers.lua.models.ScriptType; import javax.annotation.Nullable; import java.util.*; @@ -20,36 +19,7 @@ import java.util.stream.Collectors; @ToString @Getter public class SceneGroup { - public transient int block_id; // Not an actual variable in the scripts but we will keep it here for reference - - @Setter - private int id; - // from block - private int refresh_id; - private int area; - @Nullable - private Position pos; - @Nullable - private SceneReplaceable is_replaceable; - private final boolean dynamic_load = false; - @Nullable - private SceneBusiness business; - @Nullable - private GroupLifecycle life_cycle = GroupLifecycle.FULL_TIME__CYCLE; - private int activity_revise_level_grow_id; - private int rely_start_world_level_limit_activity_id; - private int vision_type; - private boolean across_block = false; - private boolean unload_when_disconnect = false; - private boolean ignore_world_level_revise = false; - private boolean force_unload_nodelay = false; - private boolean force_clean_sub_entity = false; - private boolean is_load_by_vision_type = false; - private int load_strategy; - private Set forbid_monster_die; //todo find enum values - private List related_level_tag_series_list; - private List group_tag_list; - private List weathers; + private static KLogger logger = KotlinLogging.INSTANCE.logger(SceneGroup.class.getName()); // from group script @Nullable @@ -80,17 +50,19 @@ public class SceneGroup { // internal + private transient SceneGroupInfo groupInfo; + private transient SceneMeta sceneMeta; private transient boolean loaded; // Not an actual variable in the scripts either private transient LuaScript script; - public static SceneGroup of(int groupId) { - var group = new SceneGroup(); - group.id = groupId; + public static SceneGroup of(SceneGroupInfo groupInfo) { + var group = new SceneGroup(groupInfo); return group; } - public int getBusinessType() { - return this.business == null ? 0 : this.business.getType(); + protected SceneGroup(SceneGroupInfo groupInfo) { + this.groupInfo = groupInfo; + this.sceneMeta = groupInfo.getSceneMeta(); } public boolean hasGarbages() { @@ -102,9 +74,6 @@ public class SceneGroup { return this.garbages == null ? null : this.garbages.getGadgets(); } - public boolean isReplaceable() { - return this.is_replaceable != null && this.is_replaceable.isValue(); - } public SceneSuite getSuiteByIndex(int index) { if (index < 1 || index > suites.size()) { @@ -113,46 +82,62 @@ public class SceneGroup { return this.suites.get(index - 1); } - public synchronized SceneGroup load(int sceneId, GIScriptLoader scriptLoader) { + public synchronized SceneGroup load(GIScriptLoader scriptLoader) { if (this.loaded) { return this; } // Set flag here so if there is no script, we don't call this function over and over again. this.loaded = true; + val sceneId = sceneMeta.getSceneId(); + val groupId = groupInfo.getId(); + val blockId = groupInfo.getBlockId(); + val activityId = groupInfo.getActivityId(); - val cs = scriptLoader.getSceneScript(sceneId, "scene" + sceneId + "_group" + this.id + ".lua", ScriptType.EXECUTABLE); - - if (cs == null) { - return this; - } - - this.script = cs; - - // Eval script - try { - cs.evaluate(); - + val scriptType = activityId == 0 ? ScriptSource.SCENE : ScriptSource.ACTIVITY; + val typeId = activityId == 0 ? sceneId : activityId; + if (!scriptLoader.loadSceneGroupScript(scriptType, typeId, groupId, cs -> { + this.script = cs; // Set this.monsters = cs.getGlobalVariableList("monsters", SceneMonster.class).stream() - .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); - this.monsters.values().forEach(m -> m.group = this); + .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); + this.monsters.values().forEach(m -> { + m.groupId = groupId; + m.blockId = blockId; + m.sceneMeta = sceneMeta; + }); this.npcs = cs.getGlobalVariableList("npcs", SceneNPC.class).stream() - .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); - this.npcs.values().forEach(m -> m.group = this); + .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); + this.npcs.values().forEach(m -> { + m.groupId = groupId; + m.blockId = blockId; + m.sceneMeta = sceneMeta; + }); this.gadgets = cs.getGlobalVariableList("gadgets", SceneGadget.class).stream() - .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); - this.gadgets.values().forEach(m -> m.group = this); + .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); + this.gadgets.values().forEach(m -> { + m.groupId = groupId; + m.blockId = blockId; + m.sceneMeta = sceneMeta; + }); this.triggers = cs.getGlobalVariableList("triggers", SceneTrigger.class).stream() - .collect(Collectors.toMap(SceneTrigger::getName, y -> y, (a, b) -> a)); - this.triggers.values().forEach(t -> t.setCurrentGroup(this)); + .collect(Collectors.toMap(SceneTrigger::getName, y -> y, (a, b) -> a)); + this.triggers.values().forEach(t -> { + t.setGroupId(groupId); + t.setBlockId(blockId); + t.setSceneMeta(sceneMeta); + }); this.suites = cs.getGlobalVariableList("suites", SceneSuite.class); this.regions = cs.getGlobalVariableList("regions", SceneRegion.class).stream() - .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); - this.regions.values().forEach(m -> m.group = this); + .collect(Collectors.toMap(x -> x.config_id, y -> y, (a, b) -> a)); + this.regions.values().forEach(m -> { + m.groupId = groupId; + m.blockId = blockId; + m.sceneMeta = sceneMeta; + }); this.init_config = cs.getGlobalVariable("init_config", SceneInitConfig.class); @@ -169,14 +154,16 @@ public class SceneGroup { // Add variables to suite this.variables = cs.getGlobalVariableList("variables", SceneVar.class); + this.monster_pools = cs.getGlobalVariableList("monster_pools", SceneMonsterPool.class); + //this.sight_groups = cs.getGlobalVariableList("sight_groups", List.class); + // Add monsters and gadgets to suite this.suites.forEach(i -> i.init(this)); - - } catch (Exception e) { - //Grasscutter.getLogger().error("An error occurred while loading group " + this.id + " in scene " + sceneId + ".", e); + })) { + return null; } - //Grasscutter.getLogger().debug("Successfully loaded group {} in scene {}.", this.id, sceneId); + logger.debug(() -> "Successfully loaded group " + groupId + " in scene " + sceneId + "."); return this; } @@ -202,8 +189,8 @@ public class SceneGroup { public Optional searchBossChestInGroup() { return this.gadgets.values().stream().map(g -> g.getBoss_chest()).filter(Objects::nonNull) - .filter(bossChest -> bossChest.getMonster_config_id() > 0) - .findFirst(); + .filter(bossChest -> bossChest.getMonster_config_id() > 0) + .findFirst(); } /*public List getReplaceableGroups(Collection loadedGroups) { diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneObject.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneObject.java index 7983f09..7616a50 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneObject.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneObject.java @@ -2,9 +2,9 @@ package org.anime_game_servers.gi_lua.models.scene.group; import lombok.Getter; import lombok.ToString; -import org.anime_game_servers.gi_lua.models.Position; +import org.anime_game_servers.gi_lua.models.PositionImpl; +import org.anime_game_servers.gi_lua.models.SceneMeta; import org.anime_game_servers.gi_lua.models.constants.EntityType; -import org.anime_game_servers.gi_lua.models.scene.group.SceneGroup; @ToString @Getter @@ -20,12 +20,14 @@ public abstract class SceneObject { protected int sight_group_index; // server_global_value_config, might be group only - protected Position pos; - protected Position rot; + protected PositionImpl pos; + protected PositionImpl rot; /** * not set by lua */ - protected transient SceneGroup group; + protected transient int groupId; + protected transient int blockId; + protected transient SceneMeta sceneMeta; public abstract EntityType getType(); } diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneRegion.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneRegion.java index c353136..54ff576 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneRegion.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneRegion.java @@ -2,6 +2,7 @@ package org.anime_game_servers.gi_lua.models.scene.group; import lombok.Getter; import org.anime_game_servers.gi_lua.models.Position; +import org.anime_game_servers.gi_lua.models.PositionImpl; import org.anime_game_servers.gi_lua.models.constants.EntityType; import org.anime_game_servers.gi_lua.models.constants.ScriptRegionShape; @@ -13,12 +14,12 @@ import java.util.List; public class SceneRegion extends SceneObject{ private int shape; // for CUBIC - private Position size; + private PositionImpl size; // for SPHERE AND CYLINDER private int radius; // for CYLINDER and POLYGON private float height; - private List point_array; + private List point_array; private List ability_group_list; private List team_ability_group; private boolean is_trigger_reload_group = false; @@ -39,10 +40,6 @@ public class SceneRegion extends SceneObject{ return false; } - public int getGroupId() { - return group.getId(); - } - @Override public EntityType getType() { return EntityType.REGION; diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneTrigger.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneTrigger.java index 3855f23..919ec26 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneTrigger.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/models/scene/group/SceneTrigger.java @@ -2,6 +2,7 @@ package org.anime_game_servers.gi_lua.models.scene.group; import lombok.Data; import lombok.NoArgsConstructor; +import org.anime_game_servers.gi_lua.models.SceneMeta; import org.anime_game_servers.gi_lua.models.scene.group.SceneGroup; @Data @@ -23,5 +24,7 @@ public class SceneTrigger { private String tlog_tag; private boolean forbid_guest = true; - private transient SceneGroup currentGroup; + private transient int groupId; + private transient int blockId; + private transient SceneMeta sceneMeta; } diff --git a/GILua/src/main/java/org/anime_game_servers/gi_lua/utils/ScriptUtils.java b/GILua/src/main/java/org/anime_game_servers/gi_lua/utils/ScriptUtils.java index 2f051cb..3d8fca0 100644 --- a/GILua/src/main/java/org/anime_game_servers/gi_lua/utils/ScriptUtils.java +++ b/GILua/src/main/java/org/anime_game_servers/gi_lua/utils/ScriptUtils.java @@ -2,11 +2,10 @@ package org.anime_game_servers.gi_lua.utils; import lombok.val; import org.anime_game_servers.gi_lua.models.Position; +import org.anime_game_servers.gi_lua.models.PositionImpl; import org.anime_game_servers.lua.engine.LuaEngine; import org.anime_game_servers.lua.engine.LuaTable; -import java.util.HashMap; - public class ScriptUtils { public static LuaTable posToLua(Position position, LuaEngine engine){ @@ -25,7 +24,7 @@ public class ScriptUtils { } public static Position luaToPos(LuaTable position){ - val result = new Position(); + val result = new PositionImpl(); if(position != null){ result.setX(position.optInt("x", 0)); result.setY(position.optInt("y", 0));