ResetConstCommand.java 1.77 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
17
18
@Command(label = "resetconst", usage = "resetconst [all]",
        description = "Resets the constellation level on your current active character, will need to relog after using the command to see any changes.",
        aliases = {"resetconstellation"}, permission = "player.resetconstellation")
public final class ResetConstCommand implements CommandHandler {

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

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

34
            Avatar avatar = entity.getAvatar();
KingRainbow44's avatar
KingRainbow44 committed
35
36
            this.resetConstellation(avatar);

37
            CommandHandler.sendMessage(sender, translate("commands.resetConst.success", avatar.getAvatarData().getName()));
KingRainbow44's avatar
KingRainbow44 committed
38
39
40
        }
    }

41
    private void resetConstellation(Avatar avatar) {
KingRainbow44's avatar
KingRainbow44 committed
42
43
44
45
46
        avatar.getTalentIdList().clear();
        avatar.setCoreProudSkillLevel(0);
        avatar.recalcStats();
        avatar.save();
    }
Jaida Wu's avatar
Jaida Wu committed
47
}