mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-20 01:29:54 +02:00
Add !character command
This commit is contained in:
@@ -3,6 +3,7 @@ package emu.nebula.command;
|
||||
import java.util.List;
|
||||
|
||||
import emu.nebula.Nebula;
|
||||
import emu.nebula.game.character.GameCharacter;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.util.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
@@ -21,9 +22,9 @@ public class CommandArgs {
|
||||
private int targetUid;
|
||||
private int amount;
|
||||
private int level = -1;
|
||||
private int rank = -1;
|
||||
private int promotion = -1;
|
||||
private int stage = -1;
|
||||
private int advance = -1;
|
||||
private int talent = -1;
|
||||
private int skill = -1;
|
||||
|
||||
private Int2IntMap map;
|
||||
private ObjectSet<String> flags;
|
||||
@@ -50,17 +51,14 @@ public class CommandArgs {
|
||||
} else if (arg.startsWith("lv")) { // Level
|
||||
this.level = Utils.parseSafeInt(arg.substring(2));
|
||||
it.remove();
|
||||
} else if (arg.startsWith("r")) { // Rank
|
||||
this.rank = Utils.parseSafeInt(arg.substring(1));
|
||||
} else if (arg.startsWith("a")) { // Advance
|
||||
this.advance = Utils.parseSafeInt(arg.substring(1));
|
||||
it.remove();
|
||||
} else if (arg.startsWith("e")) { // Eidolons
|
||||
this.rank = Utils.parseSafeInt(arg.substring(1));
|
||||
} else if (arg.startsWith("t")) { // Talents
|
||||
this.talent = Utils.parseSafeInt(arg.substring(1));
|
||||
it.remove();
|
||||
} else if (arg.startsWith("p")) { // Promotion
|
||||
this.promotion = Utils.parseSafeInt(arg.substring(1));
|
||||
it.remove();
|
||||
} else if (arg.startsWith("s")) { // Stage or Superimposition
|
||||
this.stage = Utils.parseSafeInt(arg.substring(1));
|
||||
} else if (arg.startsWith("s")) { // Skill
|
||||
this.skill = Utils.parseSafeInt(arg.substring(1));
|
||||
it.remove();
|
||||
}
|
||||
} else if (arg.startsWith("-")) { // Flag
|
||||
@@ -127,4 +125,67 @@ public class CommandArgs {
|
||||
return this.flags.contains(flag);
|
||||
}
|
||||
|
||||
// Utility commands
|
||||
|
||||
/**
|
||||
* Changes the properties of an character based on the arguments provided
|
||||
* @param character The targeted character to change
|
||||
* @return A boolean of whether or not any changes were made to the character
|
||||
*/
|
||||
public boolean setProperties(GameCharacter character) {
|
||||
boolean hasChanged = false;
|
||||
|
||||
// Try to set level
|
||||
if (this.getLevel() > 0 && character.getLevel() != this.getLevel()) {
|
||||
character.setLevel(Math.min(this.getLevel(), 90));
|
||||
character.setAdvance(Utils.getMinAdvanceForLevel(character.getLevel()));
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
// Try to set advance (ascension level)
|
||||
if (this.getAdvance() >= 0 && character.getAdvance() != this.getAdvance()) {
|
||||
character.setAdvance(Math.min(this.getAdvance(), 8));
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
// Try to set skill trees
|
||||
if (this.getSkill() > 0) {
|
||||
int skill = Math.min(this.getSkill(), 10);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int s = character.getSkills()[i];
|
||||
|
||||
if (s != skill) {
|
||||
character.getSkills()[i] = skill;
|
||||
hasChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try to set talents
|
||||
if (this.getTalent() >= 0) {
|
||||
// Clear talents first
|
||||
character.getTalents().clear();
|
||||
|
||||
// Calculate how many talent stars we want to set
|
||||
int talent = Math.min(this.getTalent(), 5);
|
||||
|
||||
for (int i = 0; i < talent; i++) {
|
||||
// Get bitset offset
|
||||
int offset = i * 16;
|
||||
|
||||
// First 10 sub nodes of a talent star
|
||||
for (int x = 1; x <= 10; x++) {
|
||||
character.getTalents().setBit(offset + x);
|
||||
}
|
||||
|
||||
// Final sub node of a talent star
|
||||
character.getTalents().setBit(offset + 16);
|
||||
}
|
||||
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
return hasChanged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package emu.nebula.command.commands;
|
||||
|
||||
import emu.nebula.util.Utils;
|
||||
import emu.nebula.game.character.GameCharacter;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.PubilcGm.Chars;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import emu.nebula.command.Command;
|
||||
import emu.nebula.command.CommandArgs;
|
||||
import emu.nebula.command.CommandHandler;
|
||||
|
||||
@Command(
|
||||
label = "character",
|
||||
aliases = {"c", "char"},
|
||||
permission = "player.character",
|
||||
requireTarget = true,
|
||||
desc = "!c [all | {characterId}] lv(level) a(ascension) s(skill level) t(talent level)"
|
||||
)
|
||||
public class CharacterCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(CommandArgs args) {
|
||||
// Init
|
||||
var player = args.getTarget();
|
||||
var characters = new HashSet<GameCharacter>();
|
||||
|
||||
// Parse args
|
||||
for (String arg : args.getList()) {
|
||||
// Lowercase
|
||||
arg = arg.toLowerCase();
|
||||
|
||||
// Handle all characters
|
||||
if (arg.equals("all")) {
|
||||
characters.addAll(player.getCharacters().getCharacterCollection());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parse char id
|
||||
int charId = Utils.parseSafeInt(arg);
|
||||
|
||||
var character = player.getCharacters().getCharacterById(charId);
|
||||
if (character == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
characters.add(character);
|
||||
}
|
||||
|
||||
// Sanity check
|
||||
if (characters.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// List of modified characters that we send to the client for updates
|
||||
var modified = new ArrayList<GameCharacter>();
|
||||
|
||||
// Modify characters
|
||||
for (var character : characters) {
|
||||
// Apply changes
|
||||
boolean changed = args.setProperties(character);
|
||||
|
||||
if (changed) {
|
||||
// Save to database
|
||||
character.save();
|
||||
|
||||
// Add to modified list
|
||||
modified.add(character);
|
||||
}
|
||||
}
|
||||
|
||||
if (modified.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
var proto = Chars.newInstance();
|
||||
|
||||
for (var character : modified) {
|
||||
proto.addList(character.toProto());
|
||||
}
|
||||
|
||||
player.addNextPackage(NetMsgId.chars_final_notify, proto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user