Ejemplo n.º 1
0
int LuaSceneObject::getPlayersInRange(lua_State *L) {
	int range = lua_tonumber(L, -1);

	Zone* thisZone = realObject->getZone();

	if (thisZone == NULL) {
		lua_pushnil(L);
		return 1;
	}

	lua_newtable(L);

	Reference<SortedVector<ManagedReference<QuadTreeEntry*> >*> closeObjects = new SortedVector<ManagedReference<QuadTreeEntry*> >();
	thisZone->getInRangeObjects(realObject->getWorldPositionX(), realObject->getWorldPositionY(), range, closeObjects, true);
	int numPlayers = 0;

	for (int i = 0; i < closeObjects->size(); ++i) {
		SceneObject* object = cast<SceneObject*>(closeObjects->get(i).get());

		if (object == NULL || !object->isPlayerCreature())
			continue;

		CreatureObject* player = object->asCreatureObject();

		if (player == NULL || player->isInvisible())
			continue;

		numPlayers++;
		lua_pushlightuserdata(L, object);
		lua_rawseti(L, -2, numPlayers);
	}

	return 1;
}
void SpawnAreaImplementation::notifyEnter(SceneObject* object) {
	if (!(tier & SpawnAreaMap::SPAWNAREA)) {
		ActiveAreaImplementation::notifyEnter(object);
		return;
	}

	if (!object->isPlayerCreature())
		return;

	CreatureObject* creo = cast<CreatureObject*>(object);
	if (creo->isInvisible()) {
		return;
	}

	ManagedReference<SceneObject*> parent = object->getParent();

	if (parent != NULL && parent->isCellObject())
		return;

	if (object->getCityRegion() != NULL)
		return;

	ManagedReference<SpawnArea*> spawnArea = _this.getReferenceUnsafeStaticCast();
	ManagedReference<SceneObject*> obj = object;

	EXECUTE_TASK_2(spawnArea, obj, {
			spawnArea_p->tryToSpawn(obj_p);
	});
void PlayerZoneComponent::notifyInsert(SceneObject* sceneObject, QuadTreeEntry* entry) {
	SceneObject* scno = cast<SceneObject*>( entry);

	if (scno == NULL || scno == sceneObject)
		return;

	if (scno->isPlayerCreature()) {
		CreatureObject* player = cast<CreatureObject*>( scno);

		if (player->isInvisible())
			return;
	}

	ManagedReference<SceneObject*> parent = scno->getParent().get();

	if (parent != NULL /*&& parent->isCellObject()*/) {
		return;
	}

	scno->sendTo(sceneObject, true);
}
Ejemplo n.º 4
0
void ZoneComponent::updateZoneWithParent(SceneObject* sceneObject, SceneObject* newParent, bool lightUpdate, bool sendPackets) {
	ManagedReference<Zone*> zone = sceneObject->getZone();
	ManagedReference<SceneObject*> oldParent = sceneObject->getParent();

	if (oldParent != NULL && !oldParent->isCellObject())
		return;

	if (zone == NULL)
		zone = newParent->getRootParent().get()->getZone();

	Locker _locker(zone);

	if (oldParent == NULL) { // we are in zone, enter cell
		//zone->remove(sceneObject);

		newParent->transferObject(sceneObject, -1, true);

		zone->unlock();
		//insertToBuilding(sceneObject, dynamic_cast<BuildingObject*>(newParent->getParent()));
	} else { // we are in cell already
		if (oldParent != newParent) {
			//oldParent->removeObject(sceneObject, false);
			newParent->transferObject(sceneObject, -1, true);

			zone->unlock();
		} else {
			zone->unlock();

			zone->updateActiveAreas(sceneObject);
		}

		//notify in range objects that i moved
	}

	CloseObjectsVector* closeObjects = (CloseObjectsVector*) sceneObject->getCloseObjects();

	if (closeObjects != NULL) {
		SortedVector<ManagedReference<QuadTreeEntry*> > objects(closeObjects->size(), 10);
		closeObjects->safeCopyTo(objects);

		for (int i = 0; i < objects.size(); ++i) {
			QuadTreeEntry* object = objects.get(i);
			try {
				object->notifyPositionUpdate(sceneObject);
			} catch (Exception& e) {

			}
		}
	}

	//zoneLocker.release();

	//zone->unlock();

	bool isInvis = false;

	if (sceneObject->isCreatureObject()) {
		CreatureObject* creo = cast<CreatureObject*>(sceneObject);
		if(creo->isInvisible())
			isInvis = true;
	}

	if (sendPackets && !isInvis) {
		if (lightUpdate) {
			LightUpdateTransformWithParentMessage* message = new LightUpdateTransformWithParentMessage(sceneObject);
			sceneObject->broadcastMessage(message, false, true);
		} else {
			UpdateTransformWithParentMessage* message = new UpdateTransformWithParentMessage(sceneObject);
			sceneObject->broadcastMessage(message, false, true);
		}
	}

	try {
		notifySelfPositionUpdate(sceneObject);
	} catch (Exception& e) {
		sceneObject->error("Exception caught while calling notifySelfPositionUpdate(sceneObject) in ZoneComponent::updateZoneWithParent");
		sceneObject->error(e.getMessage());
	}

	zone->wlock();
}
Ejemplo n.º 5
0
void ZoneComponent::updateZone(SceneObject* sceneObject, bool lightUpdate, bool sendPackets) {
	ManagedReference<SceneObject*> parent = sceneObject->getParent();
	Zone* zone = sceneObject->getZone();
	ManagedReference<SceneObject*> sceneObjectRootParent = sceneObject->getRootParent();

	if (zone == NULL) {
		if (sceneObjectRootParent == NULL)
			return;

		zone = sceneObjectRootParent->getZone();
	}

	if (parent != NULL && (parent->isVehicleObject() || parent->isMount()))
		sceneObject->updateVehiclePosition(sendPackets);

	Locker _locker(zone);

	bool zoneUnlocked = false;

	if (parent != NULL && parent->isCellObject()) {
		//parent->removeObject(sceneObject, true);
		//removeFromBuilding(sceneObject, dynamic_cast<BuildingObject*>(parent->getParent()));

		zone = parent->getRootParent().get()->getZone();

		zone->transferObject(sceneObject, -1, false);

		zone->unlock();
	} else {
		if (sceneObject->getLocalZone() != NULL) {
			zone->update(sceneObject);

			zone->unlock();

			zone->inRange(sceneObject, 192);
		} else if (parent != NULL) {
			zone->unlock();

			updateInRangeObjectsOnMount(sceneObject);
		}
	}

	zone->updateActiveAreas(sceneObject);
	
	bool isInvis = false;

	if (sceneObject->isCreatureObject()) {
		CreatureObject* creo = cast<CreatureObject*>(sceneObject);
		
		if(creo->isInvisible())
			isInvis = true;
		}


	if (!isInvis && sendPackets && (parent == NULL || (!parent->isVehicleObject() && !parent->isMount()))) {
		if (lightUpdate) {
			LightUpdateTransformMessage* message = new LightUpdateTransformMessage(sceneObject);
			sceneObject->broadcastMessage(message, false, true);
		} else {
			UpdateTransformMessage* message = new UpdateTransformMessage(sceneObject);
			sceneObject->broadcastMessage(message, false, true);
		}
	}

	try {
		notifySelfPositionUpdate(sceneObject);
	} catch (Exception& e) {
		sceneObject->error("Exception caught while calling notifySelfPositionUpdate(sceneObject) in ZoneComponent::updateZone");
		sceneObject->error(e.getMessage());
	}

	zone->wlock();
}