void NonPersistentItemFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { QueryNonPersistentItemFactory* asyncContainer = reinterpret_cast<QueryNonPersistentItemFactory*>(ref); switch(asyncContainer->mQueryType) { case NPQuery_MainData: { Item* item = _createItem(result, asyncContainer->mId); // To be used when doing item factories. if (item->getLoadState() == LoadState_Attributes) { QueryNonPersistentItemFactory* asContainer = new(mQueryContainerPool.ordered_malloc()) QueryNonPersistentItemFactory(asyncContainer->mOfCallback,NPQuery_Attributes,asyncContainer->mId); asContainer->mObject = item; mDatabase->executeSqlAsync(this,asContainer,"SELECT attributes.name,item_family_attribute_defaults.attribute_value,attributes.internal" " FROM %s.item_family_attribute_defaults" " INNER JOIN %s.attributes ON (item_family_attribute_defaults.attribute_id = attributes.id)" " WHERE item_family_attribute_defaults.item_type_id = %u ORDER BY item_family_attribute_defaults.attribute_order", mDatabase->galaxy(),mDatabase->galaxy(),item->getItemType()); } else if (item->getLoadState() == LoadState_Loaded && asyncContainer->mOfCallback) { asyncContainer->mOfCallback->handleObjectReady(item); } } break; case NPQuery_Attributes: { _buildAttributeMap(asyncContainer->mObject,result); if ((asyncContainer->mObject->getLoadState() == LoadState_Loaded) && (asyncContainer->mOfCallback)) { asyncContainer->mOfCallback->handleObjectReady(asyncContainer->mObject); } } break; default: break; } mQueryContainerPool.free(asyncContainer); }
void PersistentNpcFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { QueryContainerBase* asyncContainer = reinterpret_cast<QueryContainerBase*>(ref); switch(asyncContainer->mQueryType) { case PersistentNpcQuery_MainData: { NPCObject* npc = _createPersistentNpc(result); if(npc->getLoadState() == LoadState_Loaded && asyncContainer->mOfCallback) asyncContainer->mOfCallback->handleObjectReady(npc,asyncContainer->mClient); else if(npc->getLoadState() == LoadState_Attributes) { QueryContainerBase* asContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,PersistentNpcQuery_Attributes,asyncContainer->mClient); asContainer->mObject = npc; mDatabase->ExecuteSqlAsync(this,asContainer,"SELECT attributes.name,persistent_npc_attributes.value,attributes.internal" " FROM persistent_npc_attributes" " INNER JOIN attributes ON (persistent_npc_attributes.attribute_id = attributes.id)" " WHERE persistent_npc_attributes.npc_id = %"PRIu64" ORDER BY persistent_npc_attributes.order",npc->getId()); } } break; case PersistentNpcQuery_Attributes: { _buildAttributeMap(asyncContainer->mObject,result); if(asyncContainer->mObject->getLoadState() == LoadState_Loaded && asyncContainer->mOfCallback) asyncContainer->mOfCallback->handleObjectReady(asyncContainer->mObject,asyncContainer->mClient); } break; default: break; } mQueryContainerPool.free(asyncContainer); }
void VehicleControllerFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { QueryContainerBase* asyncContainer = reinterpret_cast<QueryContainerBase*>(ref); switch(asyncContainer->mQueryType) { case VehicleControllerFactoryQuery_Create: { //get id of newly created vehicle DataBinding* binding = mDatabase->CreateDataBinding(1); binding->addField(DFT_uint64,0,8); uint64 id = 0; uint64 count = result->getRowCount(); if(!count) { gLogger->log(LogManager::DEBUG,"VehicleControllerFactory::createVehicle query without result"); mDatabase->DestroyDataBinding(binding); return; } result->GetNextRow(binding,&id); mDatabase->DestroyDataBinding(binding); asyncContainer->mId = id; if(!id) { gLogger->log(LogManager::DEBUG,"VehicleControllerFactory::createVehicle query with invalid result"); mDatabase->DestroyDataBinding(binding); return; } gVehicleControllerFactory->requestObject(asyncContainer->mOfCallback,id,0,0,asyncContainer->mClient); } break; case VehicleControllerFactoryQuery_TypesId: { uint32 vehicleType = 0; DataBinding* binding = mDatabase->CreateDataBinding(1); binding->addField(DFT_uint32,0,4); uint64 count = result->getRowCount(); result->GetNextRow(binding,&vehicleType); mDatabase->DestroyDataBinding(binding); QueryContainerBase* asContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,VehicleControllerFactoryQuery_ItnoData,asyncContainer->mClient,asyncContainer->mId); mDatabase->ExecuteSqlAsync(this,asContainer,"SELECT vehicle_object_string, vehicle_itno_object_string, vehicle_name_file, vehicle_detail_file, vehicle_name FROM vehicle_types WHERE id = %u",vehicleType); } break; case VehicleControllerFactoryQuery_ItnoData: { VehicleController* vehicleController = _createVehicle(result); result->GetNextRow(mVehicleItno_Binding,vehicleController); vehicleController->setId(asyncContainer->mId); vehicleController->setDetail(vehicleController->getName().getAnsi()); QueryContainerBase* aContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,VehicleControllerFactoryQuery_MainData,asyncContainer->mClient,asyncContainer->mId); aContainer->mObject = (Object*)(IntangibleObject*)vehicleController; mDatabase->ExecuteSqlAsync(this,aContainer,"SELECT vehicle_types_id, parent, vehicle_hitpoint_loss, vehicle_incline_acceleration, vehicle_flat_acceleration FROM vehicles WHERE id = %"PRIu64"",vehicleController->getId()); } break; case VehicleControllerFactoryQuery_MainData: { VehicleController* vehicle = dynamic_cast<VehicleController*>(asyncContainer->mObject); uint64 count = result->getRowCount(); if(count == 1) { result->GetNextRow(mVehicleCreo_Binding,vehicle); QueryContainerBase* asyncrContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,VehicleControllerFactoryQuery_Attributes,asyncContainer->mClient,asyncContainer->mId); asyncrContainer->mObject = (Object*)(IntangibleObject*)vehicle; mDatabase->ExecuteSqlAsync(this,asyncrContainer,"SELECT attributes.name, vehicle_attributes.attribute_value, attributes.internal" " FROM attributes" " INNER JOIN vehicle_attributes ON (attributes.id = vehicle_attributes.attribute_id)" " WHERE vehicle_attributes.vehicles_id = %"PRIu64" ORDER BY vehicle_attributes.attribute_order", asyncContainer->mId); } } break; case VehicleControllerFactoryQuery_Attributes: { _buildAttributeMap(asyncContainer->mObject,result); if(asyncContainer->mOfCallback) { if(asyncContainer->mOfCallback == this) handleObjectReady(asyncContainer->mObject,asyncContainer->mClient); else asyncContainer->mOfCallback->handleObjectReady(asyncContainer->mObject,asyncContainer->mClient); } } break; default: break; } mQueryContainerPool.free(asyncContainer); }
void NonPersistentNpcFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { QueryNonPersistentNpcFactory* asyncContainer = reinterpret_cast<QueryNonPersistentNpcFactory*>(ref); switch(asyncContainer->mQueryType) { case NonPersistentNpcQuery_Attributes: { // gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() AT NonPersistentNpcQuery_Attributes:", MSG_NORMAL); Object* object = gWorldManager->getObjectById(asyncContainer->mId); if (object) { _buildAttributeMap(object,result); if (object->getLoadState() == LoadState_Loaded && asyncContainer->mOfCallback) { // gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() Invoking mOfCallback->handleObjectReady(npc)", MSG_NORMAL); asyncContainer->mOfCallback->handleObjectReady(object); } else { // gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() Invoking NOTHING", MSG_NORMAL); } } else { gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() Object is GONE", MSG_NORMAL); } } break; //============================================================================= // // Upgrade version for use of the correct DB. // //============================================================================= case NonPersistentNpcQuery_LairTemplate: { // gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() AT NonPersistentNpcQuery_LairTemplate:", MSG_NORMAL); NpcLairEntityEx lair; DataBinding* lairSpawnBinding = mDatabase->CreateDataBinding(9); lairSpawnBinding->addField(DFT_uint64,offsetof(NpcLairEntityEx,mCreatureSpwanRegion),8,0); lairSpawnBinding->addField(DFT_uint64,offsetof(NpcLairEntityEx,mTemplateId),8,1); lairSpawnBinding->addField(DFT_uint32,offsetof(NpcLairEntityEx,mCreatureGroup),4,2); lairSpawnBinding->addField(DFT_uint32,offsetof(NpcLairEntityEx,mNumberOfLairs),4,3); lairSpawnBinding->addField(DFT_float,offsetof(NpcLairEntityEx,mSpawnPosX),4,4); lairSpawnBinding->addField(DFT_float,offsetof(NpcLairEntityEx,mSpawnPosZ),4,5); lairSpawnBinding->addField(DFT_float,offsetof(NpcLairEntityEx,mSpawnDirY),4,6); lairSpawnBinding->addField(DFT_float,offsetof(NpcLairEntityEx,mSpawnDirW),4,7); lairSpawnBinding->addField(DFT_uint32,offsetof(NpcLairEntityEx,mFamily),4,8); DataBinding* lairSpawnNpcBinding = mDatabase->CreateDataBinding(4); lairSpawnNpcBinding->addField(DFT_bstring,offsetof(NPCObject,mModel),255,9); lairSpawnNpcBinding->addField(DFT_bstring,offsetof(NPCObject,mSpecies),255,10); lairSpawnNpcBinding->addField(DFT_bstring,offsetof(NPCObject,mSpeciesGroup),255,11); lairSpawnNpcBinding->addField(DFT_bstring,offsetof(NPCObject,mFaction),32,12); uint64 count = result->getRowCount(); result->GetNextRow(lairSpawnBinding,&lair); // Let's create the lair. // We save the lairs-type... that's kinda a template for the complete lair. LairObject* npc = new LairObject(asyncContainer->mTemplateId); // Set the new if of this temp object. npc->setId(asyncContainer->mId); // Register object with WorldManager. gWorldManager->addObject(npc, true); // May need the height also, in case of pre set (fixed) spawn position. npc->mPosition.x = lair.mSpawnPosX; npc->mPosition.z = lair.mSpawnPosZ; if (npc->getParentId() == 0) { // Heightmap only works outside. npc->mPosition.y = npc->getHeightAt2DPosition(lair.mSpawnPosX, lair.mSpawnPosZ, true); } else { // We do not have support for handling creatures inside. assert(false && "NonPersistentNpcFactory::handleDatabaseJobComplete NonPersistentNpcQuery_LairTemplate No support for handling creatures inside"); npc->mPosition.y = 0; } npc->mDirection.y = lair.mSpawnDirY; npc->mDirection.w = lair.mSpawnDirW; // Let's get the spawn area. const Anh_Math::Rectangle spawnArea = gWorldManager->getSpawnArea(lair.mCreatureSpwanRegion); // lair.mCreatureSpwanRegion npc->setSpawnArea(spawnArea); result->ResetRowIndex(); result->GetNextRow(lairSpawnNpcBinding,(void*)npc ); mDatabase->DestroyDataBinding(lairSpawnBinding); mDatabase->DestroyDataBinding(lairSpawnNpcBinding); Inventory* npcInventory = new Inventory(); npcInventory->setParent(npc); npc->mHam.mHealth.setCurrentHitPoints(500); npc->mHam.mAction.setCurrentHitPoints(500); npc->mHam.mMind.setCurrentHitPoints(500); npc->mHam.calcAllModifiedHitPoints(); // inventory npcInventory->setId(npc->mId + 1); npcInventory->setParentId(npc->mId); npcInventory->setModelString("object/tangible/inventory/shared_creature_inventory.iff"); npcInventory->setName("inventory"); npcInventory->setNameFile("item_n"); npcInventory->setTangibleGroup(TanGroup_Inventory); npcInventory->setTangibleType(TanType_CreatureInventory); npc->mEquipManager.addEquippedObject(CreatureEquipSlot_Inventory,npcInventory); npc->setType(ObjType_Creature); // This will ensure the use of the single H(am) bar. npc->setCreoGroup(CreoGroup_AttackableObject); npc->mTypeOptions = 0x0; npc->togglePvPStateOn((CreaturePvPStatus)(CreaturePvPStatus_Attackable)); // gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() Attempting to get the creature templates for group %u used by this lair.", MSG_NORMAL, lair.mCreatureGroup); QueryNonPersistentNpcFactory* asContainer = new QueryNonPersistentNpcFactory(asyncContainer->mOfCallback, NonPersistentNpcQuery_LairCreatureTemplates, asyncContainer->mTemplateId, asyncContainer->mId); // Do not transfer object refs, use the handle, i.e. asyncContainer->mId // asContainer->mObject = npc; mDatabase->ExecuteSqlAsync(this, asContainer, "SELECT creature_groups.creature_id " "FROM creature_groups " "WHERE creature_groups.creature_group_id=%u;",lair.mCreatureGroup); } break; case NonPersistentNpcQuery_LairCreatureTemplates: { // Get the lair object. LairObject* npc = dynamic_cast<LairObject*>(gWorldManager->getObjectById(asyncContainer->mId)); assert(npc && "NonPersistentNpcFactory::handleDatabaseJobComplete NonPersistentNpcQuery_LairCreatureTemplates WorldManager unable to find object id"); uint64 creatureTemplateId; DataBinding* creatureTemplateBinding = mDatabase->CreateDataBinding(1); creatureTemplateBinding->addField(DFT_uint64,0,8,0); uint64 count = result->getRowCount(); int32 spawnRateInc = 100/static_cast<uint32>(count); int32 spawnRate = -1; for (uint64 i = 0; i < count; i++) { result->GetNextRow(creatureTemplateBinding, &creatureTemplateId); // gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() Creature template %"PRIu64" used by lair ", MSG_NORMAL, creatureTemplateId); npc->setCreatureTemplate((uint32)i, creatureTemplateId); spawnRate += spawnRateInc; npc->setCreatureSpawnRate((uint32)i, (uint32)spawnRate); } if (count > 0 && spawnRate < 99) { npc->setCreatureSpawnRate(static_cast<uint32>(count) - 1, 99); } mDatabase->DestroyDataBinding(creatureTemplateBinding); // gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() Attempting to get the Attributes", MSG_NORMAL); QueryNonPersistentNpcFactory* asContainer = new QueryNonPersistentNpcFactory(asyncContainer->mOfCallback,NonPersistentNpcQuery_Attributes, 0, npc->getId()); mDatabase->ExecuteSqlAsync(this,asContainer,"SELECT attributes.name,lair_attributes.value,attributes.internal" " FROM lair_attributes" " INNER JOIN attributes ON (lair_attributes.attribute_id = attributes.id)" " WHERE lair_attributes.lair_id = %"PRIu64" ORDER BY lair_attributes.order", asyncContainer->mTemplateId); } break; case NonPersistentNpcQuery_NpcTemplate: { // gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() AT NonPersistentNpcQuery_NpcTemplate:", MSG_NORMAL); NPCObject* npc = _createNonPersistentNpc(result, asyncContainer->mTemplateId, asyncContainer->mId, asyncContainer->mParentObjectId); assert(npc); // Spawn related data. npc->setCellIdForSpawn(asyncContainer->mSpawnCellId); npc->setSpawnPosition(asyncContainer->mSpawnPosition); npc->setSpawnDirection(asyncContainer->mSpawnDirection); npc->setRespawnDelay(asyncContainer->mRespawnDelay); if( npc->getLoadState() == LoadState_Loaded && asyncContainer->mOfCallback) { // gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() Invoking mOfCallback->handleObjectReady(npc)", MSG_NORMAL); asyncContainer->mOfCallback->handleObjectReady(npc); } else if (npc->getLoadState() == LoadState_Attributes) { QueryNonPersistentNpcFactory* asContainer = new QueryNonPersistentNpcFactory(asyncContainer->mOfCallback,NonPersistentNpcQuery_Attributes, 0, npc->getId()); // gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() Invoking NonPersistentNpcQuery_Attributes NPC ID = %"PRIu64"", MSG_NORMAL, npc->getId()); mDatabase->ExecuteSqlAsync(this,asContainer,"SELECT attributes.name,non_persistent_npc_attributes.value,attributes.internal" " FROM non_persistent_npc_attributes" " INNER JOIN attributes ON (non_persistent_npc_attributes.attribute_id = attributes.id)" " WHERE non_persistent_npc_attributes.npc_id = %"PRIu64" ORDER BY non_persistent_npc_attributes.order", asyncContainer->mTemplateId); } } break; default: { gLogger->logMsgF("NonPersistentNpcFactory::handleDatabaseJobComplete() UNKNOWN query = %u\n", MSG_NORMAL, asyncContainer->mQueryType); } break; } delete asyncContainer; }