public void equip(CreatureObject actor, SWGObject item) {
    String template =
        ((item.getAttachment("customServerTemplate") == null)
            ? item.getTemplate()
            : (item.getTemplate().split("shared_")[0]
                + "shared_"
                + ((String) item.getAttachment("customServerTemplate"))
                + ".iff"));
    String serverTemplate = template.replace(".iff", "");

    PyObject func =
        core.scriptService.getMethod(
            "scripts/" + serverTemplate.split("shared_", 2)[0].replace("shared_", ""),
            serverTemplate.split("shared_", 2)[1],
            "equip");
    if (func != null) func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item));

    // TODO: bio-link (assign it by objectID with setAttachment and then just display the customName
    // for that objectID).

    if (!actor.getEquipmentList().contains(item)) {
      actor.addObjectToEquipList(item);
      processItemAtrributes(actor, item, true);
    }
  }
 private int getForceProtection(SWGObject item) {
   return core.scriptService
       .getMethod(
           "scripts/equipment/",
           "force_protection",
           item.getAttachment("type") + "_" + item.getStringAttribute("protection_level"))
       .__call__()
       .asInt();
 }
Example #3
0
 public void faceObject(SWGObject object) {
   float direction =
       (float)
           Math.atan2(
               object.getWorldPosition().x - creature.getWorldPosition().x,
               object.getWorldPosition().z - creature.getWorldPosition().z);
   if (direction < 0) direction = (float) (2 * Math.PI + direction);
   if (Math.abs(direction - creature.getRadians()) < 0.05) return;
   Quaternion quaternion =
       new Quaternion((float) Math.cos(direction / 2), 0, (float) Math.sin(direction / 2), 0);
   if (quaternion.y < 0.0f && quaternion.w > 0.0f) {
     quaternion.y *= -1;
     quaternion.w *= -1;
   }
   if (creature.getContainer() instanceof CellObject)
     NGECore.getInstance()
         .simulationService
         .moveObject(
             creature,
             creature.getPosition(),
             quaternion,
             creature.getMovementCounter(),
             0,
             (CellObject) creature.getContainer());
   else
     NGECore.getInstance()
         .simulationService
         .moveObject(
             creature, creature.getPosition(), quaternion, creature.getMovementCounter(), 0, null);
 }
  public void unequip(CreatureObject actor, SWGObject item) {
    String template =
        ((item.getAttachment("customServerTemplate") == null)
            ? item.getTemplate()
            : (item.getTemplate().split("shared_")[0]
                + "shared_"
                + ((String) item.getAttachment("customServerTemplate"))
                + ".iff"));
    String serverTemplate = template.replace(".iff", "");

    PyObject func =
        core.scriptService.getMethod(
            "scripts/" + serverTemplate.split("shared_", 2)[0].replace("shared_", ""),
            serverTemplate.split("shared_", 2)[1],
            "unequip");
    if (func != null) func.__call__(Py.java2py(core), Py.java2py(actor), Py.java2py(item));

    if (actor.getEquipmentList().contains(item)) {
      actor.removeObjectFromEquipList(item);
      processItemAtrributes(actor, item, false);
    }
  }
  public boolean canEquip(CreatureObject actor, SWGObject item) {
    // TODO: Species restrictions
    // TODO: Gender restrictions

    boolean result = true;

    if (item == null) return false;

    if (item.getAttributes().toString().contains("cat_armor")) {
      if (actor.hasAbility("wear_all_armor"))
        result = true; // Change to "wear_all_armor" ability instead of lvl 22
      else return false;
    }

    if (item.getStringAttribute("class_required") != null) {
      String profession = ((PlayerObject) actor.getSlottedObject("ghost")).getProfession();
      if (item.getStringAttribute("class_required")
              .contentEquals(core.playerService.getFormalProfessionName(profession))
          || item.getStringAttribute("class_required").contentEquals("None")) result = true;
      else return false;
    }

    if (item.getStringAttribute("faction_restriction") != null)
      if (item.getStringAttribute("faction_restriction")
              .toLowerCase()
              .contentEquals(actor.getFaction())
          && actor.getFactionStatus() >= FactionStatus.Combatant) result = true;
      else return false;

    if (item.getAttributes().containsKey("required_combat_level")) {
      if (actor.getLevel() >= item.getIntAttribute("required_combat_level")) result = true;
      else return false;
    }

    if (item.getAttachment("unity") != null) {
      actor.sendSystemMessage("@unity:cannot_remove_ring", (byte) 0);
      return false;
    }

    return result;
  }
  private int getWeaponCriticalChance(CreatureObject actor, SWGObject item) {
    int weaponCriticalChance = 0;
    String weaponCriticalSkillMod =
        (core.scriptService
            .getMethod(
                "scripts/equipment/",
                "weapon_critical",
                item.getStringAttribute("cat_wpn_damage.wpn_category"))
            .__call__()
            .asString());

    if (weaponCriticalSkillMod.contains(" ")) weaponCriticalSkillMod.replace(" ", "");

    if (weaponCriticalSkillMod.contains("-")) weaponCriticalSkillMod.replace("-", "");

    if (actor.getSkillMod(weaponCriticalSkillMod) != null)
      weaponCriticalChance = actor.getSkillModBase(weaponCriticalSkillMod);

    return weaponCriticalChance;
  }
