PlayerCommands.java 22.7 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
package emu.grasscutter.commands;

KingRainbow44's avatar
KingRainbow44 committed
3
import emu.grasscutter.Grasscutter;
Melledy's avatar
Melledy committed
4
5
import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.def.ItemData;
6
import emu.grasscutter.data.def.AvatarData;
7
import emu.grasscutter.data.def.AvatarSkillDepotData;
Melledy's avatar
Melledy committed
8
9
import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.game.GenshinPlayer;
Melledy's avatar
Melledy committed
10
import emu.grasscutter.game.GenshinScene;
KingRainbow44's avatar
KingRainbow44 committed
11
import emu.grasscutter.game.World;
Melledy's avatar
Melledy committed
12
13
14
15
16
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.inventory.GenshinItem;
KingRainbow44's avatar
KingRainbow44 committed
17
import emu.grasscutter.game.inventory.Inventory;
Melledy's avatar
Melledy committed
18
19
20
import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.FightProperty;
SpikeHD's avatar
SpikeHD committed
21
import emu.grasscutter.game.props.PlayerProperty;
Melledy's avatar
Melledy committed
22
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
23
import emu.grasscutter.server.packet.send.PacketGetPlayerTokenRsp;
Melledy's avatar
Melledy committed
24
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
25
import emu.grasscutter.server.packet.send.PacketPlayerLoginRsp;
Melledy's avatar
Melledy committed
26
27
import emu.grasscutter.utils.Position;

KingRainbow44's avatar
KingRainbow44 committed
28
29
30
31
32
33
34
import java.util.LinkedList;
import java.util.List;

/**
 * A container for player-related commands.
 */
public final class PlayerCommands {
35
36
    @Command(label = "give", aliases = { "g", "item",
            "giveitem" }, usage = "Usage: give [player] <itemId|itemName> [amount]")
KingRainbow44's avatar
KingRainbow44 committed
37
38
39
40
41
42
    public static class GiveCommand implements CommandHandler {

        @Override
        public void execute(GenshinPlayer player, List<String> args) {
            int target, item, amount = 1;

43
            switch (args.size()) {
KingRainbow44's avatar
KingRainbow44 committed
44
45
46
47
48
49
                default:
                    CommandHandler.sendMessage(player, "Usage: give <player> <itemId|itemName> [amount]");
                    return;
                case 1:
                    try {
                        item = Integer.parseInt(args.get(0));
KingRainbow44's avatar
KingRainbow44 committed
50
                        target = player.getAccount().getPlayerId();
KingRainbow44's avatar
KingRainbow44 committed
51
52
53
54
55
56
57
58
59
                    } catch (NumberFormatException ignored) {
                        // TODO: Parse from item name using GM Handbook.
                        CommandHandler.sendMessage(player, "Invalid item id.");
                        return;
                    }
                    break;
                case 2:
                    try {
                        target = Integer.parseInt(args.get(0));
Melledy's avatar
Melledy committed
60

61
62
63
                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            target = player.getUid();
                            amount = Integer.parseInt(args.get(1));
KingRainbow44's avatar
KingRainbow44 committed
64
65
66
67
68
69
70
71
72
73
74
75
76
                            item = Integer.parseInt(args.get(0));
                        } else {
                            item = Integer.parseInt(args.get(1));
                        }
                    } catch (NumberFormatException ignored) {
                        // TODO: Parse from item name using GM Handbook.
                        CommandHandler.sendMessage(player, "Invalid item or player ID.");
                        return;
                    }
                    break;
                case 3:
                    try {
                        target = Integer.parseInt(args.get(0));
77
78
79
80

                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            CommandHandler.sendMessage(player, "Invalid player ID.");
                            return;
KingRainbow44's avatar
KingRainbow44 committed
81
82
83
84
85
86
87
88
89
90
91
92
                        }

                        item = Integer.parseInt(args.get(1));
                        amount = Integer.parseInt(args.get(2));
                    } catch (NumberFormatException ignored) {
                        // TODO: Parse from item name using GM Handbook.
                        CommandHandler.sendMessage(player, "Invalid item or player ID.");
                        return;
                    }
                    break;
            }

93
            GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
Melledy's avatar
Melledy committed
94

95
96
97
            if (targetPlayer == null) {
                CommandHandler.sendMessage(player, "Player not found.");
                return;
KingRainbow44's avatar
KingRainbow44 committed
98
99
100
            }

