Merge pull request #15732 from ShinDarth/reset-health-mana

Scripts/Duel: implement duel reset of health and mana and improve duel reset
This commit is contained in:
MitchesD
2015-11-12 19:40:26 +01:00
6 changed files with 100 additions and 23 deletions

View File

@@ -1947,6 +1947,12 @@ class Player : public Unit, public GridObject<Player>
void SetHonorPoints(uint32 value);
void SetArenaPoints(uint32 value);
// duel health and mana reset methods
void SaveHealthBeforeDuel() { healthBeforeDuel = GetHealth(); }
void SaveManaBeforeDuel() { manaBeforeDuel = GetPower(POWER_MANA); }
void RestoreHealthAfterDuel() { SetHealth(healthBeforeDuel); }
void RestoreManaAfterDuel() { SetPower(POWER_MANA, manaBeforeDuel); }
//End of PvP System
void SetDrunkValue(uint8 newDrunkValue, uint32 itemId = 0);
@@ -2630,6 +2636,10 @@ class Player : public Unit, public GridObject<Player>
uint32 _activeCheats;
// variables to save health and mana before duel and restore them after duel
uint32 healthBeforeDuel;
uint32 manaBeforeDuel;
WorldLocation _corpseLocation;
};

View File

@@ -671,19 +671,14 @@ void SpellHistory::RestoreCooldownStateAfterDuel()
_spellCooldownsBeforeDuel[itr->first] = _spellCooldowns[itr->first];
}
_spellCooldowns = _spellCooldownsBeforeDuel;
// update the client: clear all cooldowns
std::vector<int32> resetCooldowns;
resetCooldowns.reserve(_spellCooldowns.size());
for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end(); ++itr)
resetCooldowns.push_back(itr->first);
if (resetCooldowns.empty())
return;
SendClearCooldowns(resetCooldowns);
// check for spell with onHold active before and during the duel
for (auto itr = _spellCooldownsBeforeDuel.begin(); itr != _spellCooldownsBeforeDuel.end(); ++itr)
{
if (!itr->second.OnHold &&
_spellCooldowns.find(itr->first) != _spellCooldowns.end() &&
!_spellCooldowns[itr->first].OnHold)
_spellCooldowns[itr->first] = _spellCooldownsBeforeDuel[itr->first];
}
// update the client: restore old cooldowns
PacketCooldowns cooldowns;
@@ -694,14 +689,14 @@ void SpellHistory::RestoreCooldownStateAfterDuel()
uint32 cooldownDuration = itr->second.CooldownEnd > now ? std::chrono::duration_cast<std::chrono::milliseconds>(itr->second.CooldownEnd - now).count() : 0;
// cooldownDuration must be between 0 and 10 minutes in order to avoid any visual bugs
if (cooldownDuration == 0 || cooldownDuration > 10 * MINUTE * IN_MILLISECONDS)
if (cooldownDuration <= 0 || cooldownDuration > 10 * MINUTE * IN_MILLISECONDS || itr->second.OnHold)
continue;
cooldowns[itr->first] = cooldownDuration;
}
WorldPacket data;
BuildCooldownPacket(data, SPELL_COOLDOWN_FLAG_NONE, cooldowns);
BuildCooldownPacket(data, SPELL_COOLDOWN_FLAG_INCLUDE_EVENT_COOLDOWNS, cooldowns);
player->SendDirectMessage(&data);
}
}

View File

@@ -1183,6 +1183,7 @@ void World::LoadConfigSettings(bool reload)
m_bool_configs[CONFIG_START_ALL_SPELLS] = sConfigMgr->GetBoolDefault("PlayerStart.AllSpells", false);
m_int_configs[CONFIG_HONOR_AFTER_DUEL] = sConfigMgr->GetIntDefault("HonorPointsAfterDuel", 0);
m_bool_configs[CONFIG_RESET_DUEL_COOLDOWNS] = sConfigMgr->GetBoolDefault("ResetDuelCooldowns", false);
m_bool_configs[CONFIG_RESET_DUEL_HEALTH_MANA] = sConfigMgr->GetBoolDefault("ResetDuelHealthMana", false);
m_bool_configs[CONFIG_START_ALL_EXPLORED] = sConfigMgr->GetBoolDefault("PlayerStart.MapsExplored", false);
m_bool_configs[CONFIG_START_ALL_REP] = sConfigMgr->GetBoolDefault("PlayerStart.AllReputation", false);
m_bool_configs[CONFIG_ALWAYS_MAXSKILL] = sConfigMgr->GetBoolDefault("AlwaysMaxWeaponSkill", false);

