Improve give command

This commit is contained in:
Melledy
2023-10-30 11:58:43 -07:00
parent dd9b126e9e
commit 9db09cd451
3 changed files with 44 additions and 4 deletions

View File

@@ -46,7 +46,7 @@ public class ClearCommand implements CommandHandler {
}
}
}
case "items" -> {
case "items", "all" -> {
for (GameItem item : args.getTarget().getInventory().getItems().values()) {
if (!item.isLocked() && !item.isEquipped()) {
toRemove.add(item);

View File

@@ -8,7 +8,9 @@ import emu.lunarcore.command.CommandArgs;
import emu.lunarcore.command.CommandHandler;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.excel.ItemExcel;
import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.game.inventory.ItemMainType;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.util.Utils;
@@ -36,9 +38,47 @@ public class GiveCommand implements CommandHandler {
// Setup items
List<GameItem> items = new LinkedList<>();
if (itemData.isEquippable()) {
if (itemData.getItemMainType() == ItemMainType.AvatarCard) {
// Add avatar
GameAvatar avatar = new GameAvatar(itemData.getId());
if (args.getTarget().addAvatar(avatar)) {
// Try to set level
if (args.getLevel() > 0) {
avatar.setLevel(Math.min(args.getLevel(), 80));
}
// Try to set promotion
if (args.getPromotion() >= 0) {
avatar.setPromotion(Math.min(args.getPromotion(), avatar.getExcel().getMaxPromotion()));
}
// Try to set rank
if (args.getRank() >= 0) {
avatar.setRank(Math.min(args.getRank(), avatar.getExcel().getMaxRank()));
}
}
} else if (itemData.isEquippable()) {
for (int i = 0; i < amount; i++) {
items.add(new GameItem(itemData));
GameItem item = new GameItem(itemData);
if (item.getExcel().isEquipment()) {
// Try to set level
if (args.getLevel() > 0) {
item.setLevel(Math.min(args.getLevel(), 80));
}
// Try to set promotion
if (args.getPromotion() >= 0) {
item.setPromotion(Math.min(args.getPromotion(), item.getExcel().getEquipmentExcel().getMaxPromotion()));
}
// Try to set rank (superimposition)
if (args.getRank() >= 0) {
item.setRank(Math.min(args.getRank(), item.getExcel().getEquipmentExcel().getMaxRank()));
}
}
items.add(item);
}
} else {
items.add(new GameItem(itemData, amount));

View File

@@ -117,7 +117,7 @@ public class Inventory extends BasePlayerManager {
public List<GameItem> addItems(Collection<GameItem> items, boolean showHint) {
// Init results
List<GameItem> results = new ArrayList<GameItem>(items.size());
List<GameItem> results = new ArrayList<>(items.size());
// Sanity
if (items.size() == 0) {