TalentCommand.java 8.3 KB
Newer Older
alt3ri's avatar
alt3ri committed
1
2
3
4
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
xtaodada's avatar
xtaodada committed
5
import emu.grasscutter.data.def.AvatarSkillDepotData;
alt3ri's avatar
alt3ri committed
6
7
8
9
10
11
12
13
14
15
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.server.packet.send.PacketAvatarSkillChangeNotify;
import emu.grasscutter.server.packet.send.PacketAvatarSkillUpgradeRsp;

import java.util.List;

@Command(label = "talent", usage = "talent <talentID> <value>",
        description = "Set talent level for your current active character", permission = "player.settalent")
KingRainbow44's avatar
KingRainbow44 committed
16
public final class TalentCommand implements CommandHandler {
alt3ri's avatar
alt3ri committed
17
18
19
20
21
22
23
24

    @Override
    public void execute(GenshinPlayer sender, List<String> args) {
        if (sender == null) {
            CommandHandler.sendMessage(null, "Run this command in-game.");
            return;
        }

xtaodada's avatar
xtaodada committed
25
        if (args.size() < 1){
alt3ri's avatar
alt3ri committed
26
            CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
xtaodada's avatar
xtaodada committed
27
            CommandHandler.sendMessage(sender, "Another way to set talent level: /talent <n or e or q> <value>");
alt3ri's avatar
alt3ri committed
28
29
30
31
32
33
34
35
            CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
            return;
        }

        String cmdSwitch = args.get(0);
        switch (cmdSwitch) {
            default:
                CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
xtaodada's avatar
xtaodada committed
36
                CommandHandler.sendMessage(sender, "Another way to set talent level: /talent <n or e or q> <value>");
alt3ri's avatar
alt3ri committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
                CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
            return;
            case "set":
                    try {
                        int skillId = Integer.parseInt(args.get(1));
                        int nextLevel = Integer.parseInt(args.get(2));
                        EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
                        GenshinAvatar avatar = entity.getAvatar(); 
                        int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0);
                        int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1);
                        int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill();
                        int currentLevelNorAtk = avatar.getSkillLevelMap().get(skillIdNorAtk);
                        int currentLevelE = avatar.getSkillLevelMap().get(skillIdE);
                        int currentLevelQ = avatar.getSkillLevelMap().get(skillIdQ);
                        if (args.size() < 2){
                            CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
                            CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
                            return;
                        }
                        if (nextLevel > 16){ 
                            CommandHandler.sendMessage(sender, "Invalid talent level. Level should be lower than 16");
                            return;
                        }
                            if (skillId == skillIdNorAtk){ 
                            // Upgrade skill
                            avatar.getSkillLevelMap().put(skillIdNorAtk, nextLevel);
                            avatar.save();
                
                            // Packet
                            sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel));
                            sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel));
                            CommandHandler.sendMessage(sender, "Set talent Normal ATK to " + nextLevel + ".");
                        }    
                        if (skillId == skillIdE){ 
                            // Upgrade skill
                            avatar.getSkillLevelMap().put(skillIdE, nextLevel);
                            avatar.save();
                
                            // Packet
                            sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdE, currentLevelE, nextLevel));
                            sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdE, currentLevelE, nextLevel));
                            CommandHandler.sendMessage(sender, "Set talent E to " + nextLevel + ".");
                        }
                        if (skillId == skillIdQ){ 
                            // Upgrade skill
                            avatar.getSkillLevelMap().put(skillIdQ, nextLevel);
                            avatar.save();
                
                            // Packet
                            sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdQ, currentLevelQ, nextLevel));
                            sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdQ, currentLevelQ, nextLevel));
                            CommandHandler.sendMessage(sender, "Set talent Q to " + nextLevel + ".");
                        }       
                                
                    } catch (NumberFormatException ignored) {
                        CommandHandler.sendMessage(sender, "Invalid skill ID.");
                        return;
                    }
                
xtaodada's avatar
xtaodada committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
                break;
            case "n": case "e": case "q":
                try {
                    EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
                    GenshinAvatar avatar = entity.getAvatar();
                    AvatarSkillDepotData SkillDepot = avatar.getData().getSkillDepot();
                    int skillId;
                    switch (cmdSwitch) {
                        default:
                            skillId = SkillDepot.getSkills().get(0);
                            break;
                        case "e":
                            skillId = SkillDepot.getSkills().get(1);
                            break;
                        case "q":
                            skillId = SkillDepot.getEnergySkill();
                            break;
                    }
                    int nextLevel = Integer.parseInt(args.get(1));
                    int currentLevel = avatar.getSkillLevelMap().get(skillId);
                    if (args.size() < 1){
                        CommandHandler.sendMessage(sender, "To set talent level: /talent <n or e or q> <value>");
                        return;
                    }
                    if (nextLevel > 16){
                        CommandHandler.sendMessage(sender, "Invalid talent level. Level should be lower than 16");
                        return;
                    }
                    // Upgrade skill
                    avatar.getSkillLevelMap().put(skillId, nextLevel);
                    avatar.save();
                    // Packet
                    sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillId, currentLevel, nextLevel));
                    sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillId, currentLevel, nextLevel));
                    CommandHandler.sendMessage(sender, "Set this talent to " + nextLevel + ".");
                } catch (NumberFormatException ignored) {
                    CommandHandler.sendMessage(sender, "Invalid talent level.");
                    return;
                }
alt3ri's avatar
alt3ri committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
                break;
            case "getid":           
                    EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
                    GenshinAvatar avatar = entity.getAvatar(); 
                    int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0);
                    int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1);
                    int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill();
                    
                    CommandHandler.sendMessage(sender, "Normal Attack ID " + skillIdNorAtk + ".");
                    CommandHandler.sendMessage(sender, "E skill ID " + skillIdE + ".");
                    CommandHandler.sendMessage(sender, "Q skill ID " + skillIdQ + ".");
                break;
        }
    }
}