Beispiel #1
0
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;
}
//=============================================================================
// 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;

    }


}
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;
    }

}
Beispiel #4
0
//=============================================================================
// 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 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());
			}
		}
	}
}
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);
	
}
Beispiel #9
0
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;
}