uint32 CraftingSession::getComponentOffer(Item* component, uint32 needed)
{

    uint32 crateSize = 0;
    mAsyncStackSize = 1;

    FactoryCrate* fC  = dynamic_cast<FactoryCrate*>(component);
    if(fC)
    {
        if(!fC->hasAttribute("factory_count"))
        {
            DLOG(INFO) << "CraftingSession::prepareComponent crate without factory_count attribute";
            return 0;
        }

        crateSize = fC->getAttribute<uint32>("factory_count");
        mAsyncStackSize = 1;

        if(!fC->getLinkedObject()->hasAttribute("stacksize"))
        {
            if(needed> crateSize)
                return crateSize;
            else
                return needed;
        }

        mAsyncStackSize = fC->getLinkedObject()->getAttribute<uint32>("stacksize");

        if(needed> (mAsyncStackSize*crateSize))
            return mAsyncStackSize*crateSize;
        else
            return needed;

    }

    if(!component->hasAttribute("stacksize"))
    {
        return 1;
    }

    mAsyncStackSize = component->getAttribute<uint32>("stacksize");

    if(needed> mAsyncStackSize)
        return mAsyncStackSize;
    else
        return needed;

}
BString CraftingSession::ComponentGetSerial(Item* component)
{

    BString componentSerial = "";

    FactoryCrate* fC  = dynamic_cast<FactoryCrate*>(component);
    if(fC)
    {
        if(fC->getLinkedObject()->hasAttribute("serial"))
            componentSerial = fC->getLinkedObject()->getAttribute<std::string>("serial").c_str();


        return	componentSerial;
    }

    if(component->hasAttribute("serial"))
        componentSerial = component->getAttribute<std::string>("serial").c_str();

    return	componentSerial;

}
示例#3
0
void	ObjectController::_ExtractObject(uint64 targetId,Message* message,ObjectControllerCmdProperties* cmdProperties)
{
    PlayerObject*		playerObject		= dynamic_cast<PlayerObject*>(mObject);
    FactoryCrate*		crate				= dynamic_cast<FactoryCrate*>(gWorldManager->getObjectById(targetId));

    if(!crate)
    {
        DLOG(info) << "ObjectController::_ExtractObject: Crate does not exist!";
        return;
    }

    //get the crates containing container  we can use the unified interface thks to virtual functions :)
    TangibleObject* tO = dynamic_cast<TangibleObject* >(gWorldManager->getObjectById(crate->getParentId()));
    if(!tO)
    {
        assert(false && "ObjectController::_ExtractObject inventory must be a tangible object");
        return;
    }

    if(!tO->checkCapacity())
    {
        //check if we can fit an additional item in our inventory
        //TODO: say something
        return;
    }

    //create the new item
    gObjectFactory->requestNewClonedItem(tO,crate->getLinkedObject()->getId(),tO->getId());

    //decrease crate content
    int32 content = crate->decreaseContent(1);
    if(!content)
    {
		TangibleObject* container = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(crate->getParentId()));
		gContainerManager->deleteObject(crate, container);
        
        return;
    }

    if(content < 0)
    {
        assert(false && "ObjectController::_ExtractObject crate must not have negative content");
        return;
    }

    gMessageLib->sendUpdateCrateContent(crate,playerObject);

    return;


}
示例#4
0
void	ObjectController::_ExtractObject(uint64 targetId,Message* message,ObjectControllerCmdProperties* cmdProperties)
{
	PlayerObject*		playerObject		= dynamic_cast<PlayerObject*>(mObject);
	FactoryCrate*		crate				= dynamic_cast<FactoryCrate*>(gWorldManager->getObjectById(targetId));

	Inventory* inventory = dynamic_cast<Inventory*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Inventory));

	//gLogger->logMsgF("ObjectController::_ExtractObject: Container : %I64u",MSG_NORMAL,targetId);

	if(!crate)
	{
		gLogger->logMsg("ObjectController::_ExtractObject: Crate does not exist!");
		return;
	}

	//get the crates containing container - inventory is a tangible, too - we can use the unified interface thks to virtual functions :)
	//add inventories to worldmanager ?
	TangibleObject* tO = dynamic_cast<TangibleObject* >(gWorldManager->getObjectById(crate->getParentId()));
	if(!tO)
	{
		tO = dynamic_cast<TangibleObject* >(inventory);
		if(!tO)
		{
			gLogger->logMsg("ObjectController::_ExtractObject: Crates parent does not exist!");
			assert(false && "ObjectController::_ExtractObject inventory must be a tangible object");
			return;
		}
	}
	
	if(!tO->checkCapacity())
	{
		//check if we can fit an additional item in our inventory
		
		return;
	}

	//create the new item
	gObjectFactory->requestNewClonedItem(tO,crate->getLinkedObject()->getId(),tO->getId());

	//decrease crate content
	int32 content = crate->decreaseContent(1);
	if(!content)
	{
		gMessageLib->sendDestroyObject(crate->getId(),playerObject);
		gObjectFactory->deleteObjectFromDB(crate->getId());
		inventory->deleteObject(crate);
		return;
	}
	
	if(content < 0)
	{
		gLogger->logMsg("ObjectController::_ExtractObject: the crate now has negative content!");
		assert(false && "ObjectController::_ExtractObject crate must not have negative content");
		return;
	}

	gMessageLib->sendUpdateCrateContent(crate,playerObject);

	return;

	
}
bool CraftingSession::prepareComponent(Item* component, uint32 needed, ManufactureSlot* manSlot)
{

    FactoryCrate* fC  = dynamic_cast<FactoryCrate*>(component);
    if(fC)
    {

        uint32 amount = AdjustFactoryCrate(fC, needed);
        DLOG(INFO) << "CraftingSession::prepareComponent FactoryCrate take " << amount;

        //TODO - added stacks shouldnt have more items than maximally possible - needed is the amount needed for the slot
        // that might be bigger than the max stack size

        //create the new item - link it to the slot
        mAsyncComponentAmount = needed;
        mAsyncManSlot = manSlot;

        //make sure we request the right amount of stacks
        for(uint8 i = 0; i<amount; i++)
            gObjectFactory->requestNewClonedItem(this,fC->getLinkedObject()->getId(),mManufacturingSchematic->getId());


        // if its now empty remove it out of the inventory so we cant use it several times
        // and destroy it while were at it
        uint32 crateSize = fC->getAttribute<uint32>("factory_count");
        if(!crateSize)
        {
            TangibleObject* container = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(fC->getParentId()));

            //just delete it
			gContainerManager->deleteObject(fC, container);
           
        }

        //dont send result - its a callback
        return false;

    }

    //no stacksize or crate - do not bother with temporaries
    if(!component->hasAttribute("stacksize"))
    {
        // remove it out of the inventory so we cant use it several times
        TangibleObject* tO = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(component->getParentId()));

        assert(tO && "CraftingSession::prepareComponent :: cant get parent");

        tO->removeObject(component);

        //leave parent_id untouched - we might need to readd it to the container!
		//please note that we can only use components out of our inventory or the crafting stations thingy
		//so update containment for all watchers

		//TODO
        gMessageLib->sendContainmentMessage(component->getId(),mManufacturingSchematic->getId(),0xffffffff,mOwner);

        //send result directly we dont have a callback
        return true;

    }

    //only pure stacks remain
    AdjustComponentStack(component, needed);

    //create the new item - link it to the slot
    mAsyncComponentAmount = needed;
    mAsyncManSlot = manSlot;
    gObjectFactory->requestNewClonedItem(this,component->getId(),mManufacturingSchematic->getId());

    //delete the stack if empty
    uint32 stackSize = component->getAttribute<uint32>("stacksize");

    if(!stackSize)
    {
        //remove the item out of its container
        TangibleObject* tO = dynamic_cast<TangibleObject*>(gWorldManager->getObjectById(component->getParentId()));

        if(!tO)
        {
            assert(false);
            return false;
        }

        //just delete it
        tO->removeObject(component);
        gWorldManager->destroyObject(component);

    }

    //dont send result - its a callback
    return false;

}