Various command bugfixes

This commit is contained in:
Treeku
2014-04-10 10:18:20 +01:00
parent 68d5acb687
commit 351910c04a
5 changed files with 217 additions and 271 deletions
+29 -64
View File
@@ -27,7 +27,6 @@ import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import main.NGECore;
@@ -43,7 +42,6 @@ import engine.resources.scene.Point3D;
import engine.resources.service.INetworkDispatch;
import engine.resources.service.INetworkRemoteEvent;
import resources.common.*;
import resources.datatables.StateStatus;
import protocol.swg.ObjControllerMessage;
import protocol.swg.objectControllerObjects.CommandEnqueue;
import protocol.swg.objectControllerObjects.CommandEnqueueRemove;
@@ -56,6 +54,7 @@ import resources.objects.weapon.WeaponObject;
public class CommandService implements INetworkDispatch {
private Vector<BaseSWGCommand> commandLookup = new Vector<BaseSWGCommand>();
private ConcurrentHashMap<Integer, Integer> aliases = new ConcurrentHashMap<Integer, Integer>();
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private NGECore core;
@@ -63,6 +62,10 @@ public class CommandService implements INetworkDispatch {
this.core = core;
}
public void registerAlias(String name, String target) {
aliases.put(CRC.StringtoCRC(name.toLowerCase()), CRC.StringtoCRC(target.toLowerCase()));
}
public boolean callCommand(CreatureObject actor, SWGObject target, BaseSWGCommand command, int actionCounter, String commandArgs) {
if (actor == null) {
return false;
@@ -109,9 +112,7 @@ public class CommandService implements INetworkDispatch {
}
switch (command.getTargetType()) {
case 0: // Target Not Used For This Command or Self
target = actor;
case 0: // Target Not Used For This Command
break;
case 1: // Other Only
if (target == null || target == actor) {
@@ -208,26 +209,21 @@ public class CommandService implements INetworkDispatch {
}
long warmupTime = (long) (command.getWarmupTime() * 1000F);
final CreatureObject actorObject = actor;
final SWGObject targetObject = target;
if (warmupTime != 0) {
scheduler.schedule(new Runnable() {
@Override
public void run() {
processCommand(actorObject, targetObject, command, actionCounter, commandArgs);
}
}, warmupTime, TimeUnit.MILLISECONDS);
} else {
processCommand(actor, target, command, actionCounter, commandArgs);
try {
Thread.sleep(warmupTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
processCommand(actor, target, command, actionCounter, commandArgs);
return true;
}
public void callCommand(SWGObject actor, String commandName, SWGObject target, String commandArgs) {
System.out.println("CommandService: void callCommand(actor, commandName, target, commandArgs): This shouldn't be called anymore.");
if (actor == null)
return;
@@ -284,15 +280,7 @@ public class CommandService implements INetworkDispatch {
sub += 5;
}
boolean isCombatCommand = false;
System.out.println(((String) visitor.getObject(i, 85-sub)));
if(((String) visitor.getObject(i, 3)).equals("failSpecialAttack") || ((String) visitor.getObject(i, 85-sub)).equals("defaultattack"))
isCombatCommand = true;
if (hasCharacterAbility || isCombatCommand) {
if (hasCharacterAbility) {
CombatCommand command = new CombatCommand(name.toLowerCase());
commandLookup.add(command);
return command;
@@ -348,13 +336,7 @@ public class CommandService implements INetworkDispatch {
sub += 5;
}
boolean isCombatCommand = false;
if(((String) visitor.getObject(i, 3)).equals("failSpecialAttack") || ((String) visitor.getObject(i, 85-sub)).equals("defaultattack"))
isCombatCommand = true;
// "isCombatCommand" needs to be changed so that non-combat commands that are flagged to added to a combat queue are not considered combat commands
if (hasCharacterAbility || isCombatCommand) {
if (hasCharacterAbility) {
CombatCommand command = new CombatCommand(commandName);
commandLookup.add(command);
return command;
@@ -376,25 +358,21 @@ public class CommandService implements INetworkDispatch {
public void processCommand(CreatureObject actor, SWGObject target, BaseSWGCommand command, int actionCounter, String commandArgs) {
actor.addCooldown(command.getCooldownGroup(), command.getCooldown());
if (command instanceof CombatCommand) {
processCombatCommand(actor, target, (CombatCommand) command, actionCounter, commandArgs);
} else {
if (FileUtilities.doesFileExist("scripts/commands/" + command.getCommandName() + ".py")) {
core.scriptService.callScript("scripts/commands/", command.getCommandName(), "run", core, actor, target, commandArgs);
}
if (FileUtilities.doesFileExist("scripts/commands/combat/" + command.getCommandName() + ".py")) {
core.scriptService.callScript("scripts/commands/combat/", command.getCommandName(), "run", core, actor, target, commandArgs);
}
}
}
public void processCombatCommand(CreatureObject attacker, SWGObject target, CombatCommand command, int actionCounter, String commandArgs) {
// Check if the person has access to this ability.
// Abilities (inc expertise ones) are added automatically as they level
// by reading the datatables.
// disabled for now (breaks all combat)
//if (!attacker.hasAbility(command.getCommandName())) {
// return;
//}
if(FileUtilities.doesFileExist("scripts/commands/combat/" + command.getCommandName() + ".py"))
{
core.scriptService.callScript("scripts/commands/combat/", command.getCommandName(), "setup", core, attacker, target, command);
@@ -502,7 +480,6 @@ public class CommandService implements INetworkDispatch {
@Override
public void handlePacket(IoSession session, IoBuffer data) throws Exception {
data.order(ByteOrder.LITTLE_ENDIAN);
Client client = core.getClient(session);
@@ -514,7 +491,13 @@ public class CommandService implements INetworkDispatch {
CommandEnqueue commandEnqueue = new CommandEnqueue();
commandEnqueue.deserialize(data);
BaseSWGCommand command = getCommandByCRC(commandEnqueue.getCommandCRC());
int commandCRC = commandEnqueue.getCommandCRC();
if (aliases.containsKey(commandEnqueue.getCommandCRC())) {
commandCRC = aliases.get(commandCRC);
}
BaseSWGCommand command = getCommandByCRC(commandCRC);
if (command == null) {
//System.out.println("Unknown Command CRC: " + commandEnqueue.getCommandCRC());
@@ -553,26 +536,8 @@ public class CommandService implements INetworkDispatch {
}
public CombatCommand registerCombatCommand(String name) {
BaseSWGCommand command = getCommandByName(name);
if (command == null) {
return null;
}
if (command instanceof CombatCommand) {
return (CombatCommand) command;
} else {
System.out.println("Warning: Forced to make non-combat command " + name + " a combat command.");
commandLookup.remove(command);
CombatCommand combatCommand = new CombatCommand(name.toLowerCase());
commandLookup.add(combatCommand);
return combatCommand;
}
}
public BaseSWGCommand registerCombatCommand(String name) { return getCommandByName(name); }
public BaseSWGCommand registerCommand(String name) { return getCommandByName(name); }
public BaseSWGCommand registerGmCommand(String name) { return getCommandByName(name); }
public void registerAlias(String name, String target) { }
}