2022-04-24 14:01:03 +08:00
|
|
|
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;
|
2022-04-25 15:17:55 +08:00
|
|
|
import emu.grasscutter.game.inventory.ItemType;
|
2022-04-24 14:01:03 +08:00
|
|
|
|
2022-04-24 21:52:50 +08:00
|
|
|
import java.util.*;
|
2022-04-24 14:01:03 +08:00
|
|
|
|
|
|
|
@Command(label = "giveall", usage = "giveall [player] <amount>",
|
2022-04-26 16:35:06 +08:00
|
|
|
description = "Gives all items", aliases = {"givea"}, permission = "player.giveall", threading = true)
|
2022-04-24 14:01:03 +08:00
|
|
|
public class GiveAllCommand implements CommandHandler {
|
2022-04-26 16:35:06 +08:00
|
|
|
|
2022-04-24 14:01:03 +08:00
|
|
|
@Override
|
|
|
|
public void execute(GenshinPlayer sender, List<String> args) {
|
2022-04-26 16:35:06 +08:00
|
|
|
int target, amount = 99999;
|
2022-04-24 14:01:03 +08:00
|
|
|
|
|
|
|
switch (args.size()) {
|
2022-04-26 16:35:06 +08:00
|
|
|
case 0: // *no args*
|
|
|
|
if (sender == null) {
|
|
|
|
CommandHandler.sendMessage(null, "This usage can only be run in-game");
|
|
|
|
return;
|
|
|
|
}
|
2022-04-25 15:17:55 +08:00
|
|
|
target = sender.getUid();
|
2022-04-24 14:01:03 +08:00
|
|
|
break;
|
2022-04-26 16:35:06 +08:00
|
|
|
|
2022-04-24 22:49:33 +08:00
|
|
|
case 1: // [player]
|
2022-04-24 14:01:03 +08:00
|
|
|
try {
|
|
|
|
target = Integer.parseInt(args.get(0));
|
|
|
|
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
|
|
|
|
CommandHandler.sendMessage(sender, "Invalid player ID.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}catch (NumberFormatException ignored){
|
2022-04-24 22:49:33 +08:00
|
|
|
CommandHandler.sendMessage(sender, "Invalid player ID.");
|
2022-04-24 14:01:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2022-04-26 16:35:06 +08:00
|
|
|
|
2022-04-24 22:49:33 +08:00
|
|
|
case 2: // [player] [amount]
|
2022-04-24 14:01:03 +08:00
|
|
|
try {
|
|
|
|
target = Integer.parseInt(args.get(0));
|
2022-04-25 15:17:55 +08:00
|
|
|
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
|
2022-04-24 14:01:03 +08:00
|
|
|
target = sender.getUid();
|
|
|
|
amount = Integer.parseInt(args.get(0));
|
|
|
|
} else {
|
|
|
|
amount = Integer.parseInt(args.get(1));
|
|
|
|
}
|
2022-04-26 16:35:06 +08:00
|
|
|
} catch (NumberFormatException ignored) {
|
2022-04-24 14:01:03 +08:00
|
|
|
CommandHandler.sendMessage(sender, "Invalid amount or player ID.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2022-04-26 16:35:06 +08:00
|
|
|
|
|
|
|
default: // invalid
|
|
|
|
CommandHandler.sendMessage(null, "Usage: giveall [player] <amount>");
|
|
|
|
return;
|
2022-04-24 14:01:03 +08:00
|
|
|
}
|
|
|
|
|
2022-04-25 15:17:55 +08:00
|
|
|
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
2022-04-24 14:01:03 +08:00
|
|
|
if (targetPlayer == null) {
|
|
|
|
CommandHandler.sendMessage(sender, "Player not found.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-26 16:35:06 +08:00
|
|
|
this.giveAllItems(targetPlayer, amount);
|
|
|
|
CommandHandler.sendMessage(sender, "Giving all items done");
|
2022-04-24 14:01:03 +08:00
|
|
|
}
|
|
|
|
|
2022-04-26 16:35:06 +08:00
|
|
|
public void giveAllItems(GenshinPlayer player, int amount) {
|
|
|
|
CommandHandler.sendMessage(player, "Giving all items...");
|
|
|
|
|
|
|
|
for (AvatarData avatarData: GenshinData.getAvatarDataMap().values()) {
|
|
|
|
//Exclude test avatar
|
|
|
|
if (isTestAvatar(avatarData.getId())) continue;
|
|
|
|
|
|
|
|
GenshinAvatar avatar = new GenshinAvatar(avatarData);
|
|
|
|
avatar.setLevel(90);
|
|
|
|
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);
|
|
|
|
}
|
2022-04-24 21:52:50 +08:00
|
|
|
|
2022-04-26 16:35:06 +08:00
|
|
|
//some test items
|
|
|
|
List<GenshinItem> genshinItemList = new ArrayList<>();
|
2022-04-24 14:01:03 +08:00
|
|
|
for (ItemData itemdata: GenshinData.getItemDataMap().values()) {
|
2022-04-26 16:35:06 +08:00
|
|
|
//Exclude test item
|
|
|
|
if (isTestItem(itemdata.getId())) continue;
|
|
|
|
|
2022-04-24 14:01:03 +08:00
|
|
|
if (itemdata.isEquip()) {
|
2022-04-26 16:35:06 +08:00
|
|
|
for (int i = 0; i < 10; ++i) {
|
2022-04-25 15:17:55 +08:00
|
|
|
GenshinItem genshinItem = new GenshinItem(itemdata);
|
2022-04-26 16:35:06 +08:00
|
|
|
if (itemdata.getItemType() == ItemType.ITEM_WEAPON) {
|
2022-04-25 15:17:55 +08:00
|
|
|
genshinItem.setLevel(90);
|
|
|
|
genshinItem.setPromoteLevel(6);
|
2022-04-26 16:35:06 +08:00
|
|
|
genshinItem.setRefinement(4);
|
2022-04-25 15:17:55 +08:00
|
|
|
}
|
|
|
|
genshinItemList.add(genshinItem);
|
2022-04-24 14:01:03 +08:00
|
|
|
}
|
2022-04-26 16:35:06 +08:00
|
|
|
}
|
|
|
|
else {
|
2022-04-24 14:01:03 +08:00
|
|
|
GenshinItem genshinItem = new GenshinItem(itemdata);
|
|
|
|
genshinItem.setCount(amount);
|
2022-04-24 21:52:50 +08:00
|
|
|
genshinItemList.add(genshinItem);
|
2022-04-24 14:01:03 +08:00
|
|
|
}
|
|
|
|
}
|
2022-04-26 16:35:06 +08:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-24 21:52:50 +08:00
|
|
|
|
2022-04-26 16:35:06 +08:00
|
|
|
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;
|
2022-04-24 14:01:03 +08:00
|
|
|
}
|
2022-04-26 16:35:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2022-04-24 14:01:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-26 16:35:06 +08:00
|
|
|
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<Integer> testItemsList = Arrays.asList(testItemsIds);
|
|
|
|
|
2022-04-24 14:01:03 +08:00
|
|
|
}
|
2022-04-26 16:35:06 +08:00
|
|
|
|