From ecb6145e54429383f3584c6641b28faa8df13d6a Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sun, 4 Jun 2023 17:52:12 -0400 Subject: [PATCH] Revert "Fix `dropType` de-serialization" --- .../data/binout/AbilityModifier.java | 6 +-- .../actions/ActionGenerateElemBall.java | 6 +-- .../emu/grasscutter/utils/JsonAdapters.java | 19 -------- .../java/emu/grasscutter/utils/JsonUtils.java | 18 ++++--- .../grasscutter/utils/objects/DropType.java | 47 ------------------- 5 files changed, 16 insertions(+), 80 deletions(-) delete mode 100644 src/main/java/emu/grasscutter/utils/objects/DropType.java diff --git a/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java b/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java index 8342aa2a3..d999106a6 100644 --- a/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java +++ b/src/main/java/emu/grasscutter/data/binout/AbilityModifier.java @@ -3,10 +3,8 @@ package emu.grasscutter.data.binout; import com.google.gson.annotations.SerializedName; import emu.grasscutter.data.common.DynamicFloat; import emu.grasscutter.game.props.ElementType; -import emu.grasscutter.utils.objects.DropType; -import lombok.ToString; - import java.io.Serializable; +import lombok.ToString; public class AbilityModifier implements Serializable { private static final long serialVersionUID = -2001232313615923575L; @@ -329,7 +327,7 @@ public class AbilityModifier implements Serializable { public AbilityModifierAction[] successActions; public AbilityModifierAction[] failActions; - public DropType dropType; + public int dropType; public DynamicFloat baseEnergy; public DynamicFloat ratio = DynamicFloat.ONE; public int configID; diff --git a/src/main/java/emu/grasscutter/game/ability/actions/ActionGenerateElemBall.java b/src/main/java/emu/grasscutter/game/ability/actions/ActionGenerateElemBall.java index d01acd304..9aef4c396 100644 --- a/src/main/java/emu/grasscutter/game/ability/actions/ActionGenerateElemBall.java +++ b/src/main/java/emu/grasscutter/game/ability/actions/ActionGenerateElemBall.java @@ -29,7 +29,7 @@ public final class ActionGenerateElemBall extends AbilityActionHandler { } // Check if we should allow elem ball generation - if (action.dropType.getValue() == 0) { + if (action.dropType == 0x0) { String levelEntityConfig = owner.getScene().getSceneData().getLevelEntityConfig(); ConfigLevelEntity config = GameData.getConfigLevelEntityDataMap().get(levelEntityConfig); if (config != null @@ -38,12 +38,12 @@ public final class ActionGenerateElemBall extends AbilityActionHandler { Grasscutter.getLogger().warn("This level config don't allow element balls"); return true; } - } else if (action.dropType.getValue() == 1) { + } else if (action.dropType == 0x1) { if (owner.getScene().getSceneData().getSceneType() != SceneType.SCENE_WORLD) { Grasscutter.getLogger().warn("This level config only allows element balls on big world"); return true; } - } // else: the drop is forced. (value 2) + } // Else the drop is forced var energy = action.baseEnergy.get(ability) * action.ratio.get(ability); if (energy <= 0.0) return true; diff --git a/src/main/java/emu/grasscutter/utils/JsonAdapters.java b/src/main/java/emu/grasscutter/utils/JsonAdapters.java index 926e2681d..9eaf1f51e 100644 --- a/src/main/java/emu/grasscutter/utils/JsonAdapters.java +++ b/src/main/java/emu/grasscutter/utils/JsonAdapters.java @@ -5,7 +5,6 @@ import com.google.gson.reflect.TypeToken; import com.google.gson.stream.*; import emu.grasscutter.data.common.DynamicFloat; import emu.grasscutter.game.world.*; -import emu.grasscutter.utils.objects.DropType; import it.unimi.dsi.fastutil.floats.FloatArrayList; import it.unimi.dsi.fastutil.ints.*; import lombok.val; @@ -53,24 +52,6 @@ public interface JsonAdapters { public void write(JsonWriter writer, DynamicFloat f) {} } - class DropTypeAdapter extends TypeAdapter { - @Override - public void write(JsonWriter out, DropType value) throws IOException { - if (value.isString()) - out.value(value.getAsString()); - else out.value(value.getAsInt()); - } - - @Override - public DropType read(JsonReader in) throws IOException { - return switch (in.peek()) { - default -> new DropType(0); - case STRING -> new DropType(in.nextString()); - case NUMBER -> new DropType(in.nextInt()); - }; - } - } - class IntListAdapter extends TypeAdapter { @Override public IntList read(JsonReader reader) throws IOException { diff --git a/src/main/java/emu/grasscutter/utils/JsonUtils.java b/src/main/java/emu/grasscutter/utils/JsonUtils.java index 8e9a7e957..cfb3ba20d 100644 --- a/src/main/java/emu/grasscutter/utils/JsonUtils.java +++ b/src/main/java/emu/grasscutter/utils/JsonUtils.java @@ -3,23 +3,27 @@ package emu.grasscutter.utils; import com.google.gson.*; import com.google.gson.reflect.TypeToken; import emu.grasscutter.data.common.DynamicFloat; -import emu.grasscutter.game.world.*; +import emu.grasscutter.game.world.GridPosition; +import emu.grasscutter.game.world.Position; import emu.grasscutter.utils.JsonAdapters.*; -import emu.grasscutter.utils.objects.*; +import emu.grasscutter.utils.objects.JObject; import it.unimi.dsi.fastutil.ints.IntList; - -import java.io.*; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; -import java.nio.file.*; -import java.util.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; public final class JsonUtils { static final Gson gson = new GsonBuilder() .setPrettyPrinting() .registerTypeAdapter(DynamicFloat.class, new DynamicFloatAdapter()) - .registerTypeAdapter(DropType.class, new DropTypeAdapter()) .registerTypeAdapter(IntList.class, new IntListAdapter()) .registerTypeAdapter(Position.class, new PositionAdapter()) .registerTypeAdapter(GridPosition.class, new GridPositionAdapter()) diff --git a/src/main/java/emu/grasscutter/utils/objects/DropType.java b/src/main/java/emu/grasscutter/utils/objects/DropType.java deleted file mode 100644 index 55762e1e9..000000000 --- a/src/main/java/emu/grasscutter/utils/objects/DropType.java +++ /dev/null @@ -1,47 +0,0 @@ -package emu.grasscutter.utils.objects; - -import lombok.Getter; - -@Getter -public final class DropType { - private final Object raw; - private final int value; - - public DropType(int value) { - this.raw = value; - this.value = value; - } - - public DropType(String value) { - this.raw = value; - this.value = switch (value) { - default -> Integer.parseInt(value); - case "ForceDrop" -> 2; - }; - } - - /** - * @return Whether the drop type value is a string. - */ - public boolean isString() { - return this.raw instanceof String; - } - - /** - * @return The drop type value as a string. - */ - public String getAsString() { - if (this.raw instanceof String) - return (String) this.raw; - throw new UnsupportedOperationException(); - } - - /** - * @return The drop type value as an integer. - */ - public int getAsInt() { - if (this.raw instanceof Integer) - return (int) this.raw; - throw new UnsupportedOperationException(); - } -}