From d761b50656b7230ac664be4c6d04b62f5d592cc8 Mon Sep 17 00:00:00 2001 From: BaiSugar Date: Sun, 24 Apr 2022 14:01:03 +0800 Subject: [PATCH 1/9] Added command to get all items --- .../command/commands/GiveAllCommand.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java new file mode 100644 index 000000000..a90080e0a --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -0,0 +1,109 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.data.GenshinData; +import emu.grasscutter.data.def.AvatarData; +import emu.grasscutter.data.def.ItemData; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.avatar.GenshinAvatar; +import emu.grasscutter.game.inventory.GenshinItem; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; + +import java.util.LinkedList; +import java.util.List; + +@Command(label = "giveall", usage = "giveall [player] ", + description = "Gives All item to you or the specified player", aliases = {"givea"}, permission = "player.giveall") +public class GiveAllCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + int target,amount=99999; + + switch (args.size()) { + default: // giveall *no args* + target = sender.getUid(); + break; + case 1: //[player] + try { + target = Integer.parseInt(args.get(0)); + if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { + CommandHandler.sendMessage(sender, "Invalid player ID."); + return; + } + }catch (NumberFormatException ignored){ + CommandHandler.sendMessage(sender, "Invalid amount or player ID."); + return; + } + break; + case 2: //[player] [amount] + try { + target = Integer.parseInt(args.get(0)); + if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { + target = sender.getUid(); + amount = Integer.parseInt(args.get(0)); + } else { + amount = Integer.parseInt(args.get(1)); + } + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid amount or player ID."); + return; + } + break; + } + GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); + + if (targetPlayer == null) { + CommandHandler.sendMessage(sender, "Player not found."); + return; + } + + this.GetAllItem(targetPlayer,amount); + CommandHandler.sendMessage(sender, String.format("Get All Items Done.")); + } + + public void GetAllItem(GenshinPlayer player, int amount){ + CommandHandler.sendMessage(player, "Get All Items..."); + for (ItemData itemdata: GenshinData.getItemDataMap().values()) { + if(itemdata.getId() > 1000 && itemdata.getId() <= 2000)continue;//is avatar + if (itemdata.isEquip()) { + List items = new LinkedList<>(); + for (int i = 0; i < 20; i++) { + items.add(new GenshinItem(itemdata)); + } + player.getInventory().addItems(items); + player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop)); + } else { + GenshinItem genshinItem = new GenshinItem(itemdata); + genshinItem.setCount(amount); + player.getInventory().addItem(genshinItem); + player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop)); + } + } + for(AvatarData avatarData:GenshinData.getAvatarDataMap().values()) + { + int ascension; + int level = 90; + // Calculate ascension level. + if (level <= 40) { + ascension = (int) Math.ceil(90 / 20f); + } else { + ascension = (int) Math.ceil(90 / 10f) - 3; + } + + GenshinAvatar avatar = new GenshinAvatar(avatarData); + avatar.setLevel(level); + avatar.setPromoteLevel(ascension); + for (int i = 1;i<=6;i++){ + avatar.getTalentIdList().add((avatar.getAvatarId()-10000000)*10+i);//(10000058-10000000)*10+i + } + // This will handle stats and talents + avatar.recalcStats(); + player.addAvatar(avatar); + } + } + +} From 95871abb5b597340bb0e5deb3e8481824934fbda Mon Sep 17 00:00:00 2001 From: BaiSugar Date: Sun, 24 Apr 2022 21:52:50 +0800 Subject: [PATCH 2/9] Added command to get all items --- .../java/emu/grasscutter/command/Command.java | 2 ++ .../emu/grasscutter/command/CommandMap.java | 19 +++++++---- .../command/commands/GiveAllCommand.java | 33 ++++++++++--------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/Command.java b/src/main/java/emu/grasscutter/command/Command.java index d8a57e1a8..c38568d65 100644 --- a/src/main/java/emu/grasscutter/command/Command.java +++ b/src/main/java/emu/grasscutter/command/Command.java @@ -14,4 +14,6 @@ public @interface Command { String[] aliases() default {}; String permission() default ""; + + boolean threading() default false; } diff --git a/src/main/java/emu/grasscutter/command/CommandMap.java b/src/main/java/emu/grasscutter/command/CommandMap.java index f735bc642..19ab687ad 100644 --- a/src/main/java/emu/grasscutter/command/CommandMap.java +++ b/src/main/java/emu/grasscutter/command/CommandMap.java @@ -11,7 +11,6 @@ import java.util.*; public final class CommandMap { private final Map commands = new HashMap<>(); private final Map annotations = new HashMap<>(); - public CommandMap() { this(false); } @@ -106,8 +105,9 @@ public final class CommandMap { */ public void invoke(GenshinPlayer player, String rawMessage) { rawMessage = rawMessage.trim(); - if(rawMessage.length() == 0) { - CommandHandler.sendMessage(player, "No command specified."); return; + if (rawMessage.length() == 0) { + CommandHandler.sendMessage(player, "No command specified."); + return; } // Remove prefix if present. @@ -118,7 +118,6 @@ public final class CommandMap { String[] split = rawMessage.split(" "); List args = new LinkedList<>(Arrays.asList(split)); String label = args.remove(0); - // Get command handler. CommandHandler handler = this.commands.get(label); if (handler == null) { @@ -130,14 +129,22 @@ public final class CommandMap { if (player != null) { String permissionNode = this.annotations.get(label).permission(); Account account = player.getAccount(); - if(!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) { + if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) { CommandHandler.sendMessage(player, "You do not have permission to run this command."); return; } } // Invoke execute method for handler. - handler.execute(player, args); + boolean threading = this.annotations.get(label).threading(); + Runnable runnable = () -> handler.execute(player, args); + if(threading) { + Thread command = new Thread(runnable); + command.start(); + } + else { + runnable.run(); + } } /** diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java index a90080e0a..ad4240b01 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -1,5 +1,6 @@ package emu.grasscutter.command.commands; +import com.thoughtworks.proxy.toys.nullobject.Null; import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; @@ -9,14 +10,11 @@ import emu.grasscutter.data.def.ItemData; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.inventory.GenshinItem; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; -import java.util.LinkedList; -import java.util.List; +import java.util.*; @Command(label = "giveall", usage = "giveall [player] ", - description = "Gives All item to you or the specified player", aliases = {"givea"}, permission = "player.giveall") + description = "Gives all items", aliases = {"givea"}, permission = "player.giveall",threading = true) public class GiveAllCommand implements CommandHandler { @Override @@ -25,7 +23,12 @@ public class GiveAllCommand implements CommandHandler { switch (args.size()) { default: // giveall *no args* - target = sender.getUid(); + try { + target = sender.getUid(); + }catch (NullPointerException ignored){ + CommandHandler.sendMessage(sender, "Player not found."); + return; + } break; case 1: //[player] try { @@ -62,27 +65,27 @@ public class GiveAllCommand implements CommandHandler { } this.GetAllItem(targetPlayer,amount); - CommandHandler.sendMessage(sender, String.format("Get All Items Done.")); + CommandHandler.sendMessage(sender, "Done! or Getting all items done"); } public void GetAllItem(GenshinPlayer player, int amount){ - CommandHandler.sendMessage(player, "Get All Items..."); + CommandHandler.sendMessage(player, "Getting all items…"); + + Collection genshinItemList =new LinkedList<>(); for (ItemData itemdata: GenshinData.getItemDataMap().values()) { - if(itemdata.getId() > 1000 && itemdata.getId() <= 2000)continue;//is avatar + if(itemdata.getId() > 1000 && itemdata.getId() <= 1099)continue;//is avatar if (itemdata.isEquip()) { - List items = new LinkedList<>(); for (int i = 0; i < 20; i++) { - items.add(new GenshinItem(itemdata)); + genshinItemList.add(new GenshinItem(itemdata)); } - player.getInventory().addItems(items); - player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop)); } else { GenshinItem genshinItem = new GenshinItem(itemdata); genshinItem.setCount(amount); - player.getInventory().addItem(genshinItem); - player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop)); + genshinItemList.add(genshinItem); } } + player.getInventory().addItems(genshinItemList); + for(AvatarData avatarData:GenshinData.getAvatarDataMap().values()) { int ascension; From 153593b64c57e68ce275b6138c5e17d83371f863 Mon Sep 17 00:00:00 2001 From: BaiSugar Date: Sun, 24 Apr 2022 22:38:53 +0800 Subject: [PATCH 3/9] Corrected format --- .../java/emu/grasscutter/command/Command.java | 2 +- .../emu/grasscutter/command/CommandMap.java | 2 ++ .../command/commands/GiveAllCommand.java | 23 ++++++------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/Command.java b/src/main/java/emu/grasscutter/command/Command.java index c38568d65..a0edc5cdc 100644 --- a/src/main/java/emu/grasscutter/command/Command.java +++ b/src/main/java/emu/grasscutter/command/Command.java @@ -15,5 +15,5 @@ public @interface Command { String permission() default ""; - boolean threading() default false; + boolean threading() default false; } diff --git a/src/main/java/emu/grasscutter/command/CommandMap.java b/src/main/java/emu/grasscutter/command/CommandMap.java index 19ab687ad..f104e3bfc 100644 --- a/src/main/java/emu/grasscutter/command/CommandMap.java +++ b/src/main/java/emu/grasscutter/command/CommandMap.java @@ -136,9 +136,11 @@ public final class CommandMap { } // Invoke execute method for handler. + // Get whether the command starts a thread boolean threading = this.annotations.get(label).threading(); Runnable runnable = () -> handler.execute(player, args); if(threading) { + //start thread Thread command = new Thread(runnable); command.start(); } diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java index ad4240b01..d817b2967 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -1,6 +1,5 @@ package emu.grasscutter.command.commands; -import com.thoughtworks.proxy.toys.nullobject.Null; import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; @@ -22,7 +21,7 @@ public class GiveAllCommand implements CommandHandler { int target,amount=99999; switch (args.size()) { - default: // giveall *no args* + default: // *no args* try { target = sender.getUid(); }catch (NullPointerException ignored){ @@ -38,7 +37,7 @@ public class GiveAllCommand implements CommandHandler { return; } }catch (NumberFormatException ignored){ - CommandHandler.sendMessage(sender, "Invalid amount or player ID."); + CommandHandler.sendMessage(sender, "Invalid player ID."); return; } break; @@ -73,7 +72,7 @@ public class GiveAllCommand implements CommandHandler { Collection genshinItemList =new LinkedList<>(); for (ItemData itemdata: GenshinData.getItemDataMap().values()) { - if(itemdata.getId() > 1000 && itemdata.getId() <= 1099)continue;//is avatar + if(itemdata.getId() > 1000 && itemdata.getId() <= 1099) continue; if (itemdata.isEquip()) { for (int i = 0; i < 20; i++) { genshinItemList.add(new GenshinItem(itemdata)); @@ -86,22 +85,14 @@ public class GiveAllCommand implements CommandHandler { } player.getInventory().addItems(genshinItemList); - for(AvatarData avatarData:GenshinData.getAvatarDataMap().values()) - { - int ascension; - int level = 90; + for(AvatarData avatarData:GenshinData.getAvatarDataMap().values()) { // Calculate ascension level. - if (level <= 40) { - ascension = (int) Math.ceil(90 / 20f); - } else { - ascension = (int) Math.ceil(90 / 10f) - 3; - } - + int ascension = (int) Math.ceil(90 / 10f) - 3; GenshinAvatar avatar = new GenshinAvatar(avatarData); - avatar.setLevel(level); + avatar.setLevel(90); avatar.setPromoteLevel(ascension); for (int i = 1;i<=6;i++){ - avatar.getTalentIdList().add((avatar.getAvatarId()-10000000)*10+i);//(10000058-10000000)*10+i + avatar.getTalentIdList().add((avatar.getAvatarId()-10000000)*10+i); } // This will handle stats and talents avatar.recalcStats(); From 271f9b9ec53e6d878c60b4007b4d4351985973f9 Mon Sep 17 00:00:00 2001 From: BaiSugar Date: Sun, 24 Apr 2022 22:42:44 +0800 Subject: [PATCH 4/9] Revert "Corrected format" This reverts commit 153593b64c57e68ce275b6138c5e17d83371f863. --- .../java/emu/grasscutter/command/Command.java | 2 +- .../emu/grasscutter/command/CommandMap.java | 2 -- .../command/commands/GiveAllCommand.java | 23 +++++++++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/Command.java b/src/main/java/emu/grasscutter/command/Command.java index a0edc5cdc..c38568d65 100644 --- a/src/main/java/emu/grasscutter/command/Command.java +++ b/src/main/java/emu/grasscutter/command/Command.java @@ -15,5 +15,5 @@ public @interface Command { String permission() default ""; - boolean threading() default false; + boolean threading() default false; } diff --git a/src/main/java/emu/grasscutter/command/CommandMap.java b/src/main/java/emu/grasscutter/command/CommandMap.java index f104e3bfc..19ab687ad 100644 --- a/src/main/java/emu/grasscutter/command/CommandMap.java +++ b/src/main/java/emu/grasscutter/command/CommandMap.java @@ -136,11 +136,9 @@ public final class CommandMap { } // Invoke execute method for handler. - // Get whether the command starts a thread boolean threading = this.annotations.get(label).threading(); Runnable runnable = () -> handler.execute(player, args); if(threading) { - //start thread Thread command = new Thread(runnable); command.start(); } diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java index d817b2967..ad4240b01 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -1,5 +1,6 @@ package emu.grasscutter.command.commands; +import com.thoughtworks.proxy.toys.nullobject.Null; import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; @@ -21,7 +22,7 @@ public class GiveAllCommand implements CommandHandler { int target,amount=99999; switch (args.size()) { - default: // *no args* + default: // giveall *no args* try { target = sender.getUid(); }catch (NullPointerException ignored){ @@ -37,7 +38,7 @@ public class GiveAllCommand implements CommandHandler { return; } }catch (NumberFormatException ignored){ - CommandHandler.sendMessage(sender, "Invalid player ID."); + CommandHandler.sendMessage(sender, "Invalid amount or player ID."); return; } break; @@ -72,7 +73,7 @@ public class GiveAllCommand implements CommandHandler { Collection genshinItemList =new LinkedList<>(); for (ItemData itemdata: GenshinData.getItemDataMap().values()) { - if(itemdata.getId() > 1000 && itemdata.getId() <= 1099) continue; + if(itemdata.getId() > 1000 && itemdata.getId() <= 1099)continue;//is avatar if (itemdata.isEquip()) { for (int i = 0; i < 20; i++) { genshinItemList.add(new GenshinItem(itemdata)); @@ -85,14 +86,22 @@ public class GiveAllCommand implements CommandHandler { } player.getInventory().addItems(genshinItemList); - for(AvatarData avatarData:GenshinData.getAvatarDataMap().values()) { + for(AvatarData avatarData:GenshinData.getAvatarDataMap().values()) + { + int ascension; + int level = 90; // Calculate ascension level. - int ascension = (int) Math.ceil(90 / 10f) - 3; + if (level <= 40) { + ascension = (int) Math.ceil(90 / 20f); + } else { + ascension = (int) Math.ceil(90 / 10f) - 3; + } + GenshinAvatar avatar = new GenshinAvatar(avatarData); - avatar.setLevel(90); + avatar.setLevel(level); avatar.setPromoteLevel(ascension); for (int i = 1;i<=6;i++){ - avatar.getTalentIdList().add((avatar.getAvatarId()-10000000)*10+i); + avatar.getTalentIdList().add((avatar.getAvatarId()-10000000)*10+i);//(10000058-10000000)*10+i } // This will handle stats and talents avatar.recalcStats(); From 5eccbc8565a2c302cf743e04ec26768a8f767441 Mon Sep 17 00:00:00 2001 From: BaiSugar Date: Sun, 24 Apr 2022 22:45:30 +0800 Subject: [PATCH 5/9] Corrected format --- .../java/emu/grasscutter/command/commands/GiveAllCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java index ad4240b01..8d6bba061 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -1,6 +1,5 @@ package emu.grasscutter.command.commands; -import com.thoughtworks.proxy.toys.nullobject.Null; import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; From 1132c2c753f9ad70ba4174883f9a01d008da7e80 Mon Sep 17 00:00:00 2001 From: BaiSugar Date: Sun, 24 Apr 2022 22:46:43 +0800 Subject: [PATCH 6/9] Corrected format --- src/main/java/emu/grasscutter/command/Command.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/command/Command.java b/src/main/java/emu/grasscutter/command/Command.java index c38568d65..a0edc5cdc 100644 --- a/src/main/java/emu/grasscutter/command/Command.java +++ b/src/main/java/emu/grasscutter/command/Command.java @@ -15,5 +15,5 @@ public @interface Command { String permission() default ""; - boolean threading() default false; + boolean threading() default false; } From 05c6b298317fa5b7cc91f231396255f4082f002b Mon Sep 17 00:00:00 2001 From: BaiSugar Date: Sun, 24 Apr 2022 22:49:33 +0800 Subject: [PATCH 7/9] fix --- .../command/commands/GiveAllCommand.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java index 8d6bba061..4a7777565 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -21,7 +21,7 @@ public class GiveAllCommand implements CommandHandler { int target,amount=99999; switch (args.size()) { - default: // giveall *no args* + default: // *no args* try { target = sender.getUid(); }catch (NullPointerException ignored){ @@ -29,7 +29,7 @@ public class GiveAllCommand implements CommandHandler { return; } break; - case 1: //[player] + case 1: // [player] try { target = Integer.parseInt(args.get(0)); if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { @@ -37,11 +37,11 @@ public class GiveAllCommand implements CommandHandler { return; } }catch (NumberFormatException ignored){ - CommandHandler.sendMessage(sender, "Invalid amount or player ID."); + CommandHandler.sendMessage(sender, "Invalid player ID."); return; } break; - case 2: //[player] [amount] + case 2: // [player] [amount] try { target = Integer.parseInt(args.get(0)); if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { @@ -85,19 +85,11 @@ public class GiveAllCommand implements CommandHandler { } player.getInventory().addItems(genshinItemList); - for(AvatarData avatarData:GenshinData.getAvatarDataMap().values()) - { - int ascension; - int level = 90; + for(AvatarData avatarData:GenshinData.getAvatarDataMap().values()) { // Calculate ascension level. - if (level <= 40) { - ascension = (int) Math.ceil(90 / 20f); - } else { - ascension = (int) Math.ceil(90 / 10f) - 3; - } - + int ascension = (int) Math.ceil(90 / 10f) - 3; GenshinAvatar avatar = new GenshinAvatar(avatarData); - avatar.setLevel(level); + avatar.setLevel(90); avatar.setPromoteLevel(ascension); for (int i = 1;i<=6;i++){ avatar.getTalentIdList().add((avatar.getAvatarId()-10000000)*10+i);//(10000058-10000000)*10+i From 1567e480e1bacfbb3b17a01802523012fd51f1b6 Mon Sep 17 00:00:00 2001 From: BaiSugar Date: Mon, 25 Apr 2022 15:17:55 +0800 Subject: [PATCH 8/9] remove test avatar --- .../command/commands/GiveAllCommand.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java index 4a7777565..b994fe419 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -9,25 +9,24 @@ import emu.grasscutter.data.def.ItemData; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.inventory.GenshinItem; +import emu.grasscutter.game.inventory.ItemType; import java.util.*; @Command(label = "giveall", usage = "giveall [player] ", description = "Gives all items", aliases = {"givea"}, permission = "player.giveall",threading = true) public class GiveAllCommand implements CommandHandler { - @Override public void execute(GenshinPlayer sender, List args) { int target,amount=99999; + if(sender == null){ + CommandHandler.sendMessage(null, "Run this command in-game"); + return; + } switch (args.size()) { default: // *no args* - try { - target = sender.getUid(); - }catch (NullPointerException ignored){ - CommandHandler.sendMessage(sender, "Player not found."); - return; - } + target = sender.getUid(); break; case 1: // [player] try { @@ -44,7 +43,7 @@ public class GiveAllCommand implements CommandHandler { case 2: // [player] [amount] try { target = Integer.parseInt(args.get(0)); - if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { + if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { target = sender.getUid(); amount = Integer.parseInt(args.get(0)); } else { @@ -56,8 +55,8 @@ public class GiveAllCommand implements CommandHandler { } break; } - GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); + GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); if (targetPlayer == null) { CommandHandler.sendMessage(sender, "Player not found."); return; @@ -68,14 +67,19 @@ public class GiveAllCommand implements CommandHandler { } public void GetAllItem(GenshinPlayer player, int amount){ - CommandHandler.sendMessage(player, "Getting all items…"); + CommandHandler.sendMessage(player, "Getting all item...."); Collection genshinItemList =new LinkedList<>(); for (ItemData itemdata: GenshinData.getItemDataMap().values()) { if(itemdata.getId() > 1000 && itemdata.getId() <= 1099)continue;//is avatar if (itemdata.isEquip()) { for (int i = 0; i < 20; i++) { - genshinItemList.add(new GenshinItem(itemdata)); + GenshinItem genshinItem = new GenshinItem(itemdata); + if(itemdata.getItemType() == ItemType.ITEM_WEAPON){ + genshinItem.setLevel(90); + genshinItem.setPromoteLevel(6); + } + genshinItemList.add(genshinItem); } } else { GenshinItem genshinItem = new GenshinItem(itemdata); @@ -86,6 +90,7 @@ public class GiveAllCommand implements CommandHandler { player.getInventory().addItems(genshinItemList); for(AvatarData avatarData:GenshinData.getAvatarDataMap().values()) { + if(avatarData.getId() == 10000001 || avatarData.getId() >= 10000099)continue; // Calculate ascension level. int ascension = (int) Math.ceil(90 / 10f) - 3; GenshinAvatar avatar = new GenshinAvatar(avatarData); From 0132ad66abe07e20b5e868b415351a7eb08e7224 Mon Sep 17 00:00:00 2001 From: BaiSugar Date: Tue, 26 Apr 2022 16:35:06 +0800 Subject: [PATCH 9/9] remove test avatar --- .../command/commands/GiveAllCommand.java | 157 +++++++++++++----- 1 file changed, 119 insertions(+), 38 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java index b994fe419..47ac08405 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -14,20 +14,22 @@ import emu.grasscutter.game.inventory.ItemType; import java.util.*; @Command(label = "giveall", usage = "giveall [player] ", - description = "Gives all items", aliases = {"givea"}, permission = "player.giveall",threading = true) + description = "Gives all items", aliases = {"givea"}, permission = "player.giveall", threading = true) public class GiveAllCommand implements CommandHandler { + @Override public void execute(GenshinPlayer sender, List args) { - int target,amount=99999; + int target, amount = 99999; - if(sender == null){ - CommandHandler.sendMessage(null, "Run this command in-game"); - return; - } switch (args.size()) { - default: // *no args* + case 0: // *no args* + if (sender == null) { + CommandHandler.sendMessage(null, "This usage can only be run in-game"); + return; + } target = sender.getUid(); break; + case 1: // [player] try { target = Integer.parseInt(args.get(0)); @@ -40,6 +42,7 @@ public class GiveAllCommand implements CommandHandler { return; } break; + case 2: // [player] [amount] try { target = Integer.parseInt(args.get(0)); @@ -49,11 +52,15 @@ public class GiveAllCommand implements CommandHandler { } else { amount = Integer.parseInt(args.get(1)); } - } catch (NumberFormatException ignored) { + } catch (NumberFormatException ignored) { CommandHandler.sendMessage(sender, "Invalid amount or player ID."); return; } break; + + default: // invalid + CommandHandler.sendMessage(null, "Usage: giveall [player] "); + return; } GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); @@ -62,47 +69,121 @@ public class GiveAllCommand implements CommandHandler { return; } - this.GetAllItem(targetPlayer,amount); - CommandHandler.sendMessage(sender, "Done! or Getting all items done"); + this.giveAllItems(targetPlayer, amount); + CommandHandler.sendMessage(sender, "Giving all items done"); } - public void GetAllItem(GenshinPlayer player, int amount){ - CommandHandler.sendMessage(player, "Getting all item...."); + public void giveAllItems(GenshinPlayer player, int amount) { + CommandHandler.sendMessage(player, "Giving all items..."); - Collection genshinItemList =new LinkedList<>(); - for (ItemData itemdata: GenshinData.getItemDataMap().values()) { - if(itemdata.getId() > 1000 && itemdata.getId() <= 1099)continue;//is avatar - if (itemdata.isEquip()) { - for (int i = 0; i < 20; i++) { - GenshinItem genshinItem = new GenshinItem(itemdata); - if(itemdata.getItemType() == ItemType.ITEM_WEAPON){ - genshinItem.setLevel(90); - genshinItem.setPromoteLevel(6); - } - genshinItemList.add(genshinItem); - } - } else { - GenshinItem genshinItem = new GenshinItem(itemdata); - genshinItem.setCount(amount); - genshinItemList.add(genshinItem); - } - } - player.getInventory().addItems(genshinItemList); + for (AvatarData avatarData: GenshinData.getAvatarDataMap().values()) { + //Exclude test avatar + if (isTestAvatar(avatarData.getId())) continue; - for(AvatarData avatarData:GenshinData.getAvatarDataMap().values()) { - if(avatarData.getId() == 10000001 || avatarData.getId() >= 10000099)continue; - // Calculate ascension level. - int ascension = (int) Math.ceil(90 / 10f) - 3; GenshinAvatar avatar = new GenshinAvatar(avatarData); avatar.setLevel(90); - avatar.setPromoteLevel(ascension); - for (int i = 1;i<=6;i++){ - avatar.getTalentIdList().add((avatar.getAvatarId()-10000000)*10+i);//(10000058-10000000)*10+i + avatar.setPromoteLevel(6); + for (int i = 1; i <= 6; ++i) { + avatar.getTalentIdList().add((avatar.getAvatarId() - 10000000) * 10 + i); } // This will handle stats and talents avatar.recalcStats(); player.addAvatar(avatar); } + + //some test items + List genshinItemList = new ArrayList<>(); + for (ItemData itemdata: GenshinData.getItemDataMap().values()) { + //Exclude test item + if (isTestItem(itemdata.getId())) continue; + + if (itemdata.isEquip()) { + for (int i = 0; i < 10; ++i) { + GenshinItem genshinItem = new GenshinItem(itemdata); + if (itemdata.getItemType() == ItemType.ITEM_WEAPON) { + genshinItem.setLevel(90); + genshinItem.setPromoteLevel(6); + genshinItem.setRefinement(4); + } + genshinItemList.add(genshinItem); + } + } + else { + GenshinItem genshinItem = new GenshinItem(itemdata); + genshinItem.setCount(amount); + genshinItemList.add(genshinItem); + } + } + int packetNum = 20; + int itemLength = genshinItemList.size(); + int number = itemLength / packetNum; + int remainder = itemLength % packetNum; + int offset = 0; + for (int i = 0; i < packetNum; ++i) { + if (remainder > 0) { + player.getInventory().addItems(genshinItemList.subList(i * number + offset, (i + 1) * number + offset + 1)); + --remainder; + ++offset; + } + else { + player.getInventory().addItems(genshinItemList.subList(i * number + offset, (i + 1) * number + offset)); + } + } } + 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; + } + } + + if (testItemsList.contains(itemId)) { + return true; + } + + return false; + } + + static class Range { + private int min; + private int max; + + public Range(int min, int max) { + if(min > max){ + min ^= max; + max ^= min; + min ^= max; + } + this.min = min; + this.max = max; + } + + public boolean check(int value) { + return value >= this.min && value <= this.max; + } + } + + private static final Range[] testItemRanges = new Range[] { + new Range(106, 139), + new Range(1000, 1099), + new Range(2001, 2008), + new Range(2017, 2029), + // new Range(108001, 108387) //food + }; + + private static final Integer[] testItemsIds = new Integer[] { + 210, 211, 314, 315, 317, 1005, 1007, 1105, 1107, 1201, 1202, 2800, + 100001, 100002, 100244, 100305, 100312, 100313, 101212, 11411, 11506, 11507, 11508, 12505, + 12506, 12508, 12509, 13503, 13506, 14411, 14503, 14505, 14508, 15411, 15504, 15505, + 15506, 15508, 20001, 10002, 10003, 10004, 10005, 10006, 10008 //9 + }; + + private static final Collection testItemsList = Arrays.asList(testItemsIds); + } +