diff options
author | megamage <none@none> | 2009-02-08 21:54:13 -0600 |
---|---|---|
committer | megamage <none@none> | 2009-02-08 21:54:13 -0600 |
commit | 2bd90deeedb6282eab9dfce650fbaf2bda451ee8 (patch) | |
tree | 26a6af03fd6757b52002e56469a728f75a42abc8 /src/game | |
parent | 11b9bd42f76db238af914112bdc065fc8293451d (diff) |
[7239] Support multiply items loot and not normal loot items in Player::AutoStoreLoot. Author: VladimirMangos
Use this function in more cases and simplify and fix some related code.
--HG--
branch : trunk
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/LootMgr.cpp | 6 | ||||
-rw-r--r-- | src/game/LootMgr.h | 3 | ||||
-rw-r--r-- | src/game/Player.cpp | 51 | ||||
-rw-r--r-- | src/game/Player.h | 4 | ||||
-rw-r--r-- | src/game/SpellAuras.cpp | 22 | ||||
-rw-r--r-- | src/game/SpellEffects.cpp | 4 |
6 files changed, 37 insertions, 53 deletions
diff --git a/src/game/LootMgr.cpp b/src/game/LootMgr.cpp index 3ef42b36f4a..af310b452fe 100644 --- a/src/game/LootMgr.cpp +++ b/src/game/LootMgr.cpp @@ -646,6 +646,12 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem **qite 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) { b << uint32(li.itemid); diff --git a/src/game/LootMgr.h b/src/game/LootMgr.h index 077d42a1e17..8f54bb3bee1 100644 --- a/src/game/LootMgr.h +++ b/src/game/LootMgr.h @@ -224,7 +224,6 @@ struct Loot QuestItemMap const& GetPlayerNonQuestNonFFAConditionalItems() const { return PlayerNonQuestNonFFAConditionalItems; } std::vector<LootItem> items; - std::vector<LootItem> quest_items; uint32 gold; uint8 unlootedCount; @@ -275,6 +274,7 @@ struct Loot void AddItem(LootStoreItem const & item); LootItem* LootItemInSlot(uint32 lootslot, Player* player, QuestItem** qitem = NULL, QuestItem** ffaitem = NULL, QuestItem** conditem = NULL); + uint32 GetMaxSlotInLootFor(Player* player) const; private: void FillNotNormalLootFor(Player* player); @@ -282,6 +282,7 @@ struct Loot QuestItemList* FillQuestLoot(Player* player); QuestItemList* FillNonQuestNonFFAConditionalLoot(Player* player); + std::vector<LootItem> quest_items; std::set<uint64> PlayersLooting; QuestItemMap PlayerQuestItems; QuestItemMap PlayerFFAItems; diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 85d0dcbdcc5..9e5880afc9f 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -7687,7 +7687,7 @@ void Player::SendLoot(uint64 guid, LootType loot_type) uint32 pLevel = bones->loot.gold; bones->loot.clear(); if(GetBattleGround()->GetTypeID() == BATTLEGROUND_AV) - loot->FillLoot(1, LootTemplates_Creature, this); + loot->FillLoot(1, LootTemplates_Creature, this, true); // It may need a better formula // Now it works like this: lvl10: ~6copper, lvl70: ~9silver bones->loot.gold = (uint32)( urand(50, 150) * 0.016f * pow( ((float)pLevel)/5.76f, 2.5f) * sWorld.getRate(RATE_DROP_MONEY) ); @@ -13115,7 +13115,8 @@ void Player::RewardQuest( Quest const *pQuest, uint32 reward, Object* questGiver // fill mail 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)) { @@ -13127,18 +13128,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()); } @@ -20202,27 +20191,31 @@ void Player::InitRunes() 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.FillLoot (loot_id,store,this,true); - if(loot.items.empty ()) - return; - LootItem const* lootItem = &loot.items[0]; - ItemPosCountVec dest; - 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) + uint32 max_slot = loot.GetMaxSlotInLootFor(this); + for(uint32 i = 0; i < max_slot; ++i) { - SendEquipError( msg, NULL, NULL ); - return; + LootItem* lootItem = loot.LootItemInSlot(i,this); + + ItemPosCountVec dest; + 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); } - Item* pItem = StoreNewItem (dest,lootItem->itemid,true,lootItem->randomPropertyId); - SendNewItem(pItem, lootItem->count, true, false); } uint32 Player::CalculateTalentsPoints() const diff --git a/src/game/Player.h b/src/game/Player.h index 186d0b5692c..b3867d84878 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -1114,8 +1114,8 @@ class TRINITY_DLL_SPEC Player : public Unit Item* EquipItem( uint16 pos, Item *pItem, bool update ); void AutoUnequipOffhandIfNeed(); bool StoreNewItemInBestSlots(uint32 item_id, uint32 item_count); - void AutoStoreLootItem(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store); - void AutoStoreLootItem(uint32 loot_id, LootStore const& store) { AutoStoreLootItem(NULL_BAG,NULL_SLOT,loot_id,store); } + void AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store, bool broadcast = false); + 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 _CanStoreItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, uint32 entry, uint32 count, Item *pItem = NULL, bool swap = false, uint32* no_space_count = NULL ) const; diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index 55ea69eefb2..cf7ad71245e 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -1369,26 +1369,10 @@ void Aura::TriggerSpell() Creature* creature = (Creature*)target; // missing lootid has been reported on startup - just return if (!creature->GetCreatureInfo()->SkinLootId) - { 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); - } - else - player->SendEquipError( msg, NULL, NULL ); - } + + player->AutoStoreLoot(creature->GetCreatureInfo()->SkinLootId,LootTemplates_Skinning,true); + creature->setDeathState(JUST_DIED); creature->RemoveCorpse(); creature->SetHealth(0); // just for nice GM-mode view diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index a908db9185c..11af74f7f86 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -2747,7 +2747,7 @@ void Spell::EffectCreateItem2(uint32 i) return; // create some random items - ((Player*)m_caster)->AutoStoreLootItem(m_spellInfo->Id,LootTemplates_Spell); + ((Player*)m_caster)->AutoStoreLoot(m_spellInfo->Id,LootTemplates_Spell); return; } DoCreateItem(i,m_spellInfo->EffectItemType[i]); @@ -5103,7 +5103,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) player->DestroyItemCount (reagent_id,count,true); // 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) if(uint32 discoveredSpell = GetExplicitDiscoverySpell(m_spellInfo->Id, player)) |