From 9edb70d6cf6d2f435137ade57211ed553ea465d1 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Fri, 22 Apr 2022 22:27:40 +0800 Subject: [PATCH] AvatarFetterLevel --- .../emu/grasscutter/data/GenshinData.java | 10 ++++++++ .../data/def/AvatarFetterLevelData.java | 23 +++++++++++++++++ .../game/avatar/GenshinAvatar.java | 23 +++++++++++++++-- .../game/managers/InventoryManager.java | 25 +++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/main/java/emu/grasscutter/data/def/AvatarFetterLevelData.java diff --git a/src/main/java/emu/grasscutter/data/GenshinData.java b/src/main/java/emu/grasscutter/data/GenshinData.java index 7e14b1b46..155ebb60c 100644 --- a/src/main/java/emu/grasscutter/data/GenshinData.java +++ b/src/main/java/emu/grasscutter/data/GenshinData.java @@ -31,6 +31,7 @@ public class GenshinData { private static final Int2ObjectMap avatarSkillDepotDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap avatarSkillDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap avatarCurveDataMap = new Int2ObjectLinkedOpenHashMap<>(); + private static final Int2ObjectMap avatarFetterLevelDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap avatarPromoteDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap avatarTalentDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap proudSkillDataMap = new Int2ObjectOpenHashMap<>(); @@ -114,6 +115,10 @@ public class GenshinData { return playerLevelDataMap; } + public static Int2ObjectMap getAvatarFetterLevelDataMap() { + return avatarFetterLevelDataMap; + } + public static Int2ObjectMap getAvatarLevelDataMap() { return avatarLevelDataMap; } @@ -175,6 +180,11 @@ public class GenshinData { AvatarLevelData levelData = avatarLevelDataMap.get(level); return levelData != null ? levelData.getExp() : 0; } + + public static int getAvatarFetterLevelExpRequired(int level) { + AvatarFetterLevelData levelData = avatarFetterLevelDataMap.get(level); + return levelData != null ? levelData.getExp() : 0; + } public static Int2ObjectMap getProudSkillDataMap() { return proudSkillDataMap; diff --git a/src/main/java/emu/grasscutter/data/def/AvatarFetterLevelData.java b/src/main/java/emu/grasscutter/data/def/AvatarFetterLevelData.java new file mode 100644 index 000000000..8dd93eea5 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/def/AvatarFetterLevelData.java @@ -0,0 +1,23 @@ +package emu.grasscutter.data.def; + +import emu.grasscutter.data.GenshinResource; +import emu.grasscutter.data.ResourceType; + +@ResourceType(name = "AvatarFettersLevelExcelConfigData.json") +public class AvatarFetterLevelData extends GenshinResource { + private int FetterLevel; + private int NeedExp; + + @Override + public int getId() { + return this.FetterLevel; + } + + public int getLevel() { + return FetterLevel; + } + + public int getExp() { + return NeedExp; + } +} diff --git a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java index 6906d3896..d4e998d46 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -89,6 +89,9 @@ public class GenshinAvatar { private int flyCloak; private int costume; private int bornTime; + + private int fetterLevel = 1; + private int fetterExp; public GenshinAvatar() { // Morhpia only! @@ -281,6 +284,22 @@ public class GenshinAvatar { return fetters; } + public int getFetterLevel() { + return fetterLevel; + } + + public void setFetterLevel(int fetterLevel) { + this.fetterLevel = fetterLevel; + } + + public int getFetterExp() { + return fetterExp; + } + + public void setFetterExp(int fetterExp) { + this.fetterExp = fetterExp; + } + public float getCurrentHp() { return currentHp; } @@ -702,8 +721,8 @@ public class GenshinAvatar { public AvatarInfo toProto() { AvatarFetterInfo.Builder avatarFetter = AvatarFetterInfo.newBuilder() - .setExpLevel(10) - .setExpNumber(6325); // Highest Level + .setExpLevel(this.getFetterLevel()) + .setExpNumber(this.getFetterExp()); if (this.getFetterList() != null) { for (int i = 0; i < this.getFetterList().size(); i++) { diff --git a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java index 532155db1..96ab032b8 100644 --- a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java +++ b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java @@ -711,6 +711,31 @@ public class InventoryManager { player.sendPacket(new PacketAvatarUpgradeRsp(avatar, oldLevel, oldPropMap)); } + public void upgradeAvatarFetterLevel(GenshinPlayer player, GenshinAvatar avatar, int expGain) { + // May work. Not test. + int maxLevel = GenshinData.getAvatarFetterLevelDataMap().get(GenshinData.getAvatarFetterLevelDataMap().size() - 1).getLevel(); + int level = avatar.getFetterLevel(); + int exp = avatar.getFetterExp(); + int reqExp = GenshinData.getAvatarFetterLevelExpRequired(level); + + while (expGain > 0 && reqExp > 0 && level < maxLevel) { + int toGain = Math.min(expGain, reqExp - exp); + exp += toGain; + expGain -= toGain; + if (exp >= reqExp) { + exp = 0; + level += 1; + reqExp = GenshinData.getAvatarFetterLevelExpRequired(level); + } + } + + avatar.setFetterLevel(level); + avatar.setFetterExp(exp); + avatar.save(); + + player.sendPacket(new PacketAvatarPropNotify(avatar)); + } + public void upgradeAvatarSkill(GenshinPlayer player, long guid, int skillId) { // Sanity checks GenshinAvatar avatar = player.getAvatars().getAvatarByGuid(guid);