Guest User

Untitled

a guest
Jan 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.62 KB | None | 0 0
  1. diff --git a/src/game/DynamicObject.cpp b/src/game/DynamicObject.cpp
  2. index c84b2a3..f4a135b 100644
  3. --- a/src/game/DynamicObject.cpp
  4. +++ b/src/game/DynamicObject.cpp
  5. @@ -170,7 +170,7 @@ void DynamicObject::Delay(int32 delaytime)
  6. bool foundAura = false;
  7. for (int32 i = m_effIndex + 1; i < MAX_EFFECT_INDEX; ++i)
  8. {
  9. - if ((holder->GetSpellProto()->Effect[i] == SPELL_EFFECT_PERSISTENT_AREA_AURA || holder->GetSpellProto()->Effect[i] == SPELL_EFFECT_ADD_FARSIGHT) && holder->m_auras[i])
  10. + if ((holder->GetSpellProto()->Effect[i] == SPELL_EFFECT_PERSISTENT_AREA_AURA || holder->GetSpellProto()->Effect[i] == SPELL_EFFECT_ADD_FARSIGHT) && holder->GetAuraByEffectIndex(SpellEffectIndex(i)))
  11. {
  12. foundAura = true;
  13. break;
  14. diff --git a/src/game/GridNotifiersImpl.h b/src/game/GridNotifiersImpl.h
  15. index f8e8e8f..cd79f20 100644
  16. --- a/src/game/GridNotifiersImpl.h
  17. +++ b/src/game/GridNotifiersImpl.h
  18. @@ -166,8 +166,7 @@ inline void MaNGOS::DynamicObjectUpdater::VisitHelper(Unit* target)
  19. {
  20. if (!holder->GetAuraByEffectIndex(eff_index))
  21. {
  22. - PersistentAreaAura* Aur = new PersistentAreaAura(spellInfo, eff_index, NULL, holder, target, i_dynobject.GetCaster());
  23. - holder->AddAura(Aur, eff_index);
  24. + PersistentAreaAura* Aur = holder->CreatePersistentAreaAura(spellInfo, eff_index, NULL, target, i_dynobject.GetCaster());
  25. target->AddAuraToModList(Aur);
  26. holder->SetInUse(true);
  27. Aur->ApplyModifier(true,true);
  28. @@ -182,8 +181,7 @@ inline void MaNGOS::DynamicObjectUpdater::VisitHelper(Unit* target)
  29. else
  30. {
  31. holder = CreateSpellAuraHolder(spellInfo, target, i_dynobject.GetCaster());
  32. - PersistentAreaAura* Aur = new PersistentAreaAura(spellInfo, eff_index, NULL, holder, target, i_dynobject.GetCaster());
  33. - holder->AddAura(Aur, eff_index);
  34. + holder->CreatePersistentAreaAura(spellInfo, eff_index, NULL, target, i_dynobject.GetCaster());
  35. target->AddSpellAuraHolder(holder);
  36. }
  37.  
  38. diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp
  39. index 3e83a72..27e708e 100644
  40. --- a/src/game/Level3.cpp
  41. +++ b/src/game/Level3.cpp
  42. @@ -4018,8 +4018,7 @@ bool ChatHandler::HandleAuraCommand(char* args)
  43. eff == SPELL_EFFECT_APPLY_AURA ||
  44. eff == SPELL_EFFECT_PERSISTENT_AREA_AURA)
  45. {
  46. - Aura *aur = CreateAura(spellInfo, SpellEffectIndex(i), NULL, holder, target);
  47. - holder->AddAura(aur, SpellEffectIndex(i));
  48. + holder->CreateAura(spellInfo, SpellEffectIndex(i), NULL, target, NULL, NULL);
  49. }
  50. }
  51. target->AddSpellAuraHolder(holder);
  52. diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp
  53. index 13c2542..18acaee 100644
  54. --- a/src/game/Pet.cpp
  55. +++ b/src/game/Pet.cpp
  56. @@ -406,7 +406,13 @@ void Pet::SavePetToDB(PetSaveMode mode)
  57. CharacterDatabase.BeginTransaction();
  58. _SaveSpells();
  59. _SaveSpellCooldowns();
  60. - _SaveAuras();
  61. + if (GetMap())
  62. + {
  63. + MAPLOCK_READ(this,MAP_LOCK_TYPE_AURAS)
  64. + _SaveAuras();
  65. + }
  66. + else
  67. + _SaveAuras();
  68.  
  69. uint32 ownerLow = GetOwnerGuid().GetCounter();
  70. // remove current data
  71. @@ -1394,12 +1400,11 @@ void Pet::_LoadAuras(uint32 timediff)
  72. if ((effIndexMask & (1 << i)) == 0)
  73. continue;
  74.  
  75. - Aura* aura = CreateAura(spellproto, SpellEffectIndex(i), NULL, holder, this);
  76. + Aura* aura = holder->CreateAura(spellproto, SpellEffectIndex(i), NULL, (Unit*)this, NULL, NULL);
  77. if (!damage[i])
  78. damage[i] = aura->GetModifier()->m_amount;
  79.  
  80. aura->SetLoadedState(damage[i], periodicTime[i]);
  81. - holder->AddAura(aura, SpellEffectIndex(i));
  82. }
  83.  
  84. if (!holder->IsEmptyHolder())
  85. @@ -1415,6 +1420,8 @@ void Pet::_LoadAuras(uint32 timediff)
  86.  
  87. void Pet::_SaveAuras()
  88. {
  89. + MAPLOCK_READ(this,MAP_LOCK_TYPE_AURAS);
  90. +
  91. static SqlStatementID delAuras ;
  92. static SqlStatementID insAuras ;
  93.  
  94. @@ -1430,14 +1437,20 @@ void Pet::_SaveAuras()
  95. "basepoints0, basepoints1, basepoints2, periodictime0, periodictime1, periodictime2, maxduration, remaintime, effIndexMask) "
  96. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  97.  
  98. - for(SpellAuraHolderMap::const_iterator itr = auraHolders.begin(); itr != auraHolders.end(); ++itr)
  99. + for (SpellAuraHolderMap::const_iterator itr = auraHolders.begin(); itr != auraHolders.end(); ++itr)
  100. {
  101. SpellAuraHolder *holder = itr->second;
  102.  
  103. + if (!holder || holder->IsDeleted())
  104. + continue;
  105. +
  106. + SpellEntry const* spellInfo = holder->GetSpellProto();
  107. + if (!spellInfo)
  108. + continue;
  109. +
  110. bool save = true;
  111. for (int32 j = 0; j < MAX_EFFECT_INDEX; ++j)
  112. {
  113. - SpellEntry const* spellInfo = holder->GetSpellProto();
  114. if (spellInfo->EffectApplyAuraName[j] == SPELL_AURA_MOD_STEALTH ||
  115. spellInfo->Effect[j] == SPELL_EFFECT_APPLY_AREA_AURA_OWNER ||
  116. spellInfo->Effect[j] == SPELL_EFFECT_APPLY_AREA_AURA_PET )
  117. @@ -3073,8 +3086,7 @@ bool Pet::ReapplyScalingAura(SpellAuraHolder* holder, SpellEntry const *spellpro
  118. RemoveAura(oldaura, AURA_REMOVE_BY_STACK);
  119. }
  120.  
  121. - Aura* aura = CreateAura(spellproto, index, &basePoints, holder, this, this, NULL);
  122. - holder->AddAura(aura, index);
  123. + Aura* aura = holder->CreateAura(spellproto, index, &basePoints, this, this, NULL);
  124. holder->SetAuraDuration(aura->GetAuraMaxDuration());
  125. AddAuraToModList(aura);
  126. aura->ApplyModifier(true,true);
  127. diff --git a/src/game/Player.cpp b/src/game/Player.cpp
  128. index 086d2ca..6f59567 100644
  129. --- a/src/game/Player.cpp
  130. +++ b/src/game/Player.cpp
  131. @@ -16791,12 +16791,12 @@ void Player::_LoadAuras(QueryResult *result, uint32 timediff)
  132. if ((effIndexMask & (1 << i)) == 0)
  133. continue;
  134.  
  135. - Aura* aura = CreateAura(spellproto, SpellEffectIndex(i), NULL, holder, this);
  136. + Aura* aura = holder->CreateAura(spellproto, SpellEffectIndex(i), NULL, this, NULL, NULL);
  137. +
  138. if (!damage[i])
  139. damage[i] = aura->GetModifier()->m_amount;
  140.  
  141. aura->SetLoadedState(damage[i], periodicTime[i]);
  142. - holder->AddAura(aura, SpellEffectIndex(i));
  143. }
  144.  
  145. if (!holder->IsEmptyHolder())
  146. @@ -18160,7 +18160,14 @@ void Player::SaveToDB()
  147. _SaveSpells();
  148. _SaveSpellCooldowns();
  149. _SaveActions();
  150. - _SaveAuras();
  151. + if (GetMap())
  152. + {
  153. + MAPLOCK_READ(this,MAP_LOCK_TYPE_AURAS)
  154. + _SaveAuras();
  155. + }
  156. + else
  157. + _SaveAuras();
  158. +
  159. _SaveSkills();
  160. m_achievementMgr.SaveToDB();
  161. m_reputationMgr.SaveToDB();
  162. @@ -19489,6 +19496,10 @@ void Player::RemovePetActionBar()
  163.  
  164. void Player::AddSpellMod(Aura* aura, bool apply)
  165. {
  166. + // For deleted auras enable only unapply mods!
  167. + if (!aura || (aura->IsDeleted() && apply))
  168. + return;
  169. +
  170. Modifier const* mod = aura->GetModifier();
  171. uint16 Opcode= (mod->m_auraname == SPELL_AURA_ADD_FLAT_MODIFIER) ? SMSG_SET_FLAT_SPELL_MODIFIER : SMSG_SET_PCT_SPELL_MODIFIER;
  172.  
  173. diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp
  174. index b161c40..f1eb19b 100644
  175. --- a/src/game/SpellAuras.cpp
  176. +++ b/src/game/SpellAuras.cpp
  177. @@ -372,10 +372,10 @@ pAuraHandler AuraHandler[TOTAL_AURAS]=
  178.  
  179. static AuraType const frozenAuraTypes[] = { SPELL_AURA_MOD_ROOT, SPELL_AURA_MOD_STUN, SPELL_AURA_NONE };
  180.  
  181. -Aura::Aura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster, Item* castItem) :
  182. +Aura::Aura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder* holder, Unit *target, Unit *caster, Item* castItem) :
  183. m_periodicTimer(0), m_periodicTick(0), m_removeMode(AURA_REMOVE_BY_DEFAULT),
  184. m_effIndex(eff), m_positive(false), m_isPeriodic(false), m_isAreaAura(false),
  185. -m_isPersistent(false), m_in_use(0), m_spellAuraHolder(holder)
  186. +m_isPersistent(false), m_in_use(0), m_spellAuraHolder(holder), m_deleted(false)
  187. {
  188. MANGOS_ASSERT(target);
  189. MANGOS_ASSERT(spellproto && spellproto == sSpellStore.LookupEntry( spellproto->Id ) && "`info` must be pointer to sSpellStore element");
  190. @@ -447,7 +447,7 @@ Aura::~Aura()
  191. {
  192. }
  193.  
  194. -AreaAura::AreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target,
  195. +AreaAura::AreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder* holder, Unit *target,
  196. Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, holder, target, caster, castItem)
  197. {
  198. m_isAreaAura = true;
  199. @@ -501,7 +501,7 @@ AreaAura::~AreaAura()
  200. {
  201. }
  202.  
  203. -PersistentAreaAura::PersistentAreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target,
  204. +PersistentAreaAura::PersistentAreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder* holder, Unit *target,
  205. Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, holder, target, caster, castItem)
  206. {
  207. m_isPersistent = true;
  208. @@ -511,7 +511,7 @@ PersistentAreaAura::~PersistentAreaAura()
  209. {
  210. }
  211.  
  212. -SingleEnemyTargetAura::SingleEnemyTargetAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target,
  213. +SingleEnemyTargetAura::SingleEnemyTargetAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder* holder, Unit *target,
  214. Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, holder, target, caster, castItem)
  215. {
  216. if (caster)
  217. @@ -534,19 +534,44 @@ Unit* SingleEnemyTargetAura::GetTriggerTarget() const
  218. return ObjectAccessor::GetUnit(*(m_spellAuraHolder->GetTarget()), m_castersTargetGuid);
  219. }
  220.  
  221. -Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster, Item* castItem)
  222. +Aura* SpellAuraHolder::CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32* currentBasePoints, Unit *target, Unit *caster, Item* castItem)
  223. {
  224. - if (IsAreaAuraEffect(spellproto->Effect[eff]))
  225. - return new AreaAura(spellproto, eff, currentBasePoints, holder, target, caster, castItem);
  226. -
  227. uint32 triggeredSpellId = spellproto->EffectTriggerSpell[eff];
  228. -
  229. - if (SpellEntry const* triggeredSpellInfo = sSpellStore.LookupEntry(triggeredSpellId))
  230. + if (IsAreaAuraEffect(spellproto->Effect[eff]))
  231. + {
  232. + AddAura((Aura)AreaAura(spellproto, eff, currentBasePoints, this, target, caster, castItem), eff);
  233. + return GetAuraByEffectIndex(eff);
  234. + }
  235. + else if (SpellEntry const* triggeredSpellInfo = sSpellStore.LookupEntry(triggeredSpellId))
  236. + {
  237. for (int i = 0; i < MAX_EFFECT_INDEX; ++i)
  238. + {
  239. if (triggeredSpellInfo->EffectImplicitTargetA[i] == TARGET_SINGLE_ENEMY)
  240. - return new SingleEnemyTargetAura(spellproto, eff, currentBasePoints, holder, target, caster, castItem);
  241. + {
  242. + AddAura((Aura)SingleEnemyTargetAura(spellproto, eff, currentBasePoints, this, target, caster, castItem),eff);
  243. + return GetAuraByEffectIndex(eff);
  244. + }
  245. + }
  246. + }
  247. + // else - normal aura
  248.  
  249. - return new Aura(spellproto, eff, currentBasePoints, holder, target, caster, castItem);
  250. + AddAura(Aura(spellproto, eff, currentBasePoints, this, target, caster, castItem),eff);
  251. +
  252. + return GetAuraByEffectIndex(eff);
  253. +}
  254. +
  255. +PersistentAreaAura* SpellAuraHolder::CreatePersistentAreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32* currentBasePoints, Unit* target, Unit* caster, Item* castItem)
  256. +{
  257. + AddAura((Aura)PersistentAreaAura(spellproto, eff, currentBasePoints, this, target, caster, castItem),eff);
  258. +
  259. + return ((PersistentAreaAura*)GetAuraByEffectIndex(eff));
  260. +}
  261. +
  262. +AreaAura* SpellAuraHolder::CreateAreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32* currentBasePoints, Unit* target, Unit* caster, Item* castItem)
  263. +{
  264. + AddAura((Aura)AreaAura(spellproto, eff, currentBasePoints, this, target, caster, castItem),eff);
  265. +
  266. + return ((AreaAura*)GetAuraByEffectIndex(eff));
  267. }
  268.  
  269. SpellAuraHolder* CreateSpellAuraHolder(SpellEntry const* spellproto, Unit *target, WorldObject *caster, Item *castItem)
  270. @@ -565,6 +590,9 @@ void Aura::SetModifier(AuraType t, int32 a, uint32 pt, int32 miscValue)
  271.  
  272. void Aura::Update(uint32 diff)
  273. {
  274. + if (IsDeleted())
  275. + return;
  276. +
  277. if (m_isPeriodic)
  278. {
  279. m_periodicTimer -= diff;
  280. @@ -779,8 +807,7 @@ void AreaAura::Update(uint32 diff)
  281.  
  282. holder->SetAuraDuration(GetAuraDuration());
  283.  
  284. - AreaAura *aur = new AreaAura(actualSpellInfo, m_effIndex, &actualBasePoints, holder, (*tIter), caster, NULL);
  285. - holder->AddAura(aur, m_effIndex);
  286. + AreaAura* aur = holder->CreateAreaAura(actualSpellInfo, m_effIndex, &actualBasePoints, (*tIter), caster, NULL);
  287.  
  288. if (addedToExisting)
  289. {
  290. @@ -890,6 +917,10 @@ void PersistentAreaAura::Update(uint32 diff)
  291.  
  292. void Aura::ApplyModifier(bool apply, bool Real)
  293. {
  294. + // For deleted auras accept only remove modifier!
  295. + if (IsDeleted() && apply)
  296. + return;
  297. +
  298. AuraType aura = m_modifier.m_auraname;
  299.  
  300. GetHolder()->SetInUse(true);
  301. @@ -1037,11 +1068,17 @@ void Aura::ReapplyAffectedPassiveAuras()
  302. GetTarget()->CallForAllControlledUnits(ReapplyAffectedPassiveAurasHelper(this), CONTROLLED_PET|CONTROLLED_TOTEMS);
  303.  
  304. // re-apply talents/passives/area auras applied to group members (it affected by player spellmods)
  305. - if (Group* group = ((Player*)GetTarget())->GetGroup())
  306. - for(GroupReference *itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
  307. - if (Player* member = itr->getSource())
  308. - if (member != GetTarget() && member->IsInMap(GetTarget()))
  309. - ReapplyAffectedPassiveAuras(member, false);
  310. + if (GetTarget() && GetTarget()->IsInWorld() && GetTarget()->GetTypeId() == TYPEID_PLAYER)
  311. + {
  312. + if (Group* group = ((Player*)GetTarget())->GetGroup())
  313. + {
  314. + // Group locking implement required
  315. + for(GroupReference *itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
  316. + if (Player* member = itr->getSource())
  317. + if (member != GetTarget() && member->IsInMap(GetTarget()))
  318. + ReapplyAffectedPassiveAuras(member, false);
  319. + }
  320. + }
  321. }
  322.  
  323. bool Aura::IsEffectStacking()
  324. @@ -1188,7 +1225,16 @@ void Aura::HandleAddModifier(bool apply, bool Real)
  325. entry->EffectSpellClassMask[GetEffIndex()] = ClassFamilyMask::create<CF_SHAMAN_FLAMETONGUE_WEAPON>();
  326. }
  327. }
  328. - ((Player*)GetTarget())->AddSpellMod(this, apply);
  329. + if (GetTarget()->IsInWorld() && GetTarget()->GetMap())
  330. + {
  331. + MAPLOCK_READ(GetTarget(),MAP_LOCK_TYPE_AURAS)
  332. + ((Player*)GetTarget())->AddSpellMod(this, apply);
  333. + }
  334. + else
  335. + {
  336. + DEBUG_LOG("Player::AddSpellMod player %u not in world!",GetTarget()->GetObjectGuid().GetCounter());
  337. + ((Player*)GetTarget())->AddSpellMod(this, apply);
  338. + }
  339.  
  340. ReapplyAffectedPassiveAuras();
  341. }
  342. @@ -9765,7 +9811,7 @@ void Aura::HandleAuraStopNaturalManaRegen(bool apply, bool Real)
  343. bool Aura::IsLastAuraOnHolder()
  344. {
  345. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  346. - if (i != GetEffIndex() && GetHolder()->m_auras[i])
  347. + if (i != GetEffIndex() && GetHolder()->GetAuraByEffectIndex(SpellEffectIndex(i)))
  348. return false;
  349. return true;
  350. }
  351. @@ -9784,6 +9830,7 @@ m_permanent(false), m_isRemovedOnShapeLost(true), m_deleted(false), m_in_use(0)
  352. {
  353. MANGOS_ASSERT(target);
  354. MANGOS_ASSERT(spellproto && spellproto == sSpellStore.LookupEntry( spellproto->Id ) && "`info` must be pointer to sSpellStore element");
  355. + m_aurasStorage.clear();
  356.  
  357. if (!caster)
  358. m_casterGuid = target->GetObjectGuid();
  359. @@ -9842,16 +9889,53 @@ m_permanent(false), m_isRemovedOnShapeLost(true), m_deleted(false), m_in_use(0)
  360. RemoveAura(SpellEffectIndex(i));
  361. }
  362.  
  363. -void SpellAuraHolder::AddAura(Aura *aura, SpellEffectIndex index)
  364. +void SpellAuraHolder::AddAura(Aura aura, SpellEffectIndex index)
  365. {
  366. - m_auras[index] = aura;
  367. + if (Aura* _aura = GetAuraByEffectIndex(index))
  368. + {
  369. + if (!_aura->IsDeleted())
  370. + {
  371. + DEBUG_LOG("SpellAuraHolder::AddAura attempt to add aura (effect %u) to holder of spell %u, but holder already have active aura!", index, GetId());
  372. + return;
  373. + }
  374. + else
  375. + RemoveAura(index);
  376. + }
  377. +
  378. + m_aurasStorage.insert(std::make_pair(index,aura));
  379. m_auraFlags |= (1 << index);
  380. }
  381.  
  382. void SpellAuraHolder::RemoveAura(SpellEffectIndex index)
  383. {
  384. - m_auras[index] = (Aura*)NULL;
  385. - m_auraFlags &= ~(1 << index);
  386. +
  387. + if (m_auraFlags & (1 << index))
  388. + {
  389. + m_auraFlags &= ~(1 << index);
  390. +
  391. + if (m_aurasStorage.empty())
  392. + return;
  393. +
  394. + AuraStorage::iterator itr = m_aurasStorage.find(index);
  395. + if (itr != m_aurasStorage.end())
  396. + m_aurasStorage.erase(itr);
  397. + }
  398. + else
  399. + {
  400. + m_auraFlags &= ~(1 << index);
  401. + }
  402. +}
  403. +
  404. +Aura* SpellAuraHolder::GetAuraByEffectIndex(SpellEffectIndex index)
  405. +{
  406. + if (m_auraFlags & (1 << index))
  407. + {
  408. + AuraStorage::iterator itr = m_aurasStorage.find(index);
  409. + if (itr != m_aurasStorage.end())
  410. + return &itr->second;
  411. + }
  412. +
  413. + return (Aura*)NULL;
  414. }
  415.  
  416. void SpellAuraHolder::ApplyAuraModifiers(bool apply, bool real)
  417. @@ -9904,7 +9988,7 @@ void SpellAuraHolder::_AddSpellAuraHolder()
  418. uint8 flags = 0;
  419. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  420. {
  421. - if (m_auras[i])
  422. + if (GetAuraByEffectIndex(SpellEffectIndex(i)))
  423. flags |= (1 << i);
  424. }
  425. flags |= ((GetCasterGuid() == GetTarget()->GetObjectGuid()) ? AFLAG_NOT_CASTER : AFLAG_NONE) | ((GetSpellMaxDuration(m_spellProto) > 0 && !(m_spellProto->AttributesEx5 & SPELL_ATTR_EX5_NO_DURATION)) ? AFLAG_DURATION : AFLAG_NONE) | (IsPositive() ? AFLAG_POSITIVE : AFLAG_NEGATIVE);
  426. @@ -10177,7 +10261,7 @@ void SpellAuraHolder::SetStackAmount(uint32 stackAmount)
  427.  
  428. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  429. {
  430. - if (Aura *aur = m_auras[i])
  431. + if (Aura* aur = GetAuraByEffectIndex(SpellEffectIndex(i)))
  432. {
  433. int32 bp = aur->GetBasePoints();
  434. int32 amount = m_stackAmount * caster->CalculateSpellDamage(target, m_spellProto, SpellEffectIndex(i), &bp);
  435. @@ -10221,13 +10305,16 @@ void SpellAuraHolder::SetStackAmount(uint32 stackAmount)
  436.  
  437. Unit* SpellAuraHolder::GetCaster() const
  438. {
  439. + if (!m_target)
  440. + return NULL;
  441. +
  442. if (GetCasterGuid() == m_target->GetObjectGuid())
  443. return m_target;
  444.  
  445. return ObjectAccessor::GetUnit(*m_target, m_casterGuid);// player will search at any maps
  446. }
  447.  
  448. -bool SpellAuraHolder::IsWeaponBuffCoexistableWith(SpellAuraHolder const* ref) const
  449. +bool SpellAuraHolder::IsWeaponBuffCoexistableWith(SpellAuraHolder const* ref)
  450. {
  451. // only item casted spells
  452. if (!GetCastItemGuid())
  453. @@ -11298,10 +11385,6 @@ void SpellAuraHolder::HandleSpellSpecificBoostsForward(bool apply)
  454.  
  455. SpellAuraHolder::~SpellAuraHolder()
  456. {
  457. - // note: auras in delete list won't be affected since they clear themselves from holder when adding to deletedAuraslist
  458. - for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  459. - if (Aura *aur = m_auras[i])
  460. - delete aur;
  461. }
  462.  
  463. void SpellAuraHolder::Update(uint32 diff)
  464. @@ -11340,7 +11423,7 @@ void SpellAuraHolder::Update(uint32 diff)
  465. }
  466.  
  467. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  468. - if (Aura *aura = m_auras[i])
  469. + if (Aura *aura = GetAuraByEffectIndex(SpellEffectIndex(i)))
  470. aura->UpdateAura(diff);
  471.  
  472. // Channeled aura required check distance from caster
  473. @@ -11394,59 +11477,59 @@ void SpellAuraHolder::SetAuraMaxDuration(int32 duration)
  474. SetAuraFlags(GetAuraFlags() & ~AFLAG_DURATION);
  475. }
  476.  
  477. -bool SpellAuraHolder::HasMechanic(uint32 mechanic) const
  478. +bool SpellAuraHolder::HasMechanic(uint32 mechanic)
  479. {
  480. if (mechanic == m_spellProto->Mechanic)
  481. return true;
  482.  
  483. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  484. - if (m_auras[i] && m_spellProto->EffectMechanic[i] == mechanic)
  485. + if (GetAuraByEffectIndex(SpellEffectIndex(i)) && m_spellProto->EffectMechanic[i] == mechanic)
  486. return true;
  487. return false;
  488. }
  489.  
  490. -bool SpellAuraHolder::HasMechanicMask(uint32 mechanicMask) const
  491. +bool SpellAuraHolder::HasMechanicMask(uint32 mechanicMask)
  492. {
  493. if (mechanicMask & (1 << (m_spellProto->Mechanic - 1)))
  494. return true;
  495.  
  496. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  497. - if (m_auras[i] && m_spellProto->EffectMechanic[i] && ((1 << (m_spellProto->EffectMechanic[i] -1)) & mechanicMask))
  498. + if (GetAuraByEffectIndex(SpellEffectIndex(i)) && m_spellProto->EffectMechanic[i] && ((1 << (m_spellProto->EffectMechanic[i] -1)) & mechanicMask))
  499. return true;
  500. return false;
  501. }
  502.  
  503. -bool SpellAuraHolder::IsPersistent() const
  504. +bool SpellAuraHolder::IsPersistent()
  505. {
  506. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  507. - if (Aura *aur = m_auras[i])
  508. + if (Aura *aur = GetAuraByEffectIndex(SpellEffectIndex(i)))
  509. if (aur->IsPersistent())
  510. return true;
  511. return false;
  512. }
  513.  
  514. -bool SpellAuraHolder::IsAreaAura() const
  515. +bool SpellAuraHolder::IsAreaAura()
  516. {
  517. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  518. - if (Aura *aur = m_auras[i])
  519. + if (Aura *aur = GetAuraByEffectIndex(SpellEffectIndex(i)))
  520. if (aur->IsAreaAura())
  521. return true;
  522. return false;
  523. }
  524.  
  525. -bool SpellAuraHolder::IsPositive() const
  526. +bool SpellAuraHolder::IsPositive()
  527. {
  528. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  529. - if (Aura *aur = m_auras[i])
  530. + if (Aura *aur = GetAuraByEffectIndex(SpellEffectIndex(i)))
  531. if (!aur->IsPositive())
  532. return false;
  533. return true;
  534. }
  535.  
  536. -bool SpellAuraHolder::IsEmptyHolder() const
  537. +bool SpellAuraHolder::IsEmptyHolder()
  538. {
  539. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  540. - if (m_auras[i])
  541. + if (GetAuraByEffectIndex(SpellEffectIndex(i)))
  542. return false;
  543. return true;
  544. }
  545. diff --git a/src/game/SpellAuras.h b/src/game/SpellAuras.h
  546. index 7518fa8..5f21d07 100644
  547. --- a/src/game/SpellAuras.h
  548. +++ b/src/game/SpellAuras.h
  549. @@ -37,6 +37,10 @@ struct ProcTriggerSpell;
  550.  
  551. // forward decl
  552. class Aura;
  553. +class AreaAura;
  554. +class PersistentAreaAura;
  555. +
  556. +typedef std::map<SpellEffectIndex,Aura> AuraStorage;
  557.  
  558. // internal helper
  559. struct ReapplyAffectedPassiveAurasHelper;
  560. @@ -45,9 +49,11 @@ class MANGOS_DLL_SPEC SpellAuraHolder
  561. {
  562. public:
  563. SpellAuraHolder (SpellEntry const* spellproto, Unit *target, WorldObject *caster, Item *castItem);
  564. - Aura* m_auras[MAX_EFFECT_INDEX];
  565.  
  566. - void AddAura(Aura *aura, SpellEffectIndex index);
  567. + Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32* currentBasePoints, Unit *target, Unit *caster, Item* castItem);
  568. + PersistentAreaAura* CreatePersistentAreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  569. + AreaAura* CreateAreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  570. +
  571. void RemoveAura(SpellEffectIndex index);
  572. void ApplyAuraModifiers(bool apply, bool real = false);
  573. void _AddSpellAuraHolder();
  574. @@ -65,7 +71,7 @@ class MANGOS_DLL_SPEC SpellAuraHolder
  575. void SetStackAmount(uint32 stackAmount);
  576. bool ModStackAmount(int32 num); // return true if last charge dropped
  577.  
  578. - Aura* GetAuraByEffectIndex(SpellEffectIndex index) const { return m_auras[index]; }
  579. + Aura* GetAuraByEffectIndex(SpellEffectIndex index);
  580.  
  581. uint32 GetId() const { return m_spellProto->Id; }
  582. SpellEntry const* GetSpellProto() const { return m_spellProto; }
  583. @@ -81,15 +87,15 @@ class MANGOS_DLL_SPEC SpellAuraHolder
  584. void SetPermanent(bool permanent) { m_permanent = permanent; }
  585. bool IsPassive() const { return m_isPassive; }
  586. bool IsDeathPersistent() const { return m_isDeathPersist; }
  587. - bool IsPersistent() const;
  588. - bool IsPositive() const;
  589. - bool IsAreaAura() const; // if one from auras of holder applied as area aura
  590. - bool IsWeaponBuffCoexistableWith(SpellAuraHolder const* ref) const;
  591. + bool IsPersistent();
  592. + bool IsPositive();
  593. + bool IsAreaAura(); // if one from auras of holder applied as area aura
  594. + bool IsWeaponBuffCoexistableWith(SpellAuraHolder const* ref);
  595. bool IsNeedVisibleSlot(Unit const* caster) const;
  596. bool IsRemovedOnShapeLost() const { return m_isRemovedOnShapeLost; }
  597. bool IsInUse() const { return (m_in_use > 0);}
  598. bool IsDeleted() const { return m_deleted;}
  599. - bool IsEmptyHolder() const;
  600. + bool IsEmptyHolder();
  601.  
  602. void SetDeleted() { m_deleted = true; }
  603.  
  604. @@ -157,11 +163,13 @@ class MANGOS_DLL_SPEC SpellAuraHolder
  605. SetAuraDuration(duration);
  606. }
  607.  
  608. - bool HasMechanic(uint32 mechanic) const;
  609. - bool HasMechanicMask(uint32 mechanicMask) const;
  610. + bool HasMechanic(uint32 mechanic);
  611. + bool HasMechanicMask(uint32 mechanicMask);
  612.  
  613. ~SpellAuraHolder();
  614. +
  615. private:
  616. + void AddAura(Aura aura, SpellEffectIndex index);
  617. Unit* m_target;
  618. ObjectGuid m_casterGuid;
  619. ObjectGuid m_castItemGuid; // it is NOT safe to keep a pointer to the item because it may get deleted
  620. @@ -181,6 +189,8 @@ class MANGOS_DLL_SPEC SpellAuraHolder
  621. AuraRemoveMode m_removeMode:8; // Store info for know remove aura reason
  622. DiminishingGroup m_AuraDRGroup:8; // Diminishing
  623.  
  624. + AuraStorage m_aurasStorage; // Auras storage
  625. +
  626. bool m_permanent:1;
  627. bool m_isPassive:1;
  628. bool m_isDeathPersist:1;
  629. @@ -207,8 +217,8 @@ typedef void(Aura::*pAuraHandler)(bool Apply, bool Real);
  630.  
  631. class MANGOS_DLL_SPEC Aura
  632. {
  633. + friend class SpellAuraHolder;
  634. friend struct ReapplyAffectedPassiveAurasHelper;
  635. - MANGOS_DLL_SPEC friend Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster, Item* castItem);
  636.  
  637. public:
  638. //aura handlers
  639. @@ -458,15 +468,18 @@ class MANGOS_DLL_SPEC Aura
  640. bool isAffectedOnSpell(SpellEntry const *spell) const;
  641. bool CanProcFrom(SpellEntry const *spell, uint32 procFlag, uint32 EventProcEx, uint32 procEx, bool active, bool useClassMask) const;
  642.  
  643. - //SpellAuraHolder const* GetHolder() const { return m_spellHolder; }
  644. - SpellAuraHolder* GetHolder() { return m_spellAuraHolder; }
  645. + SpellAuraHolder* GetHolder() { return m_spellAuraHolder; }
  646. SpellAuraHolder* const GetHolder() const { return m_spellAuraHolder; }
  647.  
  648. bool IsLastAuraOnHolder();
  649.  
  650. bool HasMechanic(uint32 mechanic) const;
  651. +
  652. + bool IsDeleted() const { return m_deleted;}
  653. + void SetDeleted() { m_deleted = true; }
  654. +
  655. protected:
  656. - Aura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  657. + Aura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder* holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  658.  
  659. // must be called only from Aura::UpdateAura
  660. virtual void Update(uint32 diff);
  661. @@ -497,10 +510,11 @@ class MANGOS_DLL_SPEC Aura
  662. bool m_stacking:1; // Aura is not overwritten, but effects are not cumulative with similar effects
  663.  
  664. int32 m_in_use; // > 0 while in Aura::ApplyModifier call/Aura::Update/etc
  665. + bool m_deleted;
  666.  
  667. bool IsEffectStacking();
  668.  
  669. - SpellAuraHolder* const m_spellAuraHolder;
  670. + SpellAuraHolder* m_spellAuraHolder;
  671. private:
  672. void ReapplyAffectedPassiveAuras(Unit* target, bool owner_mode);
  673. };
  674. @@ -508,7 +522,7 @@ class MANGOS_DLL_SPEC Aura
  675. class MANGOS_DLL_SPEC AreaAura : public Aura
  676. {
  677. public:
  678. - AreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  679. + AreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder* holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  680. ~AreaAura();
  681. protected:
  682. void Update(uint32 diff);
  683. @@ -520,7 +534,7 @@ class MANGOS_DLL_SPEC AreaAura : public Aura
  684. class MANGOS_DLL_SPEC PersistentAreaAura : public Aura
  685. {
  686. public:
  687. - PersistentAreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  688. + PersistentAreaAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder* holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  689. ~PersistentAreaAura();
  690. protected:
  691. void Update(uint32 diff);
  692. @@ -528,17 +542,16 @@ class MANGOS_DLL_SPEC PersistentAreaAura : public Aura
  693.  
  694. class MANGOS_DLL_SPEC SingleEnemyTargetAura : public Aura
  695. {
  696. - MANGOS_DLL_SPEC friend Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster, Item* castItem);
  697. + friend class SpellAuraHolder;
  698.  
  699. public:
  700. ~SingleEnemyTargetAura();
  701. Unit* GetTriggerTarget() const;
  702.  
  703. protected:
  704. - SingleEnemyTargetAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  705. + SingleEnemyTargetAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder* holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  706. ObjectGuid m_castersTargetGuid;
  707. };
  708.  
  709. -MANGOS_DLL_SPEC Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
  710. MANGOS_DLL_SPEC SpellAuraHolder* CreateSpellAuraHolder(SpellEntry const* spellproto, Unit *target, WorldObject *caster, Item *castItem = NULL);
  711. #endif
  712. diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp
  713. index 2468eb9..994dcbd 100644
  714. --- a/src/game/SpellEffects.cpp
  715. +++ b/src/game/SpellEffects.cpp
  716. @@ -4485,7 +4485,7 @@ void Spell::EffectApplyAura(SpellEffectIndex eff_idx)
  717.  
  718. DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell: Aura is: %u", m_spellInfo->EffectApplyAuraName[eff_idx]);
  719.  
  720. - Aura* aur = CreateAura(m_spellInfo, eff_idx, &m_currentBasePoints[eff_idx], m_spellAuraHolder, unitTarget, caster, m_CastItem);
  721. + Aura* aur = m_spellAuraHolder->CreateAura(m_spellInfo, eff_idx, &m_currentBasePoints[eff_idx], unitTarget, caster, m_CastItem);
  722.  
  723. // Now Reduce spell duration using data received at spell hit
  724. int32 duration = aur->GetAuraMaxDuration();
  725. @@ -4510,8 +4510,6 @@ void Spell::EffectApplyAura(SpellEffectIndex eff_idx)
  726. m_spellAuraHolder->SetAuraMaxDuration(duration);
  727. m_spellAuraHolder->SetAuraDuration(duration);
  728. }
  729. -
  730. - m_spellAuraHolder->AddAura(aur, eff_idx);
  731. }
  732.  
  733. void Spell::EffectUnlearnSpecialization(SpellEffectIndex eff_idx)
  734. @@ -5341,8 +5339,7 @@ void Spell::EffectApplyAreaAura(SpellEffectIndex eff_idx)
  735. if (!unitTarget->isAlive())
  736. return;
  737.  
  738. - AreaAura* Aur = new AreaAura(m_spellInfo, eff_idx, &m_currentBasePoints[eff_idx], m_spellAuraHolder, unitTarget, m_caster, m_CastItem);
  739. - m_spellAuraHolder->AddAura(Aur, eff_idx);
  740. + m_spellAuraHolder->CreateAreaAura(m_spellInfo, eff_idx, &m_currentBasePoints[eff_idx], unitTarget, m_caster, m_CastItem);
  741. }
  742.  
  743. void Spell::EffectSummonType(SpellEffectIndex eff_idx)
  744. diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
  745. index 76ccc5b..e3907df 100644
  746. --- a/src/game/Unit.cpp
  747. +++ b/src/game/Unit.cpp
  748. @@ -3720,7 +3720,7 @@ void Unit::_UpdateSpells( uint32 time )
  749. {
  750. SpellAuraHolder *holder = iter->second;
  751.  
  752. - if (!(holder->IsPermanent() || holder->IsPassive()) && holder->GetAuraDuration() == 0)
  753. + if (!holder->IsDeleted() && !(holder->IsPermanent() || holder->IsPassive()) && holder->GetAuraDuration() == 0)
  754. {
  755. RemoveSpellAuraHolder(holder, AURA_REMOVE_BY_EXPIRE);
  756. iter = m_spellAuraHolders.begin();
  757. @@ -4726,7 +4726,7 @@ void Unit::RemoveAura(uint32 spellId, SpellEffectIndex effindex, Aura* except)
  758. SpellAuraHolderBounds spair = GetSpellAuraHolderBounds(spellId);
  759. for(SpellAuraHolderMap::iterator iter = spair.first; iter != spair.second; )
  760. {
  761. - Aura *aur = iter->second->m_auras[effindex];
  762. + Aura *aur = iter->second->GetAuraByEffectIndex(effindex);
  763. if (aur && aur != except)
  764. {
  765. RemoveSingleAuraFromSpellAuraHolder(iter->second, effindex);
  766. @@ -4776,7 +4776,7 @@ void Unit::RemoveSingleAuraFromSpellAuraHolder(uint32 spellId, SpellEffectIndex
  767. SpellAuraHolderBounds spair = GetSpellAuraHolderBounds(spellId);
  768. for(SpellAuraHolderMap::iterator iter = spair.first; iter != spair.second; )
  769. {
  770. - Aura *aur = iter->second->m_auras[effindex];
  771. + Aura* aur = iter->second->GetAuraByEffectIndex(effindex);
  772. if (aur && aur->GetCasterGuid() == casterGuid)
  773. {
  774. RemoveSingleAuraFromSpellAuraHolder(iter->second, effindex, mode);
  775. @@ -4905,14 +4905,11 @@ void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, ObjectGuid casterGuid, U
  776. int32 basePoints = aur->GetBasePoints();
  777. // construct the new aura for the attacker - will never return NULL, it's just a wrapper for
  778. // some different constructors
  779. - Aura * new_aur = CreateAura(spellProto, aur->GetEffIndex(), &basePoints, new_holder, stealer, this);
  780. + Aura* new_aur = new_holder->CreateAura(spellProto, aur->GetEffIndex(), &basePoints, stealer, this, NULL);
  781.  
  782. // set periodic to do at least one tick (for case when original aura has been at last tick preparing)
  783. int32 periodic = aur->GetModifier()->periodictime;
  784. new_aur->GetModifier()->periodictime = periodic < new_max_dur ? periodic : new_max_dur;
  785. -
  786. - // add the new aura to stealer
  787. - new_holder->AddAura(new_aur, new_aur->GetEffIndex());
  788. }
  789.  
  790. if (holder->GetSpellProto()->AttributesEx7 & SPELL_ATTR_EX7_DISPEL_CHARGES)
  791. @@ -5126,7 +5123,7 @@ void Unit::RemoveNotOwnSingleTargetAuras(uint32 newPhase)
  792.  
  793. void Unit::RemoveSpellAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode)
  794. {
  795. - if (!holder)
  796. + if (!holder || holder->IsDeleted())
  797. return;
  798.  
  799. if (mode != AURA_REMOVE_BY_DELETE)
  800. @@ -5135,10 +5132,10 @@ void Unit::RemoveSpellAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode)
  801. // Statue unsummoned at holder remove
  802. SpellEntry const* AurSpellInfo = holder->GetSpellProto();
  803. Totem* statue = NULL;
  804. - Unit* caster = holder->GetCaster();
  805. - if (IsChanneledSpell(AurSpellInfo) && caster)
  806. - if (caster->GetTypeId()==TYPEID_UNIT && ((Creature*)caster)->IsTotem() && ((Totem*)caster)->GetTotemType()==TOTEM_STATUE)
  807. - statue = ((Totem*)caster);
  808. + if (Unit* caster = holder->GetCaster())
  809. + if (IsChanneledSpell(AurSpellInfo))
  810. + if (caster->GetTypeId()==TYPEID_UNIT && ((Creature*)caster)->IsTotem() && ((Totem*)caster)->GetTotemType()==TOTEM_STATUE)
  811. + statue = ((Totem*)caster);
  812.  
  813. if (m_spellAuraHoldersUpdateIterator != m_spellAuraHolders.end() && m_spellAuraHoldersUpdateIterator->second == holder)
  814. ++m_spellAuraHoldersUpdateIterator;
  815. @@ -5158,7 +5155,7 @@ void Unit::RemoveSpellAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode)
  816.  
  817. for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
  818. {
  819. - if (Aura *aura = holder->m_auras[i])
  820. + if (Aura* aura = holder->GetAuraByEffectIndex(SpellEffectIndex(i)))
  821. RemoveAura(aura, mode);
  822. }
  823.  
  824. @@ -5178,11 +5175,12 @@ void Unit::RemoveSpellAuraHolder(SpellAuraHolder *holder, AuraRemoveMode mode)
  825. m_deletedHolders.push_back(holder);
  826. }
  827.  
  828. - if (mode != AURA_REMOVE_BY_EXPIRE && IsChanneledSpell(AurSpellInfo) && !IsAreaOfEffectSpell(AurSpellInfo) &&
  829. - caster && caster->GetObjectGuid() != GetObjectGuid())
  830. - {
  831. - caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
  832. - }
  833. + if (Unit* caster = holder->GetCaster())
  834. + if (mode != AURA_REMOVE_BY_EXPIRE && IsChanneledSpell(AurSpellInfo) && !IsAreaOfEffectSpell(AurSpellInfo) &&
  835. + caster->GetObjectGuid() != GetObjectGuid())
  836. + {
  837. + caster->InterruptSpell(CURRENT_CHANNELED_SPELL);
  838. + }
  839. }
  840.  
  841. void Unit::RemoveSingleAuraFromSpellAuraHolder(SpellAuraHolder *holder, SpellEffectIndex index, AuraRemoveMode mode)
  842. @@ -5199,6 +5197,9 @@ void Unit::RemoveSingleAuraFromSpellAuraHolder(SpellAuraHolder *holder, SpellEff
  843.  
  844. void Unit::RemoveAura(Aura *Aur, AuraRemoveMode mode)
  845. {
  846. + if (Aur->IsDeleted())
  847. + return;
  848. +
  849. // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
  850. if (Aur->GetModifier()->m_auraname < TOTAL_AURAS)
  851. {
  852. @@ -5212,12 +5213,12 @@ void Unit::RemoveAura(Aura *Aur, AuraRemoveMode mode)
  853. // remove aura from list before to prevent deleting it before
  854. ///m_Auras.erase(i);
  855.  
  856. - DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Aura %u now is remove mode %d",Aur->GetModifier()->m_auraname, mode);
  857. + DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Aura (spell %u) %u now is remove mode %d",Aur->GetId(),Aur->GetModifier()->m_auraname, mode);
  858.  
  859. // aura _MUST_ be remove from holder before unapply.
  860. // un-apply code expected that aura not find by diff searches
  861. // in another case it can be double removed for example, if target die/etc in un-apply process.
  862. - Aur->GetHolder()->RemoveAura(Aur->GetEffIndex());
  863. + Aur->SetDeleted();
  864.  
  865. // some auras also need to apply modifier (on caster) on remove
  866. if (mode == AURA_REMOVE_BY_DELETE)
  867. @@ -7113,10 +7114,10 @@ uint32 Unit::SpellDamageBonusDone(Unit *pVictim, SpellEntry const *spellProto, u
  868. else if (spellProto->SpellFamilyFlags.test<CF_PRIEST_SHADOW_WORD_DEATH_TARGET>())
  869. {
  870. // Glyph of Shadow word: Death
  871. - if (SpellAuraHolder const* glyph = GetSpellAuraHolder(55682))
  872. + if (SpellAuraHolder* const glyph = GetSpellAuraHolder(55682))
  873. {
  874. - Aura const* hpPct = glyph->GetAuraByEffectIndex(EFFECT_INDEX_0);
  875. - Aura const* dmPct = glyph->GetAuraByEffectIndex(EFFECT_INDEX_1);
  876. + Aura* hpPct = glyph->GetAuraByEffectIndex(EFFECT_INDEX_0);
  877. + Aura* dmPct = glyph->GetAuraByEffectIndex(EFFECT_INDEX_1);
  878. if (hpPct && dmPct && pVictim->GetHealth() * 100 <= pVictim->GetMaxHealth() * hpPct->GetModifier()->m_amount)
  879. DoneTotalMod *= (dmPct->GetModifier()->m_amount + 100.0f) / 100.0f;
  880. }
  881. @@ -12094,14 +12095,43 @@ bool Unit::IsIgnoreUnitState(SpellEntry const *spell, IgnoreUnitState ignoreStat
  882.  
  883. void Unit::CleanupDeletedAuras()
  884. {
  885. - for (SpellAuraHolderList::const_iterator iter = m_deletedHolders.begin(); iter != m_deletedHolders.end(); ++iter)
  886. - delete *iter;
  887. - m_deletedHolders.clear();
  888. -
  889. // really delete auras "deleted" while processing its ApplyModify code
  890. - for(AuraList::const_iterator itr = m_deletedAuras.begin(); itr != m_deletedAuras.end(); ++itr)
  891. - delete *itr;
  892. + if (IsInWorld()) // Not require true deleting aura in not-in-world unit. be removed in holders.
  893. + {
  894. + for(AuraList::const_iterator itr = m_deletedAuras.begin(); itr != m_deletedAuras.end(); ++itr)
  895. + {
  896. + Aura* aura = *itr;
  897. + if (!aura)
  898. + continue;
  899. +
  900. + SpellAuraHolder* holder = aura->GetHolder();
  901. +
  902. + if (!holder) // now this impossible. need ASSERT in this.
  903. + {
  904. + sLog.outError("Unit::CleanupDeletedAuras - attempt to delete aura withot holder!");
  905. + continue;
  906. + }
  907. +
  908. + if (holder->IsDeleted()) // not need cleanup deleted holders - be removed later.
  909. + continue;
  910. +
  911. + holder->RemoveAura(aura->GetEffIndex());
  912. + }
  913. + }
  914. m_deletedAuras.clear();
  915. +
  916. + // really delete holders, "deleted" while processing update code
  917. + for (SpellAuraHolderList::const_iterator iter = m_deletedHolders.begin(); iter != m_deletedHolders.end(); ++iter)
  918. + {
  919. + if (*iter && (*iter)->IsDeleted())
  920. + delete *iter;
  921. + else if (*iter)
  922. + {
  923. + DEBUG_LOG("Unit::CleanupDeletedAuras - attempt to delete not marked for delete holder, unit %u, spell %u",GetObjectGuid().GetCounter(),(*iter)->GetId());
  924. + delete *iter;
  925. + }
  926. + }
  927. + m_deletedHolders.clear();
  928. }
  929.  
  930. bool Unit::CheckAndIncreaseCastCounter()
  931. @@ -12154,8 +12184,7 @@ void Unit::_AddAura(uint32 spellID, uint32 duration)
  932. spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA ||
  933. spellInfo->Effect[i] == SPELL_EFFECT_PERSISTENT_AREA_AURA )
  934. {
  935. - Aura *aura = CreateAura(spellInfo, SpellEffectIndex(i), NULL, holder, this);
  936. - holder->AddAura(aura, SpellEffectIndex(i));
  937. + Aura *aura = holder->CreateAura(spellInfo, SpellEffectIndex(i), NULL, this, NULL, NULL);
  938. holder->SetAuraDuration(duration);
  939. DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Manually adding aura of spell %u, index %u, duration %u ms", spellID, i, duration);
  940. }
  941. diff --git a/src/game/UnitAuraProcHandler.cpp b/src/game/UnitAuraProcHandler.cpp
  942. index e2a9e02..99ee2b7 100644
  943. --- a/src/game/UnitAuraProcHandler.cpp
  944. +++ b/src/game/UnitAuraProcHandler.cpp
  945. @@ -4671,8 +4671,7 @@ SpellAuraProcResult Unit::HandleMendingAuraProc( Unit* /*pVictim*/, uint32 /*dam
  946. continue;
  947.  
  948. int32 basePoints = aur->GetBasePoints();
  949. - Aura * new_aur = CreateAura(spellProto, aur->GetEffIndex(), &basePoints, new_holder, target, caster);
  950. - new_holder->AddAura(new_aur, new_aur->GetEffIndex());
  951. + new_holder->CreateAura(spellProto, aur->GetEffIndex(), &basePoints, target, caster, NULL);
  952. }
  953. new_holder->SetAuraCharges(jumps, false);
Add Comment
Please, Sign In to add comment