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); + } +}