Command fixes, command removing

This commit is contained in:
Treeku
2014-04-13 00:29:30 +01:00
parent eeb1ea54af
commit 03c5201cf4
3 changed files with 121 additions and 26 deletions
+76 -13
View File
@@ -45,7 +45,6 @@ import resources.common.*;
import protocol.swg.ObjControllerMessage;
import protocol.swg.objectControllerObjects.CommandEnqueue;
import protocol.swg.objectControllerObjects.CommandEnqueueRemove;
import protocol.swg.objectControllerObjects.ShowFlyText;
import protocol.swg.objectControllerObjects.StartTask;
import resources.objects.creature.CreatureObject;
import resources.objects.tangible.TangibleObject;
@@ -114,8 +113,18 @@ public class CommandService implements INetworkDispatch {
switch (command.getTargetType()) {
case 0: // Target Not Used For This Command
break;
case 1: // Other Only
if (target == null || target == actor) {
case 1: // Other Only (objectId/targetName)
if (target == null) {
if (commandArgs != null && !commandArgs.equals("")) {
String name = commandArgs.split(" ")[0];
target = core.objectService.getObjectByFirstName(name);
}
break;
}
if (target == actor) {
return false;
}
@@ -128,16 +137,32 @@ public class CommandService implements INetworkDispatch {
}
if (!core.simulationService.checkLineOfSight(actor, target)) {
actor.showFlyText("@combat_effects:cant_see", 1.5f, new RGB(72, 209, 204), 1, true);
return false;
}
break;
case 2: // Self Only
case 2: // Anyone (objectId/targetName)
if (target == null) {
target = actor;
if (commandArgs != null && !commandArgs.equals("")) {
String name = commandArgs.split(" ")[0];
target = core.objectService.getObjectByFirstName(name);
}
break;
}
if (target != actor) {
if (target.getContainer() == actor || target.getGrandparent() == actor) {
break;
}
if (command.getMaxRangeToTarget() != 0 && actor.getPosition().getDistance(target.getPosition()) > command.getMaxRangeToTarget()) {
return false;
}
if (!core.simulationService.checkLineOfSight(actor, target)) {
actor.showFlyText("@combat_effects:cant_see", 1.5f, new RGB(72, 209, 204), 1, true);
return false;
}
@@ -145,13 +170,45 @@ public class CommandService implements INetworkDispatch {
case 3: // Free Target Mode (rally points, group waypoints)
target = null;
if (commandArgs == null) {
break;
}
String[] args = commandArgs.split(" ");
float x = 0, y = 0, z = 0;
try {
if (args.length == 2) {
x = Integer.valueOf(args[0]);
z = Integer.valueOf(args[1]);
} else if (args.length > 2) {
x = Integer.valueOf(args[0]);
y = Integer.valueOf(args[1]);
z = Integer.valueOf(args[2]);
}
} catch (NumberFormatException e) {
return false;
}
Point3D position = new Point3D(x, y, z);
if (command.getMaxRangeToTarget() != 0 && actor.getPosition().getDistance(position) > command.getMaxRangeToTarget()) {
return false;
}
break;
case 4: // Anyone
case 4: // Any object
if (target == null) {
target = actor;
break;
}
if (command.getMaxRangeToTarget() != 0 && actor.getPosition().getDistance(target.getPosition()) > command.getMaxRangeToTarget()) {
return false;
}
if (!core.simulationService.checkLineOfSight(actor, target)) {
actor.showFlyText("@combat_effects:cant_see", 1.5f, new RGB(72, 209, 204), 1, true);
return false;
}
@@ -428,12 +485,8 @@ public class CommandService implements INetworkDispatch {
if(target != attacker && success && !core.simulationService.checkLineOfSight(attacker, target)) {
ShowFlyText los = new ShowFlyText(attacker.getObjectID(), attacker.getObjectID(), "combat_effects", "cant_see", (float) 1.5, new RGB(72, 209, 204), 1);
ObjControllerMessage objController = new ObjControllerMessage(0x1B, los);
attacker.getClient().getSession().write(objController.serialize());
attacker.showFlyText("@combat_effects:cant_see", 1.5f, new RGB(72, 209, 204), 1, true);
success = false;
}
if(!success && attacker.getClient() != null) {
@@ -466,6 +519,15 @@ public class CommandService implements INetworkDispatch {
}
public void removeCommand(CreatureObject actor, int actionCounter, BaseSWGCommand command) {
if (actor == null || actor.getClient() == null || command == null) {
return;
}
actor.getClient().getSession().write(new ObjControllerMessage(0x0B, new CommandEnqueueRemove(actor.getObjectId(), actionCounter)).serialize());
actor.removeCooldown(actionCounter, command);
}
@Override
public void insertOpcodes(Map<Integer, INetworkRemoteEvent> swgOpcodes, Map<Integer, INetworkRemoteEvent> objControllerOpcodes) {
@@ -508,6 +570,7 @@ public class CommandService implements INetworkDispatch {
if (!callCommand(actor, target, command, commandEnqueue.getActionCounter(), commandEnqueue.getCommandArguments())) {
// Call failScriptHook
removeCommand(actor, commandEnqueue.getActionCounter(), command);
}
}