GiveAllCommand.java 6.54 KB
Newer Older
BaiSugar's avatar
BaiSugar committed
1
2
package emu.grasscutter.command.commands;

3
import emu.grasscutter.GameConstants;
BaiSugar's avatar
BaiSugar 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
9
import emu.grasscutter.data.excels.AvatarData;
import emu.grasscutter.data.excels.ItemData;
10
11
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.inventory.GameItem;
BaiSugar's avatar
BaiSugar committed
12
import emu.grasscutter.game.inventory.ItemType;
Melledy's avatar
Melledy committed
13
import emu.grasscutter.game.player.Player;
BaiSugar's avatar
BaiSugar committed
14

BaiSugar's avatar
BaiSugar committed
15
import java.util.*;
BaiSugar's avatar
BaiSugar committed
16

17
18
import static emu.grasscutter.utils.Language.translate;

19
@Command(label = "giveall", usage = "giveall [amount]", aliases = {"givea"}, permission = "player.giveall", permissionTargeted = "player.giveall.others", threading = true, description = "commands.giveAll.description")
KingRainbow44's avatar
KingRainbow44 committed
20
public final class GiveAllCommand implements CommandHandler {
BaiSugar's avatar
BaiSugar committed
21

BaiSugar's avatar
BaiSugar committed
22
    @Override
AnimeGitB's avatar
AnimeGitB committed
23
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
24
        int amount = 99999;
BaiSugar's avatar
BaiSugar committed
25
26

        switch (args.size()) {
AnimeGitB's avatar
AnimeGitB committed
27
            case 0:
BaiSugar's avatar
BaiSugar committed
28
                break;
AnimeGitB's avatar
AnimeGitB committed
29
            case 1: // [amount]
BaiSugar's avatar
BaiSugar committed
30
                try {
AnimeGitB's avatar
AnimeGitB committed
31
                    amount = Integer.parseInt(args.get(0));
BaiSugar's avatar
BaiSugar committed
32
                } catch (NumberFormatException ignored) {
Secretboy's avatar
Secretboy committed
33
                    CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.amount"));
BaiSugar's avatar
BaiSugar committed
34
35
36
                    return;
                }
                break;
BaiSugar's avatar
BaiSugar committed
37
            default: // invalid
Secretboy's avatar
Secretboy committed
38
                CommandHandler.sendMessage(sender, translate(sender, "commands.giveAll.usage"));
BaiSugar's avatar
BaiSugar committed
39
                return;
BaiSugar's avatar
BaiSugar committed
40
41
        }

BaiSugar's avatar
BaiSugar committed
42
        this.giveAllItems(targetPlayer, amount);
Secretboy's avatar
Secretboy committed
43
        CommandHandler.sendMessage(sender, translate(targetPlayer, "commands.giveAll.success", targetPlayer.getNickname()));
BaiSugar's avatar
BaiSugar committed
44
45
    }

46
    public void giveAllItems(Player player, int amount) {
Secretboy's avatar
Secretboy committed
47
        CommandHandler.sendMessage(player, translate(player, "commands.giveAll.started"));
BaiSugar's avatar
BaiSugar committed
48

49
        for (AvatarData avatarData: GameData.getAvatarDataMap().values()) {
BaiSugar's avatar
BaiSugar committed
50
51
52
            //Exclude test avatar
            if (isTestAvatar(avatarData.getId())) continue;

53
            Avatar avatar = new Avatar(avatarData);
BaiSugar's avatar
BaiSugar committed
54
55
            avatar.setLevel(90);
            avatar.setPromoteLevel(6);
56
57
58
59
60
61
62
63

            // Add constellations.
            int talentBase = switch (avatar.getAvatarId()) {
                case 10000005   -> 70;
                case 10000006   -> 40;
                default         -> (avatar.getAvatarId()-10000000)*10;
            };

64
            for(int i = 1;i <= 6;++i){
65
66
67
68
69
70
71
72
73
                avatar.getTalentIdList().add(talentBase + i);
            }

            // 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));
BaiSugar's avatar
BaiSugar committed
74
            }
75

BaiSugar's avatar
BaiSugar committed
76
77
            // This will handle stats and talents
            avatar.recalcStats();
ProxyismGH's avatar
ProxyismGH committed
78
79
            // Don't try to add each avatar to the current team
            player.addAvatar(avatar, false);
BaiSugar's avatar
BaiSugar committed
80
        }
BaiSugar's avatar
BaiSugar committed
81

BaiSugar's avatar
BaiSugar committed
82
        //some test items
