From 3baef42aac418ec5d79891836ece4e893389876c 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] 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();