            ItemData itemData = GenshinData.getItemDataMap().get(item);
101
102
103
            if (itemData == null) {
                CommandHandler.sendMessage(player, "Invalid item id.");
                return;
KingRainbow44's avatar
KingRainbow44 committed
104
            }
105

KingRainbow44's avatar
KingRainbow44 committed
106
107
108
109
110
111
            this.item(targetPlayer, itemData, amount);
        }

        /**
         * give [player] [itemId|itemName] [amount]
         */
112
113
114
        @Override
        public void execute(List<String> args) {
            if (args.size() < 2) {
KingRainbow44's avatar
KingRainbow44 committed
115
116
117
                CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount]");
                return;
            }
118

KingRainbow44's avatar
KingRainbow44 committed
119
120
121
            try {
                int target = Integer.parseInt(args.get(0));
                int item = Integer.parseInt(args.get(1));
122
123
124
125
                int amount = 1;
                if (args.size() > 2)
                    amount = Integer.parseInt(args.get(2));

126
                GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
Melledy's avatar
Melledy committed
127

128
129
130
                if (targetPlayer == null) {
                    CommandHandler.sendMessage(null, "Player not found.");
                    return;
KingRainbow44's avatar
KingRainbow44 committed
131
                }
132

KingRainbow44's avatar
KingRainbow44 committed
133
                ItemData itemData = GenshinData.getItemDataMap().get(item);
134
135
136
                if (itemData == null) {
                    CommandHandler.sendMessage(null, "Invalid item id.");
                    return;
KingRainbow44's avatar
KingRainbow44 committed
137
                }
138

KingRainbow44's avatar
KingRainbow44 committed
139
140
141
142
143
                this.item(targetPlayer, itemData, amount);
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid item or player ID.");
            }
        }
144

KingRainbow44's avatar
KingRainbow44 committed
145
146
        private void item(GenshinPlayer player, ItemData itemData, int amount) {
            GenshinItem genshinItem = new GenshinItem(itemData);
147
            if (itemData.isEquip()) {
KingRainbow44's avatar
KingRainbow44 committed
148
                List<GenshinItem> items = new LinkedList<>();
149
                for (int i = 0; i < amount; i++) {
KingRainbow44's avatar
KingRainbow44 committed
150
                    items.add(genshinItem);
151
152
                }
                player.getInventory().addItems(items);
KingRainbow44's avatar
KingRainbow44 committed
153
154
155
156
157
158
159
160
                player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop));
            } else {
                genshinItem.setCount(amount);
                player.getInventory().addItem(genshinItem);
                player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop));
            }
        }
    }
161
162
163

    @Command(label = "drop", aliases = { "d",
            "dropitem" }, usage = "Usage: drop <itemId|itemName> [amount]", execution = Command.Execution.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
164
    public static class DropCommand implements CommandHandler {
165

KingRainbow44's avatar
KingRainbow44 committed
166
167
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
168
            if (args.size() < 1) {
KingRainbow44's avatar
KingRainbow44 committed
169
                CommandHandler.sendMessage(player, "Usage: drop <itemId|itemName> [amount]");
KingRainbow44's avatar
KingRainbow44 committed
170
171
                return;
            }
172

KingRainbow44's avatar
KingRainbow44 committed
173
174
            try {
                int item = Integer.parseInt(args.get(0));
175
176
177
                int amount = 1;
                if (args.size() > 1)
                    amount = Integer.parseInt(args.get(1));
Melledy's avatar
Melledy committed
178

KingRainbow44's avatar
KingRainbow44 committed
179
                ItemData itemData = GenshinData.getItemDataMap().get(item);
180
181
182
                if (itemData == null) {
                    CommandHandler.sendMessage(player, "Invalid item id.");
                    return;
KingRainbow44's avatar
KingRainbow44 committed
183
                }
184

KingRainbow44's avatar
KingRainbow44 committed
185
186
187
                if (itemData.isEquip()) {
                    float range = (5f + (.1f * amount));
                    for (int i = 0; i < amount; i++) {
188
189
                        Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2))
                                .addY(3f).addZ((float) (Math.random() * range) - (range / 2));
Melledy's avatar
Melledy committed
190
191
                        EntityItem entity = new EntityItem(player.getScene(), player, itemData, pos, 1);
                        player.getScene().addEntity(entity);
KingRainbow44's avatar
KingRainbow44 committed
192
193
                    }
                } else {
194
195
                    EntityItem entity = new EntityItem(player.getScene(), player, itemData,
                            player.getPos().clone().addY(3f), amount);
Melledy's avatar
Melledy committed
196
                    player.getScene().addEntity(entity);
KingRainbow44's avatar
KingRainbow44 committed
197
198
                }
            } catch (NumberFormatException ignored) {
KingRainbow44's avatar
KingRainbow44 committed
199
                CommandHandler.sendMessage(player, "Invalid item or player ID.");
KingRainbow44's avatar
KingRainbow44 committed
200
201
202
            }
        }
    }
