*Update dispel code and fix crash related to it. Thanks to megamage.

--HG--
branch : trunk
This commit is contained in:
QAston
2009-03-23 01:54:50 +01:00
parent b5eed3626d
commit ce71c0e798
7 changed files with 120 additions and 123 deletions
+44 -44
View File
@@ -1,44 +1,44 @@
-- This file contains all waypoints used by escortAI scripts -- This file contains all waypoints used by escortAI scripts
/* GHOSTLANDS */ /* GHOSTLANDS */
DELETE FROM script_waypoint WHERE entry=16295; DELETE FROM script_waypoint WHERE entry=16295;
INSERT INTO script_waypoint VALUES INSERT INTO script_waypoint VALUES
(16295, 0, 7545.070000, -7359.870000, 162.354000, 4000, 'SAY_START'), (16295, 0, 7545.070000, -7359.870000, 162.354000, 4000, 'SAY_START'),
(16295, 1, 7550.048340, -7362.237793, 162.235657, 0, ''), (16295, 1, 7550.048340, -7362.237793, 162.235657, 0, ''),
(16295, 2, 7566.976074, -7364.315430, 161.738770, 0, ''), (16295, 2, 7566.976074, -7364.315430, 161.738770, 0, ''),
(16295, 3, 7578.830566, -7361.677734, 161.738770, 0, ''), (16295, 3, 7578.830566, -7361.677734, 161.738770, 0, ''),
(16295, 4, 7590.969238, -7359.053711, 162.257660, 0, ''), (16295, 4, 7590.969238, -7359.053711, 162.257660, 0, ''),
(16295, 5, 7598.354004, -7362.815430, 162.256683, 4000, 'SAY_PROGRESS_1'), (16295, 5, 7598.354004, -7362.815430, 162.256683, 4000, 'SAY_PROGRESS_1'),
(16295, 6, 7605.861328, -7380.424316, 161.937073, 0, ''), (16295, 6, 7605.861328, -7380.424316, 161.937073, 0, ''),
(16295, 7, 7605.295410, -7387.382813, 157.253998, 0, ''), (16295, 7, 7605.295410, -7387.382813, 157.253998, 0, ''),
(16295, 8, 7606.131836, -7393.893555, 156.941925, 0, ''), (16295, 8, 7606.131836, -7393.893555, 156.941925, 0, ''),
(16295, 9, 7615.207520, -7400.187012, 157.142639, 0, ''), (16295, 9, 7615.207520, -7400.187012, 157.142639, 0, ''),
(16295, 10, 7618.956543, -7402.652832, 158.202042, 0, ''), (16295, 10, 7618.956543, -7402.652832, 158.202042, 0, ''),
(16295, 11, 7636.850586, -7401.756836, 162.144791, 0, 'SAY_PROGRESS_2'), (16295, 11, 7636.850586, -7401.756836, 162.144791, 0, 'SAY_PROGRESS_2'),
(16295, 12, 7637.058105, -7404.944824, 162.206970, 4000, ''), (16295, 12, 7637.058105, -7404.944824, 162.206970, 4000, ''),
(16295, 13, 7636.910645, -7412.585449, 162.366425, 0, ''), (16295, 13, 7636.910645, -7412.585449, 162.366425, 0, ''),
(16295, 14, 7637.607910, -7425.591797, 162.630661, 0, ''), (16295, 14, 7637.607910, -7425.591797, 162.630661, 0, ''),
(16295, 15, 7637.816895, -7459.057129, 163.302704, 0, ''), (16295, 15, 7637.816895, -7459.057129, 163.302704, 0, ''),
(16295, 16, 7638.859863, -7470.902344, 162.517059, 0, ''), (16295, 16, 7638.859863, -7470.902344, 162.517059, 0, ''),
(16295, 17, 7641.395996, -7488.217285, 157.381287, 0, ''), (16295, 17, 7641.395996, -7488.217285, 157.381287, 0, ''),
(16295, 18, 7634.455566, -7505.451660, 154.682159, 0, 'SAY_PROGRESS_3'), (16295, 18, 7634.455566, -7505.451660, 154.682159, 0, 'SAY_PROGRESS_3'),
(16295, 19, 7631.906738, -7516.948730, 153.597382, 0, ''), (16295, 19, 7631.906738, -7516.948730, 153.597382, 0, ''),
(16295, 20, 7622.231445, -7537.037598, 151.587112, 0, ''), (16295, 20, 7622.231445, -7537.037598, 151.587112, 0, ''),
(16295, 21, 7610.921875, -7550.670410, 149.639374, 0, ''), (16295, 21, 7610.921875, -7550.670410, 149.639374, 0, ''),
(16295, 22, 7598.229004, -7562.551758, 145.953888, 0, ''), (16295, 22, 7598.229004, -7562.551758, 145.953888, 0, ''),
(16295, 23, 7588.509277, -7577.755371, 148.294479, 0, ''), (16295, 23, 7588.509277, -7577.755371, 148.294479, 0, ''),
(16295, 24, 7567.339355, -7608.456055, 146.006485, 0, ''), (16295, 24, 7567.339355, -7608.456055, 146.006485, 0, ''),
(16295, 25, 7562.547852, -7617.417969, 148.097504, 0, ''), (16295, 25, 7562.547852, -7617.417969, 148.097504, 0, ''),
(16295, 26, 7561.508789, -7645.064453, 151.245163, 0, ''), (16295, 26, 7561.508789, -7645.064453, 151.245163, 0, ''),
(16295, 27, 7563.337402, -7654.652344, 151.227158, 0, ''), (16295, 27, 7563.337402, -7654.652344, 151.227158, 0, ''),
(16295, 28, 7565.533691, -7658.296387, 151.248886, 0, ''), (16295, 28, 7565.533691, -7658.296387, 151.248886, 0, ''),
(16295, 39, 7571.155762, -7659.118652, 151.244568, 0, ''), (16295, 39, 7571.155762, -7659.118652, 151.244568, 0, ''),
(16295, 30, 7579.119629, -7662.213867, 151.651505, 0, 'quest complete'), (16295, 30, 7579.119629, -7662.213867, 151.651505, 0, 'quest complete'),
(16295, 31, 7603.768066, -7667.000488, 153.997726, 0, ''), (16295, 31, 7603.768066, -7667.000488, 153.997726, 0, ''),
(16295, 32, 7603.768066, -7667.000488, 153.997726, 4000, 'SAY_END_1'), (16295, 32, 7603.768066, -7667.000488, 153.997726, 4000, 'SAY_END_1'),
(16295, 33, 7603.768066, -7667.000488, 153.997726, 8000, 'SAY_END_2'), (16295, 33, 7603.768066, -7667.000488, 153.997726, 8000, 'SAY_END_2'),
(16295, 34, 7603.768066, -7667.000488, 153.997726, 0, ''); (16295, 34, 7603.768066, -7667.000488, 153.997726, 0, '');
/* EOF */ /* EOF */
-15
View File
@@ -5245,21 +5245,6 @@ void Aura::HandleShapeshiftBoosts(bool apply)
m_target->SetHealth(uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage)));*/ m_target->SetHealth(uint32(ceil((double)m_target->GetMaxHealth() * healthPercentage)));*/
} }
bool Aura::GetDispelChance(Spell* spell)
{
// we assume that aura dispel chance is 100% on start
// need formula for level difference based chance
int32 miss_chance = 100;
// Apply dispel mod from aura caster
if (Unit *caster = GetCaster())
{
if ( Player* modOwner = caster->GetSpellModOwner() )
modOwner->ApplySpellMod(GetId(), SPELLMOD_RESIST_DISPEL_CHANCE, miss_chance, spell);
}
// Try dispel
return roll_chance_i(miss_chance);
}
void Aura::HandleAuraEmpathy(bool apply, bool Real) void Aura::HandleAuraEmpathy(bool apply, bool Real)
{ {
if(m_target->GetTypeId() != TYPEID_UNIT) if(m_target->GetTypeId() != TYPEID_UNIT)
-2
View File
@@ -318,8 +318,6 @@ class TRINITY_DLL_SPEC Aura
void HandleAuraAllowOnlyAbility(bool apply, bool Real); void HandleAuraAllowOnlyAbility(bool apply, bool Real);
void HandleShapeshiftBoosts(bool apply); void HandleShapeshiftBoosts(bool apply);
bool GetDispelChance(Spell* spell);
// Allow Apply Aura Handler to modify and access m_AuraDRGroup // Allow Apply Aura Handler to modify and access m_AuraDRGroup
void setDiminishGroup(DiminishingGroup group) { m_AuraDRGroup = group; } void setDiminishGroup(DiminishingGroup group) { m_AuraDRGroup = group; }
DiminishingGroup getDiminishGroup() const { return m_AuraDRGroup; } DiminishingGroup getDiminishGroup() const { return m_AuraDRGroup; }
+34 -35
View File
@@ -3464,8 +3464,9 @@ void Spell::EffectDispel(uint32 i)
if(!unitTarget) if(!unitTarget)
return; return;
// Fill possible dispel list //std::vector <DispelEntry> dispel_list;
std::vector <Aura *> dispel_list; DispelSet dispel_list;
DispelEntry entry;
// Create dispel mask by dispel type // Create dispel mask by dispel type
uint32 dispel_type = m_spellInfo->EffectMiscValue[i]; uint32 dispel_type = m_spellInfo->EffectMiscValue[i];
@@ -3489,43 +3490,36 @@ void Spell::EffectDispel(uint32 i)
if(positive == unitTarget->IsFriendlyTo(m_caster)) if(positive == unitTarget->IsFriendlyTo(m_caster))
continue; continue;
} }
// Add every aura stack to dispel list entry.casterGuid = itr->second->GetCasterGUID();
for(uint32 stack_amount = 0; stack_amount < aur->GetStackAmount(); ++stack_amount) entry.spellId = itr->second->GetId();
dispel_list.push_back(aur); entry.caster = itr->second->GetCaster();
entry.stackAmount = itr->second->GetStackAmount();
dispel_list.insert (entry);
} }
} }
// Ok if exist some buffs for dispel try dispel it // Ok if exist some buffs for dispel try dispel it
if (!dispel_list.empty()) if (uint32 list_size = dispel_list.size())
{ {
std::list < std::pair<uint32,uint64> > success_list;// (spell_id,casterGuid) std::list < std::pair<uint32,uint64> > success_list;// (spell_id,casterGuid)
std::list < uint32 > fail_list; // spell_id std::list < uint32 > fail_list; // spell_id
int32 list_size = dispel_list.size();
// dispel N = damage buffs (or while exist buffs for dispel) // dispel N = damage buffs (or while exist buffs for dispel)
for (int32 count=0; count < damage && list_size > 0; ++count) for (int32 count=0; count < damage && list_size > 0; ++count)
{ {
// Random select buff for dispel // Random select buff for dispel
Aura *aur = dispel_list[urand(0, list_size-1)]; DispelSet::iterator itr=dispel_list.begin();
for (uint32 i=urand(0, list_size-1);i!=0;--i)
itr++;
SpellEntry const* spellInfo = aur->GetSpellProto(); if (GetDispelChance(this, itr->caster, itr->spellId))
// Base dispel chance
// TODO: possible chance depend from spell level??
if (aur->GetDispelChance(this))
success_list.push_back(std::pair<uint32,uint64>(aur->GetId(),aur->GetCasterGUID()));
else
fail_list.push_back(aur->GetId());
// Remove buff from list for prevent doubles
for (std::vector<Aura *>::iterator j = dispel_list.begin(); j != dispel_list.end(); )
{ {
Aura *dispelled = *j; entry.stackAmount-=1;
if (dispelled->GetId() == aur->GetId() && dispelled->GetCasterGUID() == aur->GetCasterGUID()) if (!itr->stackAmount)
{ dispel_list.erase(itr);
j = dispel_list.erase(j); success_list.push_back(std::pair<uint32,uint64>(itr->spellId,itr->casterGuid));
--list_size;
break;
}
else
++j;
} }
else
fail_list.push_back(itr->spellId);
} }
// Send success log and really remove auras // Send success log and really remove auras
if (!success_list.empty()) if (!success_list.empty())
@@ -6024,21 +6018,26 @@ void Spell::EffectDispelMechanic(uint32 i)
uint32 mechanic = m_spellInfo->EffectMiscValue[i]; uint32 mechanic = m_spellInfo->EffectMiscValue[i];
std::deque <Aura *> dispel_list; DispelSet dispel_list;
DispelEntry entry;
Unit::AuraMap& Auras = unitTarget->GetAuras(); Unit::AuraMap& Auras = unitTarget->GetAuras();
for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter++) for(Unit::AuraMap::iterator iter = Auras.begin(); iter != Auras.end(); iter++)
{ {
if (!iter->second->GetDispelChance(this))
continue;
SpellEntry const *spell = iter->second->GetSpellProto(); SpellEntry const *spell = iter->second->GetSpellProto();
if(spell->Mechanic == mechanic || spell->EffectMechanic[iter->second->GetEffIndex()] == mechanic) if(GetSpellMechanicMask(spell, iter->second->GetEffIndex()) & (1<<(mechanic-1)))
dispel_list.push_back(iter->second); {
entry.casterGuid = iter->second->GetCasterGUID();
entry.spellId = iter->second->GetId();
entry.caster = iter->second->GetCaster();
dispel_list.insert (entry);
}
} }
for(;!dispel_list.empty();) for(DispelSet::iterator itr = dispel_list.begin(); itr != dispel_list.end();++itr)
{ {
unitTarget->RemoveAurasDueToSpell(dispel_list.front()->GetId()); entry = *itr;
dispel_list.pop_front(); if (GetDispelChance(this, entry.caster, entry.spellId))
unitTarget->RemoveAurasByCasterSpell(entry.spellId, entry.casterGuid);
} }
} }
+15
View File
@@ -236,6 +236,21 @@ int32 GetSpellMaxDuration(SpellEntry const *spellInfo)
return (du->Duration[2] == -1) ? -1 : abs(du->Duration[2]); return (du->Duration[2] == -1) ? -1 : abs(du->Duration[2]);
} }
bool GetDispelChance(Spell* spell, Unit* caster, uint32 spellId)
{
// we assume that aura dispel chance is 100% on start
// need formula for level difference based chance
int32 miss_chance = 100;
// Apply dispel mod from aura caster
if (caster)
{
if ( Player* modOwner = caster->GetSpellModOwner() )
modOwner->ApplySpellMod(spellId, SPELLMOD_RESIST_DISPEL_CHANCE, miss_chance, spell);
}
// Try dispel
return roll_chance_i(miss_chance);
}
uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell) uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell)
{ {
SpellCastTimesEntry const *spellCastTimeEntry = sSpellCastTimesStore.LookupEntry(spellInfo->CastingTimeIndex); SpellCastTimesEntry const *spellCastTimeEntry = sSpellCastTimesStore.LookupEntry(spellInfo->CastingTimeIndex);
+16
View File
@@ -152,6 +152,7 @@ SpellSpecific GetSpellSpecific(uint32 spellId);
inline float GetSpellRadiusForHostile(SpellRadiusEntry const *radius) { return (radius ? radius->radiusHostile : 0); } inline float GetSpellRadiusForHostile(SpellRadiusEntry const *radius) { return (radius ? radius->radiusHostile : 0); }
inline float GetSpellRadiusForFriend(SpellRadiusEntry const *radius) { return (radius ? radius->radiusFriend : 0); } inline float GetSpellRadiusForFriend(SpellRadiusEntry const *radius) { return (radius ? radius->radiusFriend : 0); }
uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL); uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL);
bool GetDispelChance(Spell* spell, Unit* caster, uint32 spellId);
inline float GetSpellMinRangeForHostile(SpellRangeEntry const *range) { return (range ? range->minRangeHostile : 0); } inline float GetSpellMinRangeForHostile(SpellRangeEntry const *range) { return (range ? range->minRangeHostile : 0); }
inline float GetSpellMaxRangeForHostile(SpellRangeEntry const *range) { return (range ? range->maxRangeHostile : 0); } inline float GetSpellMaxRangeForHostile(SpellRangeEntry const *range) { return (range ? range->maxRangeHostile : 0); }
inline float GetSpellMinRangeForFriend(SpellRangeEntry const *range) { return (range ? range->minRangeFriend : 0); } inline float GetSpellMinRangeForFriend(SpellRangeEntry const *range) { return (range ? range->minRangeFriend : 0); }
@@ -161,6 +162,21 @@ inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellIn
int32 GetSpellDuration(SpellEntry const *spellInfo); int32 GetSpellDuration(SpellEntry const *spellInfo);
int32 GetSpellMaxDuration(SpellEntry const *spellInfo); int32 GetSpellMaxDuration(SpellEntry const *spellInfo);
struct DispelEntry
{
uint64 casterGuid;
uint32 spellId;
Unit * caster;
uint8 stackAmount;
bool operator < (const DispelEntry & _Right) const
{
return (spellId != _Right.spellId ? spellId < _Right.spellId : casterGuid < _Right.casterGuid);
}
};
typedef std::set < DispelEntry > DispelSet;
inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect) inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
{ {
for(int i= 0; i < 3; ++i) for(int i= 0; i < 3; ++i)
+11 -27
View File
@@ -505,37 +505,22 @@ void Unit::RemoveAuraTypeByCaster(AuraType auraType, uint64 casterGUID)
void Unit::RemoveSpellsCausingAuraWithDispel(AuraType auraType, Spell * spell) void Unit::RemoveSpellsCausingAuraWithDispel(AuraType auraType, Spell * spell)
{ {
if (auraType >= TOTAL_AURAS) return; if (auraType >= TOTAL_AURAS) return;
DispelEntry entry;
DispelSet dispel_list;
AuraList::iterator iter, next; AuraList::iterator iter, next;
for (iter = m_modAuras[auraType].begin(); iter != m_modAuras[auraType].end(); iter = next) for (iter = m_modAuras[auraType].begin(); iter != m_modAuras[auraType].end(); iter = next)
{ {
next = iter; entry.casterGuid = (*iter)->GetCasterGUID();
++next; entry.spellId = (*iter)->GetId();
entry.caster = (*iter)->GetCaster();
if (*iter) dispel_list.insert (entry);
{
if (!(*iter)->GetDispelChance( spell))
continue;
RemoveAurasDueToSpell((*iter)->GetId());
if (!m_modAuras[auraType].empty())
next = m_modAuras[auraType].begin();
else
return;
}
}
std::deque <Aura *> dispel_list;
AuraList const& dispelAuras = GetAurasByType(auraType);
for(AuraList::const_iterator itr = dispelAuras.begin(); itr != dispelAuras.end(); ++itr)
{
if (!(*iter)->GetDispelChance( spell))
continue;
dispel_list.push_back(*iter);
} }
for(;!dispel_list.empty();)
for(DispelSet::iterator itr = dispel_list.begin(); itr != dispel_list.end();++itr)
{ {
RemoveAurasDueToSpell(dispel_list.front()->GetId()); entry = *itr;
dispel_list.pop_front(); if (GetDispelChance(spell, entry.caster, entry.spellId))
RemoveAurasByCasterSpell(entry.spellId, entry.casterGuid);
} }
} }
@@ -4341,7 +4326,6 @@ void Unit::RemoveNotOwnSingleTargetAuras()
else else
++iter; ++iter;
} }
} }
void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode)