command fix

This commit is contained in:
Yazawazi 2022-04-23 01:36:48 +08:00 committed by GitHub
parent 34c0c6b01b
commit f9b5c8a9ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 3 deletions

View File

@ -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 <level>",
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.");

View File

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