Skip to content

Commit

Permalink
Merge pull request #16287 from GigaDev90/fix_bug_duel_abuse
Browse files Browse the repository at this point in the history
Core/Script: fix bug that prevent double spending reset cooldown
  • Loading branch information
FrancescoBorzi committed Jan 26, 2016
2 parents 06cc897 + c0ed819 commit d0e4f28
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/server/scripts/World/duel_reset.cpp
Expand Up @@ -34,9 +34,8 @@ class DuelResetScript : public PlayerScript
player1->GetSpellHistory()->SaveCooldownStateBeforeDuel();
player2->GetSpellHistory()->SaveCooldownStateBeforeDuel();


ResetSpellCooldowns(player1);
ResetSpellCooldowns(player2);
ResetSpellCooldowns(player1, true);
ResetSpellCooldowns(player2, true);
}

// Health and mana reset
Expand Down Expand Up @@ -73,9 +72,8 @@ class DuelResetScript : public PlayerScript
// Cooldown restore
if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_COOLDOWNS))
{

ResetSpellCooldowns(winner);
ResetSpellCooldowns(loser);
ResetSpellCooldowns(winner, false);
ResetSpellCooldowns(loser, false);

winner->GetSpellHistory()->RestoreCooldownStateAfterDuel();
loser->GetSpellHistory()->RestoreCooldownStateAfterDuel();
Expand All @@ -98,14 +96,35 @@ class DuelResetScript : public PlayerScript
}
}

static void ResetSpellCooldowns(Player* player)
static void ResetSpellCooldowns(Player* player, bool onStartDuel)
{
// remove cooldowns on spells that have < 10 min CD and has no onHold
player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool
if (onStartDuel)
{
SpellInfo const* spellInfo = sSpellMgr->EnsureSpellInfo(itr->first);
return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS && spellInfo->CategoryRecoveryTime < 10 * MINUTE * IN_MILLISECONDS && !itr->second.OnHold;
}, true);
// remove cooldowns on spells that have < 10 min CD > 30 sec and has no onHold
player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool
{
SpellHistory::Clock::time_point now = SpellHistory::Clock::now();
uint32 cooldownDuration = itr->second.CooldownEnd > now ? std::chrono::duration_cast<std::chrono::milliseconds>(itr->second.CooldownEnd - now).count() : 0;
SpellInfo const* spellInfo = sSpellMgr->EnsureSpellInfo(itr->first);
return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS
&& spellInfo->CategoryRecoveryTime < 10 * MINUTE * IN_MILLISECONDS
&& !itr->second.OnHold
&& cooldownDuration > 0
&& ( spellInfo->RecoveryTime - cooldownDuration ) > (MINUTE / 2) * IN_MILLISECONDS
&& ( spellInfo->CategoryRecoveryTime - cooldownDuration ) > (MINUTE / 2) * IN_MILLISECONDS;
}, true);
}
else
{
// remove cooldowns on spells that have < 10 min CD and has no onHold
player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool
{
SpellInfo const* spellInfo = sSpellMgr->EnsureSpellInfo(itr->first);
return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS
&& spellInfo->CategoryRecoveryTime < 10 * MINUTE * IN_MILLISECONDS
&& !itr->second.OnHold;
}, true);
}

// pet cooldowns
if (Pet* pet = player->GetPet())
Expand Down

0 comments on commit d0e4f28

Please sign in to comment.