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 1/9] 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); From 34c0c6b01b69d3ed300cef9a0c91cd39e9f04de2 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Fri, 22 Apr 2022 23:46:24 +0800 Subject: [PATCH 2/9] setfetterlevel command --- .../commands/SetFetterLevelCommand.java | 41 +++++++++++++++++++ .../game/managers/InventoryManager.java | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java b/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java new file mode 100644 index 000000000..60a7e4796 --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java @@ -0,0 +1,41 @@ +package emu.grasscutter.command.commands; + +import java.util.List; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.entity.EntityAvatar; + +@Command(label = "setfetterlevel", usage = "setfetterlevel ", + description = "Sets your fetter level for your current active character", + aliases = {"setfetterlvl"}, permission = "player.setfetterlevel") +public final class SetFetterLevelCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 1) { + CommandHandler.sendMessage(sender, "Usage: setfetterlevel "); + return; + } + + try { + int fetterLevel = Integer.parseInt(args.get(0)); + if (fetterLevel < 0 || fetterLevel > 10) { + CommandHandler.sendMessage(sender, "Fetter level must be between 0 and 10."); + return; + } + EntityAvatar avatar = sender.getTeamManager().getCurrentAvatarEntity(); + avatar.getAvatar().setFetterLevel(fetterLevel); + CommandHandler.sendMessage(sender, "Fetter level set to " + fetterLevel); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(null, "Invalid fetter level."); + } + } + +} diff --git a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java index 96ab032b8..4ea9e6bc1 100644 --- a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java +++ b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java @@ -713,7 +713,7 @@ public class InventoryManager { public void upgradeAvatarFetterLevel(GenshinPlayer player, GenshinAvatar avatar, int expGain) { // May work. Not test. - int maxLevel = GenshinData.getAvatarFetterLevelDataMap().get(GenshinData.getAvatarFetterLevelDataMap().size() - 1).getLevel(); + int maxLevel = 10; // Keep it until I think of a more "elegant" way int level = avatar.getFetterLevel(); int exp = avatar.getFetterExp(); int reqExp = GenshinData.getAvatarFetterLevelExpRequired(level); From f9b5c8a9ee2a2fbfe9955bbc14525303d9984f14 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 01:36:48 +0800 Subject: [PATCH 3/9] command fix --- .../commands/SetFetterLevelCommand.java | 13 +++++-- .../send/PacketAvatarFetterDataNotify.java | 38 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java diff --git a/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java b/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java index 60a7e4796..74847a49a 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java @@ -4,8 +4,10 @@ import java.util.List; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.data.GenshinData; import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.avatar.GenshinAvatar; +import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; @Command(label = "setfetterlevel", usage = "setfetterlevel ", description = "Sets your fetter level for your current active character", @@ -30,8 +32,13 @@ public final class SetFetterLevelCommand implements CommandHandler { CommandHandler.sendMessage(sender, "Fetter level must be between 0 and 10."); return; } - EntityAvatar avatar = sender.getTeamManager().getCurrentAvatarEntity(); - avatar.getAvatar().setFetterLevel(fetterLevel); + GenshinAvatar avatar = sender.getTeamManager().getCurrentAvatarEntity().getAvatar(); + + avatar.setFetterLevel(fetterLevel); + avatar.setFetterExp(GenshinData.getAvatarFetterLevelDataMap().get(fetterLevel).getExp()); + avatar.save(); + + sender.sendPacket(new PacketAvatarFetterDataNotify(avatar)); CommandHandler.sendMessage(sender, "Fetter level set to " + fetterLevel); } catch (NumberFormatException ignored) { CommandHandler.sendMessage(null, "Invalid fetter level."); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java new file mode 100644 index 000000000..86cea0e02 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java @@ -0,0 +1,38 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.GenshinAvatar; +import emu.grasscutter.game.props.FetterState; +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFetterDataNotifyOuterClass.AvatarFetterDataNotify; +import emu.grasscutter.net.proto.AvatarFetterInfoOuterClass.AvatarFetterInfo; +import emu.grasscutter.net.proto.FetterDataOuterClass.FetterData; + +public class PacketAvatarFetterDataNotify extends GenshinPacket { + + public PacketAvatarFetterDataNotify(GenshinAvatar avatar) { + super(PacketOpcodes.AvatarFetterDataNotify); + + AvatarFetterInfo.Builder avatarFetter = AvatarFetterInfo.newBuilder() + .setExpLevel(avatar.getFetterLevel()) + .setExpNumber(avatar.getFetterExp()); + + if (avatar.getFetterList() != null) { + for (int i = 0; i < avatar.getFetterList().size(); i++) { + avatarFetter.addFetterList( + FetterData.newBuilder() + .setFetterId(avatar.getFetterList().get(i)) + .setFetterState(FetterState.FINISH.getValue()) + ); + } + } + + AvatarFetterInfo avatarFetterInfo = avatarFetter.build(); + + AvatarFetterDataNotify proto = AvatarFetterDataNotify.newBuilder() + .putFetterInfoMap(avatar.getGuid(), avatarFetterInfo) + .build(); + + this.setData(proto); + } +} From 53659d2586ef6b356bcbf83678c705a5aa1ad568 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 06:08:37 +0800 Subject: [PATCH 4/9] AvatarFetterLevelReward --- .../emu/grasscutter/data/GenshinData.java | 5 +++ .../emu/grasscutter/data/def/AvatarData.java | 9 +++++ .../data/def/FetterCharacterCardData.java | 24 +++++++++++++ .../game/avatar/GenshinAvatar.java | 11 ++++++ .../HandlerAvatarFetterLevelRewardReq.java | 32 +++++++++++++++++ .../PacketAvatarFetterLevelRewardRsp.java | 35 +++++++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 src/main/java/emu/grasscutter/data/def/FetterCharacterCardData.java create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java diff --git a/src/main/java/emu/grasscutter/data/GenshinData.java b/src/main/java/emu/grasscutter/data/GenshinData.java index 155ebb60c..98f235c1e 100644 --- a/src/main/java/emu/grasscutter/data/GenshinData.java +++ b/src/main/java/emu/grasscutter/data/GenshinData.java @@ -58,6 +58,7 @@ public class GenshinData { private static final Int2ObjectMap sceneDataMap = new Int2ObjectLinkedOpenHashMap<>(); private static final Int2ObjectMap fetterDataMap = new Int2ObjectOpenHashMap<>(); + private static final Int2ObjectMap fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>(); // Cache private static Map> fetters = new HashMap<>(); @@ -119,6 +120,10 @@ public class GenshinData { return avatarFetterLevelDataMap; } + public static Int2ObjectMap getFetterCharacterCardDataMap() { + return fetterCharacterCardDataMap; + } + public static Int2ObjectMap getAvatarLevelDataMap() { return avatarLevelDataMap; } diff --git a/src/main/java/emu/grasscutter/data/def/AvatarData.java b/src/main/java/emu/grasscutter/data/def/AvatarData.java index 8097e04a7..a714344ae 100644 --- a/src/main/java/emu/grasscutter/data/def/AvatarData.java +++ b/src/main/java/emu/grasscutter/data/def/AvatarData.java @@ -57,6 +57,7 @@ public class AvatarData extends GenshinResource { private IntList abilities; private List fetters; + private int nameCardRewardId; @Override public int getId(){ @@ -199,12 +200,20 @@ public class AvatarData extends GenshinResource { return fetters; } + public int getNameCardRewardId() { + return nameCardRewardId; + } + @Override public void onLoad() { this.skillDepot = GenshinData.getAvatarSkillDepotDataMap().get(this.SkillDepotId); // Get fetters from GenshinData this.fetters = GenshinData.getFetterDataEntries().get(this.Id); + + if (GenshinData.getFetterCharacterCardDataMap().get(this.Id) != null) { + this.nameCardRewardId = GenshinData.getFetterCharacterCardDataMap().get(this.Id).getRewardId(); + } int size = GenshinData.getAvatarCurveDataMap().size(); this.hpGrowthCurve = new float[size]; diff --git a/src/main/java/emu/grasscutter/data/def/FetterCharacterCardData.java b/src/main/java/emu/grasscutter/data/def/FetterCharacterCardData.java new file mode 100644 index 000000000..2bf96ad8e --- /dev/null +++ b/src/main/java/emu/grasscutter/data/def/FetterCharacterCardData.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 = "FetterCharacterCardExcelConfigData.json", loadPriority = LoadPriority.HIGHEST) +public class FetterCharacterCardData extends GenshinResource { + private int AvatarId; + private int RewardId; + + @Override + public int getId() { + return AvatarId; + } + + public int getRewardId() { + return RewardId; + } + + @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 d4e998d46..5ad553f9c 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -92,6 +92,8 @@ public class GenshinAvatar { private int fetterLevel = 1; private int fetterExp; + + private int nameCardRewardId; public GenshinAvatar() { // Morhpia only! @@ -110,6 +112,7 @@ public class GenshinAvatar { public GenshinAvatar(AvatarData data) { this(); this.avatarId = data.getId(); + this.nameCardRewardId = data.getNameCardRewardId(); this.data = data; this.bornTime = (int) (System.currentTimeMillis() / 1000); this.flyCloak = 140001; @@ -172,6 +175,14 @@ public class GenshinAvatar { this.satiation = satiation; } + public int getNameCardRewardId() { + return nameCardRewardId; + } + + public void setNameCardRewardId(int nameCardRewardId) { + this.nameCardRewardId = nameCardRewardId; + } + public int getSatiationPenalty() { return satiationPenalty; } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java new file mode 100644 index 000000000..d3431d535 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java @@ -0,0 +1,32 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFetterLevelRewardReqOuterClass.AvatarFetterLevelRewardReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarFetterLevelRewardRsp; +import emu.grasscutter.net.packet.PacketHandler; + +@Opcodes(PacketOpcodes.AvatarFetterLevelRewardReq) +public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarFetterLevelRewardReq req = AvatarFetterLevelRewardReq.parseFrom(payload); + if (req.getFetterLevel() < 10) { + // You don't have a full level of fetter level, why do you want to get a divorce certificate? + session.send(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); + } else { + long avatarGuid = req.getAvatarGuid(); + + int rewardId = session + .getPlayer() + .getAvatars() + .getAvatarByGuid(avatarGuid) + .getNameCardRewardId(); + + // Here need to send the packets, I am not at all clear ah! + + session.send(new PacketAvatarFetterLevelRewardRsp(avatarGuid, req.getFetterLevel(), rewardId)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java new file mode 100644 index 000000000..e9d4895ff --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java @@ -0,0 +1,35 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFetterLevelRewardRspOuterClass.AvatarFetterLevelRewardRsp; + +public class PacketAvatarFetterLevelRewardRsp extends GenshinPacket { + + public PacketAvatarFetterLevelRewardRsp(long guid, int fetterLevel, int rewardId) { + super(PacketOpcodes.AvatarFetterLevelRewardRsp); + + AvatarFetterLevelRewardRsp proto = AvatarFetterLevelRewardRsp.newBuilder() + .setAvatarGuid(guid) + .setFetterLevel(fetterLevel) + .setRetcode(0) + .setRewardId(rewardId) + .build(); + + this.setData(proto); + } + + public PacketAvatarFetterLevelRewardRsp(long guid, int fetterLevel) { + super(PacketOpcodes.AvatarFetterLevelRewardRsp); + + AvatarFetterLevelRewardRsp proto = AvatarFetterLevelRewardRsp.newBuilder() + .setAvatarGuid(guid) + .setFetterLevel(fetterLevel) + .setRetcode(1) + .setRewardId(0) + .build(); + + this.setData(proto); + } + +} From 23481cfe0c655dfee0e0dbc1838dd61ea987e785 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 10:51:22 +0800 Subject: [PATCH 5/9] OpenCond for unlocking judgment --- .../grasscutter/data/common/OpenCondData.java | 24 +++++++++++++++++++ .../emu/grasscutter/data/def/FetterData.java | 8 +++++++ 2 files changed, 32 insertions(+) create mode 100644 src/main/java/emu/grasscutter/data/common/OpenCondData.java diff --git a/src/main/java/emu/grasscutter/data/common/OpenCondData.java b/src/main/java/emu/grasscutter/data/common/OpenCondData.java new file mode 100644 index 000000000..9e7b62b11 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/common/OpenCondData.java @@ -0,0 +1,24 @@ +package emu.grasscutter.data.common; + +import java.util.List; + +public class OpenCondData { + private String CondType; + private List ParamList; + + public String getCondType() { + return CondType; + } + + public void setCondType(String condType) { + CondType = condType; + } + + public List getParamList() { + return ParamList; + } + + public void setParamList(List paramList) { + ParamList = paramList; + } +} diff --git a/src/main/java/emu/grasscutter/data/def/FetterData.java b/src/main/java/emu/grasscutter/data/def/FetterData.java index d17c940d1..dc88fd795 100644 --- a/src/main/java/emu/grasscutter/data/def/FetterData.java +++ b/src/main/java/emu/grasscutter/data/def/FetterData.java @@ -1,13 +1,17 @@ package emu.grasscutter.data.def; +import java.util.List; + import emu.grasscutter.data.GenshinResource; import emu.grasscutter.data.ResourceType; import emu.grasscutter.data.ResourceType.LoadPriority; +import emu.grasscutter.data.common.OpenCondData; @ResourceType(name = {"FetterInfoExcelConfigData.json", "FettersExcelConfigData.json", "FetterStoryExcelConfigData.json"}, loadPriority = LoadPriority.HIGHEST) public class FetterData extends GenshinResource { private int AvatarId; private int FetterId; + private List OpenCond; @Override public int getId() { @@ -18,6 +22,10 @@ public class FetterData extends GenshinResource { return AvatarId; } + public List getOpenConds() { + return OpenCond; + } + @Override public void onLoad() { } From 45281695feaffad71d77921eec321e7424cb478e Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:03:29 +0800 Subject: [PATCH 6/9] Try to give name card --- .../data/common/RewardItemData.java | 22 +++++++++++++++ .../emu/grasscutter/data/def/RewardData.java | 27 +++++++++++++++++++ .../game/avatar/GenshinAvatar.java | 1 + .../HandlerAvatarFetterLevelRewardReq.java | 21 +++++++++++++-- 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/main/java/emu/grasscutter/data/common/RewardItemData.java create mode 100644 src/main/java/emu/grasscutter/data/def/RewardData.java diff --git a/src/main/java/emu/grasscutter/data/common/RewardItemData.java b/src/main/java/emu/grasscutter/data/common/RewardItemData.java new file mode 100644 index 000000000..024b89f7f --- /dev/null +++ b/src/main/java/emu/grasscutter/data/common/RewardItemData.java @@ -0,0 +1,22 @@ +package emu.grasscutter.data.common; + +public class RewardItemData { + private int ItemId; + private int ItemCount; + + public int getItemId() { + return ItemId; + } + + public void setItemId(int itemId) { + ItemId = itemId; + } + + public int getItemCount() { + return ItemCount; + } + + public void setItemCount(int itemCount) { + ItemCount = itemCount; + } +} diff --git a/src/main/java/emu/grasscutter/data/def/RewardData.java b/src/main/java/emu/grasscutter/data/def/RewardData.java new file mode 100644 index 000000000..46c39ac10 --- /dev/null +++ b/src/main/java/emu/grasscutter/data/def/RewardData.java @@ -0,0 +1,27 @@ +package emu.grasscutter.data.def; + +import java.util.List; + +import emu.grasscutter.data.GenshinResource; +import emu.grasscutter.data.ResourceType; +import emu.grasscutter.data.common.RewardItemData; + +@ResourceType(name = "RewardExcelConfigData.json") +public class RewardData extends GenshinResource { + public int RewardId; + public List RewardItemList; + + @Override + public int getId() { + return RewardId; + } + + public List getRewardItemList() { + return RewardItemList; + } + + @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 254258300..45b5c09ec 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -433,6 +433,7 @@ public class GenshinAvatar { // Fetters this.setFetterList(data.getFetters()); + this.setNameCardRewardId(data.getNameCardRewardId()); // 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); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java index d3431d535..2269f8606 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java @@ -1,10 +1,17 @@ package emu.grasscutter.server.packet.recv; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.GenshinData; +import emu.grasscutter.data.def.RewardData; +import emu.grasscutter.game.inventory.GenshinItem; +import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.AvatarFetterLevelRewardReqOuterClass.AvatarFetterLevelRewardReq; import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.packet.send.PacketAvatarFetterLevelRewardRsp; +import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; +import emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify; import emu.grasscutter.net.packet.PacketHandler; @Opcodes(PacketOpcodes.AvatarFetterLevelRewardReq) @@ -23,9 +30,19 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { .getAvatars() .getAvatarByGuid(avatarGuid) .getNameCardRewardId(); - - // Here need to send the packets, I am not at all clear ah! + RewardData card = GenshinData.getRewardDataMap().get(rewardId); + int cardId = card.getRewardItemList().get(0).getItemId(); + + if (session.getPlayer().getNameCardList().contains(cardId)) { + // Already got divorce certificate. + session.send(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); + return; + } + + GenshinItem item = new GenshinItem(cardId); + session.getPlayer().sendPacket(new PacketItemAddHintNotify(item, ActionReason.FetterLevelReward)); + session.send(new PacketUnlockNameCardNotify(cardId)); session.send(new PacketAvatarFetterLevelRewardRsp(avatarGuid, req.getFetterLevel(), rewardId)); } } From 88e1a0c5551a9686ccf95f301b1e821562b0c914 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 22:16:59 +0800 Subject: [PATCH 7/9] Will --- .../packet/recv/HandlerAvatarFetterLevelRewardReq.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java index 2269f8606..d93b157df 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java @@ -36,13 +36,14 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { if (session.getPlayer().getNameCardList().contains(cardId)) { // Already got divorce certificate. - session.send(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); + session.getPlayer().sendPacket(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); return; } GenshinItem item = new GenshinItem(cardId); + session.getPlayer().getInventory().addItem(item); session.getPlayer().sendPacket(new PacketItemAddHintNotify(item, ActionReason.FetterLevelReward)); - session.send(new PacketUnlockNameCardNotify(cardId)); + session.getPlayer().sendPacket(new PacketUnlockNameCardNotify(cardId)); session.send(new PacketAvatarFetterLevelRewardRsp(avatarGuid, req.getFetterLevel(), rewardId)); } } From 9c920b139aa13c2ad312b715ac3babdf589a8f1f Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sat, 23 Apr 2022 23:48:06 +0800 Subject: [PATCH 8/9] Name Card Done!!!!!!!!!!! --- .../java/emu/grasscutter/data/GenshinData.java | 5 +++++ .../emu/grasscutter/data/def/AvatarData.java | 9 +++++++++ .../grasscutter/game/avatar/GenshinAvatar.java | 18 ++++++++++++++++++ .../HandlerAvatarFetterLevelRewardReq.java | 13 ++++++++----- .../send/PacketAvatarFetterDataNotify.java | 7 +++++++ 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/main/java/emu/grasscutter/data/GenshinData.java b/src/main/java/emu/grasscutter/data/GenshinData.java index 98f235c1e..3b3d351da 100644 --- a/src/main/java/emu/grasscutter/data/GenshinData.java +++ b/src/main/java/emu/grasscutter/data/GenshinData.java @@ -59,6 +59,7 @@ public class GenshinData { private static final Int2ObjectMap sceneDataMap = new Int2ObjectLinkedOpenHashMap<>(); private static final Int2ObjectMap fetterDataMap = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap fetterCharacterCardDataMap = new Int2ObjectOpenHashMap<>(); + private static final Int2ObjectMap rewardDataMap = new Int2ObjectOpenHashMap<>(); // Cache private static Map> fetters = new HashMap<>(); @@ -243,6 +244,10 @@ public class GenshinData { return sceneDataMap; } + public static Int2ObjectMap getRewardDataMap() { + return rewardDataMap; + } + public static Map> getFetterDataEntries() { if (fetters.isEmpty()) { fetterDataMap.forEach((k, v) -> { diff --git a/src/main/java/emu/grasscutter/data/def/AvatarData.java b/src/main/java/emu/grasscutter/data/def/AvatarData.java index a714344ae..3beb21eec 100644 --- a/src/main/java/emu/grasscutter/data/def/AvatarData.java +++ b/src/main/java/emu/grasscutter/data/def/AvatarData.java @@ -58,6 +58,7 @@ public class AvatarData extends GenshinResource { private List fetters; private int nameCardRewardId; + private int nameCardId; @Override public int getId(){ @@ -204,6 +205,10 @@ public class AvatarData extends GenshinResource { return nameCardRewardId; } + public int getNameCardId() { + return nameCardId; + } + @Override public void onLoad() { this.skillDepot = GenshinData.getAvatarSkillDepotDataMap().get(this.SkillDepotId); @@ -214,6 +219,10 @@ public class AvatarData extends GenshinResource { if (GenshinData.getFetterCharacterCardDataMap().get(this.Id) != null) { this.nameCardRewardId = GenshinData.getFetterCharacterCardDataMap().get(this.Id).getRewardId(); } + + if (GenshinData.getRewardDataMap().get(this.nameCardRewardId) != null) { + this.nameCardId = GenshinData.getRewardDataMap().get(this.nameCardRewardId).getRewardItemList().get(0).getItemId(); + } int size = GenshinData.getAvatarCurveDataMap().size(); this.hpGrowthCurve = new float[size]; diff --git a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java index 45b5c09ec..ab2f67a43 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -94,6 +94,7 @@ public class GenshinAvatar { private int fetterExp; private int nameCardRewardId; + private int nameCardId; public GenshinAvatar() { // Morhpia only! @@ -113,6 +114,7 @@ public class GenshinAvatar { this(); this.avatarId = data.getId(); this.nameCardRewardId = data.getNameCardRewardId(); + this.nameCardId = data.getNameCardId(); this.data = data; this.bornTime = (int) (System.currentTimeMillis() / 1000); this.flyCloak = 140001; @@ -311,6 +313,14 @@ public class GenshinAvatar { this.fetterExp = fetterExp; } + public int getNameCardId() { + return nameCardId; + } + + public void setNameCardId(int nameCardId) { + this.nameCardId = nameCardId; + } + public float getCurrentHp() { return currentHp; } @@ -434,6 +444,7 @@ public class GenshinAvatar { // Fetters this.setFetterList(data.getFetters()); this.setNameCardRewardId(data.getNameCardRewardId()); + this.setNameCardId(data.getNameCardId()); // 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); @@ -746,6 +757,13 @@ public class GenshinAvatar { } } + int rewardId = this.getNameCardRewardId(); + int cardId = this.getNameCardId(); + + if (this.getPlayer().getNameCardList().contains(cardId)) { + avatarFetter.addRewardedFetterLevelList(rewardId); + } + AvatarInfo.Builder avatarInfo = AvatarInfo.newBuilder() .setAvatarId(this.getAvatarId()) .setGuid(this.getGuid()) diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java index d93b157df..51192f620 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java @@ -1,14 +1,15 @@ package emu.grasscutter.server.packet.recv; -import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.def.RewardData; +import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.inventory.GenshinItem; import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.AvatarFetterLevelRewardReqOuterClass.AvatarFetterLevelRewardReq; import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; import emu.grasscutter.server.packet.send.PacketAvatarFetterLevelRewardRsp; import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; import emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify; @@ -25,18 +26,19 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { } else { long avatarGuid = req.getAvatarGuid(); - int rewardId = session + GenshinAvatar avatar = session .getPlayer() .getAvatars() - .getAvatarByGuid(avatarGuid) - .getNameCardRewardId(); + .getAvatarByGuid(avatarGuid); + + int rewardId = avatar.getNameCardRewardId(); RewardData card = GenshinData.getRewardDataMap().get(rewardId); int cardId = card.getRewardItemList().get(0).getItemId(); if (session.getPlayer().getNameCardList().contains(cardId)) { // Already got divorce certificate. - session.getPlayer().sendPacket(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); + session.getPlayer().sendPacket(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel(), rewardId)); return; } @@ -45,6 +47,7 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { session.getPlayer().sendPacket(new PacketItemAddHintNotify(item, ActionReason.FetterLevelReward)); session.getPlayer().sendPacket(new PacketUnlockNameCardNotify(cardId)); session.send(new PacketAvatarFetterLevelRewardRsp(avatarGuid, req.getFetterLevel(), rewardId)); + session.send(new PacketAvatarFetterDataNotify(avatar)); } } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java index 86cea0e02..6be12e603 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java @@ -26,6 +26,13 @@ public class PacketAvatarFetterDataNotify extends GenshinPacket { ); } } + + int rewardId = avatar.getNameCardRewardId(); + int cardId = avatar.getNameCardId(); + + if (avatar.getPlayer().getNameCardList().contains(cardId)) { + avatarFetter.addRewardedFetterLevelList(rewardId); + } AvatarFetterInfo avatarFetterInfo = avatarFetter.build(); From 523d0260d035d61fdd591d92c859d31a5fd7f45c Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sun, 24 Apr 2022 05:20:59 +0800 Subject: [PATCH 9/9] tp with relative coordinates --- .../command/commands/TelePortCommand.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java b/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java index 1a9e4f87a..84848afa5 100644 --- a/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java @@ -24,9 +24,36 @@ public class TelePortCommand implements CommandHandler { } try { - float x = Float.parseFloat(args.get(0)); - float y = Float.parseFloat(args.get(1)); - float z = Float.parseFloat(args.get(2)); + float x = 0f; + float y = 0f; + float z = 0f; + if (args.get(0).contains("~")) { + if (args.get(0).equals("~")) { + x = sender.getPos().getX(); + } else { + x = Float.parseFloat(args.get(0).replace("~", "")) + sender.getPos().getX(); + } + } else { + x = Float.parseFloat(args.get(0)); + } + if (args.get(1).contains("~")) { + if (args.get(1).equals("~")) { + y = sender.getPos().getY(); + } else { + y = Float.parseFloat(args.get(1).replace("~", "")) + sender.getPos().getY(); + } + } else { + y = Float.parseFloat(args.get(1)); + } + if (args.get(2).contains("~")) { + if (args.get(2).equals("~")) { + z = sender.getPos().getZ(); + } else { + z = Float.parseFloat(args.get(2).replace("~", "")) + sender.getPos().getZ(); + } + } else { + z = Float.parseFloat(args.get(2)); + } int sceneId = sender.getSceneId(); if (args.size() == 4){ sceneId = Integer.parseInt(args.get(3));