Пример #1
0
  /**
   * <B><U> Concept</U> :</B><br>
   * <br>
   * All visible object are identified in <B>_visibleObjects</B> of their current L2WorldRegion <br>
   * All surrounding L2WorldRegion are identified in <B>_surroundingRegions</B> of the selected
   * L2WorldRegion in order to scan a large area around a L2Object
   *
   * @param object L2object that determine the current L2WorldRegion
   * @return all visible players of the L2WorldRegion object's and of its surrounding L2WorldRegion.
   */
  public static List<L2Playable> getVisiblePlayable(L2Object object) {
    L2WorldRegion reg = object.getWorldRegion();

    if (reg == null) return null;

    // Create an FastList in order to contain all visible L2Object
    List<L2Playable> result = new ArrayList<>();

    // Go through the FastList of region
    for (L2WorldRegion regi : reg.getSurroundingRegions()) {
      Map<Integer, L2Playable> _allpls = regi.getVisiblePlayable();
      Collection<L2Playable> _playables = _allpls.values();

      // Go through visible object of the selected region
      for (L2Playable _object : _playables) {
        if (_object == null || _object.equals(object)) continue; // skip our own character

        if (!_object.isVisible()) // GM invisible is different than this...
        continue; // skip dying objects

        result.add(_object);
      }
    }
    return result;
  }
Пример #2
0
  /**
   * <B><U> Concept</U> :</B><br>
   * <br>
   * All visible object are identified in <B>_visibleObjects</B> of their current L2WorldRegion <br>
   * All surrounding L2WorldRegion are identified in <B>_surroundingRegions</B> of the selected
   * L2WorldRegion in order to scan a large area around a L2Object
   *
   * @param object L2object that determine the center of the circular area
   * @param radius Radius of the spheric area
   * @return all visible objects of the L2WorldRegions in the spheric area (radius) centered on the
   *     object.
   */
  public static List<L2Object> getVisibleObjects3D(L2Object object, int radius) {
    if (object == null || !object.isVisible()) return new ArrayList<>();

    int x = object.getX();
    int y = object.getY();
    int z = object.getZ();
    int sqRadius = radius * radius;

    // Create an FastList in order to contain all visible L2Object
    List<L2Object> result = new ArrayList<>();

    // Go through visible object of the selected region
    for (L2WorldRegion regi : object.getWorldRegion().getSurroundingRegions()) {
      Collection<L2Object> vObj = regi.getVisibleObjects().values();

      for (L2Object _object : vObj) {
        if (_object == null || _object.equals(object)) continue; // skip our own character

        int x1 = _object.getX();
        int y1 = _object.getY();
        int z1 = _object.getZ();

        long dx = x1 - x;
        long dy = y1 - y;
        long dz = z1 - z;

        if (dx * dx + dy * dy + dz * dz < sqRadius) result.add(_object);
      }
    }

    return result;
  }
Пример #3
0
  /**
   * <B><U> Concept</U> :</B><br>
   * <br>
   * All visible object are identified in <B>_visibleObjects</B> of their current L2WorldRegion <br>
   * All surrounding L2WorldRegion are identified in <B>_surroundingRegions</B> of the selected
   * L2WorldRegion in order to scan a large area around a L2Object
   *
   * @param object L2object that determine the center of the circular area
   * @param radius Radius of the circular area
   * @return all visible objects of the L2WorldRegions in the circular area (radius) centered on the
   *     object.
   */
  public static List<L2Object> getVisibleObjects(L2Object object, int radius) {
    if (object == null || !object.isVisible()) return new ArrayList<>();

    int x = object.getX();
    int y = object.getY();
    int sqRadius = radius * radius;

    // Create an FastList in order to contain all visible L2Object
    List<L2Object> result = new ArrayList<>();

    // Go through the FastList of region
    for (L2WorldRegion regi : object.getWorldRegion().getSurroundingRegions()) {
      // Go through visible objects of the selected region
      Collection<L2Object> vObj = regi.getVisibleObjects().values();
      for (L2Object _object : vObj) {
        if (_object == null || _object.equals(object)) continue; // skip our own character

        int x1 = _object.getX();
        int y1 = _object.getY();

        double dx = x1 - x;
        double dy = y1 - y;

        // If the visible object is inside the circular area add the object to the FastList result
        if (dx * dx + dy * dy < sqRadius) result.add(_object);
      }
    }

    return result;
  }
