Add a public variable in Group class (Group.h) named m_LastTimeInCombat. it should be a uint32 with a default value of 0.
i.e
Code:
uint32 m_LastTimeInCombat = 0;
Then let's go back to the GroupHandler.cpp to the HandleLootMethodOpcode method.
One solution i've come up with is to use a timestamp, it's not event based or timer tick based.
We'll be using few if statements and getMSTime() method.
Code:
if (lootMethod == MASTER_LOOT)
{
if (group->m_LastTimeInCombat == 0)
group->m_LastTimeInCombat = getMSTime(); // Set the timestamp.
if (group->InCombatToInstance(GetPlayer()->GetInstanceId())) // Check if we are in combat.
{
GetPlayer()->GetSession()->SendNotification("You can't change loot mode in combat");
group->m_LastTimeInCombat = getMSTime(); // If we are in combat just give a new stamp.
return;
}
if (getMSTimeDiff(group->m_LastTimeInCombat, getMSTime()) < 1000 * 60 * 2) // check if the stamp and the current time differences by 2 minutes.
{
GetPlayer()->GetSession()->SendNotification("You need to wait 2 minutes before you can change the loot method");
return;
}
group->m_LastTimeInCombat = 0; // Reset the stamp back to 0.
}
The HandleLootMethodOpcode should now look more like this
Code:
void WorldSession::HandleLootMethodOpcode(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "WORLD: Received CMSG_LOOT_METHOD");
uint32 lootMethod;
ObjectGuid lootMaster;
uint32 lootThreshold;
recvData >> lootMethod >> lootMaster >> lootThreshold;
Group* group = GetPlayer()->GetGroup();
if (!group)
return;
/** error handling **/
if (!group->IsLeader(GetPlayer()->GetGUID()))
return;
if (lootMethod > NEED_BEFORE_GREED)
return;
if (lootThreshold < ITEM_QUALITY_UNCOMMON || lootThreshold > ITEM_QUALITY_ARTIFACT)
return;
if (lootMethod == MASTER_LOOT && !group->IsMember(lootMaster))
return;
if (lootMethod == MASTER_LOOT)
{
if (group->m_LastTimeInCombat == 0)
group->m_LastTimeInCombat = getMSTime(); // Set the timestamp.
if (group->InCombatToInstance(GetPlayer()->GetInstanceId)) // Check if we are in combat.
{
GetPlayer()->GetSession()->SendNotification("You can't change loot mode in combat");
group->m_LastTimeInCombat = getMSTime(); // If we are in combat just give a new stamp.
return;
}
if (getMSTimeDiff(group->m_LastTimeInCombat, getMSTime()) < 1000 * 60 * 2) // check if the stamp and the current time differences by 2 minutes.
{
GetPlayer()->GetSession()->SendNotification("You need to wait 2 minutes before you can change the loot method");
return;
}
group->m_LastTimeInCombat = 0; // Reset the stamp back to 0.
}
/********************/
// everything's fine, do it
group->SetLootMethod((LootMethod)lootMethod);
group->SetMasterLooterGuid(lootMaster);
group->SetLootThreshold((ItemQualities)lootThreshold);
group->SendUpdate();
}
And again i ask you to compile, test and post the results.
Not sure if this is what you're looking for.