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-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-24 21:52:50 +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 {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute(GenshinPlayer sender, List<String> args) {
|
|
|
|
int target,amount=99999;
|
|
|
|
|
|
|
|
switch (args.size()) {
|
2022-04-24 22:42:44 +08:00
|
|
|
default: // giveall *no args*
|
2022-04-24 21:52:50 +08:00
|
|
|
try {
|
|
|
|
target = sender.getUid();
|
|
|
|
}catch (NullPointerException ignored){
|
|
|
|
CommandHandler.sendMessage(sender, "Player not found.");
|
|
|
|
return;
|
|
|
|
}
|
2022-04-24 14:01:03 +08:00
|
|
|
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){
|
2022-04-24 22:42:44 +08:00
|
|
|
CommandHandler.sendMessage(sender, "Invalid amount or player ID.");
|
2022-04-24 14:01:03 +08:00
|
|
|
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);
|
2022-04-24 21:52:50 +08:00
|
|
|
CommandHandler.sendMessage(sender, "Done! or Getting all items done");
|
2022-04-24 14:01:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void GetAllItem(GenshinPlayer player, int amount){
|
2022-04-24 21:52:50 +08:00
|
|
|
CommandHandler.sendMessage(player, "Getting all items…");
|
|
|
|
|
|
|
|
Collection<GenshinItem> genshinItemList =new LinkedList<>();
|
2022-04-24 14:01:03 +08:00
|
|
|
for (ItemData itemdata: GenshinData.getItemDataMap().values()) {
|
2022-04-24 22:42:44 +08:00
|
|
|
if(itemdata.getId() > 1000 && itemdata.getId() <= 1099)continue;//is avatar
|
2022-04-24 14:01:03 +08:00
|
|
|
if (itemdata.isEquip()) {
|
|
|
|
for (int i = 0; i < 20; i++) {
|
2022-04-24 21:52:50 +08:00
|
|
|
genshinItemList.add(new GenshinItem(itemdata));
|
2022-04-24 14:01:03 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
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-24 21:52:50 +08:00
|
|
|
player.getInventory().addItems(genshinItemList);
|
|
|
|
|
2022-04-24 22:42:44 +08:00
|
|
|
for(AvatarData avatarData:GenshinData.getAvatarDataMap().values())
|
|
|
|
{
|
|
|
|
int ascension;
|
|
|
|
int level = 90;
|
2022-04-24 14:01:03 +08:00
|
|
|
// Calculate ascension level.
|
2022-04-24 22:42:44 +08:00
|
|
|
if (level <= 40) {
|
|
|
|
ascension = (int) Math.ceil(90 / 20f);
|
|
|
|
} else {
|
|
|
|
ascension = (int) Math.ceil(90 / 10f) - 3;
|
|
|
|
}
|
|
|
|
|
2022-04-24 14:01:03 +08:00
|
|
|
GenshinAvatar avatar = new GenshinAvatar(avatarData);
|
2022-04-24 22:42:44 +08:00
|
|
|
avatar.setLevel(level);
|
2022-04-24 14:01:03 +08:00
|
|
|
avatar.setPromoteLevel(ascension);
|
|
|
|
for (int i = 1;i<=6;i++){
|
2022-04-24 22:42:44 +08:00
|
|
|
avatar.getTalentIdList().add((avatar.getAvatarId()-10000000)*10+i);//(10000058-10000000)*10+i
|
2022-04-24 14:01:03 +08:00
|
|
|
}
|
|
|
|
// This will handle stats and talents
|
|
|
|
avatar.recalcStats();
|
|
|
|
player.addAvatar(avatar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|