Beispiel #1
0
  public BaseSWGCommand getCommandByName(String name) {
    Vector<BaseSWGCommand> commands = new Vector<BaseSWGCommand>(commandLookup);

    name = name.toLowerCase();

    for (BaseSWGCommand command : commands) {
      if (command.getCommandName().equalsIgnoreCase(name)) {
        return command;
      }
    }

    try {
      String[] tableArray =
          new String[] {
            "client_command_table",
            "command_table",
            "client_command_table_ground",
            "command_table_ground",
            "client_command_table_space",
            "command_table_space"
          };

      for (int n = 0; n < tableArray.length; n++) {
        DatatableVisitor visitor =
            ClientFileManager.loadFile(
                "datatables/command/" + tableArray[n] + ".iff", DatatableVisitor.class);

        for (int i = 0; i < visitor.getRowCount(); i++) {
          if (visitor.getObject(i, 0) != null) {
            String commandName = ((String) visitor.getObject(i, 0)).toLowerCase();

            if (commandName.equalsIgnoreCase(name)) {
              if (isCombatCommand(commandName)) {
                CombatCommand command = new CombatCommand(commandName);
                commandLookup.add(command);
                return command;
              } else {
                BaseSWGCommand command = new BaseSWGCommand(commandName);
                commandLookup.add(command);
                return command;
              }
            }
          }
        }
      }
    } catch (InstantiationException | IllegalAccessException e) {
      e.printStackTrace();
    }

    return null;
  }
Beispiel #2
0
  public void processCommand(
      CreatureObject actor,
      SWGObject target,
      BaseSWGCommand command,
      int actionCounter,
      String commandArgs) {
    if (command.getCooldown() > 0f) {
      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().toLowerCase() + ".py")) {
        core.scriptService.callScript(
            "scripts/commands/",
            command.getCommandName().toLowerCase(),
            "run",
            core,
            actor,
            target,
            commandArgs);
      } else if (FileUtilities.doesFileExist(
          "scripts/commands/combat/" + command.getCommandName().toLowerCase() + ".py")) {
        core.scriptService.callScript(
            "scripts/commands/combat/",
            command.getCommandName().toLowerCase(),
            "run",
            core,
            actor,
            target,
            commandArgs);
      }
    }
  }