Example #7
0
 public void initAfterDBLoad() {
   super.init();
   defendersList = new Vector<TangibleObject>();
   cooldowns = new ConcurrentHashMap<String, Long>();
 }
Example #8
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;
  }
Example #9
0
  public void processCombatCommand(
      CreatureObject attacker,
      SWGObject target,
      CombatCommand command,
      int actionCounter,
      String commandArgs) {
    if (FileUtilities.doesFileExist(
        "scripts/commands/combat/" + command.getCommandName() + ".py")) {
      core.scriptService.callScript(
          "scripts/commands/combat/",
          command.getCommandName(),
          "setup",
          core,
          attacker,
          target,
          command);
    }

    boolean success = true;

    // if((command.getHitType() == 5 || command.getHitType() == 7) && !(target instanceof
    // CreatureObject))
    //	success = false;

    if (!(command.getAttackType() == 2)
        && !(command.getHitType() == 5)
        && !(command.getHitType() == 0)) {
      if (target == null || !(target instanceof TangibleObject) || target == attacker)
        success = false;
    } else {
      if (target == null) target = attacker;
      else if (!(target instanceof TangibleObject)) return;
    }

    if (attacker.getPosture() == 13 || attacker.getPosture() == 14) success = false;

    if (target instanceof CreatureObject) {
      if (!(command.getHitType() == 5))
        if (((CreatureObject) target).getPosture() == 13) success = false;
      if (!(command.getHitType() == 7))
        if (((CreatureObject) target).getPosture() == 14) success = false;
    }

    if (command.getHitType() == 7 && target.getClient() == null) success = false;

    WeaponObject weapon;

    if (attacker.getWeaponId() == 0)
      weapon =
          (WeaponObject)
              attacker.getSlottedObject(
                  "default_weapon"); // use unarmed/default weapon if no weapon is equipped
    else weapon = (WeaponObject) core.objectService.getObject(attacker.getWeaponId());

    float maxRange = 0;

    if (command.getMaxRange() == 0) maxRange = weapon.getMaxRange();
    else maxRange = command.getMaxRange();

    Point3D attackerPos = attacker.getWorldPosition();
    Point3D defenderPos = attacker.getWorldPosition();

    if (attackerPos.getDistance(defenderPos) > maxRange && maxRange != 0) success = false;

    if (command.getMinRange() > 0) {
      if (attackerPos.getDistance(defenderPos) < command.getMinRange()) success = false;
    }

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

    if (!success && attacker.getClient() != null) {
      IoSession session = attacker.getClient().getSession();
      CommandEnqueueRemove commandRemove =
          new CommandEnqueueRemove(attacker.getObjectId(), actionCounter);
      session.write(new ObjControllerMessage(0x0B, commandRemove).serialize());
      StartTask startTask =
          new StartTask(
              actionCounter,
              attacker.getObjectID(),
              command.getCommandCRC(),
              CRC.StringtoCRC(command.getCooldownGroup()),
              -1);
      session.write(new ObjControllerMessage(0x0B, startTask).serialize());
    } else {

      if (command.getHitType() == 5) {
        core.combatService.doHeal(
            attacker, (CreatureObject) target, weapon, command, actionCounter);
        return;
      }

      if (command.getHitType() == 7) {
        core.combatService.doRevive(
            attacker, (CreatureObject) target, weapon, command, actionCounter);
        return;
      }

      if (command.getHitType() == 0
          && command.getBuffNameSelf() != null
          && command.getBuffNameSelf().length() > 0) {
        core.combatService.doSelfBuff(attacker, weapon, command, actionCounter);
        return;
      }
      for (int i = 0; i < command.getAttack_rolls(); i++) {
        core.combatService.doCombat(
            attacker, (TangibleObject) target, weapon, command, actionCounter);
      }
    }
  }
