コード例 #1
0
ファイル: AIActor.java プロジェクト: Thorfin25/NGECore2
 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);
 }
コード例 #2
0
  public CharacterService(NGECore core) {

    this.core = core;
    this.databaseConnection = core.getDatabase1();
    this.databaseConnection2 = core.getDatabase2();
    try {
      nameGenerator = new engine.resources.common.NameGen("names.txt");
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
ファイル: CreatureObject.java プロジェクト: Chadenn/NGECore2
  @Override
  public void sendBaselines(Client destination) {

    if (destination == null || destination.getSession() == null) {
      System.out.println("NULL session");
      return;
    }

    destination.getSession().write(messageBuilder.buildBaseline3());
    destination.getSession().write(messageBuilder.buildBaseline6());
    if (destination == getClient()) {
      destination.getSession().write(messageBuilder.buildBaseline1());
      destination.getSession().write(messageBuilder.buildBaseline4());
    }
    // destination.getSession().write(messageBuilder.buildBaseline8());
    // destination.getSession().write(messageBuilder.buildBaseline9());

    if (destination != getClient()) {
      UpdatePVPStatusMessage upvpm =
          new UpdatePVPStatusMessage(
              getObjectID(),
              NGECore.getInstance()
                  .factionService
                  .calculatePvpStatus((CreatureObject) destination.getParent(), this),
              getFaction());
      destination.getSession().write(upvpm.serialize());
      UpdatePostureMessage upm = new UpdatePostureMessage(getObjectID(), getPosture());
      destination.getSession().write(upm.serialize());
    }
  }
コード例 #4
0
ファイル: Buff.java プロジェクト: Jaqsin/NGECore2
  public void updateRemovalTask() {

    if (removalTask == null) return;

    removalTask.cancel(true);

    final NGECore core = NGECore.getInstance();
    final CreatureObject owner = (CreatureObject) core.objectService.getObject(getOwnerId());

    if (owner == null) return;

    ScheduledFuture<?> task =
        Executors.newScheduledThreadPool(1)
            .schedule(
                new Runnable() {

                  @Override
                  public void run() {

                    core.buffService.removeBuffFromCreature(owner, Buff.this);
                  }
                },
                (long) getRemainingDuration(),
                TimeUnit.SECONDS);

    setRemovalTask(task);
  }
コード例 #5
0
ファイル: NGECore.java プロジェクト: Balkanac/NGECore2
  public static void main(String[] args) {

    NGECore core = new NGECore();

    core.start();

    do {
      if (didServerCrash) {
        core.restart();
      }
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {

      }
    } while (true);
  }
コード例 #6
0
ファイル: CreatureObject.java プロジェクト: Chadenn/NGECore2
  public void setOwnerId(long ownerId) {
    synchronized (objectMutex) {
      this.ownerId = ownerId;
    }

    setStringAttribute(
        "owner", NGECore.getInstance().objectService.getObject(ownerId).getCustomName());

    notifyObservers(messageBuilder.buildOwnerIdDelta(ownerId), true);
  }
コード例 #7
0
  public void updatePvpStatus() {
    HashSet<Client> observers = new HashSet<Client>(getObservers());

    for (Iterator<Client> it = observers.iterator(); it.hasNext(); ) {
      Client observer = it.next();

      if (observer.getParent() != null) {
        observer
            .getSession()
            .write(
                new UpdatePVPStatusMessage(
                        this.getObjectID(),
                        NGECore.getInstance()
                            .factionService
                            .calculatePvpStatus((CreatureObject) observer.getParent(), this),
                        getFaction())
                    .serialize());
        if (getClient() != null) {
          getClient()
              .getSession()
              .write(
                  new UpdatePVPStatusMessage(
                          observer.getParent().getObjectID(),
                          NGECore.getInstance()
                              .factionService
                              .calculatePvpStatus(
                                  (CreatureObject) this, (CreatureObject) observer.getParent()),
                          getFaction())
                      .serialize());
        }
      }
    }

    if (getClient() != null) {
      CreatureObject companion =
          NGECore.getInstance().mountService.getCompanion((CreatureObject) this);

      if (companion != null) {
        companion.updatePvpStatus();
      }
    }
  }
コード例 #8
0
ファイル: AIActor.java プロジェクト: Thorfin25/NGECore2
 public void scheduleDespawn() {
   scheduler.schedule(
       () -> {
         damageMap.clear();
         followObject = null;
         creature.setAttachment("AI", null);
         NGECore.getInstance().objectService.destroyObject(creature);
       },
       30000,
       TimeUnit.MILLISECONDS);
 }
コード例 #9
0
ファイル: GCWService.java プロジェクト: ultgamer21/NGECore2
  public List<SWGObject> getSFPlayers() {
    List<SWGObject> flagged = new ArrayList<SWGObject>();

    synchronized (core.getActiveConnectionsMap()) {
      for (Client client : core.getActiveConnectionsMap().values()) {
        if (client.getParent() != null && client.getParent() instanceof CreatureObject) {
          flagged.add(client.getParent());
        }
      }
    }

    Iterator<SWGObject> it = flagged.iterator();

    while (it.hasNext()) {
      SWGObject obj = it.next();
      if (((CreatureObject) obj).getFactionStatus() != 2) {
        it.remove();
      }
    }

    return flagged;
  }
コード例 #10
0
ファイル: CreatureObject.java プロジェクト: Chadenn/NGECore2
  @Override
  public void setFactionStatus(int factionStatus) {
    synchronized (objectMutex) {
      this.factionStatus = factionStatus;
    }

    notifyObservers(messageBuilder.buildFactionStatusDelta(factionStatus), true);

    CreatureObject companion = NGECore.getInstance().mountService.getCompanion(this);

    if (companion != null) {
      companion.setFactionStatus(factionStatus);
    }
  }
コード例 #11
0
  public String getAccountNameFromDB(long id) {
    String accountName = null;
    PreparedStatement preparedStatement;

    try {
      preparedStatement =
          core.getDatabase1().preparedStatement("SELECT user FROM accounts WHERE id=" + id);
      ResultSet resultSet = preparedStatement.executeQuery();
      if (resultSet.next()) accountName = resultSet.getString("user");
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return accountName;
  }
コード例 #12
0
 public void unmount(CreatureObject owner) {
   boolean add = false;
   synchronized (objectMutex) {
     if ((this.getOptionsBitmask() & Options.MOUNT) == Options.MOUNT) {
       add = true;
       _remove(owner);
       UpdateContainmentMessage updateContainmentMessage =
           new UpdateContainmentMessage(owner.getObjectID(), 0, -1);
       notifyObservers(updateContainmentMessage, true);
     }
   }
   if (add) {
     owner.setMounted(false);
     owner.setMountedVehicle(null);
     owner.setStateBitmask(0);
     owner.setPosture((byte) 0);
     NGECore.getInstance()
         .simulationService
         .add(owner, getWorldPosition().x, getWorldPosition().z, false);
     NGECore.getInstance()
         .simulationService
         .teleport(owner, getWorldPosition(), getOrientation(), 0);
   }
 }
コード例 #13
0
  public void mount(CreatureObject owner) {
    boolean remove = false;
    synchronized (objectMutex) {
      if ((this.getOptionsBitmask() & Options.MOUNT) == Options.MOUNT) {
        remove = true;
        _add(owner);
        UpdateContainmentMessage updateContainmentMessage =
            new UpdateContainmentMessage(owner.getObjectID(), this.getObjectID(), 4);
        notifyObservers(updateContainmentMessage, true);
      }
    }

    if (remove)
      NGECore.getInstance()
          .simulationService
          .remove(owner, owner.getWorldPosition().x, owner.getWorldPosition().z, false);
  }
コード例 #14
0
 @Override
 public IoBuffer serialize() {
   String galaxy = NGECore.getInstance().getGalaxyName();
   IoBuffer buffer =
       IoBuffer.allocate(27 + galaxy.length() + characterName.length())
           .order(ByteOrder.LITTLE_ENDIAN);
   buffer.putShort((short) 5);
   if (join) buffer.putInt(Opcodes.ChatOnEnteredRoom);
   else buffer.putInt(CRC.StringtoCRC("ChatOnLeaveRoom"));
   buffer.put(getAsciiString("SWG"));
   buffer.put(getAsciiString(galaxy));
   buffer.put(getAsciiString(characterName.toLowerCase()));
   buffer.putInt(success);
   buffer.putInt(roomId);
   buffer.putInt(0);
   return buffer.flip();
 }
コード例 #15
0
  public boolean isFull() {

    if (getTemplateData().getAttribute("containerVolumeLimit") == null) return false;

    int containerVolumeLimit = (int) getTemplateData().getAttribute("containerVolumeLimit");
    if (containerVolumeLimit == 0
        || getTemplate()
            .equals("object/tangible/inventory/shared_appearance_inventory.iff")) // appearance
      // inventory - issue
      // #755 String
      // equality vs String
      // identity ...
      return false;

    if (NGECore.getInstance().objectService.objsInContainer(this, this) >= containerVolumeLimit)
      return true;

    return false;
  }
コード例 #16
0
  public void sendBaselines(Client destination) {
    if (destination != null && destination.getSession() != null) {
      destination.getSession().write(getBaseline(3).getBaseline());
      destination.getSession().write(getBaseline(6).getBaseline());

      Client parent = ((getGrandparent() == null) ? null : getGrandparent().getClient());

      if (parent != null && destination == parent) {
        destination.getSession().write(getBaseline(8).getBaseline());
        destination.getSession().write(getBaseline(9).getBaseline());
      }

      if (destination.getParent() != this) {
        UpdatePVPStatusMessage upvpm = new UpdatePVPStatusMessage(getObjectID());
        upvpm.setFaction(CRC.StringtoCRC(getFaction()));
        upvpm.setStatus(
            NGECore.getInstance()
                .factionService
                .calculatePvpStatus((CreatureObject) destination.getParent(), this));
        destination.getSession().write(upvpm.serialize());
      }
    }
  }
コード例 #17
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);

    // BaseObject
    buffer.putInt(0x43); // serverId

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

    // TangibleObject
    buffer.put(creature.getCombatFlag());

    buffer.putLong(0); // Set<Long> cloakViewers (set of objectIds of who can see a cloaked spy)
    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 (Long objId : creature.getEquipmentList().get()) {

        SWGObject obj = NGECore.getInstance().objectService.getObject(objId);

        if (obj == null) {
          System.err.println("Cant find obj for obj id in equip list!!!");
          continue;
        }

        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 (Long objId : creature.getAppearanceEquipmentList().get()) {

        SWGObject obj = NGECore.getInstance().objectService.getObject(objId);

        if (obj == null) {
          System.err.println("Cant find obj for obj id in equip list!!!");
          continue;
        }

        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;
  }
コード例 #18
0
 public boolean isAttackableBy(TangibleObject attacker) {
   int pvpStatus = NGECore.getInstance().factionService.calculatePvpStatus(attacker, this);
   return (((pvpStatus & PvpStatus.Attackable) == PvpStatus.Attackable)
       || ((pvpStatus & PvpStatus.Aggressive) == PvpStatus.Aggressive));
 }
コード例 #19
0
 public String getFaction() {
   return NGECore.getInstance().factionService.getName((int) getBaseline(3).get("faction"));
 }