Exemplo n.º 1
0
//=============================================================================
// 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;

    }


}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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::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 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());
			}
		}
	}
}
Exemplo n.º 6
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;
}