Пример #4
0
  /**
   * Remove a L2Object from the world.<br>
   * <br>
   * <B><U> Concept</U> :</B><br>
   * <br>
   * L2Object (including L2PcInstance) are identified in <B>_visibleObjects</B> of his current
   * L2WorldRegion and in <B>_knownObjects</B> of other surrounding L2Characters <br>
   * L2PcInstance are identified in <B>_allPlayers</B> of L2World, in <B>_allPlayers</B> of his
   * current L2WorldRegion and in <B>_knownPlayer</B> of other surrounding L2Characters <br>
   * <br>
   * <B><U> Actions</U> :</B><br>
   * <br>
   * <li>Remove the L2Object object from _allPlayers* of L2World
   * <li>Remove the L2Object object from _visibleObjects and _allPlayers* of L2WorldRegion
   * <li>Remove the L2Object object from _gmList** of GmListTable
   * <li>Remove object from _knownObjects and _knownPlayer* of all surrounding L2WorldRegion
   *     L2Characters<br>
   * <li>If object is a L2Character, remove all L2Object from its _knownObjects and all L2PcInstance
   *     from its _knownPlayer<br>
   *     <br>
   *     <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T REMOVE the object from
   *     _allObjects of L2World</B></FONT><br>
   *     <br>
   *     <I>* only if object is a L2PcInstance</I><br>
   *     <I>** only if object is a GM L2PcInstance</I><br>
   *     <br>
   *     <B><U> Example of use </U> :</B><br>
   *     <br>
   * <li>Pickup an Item
   * <li>Decay a L2Character<br>
   *     <br>
   *
   * @param object L2object to remove from the world
   * @param oldRegion L2WorldRegion in wich the object was before removing
   */
  public void removeVisibleObject(L2Object object, L2WorldRegion oldRegion) {
    if (object == null) return;

    if (oldRegion != null) {
      // Remove the object from the L2ObjectHashSet(L2Object) _visibleObjects of L2WorldRegion
      // If object is a L2PcInstance, remove it from the L2ObjectHashSet(L2PcInstance) _allPlayers
      // of this L2WorldRegion
      oldRegion.removeVisibleObject(object);

      // Go through all surrounding L2WorldRegion L2Characters
      for (L2WorldRegion reg : oldRegion.getSurroundingRegions()) {
        Collection<L2Object> vObj = reg.getVisibleObjects().values();

        for (L2Object obj : vObj) {
          if (obj != null) {
            obj.getKnownList().removeKnownObject(object);
            object.getKnownList().removeKnownObject(obj);
          }
        }
      }

      // If object is a L2Character :
      // Remove all L2Object from L2ObjectHashSet(L2Object) containing all L2Object detected by the
      // L2Character
      // Remove all L2PcInstance from L2ObjectHashSet(L2PcInstance) containing all player ingame
      // detected by the L2Character
      object.getKnownList().removeAllKnownObjects();

      // If selected L2Object is a L2PcIntance, remove it from L2ObjectHashSet(L2PcInstance)
      // _allPlayers of L2World
      if (object instanceof L2PcInstance) {
        if (!((L2PcInstance) object).isTeleporting()) removeFromAllPlayers((L2PcInstance) object);
      }
    }
  }
Пример #5
0
  /**
   * <B><U> Concept</U> :</B><br>
   * <br>
   * All visible object are identified in <B>_visibleObjects</B> of their current L2WorldRegion <br>
   * All surrounding L2WorldRegion are identified in <B>_surroundingRegions</B> of the selected
   * L2WorldRegion in order to scan a large area around a L2Object<br>
   * <br>
   *
   * @param object L2object that determine the current L2WorldRegion
   * @return all visible objects of the L2WorldRegion object's and of its surrounding L2WorldRegion.
   */
  public static List<L2Object> getVisibleObjects(L2Object object) {
    L2WorldRegion reg = object.getWorldRegion();
    if (reg == null) return null;

    // Create an FastList in order to contain all visible L2Object
    List<L2Object> result = new ArrayList<>();

    // Go through the FastList of region
    for (L2WorldRegion regi : reg.getSurroundingRegions()) {
      // Go through visible objects of the selected region
      Collection<L2Object> vObj = regi.getVisibleObjects().values();
      for (L2Object _object : vObj) {
        if (_object == null || _object.equals(object)) continue; // skip our own character

        if (!_object.isVisible()) continue; // skip dying objects

        result.add(_object);
      }
    }

    return result;
  }
