Esempio n. 1
0
//-------------------------------------------------------------------------------------
void Entity::teleport(PyObject_ptr nearbyMBRef, Position3D& pos, Direction3D& dir)
{
	SPACE_ID lastSpaceID = this->getSpaceID();

	// 如果为None则是entity自己想在本space上跳转到某位置
	if(nearbyMBRef == Py_None)
	{
		this->setPositionAndDirection(pos, dir);
	}
	else
	{
		//EntityMailbox* mb = NULL;
		SPACE_ID spaceID = 0;
		
		// 如果是entity则一定是在本cellapp上, 可以直接进行操作
		if(PyObject_TypeCheck(nearbyMBRef, Entity::getScriptType()))
		{
			Entity* entity = static_cast<Entity*>(nearbyMBRef);
			spaceID = entity->getSpaceID();
			if(spaceID == this->getSpaceID())
			{
				this->setPositionAndDirection(pos, dir);
				onTeleportSuccess(nearbyMBRef, lastSpaceID);
			}
			else
			{
				this->setPositionAndDirection(pos, dir);
				Space* currspace = Spaces::findSpace(this->getSpaceID());
				Space* space = Spaces::findSpace(spaceID);
				currspace->removeEntity(this);
				space->addEntity(this);
				onTeleportSuccess(nearbyMBRef, lastSpaceID);
			}
		}
		else
		{
			if(PyObject_TypeCheck(nearbyMBRef, EntityMailbox::getScriptType()))
			{
			}
		}
	}
}
Esempio n. 2
0
//-------------------------------------------------------------------------------------
void Entity::onDestroy(void)
{
	SCOPED_PROFILE(SCRIPTCALL_PROFILE);

	SCRIPT_OBJECT_CALL_ARGS0(this, const_cast<char*>("onDestroy"));

	if(baseMailbox_ != NULL)
	{
		this->backupCellData();

		Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
		(*pBundle).newMessage(BaseappInterface::onLoseCell);
		(*pBundle) << id_;
		baseMailbox_->postMail((*pBundle));
		Mercury::Bundle::ObjPool().reclaimObject(pBundle);
	}

	// 将entity从场景中剔除
	Space* space = Spaces::findSpace(this->getSpaceID());
	if(space)
	{
		space->removeEntity(this);
	}
}
Esempio n. 3
0
//-------------------------------------------------------------------------------------
void Entity::teleportFromBaseapp(Mercury::Channel* pChannel, COMPONENT_ID cellAppID, ENTITY_ID targetEntityID, COMPONENT_ID sourceBaseAppID)
{
	DEBUG_MSG(boost::format("%1%::teleportFromBaseapp: %2%, targetEntityID=%3%, cell=%4%, sourceBaseAppID=%5%.\n") % 
		this->getScriptName() % this->getID() % targetEntityID % cellAppID % sourceBaseAppID);
	
	SPACE_ID lastSpaceID = this->getSpaceID();

	// 如果不在一个cell上
	if(cellAppID != g_componentID)
	{
		Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(cellAppID);
		if(cinfos == NULL || cinfos->pChannel == NULL)
		{
			ERROR_MSG(boost::format("%1%::teleportFromBaseapp: %2%, teleport is error, not found cellapp, targetEntityID, cellAppID=%3%.\n") %
				this->getScriptName() % this->getID() % targetEntityID % cellAppID);

			_sendBaseTeleportResult(this->getID(), sourceBaseAppID, 0, lastSpaceID);
			return;
		}
	}
	else
	{
		Entity* entity = Cellapp::getSingleton().findEntity(targetEntityID);
		if(entity == NULL || entity->isDestroyed())
		{
			ERROR_MSG(boost::format("%1%::teleportFromBaseapp: %2%, can't found targetEntity(%3%).\n") %
				this->getScriptName() % this->getID() % targetEntityID);

			_sendBaseTeleportResult(this->getID(), sourceBaseAppID, 0, lastSpaceID);
			return;
		}
		
		// 找到space
		SPACE_ID spaceID = entity->getSpaceID();

		// 如果是不同space跳转
		if(spaceID != this->getSpaceID())
		{
			Space* space = Spaces::findSpace(spaceID);
			if(space == NULL)
			{
				ERROR_MSG(boost::format("%1%::teleportFromBaseapp: %2%, can't found space(%3%).\n") %
					this->getScriptName() % this->getID() % spaceID);

				_sendBaseTeleportResult(this->getID(), sourceBaseAppID, 0, lastSpaceID);
				return;
			}
			
			Space* currspace = Spaces::findSpace(this->getSpaceID());
			currspace->removeEntity(this);
			space->addEntity(this);
			_sendBaseTeleportResult(this->getID(), sourceBaseAppID, spaceID, lastSpaceID);
		}
		else
		{
			WARNING_MSG(boost::format("%1%::teleportFromBaseapp: %2% targetSpace(%3%) == currSpaceID(%4%).\n") %
				this->getScriptName() % this->getID() % spaceID % this->getSpaceID());

			_sendBaseTeleportResult(this->getID(), sourceBaseAppID, spaceID, lastSpaceID);
		}
	}
}