mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-09-11 21:45:26 -04:00
Added basis for command service
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package resources.commands;
|
||||
|
||||
public class Command {
|
||||
|
||||
private int crc;
|
||||
|
||||
private String name;
|
||||
// defaultPriority
|
||||
private String scriptCallback;
|
||||
// fail
|
||||
private ICommandCallback javaCallback;
|
||||
// fail
|
||||
private float defaultTime;
|
||||
private String characterAbility;
|
||||
// posture booleans x63
|
||||
// temp script
|
||||
private int target;
|
||||
private int targetType;
|
||||
// string id
|
||||
// visible - unsure what it's used for (stealth maybe?)
|
||||
private boolean callOnTarget;
|
||||
// command group
|
||||
// disabled
|
||||
private int maxRange;
|
||||
private int godLevel;
|
||||
// display group
|
||||
// add to combat queue
|
||||
private int validWeapon;
|
||||
private int invalidWeapon;
|
||||
private String cooldownGroup;
|
||||
private int warmupTime;
|
||||
private int executeTime;
|
||||
private int cooldownTime;
|
||||
private String cooldownGroup2;
|
||||
private int cooldownTime2;
|
||||
// toolbarOnly
|
||||
// fromServerOnly
|
||||
private boolean autoAddToToolbar;
|
||||
|
||||
public Command(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getCrc() { return crc; }
|
||||
public void setCrc(int crc) { this.crc = crc; }
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getScriptCallback() { return scriptCallback; }
|
||||
public void setScriptCallback(String scriptCallback) { this.scriptCallback = scriptCallback; }
|
||||
public ICommandCallback getJavaCallback() { return javaCallback; }
|
||||
public void setJavaCallback(ICommandCallback javaCallback) { this.javaCallback = javaCallback; }
|
||||
public float getDefaultTime() { return defaultTime; }
|
||||
public void setDefaultTime(float defaultTime) { this.defaultTime = defaultTime; }
|
||||
public String getCharacterAbility() { return characterAbility; }
|
||||
public void setCharacterAbility(String characterAbility) { this.characterAbility = characterAbility; }
|
||||
public int getTarget() { return target; }
|
||||
public void setTarget(int target) { this.target = target; }
|
||||
public int getTargetType() { return targetType; }
|
||||
public void setTargetType(int targetType) { this.targetType = targetType; }
|
||||
public boolean isCallOnTarget() { return callOnTarget; }
|
||||
public void setCallOnTarget(boolean callOnTarget) { this.callOnTarget = callOnTarget; }
|
||||
public int getMaxRange() { return maxRange; }
|
||||
public void setMaxRange(int maxRange) { this.maxRange = maxRange; }
|
||||
public int getGodLevel() { return godLevel; }
|
||||
public void setGodLevel(int godLevel) { this.godLevel = godLevel; }
|
||||
public int getValidWeapon() { return validWeapon; }
|
||||
public void setValidWeapon(int validWeapon) { this.validWeapon = validWeapon; }
|
||||
public int getInvalidWeapon() { return invalidWeapon; }
|
||||
public void setInvalidWeapon(int invalidWeapon) { this.invalidWeapon = invalidWeapon; }
|
||||
public String getCooldownGroup() { return cooldownGroup; }
|
||||
public void setCooldownGroup(String cooldownGroup) { this.cooldownGroup = cooldownGroup; }
|
||||
public int getWarmupTime() { return warmupTime; }
|
||||
public void setWarmupTime(int warmupTime) { this.warmupTime = warmupTime; }
|
||||
public int getExecuteTime() { return executeTime; }
|
||||
public void setExecuteTime(int executeTime) { this.executeTime = executeTime; }
|
||||
public int getCooldownTime() { return cooldownTime; }
|
||||
public void setCooldownTime(int cooldownTime) { this.cooldownTime = cooldownTime; }
|
||||
public String getCooldownGroup2() { return cooldownGroup2; }
|
||||
public void setCooldownGroup2(String cooldownGroup2) { this.cooldownGroup2 = cooldownGroup2; }
|
||||
public int getCooldownTime2() { return cooldownTime2; }
|
||||
public void setCooldownTime2(int cooldownTime2) { this.cooldownTime2 = cooldownTime2; }
|
||||
public boolean isAutoAddToToolbar() { return autoAddToToolbar; }
|
||||
public void setAutoAddToToolbar(boolean autoAddToToolbar) { this.autoAddToToolbar = autoAddToToolbar; }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + ":" + crc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package services.commands;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import network.packets.Packet;
|
||||
import network.packets.swg.zone.object_controller.CommandQueueEnqueue;
|
||||
import network.packets.swg.zone.object_controller.ObjectController;
|
||||
import intents.GalacticPacketIntent;
|
||||
import resources.client_info.ClientFactory;
|
||||
import resources.client_info.visitors.DatatableData;
|
||||
import resources.commands.Command;
|
||||
import resources.common.CRC;
|
||||
import resources.control.Intent;
|
||||
import resources.control.Service;
|
||||
import resources.objects.SWGObject;
|
||||
import resources.objects.creature.CreatureObject;
|
||||
import resources.player.Player;
|
||||
import resources.utilities.Scripts;
|
||||
import services.objects.ObjectManager;
|
||||
|
||||
public class CommandService extends Service {
|
||||
|
||||
private Map<Integer, Command> commands; // NOTE: CRC's are all lowercased for commands!
|
||||
private Map<String, Integer> commandCrcLookup;
|
||||
|
||||
public CommandService() { }
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
commands = new ConcurrentHashMap<Integer, Command>();
|
||||
commandCrcLookup = new ConcurrentHashMap<String, Integer>();
|
||||
registerForIntent(GalacticPacketIntent.TYPE);
|
||||
loadBaseCommands();
|
||||
return super.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIntentReceived(Intent i) {
|
||||
if (i instanceof GalacticPacketIntent) {
|
||||
Packet p = ((GalacticPacketIntent) i).getPacket();
|
||||
long netId = ((GalacticPacketIntent) i).getNetworkId();
|
||||
Player player = ((GalacticPacketIntent) i).getPlayerManager().getPlayerFromNetworkId(netId);
|
||||
if (player != null) {
|
||||
if (p instanceof ObjectController) {
|
||||
ObjectController controller = ((ObjectController) p).getController();
|
||||
if (controller == null)
|
||||
return;
|
||||
|
||||
if (controller instanceof CommandQueueEnqueue)
|
||||
handleCommandRequest(player, ((GalacticPacketIntent) i).getObjectManager(), (CommandQueueEnqueue) controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Call Command intent to allow other services/managers to perform a command callback
|
||||
}
|
||||
|
||||
private void handleCommandRequest(Player player, ObjectManager objManager, CommandQueueEnqueue request) {
|
||||
if (!commands.containsKey(request.getCrc()))
|
||||
return;
|
||||
|
||||
SWGObject target = null;
|
||||
if (request.getTargetId() != 0) { target = objManager.getObjectById(request.getTargetId()); }
|
||||
|
||||
executeCommand(objManager, player, commands.get(request.getCrc()), target, request.getArguments());
|
||||
}
|
||||
|
||||
private void executeCommand(ObjectManager objManager, Player player, Command command, SWGObject target, String args) {
|
||||
CreatureObject playerCreo = (CreatureObject) player.getCreatureObject();
|
||||
if (playerCreo == null)
|
||||
return;
|
||||
|
||||
// TODO: Check if the player has the ability
|
||||
|
||||
// TODO: Cool-down checks
|
||||
|
||||
// TODO: Handle for different target
|
||||
|
||||
// TODO: Handle for different targetType
|
||||
|
||||
Scripts.execute("commands/generic/" + command.getScriptCallback(), "execute", objManager, playerCreo, target, args);
|
||||
}
|
||||
|
||||
private void loadBaseCommands() {
|
||||
ClientFactory clientFac = new ClientFactory();
|
||||
|
||||
DatatableData baseCommands = (DatatableData) clientFac.getInfoFromFile("datatables/command/command_table.iff");
|
||||
|
||||
for (int row = 0; row < baseCommands.getRowCount(); row++) {
|
||||
Command command = new Command((String) baseCommands.getCell(row, 0));
|
||||
command.setCrc(CRC.getCrc(command.getName().toLowerCase()));
|
||||
// Use cppHook if the scriptHook is empty
|
||||
command.setScriptCallback(((String) (((String) baseCommands.getCell(row, 2)).isEmpty() ? baseCommands.getCell(row, 4) : baseCommands.getCell(row, 2))) + ".py");
|
||||
command.setDefaultTime((float) baseCommands.getCell(row, 6));
|
||||
command.setCharacterAbility((String) baseCommands.getCell(row, 7));
|
||||
|
||||
commands.put(command.getCrc(), command);
|
||||
commandCrcLookup.put(command.getName(), command.getCrc());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,18 @@ package services.galaxy;
|
||||
|
||||
import resources.control.Manager;
|
||||
import services.chat.ChatService;
|
||||
import services.commands.CommandService;
|
||||
|
||||
public class GameManager extends Manager {
|
||||
|
||||
private ChatService chatService;
|
||||
private CommandService commandService;
|
||||
|
||||
public GameManager() {
|
||||
chatService = new ChatService();
|
||||
commandService = new CommandService();
|
||||
|
||||
addChildService(chatService);
|
||||
addChildService(commandService);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -258,4 +258,8 @@ public class ObjectManager extends Manager {
|
||||
private WeaponObject createWeaponObject(long objectId, String template) {
|
||||
return new WeaponObject(objectId);
|
||||
}
|
||||
|
||||
public SWGObject getObjectById(long id) {
|
||||
return objects.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user