Пример #6
0
  /**
   * Add a L2Object in the world.<br>
   * <br>
   * <B><U> Concept</U> :</B><br>
   * <br>
   * L2Object (including L2PcInstance) are identified in <B>_visibleObjects</B> of his current
   * L2WorldRegion and in <B>_knownObjects</B> of other surrounding L2Characters <br>
   * L2PcInstance are identified in <B>_allPlayers</B> of L2World, in <B>_allPlayers</B> of his
   * current L2WorldRegion and in <B>_knownPlayer</B> of other surrounding L2Characters <br>
   * <br>
   * <B><U> Actions</U> :</B><br>
   * <br>
   * <li>Add the L2Object object in _allPlayers* of L2World
   * <li>Add the L2Object object in _gmList** of GmListTable
   * <li>Add object in _knownObjects and _knownPlayer* of all surrounding L2WorldRegion L2Characters
   *     <br>
   * <li>If object is a L2Character, add all surrounding L2Object in its _knownObjects and all
   *     surrounding L2PcInstance in its _knownPlayer <br>
   *     <I>* only if object is a L2PcInstance</I><br>
   *     <I>** only if object is a GM L2PcInstance</I><br>
   *     <br>
   *     <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T ADD the object in
   *     _visibleObjects and _allPlayers* of L2WorldRegion (need synchronisation)</B></FONT><br>
   *     <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T ADD the object to _allObjects
   *     and _allPlayers* of L2World (need synchronisation)</B></FONT><br>
   *     <br>
   *     <B><U> Example of use </U> :</B><br>
   *     <br>
   * <li>Drop an Item
   * <li>Spawn a L2Character
   * <li>Apply Death Penalty of a L2PcInstance<br>
   *     <br>
   *
   * @param object L2object to add in the world
   * @param newRegion L2WorldRegion in wich the object will be add (not used)
   */
  public void addVisibleObject(L2Object object, L2WorldRegion newRegion) {
    // If selected L2Object is a L2PcIntance, add it in L2ObjectHashSet(L2PcInstance) _allPlayers of
    // L2World
    // XXX TODO: this code should be obsoleted by protection in putObject func...
    if (object instanceof L2PcInstance) {
      L2PcInstance player = (L2PcInstance) object;

      if (!player.isTeleporting()) {
        L2PcInstance tmp = _allPlayers.get(Integer.valueOf(player.getObjectId()));
        if (tmp != null) {
          _log.warn("Duplicate character!? Closing both characters (" + player.getName() + ")");
          player.logout();
          tmp.logout();
          return;
        }
        _allPlayers.put(player.getObjectId(), player);
      }
    }

    if (!newRegion.isActive()) return;

    // Get all visible objects contained in the _visibleObjects of
    // L2WorldRegions in a circular area of 2000 units
    List<L2Object> visibles = getVisibleObjects(object, 2000);

    _log.trace("objects in range:" + visibles.size());

    // tell the player about the surroundings
    // Go through the visible objects contained in the circular area
    for (L2Object visible : visibles) {
      // Add the object in L2ObjectHashSet(L2Object) _knownObjects of the visible L2Character
      // according to conditions :
      // - L2Character is visible
      // - object is not already known
      // - object is in the watch distance
      // If L2Object is a L2PcInstance, add L2Object in L2ObjectHashSet(L2PcInstance) _knownPlayer
      // of the visible
      // L2Character
      visible.getKnownList().addKnownObject(object);

      // Add the visible L2Object in L2ObjectHashSet(L2Object) _knownObjects of the object according
      // to conditions
      // If visible L2Object is a L2PcInstance, add visible L2Object in
      // L2ObjectHashSet(L2PcInstance) _knownPlayer of the
      // object
      object.getKnownList().addKnownObject(visible);
    }
  }