View File

@@ -164,6 +164,7 @@ enum WorldBoolConfigs
CONFIG_CALCULATE_CREATURE_ZONE_AREA_DATA,
CONFIG_CALCULATE_GAMEOBJECT_ZONE_AREA_DATA,
CONFIG_RESET_DUEL_COOLDOWNS,
CONFIG_RESET_DUEL_HEALTH_MANA,
BOOL_CONFIG_VALUE_COUNT
};

View File

@@ -17,6 +17,7 @@
#include "ScriptMgr.h"
#include "Player.h"
#include "Pet.h"
class DuelResetScript : public PlayerScript
{
@@ -26,28 +27,90 @@ class DuelResetScript : public PlayerScript
// Called when a duel starts (after 3s countdown)
void OnDuelStart(Player* player1, Player* player2) override
{
// Cooldowns reset
if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_COOLDOWNS))
{
player1->GetSpellHistory()->SaveCooldownStateBeforeDuel();
player2->GetSpellHistory()->SaveCooldownStateBeforeDuel();
player1->RemoveArenaSpellCooldowns(true);
player2->RemoveArenaSpellCooldowns(true);
ResetSpellCooldowns(player1, true);
ResetSpellCooldowns(player2, true);
}
// Health and mana reset
if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_HEALTH_MANA))
{
player1->SaveHealthBeforeDuel();
player1->SetHealth(player1->GetMaxHealth());
player2->SaveHealthBeforeDuel();
player2->SetHealth(player2->GetMaxHealth());
// check if player1 class uses mana
if (player1->getPowerType() == POWER_MANA || player1->getClass() == CLASS_DRUID)
{
player1->SaveManaBeforeDuel();
player1->SetPower(POWER_MANA, player1->GetMaxPower(POWER_MANA));
}
// check if player2 class uses mana
if (player2->getPowerType() == POWER_MANA || player2->getClass() == CLASS_DRUID)
{
player2->SaveManaBeforeDuel();
player2->SetPower(POWER_MANA, player2->GetMaxPower(POWER_MANA));
}
}
}
// Called when a duel ends
void OnDuelEnd(Player* winner, Player* loser, DuelCompleteType /*type*/) override
void OnDuelEnd(Player* winner, Player* loser, DuelCompleteType type) override
{
if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_COOLDOWNS))
// do not reset anything if DUEL_INTERRUPTED or DUEL_FLED
if (type == DUEL_WON)
{
winner->RemoveArenaSpellCooldowns(true);
loser->RemoveArenaSpellCooldowns(true);
// Cooldown restore
if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_COOLDOWNS))
{
winner->GetSpellHistory()->RestoreCooldownStateAfterDuel();
loser->GetSpellHistory()->RestoreCooldownStateAfterDuel();
ResetSpellCooldowns(winner, true);
ResetSpellCooldowns(loser, true);
winner->GetSpellHistory()->RestoreCooldownStateAfterDuel();
loser->GetSpellHistory()->RestoreCooldownStateAfterDuel();
}
// Health and mana restore
if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_HEALTH_MANA))
{
winner->RestoreHealthAfterDuel();
loser->RestoreHealthAfterDuel();
// check if player1 class uses mana
if (winner->getPowerType() == POWER_MANA || winner->getClass() == CLASS_DRUID)
winner->RestoreManaAfterDuel();
// check if player2 class uses mana
if (loser->getPowerType() == POWER_MANA || loser->getClass() == CLASS_DRUID)
loser->RestoreManaAfterDuel();
}
}
}
void ResetSpellCooldowns(Player* player, bool removeActivePetCooldowns)
{
// 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 (removeActivePetCooldowns)
if (Pet* pet = player->GetPet())
pet->GetSpellHistory()->ResetAllCooldowns();
}
};
void AddSC_duel_reset()

View File

@@ -2640,6 +2640,13 @@ HonorPointsAfterDuel = 0
ResetDuelCooldowns = 0
# ResetDuelHealthMana
# Description: Reset health and mana before duel starts and restore them when duel ends.
# Default: 0 - (Disabled)
# 1 - (Enabled)
ResetDuelHealthMana = 0
#
# AlwaysMaxWeaponSkill
# Description: Players will automatically gain max weapon/defense skill when logging in,