mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-26 16:40:55 +00:00
Fix dropType
de-serialization
This commit is contained in:
parent
6d6e6a041d
commit
6080297be9
@ -3,9 +3,11 @@ package emu.grasscutter.data.binout;
|
|||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import emu.grasscutter.data.common.DynamicFloat;
|
import emu.grasscutter.data.common.DynamicFloat;
|
||||||
import emu.grasscutter.game.props.ElementType;
|
import emu.grasscutter.game.props.ElementType;
|
||||||
import java.io.Serializable;
|
import emu.grasscutter.utils.objects.DropType;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class AbilityModifier implements Serializable {
|
public class AbilityModifier implements Serializable {
|
||||||
private static final long serialVersionUID = -2001232313615923575L;
|
private static final long serialVersionUID = -2001232313615923575L;
|
||||||
|
|
||||||
@ -327,7 +329,7 @@ public class AbilityModifier implements Serializable {
|
|||||||
public AbilityModifierAction[] successActions;
|
public AbilityModifierAction[] successActions;
|
||||||
public AbilityModifierAction[] failActions;
|
public AbilityModifierAction[] failActions;
|
||||||
|
|
||||||
public int dropType;
|
public DropType dropType;
|
||||||
public DynamicFloat baseEnergy;
|
public DynamicFloat baseEnergy;
|
||||||
public DynamicFloat ratio = DynamicFloat.ONE;
|
public DynamicFloat ratio = DynamicFloat.ONE;
|
||||||
public int configID;
|
public int configID;
|
||||||
|
@ -29,7 +29,7 @@ public final class ActionGenerateElemBall extends AbilityActionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if we should allow elem ball generation
|
// Check if we should allow elem ball generation
|
||||||
if (action.dropType == 0x0) {
|
if (action.dropType.getValue() == 0) {
|
||||||
String levelEntityConfig = owner.getScene().getSceneData().getLevelEntityConfig();
|
String levelEntityConfig = owner.getScene().getSceneData().getLevelEntityConfig();
|
||||||
ConfigLevelEntity config = GameData.getConfigLevelEntityDataMap().get(levelEntityConfig);
|
ConfigLevelEntity config = GameData.getConfigLevelEntityDataMap().get(levelEntityConfig);
|
||||||
if (config != null
|
if (config != null
|
||||||
@ -38,12 +38,12 @@ public final class ActionGenerateElemBall extends AbilityActionHandler {
|
|||||||
Grasscutter.getLogger().warn("This level config don't allow element balls");
|
Grasscutter.getLogger().warn("This level config don't allow element balls");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (action.dropType == 0x1) {
|
} else if (action.dropType.getValue() == 1) {
|
||||||
if (owner.getScene().getSceneData().getSceneType() != SceneType.SCENE_WORLD) {
|
if (owner.getScene().getSceneData().getSceneType() != SceneType.SCENE_WORLD) {
|
||||||
Grasscutter.getLogger().warn("This level config only allows element balls on big world");
|
Grasscutter.getLogger().warn("This level config only allows element balls on big world");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} // Else the drop is forced
|
} // else: the drop is forced. (value 2)
|
||||||
|
|
||||||
var energy = action.baseEnergy.get(ability) * action.ratio.get(ability);
|
var energy = action.baseEnergy.get(ability) * action.ratio.get(ability);
|
||||||
if (energy <= 0.0) return true;
|
if (energy <= 0.0) return true;
|
||||||
|
@ -1,24 +1,18 @@
|
|||||||
package emu.grasscutter.utils;
|
package emu.grasscutter.utils;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.*;
|
||||||
import com.google.gson.TypeAdapter;
|
|
||||||
import com.google.gson.TypeAdapterFactory;
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.*;
|
||||||
import com.google.gson.stream.JsonToken;
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
|
||||||
import emu.grasscutter.data.common.DynamicFloat;
|
import emu.grasscutter.data.common.DynamicFloat;
|
||||||
import emu.grasscutter.game.world.GridPosition;
|
import emu.grasscutter.game.world.*;
|
||||||
import emu.grasscutter.game.world.Position;
|
import emu.grasscutter.utils.objects.DropType;
|
||||||
import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
import it.unimi.dsi.fastutil.floats.FloatArrayList;
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
import it.unimi.dsi.fastutil.ints.*;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import lombok.val;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Objects;
|
|
||||||
import lombok.val;
|
|
||||||
|
|
||||||
public interface JsonAdapters {
|
public interface JsonAdapters {
|
||||||
class DynamicFloatAdapter extends TypeAdapter<DynamicFloat> {
|
class DynamicFloatAdapter extends TypeAdapter<DynamicFloat> {
|
||||||
@ -59,6 +53,24 @@ public interface JsonAdapters {
|
|||||||
public void write(JsonWriter writer, DynamicFloat f) {}
|
public void write(JsonWriter writer, DynamicFloat f) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DropTypeAdapter extends TypeAdapter<DropType> {
|
||||||
|
@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<IntList> {
|
class IntListAdapter extends TypeAdapter<IntList> {
|
||||||
@Override
|
@Override
|
||||||
public IntList read(JsonReader reader) throws IOException {
|
public IntList read(JsonReader reader) throws IOException {
|
||||||
|
@ -3,27 +3,23 @@ package emu.grasscutter.utils;
|
|||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import emu.grasscutter.data.common.DynamicFloat;
|
import emu.grasscutter.data.common.DynamicFloat;
|
||||||
import emu.grasscutter.game.world.GridPosition;
|
import emu.grasscutter.game.world.*;
|
||||||
import emu.grasscutter.game.world.Position;
|
|
||||||
import emu.grasscutter.utils.JsonAdapters.*;
|
import emu.grasscutter.utils.JsonAdapters.*;
|
||||||
import emu.grasscutter.utils.objects.JObject;
|
import emu.grasscutter.utils.objects.*;
|
||||||
import it.unimi.dsi.fastutil.ints.IntList;
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Path;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public final class JsonUtils {
|
public final class JsonUtils {
|
||||||
static final Gson gson =
|
static final Gson gson =
|
||||||
new GsonBuilder()
|
new GsonBuilder()
|
||||||
.setPrettyPrinting()
|
.setPrettyPrinting()
|
||||||
.registerTypeAdapter(DynamicFloat.class, new DynamicFloatAdapter())
|
.registerTypeAdapter(DynamicFloat.class, new DynamicFloatAdapter())
|
||||||
|
.registerTypeAdapter(DropType.class, new DropTypeAdapter())
|
||||||
.registerTypeAdapter(IntList.class, new IntListAdapter())
|
.registerTypeAdapter(IntList.class, new IntListAdapter())
|
||||||
.registerTypeAdapter(Position.class, new PositionAdapter())
|
.registerTypeAdapter(Position.class, new PositionAdapter())
|
||||||
.registerTypeAdapter(GridPosition.class, new GridPositionAdapter())
|
.registerTypeAdapter(GridPosition.class, new GridPositionAdapter())
|
||||||
|
47
src/main/java/emu/grasscutter/utils/objects/DropType.java
Normal file
47
src/main/java/emu/grasscutter/utils/objects/DropType.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user