From 4d8a16ece892657dd2c84688a5ad3369c4e723f7 Mon Sep 17 00:00:00 2001 From: Jaida Wu Date: Wed, 20 Apr 2022 21:15:37 +0800 Subject: [PATCH] Add setstats command Signed-off-by: Jaida Wu --- .../command/commands/SetHealth.java | 42 ------ .../command/commands/SetStats.java | 120 ++++++++++++++++++ 2 files changed, 120 insertions(+), 42 deletions(-) delete mode 100644 src/main/java/emu/grasscutter/command/commands/SetHealth.java create mode 100644 src/main/java/emu/grasscutter/command/commands/SetStats.java diff --git a/src/main/java/emu/grasscutter/command/commands/SetHealth.java b/src/main/java/emu/grasscutter/command/commands/SetHealth.java deleted file mode 100644 index 2daf792ef..000000000 --- a/src/main/java/emu/grasscutter/command/commands/SetHealth.java +++ /dev/null @@ -1,42 +0,0 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.game.props.FightProperty; -import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; - -import java.util.List; - -@Command(label = "sethealth", usage = "sethealth ", - description = "Sets your health to the specified value", aliases = {"sethp"}, permission = "player.sethealth") -public class SetHealth implements CommandHandler { - - @Override - public void onCommand(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; // TODO: set player's health from console or other players - } - - if (args.size() < 1) { - CommandHandler.sendMessage(null, "Usage: sethealth "); - return; - } - - try { - int health = Integer.parseInt(args.get(0)); - EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); - if (entity == null) { - return; - } - - entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health); - entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP)); - sender.dropMessage("Health set to " + health + "."); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(null, "Invalid health value."); - } - } -} diff --git a/src/main/java/emu/grasscutter/command/commands/SetStats.java b/src/main/java/emu/grasscutter/command/commands/SetStats.java new file mode 100644 index 000000000..64f594ded --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/SetStats.java @@ -0,0 +1,120 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; + +import java.util.List; + +@Command(label = "setstats", usage = "setstats ", + aliases = {"stats"}) +public class SetStats implements CommandHandler { + + @Override + public void onCommand(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + String stat = args.get(0); + switch (stat) { + default: + CommandHandler.sendMessage(sender, "Usage: setstats|stats "); + return; + case "hp": + try { + int health = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP)); + CommandHandler.sendMessage(sender, "HP set to " + health + "."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid HP value."); + return; + } + break; + case "def": + try { + int def = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, def); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_DEFENSE)); + CommandHandler.sendMessage(sender, "DEF set to " + def + "."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid DEF value."); + return; + } + break; + case "atk": + try { + int atk = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, atk); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_ATTACK)); + CommandHandler.sendMessage(sender, "ATK set to " + atk + "."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid ATK value."); + return; + } + break; + case "em": + try { + int em = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + entity.setFightProperty(FightProperty.FIGHT_PROP_ELEMENT_MASTERY, em); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ELEMENT_MASTERY)); + CommandHandler.sendMessage(sender, "Elemental Mastery set to " + em + "."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid EM value."); + return; + } + break; + case "er": + try { + float er = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + float erecharge = er / 10000; + entity.setFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, erecharge); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY)); + float iger = erecharge * 100; + CommandHandler.sendMessage(sender, "Energy recharge set to " + iger + "%."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid ER value."); + return; + } + break; + case "crate": + try { + float cr = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + float crate = cr / 10000; + entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL, crate); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL)); + float igcrate = crate * 100; + CommandHandler.sendMessage(sender, "Crit Rate set to " + igcrate + "%."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid Crit Rate value."); + return; + } + break; + case "cdmg": + try { + float cdmg = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + float cdamage = cdmg / 10000; + entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL_HURT, cdamage); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL_HURT)); + float igcdmg = cdamage * 100; + CommandHandler.sendMessage(sender, "Crit DMG set to " + igcdmg + "%"); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid Crit DMG value."); + return; + } + break; + } + } +}