void InstallationObjectImplementation::clearResourceHopper() { Time timeToWorkTill; if (resourceHopper.size() == 0) return; setOperating(false); //lets delete the containers from db for (int i = 0; i < resourceHopper.size(); ++i) { ResourceContainer* container = resourceHopper.get(i); if (container != NULL) { Locker locker(container); container->destroyObjectFromDatabase(true); } } InstallationObjectDeltaMessage7* inso7 = new InstallationObjectDeltaMessage7( _this.get()); inso7->updateHopper(); inso7->startUpdate(0x0D); resourceHopper.removeAll(inso7); inso7->updateActiveResourceSpawn(getActiveResourceSpawnID()); inso7->updateHopperSize(getHopperSize()); inso7->updateExtractionRate(getActualRate()); inso7->close(); broadcastToOperators(inso7); }
void ResourceManagerImplementation::givePlayerResource(CreatureObject* playerCreature, const String& restype, const int quantity) { ManagedReference<ResourceSpawn* > spawn = getResourceSpawn(restype); if(spawn == NULL) { playerCreature->sendSystemMessage("Selected spawn does not exist."); return; } ManagedReference<SceneObject*> inventory = playerCreature->getSlottedObject("inventory"); if(inventory != NULL && !inventory->hasFullContainerObjects()) { Locker locker(spawn); ResourceContainer* newResource = spawn->createResource(quantity); if(newResource != NULL) { spawn->extractResource("", quantity); Locker rlocker(newResource); if (inventory->transferObject(newResource, -1, true)) { inventory->broadcastObject(newResource, true); } else { newResource->destroyObjectFromDatabase(true); } } } }
uint32 ResourceManagerImplementation::getAvailablePowerFromPlayer(CreatureObject* player) { SceneObject* inventory = player->getSlottedObject("inventory"); uint32 power = 0; for (int i = 0; i < inventory->getContainerObjectsSize(); i++) { Reference<SceneObject*> obj = inventory->getContainerObject(i).castTo<SceneObject*>(); if (obj == NULL || !obj->isResourceContainer()) continue; ResourceContainer* rcno = cast<ResourceContainer*>( obj.get()); ManagedReference<ResourceSpawn*> spawn = rcno->getSpawnObject(); if (spawn == NULL || !spawn->isEnergy()) continue; int quantity = rcno->getQuantity(); int pe = spawn->getValueOf(CraftingManager::PE); // potential energy float modifier = MAX(1.0f, pe / 500.0f); power += (uint32) (modifier * quantity); } return power; }
ResourceContainer* InstallationObjectImplementation::getContainerFromHopper(ResourceSpawn* spawn) { for (int i = 0; i < resourceHopper.size(); ++i) { ResourceContainer* entry = resourceHopper.get(i); if (entry->getSpawnObject() == spawn) return entry; } return NULL; }
int InstallationObjectImplementation::getHopperItemQuantity(ResourceSpawn* spawn) { for (int i = 0; i < resourceHopper.size(); ++i) { ResourceContainer* entry = resourceHopper.get(i); if (entry->getSpawnObject() == spawn) return entry->getQuantity(); } return -1; }
float InstallationObjectImplementation::getHopperSize() { float hopperSize = 0.0f; for (int i = 0; i < resourceHopper.size(); i++) { ResourceContainer* entry = resourceHopper.get(i); hopperSize += entry->getQuantity(); } return hopperSize; }
void InstallationObjectImplementation::destroyObjectFromDatabase(bool destroyContainedObjects) { StructureObjectImplementation::destroyObjectFromDatabase(destroyContainedObjects); if (!destroyContainedObjects) return; ManagedReference<SceneObject*> deed = getZoneServer()->getObject(deedObjectID); if (deed != NULL) { Locker locker(deed); deed->destroyObjectFromDatabase(true); } for (int i = 0; i < resourceHopper.size(); ++i) { ResourceContainer* container = resourceHopper.get(i); Locker locker(container); container->destroyObjectFromDatabase(true); } }
void HarvesterObjectImplementation::synchronizedUIListen(CreatureObject* player, int value) { if (!player->isPlayerCreature() || !isOnAdminList(player) || getZone() == NULL) return; addOperator(player); updateInstallationWork(); HarvesterObjectMessage7* msg = new HarvesterObjectMessage7(_this.getReferenceUnsafeStaticCast()); player->sendMessage(msg); /// Have to send the spawns of items no in shift, or the dont show /// up in the hopper when you look. for (int i = 0; i < resourceHopper.size(); ++i) { ResourceContainer* container = resourceHopper.get(i); if (container != NULL) { container->sendTo(player, true); } } activateUiSync(); }
//=============================================================================== //collects a resourcelist to give to a manufacturing schematic // void CraftingSession::updateResourceContainer(uint64 containerID, uint32 newAmount) { // destroy if its empty if(!newAmount) { ResourceContainer* resContainer = dynamic_cast<ResourceContainer*>(gWorldManager->getObjectById(containerID)); TangibleObject* container = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(resContainer->getParentId())); //now destroy it client side gContainerManager->deleteObject(resContainer, container); } // update it else { ResourceContainer* resContainer = dynamic_cast<ResourceContainer*>(gWorldManager->getObjectById(containerID)); resContainer->setAmount(newAmount); gMessageLib->sendResourceContainerUpdateAmount(resContainer,mOwner); mDatabase->executeSqlAsync(NULL,NULL,"UPDATE %s.resource_containers SET amount=%u WHERE id=%" PRIu64 "",mDatabase->galaxy(),newAmount,resContainer->getId()); } }
void ResourceManagerImplementation::removePowerFromPlayer(CreatureObject* player, uint32 power) { if (power == 0) return; SceneObject* inventory = player->getSlottedObject("inventory"); uint32 containerPower = 0; for (int i = 0; i < inventory->getContainerObjectsSize() && power > 0; ++i) { ManagedReference<SceneObject*> obj = inventory->getContainerObject(i); if (obj == NULL || !obj->isResourceContainer()) continue; ResourceContainer* rcno = cast<ResourceContainer*>( obj.get()); Locker locker(rcno); ManagedReference<ResourceSpawn*> spawn = rcno->getSpawnObject(); if (spawn == NULL || !spawn->isEnergy()) continue; int quantity = rcno->getQuantity(); int pe = spawn->getValueOf(CraftingManager::PE); // potential energy float modifier = MAX(1.0f, pe / 500.0f); containerPower = modifier * quantity; if (containerPower > power) { uint32 consumedUnits = (uint64) power / modifier; rcno->setQuantity(quantity - consumedUnits); ResourceContainerObjectDeltaMessage3* drcno3 = new ResourceContainerObjectDeltaMessage3(rcno); drcno3->updateQuantity(); drcno3->close(); player->sendMessage(drcno3); return; } else { rcno->destroyObjectFromWorld(true); rcno->destroyObjectFromDatabase(true); } power -= containerPower; } }
void ObjectController::_handleResourceContainerSplit(uint64 targetId,Message* message,ObjectControllerCmdProperties* cmdProperties) { PlayerObject* playerObject = dynamic_cast<PlayerObject*>(mObject); ResourceContainer* selectedContainer = dynamic_cast<ResourceContainer*>(gWorldManager->getObjectById(targetId)); Inventory* inventory = dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); gLogger->logMsgF("ObjectController::_handleResourceContainerSplit: Container : %I64u",MSG_NORMAL,targetId); if(!selectedContainer) { gLogger->logMsg("ObjectController::_handleResourceContainerSplit: Container does not exist!"); return; } string dataStr; message->getStringUnicode16(dataStr); dataStr.convert(BSTRType_ANSI); BStringVector dataElements; uint16 elementCount = dataStr.split(dataElements,' '); if(!elementCount) { gLogger->logMsg("ObjectController::_handleResourceContainerSplit: Error in requestStr"); return; } uint32 splitOffAmount = boost::lexical_cast<uint32>(dataElements[0].getAnsi()); uint64 parentId = boost::lexical_cast<uint64>(dataElements[1].getAnsi()); if(selectedContainer->getParentId() == inventory->getId()) { //check if we can fit an additional resource container in our inventory if(!inventory->checkSlots(1)) { gMessageLib->sendSystemMessage(playerObject,L"","error_message","inv_full"); return; } mDatabase->ExecuteSqlAsync(NULL,NULL,"UPDATE resource_containers SET amount=%u WHERE id=%"PRIu64"",selectedContainer->getAmount(),selectedContainer->getId()); // create a new one // update selected container contents selectedContainer->setAmount(selectedContainer->getAmount() - splitOffAmount); gMessageLib->sendResourceContainerUpdateAmount(selectedContainer,playerObject); gObjectFactory->requestNewResourceContainer(inventory,(selectedContainer->getResource())->getId(),parentId,99,splitOffAmount); return; } Item* item = dynamic_cast<Item*>(gWorldManager->getObjectById(parentId)); if(!item) { gLogger->logMsg("ObjectController::_ExtractObject: resourcecontainers parent does not exist!"); assert(false && "ObjectController::_ExtractObject resourcecontainers parent does not exist"); return; } if(!item->checkCapacity()) { //check if we can fit an additional item in our inventory gMessageLib->sendSystemMessage(playerObject,L"","container_error_message","container3"); return; } // update selected container contents selectedContainer->setAmount(selectedContainer->getAmount() - splitOffAmount); gMessageLib->sendResourceContainerUpdateAmount(selectedContainer,playerObject); gObjectFactory->requestNewResourceContainer(item,(selectedContainer->getResource())->getId(),parentId,99,splitOffAmount); }
void CraftingSession::bagResource(ManufactureSlot* manSlot,uint64 containerId) { //iterates through the slots filled resources //respectively create a new one if necessary //TODO : what happens if the container is full ? FilledResources::iterator resIt = manSlot->mFilledResources.begin(); manSlot->setFilledType(DST_Empty); while(resIt != manSlot->mFilledResources.end()) { uint32 amount = (*resIt).second; // see if we can add it to an existing container ObjectIDList* invObjects = dynamic_cast<Inventory*>(mOwner->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->getObjects(); ObjectIDList::iterator listIt = invObjects->begin(); bool foundSameType = false; while(listIt != invObjects->end()) { // we are looking for resource containers ResourceContainer* resCont = dynamic_cast<ResourceContainer*>(gWorldManager->getObjectById((*listIt))); if(resCont) { uint32 targetAmount = resCont->getAmount(); uint32 maxAmount = resCont->getMaxAmount(); uint32 newAmount; if((resCont->getResourceId() == (*resIt).first) && (targetAmount < maxAmount)) { foundSameType = true; newAmount = targetAmount + amount; if(newAmount <= maxAmount) { // update target container resCont->setAmount(newAmount); gMessageLib->sendResourceContainerUpdateAmount(resCont,mOwner); gWorldManager->getDatabase()->executeSqlAsync(NULL,NULL,"UPDATE %s.resource_containers SET amount=%u WHERE id=%" PRIu64 "",mDatabase->galaxy(),newAmount,resCont->getId()); } // target container full, put in what fits, create a new one else if(newAmount > maxAmount) { uint32 selectedNewAmount = newAmount - maxAmount; resCont->setAmount(maxAmount); gMessageLib->sendResourceContainerUpdateAmount(resCont,mOwner); gWorldManager->getDatabase()->executeSqlAsync(NULL,NULL,"UPDATE %s.resource_containers SET amount=%u WHERE id=%" PRIu64 "",mDatabase->galaxy(),maxAmount,resCont->getId()); gObjectFactory->requestNewResourceContainer(dynamic_cast<Inventory*>(mOwner->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)),(*resIt).first,mOwner->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)->getId(),99,selectedNewAmount); } break; } } ++listIt; } // or need to create a new one if(!foundSameType) { gObjectFactory->requestNewResourceContainer(dynamic_cast<Inventory*>(mOwner->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)),(*resIt).first,mOwner->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)->getId(),99,amount); } ++resIt; } }
void CraftingSession::handleFillSlotResourceRewrite(uint64 resContainerId,uint32 slotId,uint32 unknown,uint8 counter) { // update resource container ResourceContainer* resContainer = dynamic_cast<ResourceContainer*>(gWorldManager->getObjectById(resContainerId)); ManufactureSlot* manSlot = mManufacturingSchematic->getManufactureSlots()->at(slotId); //bool resourceBool = false; bool smallupdate = false; if(!resContainer) { gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_Ingredient_Not_In_Inventory,counter,mOwner); } if(!manSlot) { gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_Invalid_Slot,counter,mOwner); } uint32 availableAmount = resContainer->getAmount(); uint32 totalNeededAmount = manSlot->mDraftSlot->getNecessaryAmount(); uint32 existingAmount = 0; uint64 containerResId = resContainer->getResourceId(); // see if something is filled already existingAmount = manSlot->getFilledAmount(); //check whether we have the same resource - if it's different replace the current resource with the new one if(manSlot->getResourceId() && (containerResId != manSlot->getResourceId())) { // remove the old resource from the slot and input the new one. emptySlot(slotId, manSlot, manSlot->getResourceId()); //gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_Internal_Invalid_Ingredient,counter,mOwner); //return; } else { // update the needed amount totalNeededAmount -= existingAmount; } // fail if its already complete if(!totalNeededAmount) { gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_Slot_Already_Full,counter,mOwner); return; } uint32 takeAmount = 0; if(availableAmount >= totalNeededAmount) { takeAmount = totalNeededAmount; } else { takeAmount = availableAmount; } // add it to the slot get the update type smallupdate = manSlot->addResourcetoSlot(containerResId,takeAmount,manSlot->mDraftSlot->getType()); // update the container amount uint32 newContainerAmount = availableAmount - takeAmount; updateResourceContainer(resContainer->getId(),newContainerAmount); // update the slot total resource amount manSlot->setFilledAmount(manSlot->getFilledAmount()+takeAmount); if(manSlot->getFilledAmount() == manSlot->mDraftSlot->getNecessaryAmount()) { // update the total count of filled slots mManufacturingSchematic->addFilledSlot(); gMessageLib->sendUpdateFilledManufactureSlots(mManufacturingSchematic,mOwner); } // update the slot contents, send all slots on first fill // we need to make sure we only update lists with changes, so the lists dont desynchronize! if(!mFirstFill) { mFirstFill = true; gMessageLib->sendDeltasMSCO_7(mManufacturingSchematic,mOwner); } else if(smallupdate == true) { gMessageLib->sendManufactureSlotUpdateSmall(mManufacturingSchematic,static_cast<uint8>(slotId),mOwner); } else { gMessageLib->sendManufactureSlotUpdate(mManufacturingSchematic,static_cast<uint8>(slotId),mOwner); } // done gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_None,counter,mOwner); }
void CraftingSession::handleFillSlotResource(uint64 resContainerId,uint32 slotId,uint32 unknown,uint8 counter) { // update resource container ResourceContainer* resContainer = dynamic_cast<ResourceContainer*>(gWorldManager->getObjectById(resContainerId)); ManufactureSlot* manSlot = mManufacturingSchematic->getManufactureSlots()->at(slotId); FilledResources::iterator filledResIt = manSlot->mFilledResources.begin(); //bool resourceBool = false; bool smallupdate = false; if(!resContainer) { gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_Ingredient_Not_In_Inventory,counter,mOwner); } if(!manSlot) { gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_Invalid_Slot,counter,mOwner); } uint32 availableAmount = resContainer->getAmount(); uint32 totalNeededAmount = manSlot->mDraftSlot->getNecessaryAmount(); uint32 existingAmount = 0; uint64 containerResId = resContainer->getResourceId(); // see if something is filled already existingAmount = manSlot->getFilledAmount(); // update the needed amount totalNeededAmount -= existingAmount; // fail if its already complete if(!totalNeededAmount) { gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_Slot_Already_Full,counter,mOwner); return; } //check whether we have the same resource - no go if its different - check for the slot being empty though if(manSlot->getResourceId() && (containerResId != manSlot->getResourceId())) { gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_Internal_Invalid_Ingredient,counter,mOwner); return; } // see how much this container has to offer // slot completely filled if(availableAmount >= totalNeededAmount) { // add to the filled resources filledResIt = manSlot->mFilledResources.begin(); while(filledResIt != manSlot->mFilledResources.end()) { // already got something of that type filled if(containerResId == (*filledResIt).first) { //hark in live the same resource gets added to a second slot manSlot->mFilledResources.push_back(std::make_pair(containerResId,totalNeededAmount)); filledResIt = manSlot->mFilledResources.begin(); manSlot->setFilledType(DST_Resource);//4 resource has been filled smallupdate = true; break; } ++filledResIt; } // nothing of that resource filled, add a new entry if(filledResIt == manSlot->mFilledResources.end()) { //resourceBool = true; // only allow one unique type if(manSlot->mFilledResources.empty()) { manSlot->mFilledResources.push_back(std::make_pair(containerResId,totalNeededAmount)); manSlot->setFilledType(DST_Resource); manSlot->mFilledIndicatorChange = true; } else { gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_Bad_Resource_Chosen,counter,mOwner); return; } } // update the container amount uint32 newContainerAmount = availableAmount - totalNeededAmount; // destroy if its empty if(!newContainerAmount) { //now destroy it client side TangibleObject* container = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(resContainer->getParentId())); //just delete it gContainerManager->deleteObject(resContainer, container); } // update it else { resContainer->setAmount(newContainerAmount); gMessageLib->sendResourceContainerUpdateAmount(resContainer,mOwner); mDatabase->executeSqlAsync(NULL,NULL,"UPDATE %s.resource_containers SET amount=%u WHERE id=%" PRIu64 "",mDatabase->galaxy(),newContainerAmount,resContainer->getId()); } // update the slot total resource amount manSlot->setFilledAmount(manSlot->mDraftSlot->getNecessaryAmount()); // update the total count of filled slots mManufacturingSchematic->addFilledSlot(); gMessageLib->sendUpdateFilledManufactureSlots(mManufacturingSchematic,mOwner); } // got only a bit else { // add to the filled resources uint64 containerResId = resContainer->getResourceId(); filledResIt = manSlot->mFilledResources.begin(); while(filledResIt != manSlot->mFilledResources.end()) { // already got something of that type filled if(containerResId == (*filledResIt).first) { //(*filledResIt).second += availableAmount; manSlot->mFilledResources.push_back(std::make_pair(containerResId,availableAmount)); filledResIt = manSlot->mFilledResources.begin(); manSlot->setFilledType(DST_Resource); smallupdate = true; break; } ++filledResIt; } // nothing of that resource filled, add a new entry if(filledResIt == manSlot->mFilledResources.end()) { // only allow one unique type if(manSlot->mFilledResources.empty()) { manSlot->mFilledResources.push_back(std::make_pair(containerResId,availableAmount)); manSlot->setFilledType(DST_Resource); } else { gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_Bad_Resource_Chosen,counter,mOwner); return; } } // destroy the container as its empty now TangibleObject* container = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(resContainer->getParentId())); gContainerManager->deleteObject(resContainer, container); // update the slot total resource amount manSlot->mFilled += availableAmount; } // update the slot contents, send all slots on first fill // we need to make sure we only update lists with changes, so the lists dont desynchronize! if(!mFirstFill) { mFirstFill = true; gMessageLib->sendDeltasMSCO_7(mManufacturingSchematic,mOwner); } else if(smallupdate == true) { gMessageLib->sendManufactureSlotUpdateSmall(mManufacturingSchematic,static_cast<uint8>(slotId),mOwner); } else { gMessageLib->sendManufactureSlotUpdate(mManufacturingSchematic,static_cast<uint8>(slotId),mOwner); } // done gMessageLib->sendCraftAcknowledge(opCraftFillSlot,CraftError_None,counter,mOwner); }
void ObjectController::_handleResourceContainerTransfer(uint64 targetId,Message* message,ObjectControllerCmdProperties* cmdProperties) { PlayerObject* playerObject = dynamic_cast<PlayerObject*>(mObject); ResourceContainer* selectedContainer = dynamic_cast<ResourceContainer*>(gWorldManager->getObjectById(targetId)); if(selectedContainer) { string dataStr; message->getStringUnicode16(dataStr); dataStr.convert(BSTRType_ANSI); BStringVector dataElements; uint16 elementCount = dataStr.split(dataElements,' '); if(!elementCount) { gLogger->logMsg("ObjectController::_handleResourceContainerTransfer: Error in requestStr"); return; } ResourceContainer* targetContainer = dynamic_cast<ResourceContainer*>(gWorldManager->getObjectById(boost::lexical_cast<uint64>(dataElements[0].getAnsi()))); if(targetContainer && targetContainer->getResourceId() == selectedContainer->getResourceId()) { uint32 targetAmount = targetContainer->getAmount(); uint32 selectedAmount = selectedContainer->getAmount(); uint32 maxAmount = targetContainer->getMaxAmount(); uint32 newAmount; gLogger->logMsg("transfer resi"); // all fits if((newAmount = targetAmount + selectedAmount) <= maxAmount) { // update target container targetContainer->setAmount(newAmount); gMessageLib->sendResourceContainerUpdateAmount(targetContainer,playerObject); mDatabase->ExecuteSqlAsync(NULL,NULL,"UPDATE resource_containers SET amount=%u WHERE id=%"PRIu64"",newAmount,targetContainer->getId()); // delete old container gMessageLib->sendDestroyObject(selectedContainer->getId(),playerObject); gObjectFactory->deleteObjectFromDB(selectedContainer); dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->deleteObject(selectedContainer); } // target container full, update both contents else if(newAmount > maxAmount) { uint32 selectedNewAmount = newAmount - maxAmount; targetContainer->setAmount(maxAmount); selectedContainer->setAmount(selectedNewAmount); gMessageLib->sendResourceContainerUpdateAmount(targetContainer,playerObject); gMessageLib->sendResourceContainerUpdateAmount(selectedContainer,playerObject); mDatabase->ExecuteSqlAsync(NULL,NULL,"UPDATE resource_containers SET amount=%u WHERE id=%"PRIu64"",maxAmount,targetContainer->getId()); mDatabase->ExecuteSqlAsync(NULL,NULL,"UPDATE resource_containers SET amount=%u WHERE id=%"PRIu64"",selectedNewAmount,selectedContainer->getId()); } } } }
//============================================================================= // creates resource containers ín our inventory void HarvesterObject::createResourceContainer(uint64 resID, PlayerObject* player, uint32 amount) { //now create the resource container uint32 rAmount = amount; auto inventory = gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::equipment::EquipmentService>("EquipmentService")->GetEquippedObject(player, "inventory"); inventory->ViewObjects(player, 0, true, [&] (Object* object) { // we are looking for resource containers ResourceContainer* resCont = dynamic_cast<ResourceContainer*>(object); if(resCont) { uint32 targetAmount = resCont->getAmount(); uint32 maxAmount = resCont->getMaxAmount(); uint32 newAmount; if((resCont->getResourceId() == resID)) { //find out how much we can add to the container uint32 addAmount = maxAmount - targetAmount; if(addAmount >rAmount) { addAmount = rAmount; rAmount = 0; } else rAmount -= addAmount; if(addAmount) { // find out how big our container is now newAmount = targetAmount + addAmount; // update target container resCont->setAmount(newAmount); gMessageLib->sendResourceContainerUpdateAmount(resCont,player); gWorldManager->getKernel()->GetDatabase()->executeSqlAsync(NULL,NULL,"UPDATE %s.resource_containers SET amount=%u WHERE id=%"PRIu64"",gWorldManager->getKernel()->GetDatabase()->galaxy(),newAmount,resCont->getId()); } } } }); // or need to create a new one while(rAmount) { uint32 a = 100000; if( a > rAmount) a = rAmount; gObjectFactory->requestNewResourceContainer(inventory,resID,inventory->getId(),99,a); rAmount -= a; } }
//============================================================================= // creates resource containers ín our inventory void HarvesterObject::createResourceContainer(uint64 resID, PlayerObject* player, uint32 amount) { //now create the resource container ObjectIDList* invObjects = dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory))->getObjects(); ObjectIDList::iterator listIt = invObjects->begin(); uint32 rAmount = amount; bool foundSameType = false; while(listIt != invObjects->end()) { // we are looking for resource containers ResourceContainer* resCont = dynamic_cast<ResourceContainer*>(gWorldManager->getObjectById((*listIt))); if(resCont) { uint32 targetAmount = resCont->getAmount(); uint32 maxAmount = resCont->getMaxAmount(); uint32 newAmount; if((resCont->getResourceId() == resID)) { //find out how much we can add to the container uint32 addAmount = maxAmount - targetAmount; if(addAmount >rAmount) { addAmount = rAmount; rAmount = 0; } else rAmount -= addAmount; if(addAmount) { // find out how big our container is now newAmount = targetAmount + addAmount; // update target container resCont->setAmount(newAmount); gMessageLib->sendResourceContainerUpdateAmount(resCont,player); gWorldManager->getDatabase()->ExecuteSqlAsync(NULL,NULL,"UPDATE resource_containers SET amount=%u WHERE id=%I64u",newAmount,resCont->getId()); } } } ++listIt; } // or need to create a new one while(rAmount) { uint32 a = 100000; if( a > rAmount) a = rAmount; gObjectFactory->requestNewResourceContainer(dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)),resID,player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)->getId(),99,a); rAmount -= a; } }
void ArtisanManager::finishSampling(PlayerObject* player, CurrentResource* resource, SurveyTool* tool, uint32 sampleAmount) { bool foundSameType = false; //grants 20xp -> 40xp inclusive -- Feature suggestion: Grant less XP for smaller samples, more xp for greater samples. IE: 20 + X*sampleSize gSkillManager->addExperience(XpType_resource_harvesting_inorganic,(int32)((gRandom->getRand()%20) + 20),player); // see if we can add it to an existing container auto equip_service = gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::equipment::EquipmentService>("EquipmentService"); auto inventory = dynamic_cast<Inventory*>(equip_service->GetEquippedObject(player->GetCreature(), "inventory")); inventory->ViewObjects(player, 0, true, [&] (Object* object) { // we are looking for resource containers ResourceContainer* resCont = dynamic_cast<ResourceContainer*>(object); if(resCont) { uint32 targetAmount = resCont->getAmount(); uint32 maxAmount = resCont->getMaxAmount(); uint32 newAmount; if(resCont->getResourceId() == resource->getId() && targetAmount < maxAmount) { foundSameType = true; if((newAmount = targetAmount + sampleAmount) <= maxAmount) { // update target container resCont->setAmount(newAmount); gMessageLib->sendResourceContainerUpdateAmount(resCont,player); stringstream query_stream; query_stream << "UPDATE "<<gWorldManager->getKernel()->GetDatabase()->galaxy()<<".resource_containers SET amount=" << newAmount << " WHERE id=" << resCont->getId(); gWorldManager->getKernel()->GetDatabase()->executeAsyncSql(query_stream); } // target container full, put in what fits, create a new one else if(newAmount > maxAmount) { uint32 selectedNewAmount = newAmount - maxAmount; resCont->setAmount(maxAmount); gMessageLib->sendResourceContainerUpdateAmount(resCont,player); stringstream query_stream; query_stream << "UPDATE "<<gWorldManager->getKernel()->GetDatabase()->galaxy()<<".resource_containers SET amount=" << newAmount << " WHERE id=" << resCont->getId(); gWorldManager->getKernel()->GetDatabase()->executeAsyncSql(query_stream); gObjectFactory->requestNewResourceContainer(inventory,resource->getId(),inventory->getId(),99,selectedNewAmount); } return; } } }); // or need to create a new one if(!foundSameType) { gObjectFactory->requestNewResourceContainer(inventory,resource->getId(),inventory->getId(),99,sampleAmount); } // deplete resource gResourceManager->setResourceDepletion(resource, sampleAmount); return; }
void ArtisanManager::finishSampling(PlayerObject* player, CurrentResource* resource, SurveyTool* tool, uint32 sampleAmount) { bool foundSameType = false; //grants 20xp -> 40xp inclusive -- Feature suggestion: Grant less XP for smaller samples, more xp for greater samples. IE: 20 + X*sampleSize gSkillManager->addExperience(XpType_resource_harvesting_inorganic,(int32)((gRandom->getRand()%20) + 20),player); // see if we can add it to an existing container Inventory* inventory = dynamic_cast<Inventory*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory)); ObjectIDList* invObjects = inventory->getObjects(); ObjectIDList::iterator listIt = invObjects->begin(); while(listIt != invObjects->end()) { // we are looking for resource containers ResourceContainer* resCont = dynamic_cast<ResourceContainer*>(gWorldManager->getObjectById((*listIt))); if(resCont) { uint32 targetAmount = resCont->getAmount(); uint32 maxAmount = resCont->getMaxAmount(); uint32 newAmount; if(resCont->getResourceId() == resource->getId() && targetAmount < maxAmount) { foundSameType = true; if((newAmount = targetAmount + sampleAmount) <= maxAmount) { // update target container resCont->setAmount(newAmount); gMessageLib->sendResourceContainerUpdateAmount(resCont,player); gWorldManager->getDatabase()->executeSqlAsync(NULL,NULL,"UPDATE resource_containers SET amount=%u WHERE id=%"PRIu64"",newAmount,resCont->getId()); } // target container full, put in what fits, create a new one else if(newAmount > maxAmount) { uint32 selectedNewAmount = newAmount - maxAmount; resCont->setAmount(maxAmount); gMessageLib->sendResourceContainerUpdateAmount(resCont,player); gWorldManager->getDatabase()->executeSqlAsync(NULL,NULL,"UPDATE resource_containers SET amount=%u WHERE id=%"PRIu64"",maxAmount,resCont->getId()); gObjectFactory->requestNewResourceContainer(inventory,resource->getId(),inventory->getId(),99,selectedNewAmount); } break; } } ++listIt; } // or need to create a new one if(!foundSameType) { gObjectFactory->requestNewResourceContainer(inventory,resource->getId(),inventory->getId(),99,sampleAmount); } // deplete resource gResourceManager->setResourceDepletion(resource, sampleAmount); return; }