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

方块君's avatar
方块君 committed
3
import emu.grasscutter.Grasscutter;
KingRainbow44's avatar
KingRainbow44 committed
4
5
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
6
import emu.grasscutter.game.avatar.Avatar;
KingRainbow44's avatar
KingRainbow44 committed
7
import emu.grasscutter.game.entity.EntityAvatar;
Melledy's avatar
Melledy committed
8
import emu.grasscutter.game.player.Player;
KingRainbow44's avatar
KingRainbow44 committed
9
10
11
12
13
14
15
16
17

import java.util.List;

@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
18
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
19
20
        if (targetPlayer == null) {
            CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
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);
AnimeGitB's avatar
AnimeGitB committed
26
            CommandHandler.sendMessage(sender, Grasscutter.getLanguage().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);

AnimeGitB's avatar
AnimeGitB committed
36
            CommandHandler.sendMessage(sender, Grasscutter.getLanguage().ResetConst_reset_all_done.replace("{name}", 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
}