Ejemplo n.º 1
0
  public IoBuffer buildAddEquipmentDelta(TangibleObject item) {

    CreatureObject creature = (CreatureObject) object;

    IoBuffer buffer = bufferPool.allocate(496, false).order(ByteOrder.LITTLE_ENDIAN);
    buffer.putInt(1);
    buffer.putInt(creature.getEquipmentListUpdateCounter());
    buffer.put((byte) 1);
    buffer.putShort((short) creature.getEquipmentList().indexOf(item));
    if (item.getCustomization() == null || item.getCustomization().length == 0) {
      buffer.putShort((short) 0);
    } else {
      buffer.putShort((short) item.getCustomization().length);
      buffer.put(item.getCustomization());
    }
    buffer.putInt(item.getArrangementId());
    buffer.putLong(item.getObjectID());
    buffer.putInt(CRC.StringtoCRC(item.getTemplate()));
    if (item instanceof WeaponObject) {
      WeaponObject weapon = (WeaponObject) item;
      buffer.put((byte) 1);
      buffer.put(weapon.getMessageBuilder().buildBaseline3());
      buffer.put(weapon.getMessageBuilder().buildBaseline6());
    } else {
      buffer.put((byte) 0);
    }

    int size = buffer.position();
    buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size);
    buffer.flip();
    buffer = createDelta("CREO", (byte) 6, (short) 1, (short) 0x17, buffer, size + 4);

    return buffer;
  }
Ejemplo n.º 2
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);
      }
    }
  }
Ejemplo n.º 3
0
  public IoBuffer buildBaseline6() {
    CreatureObject creature = (CreatureObject) object;

    IoBuffer buffer = bufferPool.allocate(100, false).order(ByteOrder.LITTLE_ENDIAN);
    buffer.setAutoExpand(true);
    buffer.putShort((short) 0x23);
    buffer.putInt(0x43); // serverId

    buffer.putShort((short) 0); // detaiLStfFilename
    buffer.putInt(0); // detailStfSpacer
    buffer.putShort((short) 0); // detailStfName

    // TANO 6 lists TODO: research

    buffer.put(creature.getCombatFlag());

    buffer.putLong(0); // List<Long> possibly defenders list
    buffer.putInt(0); // Int
    buffer.putLong(0); // List<Long>
    buffer.putLong(0); // List<Int>
    buffer.putLong(0); // List<Unknown>

    buffer.putShort(creature.getLevel());
    buffer.putInt(
        creature
            .getGrantedHealth()); // From player_level.iff.  Ranges from 0-2000 as you level,
                                  // consistent with that table.

    // 0A
    if (creature.getCurrentAnimation() == null || creature.getCurrentAnimation().length() == 0)
      buffer.putShort((short) 0);
    else buffer.put(getAsciiString(creature.getCurrentAnimation()));

    if (creature.getMoodAnimation() == null || creature.getMoodAnimation().length() == 0)
      buffer.put(getAsciiString("neutral"));
    else buffer.put(getAsciiString(creature.getMoodAnimation()));

    buffer.putLong(creature.getWeaponId());

    buffer.putLong(creature.getGroupId());
    buffer.putLong(creature.getInviteSenderId());
    if (creature.getInviteSenderName() == null || creature.getInviteSenderName().length() == 0)
      buffer.putShort((short) 0);
    else buffer.put(getAsciiString(creature.getInviteSenderName()));

    buffer.putLong(creature.getInviteCounter());

    buffer.putInt(creature.getGuildId());

    buffer.putLong(creature.getLookAtTarget()); // lookAtTarget 0x10
    buffer.putLong(creature.getIntendedTarget()); // intendedTarget 0x11
    buffer.put(creature.getMoodId());
    buffer.putInt(creature.getPerformanceCounter());
    /*
     * minor dilemma: performance ID is needed for XP calculation, but it can't be sent
     * in the CREO, otherwise the evul note bubbles appear
     */
    buffer.putInt((creature.getPerformanceType()) ? 0 : creature.getPerformanceId());

    buffer.putInt(6); // Current HAM
    buffer.putInt(creature.getHamListCounter());

    buffer.putInt(creature.getHealth());
    // 1A
    buffer.putInt(0);
    buffer.putInt(creature.getAction());
    buffer.putInt(0);
    buffer.putInt(0x2C01);
    buffer.putInt(0);

    buffer.putInt(6); // Max HAM
    buffer.putInt(creature.getMaxHAMListCounter());

    buffer.putInt(creature.getMaxHealth());
    buffer.putInt(0);
    buffer.putInt(creature.getMaxAction());
    buffer.putInt(0);
    buffer.putInt(0x2C01);
    buffer.putInt(0);

    if (creature.getEquipmentList().isEmpty()) {
      buffer.putInt(0);
      buffer.putInt(creature.getEquipmentListUpdateCounter());
    } else {
      buffer.putInt(creature.getEquipmentList().size());
      buffer.putInt(creature.getEquipmentListUpdateCounter());

      for (SWGObject obj : creature.getEquipmentList().get()) {

        if (obj instanceof TangibleObject && !(obj instanceof WeaponObject)) {
          TangibleObject tangible = (TangibleObject) obj;
          if (tangible.getCustomization() == null || tangible.getCustomization().length == 0) {
            buffer.putShort((short) 0);
          } else {
            buffer.putShort((short) tangible.getCustomization().length);
            buffer.put(tangible.getCustomization());
          }
          buffer.putInt(tangible.getArrangementId());
          buffer.putLong(tangible.getObjectID());
          buffer.putInt(CRC.StringtoCRC(tangible.getTemplate()));
          buffer.put((byte) 0);
        } else if (obj instanceof WeaponObject) {
          WeaponObject weapon = (WeaponObject) obj;
          if (weapon.getCustomization() == null || weapon.getCustomization().length == 0) {
            buffer.putShort((short) 0);
          } else {
            buffer.putShort((short) weapon.getCustomization().length);
            buffer.put(weapon.getCustomization());
          }
          buffer.putInt(weapon.getArrangementId());
          buffer.putLong(weapon.getObjectID());
          buffer.putInt(CRC.StringtoCRC(weapon.getTemplate()));

          buffer.put((byte) 1);
          buffer.put(weapon.getMessageBuilder().buildBaseline3());
          buffer.put(weapon.getMessageBuilder().buildBaseline6());
        } else {
          System.out.println("Bad equipment object");
        }
      }
    }

    buffer.putShort((short) 0); // costume
    // buffer.put(getAsciiString("appearance/gungan_m.sat"));
    buffer.put((byte) (creature.isInStealth() ? 0 : 1));

    if (creature.getBuffList().isEmpty()) {
      buffer.putInt(0);
      buffer.putInt(creature.getBuffListCounter());
    } else {
      buffer.putInt(creature.getBuffList().size() + 1);
      buffer.putInt(creature.getBuffListCounter());

      buffer.put((byte) 0);
      // buffer.putInt(0x2098793D);
      buffer.putInt(0);
      buffer.putInt(-1);
      buffer.putInt(0);
      buffer.putInt(0);
      buffer.putLong(creature.getObjectID());

      PlayerObject player = (PlayerObject) creature.getSlottedObject("ghost");

      for (Buff buff : creature.getBuffList().get()) {

        if (player != null)
          buff.setTotalPlayTime(
              (int)
                  (player.getTotalPlayTime()
                      + (System.currentTimeMillis() - player.getLastPlayTimeUpdate()) / 1000));
        else buff.setTotalPlayTime(0);
        buffer.put((byte) 1);
        buffer.putInt(0);
        buffer.putInt(CRC.StringtoCRC(buff.getBuffName().toLowerCase()));
        if (buff.getDuration() > 0) {
          buffer.putInt((int) (buff.getTotalPlayTime() + buff.getRemainingDuration()));
          buffer.putInt(0);
          buffer.putInt((int) buff.getDuration());
        } else {
          buffer.putInt(-1);
          buffer.putInt(0);
          buffer.putInt(0);
        }

        buffer.putLong(creature.getObjectID());
      }

      buffer.putInt(1);
    }

    buffer.put(
        (byte)
            (creature.isStationary() ? 1 : 0)); // if the server accepts transforms from the object
    buffer.put(creature.getDifficulty());

    if (creature.isHologram()) buffer.putInt(0);
    else buffer.putInt(0xFFFFFFFF);

    buffer.put((byte) (creature.isRadarVisible() ? 1 : 0));
    buffer.put((byte) 0); // no effect for 1?
    buffer.put((byte) 0); // no effect for 1?

    if (creature.getAppearanceEquipmentList().isEmpty()) {
      buffer.putInt(0);
      buffer.putInt(creature.getAppearanceEquipmentListUpdateCounter());
    } else {
      buffer.putInt(creature.getAppearanceEquipmentList().size());
      buffer.putInt(creature.getAppearanceEquipmentListUpdateCounter());

      for (SWGObject obj : creature.getAppearanceEquipmentList().get()) {

        if (obj instanceof TangibleObject) {
          TangibleObject tangible = (TangibleObject) obj;
          if (tangible.getCustomization() == null || tangible.getCustomization().length == 0) {
            buffer.putShort((short) 0);
          } else {
            buffer.putShort((short) tangible.getCustomization().length);
            buffer.put(tangible.getCustomization());
          }
          buffer.putInt(tangible.getArrangementId());
          buffer.putLong(tangible.getObjectID());
          buffer.putInt(CRC.StringtoCRC(tangible.getTemplate()));
          buffer.put((byte) 0);
        } else {
          System.out.println("Bad appearance equipment object");
        }
      }
    }

    buffer.putLong(0); // unk long

    int size = buffer.position();
    buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size);

    buffer.flip();
    buffer = createBaseline("CREO", (byte) 6, buffer, size);

    return buffer;
  }
  public IoBuffer buildBaseline6() {
    CreatureObject creature = (CreatureObject) object;

    IoBuffer buffer = bufferPool.allocate(100, false).order(ByteOrder.LITTLE_ENDIAN);
    buffer.setAutoExpand(true);
    buffer.putShort((short) 0x23);
    buffer.putInt(0x4E);

    buffer.putInt(0); // defenders list unused in NGE
    buffer.putInt(0);

    buffer.put(creature.getCombatFlag());

    buffer.putLong(0);
    buffer.putLong(0);
    buffer.putLong(0); // Vehicle vars or TANO 6 vars TODO: research
    buffer.putLong(0);
    buffer.putInt(0);

    // buffer.putShort(creature.getLevel());
    buffer.putShort((short) 90);
    buffer.putInt(0xD007); // unk

    if (creature.getCurrentAnimation() == null || creature.getCurrentAnimation().length() == 0)
      buffer.putShort((short) 0);
    else buffer.put(getAsciiString(creature.getCurrentAnimation()));
    if (creature.getMoodAnimation() == null || creature.getMoodAnimation().length() == 0)
      buffer.put(getAsciiString("neutral"));
    else buffer.put(getAsciiString(creature.getMoodAnimation()));

    buffer.putLong(creature.getWeaponId());

    buffer.putLong(creature.getGroupId());
    buffer.putLong(creature.getInviteSenderId());
    if (creature.getInviteSenderName() == null || creature.getInviteSenderName().length() == 0)
      buffer.putShort((short) 0);
    else buffer.put(getAsciiString(creature.getInviteSenderName()));

    buffer.putLong(creature.getInviteCounter());

    buffer.putInt(creature.getGuildId());
    buffer.putLong(creature.getTargetId());
    buffer.put(creature.getMoodId());
    buffer.putInt(creature.getPerformanceCounter());
    buffer.putInt(creature.getPerformanceId());

    buffer.putInt(0); // unks
    buffer.putInt(0);

    buffer.putInt(6); // Current HAM
    buffer.putInt(creature.getHamListCounter());

    buffer.putInt(creature.getHealth());
    buffer.putInt(0);
    buffer.putInt(creature.getAction());
    buffer.putInt(0);
    buffer.putInt(0x2C01);
    buffer.putInt(0);

    buffer.putInt(6); // Max HAM
    buffer.putInt(0);

    buffer.putInt(creature.getMaxHealth());
    buffer.putInt(0);
    buffer.putInt(creature.getMaxAction());
    buffer.putInt(0);
    buffer.putInt(0x2C01);
    buffer.putInt(0);

    if (creature.getEquipmentList().isEmpty()) {
      buffer.putInt(0);
      buffer.putInt(0);
    } else {
      buffer.putInt(creature.getEquipmentList().size());
      buffer.putInt(0);

      for (SWGObject obj : creature.getEquipmentList().get()) {

        if (obj instanceof TangibleObject) {
          TangibleObject tangible = (TangibleObject) obj;
          if (tangible.getCustomization() == null || tangible.getCustomization().length == 0) {
            buffer.putShort((short) 0);
          } else {
            buffer.putShort((short) tangible.getCustomization().length);
            buffer.put(tangible.getCustomization());
          }
          buffer.putInt(tangible.getArrangementId());
          buffer.putLong(tangible.getObjectID());
          buffer.putInt(CRC.StringtoCRC(tangible.getTemplate()));
          buffer.put((byte) 0);
        } else if (obj instanceof WeaponObject) {
          WeaponObject weapon = (WeaponObject) obj;
          if (weapon.getCustomization() == null || weapon.getCustomization().length == 0) {
            buffer.putShort((short) 0);
          } else {
            buffer.putShort((short) weapon.getCustomization().length);
            buffer.put(weapon.getCustomization());
          }
          buffer.putInt(weapon.getArrangementId());
          buffer.putLong(weapon.getObjectID());
          buffer.putInt(CRC.StringtoCRC(weapon.getTemplate()));

          buffer.put((byte) 1);
          buffer.put(weapon.getMessageBuilder().buildBaseline3());
          buffer.put(weapon.getMessageBuilder().buildBaseline6());
        } else {
          System.out.println("Bad equipment object");
        }
      }
    }

    buffer.putShort((short) 0);
    // buffer.put(getAsciiString("appearance/gungan_m.sat"));
    buffer.put((byte) 1);

    if (creature.getBuffList().isEmpty()) {
      buffer.putInt(0);
      buffer.putInt(creature.getBuffListCounter());
    } else {
      buffer.putInt(creature.getBuffList().size() + 1);
      buffer.putInt(creature.getBuffListCounter());

      buffer.put((byte) 0);
      // buffer.putInt(0x2098793D);
      buffer.putInt(0);
      buffer.putInt(-1);
      buffer.putInt(0);
      buffer.putInt(0);
      buffer.putLong(creature.getObjectID());

      PlayerObject player = (PlayerObject) creature.getSlottedObject("ghost");

      for (Buff buff : creature.getBuffList().get()) {

        buff.setTotalPlayTime(
            (int)
                (player.getTotalPlayTime()
                    + (System.currentTimeMillis() - player.getLastPlayTimeUpdate()) / 1000));
        buffer.put((byte) 1);
        buffer.putInt(0);
        buffer.putInt(CRC.StringtoCRC(buff.getBuffName()));
        if (buff.getDuration() > 0) {
          buffer.putInt((int) (buff.getTotalPlayTime() + buff.getRemainingDuration()));
          buffer.putInt(0);
          buffer.putInt((int) buff.getDuration());
        } else {
          buffer.putInt(-1);
          buffer.putInt(0);
          buffer.putInt(0);
        }

        buffer.putLong(creature.getObjectID());
      }

      buffer.putInt(1);
    }

    buffer.putShort((short) 0);
    buffer.putInt(0xFFFFFFFF);
    buffer.put((byte) 1);
    buffer.putShort((short) 0);

    if (creature.getAppearanceEquipmentList().isEmpty()) {
      buffer.putInt(0);
      buffer.putInt(0);
    } else {
      buffer.putInt(creature.getAppearanceEquipmentList().size());
      buffer.putInt(0);

      for (SWGObject obj : creature.getAppearanceEquipmentList().get()) {

        if (obj instanceof TangibleObject) {
          TangibleObject tangible = (TangibleObject) obj;
          if (tangible.getCustomization() == null || tangible.getCustomization().length == 0) {
            buffer.putShort((short) 0);
          } else {
            buffer.putShort((short) tangible.getCustomization().length);
            buffer.put(tangible.getCustomization());
          }
          buffer.putInt(tangible.getArrangementId());
          buffer.putLong(tangible.getObjectID());
          buffer.putInt(CRC.StringtoCRC(tangible.getTemplate()));
          buffer.put((byte) 0);
        } else {
          System.out.println("Bad appearance equipment object");
        }
      }
    }

    buffer.putInt(0);
    buffer.putInt(0);

    int size = buffer.position();
    buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size);

    buffer.flip();
    buffer = createBaseline("CREO", (byte) 6, buffer, size);

    return buffer;
  }