ResetConstCommand.java 1.73 KB
Newer Older
KingRainbow44's avatar
KingRainbow44 committed
1
2
3
4
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
5
import emu.grasscutter.game.avatar.Avatar;
KingRainbow44's avatar
KingRainbow44 committed
6
import emu.grasscutter.game.entity.EntityAvatar;
Melledy's avatar
Melledy committed
7
import emu.grasscutter.game.player.Player;
KingRainbow44's avatar
KingRainbow44 committed
8
9
10

import java.util.List;

11
12
import static emu.grasscutter.utils.Language.translate;

KingRainbow44's avatar
KingRainbow44 committed
13
14
15
16
@Command(label = "resetconst", usage = "resetconst [all]",
        aliases = {"resetconstellation"}, permission = "player.resetconstellation")
public final class ResetConstCommand implements CommandHandler {

17
18
19
20
21
    @Override
    public String description() {
        return translate("commands.resetConst.description");
    }

KingRainbow44's avatar
KingRainbow44 committed
22
    @Override
AnimeGitB's avatar
AnimeGitB committed
23
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
24
        if (targetPlayer == null) {
25
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
KingRainbow44's avatar
KingRainbow44 committed
26
27
28
29
            return;
        }

        if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
AnimeGitB's avatar
AnimeGitB committed
30
            targetPlayer.getAvatars().forEach(this::resetConstellation);
31
            CommandHandler.sendMessage(sender, translate("commands.resetConst.reset_all"));
KingRainbow44's avatar
KingRainbow44 committed
32
        } else {
AnimeGitB's avatar
AnimeGitB committed
33
            EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
KingRainbow44's avatar
KingRainbow44 committed
34
35
36
37
            if (entity == null) {
                return;
            }

38
            Avatar avatar = entity.getAvatar();
KingRainbow44's avatar
KingRainbow44 committed
39
40
            this.resetConstellation(avatar);

41
            CommandHandler.sendMessage(sender, translate("commands.resetConst.success", avatar.getAvatarData().getName()));
KingRainbow44's avatar
KingRainbow44 committed
42
43
44
        }
    }

45
    private void resetConstellation(Avatar avatar) {
KingRainbow44's avatar
KingRainbow44 committed
46
47
48
49
50
        avatar.getTalentIdList().clear();
        avatar.setCoreProudSkillLevel(0);
        avatar.recalcStats();
        avatar.save();
    }
Jaida Wu's avatar
Jaida Wu committed
51
}