ResetConstCommand.java 1.72 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
@Command(label = "resetconst", usage = "resetconst [all]",
14
        aliases = {"resetconstellation"}, permission = "player.resetconstellation", permissionTargeted = "player.resetconstellation.others", description = "commands.resetConst.description")
KingRainbow44's avatar
KingRainbow44 committed
15
16
17
public final class ResetConstCommand implements CommandHandler {

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

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

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

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

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