SpikeHD's avatar
SpikeHD committed
203

204
205
    @Command(label = "givechar", aliases = {
            "givec" }, usage = "Usage: givechar <player|avatarId> [level|avatarId] [level]")
SpikeHD's avatar
SpikeHD committed
206
    public static class GiveCharCommand implements CommandHandler {
207
208
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
KingRainbow44's avatar
KingRainbow44 committed
209
            int target, avatarId, level = 1, ascension = 1;
SpikeHD's avatar
SpikeHD committed
210

211
            if (args.size() < 1) {
KingRainbow44's avatar
KingRainbow44 committed
212
                CommandHandler.sendMessage(player, "Usage: givechar <player> <avatarId> [level]");
213
214
                return;
            }
215
216

            switch (args.size()) {
217
                default:
218
                    CommandHandler.sendMessage(player, "Usage: givechar <player> <avatarId> [level]");
219
220
221
222
                    return;
                case 2:
                    try {
                        target = Integer.parseInt(args.get(0));
223
224
                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            target = player.getUid();
KingRainbow44's avatar
KingRainbow44 committed
225
                            level = Integer.parseInt(args.get(1));
KingRainbow44's avatar
KingRainbow44 committed
226
                            avatarId = Integer.parseInt(args.get(0));
227
                        } else {
KingRainbow44's avatar
KingRainbow44 committed
228
                            avatarId = Integer.parseInt(args.get(1));
229
230
231
232
233
234
235
236
237
238
                        }
                    } catch (NumberFormatException ignored) {
                        // TODO: Parse from avatar name using GM Handbook.
                        CommandHandler.sendMessage(player, "Invalid avatar or player ID.");
                        return;
                    }
                    break;
                case 3:
                    try {
                        target = Integer.parseInt(args.get(0));
239
240
241
                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            CommandHandler.sendMessage(player, "Invalid player ID.");
                            return;
242
243
                        }

KingRainbow44's avatar
KingRainbow44 committed
244
                        avatarId = Integer.parseInt(args.get(1));
245
246
247
248
249
250
251
252
                        level = Integer.parseInt(args.get(2));
                    } catch (NumberFormatException ignored) {
                        // TODO: Parse from avatar name using GM Handbook.
                        CommandHandler.sendMessage(player, "Invalid avatar or player ID.");
                        return;
                    }
                    break;
            }
SpikeHD's avatar
SpikeHD committed
253

Melledy's avatar
Melledy committed
254
            GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
255
256
257
            if (targetPlayer == null) {
                CommandHandler.sendMessage(player, "Player not found.");
                return;
SpikeHD's avatar
SpikeHD committed
258
            }
259

KingRainbow44's avatar
KingRainbow44 committed
260
            AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId);
261
262
263
            if (avatarData == null) {
                CommandHandler.sendMessage(player, "Invalid avatar id.");
                return;
SpikeHD's avatar
SpikeHD committed
264
265
            }

266
267
            // Calculate ascension level.
            if (level <= 40) {
KingRainbow44's avatar
KingRainbow44 committed
268
269
270
                ascension = (int) Math.ceil(level / 20f);
            } else {
                ascension = (int) Math.ceil(level / 10f) - 3;
271
272
            }

KingRainbow44's avatar
KingRainbow44 committed
273
            GenshinAvatar avatar = new GenshinAvatar(avatarId);
