Commit 1c6c5813 authored by Akka's avatar Akka Committed by Melledy
Browse files

fix gadget infinity create

parent b7963720
...@@ -351,6 +351,16 @@ public class SceneScriptManager { ...@@ -351,6 +351,16 @@ public class SceneScriptManager {
} }
public EntityGadget createGadget(int groupId, int blockId, SceneGadget g) { 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); EntityGadget entity = new EntityGadget(getScene(), g.gadget_id, g.pos);
if (entity.getGadgetData() == null){ if (entity.getGadgetData() == null){
......
...@@ -11,4 +11,9 @@ public class SceneGadget extends SceneObject{ ...@@ -11,4 +11,9 @@ public class SceneGadget extends SceneObject{
public int point_type; public int point_type;
public SceneBossChest boss_chest; public SceneBossChest boss_chest;
public int interact_id; public int interact_id;
public boolean isOneoff;
public void setIsOneoff(boolean isOneoff){
this.isOneoff = isOneoff;
}
} }
package emu.grasscutter.scripts.serializer; package emu.grasscutter.scripts.serializer;
import com.esotericsoftware.reflectasm.ConstructorAccess; import com.esotericsoftware.reflectasm.ConstructorAccess;
import com.esotericsoftware.reflectasm.MethodAccess; import com.esotericsoftware.reflectasm.MethodAccess;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.scripts.ScriptUtils; import emu.grasscutter.scripts.ScriptUtils;
import lombok.AccessLevel; import lombok.AccessLevel;
...@@ -12,8 +11,6 @@ import lombok.experimental.FieldDefaults; ...@@ -12,8 +11,6 @@ import lombok.experimental.FieldDefaults;
import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue; import org.luaj.vm2.LuaValue;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -56,10 +53,12 @@ public class LuaSerializer implements Serializer { ...@@ -56,10 +53,12 @@ public class LuaSerializer implements Serializer {
object = (T) (Float) keyValue.tofloat(); // terrible... object = (T) (Float) keyValue.tofloat(); // terrible...
} else if (keyValue.isstring()) { } else if (keyValue.isstring()) {
object = (T) keyValue.tojstring(); object = (T) keyValue.tojstring();
} else { } else if (keyValue.isboolean()) {
object = (T) (Boolean) keyValue.toboolean();
} else {
object = (T) keyValue; object = (T) keyValue;
} }
if (object != null) { if (object != null) {
list.add(object); list.add(object);
} }
...@@ -118,7 +117,9 @@ public class LuaSerializer implements Serializer { ...@@ -118,7 +117,9 @@ public class LuaSerializer implements Serializer {
methodAccess.invoke(object, fieldMeta.index, keyValue.toint()); methodAccess.invoke(object, fieldMeta.index, keyValue.toint());
} else if (fieldMeta.getType().equals(String.class)) { } else if (fieldMeta.getType().equals(String.class)) {
methodAccess.invoke(object, fieldMeta.index, keyValue.tojstring()); 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()); methodAccess.invoke(object, fieldMeta.index, keyValue.tojstring());
} }
} catch (Exception ex) { } catch (Exception ex) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment