[7239] Support multiply items loot and not normal loot items in Player::AutoStoreLoot.

Use this function in more cases and simplify and fix some related code.
This commit is contained in:
VladimirMangos 2009-02-07 10:07:27 +03:00
parent 7d63f4ce02
commit 5e2553ff7e
7 changed files with 36 additions and 53 deletions

View file

@ -643,6 +643,12 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem **qite
return item; return item;
} }
uint32 Loot::GetMaxSlotInLootFor(Player* player) const
{
QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUIDLow());
return items.size() + (itr != PlayerQuestItems.end() ? itr->second->size() : 0);
}
ByteBuffer& operator<<(ByteBuffer& b, LootItem const& li) ByteBuffer& operator<<(ByteBuffer& b, LootItem const& li)
{ {
b << uint32(li.itemid); b << uint32(li.itemid);

View file

@ -222,7 +222,6 @@ struct Loot
QuestItemMap const& GetPlayerNonQuestNonFFAConditionalItems() const { return PlayerNonQuestNonFFAConditionalItems; } QuestItemMap const& GetPlayerNonQuestNonFFAConditionalItems() const { return PlayerNonQuestNonFFAConditionalItems; }
std::vector<LootItem> items; std::vector<LootItem> items;
std::vector<LootItem> quest_items;
uint32 gold; uint32 gold;
uint8 unlootedCount; uint8 unlootedCount;
@ -273,6 +272,7 @@ struct Loot
void AddItem(LootStoreItem const & item); void AddItem(LootStoreItem const & item);
LootItem* LootItemInSlot(uint32 lootslot, Player* player, QuestItem** qitem = NULL, QuestItem** ffaitem = NULL, QuestItem** conditem = NULL); LootItem* LootItemInSlot(uint32 lootslot, Player* player, QuestItem** qitem = NULL, QuestItem** ffaitem = NULL, QuestItem** conditem = NULL);
uint32 GetMaxSlotInLootFor(Player* player) const;
private: private:
void FillNotNormalLootFor(Player* player); void FillNotNormalLootFor(Player* player);
@ -280,6 +280,7 @@ struct Loot
QuestItemList* FillQuestLoot(Player* player); QuestItemList* FillQuestLoot(Player* player);
QuestItemList* FillNonQuestNonFFAConditionalLoot(Player* player); QuestItemList* FillNonQuestNonFFAConditionalLoot(Player* player);
std::vector<LootItem> quest_items;
std::set<uint64> PlayersLooting; std::set<uint64> PlayersLooting;
QuestItemMap PlayerQuestItems; QuestItemMap PlayerQuestItems;
QuestItemMap PlayerFFAItems; QuestItemMap PlayerFFAItems;

View file

@ -12771,7 +12771,8 @@ void Player::RewardQuest( Quest const *pQuest, uint32 reward, Object* questGiver
// fill mail // fill mail
MailItemsInfo mi; // item list preparing MailItemsInfo mi; // item list preparing
for(size_t i = 0; mi.size() < MAX_MAIL_ITEMS && i < questMailLoot.items.size(); ++i) uint32 max_slot = questMailLoot.GetMaxSlotInLootFor(this);
for(uint32 i = 0; mi.size() < MAX_MAIL_ITEMS && i < max_slot; ++i)
{ {
if(LootItem* lootitem = questMailLoot.LootItemInSlot(i,this)) if(LootItem* lootitem = questMailLoot.LootItemInSlot(i,this))
{ {
@ -12783,18 +12784,6 @@ void Player::RewardQuest( Quest const *pQuest, uint32 reward, Object* questGiver
} }
} }
for(size_t i = 0; mi.size() < MAX_MAIL_ITEMS && i < questMailLoot.quest_items.size(); ++i)
{
if(LootItem* lootitem = questMailLoot.LootItemInSlot(i+questMailLoot.items.size(),this))
{
if(Item* item = Item::CreateItem(lootitem->itemid,lootitem->count,this))
{
item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
}
}
}
WorldSession::SendMailTo(this, mailType, MAIL_STATIONERY_NORMAL, senderGuidOrEntry, GetGUIDLow(), "", 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE,pQuest->GetRewMailDelaySecs(),pQuest->GetRewMailTemplateId()); WorldSession::SendMailTo(this, mailType, MAIL_STATIONERY_NORMAL, senderGuidOrEntry, GetGUIDLow(), "", 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE,pQuest->GetRewMailDelaySecs(),pQuest->GetRewMailTemplateId());
} }
@ -19376,28 +19365,31 @@ void Player::InitRunes()
SetFloatValue(PLAYER_RUNE_REGEN_1 + i, 0.1f); SetFloatValue(PLAYER_RUNE_REGEN_1 + i, 0.1f);
} }
void Player::AutoStoreLootItem(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store) void Player::AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store, bool broadcast)
{ {
Loot loot; Loot loot;
loot.FillLoot (loot_id,store,this,true); loot.FillLoot (loot_id,store,this,true);
if(loot.items.empty ())
return;
LootItem const* lootItem = &loot.items[0];
ItemPosCountVec dest; uint32 max_slot = loot.GetMaxSlotInLootFor(this);
uint8 msg = CanStoreNewItem (bag,slot,dest,lootItem->itemid,lootItem->count); for(uint32 i = 0; i < max_slot; ++i)
if(msg != EQUIP_ERR_OK && slot != NULL_SLOT)
msg = CanStoreNewItem( bag, NULL_SLOT,dest,lootItem->itemid,lootItem->count);
if( msg != EQUIP_ERR_OK && bag != NULL_BAG)
msg = CanStoreNewItem( NULL_BAG, NULL_SLOT,dest,lootItem->itemid,lootItem->count);
if(msg != EQUIP_ERR_OK)
{ {
SendEquipError( msg, NULL, NULL ); LootItem* lootItem = loot.LootItemInSlot(i,this);
return;
}
Item* pItem = StoreNewItem (dest,lootItem->itemid,true,lootItem->randomPropertyId); ItemPosCountVec dest;
SendNewItem(pItem, lootItem->count, true, false); uint8 msg = CanStoreNewItem (bag,slot,dest,lootItem->itemid,lootItem->count);
if(msg != EQUIP_ERR_OK && slot != NULL_SLOT)
msg = CanStoreNewItem( bag, NULL_SLOT,dest,lootItem->itemid,lootItem->count);
if( msg != EQUIP_ERR_OK && bag != NULL_BAG)
msg = CanStoreNewItem( NULL_BAG, NULL_SLOT,dest,lootItem->itemid,lootItem->count);
if(msg != EQUIP_ERR_OK)
{
SendEquipError( msg, NULL, NULL );
continue;
}
Item* pItem = StoreNewItem (dest,lootItem->itemid,true,lootItem->randomPropertyId);
SendNewItem(pItem, lootItem->count, false, false, broadcast);
}
} }
uint32 Player::CalculateTalentsPoints() const uint32 Player::CalculateTalentsPoints() const

View file

@ -1110,8 +1110,8 @@ class MANGOS_DLL_SPEC Player : public Unit
Item* EquipItem( uint16 pos, Item *pItem, bool update ); Item* EquipItem( uint16 pos, Item *pItem, bool update );
void AutoUnequipOffhandIfNeed(); void AutoUnequipOffhandIfNeed();
bool StoreNewItemInBestSlots(uint32 item_id, uint32 item_count); bool StoreNewItemInBestSlots(uint32 item_id, uint32 item_count);
void AutoStoreLootItem(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store); void AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store, bool broadcast = false);
void AutoStoreLootItem(uint32 loot_id, LootStore const& store) { AutoStoreLootItem(NULL_BAG,NULL_SLOT,loot_id,store); } void AutoStoreLoot(uint32 loot_id, LootStore const& store, bool broadcast = false) { AutoStoreLoot(NULL_BAG,NULL_SLOT,loot_id,store,broadcast); }
uint8 _CanTakeMoreSimilarItems(uint32 entry, uint32 count, Item* pItem, uint32* no_space_count = NULL) const; uint8 _CanTakeMoreSimilarItems(uint32 entry, uint32 count, Item* pItem, uint32* no_space_count = NULL) const;
uint8 _CanStoreItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, uint32 entry, uint32 count, Item *pItem = NULL, bool swap = false, uint32* no_space_count = NULL ) const; uint8 _CanStoreItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, uint32 entry, uint32 count, Item *pItem = NULL, bool swap = false, uint32* no_space_count = NULL ) const;

View file

@ -1518,26 +1518,10 @@ void Aura::TriggerSpell()
Creature* creature = (Creature*)target; Creature* creature = (Creature*)target;
// missing lootid has been reported on startup - just return // missing lootid has been reported on startup - just return
if (!creature->GetCreatureInfo()->SkinLootId) if (!creature->GetCreatureInfo()->SkinLootId)
{
return; return;
}
Loot *loot = &creature->loot;
loot->clear();
loot->FillLoot(creature->GetCreatureInfo()->SkinLootId, LootTemplates_Skinning, player, true);
for(uint8 i=0;i<loot->items.size();i++)
{
LootItem *item = loot->LootItemInSlot(i,player);
ItemPosCountVec dest;
uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, item->itemid, item->count );
if ( msg == EQUIP_ERR_OK )
{
Item * newitem = player->StoreNewItem( dest, item->itemid, true, item->randomPropertyId);
player->SendNewItem(newitem, uint32(item->count), false, false, true); player->AutoStoreLoot(creature->GetCreatureInfo()->SkinLootId,LootTemplates_Skinning,true);
}
else
player->SendEquipError( msg, NULL, NULL );
}
creature->setDeathState(JUST_DIED); creature->setDeathState(JUST_DIED);
creature->RemoveCorpse(); creature->RemoveCorpse();
creature->SetHealth(0); // just for nice GM-mode view creature->SetHealth(0); // just for nice GM-mode view

View file

@ -2691,7 +2691,7 @@ void Spell::EffectCreateItem2(uint32 i)
return; return;
// create some random items // create some random items
((Player*)m_caster)->AutoStoreLootItem(m_spellInfo->Id,LootTemplates_Spell); ((Player*)m_caster)->AutoStoreLoot(m_spellInfo->Id,LootTemplates_Spell);
return; return;
} }
DoCreateItem(i,m_spellInfo->EffectItemType[i]); DoCreateItem(i,m_spellInfo->EffectItemType[i]);
@ -4922,7 +4922,7 @@ void Spell::EffectScriptEffect(uint32 effIndex)
player->DestroyItemCount (reagent_id,count,true); player->DestroyItemCount (reagent_id,count,true);
// create some random items // create some random items
player->AutoStoreLootItem(m_spellInfo->Id,LootTemplates_Spell); player->AutoStoreLoot(m_spellInfo->Id,LootTemplates_Spell);
// learn random explicit discovery recipe (if any) // learn random explicit discovery recipe (if any)
if(uint32 discoveredSpell = GetExplicitDiscoverySpell(m_spellInfo->Id, player)) if(uint32 discoveredSpell = GetExplicitDiscoverySpell(m_spellInfo->Id, player))

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "7238" #define REVISION_NR "7239"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__