SpikeHD's avatar
SpikeHD committed
274
            avatar.setLevel(level);
275
            avatar.setPromoteLevel(ascension);
276

277
278
            // This will handle stats and talents
            avatar.recalcStats();
279

280
281
            targetPlayer.addAvatar(avatar);
        }
SpikeHD's avatar
SpikeHD committed
282

283
284
        @Override
        public void execute(List<String> args) {
285
            if (args.size() < 2) {
SpikeHD's avatar
SpikeHD committed
286
                CommandHandler.sendMessage(null, "Usage: givechar <player> <itemId|itemName> [amount]");
287
288
289
290
291
292
                return;
            }

            try {
                int target = Integer.parseInt(args.get(0));
                int avatarID = Integer.parseInt(args.get(1));
293
294
295
                int level = 1;
                if (args.size() > 2)
                    level = Integer.parseInt(args.get(2));
KingRainbow44's avatar
KingRainbow44 committed
296
                int ascension;
297

Melledy's avatar
Melledy committed
298
                GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
299
300
301
                if (targetPlayer == null) {
                    CommandHandler.sendMessage(null, "Player not found.");
                    return;
302
                }
303

304
                AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarID);
305
306
307
                if (avatarData == null) {
                    CommandHandler.sendMessage(null, "Invalid avatar id.");
                    return;
308
                }
309

310
311
                // Calculate ascension level.
                if (level <= 40) {
KingRainbow44's avatar
KingRainbow44 committed
312
313
314
                    ascension = (int) Math.ceil(level / 20f);
                } else {
                    ascension = (int) Math.ceil(level / 10f) - 3;
315
                }
316

317
318
                GenshinAvatar avatar = new GenshinAvatar(avatarID);
                avatar.setLevel(level);
319
                avatar.setPromoteLevel(ascension);
320
321
322

                // This will handle stats and talents
                avatar.recalcStats();
323

324
325
326
327
                targetPlayer.addAvatar(avatar);
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid item or player ID.");
            }
SpikeHD's avatar
SpikeHD committed
328
329
        }
    }
Melledy's avatar
Melledy committed
330

331
    @Command(label = "spawn", execution = Command.Execution.PLAYER, usage = "Usage: spawn <entityId|entityName> [level] [amount]")
KingRainbow44's avatar
KingRainbow44 committed
332
    public static class SpawnCommand implements CommandHandler {
333

KingRainbow44's avatar
KingRainbow44 committed
334
335
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
336
            if (args.size() < 1) {
KingRainbow44's avatar
KingRainbow44 committed
337
338
339
                CommandHandler.sendMessage(null, "Usage: spawn <entityId|entityName> [amount]");
                return;
            }
340

KingRainbow44's avatar
KingRainbow44 committed
341
342
            try {
                int entity = Integer.parseInt(args.get(0));
343
344
345
346
347
348
                int level = 1;
                if (args.size() > 1)
                    level = Integer.parseInt(args.get(1));
                int amount = 1;
                if (args.size() > 2)
                    amount = Integer.parseInt(args.get(2));
349

KingRainbow44's avatar
KingRainbow44 committed
350
                MonsterData entityData = GenshinData.getMonsterDataMap().get(entity);
351
352
353
                if (entityData == null) {
                    CommandHandler.sendMessage(null, "Invalid entity id.");
                    return;
KingRainbow44's avatar
KingRainbow44 committed
354
                }
355

KingRainbow44's avatar
KingRainbow44 committed
356
357
                float range = (5f + (.1f * amount));
                for (int i = 0; i < amount; i++) {
358
359
                    Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f)
                            .addZ((float) (Math.random() * range) - (range / 2));
Melledy's avatar
Melledy committed
360
361
                    EntityMonster monster = new EntityMonster(player.getScene(), entityData, pos, level);
                    player.getScene().addEntity(monster);
KingRainbow44's avatar
KingRainbow44 committed
362
363
364
365
366
367
                }
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid item or player ID.");
            }
        }
    }
368
369

    @Command(label = "killall", usage = "Usage: killall [playerUid] [sceneId]")
