From eedab79253154942e70168277325540694817250 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Fri, 22 Apr 2022 07:37:25 +0800 Subject: [PATCH] fetter try --- .../emu/grasscutter/data/GenshinData.java | 15 +++++++ .../emu/grasscutter/data/def/AvatarData.java | 9 ++++ .../emu/grasscutter/data/def/FetterData.java | 24 +++++++++++ .../game/avatar/GenshinAvatar.java | 34 ++++++++++++++- .../grasscutter/game/props/FetterState.java | 42 +++++++++++++++++++ 5 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 src/main/java/emu/grasscutter/data/def/FetterData.java create mode 100644 src/main/java/emu/grasscutter/game/props/FetterState.java diff --git a/src/main/java/emu/grasscutter/data/GenshinData.java b/src/main/java/emu/grasscutter/data/GenshinData.java index 7dc5a5f7c..1996bf074 100644 --- a/src/main/java/emu/grasscutter/data/GenshinData.java +++ b/src/main/java/emu/grasscutter/data/GenshinData.java @@ -1,7 +1,9 @@ package emu.grasscutter.data; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import emu.grasscutter.Grasscutter; @@ -54,6 +56,7 @@ public class GenshinData { private static final Int2ObjectMap avatarCostumeDataItemIdMap = new Int2ObjectLinkedOpenHashMap<>(); private static final Int2ObjectMap sceneDataMap = new Int2ObjectLinkedOpenHashMap<>(); + private static final Int2ObjectMap fetterDataMap = new Int2ObjectOpenHashMap<>(); public static Int2ObjectMap getMapByResourceDef(Class resourceDefinition) { Int2ObjectMap map = null; @@ -221,4 +224,16 @@ public class GenshinData { public static Int2ObjectMap getSceneDataMap() { return sceneDataMap; } + + public static Map> getFetterDataEntries() { + // Can I do this? + Map> fetters = new HashMap<>(); + fetterDataMap.forEach((k, v) -> { + if (!fetters.containsKey(v.getAvatarId())) { + fetters.put(v.getAvatarId(), new ArrayList<>()); + } + fetters.get(v.getAvatarId()).add(k); + }); + return fetters; + } } diff --git a/src/main/java/emu/grasscutter/data/def/AvatarData.java b/src/main/java/emu/grasscutter/data/def/AvatarData.java index dcc503994..8097e04a7 100644 --- a/src/main/java/emu/grasscutter/data/def/AvatarData.java +++ b/src/main/java/emu/grasscutter/data/def/AvatarData.java @@ -55,6 +55,8 @@ public class AvatarData extends GenshinResource { private float[] defenseGrowthCurve; private AvatarSkillDepotData skillDepot; private IntList abilities; + + private List fetters; @Override public int getId(){ @@ -193,9 +195,16 @@ public class AvatarData extends GenshinResource { return abilities; } + public List getFetters() { + return fetters; + } + @Override public void onLoad() { this.skillDepot = GenshinData.getAvatarSkillDepotDataMap().get(this.SkillDepotId); + + // Get fetters from GenshinData + this.fetters = GenshinData.getFetterDataEntries().get(this.Id); int size = GenshinData.getAvatarCurveDataMap().size(); this.hpGrowthCurve = new float[size]; diff --git a/src/main/java/emu/grasscutter/data/def/FetterData.java b/src/main/java/emu/grasscutter/data/def/FetterData.java new file mode 100644 index 000000000..d17c940d1 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/def/FetterData.java @@ -0,0 +1,24 @@ +package emu.grasscutter.data.def; + +import emu.grasscutter.data.GenshinResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.ResourceType.LoadPriority; + +@ResourceType(name = {"FetterInfoExcelConfigData.json", "FettersExcelConfigData.json", "FetterStoryExcelConfigData.json"}, loadPriority = LoadPriority.HIGHEST) +public class FetterData extends GenshinResource { + private int AvatarId; + private int FetterId; + + @Override + public int getId() { + return FetterId; + } + + public int getAvatarId() { + return AvatarId; + } + + @Override + public void onLoad() { + } +} diff --git a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java index 9723c23d7..e5dccc42d 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -1,7 +1,9 @@ package emu.grasscutter.game.avatar; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -39,9 +41,11 @@ import emu.grasscutter.game.inventory.EquipType; import emu.grasscutter.game.inventory.GenshinItem; import emu.grasscutter.game.props.ElementType; import emu.grasscutter.game.props.EntityIdType; +import emu.grasscutter.game.props.FetterState; import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.net.proto.AvatarFetterInfoOuterClass.AvatarFetterInfo; +import emu.grasscutter.net.proto.FetterDataOuterClass.FetterData; import emu.grasscutter.net.proto.AvatarInfoOuterClass.AvatarInfo; import emu.grasscutter.server.packet.send.PacketAbilityChangeNotify; import emu.grasscutter.server.packet.send.PacketAvatarEquipChangeNotify; @@ -73,6 +77,8 @@ public class GenshinAvatar { @Transient private final Int2FloatOpenHashMap fightProp; @Transient private Set extraAbilityEmbryos; + private List fetters; + private Map skillLevelMap; // Talent levels private Map proudSkillBonusMap; // Talent bonus levels (from const) private int skillDepotId; @@ -89,7 +95,8 @@ public class GenshinAvatar { this.equips = new Int2ObjectOpenHashMap<>(); this.fightProp = new Int2FloatOpenHashMap(); this.extraAbilityEmbryos = new HashSet<>(); - this.proudSkillBonusMap = new HashMap<>(); // TODO Move to genshin avatar + this.proudSkillBonusMap = new HashMap<>(); + this.fetters = new ArrayList<>(); // TODO Move to genshin avatar } // On creation @@ -266,6 +273,14 @@ public class GenshinAvatar { return extraAbilityEmbryos; } + public void setFetterList(List fetterList) { + this.fetterList = fetterList; + } + + public List getFetterList() { + return fetterList; + } + public float getCurrentHp() { return currentHp; } @@ -385,6 +400,9 @@ public class GenshinAvatar { // Extra ability embryos Set prevExtraAbilityEmbryos = this.getExtraAbilityEmbryos(); this.extraAbilityEmbryos = new HashSet<>(); + + // Fetters + this.setFetterList(data.getFetters()); // Get hp percent, set to 100% if none float hpPercent = this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) <= 0 ? 1f : this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) / this.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); @@ -683,6 +701,18 @@ public class GenshinAvatar { } public AvatarInfo toProto() { + AvatarFetterInfo.Builder avatarFetter = AvatarFetterInfo.newBuilder() + .setExpLevel(10) + .setExpNumber(6325); // Highest Level + + for (int i = 0; i < this.getFetterList().size(); i++) { + avatarFetter.addFetterList( + FetterData.newBuilder() + .setFetterId(this.getFetterList().get(i)) + .setFetterState(FetterState.FINISH.getValue()) + ); + } + AvatarInfo.Builder avatarInfo = AvatarInfo.newBuilder() .setAvatarId(this.getAvatarId()) .setGuid(this.getGuid()) @@ -696,7 +726,7 @@ public class GenshinAvatar { .putAllProudSkillExtraLevel(getProudSkillBonusMap()) .setAvatarType(1) .setBornTime(this.getBornTime()) - .setFetterInfo(AvatarFetterInfo.newBuilder().setExpLevel(1)) + .setFetterInfo(avatarFetter) .setWearingFlycloakId(this.getFlyCloak()) .setCostumeId(this.getCostume()); diff --git a/src/main/java/emu/grasscutter/game/props/FetterState.java b/src/main/java/emu/grasscutter/game/props/FetterState.java new file mode 100644 index 000000000..346060e19 --- /dev/null +++ b/src/main/java/emu/grasscutter/game/props/FetterState.java @@ -0,0 +1,42 @@ +package emu.grasscutter.game.props; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +public enum FetterState { + NONE(0), + NOT_OPEN(1), + OPEN(1), + FINISH(3); + + private final int value; + private static final Int2ObjectMap map = new Int2ObjectOpenHashMap<>(); + private static final Map stringMap = new HashMap<>(); + + static { + Stream.of(values()).forEach(e -> { + map.put(e.getValue(), e); + stringMap.put(e.name(), e); + }); + } + + private FetterState(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public static FetterState getTypeByValue(int value) { + return map.getOrDefault(value, NONE); + } + + public static FetterState getTypeByName(String name) { + return stringMap.getOrDefault(name, NONE); + } +}