Core/Player: Add new function AddItem. Useful in the scriptsystem for custom scripts.

--HG--
branch : trunk
This commit is contained in:
enjoi
2010-08-24 18:18:31 -05:00
parent aaaeecc916
commit 25c8ab63f8
2 changed files with 27 additions and 17 deletions
+25 -17
View File
@@ -6853,26 +6853,11 @@ bool Player::RewardHonor(Unit *uVictim, uint32 groupsize, int32 honor, bool pvpt
|| (MapType == 3 && !InBattleground()))
return true;
uint32 noSpaceForCount = 0;
uint32 itemId = sWorld.getIntConfig(CONFIG_PVP_TOKEN_ID);
int32 count = sWorld.getIntConfig(CONFIG_PVP_TOKEN_COUNT);
// check space and find places
ItemPosCountVec dest;
uint8 msg = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
if (msg != EQUIP_ERR_OK) // convert to possible store amount
count = noSpaceForCount;
if (count == 0 || dest.empty()) // can't add any
{
// -- TODO: Send to mailbox if no space
ChatHandler(this).PSendSysMessage("You don't have any space in your bags for a token.");
return true;
}
Item* item = StoreNewItem(dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
SendNewItem(item,count,true,false);
ChatHandler(this).PSendSysMessage("You have been awarded a token for slaying another player.");
if(AddItem(itemId, count))
ChatHandler(this).PSendSysMessage("You have been awarded a token for slaying another player.");
}
}
@@ -23997,6 +23982,29 @@ void Player::SendRefundInfo(Item *item)
GetSession()->SendPacket(&data);
}
bool Player::AddItem(uint32 itemId, uint32 count)
{
uint32 noSpaceForCount = 0;
ItemPosCountVec dest;
uint8 msg = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
if (msg != EQUIP_ERR_OK)
count = noSpaceForCount;
if (count == 0 || dest.empty())
{
// -- TODO: Send to mailbox if no space
ChatHandler(this).PSendSysMessage("You don't have any space in your bags.");
return false;
}
Item* item = StoreNewItem(dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
if(item)
SendNewItem(item,count,true,false);
else
return false;
return true;
}
void Player::RefundItem(Item *item)
{
if (!item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_REFUNDABLE))
+2
View File
@@ -1272,6 +1272,8 @@ class Player : public Unit, public GridObject<Player>
void LoadCorpse();
void LoadPet();
bool AddItem(uint32 itemId, uint32 count);
uint32 m_stableSlots;
/*********************************************************/