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

3
import emu.grasscutter.GameConstants;
KingRainbow44's avatar
KingRainbow44 committed
4
5
6
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
7
import emu.grasscutter.data.GameData;
Melledy's avatar
Melledy committed
8
import emu.grasscutter.data.excels.AvatarData;
9
import emu.grasscutter.game.avatar.Avatar;
Melledy's avatar
Melledy committed
10
import emu.grasscutter.game.player.Player;
KingRainbow44's avatar
KingRainbow44 committed
11
12
13

import java.util.List;

14
15
import static emu.grasscutter.utils.Language.translate;

tester233's avatar
tester233 committed
16
@Command(label = "givechar", usage = "givechar <avatarId> [level]", aliases = {"givec"}, permission = "player.givechar", permissionTargeted = "player.givechar.others", description = "commands.giveChar.description")
KingRainbow44's avatar
KingRainbow44 committed
17
18
19
public final class GiveCharCommand implements CommandHandler {

    @Override
AnimeGitB's avatar
AnimeGitB committed
20
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
21
22
23
        int avatarId;
        int level = 1;

KingRainbow44's avatar
KingRainbow44 committed
24
25
26
        switch (args.size()) {
            case 2:
                try {
AnimeGitB's avatar
AnimeGitB committed
27
                    level = Integer.parseInt(args.get(1));
KingRainbow44's avatar
KingRainbow44 committed
28
29
                } catch (NumberFormatException ignored) {
                    // TODO: Parse from avatar name using GM Handbook.
tester233's avatar
tester233 committed
30
                    CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.avatarLevel"));
KingRainbow44's avatar
KingRainbow44 committed
31
                    return;
AnimeGitB's avatar
AnimeGitB committed
32
33
                }  // Cheeky fall-through to parse first argument too
            case 1:
KingRainbow44's avatar
KingRainbow44 committed
34
                try {
AnimeGitB's avatar
AnimeGitB committed
35
                    avatarId = Integer.parseInt(args.get(0));
KingRainbow44's avatar
KingRainbow44 committed
36
37
                } catch (NumberFormatException ignored) {
                    // TODO: Parse from avatar name using GM Handbook.
tester233's avatar
tester233 committed
38
                    CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.avatarId"));
KingRainbow44's avatar
KingRainbow44 committed
39
40
41
                    return;
                }
                break;
AnimeGitB's avatar
AnimeGitB committed
42
            default:
Secretboy's avatar
Secretboy committed
43
                CommandHandler.sendMessage(sender, translate(sender, "commands.giveChar.usage"));
AnimeGitB's avatar
AnimeGitB committed
44
                return;
KingRainbow44's avatar
KingRainbow44 committed
45
46
        }

47
        AvatarData avatarData = GameData.getAvatarDataMap().get(avatarId);
KingRainbow44's avatar
KingRainbow44 committed
48
        if (avatarData == null) {
tester233's avatar
tester233 committed
49
            CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.avatarId"));
KingRainbow44's avatar
KingRainbow44 committed
50
51
52
            return;
        }

53
54
        // Check level.
        if (level > 90) {
tester233's avatar
tester233 committed
55
            CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.avatarLevel"));
56
57
58
            return;
        }

KingRainbow44's avatar
KingRainbow44 committed
59
        // Calculate ascension level.
AnimeGitB's avatar
AnimeGitB committed
60
        int ascension;
KingRainbow44's avatar
KingRainbow44 committed
61
        if (level <= 40) {
62
            ascension = (int) Math.ceil(level / 20f) - 1;
KingRainbow44's avatar
KingRainbow44 committed
63
64
        } else {
            ascension = (int) Math.ceil(level / 10f) - 3;
65
            ascension = Math.min(ascension, 6);
KingRainbow44's avatar
KingRainbow44 committed
66
67
        }

68
        Avatar avatar = new Avatar(avatarId);
KingRainbow44's avatar
KingRainbow44 committed
69
70
71
        avatar.setLevel(level);
        avatar.setPromoteLevel(ascension);

72
73
74
75
76
77
78
79
        // Handle skill depot for traveller.
        if (avatar.getAvatarId() == GameConstants.MAIN_CHARACTER_MALE) {
            avatar.setSkillDepotData(GameData.getAvatarSkillDepotDataMap().get(504));
        }
        else if(avatar.getAvatarId() == GameConstants.MAIN_CHARACTER_FEMALE) {
            avatar.setSkillDepotData(GameData.getAvatarSkillDepotDataMap().get(704));
        }

KingRainbow44's avatar
KingRainbow44 committed
80
81
82
83
        // This will handle stats and talents
        avatar.recalcStats();

        targetPlayer.addAvatar(avatar);
Secretboy's avatar
Secretboy committed
84
        CommandHandler.sendMessage(sender, translate(sender, "commands.giveChar.given", Integer.toString(avatarId), Integer.toString(level), Integer.toString(targetPlayer.getUid())));
KingRainbow44's avatar
KingRainbow44 committed
85
86
    }
}