From b2840b17401950bd5c08ab48dfb9da71a35622dd Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sun, 24 Apr 2022 11:25:13 +0800 Subject: [PATCH 1/2] Player level reward --- .../recv/HandlerTakePlayerLevelRewardReq.java | 43 +++++++++++++++++++ .../send/PacketTakePlayerLevelRewardRsp.java | 26 +++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java new file mode 100644 index 000000000..d3f50acee --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java @@ -0,0 +1,43 @@ +package emu.grasscutter.server.packet.recv; + +import java.util.LinkedList; +import java.util.List; + +import emu.grasscutter.data.GenshinData; +import emu.grasscutter.data.common.RewardItemData; +import emu.grasscutter.game.inventory.GenshinItem; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakePlayerLevelRewardReqOuterClass.TakePlayerLevelRewardReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; +import emu.grasscutter.server.packet.send.PacketTakePlayerLevelRewardRsp; + +@Opcodes(PacketOpcodes.TakePlayerLevelRewardReq) +public class HandlerTakePlayerLevelRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + TakePlayerLevelRewardReq req = TakePlayerLevelRewardReq.parseFrom(payload); + + int level = req.getLevel(); + int rewardId = GenshinData.getPlayerLevelDataMap().get(level).getRewardId(); + + if (rewardId != 0) { + List rewardItems = GenshinData.getRewardDataMap().get(rewardId).getRewardItemList(); + List items = new LinkedList<>(); + for (RewardItemData rewardItem : rewardItems) { + if (rewardItem != null) { + if (rewardItem.getItemId() != 0) { + items.add(new GenshinItem(rewardItem.getItemId(), rewardItem.getItemCount())); + } + } + } + session.getPlayer().getInventory().addItems(items); + session.getPlayer().sendPacket(new PacketItemAddHintNotify(items, ActionReason.PlayerUpgradeReward)); + } + + session.send(new PacketTakePlayerLevelRewardRsp(level, rewardId)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java new file mode 100644 index 000000000..5a50d0806 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java @@ -0,0 +1,26 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakePlayerLevelRewardRspOuterClass.TakePlayerLevelRewardRsp; + +public class PacketTakePlayerLevelRewardRsp extends GenshinPacket { + + public PacketTakePlayerLevelRewardRsp(int level, int rewardId) { + super(PacketOpcodes.TakePlayerLevelRewardRsp); + + int retcode = 0; + + if (rewardId == 0) { + retcode = 1; + } + + TakePlayerLevelRewardRsp proto = TakePlayerLevelRewardRsp.newBuilder() + .setLevel(level) + .setRewardId(rewardId) + .setRetcode(retcode) + .build(); + + this.setData(proto); + } +} From 56a1ab64abf8b3ca3693090d11ef46c7cca6ea35 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:22:26 +0800 Subject: [PATCH 2/2] Player Level Reward Update Notify Support! --- .../emu/grasscutter/game/GenshinPlayer.java | 12 ++++++++++ .../recv/HandlerTakePlayerLevelRewardReq.java | 5 +++++ .../PacketPlayerLevelRewardUpdateNotify.java | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java diff --git a/src/main/java/emu/grasscutter/game/GenshinPlayer.java b/src/main/java/emu/grasscutter/game/GenshinPlayer.java index cdef5852e..271a6f014 100644 --- a/src/main/java/emu/grasscutter/game/GenshinPlayer.java +++ b/src/main/java/emu/grasscutter/game/GenshinPlayer.java @@ -52,6 +52,7 @@ import emu.grasscutter.server.packet.send.PacketPlayerPropNotify; import emu.grasscutter.server.packet.send.PacketPlayerStoreNotify; import emu.grasscutter.server.packet.send.PacketPrivateChatNotify; import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify; +import emu.grasscutter.server.packet.send.PacketPlayerLevelRewardUpdateNotify; import emu.grasscutter.server.packet.send.PacketSetNameCardRsp; import emu.grasscutter.server.packet.send.PacketStoreWeightLimitNotify; import emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify; @@ -96,6 +97,7 @@ public class GenshinPlayer { private MpSettingType mpSetting = MpSettingType.MpSettingEnterAfterApply; private boolean showAvatar; private ArrayList shownAvatars; + private Set rewardedLevels; private int sceneId; private int regionId; @@ -143,6 +145,7 @@ public class GenshinPlayer { this.clientAbilityInitFinishHandler = new InvokeHandler(PacketClientAbilityInitFinishNotify.class); this.birthday = new PlayerBirthday(); + this.rewardedLevels = new HashSet<>(); } // On player creation @@ -656,6 +659,14 @@ public class GenshinPlayer { this.updateProfile(); } + public Set getRewardedLevels() { + return rewardedLevels; + } + + public void setRewardedLevels(Set rewardedLevels) { + this.rewardedLevels = rewardedLevels; + } + public SocialDetail.Builder getSocialDetail() { SocialDetail.Builder social = SocialDetail.newBuilder() .setUid(this.getUid()) @@ -773,6 +784,7 @@ public class GenshinPlayer { session.send(new PacketAvatarDataNotify(this)); session.send(new PacketPlayerEnterSceneNotify(this)); // Enter game world + session.send(new PacketPlayerLevelRewardUpdateNotify(rewardedLevels)); session.send(new PacketOpenStateUpdateNotify()); // First notify packets sent diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java index d3f50acee..a81da7758 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java @@ -2,7 +2,9 @@ package emu.grasscutter.server.packet.recv; import java.util.LinkedList; import java.util.List; +import java.util.Set; +import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.common.RewardItemData; import emu.grasscutter.game.inventory.GenshinItem; @@ -36,6 +38,9 @@ public class HandlerTakePlayerLevelRewardReq extends PacketHandler { } session.getPlayer().getInventory().addItems(items); session.getPlayer().sendPacket(new PacketItemAddHintNotify(items, ActionReason.PlayerUpgradeReward)); + Set rewardedLevels = session.getPlayer().getRewardedLevels(); + rewardedLevels.add(level); + session.getPlayer().setRewardedLevels(rewardedLevels); } session.send(new PacketTakePlayerLevelRewardRsp(level, rewardId)); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java new file mode 100644 index 000000000..6a20e288b --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java @@ -0,0 +1,22 @@ +package emu.grasscutter.server.packet.send; + +import java.util.Set; + +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerLevelRewardUpdateNotifyOuterClass.PlayerLevelRewardUpdateNotify; + +public class PacketPlayerLevelRewardUpdateNotify extends GenshinPacket { + + public PacketPlayerLevelRewardUpdateNotify(Set rewardedLevels) { + super(PacketOpcodes.PlayerLevelRewardUpdateNotify); + + PlayerLevelRewardUpdateNotify.Builder proto = PlayerLevelRewardUpdateNotify.newBuilder(); + + for (Integer level : rewardedLevels) { + proto.addLevelList(level); + } + + this.setData(proto.build()); + } +}