From 1c6c581399dc565401151d9216a035dce6cfac51 Mon Sep 17 00:00:00 2001 From: Akka <104902222+Akka0@users.noreply.github.com> Date: Thu, 23 Jun 2022 13:12:58 +0800 Subject: [PATCH] fix gadget infinity create --- .../grasscutter/scripts/SceneScriptManager.java | 10 ++++++++++ .../emu/grasscutter/scripts/data/SceneGadget.java | 5 +++++ .../scripts/serializer/LuaSerializer.java | 15 ++++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index 4df5a84fd..0c0012dc8 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -351,6 +351,16 @@ public class SceneScriptManager { } public EntityGadget createGadget(int groupId, int blockId, SceneGadget g) { + if(g.isOneoff){ + var hasEntity = getScene().getEntities().values().stream() + .filter(e -> e instanceof EntityGadget) + .filter(e -> e.getGroupId() == g.group.id) + .filter(e -> e.getConfigId() == g.config_id) + .findFirst(); + if(hasEntity.isPresent()){ + return null; + } + } EntityGadget entity = new EntityGadget(getScene(), g.gadget_id, g.pos); if (entity.getGadgetData() == null){ diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java b/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java index 3b9f2bf7c..afbe7d0d5 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneGadget.java @@ -11,4 +11,9 @@ public class SceneGadget extends SceneObject{ public int point_type; public SceneBossChest boss_chest; public int interact_id; + public boolean isOneoff; + + public void setIsOneoff(boolean isOneoff){ + this.isOneoff = isOneoff; + } } diff --git a/src/main/java/emu/grasscutter/scripts/serializer/LuaSerializer.java b/src/main/java/emu/grasscutter/scripts/serializer/LuaSerializer.java index 8e668c48a..6a08bfd04 100644 --- a/src/main/java/emu/grasscutter/scripts/serializer/LuaSerializer.java +++ b/src/main/java/emu/grasscutter/scripts/serializer/LuaSerializer.java @@ -1,8 +1,7 @@ package emu.grasscutter.scripts.serializer; - import com.esotericsoftware.reflectasm.ConstructorAccess; +import com.esotericsoftware.reflectasm.ConstructorAccess; import com.esotericsoftware.reflectasm.MethodAccess; - import emu.grasscutter.Grasscutter; import emu.grasscutter.scripts.ScriptUtils; import lombok.AccessLevel; @@ -12,8 +11,6 @@ import lombok.experimental.FieldDefaults; import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -56,10 +53,12 @@ public class LuaSerializer implements Serializer { object = (T) (Float) keyValue.tofloat(); // terrible... } else if (keyValue.isstring()) { object = (T) keyValue.tojstring(); - } else { + } else if (keyValue.isboolean()) { + object = (T) (Boolean) keyValue.toboolean(); + } else { object = (T) keyValue; } - + if (object != null) { list.add(object); } @@ -118,7 +117,9 @@ public class LuaSerializer implements Serializer { methodAccess.invoke(object, fieldMeta.index, keyValue.toint()); } else if (fieldMeta.getType().equals(String.class)) { methodAccess.invoke(object, fieldMeta.index, keyValue.tojstring()); - } else { + } else if (fieldMeta.getType().equals(boolean.class)) { + methodAccess.invoke(object, fieldMeta.index, keyValue.toboolean()); + } else { methodAccess.invoke(object, fieldMeta.index, keyValue.tojstring()); } } catch (Exception ex) {