From a93d7c579f4641161038ef909e6d2d1c4d244614 Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Mon, 2 May 2022 17:25:26 -0700 Subject: [PATCH] Fix extra skill charges being removed if you teleport Close #404 --- .../grasscutter/game/player/TeamManager.java | 8 ++++++ .../emu/grasscutter/game/world/Scene.java | 8 ++++++ .../send/PacketAvatarSkillInfoNotify.java | 25 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillInfoNotify.java diff --git a/src/main/java/emu/grasscutter/game/player/TeamManager.java b/src/main/java/emu/grasscutter/game/player/TeamManager.java index b67e9898e..666c44dee 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/player/TeamManager.java @@ -27,6 +27,7 @@ import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState; import emu.grasscutter.server.packet.send.PacketAvatarDieAnimationEndRsp; import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify; +import emu.grasscutter.server.packet.send.PacketAvatarSkillInfoNotify; import emu.grasscutter.server.packet.send.PacketAvatarTeamUpdateNotify; import emu.grasscutter.server.packet.send.PacketChangeAvatarRsp; import emu.grasscutter.server.packet.send.PacketChangeMpTeamAvatarRsp; @@ -263,6 +264,13 @@ public class TeamManager { // Packets getPlayer().getWorld().broadcastPacket(new PacketSceneTeamUpdateNotify(getPlayer())); + // Skill charges packet - Yes, this is official server behavior as of 2.6.0 + for (EntityAvatar entity : getActiveTeam()) { + if (entity.getAvatar().getSkillExtraChargeMap().size() > 0) { + getPlayer().sendPacket(new PacketAvatarSkillInfoNotify(entity.getAvatar())); + } + } + // Run callback if (responsePacket != null) { getPlayer().sendPacket(responsePacket); diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 0ca82c4cf..2e3afc087 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -25,6 +25,7 @@ import emu.grasscutter.scripts.data.SceneBlock; import emu.grasscutter.scripts.data.SceneGadget; import emu.grasscutter.scripts.data.SceneGroup; import emu.grasscutter.scripts.data.ScriptArgs; +import emu.grasscutter.server.packet.send.PacketAvatarSkillInfoNotify; import emu.grasscutter.server.packet.send.PacketDungeonChallengeFinishNotify; import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify; @@ -271,6 +272,13 @@ public class Scene { } this.addEntity(player.getTeamManager().getCurrentAvatarEntity()); + + // Notify the client of any extra skill charges + for (EntityAvatar entity : player.getTeamManager().getActiveTeam()) { + if (entity.getAvatar().getSkillExtraChargeMap().size() > 0) { + player.sendPacket(new PacketAvatarSkillInfoNotify(entity.getAvatar())); + } + } } private void addEntityDirectly(GameEntity entity) { diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillInfoNotify.java new file mode 100644 index 000000000..b099e5646 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillInfoNotify.java @@ -0,0 +1,25 @@ +package emu.grasscutter.server.packet.send; + +import java.util.Map.Entry; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarSkillInfoNotifyOuterClass.AvatarSkillInfoNotify; +import emu.grasscutter.net.proto.AvatarSkillInfoOuterClass.AvatarSkillInfo; + +public class PacketAvatarSkillInfoNotify extends BasePacket { + + public PacketAvatarSkillInfoNotify(Avatar avatar) { + super(PacketOpcodes.AvatarSkillInfoNotify); + + AvatarSkillInfoNotify.Builder proto = AvatarSkillInfoNotify.newBuilder() + .setGuid(avatar.getGuid()); + + for (Entry entry : avatar.getSkillExtraChargeMap().entrySet()) { + proto.putSkillMap(entry.getKey(), AvatarSkillInfo.newBuilder().setMaxChargeCount(entry.getValue()).build()); + } + + this.setData(proto); + } +}