Added command to set a trekker's emblem stats

Usage:
`!e [character id] [slot id - this is between 1 and 3] [attr 1] [attr 2] [attr 3] [attr 4]`

Example:
`!e 141 1 1004 1004 1004 1004` = Sets the first emblem of the character to all +ignis damage.

Notes:
Attribute ids can be found in `CharGemAttrValue.json` in the resources/bin folder.
This commit is contained in:
Melledy
2025-12-19 01:18:37 -08:00
parent 496d012c36
commit 495e76a456
4 changed files with 115 additions and 1 deletions

View File

@@ -0,0 +1,104 @@
package emu.nebula.command.commands;
import emu.nebula.util.Utils;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import emu.nebula.game.character.CharacterGem;
import emu.nebula.game.character.GameCharacter;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.PubilcGm.Chars;
import emu.nebula.command.Command;
import emu.nebula.command.CommandArgs;
import emu.nebula.command.CommandHandler;
import emu.nebula.data.GameData;
@Command(
label = "emblem",
aliases = {"e", "gem"},
permission = "player.emblem",
requireTarget = true,
desc = "!emblem [characterId] [emblem slot] [attribute value ids....]"
)
public class EmblemCommand implements CommandHandler {
@Override
public String execute(CommandArgs args) {
// Init
var player = args.getTarget();
// Sanity check
if (args.getList().size() < 6) {
return "Error: Not enough args";
}
// Parse args
var charId = Utils.parseSafeInt(args.getList().get(0));
var slotId = Utils.parseSafeInt(args.getList().get(1));
var attributes = new IntArrayList();
for (int i = 2; i < 6; i++) {
int attr = Utils.parseSafeInt(args.getList().get(i));
var data = GameData.getCharGemAttrValueDataTable().get(attr);
if (data == null) {
return "Error: Invalid attribute value id in position " + (i - 2);
}
attributes.add(attr);
}
// Get character
GameCharacter character = player.getCharacters().getCharacterById(charId);
if (character == null) {
return "Error: No trekker selected";
}
// Get gem slot
var slot = character.getGemSlot(slotId);
if (slot == null) {
return "Error: Invalid slot selected";
}
// Get gem
var preset = character.getCurrentGemPreset();
var gem = slot.getGem(preset.getGemIndex(slotId));
if (gem == null) {
if (slot.isFull()) {
// Equip the first gem we can find
preset.setGemIndex(slotId, 0);
gem = slot.getGem(preset.getGemIndex(slotId));
} else {
// Create a new gem and equip it
gem = new CharacterGem(attributes);
// Add gem to slot
slot.getGems().add(gem);
// Equip
preset.setGemIndex(slotId, slot.getGems().size() - 1);
}
// Make sure gem exists
if (gem == null) {
return "An unknown error has occured";
}
}
// Replace gem
gem.setAttributes(attributes);
// Save
character.save();
// Encode and send
var proto = Chars.newInstance()
.addList(character.toProto());
player.addNextPackage(NetMsgId.chars_final_notify, proto);
// Result
return "Updated emblem for character";
}
}

View File

@@ -25,6 +25,10 @@ public class CharacterGem {
public void setLocked(boolean locked) {
this.locked = locked;
}
public void setAttributes(IntList attributes) {
this.attributes = attributes.toIntArray();
}
public void setNewAttributes(IntList attributes) {
this.alterAttributes = attributes.toIntArray();

View File

@@ -27,7 +27,9 @@ public class CharacterGemPreset {
return this.getGems().length;
}
public int getGemIndex(int slotIndex) {
public int getGemIndex(int slotId) {
int slotIndex = slotId - 1;
if (slotIndex < 0 || slotIndex >= this.getLength()) {
return -1;
}

View File

@@ -36,6 +36,10 @@ public class CharacterGemSlot {
return getGems().size() >= GameConstants.CHARACTER_MAX_GEMS_PER_SLOT;
}
public boolean isEmpty() {
return getGems().size() <= 0;
}
// Proto
public CharGemSlot toProto() {