From 370483fae299aa6139fcd0c7a6a1025f5ae68d82 Mon Sep 17 00:00:00 2001 From: alt3ri <95161279+alt3ri@users.noreply.github.com> Date: Fri, 22 Apr 2022 17:28:52 +0700 Subject: [PATCH 1/2] Added /talent command Set current character talent level by using /talent command. > /talent getid - Gets current character talent ID > /talent set - Sets current character's talent level --- .../command/commands/TalentCommand.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/main/java/emu/grasscutter/command/commands/TalentCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java new file mode 100644 index 000000000..178942b42 --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java @@ -0,0 +1,109 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.avatar.GenshinAvatar; +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.server.packet.send.PacketAvatarSkillChangeNotify; +import emu.grasscutter.server.packet.send.PacketAvatarSkillUpgradeRsp; +import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; + +import java.util.List; + +@Command(label = "talent", usage = "talent ", + description = "Set talent level for your current active character", permission = "player.settalent") +public class TalentCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 0 || args.size() < 1){ + CommandHandler.sendMessage(sender, "To set talent level: /talent set "); + CommandHandler.sendMessage(sender, "To get talent ID: /talent getid"); + return; + } + + String cmdSwitch = args.get(0); + switch (cmdSwitch) { + default: + CommandHandler.sendMessage(sender, "To set talent level: /talent set "); + CommandHandler.sendMessage(sender, "To get talent ID: /talent getid"); + return; + case "set": + try { + int skillId = Integer.parseInt(args.get(1)); + int nextLevel = Integer.parseInt(args.get(2)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + GenshinAvatar avatar = entity.getAvatar(); + int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0); + int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1); + int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill(); + int currentLevelNorAtk = avatar.getSkillLevelMap().get(skillIdNorAtk); + int currentLevelE = avatar.getSkillLevelMap().get(skillIdE); + int currentLevelQ = avatar.getSkillLevelMap().get(skillIdQ); + if (args.size() < 2){ + CommandHandler.sendMessage(sender, "To set talent level: /talent set "); + CommandHandler.sendMessage(sender, "To get talent ID: /talent getid"); + return; + } + if (nextLevel > 16){ + CommandHandler.sendMessage(sender, "Invalid talent level. Level should be lower than 16"); + return; + } + if (skillId == skillIdNorAtk){ + // Upgrade skill + avatar.getSkillLevelMap().put(skillIdNorAtk, nextLevel); + avatar.save(); + + // Packet + sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel)); + sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel)); + CommandHandler.sendMessage(sender, "Set talent Normal ATK to " + nextLevel + "."); + } + if (skillId == skillIdE){ + // Upgrade skill + avatar.getSkillLevelMap().put(skillIdE, nextLevel); + avatar.save(); + + // Packet + sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdE, currentLevelE, nextLevel)); + sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdE, currentLevelE, nextLevel)); + CommandHandler.sendMessage(sender, "Set talent E to " + nextLevel + "."); + } + if (skillId == skillIdQ){ + // Upgrade skill + avatar.getSkillLevelMap().put(skillIdQ, nextLevel); + avatar.save(); + + // Packet + sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdQ, currentLevelQ, nextLevel)); + sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdQ, currentLevelQ, nextLevel)); + CommandHandler.sendMessage(sender, "Set talent Q to " + nextLevel + "."); + } + + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid skill ID."); + return; + } + + break; + case "getid": + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + GenshinAvatar avatar = entity.getAvatar(); + int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0); + int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1); + int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill(); + + CommandHandler.sendMessage(sender, "Normal Attack ID " + skillIdNorAtk + "."); + CommandHandler.sendMessage(sender, "E skill ID " + skillIdE + "."); + CommandHandler.sendMessage(sender, "Q skill ID " + skillIdQ + "."); + break; + } + } +} From 63898a18df898ea1e3787e1f8ca8453f6a65b3e8 Mon Sep 17 00:00:00 2001 From: alt3ri <95161279+alt3ri@users.noreply.github.com> Date: Fri, 22 Apr 2022 17:38:58 +0700 Subject: [PATCH 2/2] Deleted 2 lines --- .../java/emu/grasscutter/command/commands/TalentCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java index 178942b42..2ced6f1c3 100644 --- a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java @@ -5,10 +5,8 @@ import emu.grasscutter.command.CommandHandler; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.server.packet.send.PacketAvatarSkillChangeNotify; import emu.grasscutter.server.packet.send.PacketAvatarSkillUpgradeRsp; -import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import java.util.List;