/** Instance will be destroyed All players moved to bind location All objects - deleted */ private static void destroyInstance(WorldMapInstance instance) { instance.getEmptyInstanceTask().cancel(false); int worldId = instance.getMapId(); int instanceId = instance.getInstanceId(); WorldMap map = World.getInstance().getWorldMap(worldId); map.removeWorldMapInstance(instanceId); log.info("Destroying instance:" + worldId + " " + instanceId); Iterator<VisibleObject> it = instance.objectIterator(); while (it.hasNext()) { VisibleObject obj = it.next(); if (obj instanceof Player) { Player player = (Player) obj; PortalTemplate portal = DataManager.PORTAL_DATA.getInstancePortalTemplate( worldId, player.getCommonData().getRace()); moveToEntryPoint((Player) obj, portal, true); } else { obj.getController().delete(); } } }
/** forget out of distance objects. */ private void forgetObjects() { for (VisibleObject object : knownObjects.values()) { if (!checkObjectInRange(object) && !object.getKnownList().checkReversedObjectInRange(owner)) { del(object, true); object.getKnownList().del(owner, true); } } }
public void delVisualObject(VisibleObject object, boolean isOutOfRange) { if (visualObjects.remove(object.getObjectId()) != null) { if (visualPlayers != null) { visualPlayers.remove(object.getObjectId()); } owner.getController().notSee(object, isOutOfRange); } }
/** Clear known list. Used when object is despawned. */ public final void clearKnownList() { for (VisibleObject object : getKnownObjects().values()) { removeKnownObject(object, false); object.getKnownList().removeKnownObject(getOwner(), false); } getKnownObjects().clear(); }
protected boolean checkObjectInRange(VisibleObject newObject) { // check if Z distance is greater than maxZvisibleDistance if (Math.abs(owner.getZ() - newObject.getZ()) > owner.getMaxZVisibleDistance()) { return false; } return MathUtil.isInRange(owner, newObject, owner.getVisibilityDistance()); }
/** * Delete VisibleObject from this KnownList. * * @param object */ private void del(VisibleObject object, boolean isOutOfRange) { /** object was known. */ if (knownObjects.remove(object.getObjectId()) != null) { if (knownPlayers != null) { knownPlayers.remove(object.getObjectId()); } delVisualObject(object, isOutOfRange); } }
public double getDistanceToTarget() { if (isFollowTarget) { VisibleObject target = owner.getTarget(); if (target != null) return MathUtil.getDistance( owner.getX(), owner.getY(), owner.getZ(), target.getX(), target.getY(), target.getZ()); } return MathUtil.getDistance( owner.getX(), owner.getY(), owner.getZ(), targetX, targetY, targetZ); }
/** Find objects that are in visibility range. */ protected void findVisibleObjects() { if (getOwner() == null || !getOwner().isSpawned()) return; for (MapRegion region : getOwner().getActiveRegion().getNeighbours()) { for (VisibleObject object : region.getVisibleObjects().values()) { if (!object.isSpawned()) continue; addKnownObject(object); object.getKnownList().addKnownObject(getOwner()); } } }
public boolean shouldAffectTarget(VisibleObject object) { // If creature is at least 2 meters above the terrain, ground skill cannot be applied if (GeoDataConfig.GEO_ENABLE) { if (isGroundSkill()) { if ((object.getZ() - GeoService.getInstance().getZ(object) > 1.0f) || (object.getZ() - GeoService.getInstance().getZ(object) < -2.0f)) return false; } return GeoService.getInstance().canSee(getFirstTarget(), object); } return true; }
/** Clear known list. Used when object is despawned. */ public void clear() { for (VisibleObject object : knownObjects.values()) { object.getKnownList().del(owner, false); } knownObjects.clear(); if (knownPlayers != null) { knownPlayers.clear(); } visualObjects.clear(); if (visualPlayers != null) { visualPlayers.clear(); } }
/** * Add VisibleObject to this KnownList. * * @param object */ protected boolean add(VisibleObject object) { if (!isAwareOf(object)) { return false; } if (knownObjects.put(object.getObjectId(), object) == null) { if (object instanceof Player) { checkKnownPlayersInitialized(); knownPlayers.put(object.getObjectId(), (Player) object); } addVisualObject(object); return true; } return false; }
/** Do KnownList update. */ public final synchronized void updateKnownList() { if ((System.currentTimeMillis() - lastUpdate) < 100 || !owner.getActiveRegion().isActive()) return; updateKnownListImpl(); lastUpdate = System.currentTimeMillis(); }
/** * Remove VisibleObject from this KnownList. Object was known. * * @param object * @return */ private final boolean removeKnownObject(VisibleObject object, boolean isOutOfRange) { if (object == null) return false; if (getKnownObjects().remove(object.getObjectId()) == null) return false; getOwner().notSee(object, isOutOfRange); return true; }
/** * Add VisibleObject to this KnownList. Object is unknown. * * @param object * @return */ protected boolean addKnownObject(VisibleObject object) { if (object == null || object == getOwner()) return false; if (!checkObjectInRange(getOwner(), object)) return false; if (getKnownObjects().put(object.getObjectId(), object) != null) return false; getOwner().see(object); return true; }
/** Find objects that are in visibility range. */ protected void findVisibleObjects() { if (owner == null || !owner.isSpawned()) { return; } MapRegion[] regions = owner.getActiveRegion().getNeighbours(); for (int i = 0; i < regions.length; i++) { MapRegion r = regions[i]; FastMap<Integer, VisibleObject> objects = r.getObjects(); for (FastMap.Entry<Integer, VisibleObject> e = objects.head(), mapEnd = objects.tail(); (e = e.getNext()) != mapEnd; ) { VisibleObject newObject = e.getValue(); if (newObject == owner || newObject == null) { continue; } if (!isAwareOf(newObject)) { continue; } if (knownObjects.containsKey(newObject.getObjectId())) { continue; } if (!checkObjectInRange(newObject) && !newObject.getKnownList().checkReversedObjectInRange(owner)) { continue; } /** New object is not known. */ if (add(newObject)) { newObject.getKnownList().add(owner); } } } }
public void addVisualObject(VisibleObject object) { if (object instanceof Creature) { if (SecurityConfig.INVIS && object instanceof Player) { if (!owner.canSee((Player) object)) { return; } } if (visualObjects.put(object.getObjectId(), object) == null) { if (object instanceof Player) { checkVisiblePlayersInitialized(); visualPlayers.put(object.getObjectId(), (Player) object); } owner.getController().see(object); } } else if (visualObjects.put(object.getObjectId(), object) == null) { owner.getController().see(object); } }
/** @param object */ public void addObject(VisibleObject object) { if (worldMapObjects.put(object.getObjectId(), object) != null) throw new DuplicateAionObjectException(); if (object instanceof Player) worldMapPlayers.put(object.getObjectId(), (Player) object); }
/** * Returns MapRegion that contains coordinates of VisibleObject. If the region doesn't exist, it's * created. * * @param object * @return a MapRegion */ MapRegion getRegion(VisibleObject object) { return getRegion(object.getX(), object.getY(), object.getZ()); }
@Override public void onRespawn() { super.onRespawn(); this.gatherCount = 0; }
private final void forgetVisibleObjects() { for (VisibleObject object : getKnownObjects().values()) { forgetVisibleObject(object); object.getKnownList().forgetVisibleObject(getOwner()); } }
/** * Remove AionObject from region objects list. * * @param object */ void remove(VisibleObject object) { objects.remove(object.getObjectId()); }
/** * Add AionObject to this region objects list. * * @param object */ void add(VisibleObject object) { objects.put(object.getObjectId(), object); }
protected final boolean checkObjectInRange(VisibleObject owner, VisibleObject newObject) { // check if Z distance is greater than maxZvisibleDistance if (Math.abs(owner.getZ() - newObject.getZ()) > maxZvisibleDistance) return false; return MathUtil.isInRange(owner, newObject, visibilityDistance); }
private void move() { /** Demo npc skills - prevent movement while casting */ if (!owner.canPerformMove() || owner.isCasting()) { if (!isStopped) { isStopped = true; owner.getController().stopMoving(); } return; } VisibleObject target = owner.getTarget(); if (isFollowTarget && target != null) { setNewDirection(target.getX(), target.getY(), target.getZ()); } float ownerX = owner.getX(); float ownerY = owner.getY(); float ownerZ = owner.getZ(); double dist = MathUtil.getDistance(ownerX, ownerY, ownerZ, targetX, targetY, targetZ); if (dist > this.distance) { isStopped = false; float x2; float y2; float z2; float mod = 1; if (dist < speed * 0.5) { x2 = (targetX - ownerX); y2 = (targetY - ownerY); z2 = (targetZ - ownerZ); } else { x2 = (float) (((targetX - ownerX) / dist) * speed * 0.5); y2 = (float) (((targetY - ownerY) / dist) * speed * 0.5); z2 = (float) (((targetZ - ownerZ) / dist) * speed * 0.5); mod = 0.5f; } byte heading2 = (byte) (Math.toDegrees(Math.atan2(y2, x2)) / 3); if (directionChanged) { PacketSendUtility.broadcastPacket( owner, new SM_MOVE( owner.getObjectId(), ownerX, ownerY, ownerZ, (x2 / mod), (y2 / mod), (z2 / mod), heading2, MovementType.MOVEMENT_START_KEYBOARD)); directionChanged = false; } moveCounter++; World.getInstance() .updatePosition( owner, ownerX + x2, ownerY + y2, ownerZ + z2, heading2, moveCounter % 5 == 0); } else { if (!isStopped) { isStopped = true; owner.getController().stopMoving(); } } }