mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 16:37:01 +00:00
[10526] Implement server side global cooldown check.
Signed-off-by: VladimirMangos <vladimir@getmangos.com> Also pet/controlled unit global cooldown code replaced by new placed in charmInfo structure. Thanks to nos4r2zod for testing and gcd range check implement.
This commit is contained in:
parent
cb03e5a376
commit
3a8ad26a5e
12 changed files with 142 additions and 26 deletions
|
|
@ -134,7 +134,6 @@ m_creatureInfo(NULL), m_splineFlags(SPLINEFLAG_WALKMODE)
|
|||
|
||||
m_CreatureSpellCooldowns.clear();
|
||||
m_CreatureCategoryCooldowns.clear();
|
||||
m_GlobalCooldown = 0;
|
||||
|
||||
m_splineFlags = SPLINEFLAG_WALKMODE;
|
||||
}
|
||||
|
|
@ -407,11 +406,6 @@ uint32 Creature::ChooseDisplayId(const CreatureInfo *cinfo, const CreatureData *
|
|||
|
||||
void Creature::Update(uint32 diff)
|
||||
{
|
||||
if(m_GlobalCooldown <= diff)
|
||||
m_GlobalCooldown = 0;
|
||||
else
|
||||
m_GlobalCooldown -= diff;
|
||||
|
||||
if (m_needNotify)
|
||||
{
|
||||
m_needNotify = false;
|
||||
|
|
@ -2025,8 +2019,6 @@ void Creature::AddCreatureSpellCooldown(uint32 spellid)
|
|||
|
||||
if(spellInfo->Category)
|
||||
_AddCreatureCategoryCooldown(spellInfo->Category, time(NULL));
|
||||
|
||||
m_GlobalCooldown = spellInfo->StartRecoveryTime;
|
||||
}
|
||||
|
||||
bool Creature::HasCategoryCooldown(uint32 spell_id) const
|
||||
|
|
@ -2035,10 +2027,6 @@ bool Creature::HasCategoryCooldown(uint32 spell_id) const
|
|||
if(!spellInfo)
|
||||
return false;
|
||||
|
||||
// check global cooldown if spell affected by it
|
||||
if (spellInfo->StartRecoveryCategory > 0 && m_GlobalCooldown > 0)
|
||||
return true;
|
||||
|
||||
CreatureSpellCooldowns::const_iterator itr = m_CreatureCategoryCooldowns.find(spellInfo->Category);
|
||||
return (itr != m_CreatureCategoryCooldowns.end() && time_t(itr->second + (spellInfo->CategoryRecoveryTime / IN_MILLISECONDS)) > time(NULL));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -560,7 +560,6 @@ class MANGOS_DLL_SPEC Creature : public Unit
|
|||
uint32 m_spells[CREATURE_MAX_SPELLS];
|
||||
CreatureSpellCooldowns m_CreatureSpellCooldowns;
|
||||
CreatureSpellCooldowns m_CreatureCategoryCooldowns;
|
||||
uint32 m_GlobalCooldown;
|
||||
|
||||
float GetAttackDistance(Unit const* pl) const;
|
||||
|
||||
|
|
@ -629,8 +628,6 @@ class MANGOS_DLL_SPEC Creature : public Unit
|
|||
void SetSummonPoint(float fX, float fY, float fZ, float fOrient) { m_summonXpoint = fX; m_summonYpoint = fY; m_summonZpoint = fZ; m_summonOrientation = fOrient; }
|
||||
void GetSummonPoint(float &fX, float &fY, float &fZ, float &fOrient) const { fX = m_summonXpoint; fY = m_summonYpoint; fZ = m_summonZpoint; fOrient = m_summonOrientation; }
|
||||
|
||||
uint32 GetGlobalCooldown() const { return m_GlobalCooldown; }
|
||||
|
||||
void SetDeadByDefault (bool death_state) { m_isDeadByDefault = death_state; }
|
||||
|
||||
void SetActiveObjectState(bool on);
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ void PetAI::UpdateAI(const uint32 diff)
|
|||
}
|
||||
|
||||
// Autocast (casted only in combat or persistent spells in any state)
|
||||
if (m_creature->GetGlobalCooldown() == 0 && !m_creature->IsNonMeleeSpellCasted(false))
|
||||
if (!m_creature->IsNonMeleeSpellCasted(false))
|
||||
{
|
||||
typedef std::vector<std::pair<Unit*, Spell*> > TargetSpellList;
|
||||
TargetSpellList targetSpellStore;
|
||||
|
|
@ -215,6 +215,9 @@ void PetAI::UpdateAI(const uint32 diff)
|
|||
if (!spellInfo)
|
||||
continue;
|
||||
|
||||
if (m_creature->GetCharmInfo() && m_creature->GetCharmInfo()->GetGlobalCooldownMgr().HasGlobalCooldown(spellInfo))
|
||||
continue;
|
||||
|
||||
// ignore some combinations of combat state and combat/noncombat spells
|
||||
if (!inCombat)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -170,9 +170,6 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
|
|||
case ACT_ENABLED: // 0xC1 spell
|
||||
{
|
||||
Unit* unit_target = NULL;
|
||||
if (((Creature*)pet)->GetGlobalCooldown() > 0)
|
||||
return;
|
||||
|
||||
if(guid2)
|
||||
unit_target = _player->GetMap()->GetUnit(guid2);
|
||||
|
||||
|
|
@ -184,6 +181,9 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
|
|||
return;
|
||||
}
|
||||
|
||||
if (pet->GetCharmInfo() && pet->GetCharmInfo()->GetGlobalCooldownMgr().HasGlobalCooldown(spellInfo))
|
||||
return;
|
||||
|
||||
for(int i = 0; i < MAX_EFFECT_INDEX;++i)
|
||||
{
|
||||
if(spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA || spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_INSTANT || spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_CHANNELED)
|
||||
|
|
@ -615,9 +615,6 @@ void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket )
|
|||
return;
|
||||
}
|
||||
|
||||
if (pet->GetGlobalCooldown() > 0)
|
||||
return;
|
||||
|
||||
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid);
|
||||
if (!spellInfo)
|
||||
{
|
||||
|
|
@ -625,6 +622,10 @@ void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket )
|
|||
return;
|
||||
}
|
||||
|
||||
if (pet->GetCharmInfo() && pet->GetCharmInfo()->GetGlobalCooldownMgr().HasGlobalCooldown(spellInfo))
|
||||
return;
|
||||
|
||||
|
||||
// do not cast not learned spells
|
||||
if (!pet->HasSpell(spellid) || IsPassiveSpell(spellInfo))
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1723,6 +1723,8 @@ class MANGOS_DLL_SPEC Player : public Unit
|
|||
void RemoveSpellCategoryCooldown(uint32 cat, bool update = false);
|
||||
void SendClearCooldown( uint32 spell_id, Unit* target );
|
||||
|
||||
GlobalCooldownMgr& GetGlobalCooldownMgr() { return m_GlobalCooldownMgr; }
|
||||
|
||||
void RemoveArenaSpellCooldowns();
|
||||
void RemoveAllSpellCooldown();
|
||||
void _LoadSpellCooldowns(QueryResult *result);
|
||||
|
|
@ -2524,6 +2526,8 @@ class MANGOS_DLL_SPEC Player : public Unit
|
|||
SpellCooldowns m_spellCooldowns;
|
||||
uint32 m_lastPotionId; // last used health/mana potion in combat, that block next potion use
|
||||
|
||||
GlobalCooldownMgr m_GlobalCooldownMgr;
|
||||
|
||||
uint8 m_activeSpec;
|
||||
uint8 m_specsCount;
|
||||
|
||||
|
|
|
|||
|
|
@ -2669,6 +2669,8 @@ void Spell::prepare(SpellCastTargets const* targets, Aura* triggeredByAura)
|
|||
|
||||
// will show cast bar
|
||||
SendSpellStart();
|
||||
|
||||
TriggerGlobalCooldown();
|
||||
}
|
||||
// execute triggered without cast time explicitly in call point
|
||||
else if(m_timer == 0)
|
||||
|
|
@ -2690,6 +2692,9 @@ void Spell::cancel()
|
|||
switch (m_spellState)
|
||||
{
|
||||
case SPELL_STATE_PREPARING:
|
||||
CancelGlobalCooldown();
|
||||
|
||||
//(no break)
|
||||
case SPELL_STATE_DELAYED:
|
||||
{
|
||||
SendInterrupted(0);
|
||||
|
|
@ -4216,6 +4221,10 @@ SpellCastResult Spell::CheckCast(bool strict)
|
|||
return SPELL_FAILED_NOT_READY;
|
||||
}
|
||||
|
||||
// check global cooldown
|
||||
if (strict && !m_IsTriggeredSpell && HasGlobalCooldown())
|
||||
return SPELL_FAILED_NOT_READY;
|
||||
|
||||
// only allow triggered spells if at an ended battleground
|
||||
if (!m_IsTriggeredSpell && m_caster->GetTypeId() == TYPEID_PLAYER)
|
||||
if(BattleGround * bg = ((Player*)m_caster)->GetBattleGround())
|
||||
|
|
@ -6767,3 +6776,61 @@ void Spell::ClearCastItem()
|
|||
|
||||
m_CastItem = NULL;
|
||||
}
|
||||
|
||||
bool Spell::HasGlobalCooldown()
|
||||
{
|
||||
// global cooldown have only player or controlled units
|
||||
if (m_caster->GetCharmInfo())
|
||||
return m_caster->GetCharmInfo()->GetGlobalCooldownMgr().HasGlobalCooldown(m_spellInfo);
|
||||
else if (m_caster->GetTypeId() == TYPEID_PLAYER)
|
||||
return ((Player*)m_caster)->GetGlobalCooldownMgr().HasGlobalCooldown(m_spellInfo);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void Spell::TriggerGlobalCooldown()
|
||||
{
|
||||
int32 gcd = m_spellInfo->StartRecoveryTime;
|
||||
if (!gcd)
|
||||
return;
|
||||
|
||||
// global cooldown can't leave range 1..1.5 secs (if it it)
|
||||
// exist some spells (mostly not player directly casted) that have < 1 sec and > 1.5 sec global cooldowns
|
||||
// but its as test show not affected any spell mods.
|
||||
if (m_spellInfo->StartRecoveryTime >= 1000 && m_spellInfo->StartRecoveryTime <= 1500)
|
||||
{
|
||||
// gcd modifier auras applied only to self spells and only player have mods for this
|
||||
if (m_caster->GetTypeId() == TYPEID_PLAYER)
|
||||
((Player*)m_caster)->ApplySpellMod(m_spellInfo->Id, SPELLMOD_GLOBAL_COOLDOWN, gcd, this);
|
||||
|
||||
// apply haste rating
|
||||
gcd = int32(float(gcd) * m_caster->GetFloatValue(UNIT_MOD_CAST_SPEED));
|
||||
|
||||
if (gcd < 1000)
|
||||
gcd = 1000;
|
||||
else if (gcd > 1500)
|
||||
gcd = 1500;
|
||||
}
|
||||
|
||||
// global cooldown have only player or controlled units
|
||||
if (m_caster->GetCharmInfo())
|
||||
m_caster->GetCharmInfo()->GetGlobalCooldownMgr().AddGlobalCooldown(m_spellInfo, gcd);
|
||||
else if (m_caster->GetTypeId() == TYPEID_PLAYER)
|
||||
((Player*)m_caster)->GetGlobalCooldownMgr().AddGlobalCooldown(m_spellInfo, gcd);
|
||||
}
|
||||
|
||||
void Spell::CancelGlobalCooldown()
|
||||
{
|
||||
if (!m_spellInfo->StartRecoveryTime)
|
||||
return;
|
||||
|
||||
// cancel global cooldown when interrupting current cast
|
||||
if (m_caster->GetCurrentSpell(CURRENT_GENERIC_SPELL) != this)
|
||||
return;
|
||||
|
||||
// global cooldown have only player or controlled units
|
||||
if (m_caster->GetCharmInfo())
|
||||
m_caster->GetCharmInfo()->GetGlobalCooldownMgr().CancelGlobalCooldown(m_spellInfo);
|
||||
else if (m_caster->GetTypeId() == TYPEID_PLAYER)
|
||||
((Player*)m_caster)->GetGlobalCooldownMgr().CancelGlobalCooldown(m_spellInfo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -345,7 +345,9 @@ class Spell
|
|||
~Spell();
|
||||
|
||||
void prepare(SpellCastTargets const* targets, Aura* triggeredByAura = NULL);
|
||||
|
||||
void cancel();
|
||||
|
||||
void update(uint32 difftime);
|
||||
void cast(bool skipCheck = false);
|
||||
void finish(bool ok = true);
|
||||
|
|
@ -482,6 +484,9 @@ class Spell
|
|||
|
||||
static void SelectMountByAreaAndSkill(Unit* target, uint32 spellId75, uint32 spellId150, uint32 spellId225, uint32 spellId300, uint32 spellIdSpecial);
|
||||
protected:
|
||||
bool HasGlobalCooldown();
|
||||
void TriggerGlobalCooldown();
|
||||
void CancelGlobalCooldown();
|
||||
|
||||
void SendLoot(uint64 guid, LootType loottype);
|
||||
bool IgnoreItemRequirements() const; // some item use spells have unexpected reagent data
|
||||
|
|
|
|||
|
|
@ -1015,7 +1015,7 @@ void Aura::ReapplyAffectedPassiveAuras()
|
|||
case SPELLMOD_COOLDOWN:
|
||||
case SPELLMOD_COST:
|
||||
case SPELLMOD_ACTIVATION_TIME:
|
||||
case SPELLMOD_CASTING_TIME_OLD:
|
||||
case SPELLMOD_GLOBAL_COOLDOWN:
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@ float baseMoveSpeed[MAX_MOVE_TYPE] =
|
|||
3.14f // MOVE_PITCH_RATE
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Methods of class MovementInfo
|
||||
|
||||
void MovementInfo::Read(ByteBuffer &data)
|
||||
{
|
||||
data >> moveFlags;
|
||||
|
|
@ -155,6 +158,28 @@ void MovementInfo::Write(ByteBuffer &data) const
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Methods of class GlobalCooldownMgr
|
||||
|
||||
bool GlobalCooldownMgr::HasGlobalCooldown(SpellEntry const* spellInfo) const
|
||||
{
|
||||
GlobalCooldownList::const_iterator itr = m_GlobalCooldowns.find(spellInfo->StartRecoveryCategory);
|
||||
return itr != m_GlobalCooldowns.end() && itr->second.duration && getMSTimeDiff(itr->second.cast_time, getMSTime()) < itr->second.duration;
|
||||
}
|
||||
|
||||
void GlobalCooldownMgr::AddGlobalCooldown(SpellEntry const* spellInfo, uint32 gcd)
|
||||
{
|
||||
m_GlobalCooldowns[spellInfo->StartRecoveryCategory] = GlobalCooldown(gcd, getMSTime());
|
||||
}
|
||||
|
||||
void GlobalCooldownMgr::CancelGlobalCooldown(SpellEntry const* spellInfo)
|
||||
{
|
||||
m_GlobalCooldowns[spellInfo->StartRecoveryCategory].duration = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Methods of class Unit
|
||||
|
||||
Unit::Unit()
|
||||
: WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostileRefManager(this)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ enum SpellModOp
|
|||
SPELLMOD_CHANCE_OF_SUCCESS = 18, // Only used with SPELL_AURA_ADD_FLAT_MODIFIER and affects proc spells
|
||||
SPELLMOD_ACTIVATION_TIME = 19,
|
||||
SPELLMOD_EFFECT_PAST_FIRST = 20,
|
||||
SPELLMOD_CASTING_TIME_OLD = 21,
|
||||
SPELLMOD_GLOBAL_COOLDOWN = 21,
|
||||
SPELLMOD_DOT = 22,
|
||||
SPELLMOD_EFFECT3 = 23,
|
||||
SPELLMOD_SPELL_BONUS_DAMAGE = 24,
|
||||
|
|
@ -960,6 +960,29 @@ enum CurrentSpellTypes
|
|||
#define CURRENT_FIRST_NON_MELEE_SPELL 1
|
||||
#define CURRENT_MAX_SPELL 4
|
||||
|
||||
struct GlobalCooldown
|
||||
{
|
||||
explicit GlobalCooldown(uint32 _dur = 0, uint32 _time = 0) : duration(_dur), cast_time(_time) {}
|
||||
|
||||
uint32 duration;
|
||||
uint32 cast_time;
|
||||
};
|
||||
|
||||
typedef UNORDERED_MAP<uint32 /*category*/, GlobalCooldown> GlobalCooldownList;
|
||||
|
||||
class GlobalCooldownMgr // Shared by Player and CharmInfo
|
||||
{
|
||||
public:
|
||||
GlobalCooldownMgr() {}
|
||||
|
||||
public:
|
||||
bool HasGlobalCooldown(SpellEntry const* spellInfo) const;
|
||||
void AddGlobalCooldown(SpellEntry const* spellInfo, uint32 gcd);
|
||||
void CancelGlobalCooldown(SpellEntry const* spellInfo);
|
||||
|
||||
private:
|
||||
GlobalCooldownList m_GlobalCooldowns;
|
||||
};
|
||||
|
||||
enum ActiveStates
|
||||
{
|
||||
|
|
@ -1068,6 +1091,8 @@ struct CharmInfo
|
|||
void ToggleCreatureAutocast(uint32 spellid, bool apply);
|
||||
|
||||
CharmSpellEntry* GetCharmSpell(uint8 index) { return &(m_charmspells[index]); }
|
||||
|
||||
GlobalCooldownMgr& GetGlobalCooldownMgr() { return m_GlobalCooldownMgr; }
|
||||
private:
|
||||
|
||||
Unit* m_unit;
|
||||
|
|
@ -1076,6 +1101,7 @@ struct CharmInfo
|
|||
CommandStates m_CommandState;
|
||||
ReactStates m_reactState;
|
||||
uint32 m_petnumber;
|
||||
GlobalCooldownMgr m_GlobalCooldownMgr;
|
||||
};
|
||||
|
||||
// for clearing special attacks
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "10525"
|
||||
#define REVISION_NR "10526"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue