ResetConstCommand.java 1.58 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) {
KingRainbow44's avatar
KingRainbow44 committed
19
        if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
AnimeGitB's avatar
AnimeGitB committed
20
            targetPlayer.getAvatars().forEach(this::resetConstellation);
Secretboy's avatar
Secretboy committed
21
            CommandHandler.sendMessage(sender, translate(sender, "commands.resetConst.reset_all"));
KingRainbow44's avatar
KingRainbow44 committed
22
        } else {
AnimeGitB's avatar
AnimeGitB committed
23
            EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
KingRainbow44's avatar
KingRainbow44 committed
24
25
26
27
            if (entity == null) {
                return;
            }

28
            Avatar avatar = entity.getAvatar();
KingRainbow44's avatar
KingRainbow44 committed
29
30
            this.resetConstellation(avatar);

Secretboy's avatar
Secretboy committed
31
            CommandHandler.sendMessage(sender, translate(sender, "commands.resetConst.success", avatar.getAvatarData().getName()));
KingRainbow44's avatar
KingRainbow44 committed
32
33
34
        }
    }

35
    private void resetConstellation(Avatar avatar) {
KingRainbow44's avatar
KingRainbow44 committed
36
37
38
39
40
        avatar.getTalentIdList().clear();
        avatar.setCoreProudSkillLevel(0);
        avatar.recalcStats();
        avatar.save();
    }
Secretboy's avatar
Secretboy committed
41
}