当前位置: 首页>>代码示例>>C++>>正文


C++ Player::AddItemToSlot方法代码示例

本文整理汇总了C++中Player::AddItemToSlot方法的典型用法代码示例。如果您正苦于以下问题:C++ Player::AddItemToSlot方法的具体用法?C++ Player::AddItemToSlot怎么用?C++ Player::AddItemToSlot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Player的用法示例。


在下文中一共展示了Player::AddItemToSlot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HandleAddItemCommand

bool ChatHandler::HandleAddItemCommand(const char* args)
{
    
    WorldPacket data;

    if (!*args)  
        return false;

    char* citemid = strtok((char*)args, " ");
    char* cPos = strtok(NULL, " ");
    char* cVal = strtok(NULL, " ");

    uint32 itemid=atol(citemid);

    Player*    pl = m_session->GetPlayer();
    bool   slotfree=false;
    uint8  i,slot;
    uint32 Pos=5,Val=1;
    

    for(i =    INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END;    i++)
    {
        if (pl->GetItemBySlot(i) == NULL)
        {
            slot = i;
            slotfree=true;
            break;
        }
    }
    if (slotfree)
    {
        Item *item = new Item();    
        item->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM),    itemid, pl);

		if (!item)
			return true;
        
        
        if ((cPos) && (cVal)){
            Pos=(uint32)atol(cPos);
            Val=(uint32)atol(cVal);
            
            item->SetUInt32Value( Pos, Val );
        }

        pl->AddItemToSlot(    slot, item );
    }else{
        FillSystemMessageData(&data, m_session, "Bag is full.");
        m_session->SendPacket(&data);
    }

    return true;
}
开发者ID:Artea,项目名称:mangos-svn,代码行数:53,代码来源:Level3.cpp

示例2:

void
Spell::Effect_Create_Item(uint32 i)
{
	// NEEDS TO BE REDONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	Player* pUnit = (Player*)m_caster;
	uint8 slot = 0;
	for(uint8 i=INVENTORY_SLOT_ITEM_START; i<INVENTORY_SLOT_ITEM_END; ++i){// check if there is a free slot for the item to conjure
		if(pUnit->GetItemBySlot(i) == 0)
				slot = i;
		if(slot == 0){
			SendCastResult(CAST_FAIL_MUST_HAVE_XXXX_IN_MAINHAND); // ZeHaM: Wtf has this got to do with adding an item ?? o_O
			return;
		}

		Item* pItem;
		uint8 curSlot;
		for(uint32 i=0;i<8; ++i){
			for(uint32 j=0; j<m_spellInfo->ReagentCount[i]; ++j){
				if(j>10)// little protection to prevent loops in here
					break;
				if(m_spellInfo->Reagent[i] == 0)
					continue;
				curSlot = (uint8)pUnit->GetSlotByItemID(m_spellInfo->Reagent[i]);
				if(curSlot == 0)
					continue;
				pItem = new Item;
				pItem = pUnit->GetItemBySlot(curSlot);
				
				// if there are more then 1 in stack then just reduce it by 1
				if(pItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT) > 1){ 
					pItem->SetUInt32Value(ITEM_FIELD_STACK_COUNT,pItem->GetUInt32Value(ITEM_FIELD_STACK_COUNT)-1);
				}else{// otherwise delete it from player and db
					pUnit->RemoveItemFromSlot(curSlot);
					pItem->DeleteFromDB();
				}
				pItem = NULL;
				curSlot = 0;
			}
		}

		pItem = NULL;
		Item* newItem;
		for(i=0; i<2; ++i){// now create the Items
			if(m_spellInfo->EffectItemType[i] == 0)
				continue;

			slot = 0;
			// check if there is a free slot for the item to conjure
			for (uint8 i = INVENTORY_SLOT_ITEM_START; i<INVENTORY_SLOT_ITEM_END; ++i){
				if(pUnit->GetItemBySlot(i) == 0)
					slot = i;
			}
			if(slot == 0){
				SendCastResult(0x18);
				return;
			}
			newItem = new Item;
			newItem->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM),m_spellInfo->EffectItemType[i],pUnit);
			pUnit->AddItemToSlot(slot,newItem);
			newItem = NULL;
		}
	}
}
开发者ID:vata,项目名称:prebcwow,代码行数:63,代码来源:SpellEffects.cpp


注:本文中的Player::AddItemToSlot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。