Core/Loot: Store method used at loot generation inside Loot object

This commit is contained in:
Shauren
2022-09-14 22:03:47 +02:00
parent f19f32f2a4
commit 9700b2a786
7 changed files with 36 additions and 50 deletions

View File

@@ -8740,7 +8740,7 @@ void Player::RemovedInsignia(Player* looterPlr)
// Now we must make bones lootable, and send player loot
bones->SetCorpseDynamicFlag(CORPSE_DYNFLAG_LOOTABLE);
bones->m_loot.reset(new Loot(GetMap(), bones->GetGUID(), LOOT_INSIGNIA));
bones->m_loot.reset(new Loot(GetMap(), bones->GetGUID(), LOOT_INSIGNIA, looterPlr->GetGroup() ? looterPlr->GetGroup()->GetLootMethod() : FREE_FOR_ALL));
// For AV Achievement
if (Battleground* bg = GetBattleground())
@@ -8834,7 +8834,10 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
return;
}
loot = new Loot(GetMap(), guid, loot_type);
Group* group = GetGroup();
bool groupRules = (group && go->GetGOInfo()->type == GAMEOBJECT_TYPE_CHEST && go->GetGOInfo()->chest.usegrouplootrules);
loot = new Loot(GetMap(), guid, loot_type, groupRules ? group->GetLootMethod() : FREE_FOR_ALL);
if (go->GetMap()->Is25ManRaid())
loot->maxDuplicates = 3;
@@ -8842,9 +8845,6 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
if (lootid)
{
Group* group = GetGroup();
bool groupRules = (group && go->GetGOInfo()->type == GAMEOBJECT_TYPE_CHEST && go->GetGOInfo()->chest.usegrouplootrules);
// check current RR player and get next if necessary
if (groupRules)
group->UpdateLooterGuid(go, true);
@@ -8868,20 +8868,17 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
if (go->GetGOInfo()->type == GAMEOBJECT_TYPE_CHEST && go->GetGOInfo()->chest.usegrouplootrules)
{
if (Group* group = GetGroup())
switch (loot->GetLootMethod())
{
switch (group->GetLootMethod())
{
case GROUP_LOOT:
// GroupLoot: rolls items over threshold. Items with quality < threshold, round robin
group->GroupLoot(loot, go);
break;
case MASTER_LOOT:
group->MasterLoot(loot, go);
break;
default:
break;
}
case GROUP_LOOT:
// GroupLoot: rolls items over threshold. Items with quality < threshold, round robin
group->GroupLoot(loot, go);
break;
case MASTER_LOOT:
group->MasterLoot(loot, go);
break;
default:
break;
}
}
@@ -8892,7 +8889,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
{
if (Group* group = GetGroup())
{
switch (group->GetLootMethod())
switch (loot->GetLootMethod())
{
case MASTER_LOOT:
permission = group->GetMasterLooterGuid() == GetGUID() ? MASTER_PERMISSION : RESTRICTED_PERMISSION;
@@ -8928,7 +8925,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
if (!item->m_lootGenerated && !sLootItemStorage->LoadStoredLoot(item, this))
{
item->m_lootGenerated = true;
loot = new Loot(GetMap(), guid, loot_type);
loot = new Loot(GetMap(), guid, loot_type, FREE_FOR_ALL);
item->m_loot.reset(loot);
switch (loot_type)
@@ -8999,7 +8996,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
{
creature->StartPickPocketRefillTimer();
loot = new Loot(GetMap(), creature->GetGUID(), LOOT_PICKPOCKETING);
loot = new Loot(GetMap(), creature->GetGUID(), LOOT_PICKPOCKETING, FREE_FOR_ALL);
creature->m_loot.reset(loot);
if (uint32 lootid = creature->GetCreatureTemplate()->pickpocketLootId)
loot->FillLoot(lootid, LootTemplates_Pickpocketing, this, true);
@@ -9040,7 +9037,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
// for creature, loot is filled when creature is killed.
if (Group* group = creature->GetLootRecipientGroup())
{
switch (group->GetLootMethod())
switch (loot->GetLootMethod())
{
case GROUP_LOOT:
// GroupLoot: rolls items over threshold. Items with quality < threshold, round robin
@@ -9078,7 +9075,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
Group* group = GetGroup();
if (group == creature->GetLootRecipientGroup())
{
switch (group->GetLootMethod())
switch (loot->GetLootMethod())
{
case MASTER_LOOT:
permission = group->GetMasterLooterGuid() == GetGUID() ? MASTER_PERMISSION : RESTRICTED_PERMISSION;
@@ -9104,26 +9101,13 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
if (permission != NONE_PERMISSION)
{
LootMethod _lootMethod = FREE_FOR_ALL;
if (Group* group = GetGroup())
{
if (Creature* creature = GetMap()->GetCreature(guid))
{
if (Player* recipient = creature->GetLootRecipient())
{
if (group == recipient->GetGroup())
_lootMethod = group->GetLootMethod();
}
}
}
if (!guid.IsItem() && !aeLooting)
SetLootGUID(guid);
WorldPackets::Loot::LootResponse packet;
packet.Owner = guid;
packet.LootObj = loot->GetGUID();
packet._LootMethod = _lootMethod;
packet._LootMethod = loot->GetLootMethod();
packet.AcquireReason = GetLootTypeForClient(loot_type);
packet.Acquired = true; // false == No Loot (this too^^)
packet.AELooting = aeLooting;
@@ -18206,7 +18190,7 @@ bool Player::isAllowedToLoot(const Creature* creature) const
else if (thisGroup != creature->GetLootRecipientGroup())
return false;
switch (thisGroup->GetLootMethod())
switch (loot->GetLootMethod())
{
case PERSONAL_LOOT: /// @todo implement personal loot (http://wow.gamepedia.com/Loot#Personal_Loot)
return false;
@@ -26039,7 +26023,7 @@ void Player::InitRunes()
void Player::AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store, ItemContext context, bool broadcast, bool createdByPlayer)
{
Loot loot(nullptr, ObjectGuid::Empty, LOOT_NONE);
Loot loot(nullptr, ObjectGuid::Empty, LOOT_NONE, FREE_FOR_ALL);
loot.FillLoot(loot_id, store, this, true, false, LOOT_MODE_DEFAULT, context);
uint32 max_slot = loot.GetMaxSlotInLootFor(this);

View File

@@ -10686,7 +10686,7 @@ void Unit::SetMeleeAnimKitId(uint16 animKitId)
// Generate loot before updating looter
if (creature)
{
creature->m_loot.reset(new Loot(creature->GetMap(), creature->GetGUID(), LOOT_CORPSE));
creature->m_loot.reset(new Loot(creature->GetMap(), creature->GetGUID(), LOOT_CORPSE, group ? group->GetLootMethod() : FREE_FOR_ALL));
Loot* loot = creature->m_loot.get();
if (creature->GetMap()->Is25ManRaid())
loot->maxDuplicates = 3;

View File

@@ -1026,7 +1026,7 @@ void Group::SendLooter(Creature* creature, Player* groupLooter)
lootList.Owner = creature->GetGUID();
lootList.LootObj = creature->m_loot->GetGUID();
if (GetLootMethod() == MASTER_LOOT && creature->m_loot->hasOverThresholdItem())
if (creature->m_loot->GetLootMethod() == MASTER_LOOT && creature->m_loot->hasOverThresholdItem())
lootList.Master = GetMasterLooterGuid();
if (groupLooter)
@@ -1445,7 +1445,7 @@ void Group::CountTheRoll(Rolls::iterator rollI, Map* allowedMap)
player->AutoStoreLoot(disenchant->ID, LootTemplates_Disenchant, ItemContext::NONE, true);
else // If the player's inventory is full, send the disenchant result in a mail.
{
Loot loot(allowedMap, roll->getLoot()->GetOwnerGUID(), LOOT_DISENCHANTING);
Loot loot(allowedMap, roll->getLoot()->GetOwnerGUID(), LOOT_DISENCHANTING, roll->getLoot()->GetLootMethod());
loot.FillLoot(disenchant->ID, LootTemplates_Disenchant, player, true);
uint32 max_slot = loot.GetMaxSlotInLootFor(player);

View File

@@ -384,7 +384,7 @@ void WorldSession::HandleLootMasterGiveOpcode(WorldPackets::Loot::MasterLootItem
{
AELootResult aeResult;
if (!_player->GetGroup() || _player->GetGroup()->GetMasterLooterGuid() != _player->GetGUID() || _player->GetGroup()->GetLootMethod() != MASTER_LOOT)
if (!_player->GetGroup() || _player->GetGroup()->GetMasterLooterGuid() != _player->GetGUID())
{
_player->SendLootError(ObjectGuid::Empty, ObjectGuid::Empty, LOOT_ERROR_DIDNT_KILL);
return;
@@ -411,7 +411,7 @@ void WorldSession::HandleLootMasterGiveOpcode(WorldPackets::Loot::MasterLootItem
return;
}
if (!loot)
if (!loot || loot->GetLootMethod() != MASTER_LOOT)
return;
uint8 slotid = req.LootListID - 1;

View File

@@ -127,9 +127,9 @@ void LootItem::AddAllowedLooter(const Player* player)
// --------- Loot ---------
//
Loot::Loot(Map* map, ObjectGuid owner, LootType type) : gold(0), unlootedCount(0), roundRobinPlayer(), loot_type(type), maxDuplicates(1),
Loot::Loot(Map* map, ObjectGuid owner, LootType type, LootMethod lootMethod) : gold(0), unlootedCount(0), loot_type(type), maxDuplicates(1),
_guid(map ? ObjectGuid::Create<HighGuid::LootObject>(map->GetId(), 0, map->GenerateLowGuid<HighGuid::LootObject>()) : ObjectGuid::Empty),
_owner(owner), _itemContext(ItemContext::NONE)
_owner(owner), _itemContext(ItemContext::NONE), _lootMethod(lootMethod)
{
}
@@ -742,7 +742,7 @@ NotNormalLootItemList* Loot::FillQuestLoot(Player const* player)
{
LootItem &item = quest_items[i];
if (!item.is_looted && (item.AllowedForPlayer(player) || (item.follow_loot_rules && player->GetGroup() && ((player->GetGroup()->GetLootMethod() == MASTER_LOOT && player->GetGroup()->GetMasterLooterGuid() == player->GetGUID()) || player->GetGroup()->GetLootMethod() != MASTER_LOOT))))
if (!item.is_looted && (item.AllowedForPlayer(player) || (item.follow_loot_rules && player->GetGroup() && ((GetLootMethod() == MASTER_LOOT && player->GetGroup()->GetMasterLooterGuid() == player->GetGUID()) || GetLootMethod() != MASTER_LOOT))))
{
ql->push_back(NotNormalLootItem(i));
@@ -752,7 +752,7 @@ NotNormalLootItemList* Loot::FillQuestLoot(Player const* player)
// increase once if one looter only, looter-times if free for all
if (item.freeforall || !item.is_blocked)
++unlootedCount;
if (!player->GetGroup() || (player->GetGroup()->GetLootMethod() != GROUP_LOOT))
if (!player->GetGroup() || (GetLootMethod() != GROUP_LOOT))
item.is_blocked = true;
if (items.size() + ql->size() == MAX_NR_LOOT_ITEMS)

View File

@@ -241,11 +241,12 @@ struct TC_GAME_API Loot
LootType loot_type; // required for achievement system
uint8 maxDuplicates; // Max amount of items with the same entry that can drop (default is 1; on 25 man raid mode 3)
explicit Loot(Map* map, ObjectGuid owner, LootType type);
explicit Loot(Map* map, ObjectGuid owner, LootType type, LootMethod lootMethod);
~Loot();
ObjectGuid const& GetGUID() const { return _guid; }
ObjectGuid const& GetOwnerGUID() const { return _owner; }
LootMethod GetLootMethod() const { return _lootMethod; }
// if loot becomes invalid this reference is used to inform the listener
void addLootValidatorRef(LootValidatorRef* pLootValidatorRef)
@@ -299,6 +300,7 @@ private:
ObjectGuid _guid;
ObjectGuid _owner; // The WorldObject that holds this loot
ItemContext _itemContext;
LootMethod _lootMethod;
};
class TC_GAME_API AELootResult

View File

@@ -113,7 +113,7 @@ void MailDraft::prepareItems(Player* receiver, CharacterDatabaseTransaction tran
if (m_mailTemplateId == 123)
m_money = 1000000;
Loot mailLoot(nullptr, ObjectGuid::Empty, LOOT_NONE);
Loot mailLoot(nullptr, ObjectGuid::Empty, LOOT_NONE, FREE_FOR_ALL);
// can be empty
mailLoot.FillLoot(m_mailTemplateId, LootTemplates_Mail, receiver, true, true, LOOT_MODE_DEFAULT, ItemContext::NONE);