KingRainbow44's avatar
KingRainbow44 committed
370
    public static class KillAllCommand implements CommandHandler {
371

KingRainbow44's avatar
KingRainbow44 committed
372
373
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
Melledy's avatar
Melledy committed
374
375
            GenshinScene scene = player.getScene();
            scene.getEntities().values().stream()
KingRainbow44's avatar
KingRainbow44 committed
376
                    .filter(entity -> entity instanceof EntityMonster)
Melledy's avatar
Melledy committed
377
378
                    .forEach(entity -> scene.killEntity(entity, 0));
            CommandHandler.sendMessage(null, "Killing all monsters in scene " + scene.getId());
KingRainbow44's avatar
KingRainbow44 committed
379
        }
380

KingRainbow44's avatar
KingRainbow44 committed
381
382
        @Override
        public void execute(List<String> args) {
383
384
385
            if (args.size() < 2) {
                CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]");
                return;
KingRainbow44's avatar
KingRainbow44 committed
386
            }
387

KingRainbow44's avatar
KingRainbow44 committed
388
            try {
389
                int playerUid = Integer.parseInt(args.get(0));
Melledy's avatar
Melledy committed
390
                int sceneId = Integer.parseInt(args.get(1));
391

392
                GenshinPlayer player = Grasscutter.getGameServer().getPlayerByUid(playerUid);
Melledy's avatar
Melledy committed
393
                if (player == null) {
394
395
                    CommandHandler.sendMessage(null, "Player not found or offline.");
                    return;
Melledy's avatar
Melledy committed
396
                }
397

Melledy's avatar
Melledy committed
398
399
                GenshinScene scene = player.getWorld().getSceneById(sceneId);
                if (scene == null) {
400
401
                    CommandHandler.sendMessage(null, "Scene not found in player world");
                    return;
Melledy's avatar
Melledy committed
402
                }
403

Melledy's avatar
Melledy committed
404
405
406
407
                scene.getEntities().values().stream()
                        .filter(entity -> entity instanceof EntityMonster)
                        .forEach(entity -> scene.killEntity(entity, 0));
                CommandHandler.sendMessage(null, "Killing all monsters in scene " + scene.getId());
KingRainbow44's avatar
KingRainbow44 committed
408
            } catch (NumberFormatException ignored) {
Melledy's avatar
Melledy committed
409
                CommandHandler.sendMessage(null, "Invalid arguments.");
KingRainbow44's avatar
KingRainbow44 committed
410
411
412
            }
        }
    }
413
414
415

    @Command(label = "resetconst", aliases = {
            "resetconstellation" }, usage = "Usage: resetconst [all]", execution = Command.Execution.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
416
    public static class ResetConstellationCommand implements CommandHandler {
417

KingRainbow44's avatar
KingRainbow44 committed
418
419
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
420
            if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
KingRainbow44's avatar
KingRainbow44 committed
421
422
423
                player.getAvatars().forEach(this::resetConstellation);
                player.dropMessage("Reset all avatars' constellations.");
            } else {
424
425
                EntityAvatar entity = player.getTeamManager().getCurrentAvatarEntity();
                if (entity == null)
KingRainbow44's avatar
KingRainbow44 committed
426
                    return;
427

KingRainbow44's avatar
KingRainbow44 committed
428
429
                GenshinAvatar avatar = entity.getAvatar();
                this.resetConstellation(avatar);
430

431
432
                player.dropMessage("Constellations for " + avatar.getAvatarData().getName()
                        + " have been reset. Please relog to see changes.");
KingRainbow44's avatar
KingRainbow44 committed
433
434
            }
        }
435

KingRainbow44's avatar
KingRainbow44 committed
436
437
438
439
440
441
442
        private void resetConstellation(GenshinAvatar avatar) {
            avatar.getTalentIdList().clear();
            avatar.setCoreProudSkillLevel(0);
            avatar.recalcStats();
            avatar.save();
        }
    }
443
444

    @Command(label = "godmode", usage = "Usage: godmode", execution = Command.Execution.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
445
    public static class GodModeCommand implements CommandHandler {
446

KingRainbow44's avatar
KingRainbow44 committed
447
448
449
450
451
452
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
            player.setGodmode(!player.inGodmode());
            player.dropMessage("Godmode is now " + (player.inGodmode() ? "enabled" : "disabled") + ".");
        }
    }
