SetStats.java 6.34 KB
Newer Older
Jaida Wu's avatar
Jaida Wu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 <hp|def|atk|em|er|crate|cdmg> <value>",
        aliases = {"stats"})
public class SetStats implements CommandHandler {

    @Override
KingRainbow44's avatar
KingRainbow44 committed
17
    public void execute(GenshinPlayer sender, List<String> args) {
Jaida Wu's avatar
Jaida Wu committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
        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 <hp|def|atk|em|er|crate|cdmg> <value>");
                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;
        }
    }
}