Example #10
0
  private void calculateArmorProtection(CreatureObject creature, boolean equipping) {
    int wornArmourPieces = 0, forceProtection = 0;
    Map<String, Float> protection = new TreeMap<String, Float>();

    for (SWGObject item : new ArrayList<SWGObject>(creature.getEquipmentList())) {
      Map<String, Object> attributes = new TreeMap<String, Object>(item.getAttributes());
      boolean incPieceCount = false;

      if (item.getStringAttribute("protection_level") != null) {
        forceProtection = getForceProtection(item);
        break;
      }

      for (Entry<String, Object> e : attributes.entrySet()) {
        if (e.getKey().startsWith("cat_armor_standard_protection")) {
          String protectionType =
              e.getKey().replace("cat_armor_standard_protection.armor_eff_", "");
          float modifier =
              Float.parseFloat(
                      core.scriptService
                          .getMethod(
                              "scripts/equipment/",
                              "slot_protection",
                              creature.getSlotNameForObject(item))
                          .__call__()
                          .asString())
                  / 100;
          Float protectionAmount = Float.parseFloat((String) e.getValue()) * modifier;

          if (protection.containsKey(protectionType))
            protection.replace(protectionType, protection.get(protectionType) + protectionAmount);
          else protection.put(protectionType, protectionAmount);
          incPieceCount = true;
        } else if (e.getKey().startsWith("cat_armor_special_protection")) {
          String protectionType =
              e.getKey().replace("cat_armor_special_protection.special_protection_type_", "");
          float modifier =
              Float.parseFloat(
                      core.scriptService
                          .getMethod(
                              "scripts/equipment/",
                              "slot_protection",
                              creature.getSlotNameForObject(item))
                          .__call__()
                          .asString())
                  / 100;
          Float protectionAmount = Float.parseFloat((String) e.getValue()) * modifier;

          if (protection.containsKey(protectionType))
            protection.replace(protectionType, protection.get(protectionType) + protectionAmount);
          else protection.put(protectionType, protectionAmount);
          incPieceCount = true;
        }
      }
      if (incPieceCount) wornArmourPieces++;
    }

    if (protection.size() == 0) {
      protection.put("kinetic", (float) 0);
      protection.put("energy", (float) 0);
      protection.put("heat", (float) 0);
      protection.put("cold", (float) 0);
      protection.put("acid", (float) 0);
      protection.put("electricity", (float) 0);
    }

    for (Entry<String, Float> e : protection.entrySet()) {
      core.skillModService.deductSkillMod(
          creature, e.getKey(), creature.getSkillModBase(e.getKey()));
      core.skillModService.addSkillMod(creature, e.getKey(), forceProtection);
      if (wornArmourPieces >= 3)
        core.skillModService.addSkillMod(creature, e.getKey(), (int) e.getValue().floatValue());
    }
  }
Example #11
0
  public void processItemAtrributes(CreatureObject creature, SWGObject item, boolean equipping) {
    // TODO: crit enhancement from crafted weapons
    // TODO: check for armor category in order to add resistance to certain DoT types

    Map<String, Object> attributes = new TreeMap<String, Object>(item.getAttributes());

    if (equipping) {
      if (item.getStringAttribute("cat_wpn_damage.wpn_category") != null)
        creature.addSkillMod("display_only_critical", getWeaponCriticalChance(creature, item));
      if (item.getStringAttribute("proc_name") != null)
        core.buffService.addBuffToCreature(
            creature, item.getStringAttribute("proc_name").replace("@ui_buff:", ""), creature);

      for (Entry<String, Object> e : attributes.entrySet()) {
        if (e.getKey().startsWith("cat_skill_mod_bonus.@stat_n:")) {
          core.skillModService.addSkillMod(
              creature,
              e.getKey().replace("cat_skill_mod_bonus.@stat_n:", ""),
              Integer.parseInt((String) e.getValue()));
        }

        if (e.getKey().startsWith("cat_stat_mod_bonus.@stat_n:")) {
          core.skillModService.addSkillMod(
              creature,
              e.getKey().replace("cat_stat_mod_bonus.@stat_n:", ""),
              Integer.parseInt((String) e.getValue()));
        }

        if (e.getKey().startsWith("cat_attrib_mod_bonus.attr_health")) {
          creature.setMaxHealth(creature.getMaxHealth() + Integer.parseInt((String) e.getValue()));
        }

        if (e.getKey().startsWith("cat_attrib_mod_bonus.attr_action")) {
          creature.setMaxAction(creature.getMaxAction() + Integer.parseInt((String) e.getValue()));
        }
      }
    } else {
      if (item.getStringAttribute("cat_wpn_damage.wpn_category") != null)
        creature.deductSkillMod("display_only_critical", getWeaponCriticalChance(creature, item));
      if (item.getStringAttribute("proc_name") != null)
        core.buffService.removeBuffFromCreatureByName(
            creature, item.getStringAttribute("proc_name").replace("@ui_buff:", ""));

      for (Entry<String, Object> e : attributes.entrySet()) {
        if (e.getKey().startsWith("cat_skill_mod_bonus.@stat_n:")) {
          core.skillModService.deductSkillMod(
              creature,
              e.getKey().replace("cat_skill_mod_bonus.@stat_n:", ""),
              Integer.parseInt((String) e.getValue()));
        }
        if (e.getKey().startsWith("cat_stat_mod_bonus.@stat_n:")) {
          core.skillModService.deductSkillMod(
              creature,
              e.getKey().replace("cat_stat_mod_bonus.@stat_n:", ""),
              Integer.parseInt((String) e.getValue()));
        }

        if (e.getKey().startsWith("cat_attrib_mod_bonus.attr_health")) {
          creature.setMaxHealth(creature.getMaxHealth() - Integer.parseInt((String) e.getValue()));
        }
        if (e.getKey().startsWith("cat_attrib_mod_bonus.attr_action")) {
          creature.setMaxAction(creature.getMaxAction() - Integer.parseInt((String) e.getValue()));
        }
      }
    }

    calculateArmorProtection(creature, equipping);

    if (item.getAttachment("setBonus") != null) {
      BonusSetTemplate bonus = bonusSetTemplates.get((String) item.getAttachment("setBonus"));
      bonus.callScript(creature);
    }
  }