453
454
455

    @Command(label = "sethealth", aliases = {
            "sethp" }, usage = "Usage: sethealth <hp>", execution = Command.Execution.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
456
    public static class SetHealthCommand implements CommandHandler {
457

KingRainbow44's avatar
KingRainbow44 committed
458
459
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
460
461
462
            if (args.size() < 1) {
                CommandHandler.sendMessage(null, "Usage: sethealth <hp>");
                return;
KingRainbow44's avatar
KingRainbow44 committed
463
            }
464

KingRainbow44's avatar
KingRainbow44 committed
465
466
467
            try {
                int health = Integer.parseInt(args.get(0));
                EntityAvatar entity = player.getTeamManager().getCurrentAvatarEntity();
468
                if (entity == null)
KingRainbow44's avatar
KingRainbow44 committed
469
                    return;
470

KingRainbow44's avatar
KingRainbow44 committed
471
                entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health);
472
473
                entity.getWorld().broadcastPacket(
                        new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
KingRainbow44's avatar
KingRainbow44 committed
474
475
476
477
478
479
                player.dropMessage("Health set to " + health + ".");
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid health value.");
            }
        }
    }
SpikeHD's avatar
SpikeHD committed
480

481
482
    @Command(label = "setworldlevel", aliases = {
            "setworldlvl" }, usage = "Usage: setworldlevel <level>", execution = Command.Execution.PLAYER)
SpikeHD's avatar
SpikeHD committed
483
484
485
    public static class SetWorldLevelCommand implements CommandHandler {
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
486
487
488
            if (args.size() < 1) {
                CommandHandler.sendMessage(player, "Usage: setworldlevel <level>");
                return;
SpikeHD's avatar
SpikeHD committed
489
            }
490

SpikeHD's avatar
SpikeHD committed
491
492
493
494
495
496
497
498
499
500
501
502
503
            try {
                int level = Integer.parseInt(args.get(0));

                // Set in both world and player props
                player.getWorld().setWorldLevel(level);
                player.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level);

                player.dropMessage("World level set to " + level + ".");
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid world level.");
            }
        }
    }
504
505
506

    @Command(label = "clearartifacts", aliases = {
            "clearart" }, usage = "Usage: clearartifacts", execution = Command.Execution.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
507
508
509
510
511
512
513
514
515
516
517
    public static class ClearArtifactsCommand implements CommandHandler {
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
            Inventory playerInventory = player.getInventory();
            playerInventory.getItems().values().stream()
                    .filter(item -> item.getItemType() == ItemType.ITEM_RELIQUARY)
                    .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
                    .filter(item -> !item.isLocked() && !item.isEquipped())
                    .forEach(item -> playerInventory.removeItem(item, item.getCount()));
        }
    }
518

519
520
    @Command(label = "changescene", aliases = {
            "scene" }, usage = "Usage: changescene <scene id>", execution = Command.Execution.PLAYER)
Melledy's avatar
Melledy committed
521
522
523
    public static class ChangeSceneCommand implements CommandHandler {
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
524
525
526
            if (args.size() < 1) {
                CommandHandler.sendMessage(player, "Usage: changescene <scene id>");
                return;
Melledy's avatar
Melledy committed
527
            }
528

Melledy's avatar
Melledy committed
529
            try {
KingRainbow44's avatar
KingRainbow44 committed
530
531
532
533
534
535
                int sceneId = Integer.parseInt(args.get(0));
                boolean result = player.getWorld().transferPlayerToScene(player, sceneId, player.getPos());

                if (!result) {
                    CommandHandler.sendMessage(null, "Scene does not exist or you are already in it");
                }
Melledy's avatar
Melledy committed
536
            } catch (Exception e) {
537
538
                CommandHandler.sendMessage(player, "Usage: changescene <scene id>");
                return;
Melledy's avatar
Melledy committed
539
540
541
            }
        }
    }
542
543
544
545
546
547

    @Command(label = "restart", usage = "Usage: restart - Restarts the current session", execution = Command.Execution.PLAYER)
    public static class RestartCommand implements CommandHandler {

        @Override
        public void execute(GenshinPlayer player, List<String> args) {
548
549
            // player.getSession().close();
            player.getSession().send(new PacketGetPlayerTokenRsp(player.getSession(), true));
550
551
        }
    }
Melledy's avatar
Melledy committed
552
}