Implement !giveall command

-Also fixed server error when receiving characters
This commit is contained in:
Melledy
2025-11-17 08:57:25 -08:00
parent 5f851a0367
commit b97f23aa3c
4 changed files with 131 additions and 0 deletions

View File

@@ -0,0 +1,124 @@
package emu.nebula.command.commands;
import java.util.Set;
import emu.nebula.GameConstants;
import emu.nebula.command.Command;
import emu.nebula.command.CommandArgs;
import emu.nebula.command.CommandHandler;
import emu.nebula.data.GameData;
import emu.nebula.data.resources.ItemDef;
import emu.nebula.game.inventory.ItemParamMap;
import emu.nebula.game.inventory.ItemSubType;
import emu.nebula.game.player.Player;
import emu.nebula.game.player.PlayerChangeInfo;
import emu.nebula.net.NetMsgId;
@Command(
label = "giveall",
aliases = {"ga"},
permission = "player.give",
requireTarget = true,
desc = "!ga [characters | discs | materials]. Gives the targeted player items."
)
public class GiveAllCommand implements CommandHandler {
private static Set<ItemSubType> MATERIAL_ITEM_SUBTYPES = Set.of(
ItemSubType.DiscStrengthen, // Disc exp
ItemSubType.DiscPromote, // Disc tier up
ItemSubType.SkillStrengthen, // Skill upgrade
ItemSubType.CharacterLimitBreak, // Character tier up
ItemSubType.Equipment // Emblem crafting
);
@Override
public void execute(CommandArgs args) {
Player target = args.getTarget();
String type = args.get(0).toLowerCase();
var items = new ItemParamMap();
var change = new PlayerChangeInfo();
switch (type) {
default -> args.sendMessage("Error: Invalid type");
case "m", "materials", "mats" -> {
// Check sub type
for (ItemDef data : GameData.getItemDataTable()) {
if (!MATERIAL_ITEM_SUBTYPES.contains(data.getItemSubType())) {
continue;
}
items.add(data.getId(), 10_000);
}
// Character exp, not sure why this doesnt have an unique sub type so we have to hard code it
items.add(30001, 10_000);
items.add(30002, 10_000);
items.add(30003, 10_000);
items.add(30004, 10_000);
// Gold
items.add(GameConstants.GOLD_ITEM_ID, 50_000_000);
// Add to target's inventory
target.getInventory().addItems(items, change);
// Send message
args.sendMessage("Giving " + target.getName() + " " + items.size() + " items");
}
case "d", "discs" -> {
// Get all discs
for (var data : GameData.getDiscDataTable()) {
// Skip unavailable discs
if (!data.isAvailable() || !data.isVisible()) {
continue;
}
// Check if we have the disc already
if (target.getCharacters().hasDisc(data.getId())) {
continue;
}
// Add
items.add(data.getId(), 1);
}
// Add to target's inventory
target.getInventory().addItems(items, change);
// Send message
args.sendMessage("Giving " + target.getName() + " all discs");
}
case "c", "characters", "trekkers", "t" -> {
// Get all characters
for (var data : GameData.getCharacterDataTable()) {
// Skip unavailable characters
if (!data.isAvailable() || !data.isVisible()) {
continue;
}
// Check if we have the character already
if (target.getCharacters().hasCharacter(data.getId())) {
continue;
}
// Add
items.add(data.getId(), 1);
}
// Add to target's inventory
target.getInventory().addItems(items, change);
// Send message
args.sendMessage("Giving " + target.getName() + " all characters");
}
}
if (change.isEmpty()) {
return;
}
// Encode and send
target.addNextPackage(NetMsgId.items_change_notify, change.toProto());
}
}

View File

@@ -12,6 +12,8 @@ import lombok.Getter;
@ResourceType(name = "Character.json")
public class CharacterDef extends BaseDef {
private int Id;
private boolean Visible;
private boolean Available;
private String Name;
private int Grade;

View File

@@ -8,6 +8,9 @@ import lombok.Getter;
@ResourceType(name = "Disc.json")
public class DiscDef extends BaseDef {
private int Id;
private boolean Visible;
private boolean Available;
private int StrengthenGroupId;
private int PromoteGroupId;
private int TransformItemId;

View File

@@ -83,6 +83,8 @@ public class GameCharacter implements GameDatabaseObject {
this.skin = data.getDefaultSkinId();
this.skills = new int[] {1, 1, 1, 1, 1};
this.talents = new Bitset();
this.gemPresets = new ArrayList<>();
this.gemSlots = new CharacterGemSlot[GameConstants.CHARACTER_MAX_GEM_SLOTS];
this.createTime = Nebula.getCurrentTime();
this.contact = new CharacterContact(this);