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