83
84
        List<GameItem> itemList = new ArrayList<>();
        for (ItemData itemdata: GameData.getItemDataMap().values()) {
BaiSugar's avatar
BaiSugar committed
85
86
87
            //Exclude test item
            if (isTestItem(itemdata.getId())) continue;

BaiSugar's avatar
BaiSugar committed
88
            if (itemdata.isEquip()) {
lhhxxxxx's avatar
lhhxxxxx committed
89
90
91
                if (itemdata.getItemType() == ItemType.ITEM_WEAPON) {
                    for (int i = 0; i < 5; ++i) {
                        GameItem item = new GameItem(itemdata);
92
93
94
                        item.setLevel(90);
                        item.setPromoteLevel(6);
                        item.setRefinement(4);
lhhxxxxx's avatar
lhhxxxxx committed
95
                        itemList.add(item);
BaiSugar's avatar
BaiSugar committed
96
                    }
BaiSugar's avatar
BaiSugar committed
97
                }
BaiSugar's avatar
BaiSugar committed
98
99
            }
            else {
100
101
102
                GameItem item = new GameItem(itemdata);
                item.setCount(amount);
                itemList.add(item);
BaiSugar's avatar
BaiSugar committed
103
104
            }
        }
BaiSugar's avatar
BaiSugar committed
105
        int packetNum = 10;
106
        int itemLength = itemList.size();
BaiSugar's avatar
BaiSugar committed
107
108
109
110
111
        int number = itemLength / packetNum;
        int remainder = itemLength % packetNum;
        int offset = 0;
        for (int i = 0; i < packetNum; ++i) {
            if (remainder > 0) {
112
                player.getInventory().addItems(itemList.subList(i * number + offset, (i + 1) * number + offset + 1));
BaiSugar's avatar
BaiSugar committed
113
114
115
116
                --remainder;
                ++offset;
            }
            else {
117
                player.getInventory().addItems(itemList.subList(i * number + offset, (i + 1) * number + offset));
BaiSugar's avatar
BaiSugar committed
118
119
120
            }
        }
    }
BaiSugar's avatar
BaiSugar committed
121

BaiSugar's avatar
BaiSugar committed
122
123
124
125
126
127
128
129
    public boolean isTestAvatar(int avatarId) {
        return avatarId < 10000002 || avatarId >= 11000000;
    }

    public boolean isTestItem(int itemId) {
        for (Range range: testItemRanges) {
            if (range.check(itemId)) {
                return true;
BaiSugar's avatar
BaiSugar committed
130
            }
BaiSugar's avatar
BaiSugar committed
131
132
        }

KingRainbow44's avatar
KingRainbow44 committed
133
        return testItemsList.contains(itemId);
BaiSugar's avatar
BaiSugar committed
134
135
136
    }

    static class Range {
KingRainbow44's avatar
KingRainbow44 committed
137
        private final int min, max;
BaiSugar's avatar
BaiSugar committed
138
139
140
141
142
143
144

        public Range(int min, int max) {
            if(min > max){
                min ^= max;
                max ^= min;
                min ^= max;
            }
KingRainbow44's avatar
KingRainbow44 committed
145
            
BaiSugar's avatar
BaiSugar committed
146
147
148
149
150
151
            this.min = min;
            this.max = max;
        }

        public boolean check(int value) {
            return value >= this.min && value <= this.max;
BaiSugar's avatar
BaiSugar committed
152
153
154
        }
    }

BaiSugar's avatar
BaiSugar committed
155
156
157
    private static final Range[] testItemRanges = new Range[] {
            new Range(106, 139),
            new Range(1000, 1099),
BaiSugar's avatar
BaiSugar committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
            new Range(2001, 3022),
            new Range(23300, 23340),
            new Range(23383, 23385),
            new Range(78310, 78554),
            new Range(99310, 99554),
            new Range(100001, 100187),
            new Range(100210, 100214),
            new Range(100303, 100398),
            new Range(100414, 100425),
            new Range(100454, 103008),
            new Range(109000, 109492),
            new Range(115001, 118004),
            new Range(141001, 141072),
            new Range(220050, 221016),
BaiSugar's avatar
BaiSugar committed
172
173
    };
    private static final Integer[] testItemsIds = new Integer[] {
BaiSugar's avatar
BaiSugar committed
174
175
            210, 211, 314, 315, 317, 1005, 1007, 1105, 1107, 1201, 1202,10366,
            101212, 11411, 11506, 11507, 11508, 12505, 12506, 12508, 12509, 13503,
176
            13506, 14411, 14503, 14505, 14508, 15504, 15505, 15506,
BaiSugar's avatar
BaiSugar committed
177
178
            20001, 10002, 10003, 10004, 10005, 10006, 10008,100231,100232,100431,
            101689,105001,105004, 106000,106001,108000,110000
BaiSugar's avatar
BaiSugar committed
179
180
181
182
    };

    private static final Collection<Integer> testItemsList = Arrays.asList(testItemsIds);

BaiSugar's avatar
BaiSugar committed
183
}
BaiSugar's avatar
BaiSugar committed
184