Beispiel #3
0
  public boolean callCommand(
      CreatureObject actor,
      SWGObject target,
      BaseSWGCommand command,
      int actionCounter,
      String commandArgs) {
    if (actor == null) {
      return false;
    }

    if (command == null) {
      return false;
    }

    if (command.getCharacterAbility().length() > 0
        && !actor.hasAbility(command.getCharacterAbility())
        && actor.getClient() != null) {
      return false;
    }

    if (command.isDisabled()) {
      return false;
    }

    if (actor.getClient() != null
        && command.getGodLevel() > actor.getPlayerObject().getGodLevel()) {
      return false;
    }

    if (actor.hasCooldown(command.getCooldownGroup())
        || actor.hasCooldown(command.getCommandName())) {
      return false;
    }

    TangibleObject weapon = (TangibleObject) core.objectService.getObject(actor.getWeaponId());

    if (weapon != null
        && weapon instanceof WeaponObject
        && ((WeaponObject) weapon).getWeaponType() == command.getInvalidWeapon()) {
      return false;
    }

    for (long state : command.getInvalidStates()) {
      if ((actor.getStateBitmask() & state) == state) {
        // return false;
      }
    }

    // This SHOULD be invalid locomotions but we don't track these currently.
    // Postures are the best we can do.
    for (byte posture : command.getInvalidPostures()) {
      if (actor.getPosture() == posture) {
        // return false;
      }
    }

    switch (command.getTargetType()) {
      case 0: // Target Not Used For This Command
        break;
      case 1: // Other Only (objectId/targetName)
        if (target == null) {
          if (commandArgs != null && !commandArgs.equals("")) {
            String name = commandArgs.split(" ")[0];

            target = core.objectService.getObjectByFirstName(name);

            if (target == actor) {
              target = null;
            }
          }

          break;
        }

        if (target == actor) {
          return false;
        }

        if (target.getContainer() == actor || target.getGrandparent() == actor) {
          break;
        }

        if (command.getMaxRangeToTarget() != 0
            && actor.getPosition().getDistance(target.getPosition())
                > command.getMaxRangeToTarget()) {
          return false;
        }

        if (!target.isInQuadtree()
            && (target.getContainer() == null || !(target.getContainer() instanceof CellObject))) {
          break;
        }

        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: // Anyone (objectId/targetName)
        if (target == null) {
          if (commandArgs != null && !commandArgs.equals("")) {
            String name = commandArgs.split(" ")[0];

            target = core.objectService.getObjectByFirstName(name);

            if (target == actor) {
              target = null;
            }

            // It's possible they use c cmdString to indicate if it should always be on self
            if (name.contains("c")) {
              // target = actor;
            }
          }

          break;
        }

        if (target.getContainer() == actor || target.getGrandparent() == actor) {
          break;
        }

        if (command.getMaxRangeToTarget() != 0
            && actor.getPosition().getDistance(target.getPosition())
                > command.getMaxRangeToTarget()) {
          return false;
        }

        if (!target.isInQuadtree()
            && (target.getContainer() == null || !(target.getContainer() instanceof CellObject))) {
          break;
        }

        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 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]);
          } else {
            return false;
          }
        } 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: // Any object
        if (target == null) {
          break;
        }

        if (command.getMaxRangeToTarget() != 0
            && actor.getPosition().getDistance(target.getPosition())
                > command.getMaxRangeToTarget()) {
          return false;
        }

        if (!target.isInQuadtree()
            && (target.getContainer() == null || !(target.getContainer() instanceof CellObject))) {
          break;
        }

        if (!core.simulationService.checkLineOfSight(actor, target)) {
          actor.showFlyText("@combat_effects:cant_see", 1.5f, new RGB(72, 209, 204), 1, true);
          return false;
        }

        break;
      default:
        break;
    }

    switch (command.getTarget()) {
      case 0: // Ally Only
        if (target == null) {
          target = actor;
        }

        if (!(target instanceof TangibleObject)) {
          return false;
        }

        TangibleObject object = (TangibleObject) target;

        if (!object.getFaction().equals("") && !object.getFaction().equals(actor.getFaction())) {
          return false;
        }

        if (actor.getFactionStatus() < object.getFactionStatus()) {
          return false;
        }

        if (object.isAttackableBy(actor)) {
          return false;
        }

        // Without this we could be buffing ally NPCs and such
        // Think this is checked later on
        if (actor.getSlottedObject("ghost") != null && object.getSlottedObject("ghost") == null) {
          return false;
        }

        break;
      case 1: // Enemy Only
        if (target == null || !(target instanceof TangibleObject)) {
          return false;
        }

        TangibleObject targetObject = (TangibleObject) target;

        if (!targetObject.isAttackableBy(actor)) {
          return false;
        }

        break;
      case 2: // Indifferent
        break;
      default:
        break;
    }

    if (command.shouldCallOnTarget()) {
      if (target == null || !(target instanceof CreatureObject)) {
        return false;
      }

      actor = (CreatureObject) target;
    }

    long warmupTime = (long) (command.getWarmupTime() * 1000f);

    if (warmupTime > 0) {
      try {
        Thread.sleep(warmupTime);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    if (command instanceof CombatCommand) {
      try {
        processCommand(actor, target, (BaseSWGCommand) command.clone(), actionCounter, commandArgs);
      } catch (CloneNotSupportedException e) {
        e.printStackTrace();
      }
    } else processCommand(actor, target, command, actionCounter, commandArgs);

    return true;
  }