Esempio n. 1
0
void InventoryFactory::handleObjectReady(Object* object,DispatchClient* client)
{
	//we either have the ID of the inventory or of the player
	//the inventory of course is stored under its own Id

	InLoadingContainer* ilc	= _getObject(object->getParentId());

	assert(ilc && "InventoryFactory::handleObjectReady unable to find InLoadingContainer");
	if (! ilc) {
		return;
	}

	Inventory*			inventory	= dynamic_cast<Inventory*>(ilc->mObject);

	gWorldManager->addObject(object,true);

	//for unequipped items only
	inventory->addObjectSecure(object);

	if(inventory->getObjectLoadCounter() == (inventory->getObjects())->size())
	{
		gLogger->logMsgF("InventoryFactory: remove inventory %I64u from loadmap",MSG_HIGH,inventory->getId());

		inventory->setLoadState(LoadState_Loaded);

		if(!(_removeFromObjectLoadMap(inventory->getId())))
			gLogger->logMsg("InventoryFactory: Failed removing object from loadmap");

		ilc->mOfCallback->handleObjectReady(inventory,ilc->mClient);

		mILCPool.free(ilc);
	}
}
Esempio n. 2
0
void InventoryFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result)
{
	QueryContainerBase* asyncContainer = reinterpret_cast<QueryContainerBase*>(ref);

	switch(asyncContainer->mQueryType)
	{
		case IFQuery_MainInventoryData:
		{
			Inventory* inventory = _createInventory(result);

			QueryContainerBase* asContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,IFQuery_ObjectCount,asyncContainer->mClient);
			asContainer->mObject = inventory;

			mDatabase->ExecuteSqlAsync(this,asContainer,"SELECT sf_getInventoryObjectCount(%"PRIu64")",inventory->getId());
		}
		break;

		case IFQuery_ObjectCount:
		{
			Inventory* inventory = dynamic_cast<Inventory*>(asyncContainer->mObject);

			uint32 objectCount;
			DataBinding* binding = mDatabase->CreateDataBinding(1);

			binding->addField(DFT_uint32,0,4);
			result->GetNextRow(binding,&objectCount);

			inventory->setObjectLoadCounter(objectCount);

			if(objectCount != 0)
			{
				uint64 invId = inventory->getId();

				inventory->setLoadState(LoadState_Loading);

				// query contents				
				QueryContainerBase* asContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,IFQuery_Objects,asyncContainer->mClient);
				asContainer->mObject = inventory;

				//why would we load the lootcontainers and trashpiles for the inventory ???
				//containers are normal items like furniture, lightsabers and stuff
				mDatabase->ExecuteSqlAsync(this,asContainer,
						"(SELECT \'containers\',containers.id FROM containers INNER JOIN container_types ON (containers.container_type = container_types.id)"
						" WHERE (container_types.name NOT LIKE 'unknown') AND (containers.parent_id = %"PRIu64"))"
						" UNION (SELECT \'items\',items.id FROM items WHERE (parent_id=%"PRIu64"))"
						" UNION (SELECT \'resource_containers\',resource_containers.id FROM resource_containers WHERE (parent_id=%"PRIu64"))",
						invId,invId,invId);
				
			}
			else
			{
				inventory->setLoadState(LoadState_Loaded);
				asyncContainer->mOfCallback->handleObjectReady(inventory,asyncContainer->mClient);
			}

			mDatabase->DestroyDataBinding(binding);
		}
		break;

		case IFQuery_Objects:
		{
			Inventory* inventory = dynamic_cast<Inventory*>(asyncContainer->mObject);

			Type1_QueryContainer queryContainer;

			DataBinding*	binding = mDatabase->CreateDataBinding(2);
			binding->addField(DFT_bstring,offsetof(Type1_QueryContainer,mString),64,0);
			binding->addField(DFT_uint64,offsetof(Type1_QueryContainer,mId),8,1);

			uint64 count = result->getRowCount();

			//InLoadingContainer* ilc = new(mILCPool.ordered_malloc()) InLoadingContainer(inventory,asyncContainer->mOfCallback,asyncContainer->mClient);
			//ilc->mLoadCounter = count;

			mObjectLoadMap.insert(std::make_pair(inventory->getId(),new(mILCPool.ordered_malloc()) InLoadingContainer(inventory,asyncContainer->mOfCallback,asyncContainer->mClient,static_cast<uint8>(count))));

			for(uint32 i = 0;i < count;i++)
			{
				result->GetNextRow(binding,&queryContainer);

				if(strcmp(queryContainer.mString.getAnsi(),"containers") == 0)
					mTangibleFactory->requestObject(this,queryContainer.mId,TanGroup_Container,0,asyncContainer->mClient);
				else if(strcmp(queryContainer.mString.getAnsi(),"items") == 0)
					mTangibleFactory->requestObject(this,queryContainer.mId,TanGroup_Item,0,asyncContainer->mClient);
				else if(strcmp(queryContainer.mString.getAnsi(),"resource_containers") == 0)
					mTangibleFactory->requestObject(this,queryContainer.mId,TanGroup_ResourceContainer,0,asyncContainer->mClient);
				
					
			
			}
			
			mDatabase->DestroyDataBinding(binding);
		}
		break;

		default:break;
	}

	mQueryContainerPool.free(asyncContainer);
}