2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "WorldPacket.h"
23 #include "WorldSession.h"
25 #include "ObjectMgr.h"
26 #include "ObjectDefines.h"
34 #include "SpellAuras.h"
35 #include "MapManager.h"
36 #include "ObjectAccessor.h"
37 #include "CreatureAI.h"
42 #include "BattleGround.h"
43 #include "InstanceSaveMgr.h"
44 #include "GridNotifiersImpl.h"
47 #include "Traveller.h"
48 #include "VMapFactory.h"
52 float baseMoveSpeed
[MAX_MOVE_TYPE
] =
56 1.25f
, // MOVE_RUN_BACK
57 4.722222f
, // MOVE_SWIM
58 4.5f
, // MOVE_SWIM_BACK
59 3.141594f
, // MOVE_TURN_RATE
61 4.5f
, // MOVE_FLIGHT_BACK
62 3.14f
// MOVE_PITCH_RATE
65 // Used for prepare can/can`t triggr aura
66 static bool InitTriggerAuraData();
67 // Define can trigger auras
68 static bool isTriggerAura
[TOTAL_AURAS
];
69 // Define can`t trigger auras (need for disable second trigger)
70 static bool isNonTriggerAura
[TOTAL_AURAS
];
72 static bool procPrepared
= InitTriggerAuraData();
75 : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostileRefManager(this)
77 m_objectType
|= TYPEMASK_UNIT
;
78 m_objectTypeId
= TYPEID_UNIT
;
80 m_updateFlag
= (UPDATEFLAG_HIGHGUID
| UPDATEFLAG_LIVING
| UPDATEFLAG_HAS_POSITION
);
82 m_attackTimer
[BASE_ATTACK
] = 0;
83 m_attackTimer
[OFF_ATTACK
] = 0;
84 m_attackTimer
[RANGED_ATTACK
] = 0;
85 m_modAttackSpeedPct
[BASE_ATTACK
] = 1.0f
;
86 m_modAttackSpeedPct
[OFF_ATTACK
] = 1.0f
;
87 m_modAttackSpeedPct
[RANGED_ATTACK
] = 1.0f
;
95 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
96 m_currentSpells
[i
] = NULL
;
100 for(int i
= 0; i
< MAX_TOTEM
; ++i
)
103 m_ObjectSlot
[0] = m_ObjectSlot
[1] = m_ObjectSlot
[2] = m_ObjectSlot
[3] = 0;
105 //m_AurasCheck = 2000;
106 //m_removeAuraTimer = 4;
107 m_AurasUpdateIterator
= m_Auras
.end();
110 m_Visibility
= VISIBILITY_ON
;
112 m_detectInvisibilityMask
= 0;
113 m_invisibilityMask
= 0;
115 m_ShapeShiftFormSpellId
= 0;
116 m_canModifyStats
= false;
118 for (int i
= 0; i
< MAX_SPELL_IMMUNITY
; ++i
)
119 m_spellImmune
[i
].clear();
120 for (int i
= 0; i
< UNIT_MOD_END
; ++i
)
122 m_auraModifiersGroup
[i
][BASE_VALUE
] = 0.0f
;
123 m_auraModifiersGroup
[i
][BASE_PCT
] = 1.0f
;
124 m_auraModifiersGroup
[i
][TOTAL_VALUE
] = 0.0f
;
125 m_auraModifiersGroup
[i
][TOTAL_PCT
] = 1.0f
;
127 // implement 50% base damage from offhand
128 m_auraModifiersGroup
[UNIT_MOD_DAMAGE_OFFHAND
][TOTAL_PCT
] = 0.5f
;
130 for (int i
= 0; i
< MAX_ATTACK
; ++i
)
132 m_weaponDamage
[i
][MINDAMAGE
] = BASE_MINDAMAGE
;
133 m_weaponDamage
[i
][MAXDAMAGE
] = BASE_MAXDAMAGE
;
135 for (int i
= 0; i
< MAX_STATS
; ++i
)
136 m_createStats
[i
] = 0.0f
;
139 m_modMeleeHitChance
= 0.0f
;
140 m_modRangedHitChance
= 0.0f
;
141 m_modSpellHitChance
= 0.0f
;
142 m_baseSpellCritChance
= 5;
145 m_lastManaUseTimer
= 0;
147 //m_victimThreat = 0.0f;
148 for (int i
= 0; i
< MAX_SPELL_SCHOOL
; ++i
)
149 m_threatModifier
[i
] = 1.0f
;
151 for (int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
152 m_speed_rate
[i
] = 1.0f
;
156 // remove aurastates allowing special moves
157 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
158 m_reactiveTimer
[i
] = 0;
163 // set current spells as deletable
164 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
166 if (m_currentSpells
[i
])
168 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
169 m_currentSpells
[i
] = NULL
;
176 // those should be already removed at "RemoveFromWorld()" call
177 assert(m_gameObj
.size() == 0);
178 assert(m_dynObjGUIDs
.size() == 0);
179 assert(m_deletedAuras
.size() == 0);
182 void Unit::Update( uint32 p_time
)
187 /*if(p_time > m_AurasCheck)
192 m_AurasCheck -= p_time;*/
194 // WARNING! Order of execution here is important, do not change.
195 // Spells must be processed with event system BEFORE they go to _UpdateSpells.
196 // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
197 m_Events
.Update( p_time
);
198 _UpdateSpells( p_time
);
200 CleanupDeletedAuras();
202 if (m_lastManaUseTimer
)
204 if (p_time
>= m_lastManaUseTimer
)
205 m_lastManaUseTimer
= 0;
207 m_lastManaUseTimer
-= p_time
;
210 if (CanHaveThreatList())
211 getThreatManager().UpdateForClient(p_time
);
213 // update combat timer only for players and pets
214 if (isInCombat() && (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet() || ((Creature
*)this)->isCharmed()))
216 // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away
217 // targets without stopping half way there and running off.
218 // These flags are reset after target dies or another command is given.
219 if (m_HostileRefManager
.isEmpty())
221 // m_CombatTimer set at aura start and it will be freeze until aura removing
222 if (m_CombatTimer
<= p_time
)
225 m_CombatTimer
-= p_time
;
229 if (uint32 base_att
= getAttackTimer(BASE_ATTACK
))
231 setAttackTimer(BASE_ATTACK
, (p_time
>= base_att
? 0 : base_att
- p_time
) );
234 // update abilities available only for fraction of time
235 UpdateReactives( p_time
);
237 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, GetHealth() < GetMaxHealth()*0.20f
);
238 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, GetHealth() < GetMaxHealth()*0.35f
);
239 ModifyAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT
, GetHealth() > GetMaxHealth()*0.75f
);
241 i_motionMaster
.UpdateMotion(p_time
);
244 bool Unit::haveOffhandWeapon() const
246 if(GetTypeId() == TYPEID_PLAYER
)
247 return ((Player
*)this)->GetWeaponForAttack(OFF_ATTACK
,true,true);
252 void Unit::SendMonsterMove(float NewPosX
, float NewPosY
, float NewPosZ
, uint8 type
, MonsterMovementFlags flags
, uint32 Time
, Player
* player
)
254 float moveTime
= Time
;
256 WorldPacket
data( SMSG_MONSTER_MOVE
, (41 + GetPackGUID().size()) );
257 data
.append(GetPackGUID());
258 data
<< uint8(0); // new in 3.1
259 data
<< GetPositionX() << GetPositionY() << GetPositionZ();
260 data
<< uint32(getMSTime());
262 data
<< uint8(type
); // unknown
265 case 0: // normal packet
267 case 1: // stop packet (raw pos?)
268 SendMessageToSet( &data
, true );
270 case 2: // facing spot, not used currently
275 case 3: // not used currently
276 data
<< uint64(0); // probably target guid (facing target?)
278 case 4: // not used currently
279 data
<< float(0); // facing angle
283 data
<< uint32(flags
);
285 if(flags
& MONSTER_MOVE_WALK
)
288 data
<< uint32(moveTime
); // Time in between points
289 data
<< uint32(1); // 1 single waypoint
290 data
<< NewPosX
<< NewPosY
<< NewPosZ
; // the single waypoint Point B
293 player
->GetSession()->SendPacket(&data
);
295 SendMessageToSet( &data
, true );
298 void Unit::SendMonsterMoveByPath(Path
const& path
, uint32 start
, uint32 end
, MonsterMovementFlags flags
)
300 uint32 traveltime
= uint32(path
.GetTotalLength(start
, end
) * 32);
302 uint32 pathSize
= end
- start
;
304 WorldPacket
data( SMSG_MONSTER_MOVE
, (GetPackGUID().size()+1+4+4+4+4+1+4+4+4+pathSize
*4*3) );
305 data
.append(GetPackGUID());
307 data
<< GetPositionX();
308 data
<< GetPositionY();
309 data
<< GetPositionZ();
310 data
<< uint32(getMSTime());
312 data
<< uint32(flags
);
313 data
<< uint32(traveltime
);
314 data
<< uint32(pathSize
);
315 data
.append((char*)path
.GetNodes(start
), pathSize
* 4 * 3);
316 SendMessageToSet(&data
, true);
319 void Unit::BuildHeartBeatMsg(WorldPacket
*data
) const
321 MovementFlags move_flags
= GetTypeId()==TYPEID_PLAYER
322 ? ((Player
const*)this)->m_movementInfo
.GetMovementFlags()
325 data
->Initialize(MSG_MOVE_HEARTBEAT
, 32);
326 data
->append(GetPackGUID());
327 *data
<< uint32(move_flags
); // movement flags
328 *data
<< uint16(0); // 2.3.0
329 *data
<< uint32(getMSTime()); // time
330 *data
<< float(GetPositionX());
331 *data
<< float(GetPositionY());
332 *data
<< float(GetPositionZ());
333 *data
<< float(GetOrientation());
337 void Unit::resetAttackTimer(WeaponAttackType type
)
339 m_attackTimer
[type
] = uint32(GetAttackTime(type
) * m_modAttackSpeedPct
[type
]);
342 bool Unit::canReachWithAttack(Unit
*pVictim
) const
345 float reach
= GetFloatValue(UNIT_FIELD_COMBATREACH
);
348 return IsWithinDistInMap(pVictim
, reach
);
351 void Unit::RemoveSpellsCausingAura(AuraType auraType
)
353 if (auraType
>= TOTAL_AURAS
) return;
354 AuraList::const_iterator iter
, next
;
355 for (iter
= m_modAuras
[auraType
].begin(); iter
!= m_modAuras
[auraType
].end(); iter
= next
)
362 RemoveAurasDueToSpell((*iter
)->GetId());
363 if (!m_modAuras
[auraType
].empty())
364 next
= m_modAuras
[auraType
].begin();
371 bool Unit::HasAuraType(AuraType auraType
) const
373 return (!m_modAuras
[auraType
].empty());
376 /* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */
377 void Unit::RemoveSpellbyDamageTaken(AuraType auraType
, uint32 damage
)
379 if(!HasAuraType(auraType
))
382 // The chance to dispel an aura depends on the damage taken with respect to the casters level.
383 uint32 max_dmg
= getLevel() > 8 ? 25 * getLevel() - 150 : 50;
384 float chance
= float(damage
) / max_dmg
* 100.0f
;
385 if (roll_chance_f(chance
))
386 RemoveSpellsCausingAura(auraType
);
389 void Unit::DealDamageMods(Unit
*pVictim
, uint32
&damage
, uint32
* absorb
)
391 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
399 //You don't lose health from damage taken from another player while in a sanctuary
400 //You still see it in the combat log though
401 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
403 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
404 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) //sanctuary
412 uint32 originalDamage
= damage
;
414 //Script Event damage Deal
415 if( GetTypeId()== TYPEID_UNIT
&& ((Creature
*)this)->AI())
416 ((Creature
*)this)->AI()->DamageDeal(pVictim
, damage
);
417 //Script Event damage taken
418 if( pVictim
->GetTypeId()== TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI() )
419 ((Creature
*)pVictim
)->AI()->DamageTaken(this, damage
);
421 if(absorb
&& originalDamage
> damage
)
422 absorb
+= (originalDamage
- damage
);
425 uint32
Unit::DealDamage(Unit
*pVictim
, uint32 damage
, CleanDamage
const* cleanDamage
, DamageEffectType damagetype
, SpellSchoolMask damageSchoolMask
, SpellEntry
const *spellProto
, bool durabilityLoss
)
427 // remove affects from victim (including from 0 damage and DoTs)
429 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
431 // remove affects from attacker at any non-DoT damage (including 0 damage)
432 if( damagetype
!= DOT
)
434 RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
435 RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
438 RemoveSpellsCausingAura(SPELL_AURA_MOD_INVISIBILITY
);
440 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->IsStandState() && !pVictim
->hasUnitState(UNIT_STAT_STUNNED
))
441 pVictim
->SetStandState(UNIT_STAND_STATE_STAND
);
446 // Rage from physical damage received .
447 if(cleanDamage
&& cleanDamage
->damage
&& (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
) && pVictim
->GetTypeId() == TYPEID_PLAYER
&& (pVictim
->getPowerType() == POWER_RAGE
))
448 ((Player
*)pVictim
)->RewardRage(cleanDamage
->damage
, 0, false);
452 if (!spellProto
|| !IsSpellHaveAura(spellProto
,SPELL_AURA_MOD_FEAR
))
453 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_FEAR
, damage
);
454 // root type spells do not dispel the root effect
455 if (!spellProto
|| !(spellProto
->Mechanic
== MECHANIC_ROOT
|| IsSpellHaveAura(spellProto
,SPELL_AURA_MOD_ROOT
)))
456 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_ROOT
, damage
);
458 // no xp,health if type 8 /critters/
459 if(pVictim
->GetTypeId() != TYPEID_PLAYER
&& pVictim
->GetCreatureType() == CREATURE_TYPE_CRITTER
)
461 pVictim
->setDeathState(JUST_DIED
);
462 pVictim
->SetHealth(0);
464 // allow loot only if has loot_id in creature_template
465 CreatureInfo
const* cInfo
= ((Creature
*)pVictim
)->GetCreatureInfo();
466 if(cInfo
&& cInfo
->lootid
)
467 pVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
469 // some critters required for quests (need normal entry instead possible heroic in any cases)
470 if(GetTypeId() == TYPEID_PLAYER
)
471 if(CreatureInfo
const* normalInfo
= ObjectMgr::GetCreatureTemplate(pVictim
->GetEntry()))
472 ((Player
*)this)->KilledMonster(normalInfo
,pVictim
->GetGUID());
477 DEBUG_LOG("DealDamageStart");
479 uint32 health
= pVictim
->GetHealth();
480 sLog
.outDetail("deal dmg:%d to health:%d ",damage
,health
);
482 // duel ends when player has 1 or less hp
483 bool duel_hasEnded
= false;
484 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->duel
&& damage
>= (health
-1))
486 // prevent kill only if killed in duel and killed by opponent or opponent controlled creature
487 if(((Player
*)pVictim
)->duel
->opponent
==this || ((Player
*)pVictim
)->duel
->opponent
->GetGUID() == GetOwnerGUID())
490 duel_hasEnded
= true;
493 if(pVictim
!= this && damagetype
!= DOT
)
495 SetInCombatWith(pVictim
);
496 pVictim
->SetInCombatWith(this);
498 if(Player
* attackedPlayer
= pVictim
->GetCharmerOrOwnerPlayerOrPlayerItself())
499 SetContestedPvP(attackedPlayer
);
502 // Rage from Damage made (only from direct weapon damage)
503 if( cleanDamage
&& damagetype
==DIRECT_DAMAGE
&& this != pVictim
&& GetTypeId() == TYPEID_PLAYER
&& (getPowerType() == POWER_RAGE
))
505 uint32 weaponSpeedHitFactor
;
507 switch(cleanDamage
->attackType
)
511 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
512 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 7);
514 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
516 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
522 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
523 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
525 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 1.75f
);
527 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
536 if (GetTypeId() == TYPEID_PLAYER
&& this != pVictim
)
538 Player
*killer
= ((Player
*)this);
540 // in bg, count dmg if victim is also a player
541 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
543 if (BattleGround
*bg
= killer
->GetBattleGround())
545 // FIXME: kept by compatibility. don't know in BG if the restriction apply.
546 bg
->UpdatePlayerScore(killer
, SCORE_DAMAGE_DONE
, damage
);
550 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DAMAGE_DONE
, damage
, 0, pVictim
);
551 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_DEALT
, damage
);
554 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
555 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_RECEIVED
, damage
);
557 if (pVictim
->GetTypeId() == TYPEID_UNIT
&& !((Creature
*)pVictim
)->isPet() && !((Creature
*)pVictim
)->hasLootRecipient())
558 ((Creature
*)pVictim
)->SetLootRecipient(this);
560 if (health
<= damage
)
562 DEBUG_LOG("DealDamage: victim just died");
564 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
565 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, health
);
567 // find player: owner of controlled `this` or `this` itself maybe
568 Player
*player
= GetCharmerOrOwnerPlayerOrPlayerItself();
570 if(pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->GetLootRecipient())
571 player
= ((Creature
*)pVictim
)->GetLootRecipient();
572 // Reward player, his pets, and group/raid members
573 // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop)
574 if(player
&& player
!=pVictim
)
576 player
->RewardPlayerAndGroupAtKill(pVictim
);
577 player
->ProcDamageAndSpell(pVictim
, PROC_FLAG_KILL
, PROC_FLAG_KILLED
, PROC_EX_NONE
, 0);
579 WorldPacket
data(SMSG_PARTYKILLLOG
, (8+8)); //send event PARTY_KILL
580 data
<< uint64(player
->GetGUID()); //player with killing blow
581 data
<< uint64(pVictim
->GetGUID()); //victim
582 if (Group
*group
= player
->GetGroup())
583 group
->BroadcastPacket(&data
, group
->GetMemberGroup(player
->GetGUID()));
585 player
->SendDirectMessage(&data
);
588 DEBUG_LOG("DealDamageAttackStop");
591 pVictim
->CombatStop();
592 pVictim
->getHostileRefManager().deleteReferences();
594 bool damageFromSpiritOfRedemtionTalent
= spellProto
&& spellProto
->Id
== 27795;
596 // if talent known but not triggered (check priest class for speedup check)
597 Aura
* spiritOfRedemtionTalentReady
= NULL
;
598 if( !damageFromSpiritOfRedemtionTalent
&& // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION
599 pVictim
->GetTypeId()==TYPEID_PLAYER
&& pVictim
->getClass()==CLASS_PRIEST
)
601 AuraList
const& vDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
602 for(AuraList::const_iterator itr
= vDummyAuras
.begin(); itr
!= vDummyAuras
.end(); ++itr
)
604 if((*itr
)->GetSpellProto()->SpellIconID
==1654)
606 spiritOfRedemtionTalentReady
= *itr
;
612 DEBUG_LOG("SET JUST_DIED");
613 if(!spiritOfRedemtionTalentReady
)
614 pVictim
->setDeathState(JUST_DIED
);
616 DEBUG_LOG("DealDamageHealth1");
618 if(spiritOfRedemtionTalentReady
)
620 // save value before aura remove
621 uint32 ressSpellId
= pVictim
->GetUInt32Value(PLAYER_SELF_RES_SPELL
);
623 ressSpellId
= ((Player
*)pVictim
)->GetResurrectionSpellId();
625 //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers)
626 pVictim
->RemoveAllAurasOnDeath();
628 // restore for use at real death
629 pVictim
->SetUInt32Value(PLAYER_SELF_RES_SPELL
,ressSpellId
);
631 // FORM_SPIRITOFREDEMPTION and related auras
632 pVictim
->CastSpell(pVictim
,27827,true,NULL
,spiritOfRedemtionTalentReady
);
635 pVictim
->SetHealth(0);
637 // remember victim PvP death for corpse type and corpse reclaim delay
638 // at original death (not at SpiritOfRedemtionTalent timeout)
639 if( pVictim
->GetTypeId()==TYPEID_PLAYER
&& !damageFromSpiritOfRedemtionTalent
)
640 ((Player
*)pVictim
)->SetPvPDeath(player
!=NULL
);
642 // Call KilledUnit for creatures
643 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->AI())
644 ((Creature
*)this)->AI()->KilledUnit(pVictim
);
647 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
649 if (GetTypeId() == TYPEID_UNIT
)
650 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE
, GetEntry());
651 else if(GetTypeId() == TYPEID_PLAYER
&& pVictim
!= this)
652 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER
, 1, ((Player
*)this)->GetTeam());
655 // 10% durability loss on death
656 // clean InHateListOf
657 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
659 // only if not player and not controlled by player pet. And not at BG
660 if (durabilityLoss
&& !player
&& !((Player
*)pVictim
)->InBattleGround())
662 DEBUG_LOG("We are dead, loosing 10 percents durability");
663 ((Player
*)pVictim
)->DurabilityLossAll(0.10f
,false);
664 // durability lost message
665 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
666 ((Player
*)pVictim
)->GetSession()->SendPacket(&data
);
669 else // creature died
671 DEBUG_LOG("DealDamageNotPlayer");
672 Creature
*cVictim
= (Creature
*)pVictim
;
674 if(!cVictim
->isPet())
676 cVictim
->DeleteThreatList();
677 // only lootable if it has loot or can drop gold
678 if(cVictim
->GetCreatureInfo()->lootid
|| cVictim
->GetCreatureInfo()->maxgold
> 0)
679 cVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
681 cVictim
->lootForBody
= true; // needed for skinning
683 // Call creature just died function
685 cVictim
->AI()->JustDied(this);
687 // Dungeon specific stuff, only applies to players killing creatures
688 if(cVictim
->GetInstanceId())
690 Map
*m
= cVictim
->GetMap();
691 Player
*creditedPlayer
= GetCharmerOrOwnerPlayerOrPlayerItself();
692 // TODO: do instance binding anyway if the charmer/owner is offline
694 if(m
->IsDungeon() && creditedPlayer
)
696 if (m
->IsRaidOrHeroicDungeon())
698 if(cVictim
->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
699 ((InstanceMap
*)m
)->PermBindAllPlayers(creditedPlayer
);
703 // the reset time is set but not added to the scheduler
704 // until the players leave the instance
705 time_t resettime
= cVictim
->GetRespawnTimeEx() + 2 * HOUR
;
706 if(InstanceSave
*save
= sInstanceSaveMgr
.GetInstanceSave(cVictim
->GetInstanceId()))
707 if(save
->GetResetTime() < resettime
) save
->SetResetTime(resettime
);
713 // last damage from non duel opponent or opponent controlled creature
716 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
717 Player
*he
= (Player
*)pVictim
;
721 he
->duel
->opponent
->CombatStopWithPets(true);
722 he
->CombatStopWithPets(true);
724 he
->DuelComplete(DUEL_INTERUPTED
);
727 // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill)
728 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->InBattleGround())
730 Player
*killed
= ((Player
*)pVictim
);
731 if(BattleGround
*bg
= killed
->GetBattleGround())
733 bg
->HandleKillPlayer(killed
, player
);
735 else if(pVictim
->GetTypeId() == TYPEID_UNIT
)
738 if (BattleGround
*bg
= player
->GetBattleGround())
739 bg
->HandleKillUnit((Creature
*)pVictim
, player
);
742 else // if (health <= damage)
744 DEBUG_LOG("DealDamageAlive");
746 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
747 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, damage
);
749 pVictim
->ModifyHealth(- (int32
)damage
);
751 if(damagetype
!= DOT
)
755 // if not have main target then attack state with target (including AI call)
756 //start melee attacks only after melee hit
757 Attack(pVictim
,(damagetype
== DIRECT_DAMAGE
));
760 // if damage pVictim call AI reaction
761 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
762 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
765 // polymorphed, hex and other negative transformed cases
766 uint32 morphSpell
= pVictim
->getTransForm();
767 if (morphSpell
&& !IsPositiveSpell(morphSpell
))
769 if (SpellEntry
const* morphEntry
= sSpellStore
.LookupEntry(morphSpell
))
771 if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_CONFUSE
))
772 pVictim
->RemoveAurasDueToSpell(morphSpell
);
773 else if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_PACIFY_SILENCE
))
774 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_PACIFY_SILENCE
, damage
);
778 if(damagetype
== DIRECT_DAMAGE
|| damagetype
== SPELL_DIRECT_DAMAGE
)
780 if (!spellProto
|| !(spellProto
->AuraInterruptFlags
&AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
))
781 pVictim
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
);
783 if (pVictim
->GetTypeId() != TYPEID_PLAYER
)
785 if(spellProto
&& IsDamageToThreatSpell(spellProto
))
786 pVictim
->AddThreat(this, damage
*2, (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
788 pVictim
->AddThreat(this, damage
, (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
790 else // victim is a player
792 // Rage from damage received
793 if(this != pVictim
&& pVictim
->getPowerType() == POWER_RAGE
)
795 uint32 rage_damage
= damage
+ (cleanDamage
? cleanDamage
->damage
: 0);
796 ((Player
*)pVictim
)->RewardRage(rage_damage
, 0, false);
799 // random durability for items (HIT TAKEN)
800 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
802 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
803 ((Player
*)pVictim
)->DurabilityPointLossForEquipSlot(slot
);
807 if(GetTypeId()==TYPEID_PLAYER
)
809 // random durability for items (HIT DONE)
810 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
812 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
813 ((Player
*)this)->DurabilityPointLossForEquipSlot(slot
);
817 // TODO: Store auras by interrupt flag to speed this up.
818 AuraMap
& vAuras
= pVictim
->GetAuras();
819 for (AuraMap::const_iterator i
= vAuras
.begin(), next
; i
!= vAuras
.end(); i
= next
)
821 const SpellEntry
*se
= i
->second
->GetSpellProto();
823 if (spellProto
&& spellProto
->Id
== se
->Id
) // Not drop auras added by self
825 if( se
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_DAMAGE
)
828 if (se
->procFlags
& (1<<3))
830 if (!roll_chance_i(se
->procChance
))
835 pVictim
->RemoveAurasDueToSpell(i
->second
->GetId());
836 // FIXME: this may cause the auras with proc chance to be rerolled several times
837 next
= vAuras
.begin();
842 if (damagetype
!= NODAMAGE
&& damage
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
844 if( damagetype
!= DOT
)
846 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
848 // skip channeled spell (processed differently below)
849 if (i
== CURRENT_CHANNELED_SPELL
)
852 if(Spell
* spell
= pVictim
->GetCurrentSpell(CurrentSpellTypes(i
)))
854 if(spell
->getState() == SPELL_STATE_PREPARING
)
856 if(spell
->m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_ABORT_ON_DMG
)
857 pVictim
->InterruptSpell(CurrentSpellTypes(i
));
865 if(Spell
* spell
= pVictim
->m_currentSpells
[CURRENT_CHANNELED_SPELL
])
867 if (spell
->getState() == SPELL_STATE_CASTING
)
869 uint32 channelInterruptFlags
= spell
->m_spellInfo
->ChannelInterruptFlags
;
870 if( channelInterruptFlags
& CHANNEL_FLAG_DELAY
)
872 if(pVictim
!=this) //don't shorten the duration of channeling if you damage yourself
873 spell
->DelayedChannel();
875 else if( (channelInterruptFlags
& (CHANNEL_FLAG_DAMAGE
| CHANNEL_FLAG_DAMAGE2
)) )
877 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
878 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
881 else if (spell
->getState() == SPELL_STATE_DELAYED
)
882 // break channeled spell in delayed state on damage
884 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
885 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
890 // last damage from duel opponent
893 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
894 Player
*he
= (Player
*)pVictim
;
900 he
->duel
->opponent
->CombatStopWithPets(true);
901 he
->CombatStopWithPets(true);
903 he
->CastSpell(he
, 7267, true); // beg
904 he
->DuelComplete(DUEL_WON
);
908 DEBUG_LOG("DealDamageEnd returned %d damage", damage
);
913 void Unit::CastStop(uint32 except_spellid
)
915 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
916 if (m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
!=except_spellid
)
917 InterruptSpell(CurrentSpellTypes(i
),false);
920 void Unit::CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
922 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
926 sLog
.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId
,(GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
930 CastSpell(Victim
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
933 void Unit::CastSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
937 sLog
.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
942 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
944 if(!originalCaster
&& triggeredByAura
)
945 originalCaster
= triggeredByAura
->GetCasterGUID();
947 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
949 SpellCastTargets targets
;
950 targets
.setUnitTarget( Victim
);
951 spell
->m_CastItem
= castItem
;
952 spell
->prepare(&targets
, triggeredByAura
);
955 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
957 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
961 sLog
.outError("CastCustomSpell: unknown spell id %i", spellId
);
965 CastCustomSpell(Victim
,spellInfo
,bp0
,bp1
,bp2
,triggered
,castItem
,triggeredByAura
, originalCaster
);
968 void Unit::CastCustomSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
972 sLog
.outError("CastCustomSpell: unknown spell");
977 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
979 if(!originalCaster
&& triggeredByAura
)
980 originalCaster
= triggeredByAura
->GetCasterGUID();
982 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
985 spell
->m_currentBasePoints
[0] = *bp0
-int32(spellInfo
->EffectBaseDice
[0]);
988 spell
->m_currentBasePoints
[1] = *bp1
-int32(spellInfo
->EffectBaseDice
[1]);
991 spell
->m_currentBasePoints
[2] = *bp2
-int32(spellInfo
->EffectBaseDice
[2]);
993 SpellCastTargets targets
;
994 targets
.setUnitTarget( Victim
);
995 spell
->m_CastItem
= castItem
;
996 spell
->prepare(&targets
, triggeredByAura
);
999 // used for scripting
1000 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1002 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1006 sLog
.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s %u)", spellId
,(GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
1010 CastSpell(x
, y
, z
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
1013 // used for scripting
1014 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1018 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
1023 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1025 if(!originalCaster
&& triggeredByAura
)
1026 originalCaster
= triggeredByAura
->GetCasterGUID();
1028 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1030 SpellCastTargets targets
;
1031 targets
.setDestination(x
, y
, z
);
1032 spell
->m_CastItem
= castItem
;
1033 spell
->prepare(&targets
, triggeredByAura
);
1036 // Obsolete func need remove, here only for comotability vs another patches
1037 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
)
1039 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
1040 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, spellInfo
->SchoolMask
);
1041 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
1042 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
1043 SendSpellNonMeleeDamageLog(&damageInfo
);
1044 DealSpellDamage(&damageInfo
, true);
1045 return damageInfo
.damage
;
1048 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
1050 SpellSchoolMask damageSchoolMask
= SpellSchoolMask(damageInfo
->schoolMask
);
1051 Unit
*pVictim
= damageInfo
->target
;
1056 if(!this || !pVictim
)
1058 if(!this->isAlive() || !pVictim
->isAlive())
1061 uint32 crTypeMask
= pVictim
->GetCreatureTypeMask();
1062 // Check spell crit chance
1063 bool crit
= isSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
1064 bool blocked
= false;
1066 // damage bonus (per damage class)
1067 switch (spellInfo
->DmgClass
)
1069 // Melee and Ranged Spells
1070 case SPELL_DAMAGE_CLASS_RANGED
:
1071 case SPELL_DAMAGE_CLASS_MELEE
:
1073 //Calculate damage bonus
1074 damage
= MeleeDamageBonus(pVictim
, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1075 // Get blocked status
1076 blocked
= isSpellBlocked(pVictim
, spellInfo
, attackType
);
1078 // if crit add critical bonus
1081 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1082 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1083 // Resilience - reduce crit damage
1084 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1085 if (attackType
!= RANGED_ATTACK
)
1086 damage
-= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1088 damage
-= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1093 case SPELL_DAMAGE_CLASS_NONE
:
1094 case SPELL_DAMAGE_CLASS_MAGIC
:
1096 // Calculate damage bonus
1097 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1098 // If crit add critical bonus
1101 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1102 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1103 // Resilience - reduce crit damage
1104 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1105 damage
-= pVictim
->GetSpellCritDamageReduction(redunction_affected_damage
);
1111 // only from players
1112 if (GetTypeId() == TYPEID_PLAYER
)
1114 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1115 damage
-= pVictim
->GetSpellDamageReduction(redunction_affected_damage
);
1118 // damage mitigation
1121 // physical damage => armor
1122 if (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
1124 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1125 damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(pVictim
, armor_affected_damage
);
1128 // block (only for damage class ranged and -melee, also non-physical damage possible)
1131 damageInfo
->blocked
= uint32(pVictim
->GetShieldBlockValue());
1132 if (damage
< damageInfo
->blocked
)
1133 damageInfo
->blocked
= damage
;
1134 damage
-=damageInfo
->blocked
;
1137 uint32 absorb_affected_damage
= CalcNotIgnoreAbsorbDamage(damage
,damageSchoolMask
,spellInfo
);
1138 CalcAbsorbResist(pVictim
, damageSchoolMask
, SPELL_DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, !(spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
));
1139 damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
1143 damageInfo
->damage
= damage
;
1146 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1151 Unit
*pVictim
= damageInfo
->target
;
1153 if(!this || !pVictim
)
1156 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1159 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1160 if (spellProto
== NULL
)
1162 sLog
.outDebug("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1166 //You don't lose health from damage taken from another player while in a sanctuary
1167 //You still see it in the combat log though
1168 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1170 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1171 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1175 // Call default DealDamage (send critical in hit info for threat calculation)
1176 CleanDamage
cleanDamage(damageInfo
->cleanDamage
, BASE_ATTACK
, damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
? MELEE_HIT_CRIT
: MELEE_HIT_NORMAL
);
1177 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->schoolMask
), spellProto
, durabilityLoss
);
1180 //TODO for melee need create structure as in
1181 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1183 damageInfo
->attacker
= this;
1184 damageInfo
->target
= pVictim
;
1185 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1186 damageInfo
->attackType
= attackType
;
1187 damageInfo
->damage
= 0;
1188 damageInfo
->cleanDamage
= 0;
1189 damageInfo
->absorb
= 0;
1190 damageInfo
->resist
= 0;
1191 damageInfo
->blocked_amount
= 0;
1193 damageInfo
->TargetState
= 0;
1194 damageInfo
->HitInfo
= 0;
1195 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1196 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1197 damageInfo
->procEx
= PROC_EX_NONE
;
1198 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1200 if(!this || !pVictim
)
1202 if(!this->isAlive() || !pVictim
->isAlive())
1205 // Select HitInfo/procAttacker/procVictim flag based on attack type
1209 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
;
1210 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1211 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1214 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1215 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1216 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1219 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1220 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1221 damageInfo
->HitInfo
= 0x08;// test
1227 // Physical Immune check
1228 if (damageInfo
->target
->IsImmunedToDamage(damageInfo
->damageSchoolMask
))
1230 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1231 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1233 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1234 damageInfo
->damage
= 0;
1235 damageInfo
->cleanDamage
= 0;
1238 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1239 // Add melee damage bonus
1240 damage
= MeleeDamageBonus(damageInfo
->target
, damage
, damageInfo
->attackType
);
1241 // Calculate armor reduction
1243 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageInfo
->damageSchoolMask
);
1244 damageInfo
->damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(damageInfo
->target
, armor_affected_damage
);
1245 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1247 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1249 // Disable parry or dodge for ranged attack
1250 if (damageInfo
->attackType
== RANGED_ATTACK
)
1252 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1253 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1256 switch(damageInfo
->hitOutCome
)
1258 case MELEE_HIT_EVADE
:
1260 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1261 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1263 damageInfo
->procEx
|=PROC_EX_EVADE
;
1264 damageInfo
->damage
= 0;
1265 damageInfo
->cleanDamage
= 0;
1268 case MELEE_HIT_MISS
:
1270 damageInfo
->HitInfo
|= HITINFO_MISS
;
1271 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1273 damageInfo
->procEx
|=PROC_EX_MISS
;
1274 damageInfo
->damage
= 0;
1275 damageInfo
->cleanDamage
= 0;
1278 case MELEE_HIT_NORMAL
:
1279 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1280 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1282 case MELEE_HIT_CRIT
:
1284 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1285 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1287 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1289 damageInfo
->damage
+= damageInfo
->damage
;
1291 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1292 if(damageInfo
->attackType
== RANGED_ATTACK
)
1293 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1295 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1297 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, SPELL_SCHOOL_MASK_NORMAL
);
1299 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1301 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1302 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1304 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1306 // Resilience - reduce crit damage
1307 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1308 uint32 resilienceReduction
;
1309 if (attackType
!= RANGED_ATTACK
)
1310 resilienceReduction
= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1312 resilienceReduction
= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1314 damageInfo
->damage
-= resilienceReduction
;
1315 damageInfo
->cleanDamage
+= resilienceReduction
;
1318 case MELEE_HIT_PARRY
:
1319 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1320 damageInfo
->procEx
|=PROC_EX_PARRY
;
1321 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1322 damageInfo
->damage
= 0;
1325 case MELEE_HIT_DODGE
:
1326 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1327 damageInfo
->procEx
|=PROC_EX_DODGE
;
1328 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1329 damageInfo
->damage
= 0;
1331 case MELEE_HIT_BLOCK
:
1333 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1334 damageInfo
->HitInfo
|= HITINFO_BLOCK
;
1335 damageInfo
->procEx
|=PROC_EX_BLOCK
;
1336 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1337 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1339 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1340 damageInfo
->blocked_amount
= damageInfo
->damage
;
1342 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1343 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1346 case MELEE_HIT_GLANCING
:
1348 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1349 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1350 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1351 float reducePercent
= 1.0f
; //damage factor
1352 // calculate base values and mods
1353 float baseLowEnd
= 1.3f
;
1354 float baseHighEnd
= 1.2f
;
1355 switch(getClass()) // lowering base values for casters
1363 baseHighEnd
-= 0.3f
;
1367 float maxLowEnd
= 0.6f
;
1368 switch(getClass()) // upper for melee classes
1372 maxLowEnd
= 0.91f
; //If the attacker is a melee class then instead the lower value of 0.91
1376 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1377 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1378 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1380 // apply max/min bounds
1381 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1383 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1386 if ( highEnd
< 0.2f
) //high end limits
1388 if ( highEnd
> 0.99f
)
1391 if(lowEnd
> highEnd
) // prevent negative range size
1394 reducePercent
= lowEnd
+ rand_norm() * ( highEnd
- lowEnd
);
1396 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1397 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1400 case MELEE_HIT_CRUSHING
:
1402 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1403 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1404 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1405 // 150% normal damage
1406 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1414 // only from players
1415 if (GetTypeId() == TYPEID_PLAYER
)
1417 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageInfo
->damageSchoolMask
);
1418 if (attackType
!= RANGED_ATTACK
)
1419 damage
-= pVictim
->GetMeleeDamageReduction(redunction_affected_damage
);
1421 damage
-= pVictim
->GetRangedDamageReduction(redunction_affected_damage
);
1424 // Calculate absorb resist
1425 if(int32(damageInfo
->damage
) > 0)
1427 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1429 // Calculate absorb & resists
1430 uint32 absorb_affected_damage
= CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1431 CalcAbsorbResist(damageInfo
->target
, damageInfo
->damageSchoolMask
, DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, true);
1432 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1433 if (damageInfo
->absorb
)
1435 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1436 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1438 if (damageInfo
->resist
)
1439 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1442 else // Umpossible get negative result but....
1443 damageInfo
->damage
= 0;
1446 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1448 if (damageInfo
==0) return;
1449 Unit
*pVictim
= damageInfo
->target
;
1451 if(!this || !pVictim
)
1454 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1457 //You don't lose health from damage taken from another player while in a sanctuary
1458 //You still see it in the combat log though
1459 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1461 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1462 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1466 // Hmmmm dont like this emotes client must by self do all animations
1467 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1468 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1469 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1470 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1472 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1474 // Get attack timers
1475 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1476 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1477 // Reduce attack time
1478 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1480 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20f
;
1481 float percent60
= 3.0f
* percent20
;
1482 if(offtime
> percent20
&& offtime
<= percent60
)
1484 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1486 else if(offtime
> percent60
)
1488 offtime
-= 2.0f
* percent20
;
1489 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1494 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20;
1495 float percent60
= 3.0f
* percent20
;
1496 if(basetime
> percent20
&& basetime
<= percent60
)
1498 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1500 else if(basetime
> percent60
)
1502 basetime
-= 2.0f
* percent20
;
1503 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1508 // Call default DealDamage
1509 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1510 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, damageInfo
->damageSchoolMask
, NULL
, durabilityLoss
);
1512 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1513 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1514 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI
, this) )
1516 // -probability is between 0% and 40%
1518 float Probability
= 20.0f
;
1520 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1521 if( pVictim
->getLevel() < 30 )
1522 Probability
= 0.65f
*pVictim
->getLevel()+0.5f
;
1524 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1525 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1527 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1529 if(Probability
> 40.0f
)
1530 Probability
= 40.0f
;
1532 if(roll_chance_f(Probability
))
1533 CastSpell(pVictim
, 1604, true);
1537 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1539 // on weapon hit casts
1540 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1541 ((Player
*)this)->CastItemCombatSpell(pVictim
, damageInfo
->attackType
);
1543 // victim's damage shield
1544 std::set
<Aura
*> alreadyDone
;
1545 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1546 for(AuraList::const_iterator i
= vDamageShields
.begin(); i
!= vDamageShields
.end();)
1548 if (alreadyDone
.find(*i
) == alreadyDone
.end())
1550 alreadyDone
.insert(*i
);
1551 uint32 damage
=(*i
)->GetModifier()->m_amount
;
1552 SpellEntry
const *i_spellProto
= (*i
)->GetSpellProto();
1553 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
1556 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1557 //damage-=absorb + resist;
1559 pVictim
->DealDamageMods(this,damage
,NULL
);
1561 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4+4+4));
1562 data
<< uint64(pVictim
->GetGUID());
1563 data
<< uint64(GetGUID());
1564 data
<< uint32(i_spellProto
->Id
);
1565 data
<< uint32(damage
); // Damage
1566 data
<< uint32(0); // Overkill
1567 data
<< uint32(i_spellProto
->SchoolMask
);
1568 pVictim
->SendMessageToSet(&data
, true );
1570 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(i_spellProto
), i_spellProto
, true);
1572 i
= vDamageShields
.begin();
1581 void Unit::HandleEmoteCommand(uint32 anim_id
)
1583 WorldPacket
data( SMSG_EMOTE
, 4 + 8 );
1584 data
<< uint32(anim_id
);
1585 data
<< uint64(GetGUID());
1586 SendMessageToSet(&data
, true);
1589 uint32
Unit::CalcNotIgnoreAbsorbDamage( uint32 damage
, SpellSchoolMask damageSchoolMask
, SpellEntry
const* spellInfo
/*= NULL*/)
1591 float absorb_affected_rate
= 1.0f
;
1592 Unit::AuraList
const& ignoreAbsorbSchool
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_SCHOOL
);
1593 for(Unit::AuraList::const_iterator i
= ignoreAbsorbSchool
.begin(); i
!= ignoreAbsorbSchool
.end(); ++i
)
1594 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1595 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1599 Unit::AuraList
const& ignoreAbsorbForSpell
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL
);
1600 for(Unit::AuraList::const_iterator citr
= ignoreAbsorbForSpell
.begin(); citr
!= ignoreAbsorbForSpell
.end(); ++citr
)
1601 if ((*citr
)->isAffectedOnSpell(spellInfo
))
1602 absorb_affected_rate
*= (100.0f
- (*citr
)->GetModifier()->m_amount
)/100.0f
;
1605 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1608 uint32
Unit::CalcNotIgnoreDamageRedunction( uint32 damage
, SpellSchoolMask damageSchoolMask
)
1610 float absorb_affected_rate
= 1.0f
;
1611 Unit::AuraList
const& ignoreAbsorb
= GetAurasByType(SPELL_AURA_MOD_IGNORE_DAMAGE_REDUCTION_SCHOOL
);
1612 for(Unit::AuraList::const_iterator i
= ignoreAbsorb
.begin(); i
!= ignoreAbsorb
.end(); ++i
)
1613 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1614 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1616 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1619 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
1621 uint32 newdamage
= 0;
1622 float armor
= pVictim
->GetArmor();
1624 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
1625 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
1627 // Apply Player CR_ARMOR_PENETRATION rating and percent talents
1628 if (GetTypeId()==TYPEID_PLAYER
)
1629 armor
*= 1.0f
- ((Player
*)this)->GetArmorPenetrationPct() / 100.0f
;
1634 float levelModifier
= getLevel();
1635 if (levelModifier
> 59)
1636 levelModifier
= levelModifier
+ (4.5f
* (levelModifier
-59));
1638 float tmpvalue
= 0.1f
* armor
/ (8.5f
* levelModifier
+ 40);
1639 tmpvalue
= tmpvalue
/(1.0f
+ tmpvalue
);
1641 if (tmpvalue
< 0.0f
)
1643 if (tmpvalue
> 0.75f
)
1646 newdamage
= uint32(damage
- (damage
* tmpvalue
));
1648 return (newdamage
> 1) ? newdamage
: 1;
1651 void Unit::CalcAbsorbResist(Unit
*pVictim
,SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
, bool canReflect
)
1653 if(!pVictim
|| !pVictim
->isAlive() || !damage
)
1656 // Magic damage, check for resists
1657 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
1659 // Get base victim resistance for school
1660 float tmpvalue2
= (float)pVictim
->GetResistance(GetFirstSchoolInMask(schoolMask
));
1661 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
1662 tmpvalue2
+= (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
1664 tmpvalue2
*= (float)(0.15f
/ getLevel());
1665 if (tmpvalue2
< 0.0f
)
1667 if (tmpvalue2
> 0.75f
)
1669 uint32 ran
= urand(0, 100);
1670 uint32 faq
[4] = {24,6,4,6};
1673 for (uint8 i
= 0; i
< 4; ++i
)
1675 Binom
+= 2400 *( powf(tmpvalue2
, i
) * powf( (1-tmpvalue2
), (4-i
)))/faq
[i
];
1681 if (damagetype
== DOT
&& m
== 4)
1682 *resist
+= uint32(damage
- 1);
1684 *resist
+= uint32(damage
* m
/ 4);
1685 if(*resist
> damage
)
1691 int32 RemainingDamage
= damage
- *resist
;
1693 // Get unit state (need for some absorb check)
1694 uint32 unitflag
= pVictim
->GetUInt32Value(UNIT_FIELD_FLAGS
);
1695 // Reflect damage spells (not cast any damage spell in aura lookup)
1696 uint32 reflectSpell
= 0;
1697 int32 reflectDamage
= 0;
1698 Aura
* reflectTriggeredBy
= NULL
; // expected as not expired at reflect as in current cases
1699 // Death Prevention Aura
1700 SpellEntry
const* preventDeathSpell
= NULL
;
1701 int32 preventDeathAmount
= 0;
1703 // full absorb cases (by chance)
1704 AuraList
const& vAbsorb
= pVictim
->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1705 for(AuraList::const_iterator i
= vAbsorb
.begin(); i
!= vAbsorb
.end() && RemainingDamage
> 0; ++i
)
1707 // only work with proper school mask damage
1708 Modifier
* i_mod
= (*i
)->GetModifier();
1709 if (!(i_mod
->m_miscvalue
& schoolMask
))
1712 SpellEntry
const* i_spellProto
= (*i
)->GetSpellProto();
1713 // Fire Ward or Frost Ward
1714 if(i_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& i_spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000108))
1717 Unit::AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_ADD_PCT_MODIFIER
);
1718 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
1720 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
1721 // Frost Warding (chance full absorb)
1722 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& itr_spellProto
->SpellIconID
== 501)
1724 // chance stored in next dummy effect
1725 chance
= itr_spellProto
->CalculateSimpleValue(1);
1729 if(roll_chance_i(chance
))
1731 int32 amount
= RemainingDamage
;
1732 RemainingDamage
= 0;
1733 // Frost Warding (mana regen)
1734 pVictim
->CastCustomSpell(pVictim
, 57776, &amount
, NULL
, NULL
, true, NULL
, *i
);
1740 // Need remove expired auras after
1741 bool existExpired
= false;
1743 // absorb without mana cost
1744 AuraList
const& vSchoolAbsorb
= pVictim
->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1745 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; ++i
)
1747 Modifier
* mod
= (*i
)->GetModifier();
1748 if (!(mod
->m_miscvalue
& schoolMask
))
1751 SpellEntry
const* spellProto
= (*i
)->GetSpellProto();
1753 // Max Amount can be absorbed by this aura
1754 int32 currentAbsorb
= mod
->m_amount
;
1756 // Found empty aura (impossible but..)
1757 if (currentAbsorb
<=0)
1759 existExpired
= true;
1762 // Handle custom absorb auras
1763 // TODO: try find better way
1764 switch(spellProto
->SpellFamilyName
)
1766 case SPELLFAMILY_GENERIC
:
1769 if (spellProto
->SpellIconID
== 3066)
1771 //reduces all damage taken while stun, fear or silence
1772 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1773 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1777 if (spellProto
->SpellIconID
== 2115)
1779 // while affected by Stun and Fear
1780 if (unitflag
&(UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
))
1781 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1785 if (spellProto
->SpellIconID
== 3006)
1787 // You have a chance equal to your Parry chance
1788 if (damagetype
== DIRECT_DAMAGE
&& // Only for direct damage
1789 roll_chance_f(pVictim
->GetUnitParryChance())) // Roll chance
1790 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1793 // Reflective Shield (Lady Malande boss)
1794 if (spellProto
->Id
== 41475 && canReflect
)
1796 if(RemainingDamage
< currentAbsorb
)
1797 reflectDamage
= RemainingDamage
/ 2;
1799 reflectDamage
= currentAbsorb
/ 2;
1800 reflectSpell
= 33619;
1801 reflectTriggeredBy
= *i
;
1804 if (spellProto
->Id
== 39228 || // Argussian Compass
1805 spellProto
->Id
== 60218) // Essence of Gossamer
1807 // Max absorb stored in 1 dummy effect
1808 if (spellProto
->EffectBasePoints
[1] < currentAbsorb
)
1809 currentAbsorb
= spellProto
->EffectBasePoints
[1];
1814 case SPELLFAMILY_DRUID
:
1817 if (spellProto
->SpellIconID
== 2253)
1819 //reduces all damage taken while Stunned
1820 if (unitflag
& UNIT_FLAG_STUNNED
)
1821 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1826 case SPELLFAMILY_ROGUE
:
1828 // Cheat Death (make less prio with Guardian Spirit case)
1829 if (!preventDeathSpell
&& spellProto
->SpellIconID
== 2109 &&
1830 pVictim
->GetTypeId()==TYPEID_PLAYER
&& // Only players
1831 !((Player
*)pVictim
)->HasSpellCooldown(31231) &&
1832 // Only if no cooldown
1833 roll_chance_i((*i
)->GetModifier()->m_amount
))
1836 preventDeathSpell
= (*i
)->GetSpellProto();
1841 case SPELLFAMILY_PRIEST
:
1844 if (spellProto
->SpellIconID
== 2873)
1846 preventDeathSpell
= (*i
)->GetSpellProto();
1847 preventDeathAmount
= (*i
)->GetModifier()->m_amount
;
1850 // Power Word: Shield
1851 if (spellProto
->SpellFamilyFlags
& UI64LIT(00000001) && spellProto
->Mechanic
== MECHANIC_SHIELD
)
1853 // Glyph of Power Word: Shield
1854 if (Aura
*glyph
= pVictim
->GetAura(55672,0))
1856 int32 heal
= int32(glyph
->GetModifier()->m_amount
*
1857 (RemainingDamage
>= currentAbsorb
? currentAbsorb
: RemainingDamage
) / 100);
1858 pVictim
->CastCustomSpell(pVictim
, 56160, &heal
, NULL
, NULL
, true, 0, *i
);
1861 // Reflective Shield
1862 if (spellProto
->SpellFamilyFlags
== 0x1 && canReflect
)
1864 if (pVictim
== this)
1866 Unit
* caster
= (*i
)->GetCaster();
1869 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
1870 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
1872 switch((*k
)->GetModifier()->m_miscvalue
)
1874 case 5065: // Rank 1
1875 case 5064: // Rank 2
1877 if(RemainingDamage
>= currentAbsorb
)
1878 reflectDamage
= (*k
)->GetModifier()->m_amount
* currentAbsorb
/100;
1880 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
1881 reflectSpell
= 33619;
1882 reflectTriggeredBy
= *i
;
1891 case SPELLFAMILY_SHAMAN
:
1894 if (spellProto
->SpellIconID
== 3066)
1896 //reduces all damage taken while stun, fear or silence
1897 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1898 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1903 case SPELLFAMILY_DEATHKNIGHT
:
1906 if (spellProto
->SpellIconID
== 1958)
1908 // TODO: absorb only while transform
1911 // Anti-Magic Shell (on self)
1912 if (spellProto
->Id
== 48707)
1914 // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power.
1915 // This, if I'm not mistaken, shows that we get back ~2% of the absorbed damage as runic power.
1916 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
1917 int32 regen
= absorbed
* 2 / 10;
1918 pVictim
->CastCustomSpell(pVictim
, 49088, ®en
, NULL
, NULL
, true, NULL
, *i
);
1919 RemainingDamage
-= absorbed
;
1922 // Anti-Magic Shell (on single party/raid member)
1923 if (spellProto
->Id
== 50462)
1925 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1929 if (spellProto
->Id
== 50461)
1931 Unit
* caster
= (*i
)->GetCaster();
1934 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
1935 int32 canabsorb
= caster
->GetHealth();
1936 if (canabsorb
< absorbed
)
1937 absorbed
= canabsorb
;
1939 RemainingDamage
-= absorbed
;
1941 uint32 ab_damage
= absorbed
;
1942 DealDamageMods(caster
,ab_damage
,NULL
);
1943 DealDamage(caster
, ab_damage
, NULL
, damagetype
, schoolMask
, 0, false);
1952 // currentAbsorb - damage can be absorbed by shield
1953 // If need absorb less damage
1954 if (RemainingDamage
< currentAbsorb
)
1955 currentAbsorb
= RemainingDamage
;
1957 RemainingDamage
-= currentAbsorb
;
1959 // Reduce shield amount
1960 mod
->m_amount
-=currentAbsorb
;
1961 if((*i
)->DropAuraCharge())
1963 // Need remove it later
1964 if (mod
->m_amount
<=0)
1965 existExpired
= true;
1968 // Remove all expired absorb auras
1971 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end();)
1973 if ((*i
)->GetModifier()->m_amount
<=0)
1975 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
1976 i
= vSchoolAbsorb
.begin();
1983 // Cast back reflect damage spell
1984 if (canReflect
&& reflectSpell
)
1985 pVictim
->CastCustomSpell(this, reflectSpell
, &reflectDamage
, NULL
, NULL
, true, NULL
, reflectTriggeredBy
);
1987 // absorb by mana cost
1988 AuraList
const& vManaShield
= pVictim
->GetAurasByType(SPELL_AURA_MANA_SHIELD
);
1989 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
1993 // check damage school mask
1994 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1997 int32 currentAbsorb
;
1998 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
1999 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2001 currentAbsorb
= RemainingDamage
;
2003 if (float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()])
2005 if(Player
*modOwner
= pVictim
->GetSpellModOwner())
2006 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
2008 int32 maxAbsorb
= int32(pVictim
->GetPower(POWER_MANA
) / manaMultiplier
);
2009 if (currentAbsorb
> maxAbsorb
)
2010 currentAbsorb
= maxAbsorb
;
2012 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
2013 pVictim
->ApplyPowerMod(POWER_MANA
, manaReduction
, false);
2016 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
2017 if((*i
)->GetModifier()->m_amount
<= 0)
2019 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
2020 next
= vManaShield
.begin();
2023 RemainingDamage
-= currentAbsorb
;
2026 // effects dependent from full absorb amount
2027 if (int32 full_absorb
= damage
- RemainingDamage
- *resist
)
2029 Unit::AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
2030 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
2032 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
2034 // Incanter's Absorption
2035 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_GENERIC
&&
2036 itr_spellProto
->SpellIconID
== 2941)
2039 int32 amount
= int32(full_absorb
* (*itr
)->GetModifier()->m_amount
/ 100);
2041 // apply normalized part of already accumulated amount in aura
2042 if (Aura
* spdAura
= pVictim
->GetAura(44413,0))
2043 amount
+= spdAura
->GetModifier()->m_amount
* spdAura
->GetAuraDuration() / spdAura
->GetAuraMaxDuration();
2045 // limit 5 health percents
2046 int32 health_5percent
= pVictim
->GetMaxHealth()*5/100;
2047 if(amount
> health_5percent
)
2048 amount
= health_5percent
;
2050 // Incanter's Absorption (triggered absorb based spell power, will replace existed if any)
2051 pVictim
->CastCustomSpell(pVictim
, 44413, &amount
, NULL
, NULL
, true);
2057 // only split damage if not damaging yourself
2060 AuraList
const& vSplitDamageFlat
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
2061 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
2065 // check damage school mask
2066 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2069 // Damage can be splitted only if aura has an alive caster
2070 Unit
*caster
= (*i
)->GetCaster();
2071 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
2074 int32 currentAbsorb
;
2075 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2076 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2078 currentAbsorb
= RemainingDamage
;
2080 RemainingDamage
-= currentAbsorb
;
2083 uint32 splitted
= currentAbsorb
;
2084 uint32 splitted_absorb
= 0;
2085 DealDamageMods(caster
,splitted
,&splitted_absorb
);
2087 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, splitted_absorb
, 0, false, 0, false);
2089 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2090 DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2093 AuraList
const& vSplitDamagePct
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
2094 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
2098 // check damage school mask
2099 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2102 // Damage can be splitted only if aura has an alive caster
2103 Unit
*caster
= (*i
)->GetCaster();
2104 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
2107 uint32 splitted
= uint32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
2109 RemainingDamage
-= int32(splitted
);
2111 uint32 split_absorb
= 0;
2112 DealDamageMods(caster
,splitted
,&split_absorb
);
2114 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, split_absorb
, 0, false, 0, false);
2116 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2117 DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2121 // Apply death prevention spells effects
2122 if (preventDeathSpell
&& RemainingDamage
>= pVictim
->GetHealth())
2124 switch(preventDeathSpell
->SpellFamilyName
)
2127 case SPELLFAMILY_ROGUE
:
2130 if (preventDeathSpell
->SpellIconID
== 2109)
2132 pVictim
->CastSpell(pVictim
,31231,true);
2133 ((Player
*)pVictim
)->AddSpellCooldown(31231,0,time(NULL
)+60);
2134 // with health > 10% lost health until health==10%, in other case no losses
2135 uint32 health10
= pVictim
->GetMaxHealth()/10;
2136 RemainingDamage
= pVictim
->GetHealth() > health10
? pVictim
->GetHealth() - health10
: 0;
2141 case SPELLFAMILY_PRIEST
:
2144 if (preventDeathSpell
->SpellIconID
== 2873)
2146 int32 healAmount
= pVictim
->GetMaxHealth() * preventDeathAmount
/ 100;
2147 pVictim
->CastCustomSpell(pVictim
, 48153, &healAmount
, NULL
, NULL
, true);
2148 pVictim
->RemoveAurasDueToSpell(preventDeathSpell
->Id
);
2149 RemainingDamage
= 0;
2156 *absorb
= damage
- RemainingDamage
- *resist
;
2159 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
2161 if(hasUnitState(UNIT_STAT_CONFUSED
| UNIT_STAT_STUNNED
| UNIT_STAT_FLEEING
| UNIT_STAT_DIED
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
2164 if (!pVictim
->isAlive())
2167 if(IsNonMeleeSpellCasted(false))
2171 if (attType
== BASE_ATTACK
)
2172 hitInfo
= HITINFO_NORMALSWING2
;
2173 else if (attType
== OFF_ATTACK
)
2174 hitInfo
= HITINFO_LEFTSWING
;
2176 return; // ignore ranged case
2178 uint32 extraAttacks
= m_extraAttacks
;
2180 // melee attack spell casted at main hand attack only
2181 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
2183 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
2185 // not recent extra attack only at any non extra attack (melee spell case)
2186 if(!extra
&& extraAttacks
)
2188 while(m_extraAttacks
)
2190 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2191 if(m_extraAttacks
> 0)
2198 // attack can be redirected to another target
2199 pVictim
= SelectMagnetTarget(pVictim
);
2201 CalcDamageInfo damageInfo
;
2202 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
2203 // Send log damage message to client
2204 DealDamageMods(pVictim
,damageInfo
.damage
,&damageInfo
.absorb
);
2205 SendAttackStateUpdate(&damageInfo
);
2206 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
2207 DealMeleeDamage(&damageInfo
,true);
2209 if (GetTypeId() == TYPEID_PLAYER
)
2210 DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2211 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2213 DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2214 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2216 // if damage pVictim call AI reaction
2217 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
2218 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
2220 // extra attack only at any non extra attack (normal case)
2221 if(!extra
&& extraAttacks
)
2223 while(m_extraAttacks
)
2225 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2226 if(m_extraAttacks
> 0)
2232 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
2234 // This is only wrapper
2236 // Miss chance based on melee
2237 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
2239 // Critical hit chance
2240 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
2242 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
2243 float dodge_chance
= pVictim
->GetUnitDodgeChance();
2244 float block_chance
= pVictim
->GetUnitBlockChance();
2245 float parry_chance
= pVictim
->GetUnitParryChance();
2247 // Useful if want to specify crit & miss chances for melee, else it could be removed
2248 DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance
,crit_chance
,dodge_chance
,parry_chance
,block_chance
);
2250 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100));
2253 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const
2255 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2256 return MELEE_HIT_EVADE
;
2258 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
2259 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
2261 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
2262 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
2264 // bonus from skills is 0.04%
2265 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
2266 int32 sum
= 0, tmp
= 0;
2267 int32 roll
= urand (0, 10000);
2269 DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
2270 DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
2271 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
2275 if (tmp
> 0 && roll
< (sum
+= tmp
))
2277 DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS");
2278 return MELEE_HIT_MISS
;
2281 // always crit against a sitting target (except 0 crit chance)
2282 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
2284 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)");
2285 return MELEE_HIT_CRIT
;
2290 // only players can't dodge if attacker is behind
2291 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI
,this))
2293 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
2297 // Reduce dodge chance by attacker expertise rating
2298 if (GetTypeId() == TYPEID_PLAYER
)
2299 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2301 dodge_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2303 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2304 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2307 if ( (tmp
> 0) // check if unit _can_ dodge
2308 && ((tmp
-= skillBonus
) > 0)
2309 && roll
< (sum
+= tmp
))
2311 DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
2312 return MELEE_HIT_DODGE
;
2316 // parry & block chances
2318 // check if attack comes from behind, nobody can parry or block if attacker is behind
2319 if (!pVictim
->HasInArc(M_PI
,this))
2321 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind.");
2325 // Reduce parry chance by attacker expertise rating
2326 if (GetTypeId() == TYPEID_PLAYER
)
2327 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2329 parry_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2331 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
2333 int32 tmp2
= int32(parry_chance
);
2334 if ( (tmp2
> 0) // check if unit _can_ parry
2335 && ((tmp2
-= skillBonus
) > 0)
2336 && (roll
< (sum
+= tmp2
)))
2338 DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp2
, sum
);
2339 return MELEE_HIT_PARRY
;
2343 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
2346 if ( (tmp
> 0) // check if unit _can_ block
2347 && ((tmp
-= skillBonus
) > 0)
2348 && (roll
< (sum
+= tmp
)))
2350 DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
2351 return MELEE_HIT_BLOCK
;
2359 if (tmp
> 0 && roll
< (sum
+= tmp
))
2361 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
2362 return MELEE_HIT_CRIT
;
2365 // Max 40% chance to score a glancing blow against mobs that are higher level (can do only players and pets and not with ranged weapon)
2366 if( attType
!= RANGED_ATTACK
&&
2367 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
2368 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
2369 getLevel() < pVictim
->getLevelForTarget(this) )
2371 // cap possible value (with bonuses > max skill)
2372 int32 skill
= attackerWeaponSkill
;
2373 int32 maxskill
= attackerMaxSkillValueForLevel
;
2374 skill
= (skill
> maxskill
) ? maxskill
: skill
;
2376 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
2377 tmp
= tmp
> 4000 ? 4000 : tmp
;
2378 if (roll
< (sum
+= tmp
))
2380 DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
2381 return MELEE_HIT_GLANCING
;
2385 // mobs can score crushing blows if they're 4 or more levels above victim
2386 if (getLevelForTarget(pVictim
) >= pVictim
->getLevelForTarget(this) + 4 &&
2387 // can be from by creature (if can) or from controlled player that considered as creature
2388 (GetTypeId()!=TYPEID_PLAYER
&& !((Creature
*)this)->isPet() &&
2389 !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) ||
2390 GetTypeId()==TYPEID_PLAYER
&& GetCharmerOrOwnerGUID()))
2392 // when their weapon skill is 15 or more above victim's defense skill
2393 tmp
= victimDefenseSkill
;
2394 int32 tmpmax
= victimMaxSkillValueForLevel
;
2395 // having defense above your maximum (from items, talents etc.) has no effect
2396 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
2397 // tmp = mob's level * 5 - player's current defense skill
2398 tmp
= attackerMaxSkillValueForLevel
- tmp
;
2401 // add 2% chance per lacking skill point, min. is 15%
2402 tmp
= tmp
* 200 - 1500;
2403 if (roll
< (sum
+= tmp
))
2405 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
2406 return MELEE_HIT_CRUSHING
;
2411 DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL");
2412 return MELEE_HIT_NORMAL
;
2415 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
2417 float min_damage
, max_damage
;
2419 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
2420 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
2426 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
2427 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
2430 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
2431 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
2434 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
2435 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
2437 // Just for good manner
2445 if (min_damage
> max_damage
)
2447 std::swap(min_damage
,max_damage
);
2450 if(max_damage
== 0.0f
)
2453 return urand((uint32
)min_damage
, (uint32
)max_damage
);
2456 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
2458 if(spellProto
->spellLevel
<= 0)
2461 float LvlPenalty
= 0.0f
;
2463 if(spellProto
->spellLevel
< 20)
2464 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
2465 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
2466 if(LvlFactor
> 1.0f
)
2469 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
2472 void Unit::SendMeleeAttackStart(Unit
* pVictim
)
2474 WorldPacket
data( SMSG_ATTACKSTART
, 8 + 8 );
2475 data
<< uint64(GetGUID());
2476 data
<< uint64(pVictim
->GetGUID());
2478 SendMessageToSet(&data
, true);
2479 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
2482 void Unit::SendMeleeAttackStop(Unit
* victim
)
2487 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
2488 data
.append(GetPackGUID());
2489 data
.append(victim
->GetPackGUID()); // can be 0x00...
2490 data
<< uint32(0); // can be 0x1
2491 SendMessageToSet(&data
, true);
2492 sLog
.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER
? "player" : "creature"), GetGUIDLow(), (victim
->GetTypeId()==TYPEID_PLAYER
? "player" : "creature"),victim
->GetGUIDLow());
2494 /*if(victim->GetTypeId() == TYPEID_UNIT)
2495 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
2498 bool Unit::isSpellBlocked(Unit
*pVictim
, SpellEntry
const * /*spellProto*/, WeaponAttackType attackType
)
2500 if (pVictim
->HasInArc(M_PI
,this))
2502 /* Currently not exist spells with ignore block
2503 // Ignore combat result aura (parry/dodge check on prepare)
2504 AuraList const& ignore = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2505 for(AuraList::const_iterator i = ignore.begin(); i != ignore.end(); ++i)
2507 if (!(*i)->isAffectedOnSpell(spellProto))
2509 if ((*i)->GetModifier()->m_miscvalue == )
2514 // Check creatures flags_extra for disable block
2515 if(pVictim
->GetTypeId()==TYPEID_UNIT
&&
2516 ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
)
2519 float blockChance
= pVictim
->GetUnitBlockChance();
2520 blockChance
+= (int32(GetWeaponSkillValue(attackType
)) - int32(pVictim
->GetMaxSkillValueForLevel()))*0.04f
;
2521 if (roll_chance_f(blockChance
))
2527 // Melee based spells can be miss, parry or dodge on this step
2528 // Crit or block - determined on damage calculation phase! (and can be both in some time)
2529 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
2531 // Calculate hit chance (more correct for chance mod)
2534 // PvP - PvE melee chances
2535 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2536 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
2538 HitChance
= 95 - leveldif
;
2540 HitChance
= 93 - (leveldif
- 2) * lchance
;
2542 // Hit chance depends from victim auras
2543 if(attType
== RANGED_ATTACK
)
2544 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2546 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2548 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2549 if(Player
*modOwner
= GetSpellModOwner())
2550 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
2553 float miss_chance
= 100.0f
- HitChance
;
2555 // Bonuses from attacker aura and ratings
2556 if (attType
== RANGED_ATTACK
)
2557 miss_chance
-= m_modRangedHitChance
;
2559 miss_chance
-= m_modMeleeHitChance
;
2561 // bonus from skills is 0.04%
2562 miss_chance
-= skillDiff
* 0.04f
;
2564 // Limit miss chance from 0 to 60%
2565 if (miss_chance
< 0.0f
)
2567 if (miss_chance
> 60.0f
)
2572 // Melee based spells hit result calculations
2573 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2575 WeaponAttackType attType
= BASE_ATTACK
;
2577 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
2578 attType
= RANGED_ATTACK
;
2580 // bonus from skills is 0.04% per skill Diff
2581 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
2582 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
2583 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
2585 uint32 roll
= urand (0, 10000);
2587 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
2589 uint32 tmp
= missChance
;
2591 return SPELL_MISS_MISS
;
2593 // Chance resist mechanic (select max value from every mechanic spell effect)
2594 int32 resist_mech
= 0;
2595 // Get effects mechanic and chance
2596 for(int eff
= 0; eff
< 3; ++eff
)
2598 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2601 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2602 if (resist_mech
< temp
*100)
2603 resist_mech
= temp
*100;
2609 return SPELL_MISS_RESIST
;
2611 bool canDodge
= true;
2612 bool canParry
= true;
2614 // Same spells cannot be parry/dodge
2615 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
2616 return SPELL_MISS_NONE
;
2618 // Ranged attack cannot be parry/dodge only deflect
2619 if (attType
== RANGED_ATTACK
)
2622 if (pVictim
->HasInArc(M_PI
,this))
2624 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2625 tmp
+=deflect_chance
;
2627 return SPELL_MISS_DEFLECT
;
2629 return SPELL_MISS_NONE
;
2632 // Check for attack from behind
2633 if (!pVictim
->HasInArc(M_PI
,this))
2635 // Can`t dodge from behind in PvP (but its possible in PvE)
2636 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
2641 // Check creatures flags_extra for disable parry
2642 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
2644 uint32 flagEx
= ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
;
2645 if( flagEx
& CREATURE_FLAG_EXTRA_NO_PARRY
)
2648 // Ignore combat result aura
2649 AuraList
const& ignore
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
2650 for(AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
2652 if (!(*i
)->isAffectedOnSpell(spell
))
2654 switch((*i
)->GetModifier()->m_miscvalue
)
2656 case MELEE_HIT_DODGE
: canDodge
= false; break;
2657 case MELEE_HIT_BLOCK
: break; // Block check in hit step
2658 case MELEE_HIT_PARRY
: canParry
= false; break;
2660 DEBUG_LOG("Spell %u SPELL_AURA_IGNORE_COMBAT_RESULT have unhandled state %d", (*i
)->GetId(), (*i
)->GetModifier()->m_miscvalue
);
2668 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
2669 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2670 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
)*100;
2671 // Reduce dodge chance by attacker expertise rating
2672 if (GetTypeId() == TYPEID_PLAYER
)
2673 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2675 dodgeChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2676 if (dodgeChance
< 0)
2681 return SPELL_MISS_DODGE
;
2687 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
2688 // Reduce parry chance by attacker expertise rating
2689 if (GetTypeId() == TYPEID_PLAYER
)
2690 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2692 parryChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2693 if (parryChance
< 0)
2698 return SPELL_MISS_PARRY
;
2701 return SPELL_MISS_NONE
;
2704 // TODO need use unit spell resistances in calculations
2705 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2707 // Can`t miss on dead target (on skinning for example)
2708 if (!pVictim
->isAlive())
2709 return SPELL_MISS_NONE
;
2711 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
2712 // PvP - PvE spell misschances per leveldif > 2
2713 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
2714 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2716 // Base hit chance from attacker and victim levels
2719 modHitChance
= 96 - leveldif
;
2721 modHitChance
= 94 - (leveldif
- 2) * lchance
;
2723 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2724 if(Player
*modOwner
= GetSpellModOwner())
2725 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
2726 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
2727 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
2728 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
2729 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
2730 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
2731 if (IsAreaOfEffectSpell(spell
))
2732 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
2733 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
2734 if (IsDispelSpell(spell
))
2735 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
2736 // Chance resist mechanic (select max value from every mechanic spell effect)
2737 int32 resist_mech
= 0;
2738 // Get effects mechanic and chance
2739 for(int eff
= 0; eff
< 3; ++eff
)
2741 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2744 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2745 if (resist_mech
< temp
)
2750 modHitChance
-=resist_mech
;
2752 // Chance resist debuff
2753 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
2755 int32 HitChance
= modHitChance
* 100;
2756 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
2757 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
2759 // Decrease hit chance from victim rating bonus
2760 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2761 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
2763 if (HitChance
< 100) HitChance
= 100;
2764 if (HitChance
> 10000) HitChance
= 10000;
2766 int32 tmp
= 10000 - HitChance
;
2768 uint32 rand
= urand(0,10000);
2771 return SPELL_MISS_MISS
;
2773 // cast by caster in front of victim
2774 if (pVictim
->HasInArc(M_PI
,this))
2776 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2777 tmp
+=deflect_chance
;
2779 return SPELL_MISS_DEFLECT
;
2782 return SPELL_MISS_NONE
;
2785 // Calculate spell hit result can be:
2786 // Every spell can: Evade/Immune/Reflect/Sucesful hit
2787 // For melee based spells:
2793 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
2795 // Return evade for units in evade mode
2796 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2797 return SPELL_MISS_EVADE
;
2800 if (pVictim
->IsImmunedToSpell(spell
))
2801 return SPELL_MISS_IMMUNE
;
2803 // All positive spells can`t miss
2804 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
2805 if (IsPositiveSpell(spell
->Id
))
2806 return SPELL_MISS_NONE
;
2809 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
)))
2810 return SPELL_MISS_IMMUNE
;
2812 // Try victim reflect spell
2815 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
2816 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
2817 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
2818 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
2819 reflectchance
+= (*i
)->GetModifier()->m_amount
;
2820 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
2822 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
2823 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
2824 return SPELL_MISS_REFLECT
;
2828 switch (spell
->DmgClass
)
2830 case SPELL_DAMAGE_CLASS_RANGED
:
2831 case SPELL_DAMAGE_CLASS_MELEE
:
2832 return MeleeSpellHitResult(pVictim
, spell
);
2833 case SPELL_DAMAGE_CLASS_NONE
:
2834 case SPELL_DAMAGE_CLASS_MAGIC
:
2835 return MagicSpellHitResult(pVictim
, spell
);
2837 return SPELL_MISS_NONE
;
2840 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
2845 // Base misschance 5%
2846 float misschance
= 5.0f
;
2848 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
2849 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
2851 bool isNormal
= false;
2852 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
2854 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
2860 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
2866 // PvP : PvE melee misschances per leveldif > 2
2867 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2869 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2873 // Hit chance from attacker based on ratings and auras
2874 float m_modHitChance
;
2875 if (attType
== RANGED_ATTACK
)
2876 m_modHitChance
= m_modRangedHitChance
;
2878 m_modHitChance
= m_modMeleeHitChance
;
2881 misschance
+= (leveldif
- m_modHitChance
);
2883 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
2885 // Hit chance for victim based on ratings
2886 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2888 if (attType
== RANGED_ATTACK
)
2889 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
2891 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
2894 // Modify miss chance by victim auras
2895 if(attType
== RANGED_ATTACK
)
2896 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2898 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2900 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
2901 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
2902 misschance
-= skillBonus
* 0.04f
;
2904 // Limit miss chance from 0 to 60%
2905 if ( misschance
< 0.0f
)
2907 if ( misschance
> 60.0f
)
2913 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
2915 if(GetTypeId() == TYPEID_PLAYER
)
2917 // in PvP use full skill instead current skill value
2918 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
2919 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
2920 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
2921 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
2925 return GetUnitMeleeSkill(target
);
2928 float Unit::GetUnitDodgeChance() const
2930 if(hasUnitState(UNIT_STAT_STUNNED
))
2932 if( GetTypeId() == TYPEID_PLAYER
)
2933 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
2936 if(((Creature
const*)this)->isTotem())
2941 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
2942 return dodge
> 0.0f
? dodge
: 0.0f
;
2947 float Unit::GetUnitParryChance() const
2949 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
2952 float chance
= 0.0f
;
2954 if(GetTypeId() == TYPEID_PLAYER
)
2956 Player
const* player
= (Player
const*)this;
2957 if(player
->CanParry() )
2959 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true,true);
2961 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true,true);
2964 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
2967 else if(GetTypeId() == TYPEID_UNIT
)
2969 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
2972 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
2976 return chance
> 0.0f
? chance
: 0.0f
;
2979 float Unit::GetUnitBlockChance() const
2981 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
2984 if(GetTypeId() == TYPEID_PLAYER
)
2986 Player
const* player
= (Player
const*)this;
2987 if(player
->CanBlock() )
2989 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
2990 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
2991 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
2993 // is player but has no block ability or no not broken shield equipped
2998 if(((Creature
const*)this)->isTotem())
3003 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
3004 return block
> 0.0f
? block
: 0.0f
;
3009 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
3013 if(GetTypeId() == TYPEID_PLAYER
)
3018 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
3021 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
3024 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
3026 // Just for good manner
3035 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
3039 if(attackType
== RANGED_ATTACK
)
3040 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
3042 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
3044 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
3046 // reduce crit chance from Rating for players
3047 if (attackType
!= RANGED_ATTACK
)
3048 crit
-= pVictim
->GetMeleeCritChanceReduction();
3050 crit
-= pVictim
->GetRangedCritChanceReduction();
3052 // Apply crit chance from defence skill
3053 crit
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
3060 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
3063 if(GetTypeId() == TYPEID_PLAYER
)
3065 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true,true);
3067 // feral or unarmed skill only for base attack
3068 if(attType
!= BASE_ATTACK
&& !item
)
3072 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
3074 // weapon skill or (unarmed for base attack)
3075 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
3077 // in PvP use full skill instead current skill value
3078 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3079 ? ((Player
*)this)->GetMaxSkillValue(skill
)
3080 : ((Player
*)this)->GetSkillValue(skill
);
3081 // Modify value from ratings
3082 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
3085 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
3086 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
3087 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
3091 value
= GetUnitMeleeSkill(target
);
3095 void Unit::_UpdateSpells( uint32 time
)
3097 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
3098 _UpdateAutoRepeatSpell();
3100 // remove finished spells from current pointers
3101 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3103 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
3105 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
3106 m_currentSpells
[i
] = NULL
; // remove pointer
3111 // m_AurasUpdateIterator can be updated in inderect called code at aura remove to skip next planned to update but removed auras
3112 for (m_AurasUpdateIterator
= m_Auras
.begin(); m_AurasUpdateIterator
!= m_Auras
.end();)
3114 Aura
* i_aura
= m_AurasUpdateIterator
->second
;
3115 ++m_AurasUpdateIterator
; // need shift to next for allow update if need into aura update
3116 i_aura
->UpdateAura(time
);
3119 // remove expired auras
3120 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
3124 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
3133 if(!m_gameObj
.empty())
3135 GameObjectList::iterator ite1
, dnext1
;
3136 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
3139 //(*i)->Update( difftime );
3140 if( !(*ite1
)->isSpawned() )
3142 (*ite1
)->SetOwnerGUID(0);
3143 (*ite1
)->SetRespawnTime(0);
3145 dnext1
= m_gameObj
.erase(ite1
);
3153 void Unit::_UpdateAutoRepeatSpell()
3155 //check "realtime" interrupts
3156 if ( (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) )
3158 // cancel wand shoot
3159 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3160 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3161 m_AutoRepeatFirstCast
= true;
3166 if ( m_AutoRepeatFirstCast
&& getAttackTimer(RANGED_ATTACK
) < 500 )
3167 setAttackTimer(RANGED_ATTACK
,500);
3168 m_AutoRepeatFirstCast
= false;
3171 if (isAttackReady(RANGED_ATTACK
))
3173 // Check if able to cast
3174 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CheckCast(true) != SPELL_CAST_OK
)
3176 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3181 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
3182 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
3184 // all went good, reset attack
3185 resetAttackTimer(RANGED_ATTACK
);
3189 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
3191 assert(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
3193 CurrentSpellTypes CSpellType
= pSpell
->GetCurrentContainer();
3195 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
3197 // break same type spell if it is not delayed
3198 InterruptSpell(CSpellType
,false);
3200 // special breakage effects:
3203 case CURRENT_GENERIC_SPELL
:
3205 // generic spells always break channeled not delayed spells
3206 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3208 // autorepeat breaking
3209 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3211 // break autorepeat if not Auto Shot
3212 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3213 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3214 m_AutoRepeatFirstCast
= true;
3218 case CURRENT_CHANNELED_SPELL
:
3220 // channel spells always break generic non-delayed and any channeled spells
3221 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3222 InterruptSpell(CURRENT_CHANNELED_SPELL
);
3224 // it also does break autorepeat if not Auto Shot
3225 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
3226 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3227 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3230 case CURRENT_AUTOREPEAT_SPELL
:
3232 // only Auto Shoot does not break anything
3233 if (pSpell
->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3235 // generic autorepeats break generic non-delayed and channeled non-delayed spells
3236 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3237 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3239 // special action: set first cast flag
3240 m_AutoRepeatFirstCast
= true;
3245 // other spell types don't break anything now
3249 // current spell (if it is still here) may be safely deleted now
3250 if (m_currentSpells
[CSpellType
])
3251 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
3253 // set new current spell
3254 m_currentSpells
[CSpellType
] = pSpell
;
3255 pSpell
->SetReferencedFromCurrent(true);
3257 pSpell
->m_selfContainer
= &(m_currentSpells
[pSpell
->GetCurrentContainer()]);
3260 void Unit::InterruptSpell(CurrentSpellTypes spellType
, bool withDelayed
)
3262 assert(spellType
< CURRENT_MAX_SPELL
);
3264 if (m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
3266 // send autorepeat cancel message for autorepeat spells
3267 if (spellType
== CURRENT_AUTOREPEAT_SPELL
)
3269 if(GetTypeId() == TYPEID_PLAYER
)
3270 ((Player
*)this)->SendAutoRepeatCancel(this);
3273 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
3274 m_currentSpells
[spellType
]->cancel();
3276 // cancel can interrupt spell already (caster cancel ->target aura remove -> caster iterrupt)
3277 if (m_currentSpells
[spellType
])
3279 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
3280 m_currentSpells
[spellType
] = NULL
;
3285 void Unit::FinishSpell(CurrentSpellTypes spellType
, bool ok
/*= true*/)
3287 Spell
* spell
= m_currentSpells
[spellType
];
3291 if (spellType
== CURRENT_CHANNELED_SPELL
)
3292 spell
->SendChannelUpdate(0);
3298 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
3300 // We don't do loop here to explicitly show that melee spell is excluded.
3301 // Maybe later some special spells will be excluded too.
3303 // generic spells are casted when they are not finished and not delayed
3304 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
3305 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3306 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3309 // channeled spells may be delayed, but they are still considered casted
3310 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
3311 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
3314 // autorepeat spells may be finished or delayed, but they are still considered casted
3315 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3321 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
3323 // generic spells are interrupted if they are not finished or delayed
3324 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
3325 InterruptSpell(CURRENT_GENERIC_SPELL
,withDelayed
);
3327 // autorepeat spells are interrupted if they are not finished or delayed
3328 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
3329 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
,withDelayed
);
3331 // channeled spells are interrupted if they are not finished, even if they are delayed
3332 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
3333 InterruptSpell(CURRENT_CHANNELED_SPELL
,true);
3336 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
3338 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3339 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
3340 return m_currentSpells
[i
];
3344 void Unit::SetInFront(Unit
const* target
)
3346 SetOrientation(GetAngle(target
));
3349 void Unit::SetFacingToObject(WorldObject
* pObject
)
3351 // update orientation at server
3352 SetOrientation(GetAngle(pObject
));
3356 BuildHeartBeatMsg(&data
);
3357 SendMessageToSet(&data
, false);
3360 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
3363 return c
->canSwim();
3365 return c
->canWalk() || c
->canFly();
3368 bool Unit::IsInWater() const
3370 return GetBaseMap()->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
3373 bool Unit::IsUnderWater() const
3375 return GetBaseMap()->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3378 void Unit::DeMorph()
3380 SetDisplayId(GetNativeDisplayId());
3383 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3387 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3388 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3389 modifier
+= (*i
)->GetModifier()->m_amount
;
3394 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3396 float multiplier
= 1.0f
;
3398 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3399 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3400 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3405 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3409 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3410 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3411 if ((*i
)->GetModifier()->m_amount
> modifier
)
3412 modifier
= (*i
)->GetModifier()->m_amount
;
3417 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
3421 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3422 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3423 if ((*i
)->GetModifier()->m_amount
< modifier
)
3424 modifier
= (*i
)->GetModifier()->m_amount
;
3429 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3436 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3437 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3439 Modifier
* mod
= (*i
)->GetModifier();
3440 if (mod
->m_miscvalue
& misc_mask
)
3441 modifier
+= mod
->m_amount
;
3446 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3451 float multiplier
= 1.0f
;
3453 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3454 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3456 Modifier
* mod
= (*i
)->GetModifier();
3457 if (mod
->m_miscvalue
& misc_mask
)
3458 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3463 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3470 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3471 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3473 Modifier
* mod
= (*i
)->GetModifier();
3474 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
> modifier
)
3475 modifier
= mod
->m_amount
;
3481 int32
Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3488 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3489 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3491 Modifier
* mod
= (*i
)->GetModifier();
3492 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
< modifier
)
3493 modifier
= mod
->m_amount
;
3499 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3503 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3504 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3506 Modifier
* mod
= (*i
)->GetModifier();
3507 if (mod
->m_miscvalue
== misc_value
)
3508 modifier
+= mod
->m_amount
;
3513 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
3515 float multiplier
= 1.0f
;
3517 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3518 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3520 Modifier
* mod
= (*i
)->GetModifier();
3521 if (mod
->m_miscvalue
== misc_value
)
3522 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3527 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3531 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3532 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3534 Modifier
* mod
= (*i
)->GetModifier();
3535 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
3536 modifier
= mod
->m_amount
;
3542 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3546 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3547 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3549 Modifier
* mod
= (*i
)->GetModifier();
3550 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
< modifier
)
3551 modifier
= mod
->m_amount
;
3557 float Unit::GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype
, uint32 mask
) const
3562 float multiplier
= 1.0f
;
3564 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3565 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3567 Modifier
* mod
= (*i
)->GetModifier();
3568 if (mask
& (1 << (mod
->m_miscvalue
-1)))
3569 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3574 bool Unit::AddAura(Aura
*Aur
)
3576 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
3578 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
3579 if( !isAlive() && !IsDeathPersistentSpell(aurSpellInfo
) &&
3580 !IsDeathOnlySpell(aurSpellInfo
) &&
3581 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
3587 if(Aur
->GetTarget() != this)
3589 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
3590 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
3591 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
3596 // m_auraname can be modified to SPELL_AURA_NONE for area auras, this expected for this value
3597 AuraType aurName
= Aur
->GetModifier()->m_auraname
;
3599 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
3600 AuraMap::iterator i
= m_Auras
.find( spair
);
3602 // take out same spell
3603 if (i
!= m_Auras
.end())
3605 // passive and persistent auras can stack with themselves any number of times
3606 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
3608 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
3610 Aura
* aur2
= i2
->second
;
3611 if(aur2
->GetCasterGUID()==Aur
->GetCasterGUID())
3613 // Aura can stack on self -> Stack it;
3614 if(aurSpellInfo
->StackAmount
)
3616 // can be created with >1 stack by some spell mods
3617 aur2
->modStackAmount(Aur
->GetStackAmount());
3621 // Carry over removed Aura's remaining damage if Aura still has ticks remaining
3622 else if (aur2
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_STACK_DOT_MODIFIER
&& aurName
== SPELL_AURA_PERIODIC_DAMAGE
&& aur2
->GetAuraDuration() > 0)
3624 int32 remainingTicks
= aur2
->GetAuraMaxTicks() - aur2
->GetAuraTicks();
3625 int32 remainingDamage
= aur2
->GetModifier()->m_amount
* remainingTicks
;
3627 Aur
->GetModifier()->m_amount
+= int32(remainingDamage
/ Aur
->GetAuraMaxTicks());
3629 // can be only single (this check done at _each_ aura add
3630 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3636 // m_auraname can be modified to SPELL_AURA_NONE for area auras, use original
3637 AuraType aurNameReal
= AuraType(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()]);
3642 case SPELL_AURA_DUMMY
: // allow stack
3643 case SPELL_AURA_PERIODIC_DAMAGE
:
3644 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
3645 case SPELL_AURA_PERIODIC_LEECH
:
3646 case SPELL_AURA_PERIODIC_HEAL
:
3647 case SPELL_AURA_OBS_MOD_HEALTH
:
3648 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3649 case SPELL_AURA_OBS_MOD_MANA
:
3650 case SPELL_AURA_POWER_BURN_MANA
:
3652 case SPELL_AURA_PERIODIC_ENERGIZE
: // all or self or clear non-stackable
3653 default: // not allow
3654 // can be only single (this check done at _each_ aura add
3655 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3666 // passive auras not stacable with other ranks
3667 if (!IsPassiveSpellStackableWithRanks(aurSpellInfo
))
3669 if (!RemoveNoStackAurasDueToAura(Aur
))
3672 return false; // couldn't remove conflicting aura with higher rank
3676 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
3677 if (Aur
->IsSingleTarget() && Aur
->GetTarget())
3679 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
3682 Unit
* caster
= Aur
->GetCaster();
3683 if(!caster
) // caster deleted and not required adding scAura
3686 bool restart
= false;
3687 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3688 for(AuraList::const_iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
3690 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
3691 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
3693 if ((*itr
)->IsInUse())
3695 sLog
.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for IsSingleTargetSpell", (*itr
)->GetId(), (*itr
)->GetEffIndex(),Aur
->GetId(), Aur
->GetEffIndex());
3698 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
3707 scAuras
.push_back(Aur
);
3713 // add aura, register in lists and arrays
3715 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
3716 if (aurName
< TOTAL_AURAS
)
3718 m_modAuras
[aurName
].push_back(Aur
);
3721 Aur
->ApplyModifier(true,true);
3722 sLog
.outDebug("Aura %u now is in use", aurName
);
3724 // if aura deleted before boosts apply ignore
3725 // this can be possible it it removed indirectly by triggered spell effect at ApplyModifier
3726 if (Aur
->IsDeleted())
3729 if(IsSpellLastAuraEffect(aurSpellInfo
,Aur
->GetEffIndex()))
3730 Aur
->HandleSpellSpecificBoosts(true);
3735 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
3737 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3740 AuraMap::const_iterator i
,next
;
3741 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3745 uint32 i_spellId
= (*i
).second
->GetId();
3746 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
3748 if(sSpellMgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
3750 RemoveAurasDueToSpell(i_spellId
);
3752 if( m_Auras
.empty() )
3755 next
= m_Auras
.begin();
3761 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
3766 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
3770 uint32 spellId
= Aur
->GetId();
3771 uint32 effIndex
= Aur
->GetEffIndex();
3773 // passive spell special case (only non stackable with ranks)
3774 if(IsPassiveSpell(spellId
))
3776 if(IsPassiveSpellStackableWithRanks(spellProto
))
3780 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
3782 AuraMap::iterator i
,next
;
3783 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3787 if (!(*i
).second
) continue;
3789 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
3794 uint32 i_spellId
= i_spellProto
->Id
;
3796 // early checks that spellId is passive non stackable spell
3797 if(IsPassiveSpell(i_spellId
))
3799 // passive non-stackable spells not stackable only for same caster
3800 if(Aur
->GetCasterGUID()!=i
->second
->GetCasterGUID())
3803 // passive non-stackable spells not stackable only with another rank of same spell
3804 if (!sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3808 uint32 i_effIndex
= (*i
).second
->GetEffIndex();
3810 if(i_spellId
== spellId
) continue;
3812 bool is_triggered_by_spell
= false;
3813 // prevent triggering aura of removing aura that triggered it
3814 for(int j
= 0; j
< 3; ++j
)
3815 if (i_spellProto
->EffectTriggerSpell
[j
] == spellId
)
3816 is_triggered_by_spell
= true;
3818 // prevent triggered aura of removing aura that triggering it (triggered effect early some aura of parent spell
3819 for(int j
= 0; j
< 3; ++j
)
3820 if (spellProto
->EffectTriggerSpell
[j
] == i_spellId
)
3821 is_triggered_by_spell
= true;
3823 if (is_triggered_by_spell
)
3826 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
3828 // single allowed spell specific from same caster or from any caster at target
3829 bool is_spellSpecPerTargetPerCaster
= IsSingleFromSpellSpecificPerTargetPerCaster(spellId_spec
,i_spellId_spec
);
3830 bool is_spellSpecPerTarget
= IsSingleFromSpellSpecificPerTarget(spellId_spec
,i_spellId_spec
);
3831 if( is_spellSpecPerTarget
|| is_spellSpecPerTargetPerCaster
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
3833 // cannot remove higher rank
3834 if (sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3835 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3838 // Its a parent aura (create this aura in ApplyModifier)
3839 if ((*i
).second
->IsInUse())
3841 sLog
.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i
->second
->GetId(), i
->second
->GetEffIndex(),Aur
->GetId(), Aur
->GetEffIndex());
3844 RemoveAurasDueToSpell(i_spellId
);
3846 if( m_Auras
.empty() )
3849 next
= m_Auras
.begin();
3854 // spell with spell specific that allow single ranks for spell from diff caster
3855 // same caster case processed or early or later
3856 bool is_spellPerTarget
= IsSingleFromSpellSpecificSpellRanksPerTarget(spellId_spec
,i_spellId_spec
);
3857 if ( is_spellPerTarget
&& Aur
->GetCasterGUID() != (*i
).second
->GetCasterGUID() && sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3859 // cannot remove higher rank
3860 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3863 // Its a parent aura (create this aura in ApplyModifier)
3864 if ((*i
).second
->IsInUse())
3866 sLog
.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i
->second
->GetId(), i
->second
->GetEffIndex(),Aur
->GetId(), Aur
->GetEffIndex());
3869 RemoveAurasDueToSpell(i_spellId
);
3871 if( m_Auras
.empty() )
3874 next
= m_Auras
.begin();
3879 // non single (per caster) per target spell specific (possible single spell per target at caster)
3880 if( !is_spellSpecPerTargetPerCaster
&& !is_spellSpecPerTarget
&& sSpellMgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
3882 // Its a parent aura (create this aura in ApplyModifier)
3883 if ((*i
).second
->IsInUse())
3885 sLog
.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i
->second
->GetId(), i
->second
->GetEffIndex(),Aur
->GetId(), Aur
->GetEffIndex());
3888 RemoveAurasDueToSpell(i_spellId
);
3890 if( m_Auras
.empty() )
3893 next
= m_Auras
.begin();
3898 // Potions stack aura by aura (elixirs/flask already checked)
3899 if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
3901 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
3903 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3904 return false; // cannot remove higher rank
3906 // Its a parent aura (create this aura in ApplyModifier)
3907 if ((*i
).second
->IsInUse())
3909 sLog
.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i
->second
->GetId(), i
->second
->GetEffIndex(),Aur
->GetId(), Aur
->GetEffIndex());
3920 void Unit::RemoveAura(uint32 spellId
, uint32 effindex
, Aura
* except
)
3922 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
3923 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
3925 if(iter
->second
!=except
)
3928 iter
= m_Auras
.lower_bound(spair
);
3935 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
)
3937 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3939 Aura
*aur
= iter
->second
;
3940 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3947 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint32 effindex
, uint64 casterGUID
)
3949 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
3950 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
3952 Aura
*aur
= iter
->second
;
3953 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3956 iter
= m_Auras
.lower_bound(spair
);
3963 void Unit::RemoveSingleAuraDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
3965 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(spellId
);
3967 // Custom dispel cases
3968 // Unstable Affliction
3969 if(spellEntry
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x010000000000)))
3971 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
,SPELLFAMILY_WARLOCK
,UI64LIT(0x010000000000),0x00000000,casterGUID
))
3973 int32 damage
= dotAura
->GetModifier()->m_amount
*9;
3975 // Remove spell auras from stack
3976 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
3978 // backfire damage and silence
3979 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,casterGUID
);
3984 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x10000000)))
3986 Unit
* caster
= NULL
;
3987 uint32 triggeredSpell
= 0;
3989 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x10000000), 0x00000000, casterGUID
))
3990 caster
= dotAura
->GetCaster();
3992 if (caster
&& !caster
->isDead())
3994 Unit::AuraList
const& auras
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
3995 for (Unit::AuraList::const_iterator i
= auras
.begin(); i
!= auras
.end(); ++i
)
3997 switch((*i
)->GetId())
3999 case 51480: triggeredSpell
=64694; break;// Lava Flows, Rank 1
4000 case 51481: triggeredSpell
=65263; break;// Lava Flows, Rank 2
4001 case 51482: triggeredSpell
=65264; break;// Lava Flows, Rank 3
4008 // Remove spell auras from stack
4009 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4013 caster
->CastSpell(caster
, triggeredSpell
, true);
4016 // Vampiric touch (first dummy aura)
4017 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_PRIEST
&& spellEntry
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
4019 if (Aura
*dot
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000040000000000), 0x00000000, casterGUID
))
4021 if(Unit
* caster
= dot
->GetCaster())
4023 int32 bp0
= dot
->GetModifier()->m_amount
;
4024 bp0
= 8 * caster
->SpellDamageBonus(this, spellEntry
, bp0
, DOT
, 1);
4026 // Remove spell auras from stack
4027 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4029 CastCustomSpell(this, 64085, &bp0
, NULL
, NULL
, true, NULL
, NULL
, casterGUID
);
4035 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4038 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
4040 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4042 Aura
*aur
= iter
->second
;
4043 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4045 int32 basePoints
= aur
->GetBasePoints();
4046 // construct the new aura for the attacker - will never return NULL, it's just a wrapper for
4047 // some different constructors
4048 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
, this);
4050 // set its duration and maximum duration
4051 // max duration 2 minutes (in msecs)
4052 int32 dur
= aur
->GetAuraDuration();
4053 const int32 max_dur
= 2*MINUTE
*IN_MILISECONDS
;
4054 new_aur
->SetAuraMaxDuration( max_dur
> dur
? dur
: max_dur
);
4055 new_aur
->SetAuraDuration( max_dur
> dur
? dur
: max_dur
);
4057 // Unregister _before_ adding to stealer
4058 aur
->UnregisterSingleCastAura();
4060 // strange but intended behaviour: Stolen single target auras won't be treated as single targeted
4061 new_aur
->SetIsSingleTarget(false);
4063 // add the new aura to stealer
4064 stealer
->AddAura(new_aur
);
4066 // Remove aura as dispel
4067 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
4074 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
4076 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4078 if (iter
->second
->GetId() == spellId
)
4079 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
4085 void Unit::RemoveAurasWithDispelType( DispelType type
)
4087 // Create dispel mask by dispel type
4088 uint32 dispelMask
= GetDispellMask(type
);
4089 // Dispel all existing auras vs current dispel type
4090 AuraMap
& auras
= GetAuras();
4091 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
4093 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
4094 if( (1<<spell
->Dispel
) & dispelMask
)
4097 RemoveAurasDueToSpell(spell
->Id
);
4098 itr
= auras
.begin();
4105 void Unit::RemoveSingleAuraFromStack(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4107 if (i
->second
->modStackAmount(-1))
4112 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, uint32 effindex
, AuraRemoveMode mode
)
4114 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4115 if(iter
!= m_Auras
.end())
4116 RemoveSingleAuraFromStack(iter
,mode
);
4119 void Unit::RemoveSingleSpellAurasFromStack(uint32 spellId
, AuraRemoveMode mode
)
4121 for (int i
=0; i
<3; ++i
)
4122 RemoveSingleAuraFromStack(spellId
, i
, mode
);
4125 void Unit::RemoveSingleSpellAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
, AuraRemoveMode mode
)
4127 for (int i
=0; i
<3; ++i
)
4128 RemoveSingleAuraByCasterSpell(spellId
, i
, casterGUID
, mode
);
4131 void Unit::RemoveSingleAuraByCasterSpell(uint32 spellId
, uint32 effindex
, uint64 casterGUID
, AuraRemoveMode mode
)
4133 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4134 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
); ++iter
)
4136 Aura
*aur
= iter
->second
;
4137 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4139 RemoveSingleAuraFromStack(iter
,mode
);
4146 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
)
4148 for (int i
= 0; i
< 3; ++i
)
4149 RemoveAura(spellId
,i
,except
);
4152 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
4154 for (int k
=0; k
< 3; ++k
)
4156 spellEffectPair spair
= spellEffectPair(spellId
, k
);
4157 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4159 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
4162 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
4170 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
4172 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4174 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
4181 void Unit::RemoveNotOwnSingleTargetAuras(uint32 newPhase
)
4183 // single target auras from other casters
4184 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4186 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
4192 Unit
* caster
= iter
->second
->GetCaster();
4193 if(!caster
|| !caster
->InSamePhase(newPhase
))
4203 // single target auras at other targets
4204 AuraList
& scAuras
= GetSingleCastAuras();
4205 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
4208 if (aura
->GetTarget() != this && !aura
->GetTarget()->InSamePhase(newPhase
))
4210 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
4211 aura
->GetTarget()->RemoveAura(aura
);
4212 iter
= scAuras
.begin();
4220 void Unit::RemoveAura(Aura
* aura
, AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4222 AuraMap::iterator i
= m_Auras
.lower_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4223 AuraMap::iterator upperBound
= m_Auras
.upper_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4224 for (; i
!= upperBound
; ++i
)
4226 if (i
->second
== aura
)
4232 sLog
.outDebug("Trying to remove aura id %u effect %u by pointer but aura not found on target", aura
->GetId(), aura
->GetEffIndex());
4235 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4237 Aura
* Aur
= i
->second
;
4238 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
4240 Aur
->UnregisterSingleCastAura();
4242 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
4243 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
4245 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
4249 Aur
->SetRemoveMode(mode
);
4251 // if unit currently update aura list then make safe update iterator shift to next
4252 if (m_AurasUpdateIterator
== i
)
4253 ++m_AurasUpdateIterator
;
4255 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
4256 // remove aura from list before to prevent deleting it before
4259 // now aura removed from from list and can't be deleted by indirect call but can be referenced from callers
4261 // Statue unsummoned at aura remove
4262 Totem
* statue
= NULL
;
4263 if(IsChanneledSpell(AurSpellInfo
))
4264 if(Unit
* caster
= Aur
->GetCaster())
4265 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
4266 statue
= ((Totem
*)caster
);
4268 sLog
.outDebug("Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
4269 if (mode
!= AURA_REMOVE_BY_DELETE
) // not unapply if target will deleted
4270 Aur
->ApplyModifier(false,true);
4272 if (Aur
->_RemoveAura())
4274 // last aura in stack removed
4275 if (mode
!= AURA_REMOVE_BY_DELETE
&& IsSpellLastAuraEffect(Aur
->GetSpellProto(),Aur
->GetEffIndex()))
4276 Aur
->HandleSpellSpecificBoosts(false);
4279 // If aura in use (removed from code that plan access to it data after return)
4280 // store it in aura list with delayed deletion
4282 m_deletedAuras
.push_back(Aur
);
4289 // only way correctly remove all auras from list
4290 if( m_Auras
.empty() )
4293 i
= m_Auras
.begin();
4297 void Unit::RemoveAllAuras(AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4299 while (!m_Auras
.empty())
4301 AuraMap::iterator iter
= m_Auras
.begin();
4302 RemoveAura(iter
,mode
);
4306 void Unit::RemoveArenaAuras(bool onleave
)
4308 // in join, remove positive buffs, on end, remove negative
4309 // used to remove positive visible auras in arenas
4310 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4312 if (!(iter
->second
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_UNK21
) &&
4313 // don't remove stances, shadowform, pally/hunter auras
4314 !iter
->second
->IsPassive() && // don't remove passive auras
4315 (!(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
) ||
4316 !(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNK8
)) &&
4317 // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable)
4318 (iter
->second
->IsPositive() != onleave
)) // remove positive buffs on enter, negative buffs on leave
4325 void Unit::RemoveAllAurasOnDeath()
4327 // used just after dieing to remove all visible auras
4328 // and disable the mods for the passive ones
4329 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4331 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
4332 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
4338 void Unit::DelayAura(uint32 spellId
, uint32 effindex
, int32 delaytime
)
4340 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4341 if (iter
!= m_Auras
.end())
4343 if (iter
->second
->GetAuraDuration() < delaytime
)
4344 iter
->second
->SetAuraDuration(0);
4346 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
4347 iter
->second
->SendAuraUpdate(false);
4348 sLog
.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter
->second
->GetModifier()->m_auraname
, GetGUIDLow(), iter
->second
->GetAuraDuration());
4352 void Unit::_RemoveAllAuraMods()
4354 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4356 (*i
).second
->ApplyModifier(false);
4360 void Unit::_ApplyAllAuraMods()
4362 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4364 (*i
).second
->ApplyModifier(true);
4368 Aura
* Unit::GetAura(uint32 spellId
, uint32 effindex
)
4370 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4371 if (iter
!= m_Auras
.end())
4372 return iter
->second
;
4376 Aura
* Unit::GetAura(AuraType type
, uint32 family
, uint64 familyFlag
, uint32 familyFlag2
, uint64 casterGUID
)
4378 AuraList
const& auras
= GetAurasByType(type
);
4379 for(AuraList::const_iterator i
= auras
.begin();i
!= auras
.end(); ++i
)
4381 SpellEntry
const *spell
= (*i
)->GetSpellProto();
4382 if (spell
->SpellFamilyName
== family
&& (spell
->SpellFamilyFlags
& familyFlag
|| spell
->SpellFamilyFlags2
& familyFlag2
))
4384 if (casterGUID
&& (*i
)->GetCasterGUID()!=casterGUID
)
4392 bool Unit::HasAura(uint32 spellId
) const
4394 for (int i
= 0; i
< 3 ; ++i
)
4396 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, i
));
4397 if (iter
!= m_Auras
.end())
4403 void Unit::AddDynObject(DynamicObject
* dynObj
)
4405 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
4408 void Unit::RemoveDynObject(uint32 spellid
)
4410 if(m_dynObjGUIDs
.empty())
4412 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4414 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4417 i
= m_dynObjGUIDs
.erase(i
);
4419 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
4422 i
= m_dynObjGUIDs
.erase(i
);
4429 void Unit::RemoveAllDynObjects()
4431 while(!m_dynObjGUIDs
.empty())
4433 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*m_dynObjGUIDs
.begin());
4436 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
4440 DynamicObject
* Unit::GetDynObject(uint32 spellId
, uint32 effIndex
)
4442 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4444 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4447 i
= m_dynObjGUIDs
.erase(i
);
4451 if (dynObj
->GetSpellId() == spellId
&& dynObj
->GetEffIndex() == effIndex
)
4458 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
4460 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4462 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4465 i
= m_dynObjGUIDs
.erase(i
);
4469 if (dynObj
->GetSpellId() == spellId
)
4476 GameObject
* Unit::GetGameObject(uint32 spellId
) const
4478 for (GameObjectList::const_iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); ++i
)
4479 if ((*i
)->GetSpellId() == spellId
)
4485 void Unit::AddGameObject(GameObject
* gameObj
)
4487 assert(gameObj
&& gameObj
->GetOwnerGUID()==0);
4488 m_gameObj
.push_back(gameObj
);
4489 gameObj
->SetOwnerGUID(GetGUID());
4491 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
4493 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
4494 // Need disable spell use for owner
4495 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4496 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4497 ((Player
*)this)->AddSpellAndCategoryCooldowns(createBySpell
,0,NULL
,true);
4501 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
4503 assert(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
4505 gameObj
->SetOwnerGUID(0);
4507 // GO created by some spell
4508 if (uint32 spellid
= gameObj
->GetSpellId())
4510 RemoveAurasDueToSpell(spellid
);
4512 if (GetTypeId()==TYPEID_PLAYER
)
4514 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(spellid
);
4515 // Need activate spell use for owner
4516 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4517 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4518 ((Player
*)this)->SendCooldownEvent(createBySpell
);
4522 m_gameObj
.remove(gameObj
);
4526 gameObj
->SetRespawnTime(0);
4531 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
4533 if(m_gameObj
.empty())
4535 GameObjectList::iterator i
, next
;
4536 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
4539 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
4541 (*i
)->SetOwnerGUID(0);
4544 (*i
)->SetRespawnTime(0);
4548 next
= m_gameObj
.erase(i
);
4555 void Unit::RemoveAllGameObjects()
4557 // remove references to unit
4558 for(GameObjectList::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4560 (*i
)->SetOwnerGUID(0);
4561 (*i
)->SetRespawnTime(0);
4563 i
= m_gameObj
.erase(i
);
4567 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
4569 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+4+1+4+4+1+1+4+4+1)); // we guess size
4570 data
.append(log
->target
->GetPackGUID());
4571 data
.append(log
->attacker
->GetPackGUID());
4572 data
<< uint32(log
->SpellID
);
4573 data
<< uint32(log
->damage
); // damage amount
4574 data
<< uint32(log
->overkill
); // overkill
4575 data
<< uint8 (log
->schoolMask
); // damage school
4576 data
<< uint32(log
->absorb
); // AbsorbedDamage
4577 data
<< uint32(log
->resist
); // resist
4578 data
<< uint8 (log
->physicalLog
); // if 1, then client show spell name (example: %s's ranged shot hit %s for %u school or %s suffers %u school damage from %s's spell_name
4579 data
<< uint8 (log
->unused
); // unused
4580 data
<< uint32(log
->blocked
); // blocked
4581 data
<< uint32(log
->HitInfo
);
4582 data
<< uint8 (0); // flag to use extend data
4583 SendMessageToSet( &data
, true );
4586 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
, uint32 SpellID
, uint32 Damage
, SpellSchoolMask damageSchoolMask
, uint32 AbsorbedDamage
, uint32 Resist
, bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
4588 SpellNonMeleeDamage
log(this, target
, SpellID
, damageSchoolMask
);
4589 log
.damage
= Damage
- AbsorbedDamage
- Resist
- Blocked
;
4590 log
.absorb
= AbsorbedDamage
;
4591 log
.resist
= Resist
;
4592 log
.physicalLog
= PhysicalDamage
;
4593 log
.blocked
= Blocked
;
4594 log
.HitInfo
= SPELL_HIT_TYPE_UNK1
| SPELL_HIT_TYPE_UNK3
| SPELL_HIT_TYPE_UNK6
;
4596 log
.HitInfo
|= SPELL_HIT_TYPE_CRIT
;
4597 SendSpellNonMeleeDamageLog(&log
);
4600 void Unit::SendPeriodicAuraLog(SpellPeriodicAuraLogInfo
*pInfo
)
4602 Aura
*aura
= pInfo
->aura
;
4603 Modifier
*mod
= aura
->GetModifier();
4605 WorldPacket
data(SMSG_PERIODICAURALOG
, 30);
4606 data
.append(aura
->GetTarget()->GetPackGUID());
4607 data
.appendPackGUID(aura
->GetCasterGUID());
4608 data
<< uint32(aura
->GetId()); // spellId
4609 data
<< uint32(1); // count
4610 data
<< uint32(mod
->m_auraname
); // auraId
4611 switch(mod
->m_auraname
)
4613 case SPELL_AURA_PERIODIC_DAMAGE
:
4614 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
4615 data
<< uint32(pInfo
->damage
); // damage
4616 data
<< uint32(pInfo
->overDamage
); // overkill?
4617 data
<< uint32(GetSpellSchoolMask(aura
->GetSpellProto()));
4618 data
<< uint32(pInfo
->absorb
); // absorb
4619 data
<< uint32(pInfo
->resist
); // resist
4620 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4622 case SPELL_AURA_PERIODIC_HEAL
:
4623 case SPELL_AURA_OBS_MOD_HEALTH
:
4624 data
<< uint32(pInfo
->damage
); // damage
4625 data
<< uint32(pInfo
->overDamage
); // overheal?
4626 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4628 case SPELL_AURA_OBS_MOD_MANA
:
4629 case SPELL_AURA_PERIODIC_ENERGIZE
:
4630 data
<< uint32(mod
->m_miscvalue
); // power type
4631 data
<< uint32(pInfo
->damage
); // damage
4633 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4634 data
<< uint32(mod
->m_miscvalue
); // power type
4635 data
<< uint32(pInfo
->damage
); // amount
4636 data
<< float(pInfo
->multiplier
); // gain multiplier
4639 sLog
.outError("Unit::SendPeriodicAuraLog: unknown aura %u", uint32(mod
->m_auraname
));
4643 aura
->GetTarget()->SendMessageToSet(&data
, true);
4646 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
4648 // Not much to do if no flags are set.
4650 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
4651 // Now go on with a victim's events'n'auras
4652 // Not much to do if no flags are set or there is no victim
4653 if(pVictim
&& pVictim
->isAlive() && procVictim
)
4654 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4657 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4659 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4660 data
<< uint32(spellID
);
4661 data
<< uint64(GetGUID());
4662 data
<< uint8(0); // can be 0 or 1
4663 data
<< uint32(1); // target count
4664 // for(i = 0; i < target count; ++i)
4665 data
<< uint64(target
->GetGUID()); // target GUID
4666 data
<< uint8(missInfo
);
4668 SendMessageToSet(&data
, true);
4671 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4673 sLog
.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4676 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, 16 + 45); // we guess size
4677 data
<< uint32(damageInfo
->HitInfo
);
4678 data
.append(damageInfo
->attacker
->GetPackGUID());
4679 data
.append(damageInfo
->target
->GetPackGUID());
4680 data
<< uint32(damageInfo
->damage
); // Full damage
4681 data
<< uint32(0); // overkill value
4682 data
<< uint8(count
); // Sub damage count
4684 for(int i
= 0; i
< count
; ++i
)
4686 data
<< uint32(damageInfo
->damageSchoolMask
); // School of sub damage
4687 data
<< float(damageInfo
->damage
); // sub damage
4688 data
<< uint32(damageInfo
->damage
); // Sub Damage
4691 if(damageInfo
->HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4693 for(int i
= 0; i
< count
; ++i
)
4694 data
<< uint32(damageInfo
->absorb
); // Absorb
4697 if(damageInfo
->HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4699 for(int i
= 0; i
< count
; ++i
)
4700 data
<< uint32(damageInfo
->resist
); // Resist
4703 data
<< uint8(damageInfo
->TargetState
);
4707 if(damageInfo
->HitInfo
& HITINFO_BLOCK
)
4708 data
<< uint32(damageInfo
->blocked_amount
);
4710 if(damageInfo
->HitInfo
& HITINFO_UNK3
)
4713 if(damageInfo
->HitInfo
& HITINFO_UNK1
)
4724 for(uint8 i
= 0; i
< 5; ++i
)
4732 SendMessageToSet( &data
, true );
4735 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8 SwingType
, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4737 CalcDamageInfo dmgInfo
;
4738 dmgInfo
.HitInfo
= HitInfo
;
4739 dmgInfo
.attacker
= this;
4740 dmgInfo
.target
= target
;
4741 dmgInfo
.damage
= Damage
- AbsorbDamage
- Resist
- BlockedAmount
;
4742 dmgInfo
.damageSchoolMask
= damageSchoolMask
;
4743 dmgInfo
.absorb
= AbsorbDamage
;
4744 dmgInfo
.resist
= Resist
;
4745 dmgInfo
.TargetState
= TargetState
;
4746 dmgInfo
.blocked_amount
= BlockedAmount
;
4747 SendAttackStateUpdate(&dmgInfo
);
4750 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4752 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
4754 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4755 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4757 uint32 triggered_spell_id
= 0;
4758 Unit
* target
= pVictim
;
4759 int32 basepoints0
= 0;
4761 switch(hasteSpell
->SpellFamilyName
)
4763 case SPELLFAMILY_ROGUE
:
4765 switch(hasteSpell
->Id
)
4771 target
= SelectNearbyTarget(pVictim
);
4774 basepoints0
= damage
;
4775 triggered_spell_id
= 22482;
4783 // processed charge only counting case
4784 if(!triggered_spell_id
)
4787 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
4791 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
4796 if(!target
|| target
!=this && !target
->isAlive())
4799 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
4803 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4805 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
4807 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
4808 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
4813 bool Unit::HandleSpellCritChanceAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4815 SpellEntry
const *triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
4817 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4818 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4820 uint32 triggered_spell_id
= 0;
4821 Unit
* target
= pVictim
;
4822 int32 basepoints0
= 0;
4824 switch(triggeredByAuraSpell
->SpellFamilyName
)
4826 case SPELLFAMILY_MAGE
:
4828 switch(triggeredByAuraSpell
->Id
)
4833 Unit
* caster
= triggeredByAura
->GetCaster();
4837 triggered_spell_id
= 54648;
4845 // processed charge only counting case
4846 if(!triggered_spell_id
)
4849 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
4853 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",triggeredByAuraSpell
->Id
,triggered_spell_id
);
4858 if(!target
|| target
!=this && !target
->isAlive())
4861 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
4865 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4867 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
4869 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
4870 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
4875 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
4877 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
4878 uint32 effIndex
= triggeredByAura
->GetEffIndex();
4879 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
4881 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4882 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4884 uint32 triggered_spell_id
= 0;
4885 Unit
* target
= pVictim
;
4886 int32 basepoints0
= 0;
4888 switch(dummySpell
->SpellFamilyName
)
4890 case SPELLFAMILY_GENERIC
:
4892 switch (dummySpell
->Id
)
4898 // return damage % to attacker but < 50% own total health
4899 basepoints0
= triggerAmount
*int32(damage
)/100;
4900 if(basepoints0
> GetMaxHealth()/2)
4901 basepoints0
= GetMaxHealth()/2;
4903 triggered_spell_id
= 25997;
4906 // Sweeping Strikes (NPC spells may be)
4910 // prevent chain of triggered spell from same triggered spell
4911 if(procSpell
&& procSpell
->Id
== 26654)
4914 target
= SelectNearbyTarget(pVictim
);
4918 triggered_spell_id
= 26654;
4921 // Twisted Reflection (boss spell)
4923 triggered_spell_id
= 21064;
4928 if (!procSpell
|| procSpell
->Id
== 24659)
4930 // Need remove one 24659 aura
4931 RemoveSingleSpellAurasFromStack(24659);
4934 // Restless Strength
4937 // Need remove one 24662 aura
4938 RemoveSingleSpellAurasFromStack(24662);
4941 // Adaptive Warding (Frostfire Regalia set)
4949 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
4950 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
4952 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
4954 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& UI64LIT(0x10000000)))
4964 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
4966 case SPELL_SCHOOL_NORMAL
:
4967 case SPELL_SCHOOL_HOLY
:
4968 return false; // ignored
4969 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
4970 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
4971 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
4972 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
4973 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
4981 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
4987 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
4989 case SPELL_SCHOOL_NORMAL
:
4990 return false; // ignore
4991 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
4992 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
4993 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
4994 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
4995 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
4996 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
5004 // Mana Leech (Passive) (Priest Pet Aura)
5008 target
= GetOwner();
5012 triggered_spell_id
= 34650;
5020 if (!roll_chance_i(triggerAmount
))
5023 // Remove any stun effect on target
5024 AuraMap
& Auras
= pVictim
->GetAuras();
5025 for(AuraMap::const_iterator iter
= Auras
.begin(); iter
!= Auras
.end();)
5027 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
5028 if( spell
->Mechanic
== MECHANIC_STUN
||
5029 spell
->EffectMechanic
[iter
->second
->GetEffIndex()] == MECHANIC_STUN
)
5031 pVictim
->RemoveAurasDueToSpell(spell
->Id
);
5032 iter
= Auras
.begin();
5042 // Cast finish spell at last charge
5043 if (triggeredByAura
->GetAuraCharges() > 1)
5047 triggered_spell_id
= 33494;
5050 // Vampiric Aura (boss spell)
5053 basepoints0
= 3 * damage
; // 300%
5054 if (basepoints0
< 0)
5057 triggered_spell_id
= 31285;
5061 // Aura of Madness (Darkmoon Card: Madness trinket)
5062 //=====================================================
5063 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
5064 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
5065 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
5066 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5067 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
5068 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
5069 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
5070 // 41011 Martyr Complex: +35 stamina (All classes)
5071 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5072 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5075 if(GetTypeId() != TYPEID_PLAYER
)
5078 // Select class defined buff
5081 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5082 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5084 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
5085 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5088 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
5089 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
5091 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
5092 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5095 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
5096 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
5097 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
5098 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
5100 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
5101 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5104 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
5106 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
5107 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5115 if (roll_chance_i(10))
5116 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
5119 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
5120 // cast 45479 Light's Wrath if Exalted by Aldor
5121 // cast 45429 Arcane Bolt if Exalted by Scryers
5124 if(GetTypeId() != TYPEID_PLAYER
)
5127 // Get Aldor reputation rank
5128 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5131 triggered_spell_id
= 45479;
5134 // Get Scryers reputation rank
5135 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5137 // triggered at positive/self casts also, current attack target used then
5138 if(IsFriendlyTo(target
))
5140 target
= getVictim();
5143 uint64 selected_guid
= ((Player
*)this)->GetSelection();
5144 target
= ObjectAccessor::GetUnit(*this,selected_guid
);
5148 if(IsFriendlyTo(target
))
5152 triggered_spell_id
= 45429;
5157 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
5158 // cast 45480 Light's Strength if Exalted by Aldor
5159 // cast 45428 Arcane Strike if Exalted by Scryers
5162 if(GetTypeId() != TYPEID_PLAYER
)
5165 // Get Aldor reputation rank
5166 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5169 triggered_spell_id
= 45480;
5172 // Get Scryers reputation rank
5173 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5175 triggered_spell_id
= 45428;
5180 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
5181 // cast 45431 Arcane Insight if Exalted by Aldor
5182 // cast 45432 Light's Ward if Exalted by Scryers
5185 if(GetTypeId() != TYPEID_PLAYER
)
5188 // Get Aldor reputation rank
5189 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5192 triggered_spell_id
= 45432;
5195 // Get Scryers reputation rank
5196 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5199 triggered_spell_id
= 45431;
5204 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
5205 // cast 45478 Light's Salvation if Exalted by Aldor
5206 // cast 45430 Arcane Surge if Exalted by Scryers
5209 if(GetTypeId() != TYPEID_PLAYER
)
5212 // Get Aldor reputation rank
5213 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5216 triggered_spell_id
= 45478;
5219 // Get Scryers reputation rank
5220 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5222 triggered_spell_id
= 45430;
5228 // Sunwell Exalted Caster Neck (??? neck)
5229 // cast ??? Light's Wrath if Exalted by Aldor
5230 // cast ??? Arcane Bolt if Exalted by Scryers*/
5232 return false; // old unused version
5236 triggered_spell_id
= 48503;
5237 basepoints0
= triggerAmount
;
5241 // Vampiric Touch (generic, used by some boss)
5245 triggered_spell_id
= 52724;
5246 basepoints0
= damage
/ 2;
5250 // Shadowfiend Death (Gain mana if pet dies with Glyph of Shadowfiend)
5253 Unit
*owner
= GetOwner();
5254 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
5257 // Glyph of Shadowfiend (need cast as self cast for owner, no hidden cooldown)
5258 owner
->CastSpell(owner
,58227,true,castItem
,triggeredByAura
);
5261 // Glyph of Life Tap
5263 triggered_spell_id
= 63321;
5268 case SPELLFAMILY_MAGE
:
5271 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
5273 if (getPowerType() != POWER_MANA
)
5277 basepoints0
= (triggerAmount
* GetMaxPower(POWER_MANA
) / 100);
5279 triggered_spell_id
= 29442;
5282 // Master of Elements
5283 if (dummySpell
->SpellIconID
== 1920)
5289 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5290 basepoints0
= cost
* triggerAmount
/100;
5291 if( basepoints0
<=0 )
5295 triggered_spell_id
= 29077;
5300 if (dummySpell
->SpellIconID
== 2120)
5306 switch (dummySpell
->Id
)
5308 case 31571: triggered_spell_id
= 57529; break;
5309 case 31572: triggered_spell_id
= 57531; break;
5311 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u",dummySpell
->Id
);
5318 if (dummySpell
->SpellIconID
== 2999)
5322 Aura
*counter
= GetAura(triggeredByAura
->GetId(), 1);
5326 // Count spell criticals in a row in second aura
5327 Modifier
*mod
= counter
->GetModifier();
5328 if (procEx
& PROC_EX_CRITICAL_HIT
)
5331 if (mod
->m_amount
< 100) // not enough
5333 // Crititcal counted -> roll chance
5334 if (roll_chance_i(triggerAmount
))
5335 CastSpell(this, 48108, true, castItem
, triggeredByAura
);
5341 if (dummySpell
->SpellIconID
== 2998)
5346 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5347 basepoints0
= cost
* triggerAmount
/100;
5348 if( basepoints0
<=0 )
5350 triggered_spell_id
= 44450;
5354 // Incanter's Regalia set (add trigger chance to Mana Shield)
5355 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5357 if(GetTypeId() != TYPEID_PLAYER
)
5361 triggered_spell_id
= 37436;
5364 switch(dummySpell
->Id
)
5373 switch (dummySpell
->Id
)
5375 case 11119: basepoints0
= int32(0.04f
*damage
); break;
5376 case 11120: basepoints0
= int32(0.08f
*damage
); break;
5377 case 12846: basepoints0
= int32(0.12f
*damage
); break;
5378 case 12847: basepoints0
= int32(0.16f
*damage
); break;
5379 case 12848: basepoints0
= int32(0.20f
*damage
); break;
5381 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
5385 triggered_spell_id
= 12654;
5391 //last charge and crit
5392 if (triggeredByAura
->GetAuraCharges() <= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
5394 RemoveAurasDueToSpell(28682); //-> remove Combustion auras
5395 return true; // charge counting (will removed)
5398 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
5399 return (procEx
& PROC_EX_CRITICAL_HIT
); // charge update only at crit hits, no hidden cooldowns
5401 // Glyph of Ice Block
5404 if (GetTypeId() != TYPEID_PLAYER
)
5407 // not 100% safe with client version switches but for 3.1.3 no spells with cooldown that can have mage player except Frost Nova.
5408 ((Player
*)this)->RemoveSpellCategoryCooldown(35, true);
5411 // Glyph of Polymorph
5414 if (!pVictim
|| !pVictim
->isAlive())
5417 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE
);
5418 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE_PERCENT
);
5424 case SPELLFAMILY_WARRIOR
:
5427 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0000000800000000))
5429 // check attack comes not from behind
5430 if (!HasInArc(M_PI
, pVictim
))
5433 triggered_spell_id
= 22858;
5437 if (dummySpell
->SpellIconID
== 1697)
5439 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
5440 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
5442 // Need stun or root mechanic
5443 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_STUN_MASK
))
5446 switch (dummySpell
->Id
)
5448 case 29838: triggered_spell_id
=29842; break;
5449 case 29834: triggered_spell_id
=29841; break;
5450 case 42770: triggered_spell_id
=42771; break;
5452 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
5460 if (dummySpell
->SpellIconID
== 3214)
5462 triggered_spell_id
= 59653;
5463 basepoints0
= GetShieldBlockValue() * triggerAmount
/ 100;
5468 if (dummySpell
->Id
== 12328)
5470 // prevent chain of triggered spell from same triggered spell
5471 if(procSpell
&& procSpell
->Id
== 26654)
5474 target
= SelectNearbyTarget(pVictim
);
5478 triggered_spell_id
= 26654;
5483 case SPELLFAMILY_WARLOCK
:
5485 // Seed of Corruption
5486 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
5488 Modifier
* mod
= triggeredByAura
->GetModifier();
5489 // if damage is more than need or target die from damage deal finish spell
5490 if( mod
->m_amount
<= damage
|| GetHealth() <= damage
)
5492 // remember guid before aura delete
5493 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5495 // Remove aura (before cast for prevent infinite loop handlers)
5496 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5498 // Cast finish spell (triggeredByAura already not exist!)
5499 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
5500 return true; // no hidden cooldown
5504 mod
->m_amount
-=damage
;
5507 // Seed of Corruption (Mobs cast) - no die req
5508 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0) && dummySpell
->SpellIconID
== 1932)
5510 Modifier
* mod
= triggeredByAura
->GetModifier();
5511 // if damage is more than need deal finish spell
5512 if( mod
->m_amount
<= damage
)
5514 // remember guid before aura delete
5515 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5517 // Remove aura (before cast for prevent infinite loop handlers)
5518 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5520 // Cast finish spell (triggeredByAura already not exist!)
5521 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
5522 return true; // no hidden cooldown
5525 mod
->m_amount
-=damage
;
5529 if (dummySpell
->SpellIconID
== 3222)
5534 basepoints0
= damage
* triggerAmount
/ 100;
5535 triggered_spell_id
= 54181;
5538 switch(dummySpell
->Id
)
5540 // Nightfall & Glyph of Corruption
5546 triggered_spell_id
= 17941;
5555 basepoints0
= int32(damage
*triggerAmount
/100);
5557 triggered_spell_id
= 30294;
5560 // Shadowflame (Voidheart Raiment set bonus)
5563 triggered_spell_id
= 37379;
5566 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
5574 basepoints0
= damage
* triggerAmount
/100;
5575 triggered_spell_id
= 37382;
5578 // Shadowflame Hellfire (Voidheart Raiment set bonus)
5581 triggered_spell_id
= 37378;
5587 basepoints0
= int32(damage
* triggerAmount
/ 100);
5588 triggered_spell_id
= 63106;
5594 case SPELLFAMILY_PRIEST
:
5597 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
5599 if(!pVictim
|| !pVictim
->isAlive())
5602 // pVictim is caster of aura
5603 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5606 // Energize 0.25% of max. mana
5607 pVictim
->CastSpell(pVictim
,57669,true,castItem
,triggeredByAura
);
5608 return true; // no hidden cooldown
5611 switch(dummySpell
->SpellIconID
)
5613 // Improved Shadowform
5616 if(!roll_chance_i(triggerAmount
))
5619 RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT
);
5620 RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED
);
5626 basepoints0
= damage
* triggerAmount
/100;
5627 triggered_spell_id
= 47753;
5636 Aura
* healingAura
= pVictim
->GetAura(procSpell
->Id
,0);
5640 int32 healingfromticks
= SpellHealingBonus(pVictim
, procSpell
, (healingAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
)), DOT
);
5641 basepoints0
= healingfromticks
* triggerAmount
/ 100;
5642 triggered_spell_id
= 63544;
5645 // Improved Devouring Plague
5651 Aura
* leachAura
= pVictim
->GetAura(procSpell
->Id
,0);
5655 int32 damagefromticks
= SpellDamageBonus(pVictim
, procSpell
, (leachAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
)), DOT
);
5656 basepoints0
= damagefromticks
* triggerAmount
/ 100;
5657 triggered_spell_id
= 63675;
5662 switch(dummySpell
->Id
)
5667 if(!pVictim
|| !pVictim
->isAlive())
5670 // pVictim is caster of aura
5671 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5675 int32 team
= triggerAmount
*damage
/500;
5676 int32 self
= triggerAmount
*damage
/100 - team
;
5677 pVictim
->CastCustomSpell(pVictim
,15290,&team
,&self
,NULL
,true,castItem
,triggeredByAura
);
5678 return true; // no hidden cooldown
5680 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
5683 // Shadow Word: Pain
5684 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5685 triggered_spell_id
= 40441;
5687 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
5688 triggered_spell_id
= 40440;
5695 // Oracle Healing Bonus ("Garments of the Oracle" set)
5699 basepoints0
= int32(damage
* 10/100);
5701 triggered_spell_id
= 26170;
5704 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
5707 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
5711 basepoints0
= damage
* triggerAmount
/100;
5713 triggered_spell_id
= 39373;
5716 // Greater Heal (Vestments of Faith (Priest Tier 3) - 4 pieces bonus)
5719 triggered_spell_id
= 28810;
5722 // Glyph of Dispel Magic
5725 if(!target
->IsFriendlyTo(this))
5728 basepoints0
= int32(target
->GetMaxHealth() * triggerAmount
/ 100);
5729 triggered_spell_id
= 56131;
5735 case SPELLFAMILY_DRUID
:
5737 switch(dummySpell
->Id
)
5739 // Leader of the Pack
5742 // dummy m_amount store health percent (!=0 if Improved Leader of the Pack applied)
5743 int32 heal_percent
= triggeredByAura
->GetModifier()->m_amount
;
5747 // check explicitly only to prevent mana cast when halth cast cooldown
5748 if (cooldown
&& ((Player
*)this)->HasSpellCooldown(34299))
5752 triggered_spell_id
= 34299;
5753 basepoints0
= GetMaxHealth() * heal_percent
/ 100;
5757 if (triggeredByAura
->GetCasterGUID() == GetGUID())
5759 if (SpellEntry
const* manaCastEntry
= sSpellStore
.LookupEntry(60889))
5761 int32 mana_percent
= manaCastEntry
->CalculateSimpleValue(0) * heal_percent
;
5762 CastCustomSpell(this, manaCastEntry
, &mana_percent
, NULL
, NULL
, true, castItem
, triggeredByAura
);
5767 // Healing Touch (Dreamwalker Raiment set)
5771 basepoints0
= int32(procSpell
->manaCost
* 30 / 100);
5773 triggered_spell_id
= 28742;
5776 // Healing Touch Refund (Idol of Longevity trinket)
5780 triggered_spell_id
= 28848;
5783 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
5788 triggered_spell_id
= 37238;
5791 // Druid Tier 6 Trinket
5797 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
5799 triggered_spell_id
= 40445;
5803 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
5805 triggered_spell_id
= 40446;
5808 // Mangle (Bear) and Mangle (Cat)
5809 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000044000000000))
5811 triggered_spell_id
= 40452;
5817 if (!roll_chance_f(chance
))
5826 // Deadly Interrupt Effect
5827 triggered_spell_id
= 32747;
5832 if (dummySpell
->SpellIconID
== 2856)
5836 // Only 0 aura can proc
5840 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
5844 if (!roll_chance_i(60))
5846 triggered_spell_id
= 48518;
5851 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
5855 triggered_spell_id
= 48517;
5862 else if (dummySpell
->SpellIconID
== 2860)
5864 triggered_spell_id
= 48504;
5865 basepoints0
= triggerAmount
* damage
/ 100;
5870 case SPELLFAMILY_ROGUE
:
5872 switch(dummySpell
->Id
)
5874 // Deadly Throw Interrupt
5877 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
5878 if (this == pVictim
)
5881 triggered_spell_id
= 32747;
5886 if (dummySpell
->SpellIconID
== 2909)
5888 // "refresh your Slice and Dice duration to its 5 combo point maximum"
5889 // lookup Slice and Dice
5890 AuraList
const& sd
= GetAurasByType(SPELL_AURA_MOD_HASTE
);
5891 for(AuraList::const_iterator itr
= sd
.begin(); itr
!= sd
.end(); ++itr
)
5893 SpellEntry
const *spellProto
= (*itr
)->GetSpellProto();
5894 if (spellProto
->SpellFamilyName
== SPELLFAMILY_ROGUE
&&
5895 (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000040000)))
5897 (*itr
)->SetAuraMaxDuration(GetSpellMaxDuration(spellProto
));
5898 (*itr
)->RefreshAura();
5905 if (dummySpell
->SpellIconID
== 2963)
5907 triggered_spell_id
= 44289;
5911 if (dummySpell
->SpellIconID
== 2116)
5917 basepoints0
= procSpell
->manaCost
* triggerAmount
/100;
5918 if (basepoints0
<= 0)
5922 triggered_spell_id
= 31663;
5927 case SPELLFAMILY_HUNTER
:
5929 // Aspect of the Viper
5930 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x4000000000000))
5932 uint32 maxmana
= GetMaxPower(POWER_MANA
);
5933 basepoints0
= int32(maxmana
* GetAttackTime(RANGED_ATTACK
)/1000.0f
/100.0f
);
5936 triggered_spell_id
= 34075;
5939 // Thrill of the Hunt
5940 if (dummySpell
->SpellIconID
== 2236)
5946 int32 mana
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5947 basepoints0
= mana
* 40/100;
5948 if(basepoints0
<= 0)
5952 triggered_spell_id
= 34720;
5956 if ( dummySpell
->SpellIconID
== 3406 )
5958 triggered_spell_id
= 57669;
5963 if ( dummySpell
->SpellIconID
== 3579 )
5965 // Proc only from periodic (from trap activation proc another aura of this spell)
5966 if (!(procFlag
& PROC_FLAG_ON_DO_PERIODIC
) || !roll_chance_i(triggerAmount
))
5968 triggered_spell_id
= 56453;
5972 // Rapid Recuperation
5973 if ( dummySpell
->SpellIconID
== 3560 )
5975 // This effect only from Rapid Killing (mana regen)
5976 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0100000000000000)))
5981 switch(dummySpell
->Id
)
5983 case 53228: // Rank 1
5984 triggered_spell_id
= 56654;
5986 case 53232: // Rank 2
5987 triggered_spell_id
= 58882;
5994 case SPELLFAMILY_PALADIN
:
5996 // Seal of Righteousness - melee proc dummy (addition ${$MWS*(0.022*$AP+0.044*$SPH)} damage)
5997 if ((dummySpell
->SpellFamilyFlags
& UI64LIT(0x000000008000000)) && effIndex
==0)
5999 triggered_spell_id
= 25742;
6000 float ap
= GetTotalAttackPowerValue(BASE_ATTACK
);
6001 int32 holy
= SpellBaseDamageBonus(SPELL_SCHOOL_MASK_HOLY
) +
6002 SpellBaseDamageBonusForVictim(SPELL_SCHOOL_MASK_HOLY
, pVictim
);
6003 basepoints0
= GetAttackTime(BASE_ATTACK
) * int32(ap
*0.022f
+ 0.044f
* holy
) / 1000;
6006 // Righteous Vengeance
6007 if (dummySpell
->SpellIconID
== 3025)
6010 basepoints0
= triggerAmount
*damage
/400;
6011 triggered_spell_id
= 61840;
6015 if (dummySpell
->SpellIconID
== 3030)
6018 basepoints0
= triggerAmount
*damage
/400;
6019 triggered_spell_id
= 54203;
6022 switch(dummySpell
->Id
)
6024 // Judgement of Light
6027 basepoints0
= int32( pVictim
->GetMaxHealth() * triggeredByAura
->GetModifier()->m_amount
/ 100 );
6028 pVictim
->CastCustomSpell(pVictim
, 20267, &basepoints0
, NULL
, NULL
, true, NULL
, triggeredByAura
);
6031 // Judgement of Wisdom
6034 if (pVictim
->getPowerType() == POWER_MANA
)
6036 // 2% of maximum base mana
6037 basepoints0
= int32(pVictim
->GetCreateMana() * 2 / 100);
6038 pVictim
->CastCustomSpell(pVictim
, 20268, &basepoints0
, NULL
, NULL
, true, NULL
, triggeredByAura
);
6042 // Heart of the Crusader (Rank 1)
6044 triggered_spell_id
= 21183;
6046 // Heart of the Crusader (Rank 2)
6048 triggered_spell_id
= 54498;
6050 // Heart of the Crusader (Rank 3)
6052 triggered_spell_id
= 54499;
6054 case 20911: // Blessing of Sanctuary
6055 case 25899: // Greater Blessing of Sanctuary
6058 switch (target
->getPowerType())
6061 triggered_spell_id
= 57319;
6068 // Holy Power (Redemption Armor set)
6074 // Set class defined buff
6075 switch (pVictim
->getClass())
6081 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6085 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6089 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
6092 triggered_spell_id
= 28790; // Increases the friendly target's armor
6099 // Spiritual Attunement
6103 // if healed by another unit (pVictim)
6108 basepoints0
= triggerAmount
*damage
/100;
6110 triggered_spell_id
= 31786;
6113 // Seal of Vengeance (damage calc on apply aura)
6116 if(effIndex
!= 0) // effect 1,2 used by seal unleashing code
6119 triggered_spell_id
= 31803;
6121 // Add 5-stack effect
6123 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6124 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6126 if( ((*itr
)->GetId() == 31803) && (*itr
)->GetCasterGUID()==GetGUID())
6128 stacks
= (*itr
)->GetStackAmount();
6133 CastSpell(target
,42463,true,NULL
,triggeredByAura
);
6136 // Judgements of the Wise
6140 // triggered only at casted Judgement spells, not at additional Judgement effects
6141 if(!procSpell
|| procSpell
->Category
!= 1210)
6145 triggered_spell_id
= 31930;
6148 CastSpell(this, 57669, true, NULL
, triggeredByAura
);
6150 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
6158 // Flash of light/Holy light
6159 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x00000000C0000000))
6161 triggered_spell_id
= 40471;
6165 else if (GetSpellSpecific(procSpell
->Id
)==SPELL_JUDGEMENT
)
6167 triggered_spell_id
= 40472;
6173 if (!roll_chance_f(chance
))
6178 // Light's Beacon (heal target area aura)
6181 // not do bonus heal for explicit beacon focus healing
6182 if (GetGUID() == triggeredByAura
->GetCasterGUID())
6186 Unit
* beacon
= triggeredByAura
->GetCaster();
6190 // find caster main aura at beacon
6192 Unit::AuraList
const& baa
= beacon
->GetAurasByType(SPELL_AURA_PERIODIC_TRIGGER_SPELL
);
6193 for(Unit::AuraList::const_iterator i
= baa
.begin(); i
!= baa
.end(); ++i
)
6195 if ((*i
)->GetId() == 53563 && (*i
)->GetCasterGUID() == pVictim
->GetGUID())
6202 // original heal must be form beacon caster
6206 triggered_spell_id
= 53652; // Beacon of Light
6207 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*damage
/100;
6209 // cast with original caster set but beacon to beacon for apply caster mods and avoid LoS check
6210 beacon
->CastCustomSpell(beacon
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
,pVictim
->GetGUID());
6213 // Seal of Corruption (damage calc on apply aura)
6216 if(effIndex
!= 0) // effect 1,2 used by seal unleashing code
6219 triggered_spell_id
= 53742;
6221 // Add 5-stack effect
6223 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6224 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6226 if( ((*itr
)->GetId() == 53742) && (*itr
)->GetCasterGUID()==GetGUID())
6228 stacks
= (*itr
)->GetStackAmount();
6233 CastSpell(target
,53739,true,NULL
,triggeredByAura
);
6236 // Glyph of Flash of Light
6239 triggered_spell_id
= 54957;
6240 basepoints0
= triggerAmount
*damage
/100;
6243 // Glyph of Holy Light
6246 triggered_spell_id
= 54968;
6247 basepoints0
= triggerAmount
*damage
/100;
6250 // Glyph of Divinity
6253 // Lookup base amount mana restore
6254 for (int i
=0; i
<3;++i
)
6255 if (procSpell
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
6257 int32 mana
= procSpell
->EffectBasePoints
[i
];
6258 CastCustomSpell(this, 54986, NULL
, &mana
, NULL
, true, castItem
, triggeredByAura
);
6263 // Sacred Shield (buff)
6266 triggered_spell_id
= 66922;
6267 SpellEntry
const* triggeredEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6268 if (!triggeredEntry
)
6271 basepoints0
= int32(damage
/ (GetSpellDuration(triggeredEntry
) / triggeredEntry
->EffectAmplitude
[0]));
6275 // Sacred Shield (talent rank)
6278 triggered_spell_id
= 58597;
6285 case SPELLFAMILY_SHAMAN
:
6287 switch(dummySpell
->Id
)
6289 // Totemic Power (The Earthshatterer set)
6295 // Set class defined buff
6296 switch (pVictim
->getClass())
6302 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6306 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6310 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
6313 triggered_spell_id
= 28827; // Increases the friendly target's armor
6320 // Lesser Healing Wave (Totem of Flowing Water Relic)
6324 triggered_spell_id
= 28850;
6327 // Windfury Weapon (Passive) 1-5 Ranks
6330 if(GetTypeId()!=TYPEID_PLAYER
)
6333 if(!castItem
|| !castItem
->IsEquipped())
6336 // custom cooldown processing case
6337 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6340 // Now amount of extra power stored in 1 effect of Enchant spell
6341 // Get it by item enchant id
6343 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
6345 case 283: spellId
= 8232; break; // 1 Rank
6346 case 284: spellId
= 8235; break; // 2 Rank
6347 case 525: spellId
= 10486; break; // 3 Rank
6348 case 1669:spellId
= 16362; break; // 4 Rank
6349 case 2636:spellId
= 25505; break; // 5 Rank
6350 case 3785:spellId
= 58801; break; // 6 Rank
6351 case 3786:spellId
= 58803; break; // 7 Rank
6352 case 3787:spellId
= 58804; break; // 8 Rank
6355 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
6356 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
6361 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
6362 if(!windfurySpellEntry
)
6364 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
6368 int32 extra_attack_power
= CalculateSpellDamage(windfurySpellEntry
, 1, windfurySpellEntry
->EffectBasePoints
[1], pVictim
);
6371 if ( castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
6373 // Value gained from additional AP
6374 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
6375 triggered_spell_id
= 33750;
6380 // Value gained from additional AP
6381 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
6382 triggered_spell_id
= 25504;
6385 // apply cooldown before cast to prevent processing itself
6387 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6390 for ( uint32 i
= 0; i
<2; ++i
)
6391 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6395 // Shaman Tier 6 Trinket
6402 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6404 triggered_spell_id
= 40465; // Lightning Bolt
6407 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080))
6409 triggered_spell_id
= 40465; // Lesser Healing Wave
6412 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
6414 triggered_spell_id
= 40466; // Stormstrike
6420 if (!roll_chance_f(chance
))
6426 // Glyph of Healing Wave
6429 // Not proc from self heals
6432 basepoints0
= triggerAmount
* damage
/ 100;
6434 triggered_spell_id
= 55533;
6441 target
= GetOwner();
6444 basepoints0
= triggerAmount
* damage
/ 100;
6445 triggered_spell_id
= 58879;
6448 // Shaman T8 Elemental 4P Bonus
6451 basepoints0
= int32( triggerAmount
* damage
/ 100 );
6452 triggered_spell_id
= 64930; // Electrified
6456 // Storm, Earth and Fire
6457 if (dummySpell
->SpellIconID
== 3063)
6459 // Earthbind Totem summon only
6460 if(procSpell
->Id
!= 2484)
6463 float chance
= triggerAmount
;
6464 if (!roll_chance_f(chance
))
6467 triggered_spell_id
= 64695;
6470 // Ancestral Awakening
6471 if (dummySpell
->SpellIconID
== 3065)
6473 triggered_spell_id
= 52759;
6474 basepoints0
= triggerAmount
* damage
/ 100;
6479 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
6482 basepoints0
= triggerAmount
;
6484 // Glyph of Earth Shield
6485 if (Aura
* aur
= GetDummyAura(63279))
6487 int32 aur_mod
= aur
->GetModifier()->m_amount
;
6488 basepoints0
= int32(basepoints0
* (aur_mod
+ 100.0f
) / 100.0f
);
6491 triggered_spell_id
= 379;
6494 // Improved Water Shield
6495 if (dummySpell
->SpellIconID
== 2287)
6497 // Lesser Healing Wave need aditional 60% roll
6498 if ((procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)) && !roll_chance_i(60))
6500 // lookup water shield
6501 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6502 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6504 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6505 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000002000000000)))
6507 uint32 spell
= (*itr
)->GetSpellProto()->EffectTriggerSpell
[(*itr
)->GetEffIndex()];
6508 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
6509 if ((*itr
)->DropAuraCharge())
6510 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6517 // Lightning Overload
6518 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
6520 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
6523 // custom cooldown processing case
6524 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6528 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
6529 switch (procSpell
->Id
)
6532 case 403: spellId
= 45284; break; // Rank 1
6533 case 529: spellId
= 45286; break; // Rank 2
6534 case 548: spellId
= 45287; break; // Rank 3
6535 case 915: spellId
= 45288; break; // Rank 4
6536 case 943: spellId
= 45289; break; // Rank 5
6537 case 6041: spellId
= 45290; break; // Rank 6
6538 case 10391: spellId
= 45291; break; // Rank 7
6539 case 10392: spellId
= 45292; break; // Rank 8
6540 case 15207: spellId
= 45293; break; // Rank 9
6541 case 15208: spellId
= 45294; break; // Rank 10
6542 case 25448: spellId
= 45295; break; // Rank 11
6543 case 25449: spellId
= 45296; break; // Rank 12
6544 case 49237: spellId
= 49239; break; // Rank 13
6545 case 49238: spellId
= 49240; break; // Rank 14
6547 case 421: spellId
= 45297; break; // Rank 1
6548 case 930: spellId
= 45298; break; // Rank 2
6549 case 2860: spellId
= 45299; break; // Rank 3
6550 case 10605: spellId
= 45300; break; // Rank 4
6551 case 25439: spellId
= 45301; break; // Rank 5
6552 case 25442: spellId
= 45302; break; // Rank 6
6553 case 49270: spellId
= 49268; break; // Rank 7
6554 case 49271: spellId
= 49269; break; // Rank 8
6556 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
6559 // No thread generated mod
6560 // TODO: exist special flag in spell attributes for this, need found and use!
6561 SpellModifier
*mod
= new SpellModifier(SPELLMOD_THREAT
,SPELLMOD_PCT
,-100,triggeredByAura
);
6563 ((Player
*)this)->AddSpellMod(mod
, true);
6565 // Remove cooldown (Chain Lightning - have Category Recovery time)
6566 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000002))
6567 ((Player
*)this)->RemoveSpellCooldown(spellId
);
6569 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
6571 ((Player
*)this)->AddSpellMod(mod
, false);
6573 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6574 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6579 if(dummySpell
->SpellIconID
== 3059)
6581 // lookup Lightning Shield
6582 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6583 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6585 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6586 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000400)))
6589 switch ((*itr
)->GetId())
6591 case 324: spell
= 26364; break;
6592 case 325: spell
= 26365; break;
6593 case 905: spell
= 26366; break;
6594 case 945: spell
= 26367; break;
6595 case 8134: spell
= 26369; break;
6596 case 10431: spell
= 26370; break;
6597 case 10432: spell
= 26363; break;
6598 case 25469: spell
= 26371; break;
6599 case 25472: spell
= 26372; break;
6600 case 49280: spell
= 49278; break;
6601 case 49281: spell
= 49279; break;
6605 CastSpell(target
, spell
, true, castItem
, triggeredByAura
);
6606 if ((*itr
)->DropAuraCharge())
6607 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6614 if (dummySpell
->SpellIconID
== 3780)
6616 Unit
*caster
= triggeredByAura
->GetCaster();
6618 if (!procSpell
|| !caster
)
6621 float distance
= caster
->GetDistance(pVictim
);
6622 int32 chance
= triggerAmount
;
6624 if (distance
< 15.0f
|| !roll_chance_i(chance
))
6627 // make triggered cast apply after current damage spell processing for prevent remove by it
6628 if(Spell
* spell
= GetCurrentSpell(CURRENT_GENERIC_SPELL
))
6629 spell
->AddTriggeredSpell(63685);
6634 case SPELLFAMILY_DEATHKNIGHT
:
6637 if (dummySpell
->SpellIconID
== 2636)
6639 if (GetTypeId() != TYPEID_PLAYER
|| !((Player
*)this)->isHonorOrXPTarget(pVictim
))
6641 basepoints0
= triggerAmount
* damage
/ 100;
6642 triggered_spell_id
= 53168;
6646 if (dummySpell
->SpellIconID
== 2664)
6648 basepoints0
= triggerAmount
;
6649 triggered_spell_id
= 50163;
6653 // Dancing Rune Weapon
6654 if (dummySpell
->Id
== 49028)
6656 // 1 dummy aura for dismiss rune blade
6659 // TODO: wite script for this "fights on its own, doing the same attacks"
6660 // NOTE: Trigger here on every attack and spell cast
6664 if (dummySpell
->Id
== 49005)
6666 // TODO: need more info (cooldowns/PPM)
6667 triggered_spell_id
= 61607;
6671 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000010000))
6673 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
6674 triggered_spell_id
= 50181;
6679 if (dummySpell
->SpellIconID
== 2709)
6681 basepoints0
= triggerAmount
* damage
/ 100;
6682 triggered_spell_id
= 51460;
6685 // Threat of Thassarian
6686 if (dummySpell
->SpellIconID
== 2023)
6689 if (!procSpell
|| !haveOffhandWeapon())
6691 // Chance as basepoints for dummy aura
6692 if (!roll_chance_i(triggerAmount
))
6695 switch (procSpell
->Id
)
6698 case 49020: // Rank 1
6699 triggered_spell_id
= 66198; break;
6700 case 51423: // Rank 2
6701 triggered_spell_id
= 66972; break;
6702 case 51424: // Rank 3
6703 triggered_spell_id
= 66973; break;
6704 case 51425: // Rank 4
6705 triggered_spell_id
= 66974; break;
6707 case 49143: // Rank 1
6708 triggered_spell_id
= 66196; break;
6709 case 51416: // Rank 2
6710 triggered_spell_id
= 66958; break;
6711 case 51417: // Rank 3
6712 triggered_spell_id
= 66959; break;
6713 case 51418: // Rank 4
6714 triggered_spell_id
= 66960; break;
6715 case 51419: // Rank 5
6716 triggered_spell_id
= 66961; break;
6717 case 51420: // Rank 6
6718 triggered_spell_id
= 66962; break;
6720 case 45462: // Rank 1
6721 triggered_spell_id
= 66216; break;
6722 case 49917: // Rank 2
6723 triggered_spell_id
= 66988; break;
6724 case 49918: // Rank 3
6725 triggered_spell_id
= 66989; break;
6726 case 49919: // Rank 4
6727 triggered_spell_id
= 66990; break;
6728 case 49920: // Rank 5
6729 triggered_spell_id
= 66991; break;
6730 case 49921: // Rank 6
6731 triggered_spell_id
= 66992; break;
6733 case 49998: // Rank 1
6734 triggered_spell_id
= 66188; break;
6735 case 49999: // Rank 2
6736 triggered_spell_id
= 66950; break;
6737 case 45463: // Rank 3
6738 triggered_spell_id
= 66951; break;
6739 case 49923: // Rank 4
6740 triggered_spell_id
= 66952; break;
6741 case 49924: // Rank 5
6742 triggered_spell_id
= 66953; break;
6745 triggered_spell_id
= 66217; break;
6747 case 45902: // Rank 1
6748 triggered_spell_id
= 66215; break;
6749 case 49926: // Rank 2
6750 triggered_spell_id
= 66975; break;
6751 case 49927: // Rank 3
6752 triggered_spell_id
= 66976; break;
6753 case 49928: // Rank 4
6754 triggered_spell_id
= 66977; break;
6755 case 49929: // Rank 5
6756 triggered_spell_id
= 66978; break;
6757 case 49930: // Rank 6
6758 triggered_spell_id
= 66979; break;
6764 // Runic Power Back on Snare/Root
6765 if (dummySpell
->Id
== 61257)
6767 // only for spells and hit/crit (trigger start always) and not start from self casted spells
6768 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
6770 // Need snare or root mechanic
6771 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_SNARE_MASK
))
6773 triggered_spell_id
= 61258;
6778 if (dummySpell
->SpellIconID
== 1614)
6780 if (!roll_chance_f(GetUnitCriticalChance(BASE_ATTACK
, pVictim
)))
6782 basepoints0
= triggerAmount
* damage
/ 100;
6783 triggered_spell_id
= 50526;
6786 // Blood-Caked Blade
6787 if (dummySpell
->SpellIconID
== 138)
6789 triggered_spell_id
= dummySpell
->EffectTriggerSpell
[effIndex
];
6798 // processed charge only counting case
6799 if(!triggered_spell_id
)
6802 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6806 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
6811 if(!target
|| target
!=this && !target
->isAlive())
6814 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
6818 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6820 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
6822 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6823 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
6828 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
6830 // Get triggered aura spell info
6831 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
6833 // Basepoints of trigger aura
6834 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
6836 // Set trigger spell id, target, custom basepoints
6837 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
6838 Unit
* target
= NULL
;
6839 int32 basepoints
[3] = {0, 0, 0};
6841 if(triggeredByAura
->GetModifier()->m_auraname
== SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
)
6842 basepoints
[0] = triggerAmount
;
6844 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
6845 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
6847 // Try handle unknown trigger spells
6848 // Custom requirements (not listed in procEx) Warning! damage dealing after this
6849 // Custom triggered spells
6850 switch (auraSpellInfo
->SpellFamilyName
)
6852 case SPELLFAMILY_GENERIC
:
6853 switch(auraSpellInfo
->Id
)
6855 //case 191: // Elemental Response
6856 // switch (procSpell->School)
6858 // case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192; break;
6859 // case SPELL_SCHOOL_FROST: trigger_spell_id = 34193; break;
6860 // case SPELL_SCHOOL_ARCANE:trigger_spell_id = 34194; break;
6861 // case SPELL_SCHOOL_NATURE:trigger_spell_id = 34195; break;
6862 // case SPELL_SCHOOL_SHADOW:trigger_spell_id = 34196; break;
6863 // case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197; break;
6864 // case SPELL_SCHOOL_NORMAL:trigger_spell_id = 34198; break;
6867 //case 5301: break; // Defensive State (DND)
6868 //case 7137: break: // Shadow Charge (Rank 1)
6869 //case 7377: break: // Take Immune Periodic Damage <Not Working>
6870 //case 13358: break; // Defensive State (DND)
6871 //case 16092: break; // Defensive State (DND)
6872 //case 18943: break; // Double Attack
6873 //case 19194: break; // Double Attack
6874 //case 19817: break; // Double Attack
6875 //case 19818: break; // Double Attack
6876 //case 22835: break; // Drunken Rage
6877 // trigger_spell_id = 14822; break;
6878 case 23780: // Aegis of Preservation (Aegis of Preservation trinket)
6879 trigger_spell_id
= 23781;
6881 //case 24949: break; // Defensive State 2 (DND)
6882 case 27522: // Mana Drain Trigger
6883 case 40336: // Mana Drain Trigger
6884 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
6886 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
6887 if (pVictim
&& pVictim
->isAlive())
6888 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
6890 case 31255: // Deadly Swiftness (Rank 1)
6891 // whenever you deal damage to a target who is below 20% health.
6892 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
6896 trigger_spell_id
= 22588;
6898 //case 33207: break; // Gossip NPC Periodic - Fidget
6899 case 33896: // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
6900 trigger_spell_id
= 33898;
6902 //case 34082: break; // Advantaged State (DND)
6903 //case 34783: break: // Spell Reflection
6904 //case 35205: break: // Vanish
6905 //case 35321: break; // Gushing Wound
6906 //case 36096: break: // Spell Reflection
6907 //case 36207: break: // Steal Weapon
6908 //case 36576: break: // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
6909 //case 37030: break; // Chaotic Temperament
6910 //case 38363: break; // Gushing Wound
6911 //case 39215: break; // Gushing Wound
6912 //case 40250: break; // Improved Duration
6913 //case 40329: break; // Demo Shout Sensor
6914 //case 40364: break; // Entangling Roots Sensor
6915 //case 41054: break; // Copy Weapon
6916 // trigger_spell_id = 41055; break;
6917 //case 41248: break; // Consuming Strikes
6918 // trigger_spell_id = 41249; break;
6919 //case 42730: break: // Woe Strike
6920 //case 43453: break: // Rune Ward
6921 //case 43504: break; // Alterac Valley OnKill Proc Aura
6922 //case 44326: break: // Pure Energy Passive
6923 //case 44526: break; // Hate Monster (Spar) (30 sec)
6924 //case 44527: break; // Hate Monster (Spar Buddy) (30 sec)
6925 //case 44819: break; // Hate Monster (Spar Buddy) (>30% Health)
6926 //case 44820: break; // Hate Monster (Spar) (<30%)
6927 case 45057: // Evasive Maneuvers (Commendation of Kael`thas trinket)
6928 // reduce you below $s1% health
6929 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
6932 //case 45903: break: // Offensive State
6933 //case 46146: break: // [PH] Ahune Spanky Hands
6934 //case 46939: break; // Black Bow of the Betrayer
6935 // trigger_spell_id = 29471; - gain mana
6936 // 27526; - drain mana if possible
6937 case 43820: // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
6938 // Pct value stored in dummy
6939 basepoints
[0] = pVictim
->GetCreateHealth() * auraSpellInfo
->EffectBasePoints
[1] / 100;
6942 //case 45205: break; // Copy Offhand Weapon
6943 //case 45343: break; // Dark Flame Aura
6944 //case 47300: break; // Dark Flame Aura
6945 //case 48876: break; // Beast's Mark
6946 // trigger_spell_id = 48877; break;
6947 //case 49059: break; // Horde, Hate Monster (Spar Buddy) (>30% Health)
6948 //case 50051: break; // Ethereal Pet Aura
6949 //case 50689: break; // Blood Presence (Rank 1)
6950 //case 50844: break; // Blood Mirror
6951 //case 52856: break; // Charge
6952 //case 54072: break; // Knockback Ball Passive
6953 //case 54476: break; // Blood Presence
6954 //case 54775: break; // Abandon Vehicle on Poly
6955 case 57345: // Darkmoon Card: Greatness
6959 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 60229;stat
= GetStat(STAT_STRENGTH
); }
6961 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 60233;stat
= GetStat(STAT_AGILITY
); }
6963 if (GetStat(STAT_INTELLECT
)> stat
) { trigger_spell_id
= 60234;stat
= GetStat(STAT_INTELLECT
);}
6965 if (GetStat(STAT_SPIRIT
) > stat
) { trigger_spell_id
= 60235; }
6968 //case 55580: break: // Mana Link
6969 //case 57587: break: // Steal Ranged ()
6970 //case 57594: break; // Copy Ranged Weapon
6971 //case 59237: break; // Beast's Mark
6972 // trigger_spell_id = 59233; break;
6973 //case 59288: break; // Infra-Green Shield
6974 //case 59532: break; // Abandon Passengers on Poly
6975 //case 59735: break: // Woe Strike
6976 case 67702: // Death's Choice, Item - Coliseum 25 Normal Melee Trinket
6980 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67708;stat
= GetStat(STAT_STRENGTH
); }
6982 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67703; }
6985 case 67771: // Death's Choice (heroic), Item - Coliseum 25 Heroic Melee Trinket
6989 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67773;stat
= GetStat(STAT_STRENGTH
); }
6991 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67772; }
6996 case SPELLFAMILY_MAGE
:
6997 if (auraSpellInfo
->SpellIconID
== 2127) // Blazing Speed
6999 switch (auraSpellInfo
->Id
)
7001 case 31641: // Rank 1
7002 case 31642: // Rank 2
7003 trigger_spell_id
= 31643;
7006 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
7010 // Persistent Shield (Scarab Brooch trinket)
7011 else if(auraSpellInfo
->Id
== 26467)
7013 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
7014 basepoints
[0] = damage
* 15 / 100;
7016 trigger_spell_id
= 26470;
7019 case SPELLFAMILY_WARRIOR
:
7020 // Deep Wounds (replace triggered spells to directly apply DoT), dot spell have finilyflags
7021 if (auraSpellInfo
->SpellFamilyFlags
== UI64LIT(0x0) && auraSpellInfo
->SpellIconID
== 243)
7024 // DW should benefit of attack power, damage percent mods etc.
7025 // TODO: check if using offhand damage is correct and if it should be divided by 2
7026 if (haveOffhandWeapon() && getAttackTimer(BASE_ATTACK
) > getAttackTimer(OFF_ATTACK
))
7027 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
))/2;
7029 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXDAMAGE
))/2;
7031 switch (auraSpellInfo
->Id
)
7033 case 12834: basepoints
[0] = int32(weaponDamage
* 16 / 100); break;
7034 case 12849: basepoints
[0] = int32(weaponDamage
* 32 / 100); break;
7035 case 12867: basepoints
[0] = int32(weaponDamage
* 48 / 100); break;
7038 sLog
.outError("Unit::HandleProcTriggerSpell: DW unknown spell rank %u",auraSpellInfo
->Id
);
7042 // 1 tick/sec * 6 sec = 6 ticks
7045 trigger_spell_id
= 12721;
7048 if (auraSpellInfo
->Id
== 50421) // Scent of Blood
7049 trigger_spell_id
= 50422;
7051 case SPELLFAMILY_WARLOCK
:
7054 if (auraSpellInfo
->SpellIconID
== 1137)
7056 if(!pVictim
|| !pVictim
->isAlive() || pVictim
== this || procSpell
== NULL
)
7058 // Calculate spell tick count for spells
7059 uint32 tick
= 1; // Default tick = 1
7061 // Hellfire have 15 tick
7062 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000040))
7064 // Rain of Fire have 4 tick
7065 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000020))
7070 // Calculate chance = baseChance / tick
7072 switch (auraSpellInfo
->Id
)
7074 case 18096: chance
= 13.0f
/ tick
; break;
7075 case 18073: chance
= 26.0f
/ tick
; break;
7078 if (!roll_chance_f(chance
))
7081 trigger_spell_id
= 18093;
7084 else if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
7086 Unit::AuraList
const& mAddFlatModifier
= GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER
);
7087 for(Unit::AuraList::const_iterator i
= mAddFlatModifier
.begin(); i
!= mAddFlatModifier
.end(); ++i
)
7089 if ((*i
)->GetModifier()->m_miscvalue
== SPELLMOD_CHANCE_OF_SUCCESS
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
7092 CastCustomSpell(this, 18371, &basepoints
[0], NULL
, NULL
, true, castItem
, triggeredByAura
);
7096 // Not remove charge (aura removed on death in any cases)
7097 // Need for correct work Drain Soul SPELL_AURA_CHANNEL_DEATH_ITEM aura
7100 // Nether Protection
7101 else if (auraSpellInfo
->SpellIconID
== 1985)
7105 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7107 case SPELL_SCHOOL_NORMAL
:
7108 return false; // ignore
7109 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 54370; break;
7110 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 54371; break;
7111 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 54375; break;
7112 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 54372; break;
7113 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 54374; break;
7114 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
7120 else if (auraSpellInfo
->Id
== 28845)
7122 // When your health drops below 20% ....
7123 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
7127 else if (auraSpellInfo
->Id
== 63156 || auraSpellInfo
->Id
== 63158)
7129 // Looking for dummy effect
7130 Aura
*aur
= GetAura(auraSpellInfo
->Id
, 1);
7134 // If target's health is not below equal certain value (35%) not proc
7135 if ((pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth()) > aur
->GetModifier()->m_amount
)
7140 case SPELLFAMILY_PRIEST
:
7142 // Greater Heal Refund (Avatar Raiment set)
7143 if (auraSpellInfo
->Id
==37594)
7145 // Not give if target already have full health
7146 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
7148 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
7149 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
7151 trigger_spell_id
= 37595;
7154 else if (auraSpellInfo
->SpellIconID
== 1875)
7156 switch (auraSpellInfo
->Id
)
7158 case 27811: trigger_spell_id
= 27813; break;
7159 case 27815: trigger_spell_id
= 27817; break;
7160 case 27816: trigger_spell_id
= 27818; break;
7162 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
7165 basepoints
[0] = damage
* triggerAmount
/ 100 / 3;
7170 case SPELLFAMILY_DRUID
:
7172 // Druid Forms Trinket
7173 if (auraSpellInfo
->Id
==37336)
7177 case FORM_NONE
: trigger_spell_id
= 37344;break;
7178 case FORM_CAT
: trigger_spell_id
= 37341;break;
7180 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
7181 case FORM_TREE
: trigger_spell_id
= 37342;break;
7182 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
7187 // Druid T9 Feral Relic (Lacerate, Swipe, Mangle, and Shred)
7188 else if (auraSpellInfo
->Id
==67353)
7192 case FORM_CAT
: trigger_spell_id
= 67355; break;
7194 case FORM_DIREBEAR
: trigger_spell_id
= 67354; break;
7201 case SPELLFAMILY_HUNTER
:
7203 if (auraSpellInfo
->SpellIconID
== 3247 && auraSpellInfo
->SpellVisual
[0] == 0)
7205 basepoints
[0] = damage
* triggerAmount
/ 100 / 8;
7206 trigger_spell_id
= 63468;
7209 // Rapid Recuperation
7210 else if (auraSpellInfo
->Id
== 53228 || auraSpellInfo
->Id
== 53232)
7212 // This effect only from Rapid Fire (ability cast)
7213 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000020)))
7217 case SPELLFAMILY_PALADIN
:
7221 if (auraSpellInfo->SpellIconID == 2137)
7223 switch (auraSpellInfo->Id)
7225 case 31828: // Rank 1
7226 case 31829: // Rank 2
7227 case 31830: // Rank 3
7230 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
7236 if (auraSpellInfo
->Id
==37705)
7238 trigger_spell_id
= 37706;
7242 if (auraSpellInfo
->Id
==60510)
7244 trigger_spell_id
= 60515;
7248 else if (auraSpellInfo
->SpellIconID
==241)
7252 // procspell is triggered spell but we need mana cost of original casted spell
7253 uint32 originalSpellId
= procSpell
->Id
;
7255 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0001000000000000))
7257 switch(procSpell
->Id
)
7259 case 25914: originalSpellId
= 20473; break;
7260 case 25913: originalSpellId
= 20929; break;
7261 case 25903: originalSpellId
= 20930; break;
7262 case 27175: originalSpellId
= 27174; break;
7263 case 33074: originalSpellId
= 33072; break;
7264 case 48820: originalSpellId
= 48824; break;
7265 case 48821: originalSpellId
= 48825; break;
7267 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
7271 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
7274 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
7277 // percent stored in effect 1 (class scripts) base points
7278 int32 cost
= originalSpell
->manaCost
+ originalSpell
->ManaCostPercentage
* GetCreateMana() / 100;
7279 basepoints
[0] = cost
*auraSpellInfo
->CalculateSimpleValue(1)/100;
7280 trigger_spell_id
= 20272;
7283 // Lightning Capacitor
7284 else if (auraSpellInfo
->Id
==37657)
7286 if(!pVictim
|| !pVictim
->isAlive())
7289 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
7291 Aura
* dummy
= GetDummyAura(37658);
7292 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7293 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7296 RemoveAurasDueToSpell(37658);
7297 trigger_spell_id
= 37661;
7300 // Bonus Healing (Crystal Spire of Karabor mace)
7301 else if (auraSpellInfo
->Id
== 40971)
7303 // If your target is below $s1% health
7304 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
7307 // Thunder Capacitor
7308 else if (auraSpellInfo
->Id
== 54841)
7310 if(!pVictim
|| !pVictim
->isAlive())
7313 CastSpell(this, 54842, true, NULL
, triggeredByAura
);
7316 Aura
* dummy
= GetDummyAura(54842);
7317 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7318 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7321 RemoveAurasDueToSpell(54842);
7322 trigger_spell_id
= 54843;
7327 case SPELLFAMILY_SHAMAN
:
7329 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc
7330 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000400))
7332 switch(auraSpellInfo
->Id
)
7335 trigger_spell_id
= 26364; break;
7337 trigger_spell_id
= 26365; break;
7339 trigger_spell_id
= 26366; break;
7341 trigger_spell_id
= 26367; break;
7342 case 8134: // Rank 5
7343 trigger_spell_id
= 26369; break;
7344 case 10431: // Rank 6
7345 trigger_spell_id
= 26370; break;
7346 case 10432: // Rank 7
7347 trigger_spell_id
= 26363; break;
7348 case 25469: // Rank 8
7349 trigger_spell_id
= 26371; break;
7350 case 25472: // Rank 9
7351 trigger_spell_id
= 26372; break;
7352 case 49280: // Rank 10
7353 trigger_spell_id
= 49278; break;
7354 case 49281: // Rank 11
7355 trigger_spell_id
= 49279; break;
7357 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
7361 // Lightning Shield (The Ten Storms set)
7362 else if (auraSpellInfo
->Id
== 23551)
7364 trigger_spell_id
= 23552;
7367 // Damage from Lightning Shield (The Ten Storms set)
7368 else if (auraSpellInfo
->Id
== 23552)
7369 trigger_spell_id
= 27635;
7370 // Mana Surge (The Earthfury set)
7371 else if (auraSpellInfo
->Id
== 23572)
7375 basepoints
[0] = procSpell
->manaCost
* 35 / 100;
7376 trigger_spell_id
= 23571;
7379 // Nature's Guardian
7380 else if (auraSpellInfo
->SpellIconID
== 2013)
7382 // Check health condition - should drop to less 30% (damage deal after this!)
7383 if (!(10*(int32(GetHealth() - damage
)) < 3 * GetMaxHealth()))
7386 if(pVictim
&& pVictim
->isAlive())
7387 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
7389 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
7390 trigger_spell_id
= 31616;
7395 case SPELLFAMILY_DEATHKNIGHT
:
7398 if (auraSpellInfo
->SpellIconID
== 1930)
7402 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7404 case SPELL_SCHOOL_NORMAL
:
7405 return false; // ignore
7406 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 50490; break;
7407 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 50362; break;
7408 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 50488; break;
7409 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 50485; break;
7410 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 50489; break;
7411 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 50486; break;
7417 else if (auraSpellInfo
->Id
== 48266)
7419 if (GetTypeId() != TYPEID_PLAYER
)
7421 if (!((Player
*)this)->isHonorOrXPTarget(pVictim
))
7423 trigger_spell_id
= 50475;
7424 basepoints
[0] = damage
* triggerAmount
/ 100;
7427 else if (auraSpellInfo
->SpellIconID
== 85)
7429 if (GetTypeId() != TYPEID_PLAYER
|| getClass() != CLASS_DEATH_KNIGHT
||
7430 !((Player
*)this)->IsBaseRuneSlotsOnCooldown(RUNE_BLOOD
))
7439 // All ok. Check current trigger spell
7440 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
7443 // Not cast unknown spell
7444 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
7448 // not allow proc extra attack spell at extra attack
7449 if (m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
))
7452 // Custom basepoints/target for exist spell
7453 // dummy basepoints or other customs
7454 switch(trigger_spell_id
)
7456 // Cast positive spell on enemy target
7457 case 7099: // Curse of Mending
7458 case 39647: // Curse of Mending
7459 case 29494: // Temptation
7460 case 20233: // Improved Lay on Hands (cast on target)
7465 // Combo points add triggers (need add combopoint only for main target, and after possible combopoints reset)
7466 case 15250: // Rogue Setup
7468 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
7470 break; // continue normal case
7472 // Finish movies that add combo
7473 case 14189: // Seal Fate (Netherblade set)
7474 case 14157: // Ruthlessness
7476 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
7479 // Bloodthirst (($m/100)% of max health)
7482 basepoints
[0] = int32(GetMaxHealth() * triggerAmount
/ 100);
7485 // Shamanistic Rage triggered spell
7488 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7491 // Enlightenment (trigger only from mana cost spells)
7494 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
7501 // As the spell is proced from pet's attack - find owner
7502 Unit
* owner
= GetOwner();
7503 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
7506 // This spell doesn't stack, but refreshes duration. So we receive current bonuses to minus them later.
7508 if (Aura
* aur
= owner
->GetAura(48090,0))
7509 curBonus
= aur
->GetModifier()->m_amount
;
7510 int32 spellDamage
= owner
->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_MAGIC
) - curBonus
;
7511 if(spellDamage
<= 0)
7514 // percent stored in owner talent dummy
7515 AuraList
const& dummyAuras
= owner
->GetAurasByType(SPELL_AURA_DUMMY
);
7516 for (AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
7518 if ((*i
)->GetSpellProto()->SpellIconID
== 3220)
7520 basepoints
[0] = basepoints
[1] = int32(spellDamage
* (*i
)->GetModifier()->m_amount
/ 100);
7529 // Remove cooldown on Shield Slam
7530 if (GetTypeId() == TYPEID_PLAYER
)
7531 ((Player
*)this)->RemoveSpellCategoryCooldown(1209, true);
7537 // have rank dependent proc chance, ignore too often cases
7538 // PPM = 2.5 * (rank of talent),
7539 uint32 rank
= sSpellMgr
.GetSpellRank(auraSpellInfo
->Id
);
7540 // 5 rank -> 100% 4 rank -> 80% and etc from full rate
7541 if(!roll_chance_i(20*rank
))
7550 // For trigger from Blizzard need exist Improved Blizzard
7551 if (procSpell
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)))
7554 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7555 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7557 int32 script
= (*i
)->GetModifier()->m_miscvalue
;
7558 if(script
==836 || script
==988 || script
==989)
7572 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7575 // Need stun, fear or silence mechanic
7576 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_SILENCE_AND_STUN_AND_FEAR_MASK
))
7580 // Burning Determination
7585 // Need Interrupt or Silenced mechanic
7586 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_INTERRUPT_AND_SILENCE_MASK
))
7593 // Proc only from trap activation (from periodic proc another aura of this spell)
7594 if (!(procFlags
& PROC_FLAG_ON_TRAP_ACTIVATION
) || !roll_chance_i(triggerAmount
))
7598 // Druid - Savage Defense
7601 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7606 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
7609 // try detect target manually if not set
7610 if ( target
== NULL
)
7611 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
7614 if(!target
|| target
!=this && !target
->isAlive())
7617 if(basepoints
[0] || basepoints
[1] || basepoints
[2])
7618 CastCustomSpell(target
,trigger_spell_id
,
7619 basepoints
[0] ? &basepoints
[0] : NULL
,
7620 basepoints
[1] ? &basepoints
[1] : NULL
,
7621 basepoints
[2] ? &basepoints
[2] : NULL
,
7622 true,castItem
,triggeredByAura
);
7624 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
7626 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7627 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
7632 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32 damage
, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
7634 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
7636 if(!pVictim
|| !pVictim
->isAlive())
7639 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7640 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7642 // Basepoints of trigger aura
7643 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7645 uint32 triggered_spell_id
= 0;
7649 case 836: // Improved Blizzard (Rank 1)
7651 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7653 triggered_spell_id
= 12484;
7656 case 988: // Improved Blizzard (Rank 2)
7658 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7660 triggered_spell_id
= 12485;
7663 case 989: // Improved Blizzard (Rank 3)
7665 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7667 triggered_spell_id
= 12486;
7670 case 4086: // Improved Mend Pet (Rank 1)
7671 case 4087: // Improved Mend Pet (Rank 2)
7673 if(!roll_chance_i(triggerAmount
))
7676 triggered_spell_id
= 24406;
7679 case 4533: // Dreamwalker Raiment 2 pieces bonus
7682 if (!roll_chance_i(50))
7685 switch (pVictim
->getPowerType())
7687 case POWER_MANA
: triggered_spell_id
= 28722; break;
7688 case POWER_RAGE
: triggered_spell_id
= 28723; break;
7689 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
7695 case 4537: // Dreamwalker Raiment 6 pieces bonus
7696 triggered_spell_id
= 28750; // Blessing of the Claw
7698 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
7699 triggered_spell_id
= 37445; // Mana Surge
7701 case 6953: // Warbringer
7702 RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK
,0,true);
7704 case 7010: // Revitalize (rank 1)
7705 case 7011: // Revitalize (rank 2)
7706 case 7012: // Revitalize (rank 3)
7708 if(!roll_chance_i(triggerAmount
))
7711 switch( pVictim
->getPowerType() )
7713 case POWER_MANA
: triggered_spell_id
= 48542; break;
7714 case POWER_RAGE
: triggered_spell_id
= 48541; break;
7715 case POWER_ENERGY
: triggered_spell_id
= 48540; break;
7716 case POWER_RUNIC_POWER
: triggered_spell_id
= 48543; break;
7717 default: return false;
7724 if(!triggered_spell_id
)
7727 // standard non-dummy case
7728 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
7732 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
7736 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
7739 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
7741 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7742 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
7747 void Unit::setPowerType(Powers new_powertype
)
7749 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
7751 if(GetTypeId() == TYPEID_PLAYER
)
7753 if(((Player
*)this)->GetGroup())
7754 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
7756 else if(((Creature
*)this)->isPet())
7758 Pet
*pet
= ((Pet
*)this);
7759 if(pet
->isControlled())
7761 Unit
*owner
= GetOwner();
7762 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
7763 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
7767 switch(new_powertype
)
7773 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
7774 SetPower( POWER_RAGE
,0);
7777 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
7778 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
7781 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
7783 case POWER_HAPPINESS
:
7784 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
7785 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
7790 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
7792 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
7795 static uint64 guid
= 0; // prevent repeating spam same faction problem
7797 if(GetGUID() != guid
)
7799 if(GetTypeId() == TYPEID_PLAYER
)
7800 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
7802 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
7809 bool Unit::IsHostileTo(Unit
const* unit
) const
7811 // always non-hostile to self
7815 // always non-hostile to GM in GM mode
7816 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
7819 // always hostile to enemy
7820 if(getVictim()==unit
|| unit
->getVictim()==this)
7823 // test pet/charm masters instead pers/charmeds
7824 Unit
const* testerOwner
= GetCharmerOrOwner();
7825 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
7827 // always hostile to owner's enemy
7828 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
7831 // always hostile to enemy owner
7832 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
7835 // always hostile to owner of owner's enemy
7836 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
7839 Unit
const* tester
= testerOwner
? testerOwner
: this;
7840 Unit
const* target
= targetOwner
? targetOwner
: unit
;
7842 // always non-hostile to target with common owner, or to owner/pet
7846 // special cases (Duel, etc)
7847 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
7849 Player
const* pTester
= (Player
const*)tester
;
7850 Player
const* pTarget
= (Player
const*)target
;
7853 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
7857 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
7861 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
7865 if(pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
) && pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
))
7869 // Green/Blue (can't attack)
7870 if(pTester
->GetTeam()==pTarget
->GetTeam())
7873 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
7874 return pTester
->IsPvP() && pTarget
->IsPvP();
7877 // faction base cases
7878 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
7879 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
7880 if(!tester_faction
|| !target_faction
)
7883 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
7886 // PvC forced reaction and reputation case
7887 if(tester
->GetTypeId()==TYPEID_PLAYER
)
7890 if(target_faction
->faction
)
7892 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
7893 return *force
<= REP_HOSTILE
;
7895 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
7896 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
7897 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
7898 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
7901 // CvP forced reaction and reputation case
7902 else if(target
->GetTypeId()==TYPEID_PLAYER
)
7905 if(tester_faction
->faction
)
7907 if(ReputationRank
const* force
= ((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
7908 return *force
<= REP_HOSTILE
;
7910 // apply reputation state
7911 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
7912 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
7913 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) <= REP_HOSTILE
;
7917 // common faction based case (CvC,PvC,CvP)
7918 return tester_faction
->IsHostileTo(*target_faction
);
7921 bool Unit::IsFriendlyTo(Unit
const* unit
) const
7923 // always friendly to self
7927 // always friendly to GM in GM mode
7928 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
7931 // always non-friendly to enemy
7932 if(getVictim()==unit
|| unit
->getVictim()==this)
7935 // test pet/charm masters instead pers/charmeds
7936 Unit
const* testerOwner
= GetCharmerOrOwner();
7937 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
7939 // always non-friendly to owner's enemy
7940 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
7943 // always non-friendly to enemy owner
7944 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
7947 // always non-friendly to owner of owner's enemy
7948 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
7951 Unit
const* tester
= testerOwner
? testerOwner
: this;
7952 Unit
const* target
= targetOwner
? targetOwner
: unit
;
7954 // always friendly to target with common owner, or to owner/pet
7958 // special cases (Duel)
7959 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
7961 Player
const* pTester
= (Player
const*)tester
;
7962 Player
const* pTarget
= (Player
const*)target
;
7965 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
7969 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
7973 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
7977 if(pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
) && pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
))
7981 // Green/Blue (non-attackable)
7982 if(pTester
->GetTeam()==pTarget
->GetTeam())
7985 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
7986 return !pTarget
->IsPvP();
7989 // faction base cases
7990 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
7991 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
7992 if(!tester_faction
|| !target_faction
)
7995 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
7998 // PvC forced reaction and reputation case
7999 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8002 if(target_faction
->faction
)
8004 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8005 return *force
>= REP_FRIENDLY
;
8007 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
8008 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8009 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8010 return !(factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8013 // CvP forced reaction and reputation case
8014 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8017 if(tester_faction
->faction
)
8019 if(ReputationRank
const* force
=((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8020 return *force
>= REP_FRIENDLY
;
8022 // apply reputation state
8023 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
8024 if(raw_tester_faction
->reputationListID
>=0 )
8025 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) >= REP_FRIENDLY
;
8029 // common faction based case (CvC,PvC,CvP)
8030 return tester_faction
->IsFriendlyTo(*target_faction
);
8033 bool Unit::IsHostileToPlayers() const
8035 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8036 if(!my_faction
|| !my_faction
->faction
)
8039 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8040 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8043 return my_faction
->IsHostileToPlayers();
8046 bool Unit::IsNeutralToAll() const
8048 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8049 if(!my_faction
|| !my_faction
->faction
)
8052 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8053 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8056 return my_faction
->IsNeutralToAll();
8059 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
8061 if(!victim
|| victim
== this)
8064 // dead units can neither attack nor be attacked
8065 if(!isAlive() || !victim
->IsInWorld() || !victim
->isAlive())
8068 // player cannot attack in mount state
8069 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
8072 // nobody can attack GM in GM-mode
8073 if(victim
->GetTypeId()==TYPEID_PLAYER
)
8075 if(((Player
*)victim
)->isGameMaster())
8080 if(((Creature
*)victim
)->IsInEvadeMode())
8084 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
8085 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
8086 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
8088 // in fighting already
8091 if (m_attacking
== victim
)
8093 // switch to melee attack from ranged/magic
8094 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
8096 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8097 SendMeleeAttackStart(victim
);
8103 // remove old target data
8109 // set position before any AI calls/assistance
8110 if(GetTypeId()==TYPEID_UNIT
)
8111 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
8115 SetTargetGUID(victim
->GetGUID());
8118 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8120 m_attacking
= victim
;
8121 m_attacking
->_addAttacker(this);
8123 if (GetTypeId() == TYPEID_UNIT
)
8125 ((Creature
*)this)->SendAIReaction(AI_REACTION_AGGRO
);
8126 ((Creature
*)this)->CallAssistance();
8129 // delay offhand weapon attack to next attack time
8130 if(haveOffhandWeapon())
8131 resetAttackTimer(OFF_ATTACK
);
8134 SendMeleeAttackStart(victim
);
8139 bool Unit::AttackStop(bool targetSwitch
/*=false*/)
8144 Unit
* victim
= m_attacking
;
8146 m_attacking
->_removeAttacker(this);
8152 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
8154 InterruptSpell(CURRENT_MELEE_SPELL
);
8156 // reset only at real combat stop
8157 if(!targetSwitch
&& GetTypeId()==TYPEID_UNIT
)
8159 ((Creature
*)this)->SetNoCallAssistance(false);
8160 ((Creature
*)this)->SetNoSearchAssistance(false);
8163 SendMeleeAttackStop(victim
);
8168 void Unit::CombatStop(bool includingCast
)
8170 if (includingCast
&& IsNonMeleeSpellCasted(false))
8171 InterruptNonMeleeSpells(false);
8174 RemoveAllAttackers();
8175 if( GetTypeId()==TYPEID_PLAYER
)
8176 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
8180 void Unit::CombatStopWithPets(bool includingCast
)
8182 CombatStop(includingCast
);
8183 if(Pet
* pet
= GetPet())
8184 pet
->CombatStop(includingCast
);
8185 if(Unit
* charm
= GetCharm())
8186 charm
->CombatStop(includingCast
);
8188 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
8189 if(Unit
* guardian
= Unit::GetUnit(*this,*itr
))
8190 guardian
->CombatStop(includingCast
);
8193 bool Unit::isAttackingPlayer() const
8195 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
8198 Pet
* pet
= GetPet();
8199 if(pet
&& pet
->isAttackingPlayer())
8202 Unit
* charmed
= GetCharm();
8203 if(charmed
&& charmed
->isAttackingPlayer())
8206 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
8210 Creature
*totem
= GetMap()->GetCreature(m_TotemSlot
[i
]);
8211 if(totem
&& totem
->isAttackingPlayer())
8219 void Unit::RemoveAllAttackers()
8221 while (!m_attackers
.empty())
8223 AttackerSet::iterator iter
= m_attackers
.begin();
8224 if(!(*iter
)->AttackStop())
8226 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
8227 m_attackers
.erase(iter
);
8232 bool Unit::HasAuraStateForCaster(AuraState flag
, uint64 caster
) const
8234 if(!HasAuraState(flag
))
8237 // single per-caster aura state
8238 if(flag
== AURA_STATE_CONFLAGRATE
)
8240 Unit::AuraList
const& dotList
= GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
8241 for(Unit::AuraList::const_iterator i
= dotList
.begin(); i
!= dotList
.end(); ++i
)
8243 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
8244 (*i
)->GetCasterGUID() == caster
&&
8246 (((*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000004)) ||
8248 ((*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x00000002)))
8260 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
8264 if (!HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)))
8266 SetFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8267 if(GetTypeId() == TYPEID_PLAYER
)
8269 const PlayerSpellMap
& sp_list
= ((Player
*)this)->GetSpellMap();
8270 for (PlayerSpellMap::const_iterator itr
= sp_list
.begin(); itr
!= sp_list
.end(); ++itr
)
8272 if(itr
->second
->state
== PLAYERSPELL_REMOVED
) continue;
8273 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
8274 if (!spellInfo
|| !IsPassiveSpell(itr
->first
)) continue;
8275 if (spellInfo
->CasterAuraState
== flag
)
8276 CastSpell(this, itr
->first
, true, NULL
);
8283 if (HasFlag(UNIT_FIELD_AURASTATE
,1<<(flag
-1)))
8285 RemoveFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8287 if (flag
!= AURA_STATE_ENRAGE
) // enrage aura state triggering continues auras
8289 Unit::AuraMap
& tAuras
= GetAuras();
8290 for (Unit::AuraMap::iterator itr
= tAuras
.begin(); itr
!= tAuras
.end();)
8292 SpellEntry
const* spellProto
= (*itr
).second
->GetSpellProto();
8293 if (spellProto
->CasterAuraState
== flag
)
8295 // exceptions (applied at state but not removed at state change)
8297 if(spellProto
->SpellIconID
==2006 && spellProto
->SpellFamilyName
==SPELLFAMILY_WARRIOR
&& spellProto
->SpellFamilyFlags
==0x100000)
8313 Unit
*Unit::GetOwner() const
8315 if(uint64 ownerid
= GetOwnerGUID())
8316 return ObjectAccessor::GetUnit(*this, ownerid
);
8320 Unit
*Unit::GetCharmer() const
8322 if(uint64 charmerid
= GetCharmerGUID())
8323 return ObjectAccessor::GetUnit(*this, charmerid
);
8327 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
8329 uint64 guid
= GetCharmerOrOwnerGUID();
8330 if(IS_PLAYER_GUID(guid
))
8331 return ObjectAccessor::FindPlayer(guid
);
8333 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
8336 Pet
* Unit::GetPet() const
8338 if(uint64 pet_guid
= GetPetGUID())
8340 if(Pet
* pet
= GetMap()->GetPet(pet_guid
))
8343 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
8344 const_cast<Unit
*>(this)->SetPet(0);
8350 Unit
* Unit::GetCharm() const
8352 if (uint64 charm_guid
= GetCharmGUID())
8354 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
8357 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
8358 const_cast<Unit
*>(this)->SetCharm(NULL
);
8364 void Unit::Uncharm()
8366 if (Unit
* charm
= GetCharm())
8368 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM
);
8369 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS
);
8373 float Unit::GetCombatDistance( const Unit
* target
) const
8375 float radius
= target
->GetFloatValue(UNIT_FIELD_COMBATREACH
) + GetFloatValue(UNIT_FIELD_COMBATREACH
);
8376 float dx
= GetPositionX() - target
->GetPositionX();
8377 float dy
= GetPositionY() - target
->GetPositionY();
8378 float dz
= GetPositionZ() - target
->GetPositionZ();
8379 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - radius
;
8380 return ( dist
> 0 ? dist
: 0);
8383 void Unit::SetPet(Pet
* pet
)
8385 SetPetGUID(pet
? pet
->GetGUID() : 0);
8387 if(pet
&& GetTypeId() == TYPEID_PLAYER
)
8388 ((Player
*)this)->SendPetGUIDs();
8390 // FIXME: hack, speed must be set only at follow
8391 if(pet
&& GetTypeId()==TYPEID_PLAYER
)
8392 for(int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
8393 pet
->SetSpeed(UnitMoveType(i
), m_speed_rate
[i
], true);
8396 void Unit::SetCharm(Unit
* pet
)
8398 SetCharmGUID(pet
? pet
->GetGUID() : 0);
8401 void Unit::AddGuardian( Pet
* pet
)
8403 m_guardianPets
.insert(pet
->GetGUID());
8406 void Unit::RemoveGuardian( Pet
* pet
)
8408 m_guardianPets
.erase(pet
->GetGUID());
8411 void Unit::RemoveGuardians()
8413 while(!m_guardianPets
.empty())
8415 uint64 guid
= *m_guardianPets
.begin();
8416 if(Pet
* pet
= GetMap()->GetPet(guid
))
8417 pet
->Remove(PET_SAVE_AS_DELETED
);
8419 m_guardianPets
.erase(guid
);
8423 Pet
* Unit::FindGuardianWithEntry(uint32 entry
)
8425 // pet guid middle part is entry (and creature also)
8426 // and in guardian list must be guardians with same entry _always_
8427 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
8428 if(Pet
* pet
= GetMap()->GetPet(*itr
))
8429 if (pet
->GetEntry() == entry
)
8435 void Unit::UnsummonAllTotems()
8437 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
8442 Creature
*OldTotem
= GetMap()->GetCreature(m_TotemSlot
[i
]);
8443 if (OldTotem
&& OldTotem
->isTotem())
8444 ((Totem
*)OldTotem
)->UnSummon();
8448 int32
Unit::DealHeal(Unit
*pVictim
, uint32 addhealth
, SpellEntry
const *spellProto
, bool critical
)
8450 int32 gain
= pVictim
->ModifyHealth(int32(addhealth
));
8454 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8457 if (unit
->GetTypeId()==TYPEID_PLAYER
)
8459 // overheal = addhealth - gain
8460 unit
->SendHealSpellLog(pVictim
, spellProto
->Id
, addhealth
, addhealth
- gain
, critical
);
8462 if (BattleGround
*bg
= ((Player
*)unit
)->GetBattleGround())
8463 bg
->UpdatePlayerScore((Player
*)unit
, SCORE_HEALING_DONE
, gain
);
8465 // use the actual gain, as the overheal shall not be counted, skip gain 0 (it ignored anyway in to criteria)
8467 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE
, gain
, 0, pVictim
);
8469 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED
, addhealth
);
8472 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
8474 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED
, gain
);
8475 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED
, addhealth
);
8481 Unit
* Unit::SelectMagnetTarget(Unit
*victim
, SpellEntry
const *spellInfo
)
8487 if(spellInfo
&& (spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
|| spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
))
8489 Unit::AuraList
const& magnetAuras
= victim
->GetAurasByType(SPELL_AURA_SPELL_MAGNET
);
8490 for(Unit::AuraList::const_iterator itr
= magnetAuras
.begin(); itr
!= magnetAuras
.end(); ++itr
)
8491 if(Unit
* magnet
= (*itr
)->GetCaster())
8492 if(magnet
->IsWithinLOSInMap(this) && magnet
->isAlive())
8495 // Melee && ranged case
8498 AuraList
const& hitTriggerAuras
= victim
->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER
);
8499 for(AuraList::const_iterator i
= hitTriggerAuras
.begin(); i
!= hitTriggerAuras
.end(); ++i
)
8500 if(Unit
* magnet
= (*i
)->GetCaster())
8501 if(magnet
->isAlive() && magnet
->IsWithinLOSInMap(this))
8502 if(roll_chance_i((*i
)->GetModifier()->m_amount
))
8509 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, uint32 OverHeal
, bool critical
)
8512 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
8513 data
.append(pVictim
->GetPackGUID());
8514 data
.append(GetPackGUID());
8515 data
<< uint32(SpellID
);
8516 data
<< uint32(Damage
);
8517 data
<< uint32(OverHeal
);
8518 data
<< uint8(critical
? 1 : 0);
8519 data
<< uint8(0); // unused in client?
8520 SendMessageToSet(&data
, true);
8523 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8525 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
8526 data
.append(pVictim
->GetPackGUID());
8527 data
.append(GetPackGUID());
8528 data
<< uint32(SpellID
);
8529 data
<< uint32(powertype
);
8530 data
<< uint32(Damage
);
8531 SendMessageToSet(&data
, true);
8534 void Unit::EnergizeBySpell(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8536 SendEnergizeSpellLog(pVictim
, SpellID
, Damage
, powertype
);
8537 // needs to be called after sending spell log
8538 pVictim
->ModifyPower(powertype
, Damage
);
8541 uint32
Unit::SpellDamageBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
8543 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
8546 // For totems get damage bonus from owner (statue isn't totem in fact)
8547 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8549 if(Unit
* owner
= GetOwner())
8550 return owner
->SpellDamageBonus(pVictim
, spellProto
, pdamage
, damagetype
);
8553 // Taken/Done total percent damage auras
8554 float DoneTotalMod
= 1.0f
;
8555 float TakenTotalMod
= 1.0f
;
8556 int32 DoneTotal
= 0;
8557 int32 TakenTotal
= 0;
8561 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
8562 DoneTotalMod
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
8564 if (!(spellProto
->AttributesEx6
& SPELL_ATTR_EX6_NO_DMG_PERCENT_MODS
))
8566 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
8567 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
8569 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
8570 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
8571 // -1 == any item class (not wand then)
8572 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
8573 // 0 == any inventory type (not wand then)
8575 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8580 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8581 // Add flat bonus from spell damage versus
8582 DoneTotal
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
8583 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
8584 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
8585 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8586 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8588 // done scripted mod (take it from owner)
8589 Unit
*owner
= GetOwner();
8590 if (!owner
) owner
= this;
8591 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8592 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
8594 if (!(*i
)->isAffectedOnSpell(spellProto
))
8596 switch((*i
)->GetModifier()->m_miscvalue
)
8598 case 4920: // Molten Fury
8600 case 6917: // Death's Embrace
8604 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8605 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8612 // effect 1 m_amount
8613 int32 maxPercent
= (*i
)->GetModifier()->m_amount
;
8614 // effect 0 m_amount
8615 int32 stepPercent
= CalculateSpellDamage((*i
)->GetSpellProto(), 0, (*i
)->GetSpellProto()->EffectBasePoints
[0], this);
8616 // count affliction effects and calc additional damage in percentage
8617 int32 modPercent
= 0;
8618 AuraMap
const& victimAuras
= pVictim
->GetAuras();
8619 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
8621 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
8622 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_WARLOCK
|| !(m_spell
->SpellFamilyFlags
& UI64LIT(0x0004071B8044C402)))
8624 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
8625 if (modPercent
>= maxPercent
)
8627 modPercent
= maxPercent
;
8631 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
8634 case 6916: // Death's Embrace
8637 if (HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
))
8638 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8640 case 5481: // Starfire Bonus
8642 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000200002)))
8643 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8646 case 4418: // Increased Shock Damage
8647 case 4554: // Increased Lightning Damage
8648 case 4555: // Improved Moonfire
8649 case 5142: // Increased Lightning Damage
8650 case 5147: // Improved Consecration / Libram of Resurgence
8651 case 5148: // Idol of the Shooting Star
8652 case 6008: // Increased Lightning Damage / Totem of Hex
8654 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
8662 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
8664 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8665 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8667 else // Tundra Stalker
8669 // Frost Fever (target debuff)
8670 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
8671 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8676 case 7293: // Rage of Rivendare
8678 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
8679 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8685 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000000000008000), 0, GetGUID()))
8686 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8696 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
8697 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8703 // Custom scripted damage
8704 switch(spellProto
->SpellFamilyName
)
8706 case SPELLFAMILY_MAGE
:
8709 if (spellProto
->SpellIconID
== 186)
8711 if (pVictim
->isFrozen())
8713 float multiplier
= 3.0f
;
8715 // if target have higher level
8716 if (pVictim
->getLevel() > getLevel())
8717 // Glyph of Ice Lance
8718 if (Aura
* glyph
= GetDummyAura(56377))
8719 multiplier
= glyph
->GetModifier()->m_amount
;
8721 DoneTotalMod
*= multiplier
;
8724 // Torment the weak affected (Arcane Barrage, Arcane Blast, Frostfire Bolt, Arcane Missiles, Fireball)
8725 if ((spellProto
->SpellFamilyFlags
& UI64LIT(0x0000900020200021)) &&
8726 (pVictim
->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED
) || pVictim
->HasAuraType(SPELL_AURA_MELEE_SLOW
)))
8728 //Search for Torment the weak dummy aura
8729 Unit::AuraList
const& ttw
= GetAurasByType(SPELL_AURA_DUMMY
);
8730 for(Unit::AuraList::const_iterator i
= ttw
.begin(); i
!= ttw
.end(); ++i
)
8732 if ((*i
)->GetSpellProto()->SpellIconID
== 3263)
8734 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
8741 case SPELLFAMILY_WARLOCK
:
8744 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
8746 if (pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth() <= 25)
8751 case SPELLFAMILY_DEATHKNIGHT
:
8753 // Icy Touch, Howling Blast and Frost Strike
8754 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000600000002))
8758 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
8759 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
8761 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
8770 // search for Glacier Rot dummy aura
8771 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
8772 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
8774 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
8776 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
8789 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
8790 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
8792 if ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
))
8793 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
8796 // .. taken pct: dummy auras
8797 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
8800 if (Aura
*dummy
= pVictim
->GetDummyAura(45182))
8802 float mod
= -((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
8803 if (mod
< dummy
->GetModifier()->m_amount
)
8804 mod
= dummy
->GetModifier()->m_amount
;
8805 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
8809 // From caster spells
8810 AuraList
const& mOwnerTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_FROM_CASTER
);
8811 for(AuraList::const_iterator i
= mOwnerTaken
.begin(); i
!= mOwnerTaken
.end(); ++i
)
8813 if ((*i
)->GetCasterGUID() == GetGUID() && (*i
)->isAffectedOnSpell(spellProto
))
8814 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
8817 // Mod damage from spell mechanic
8818 TakenTotalMod
*= pVictim
->GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,GetAllSpellMechanicMask(spellProto
));
8820 // Mod damage taken from AoE spells
8821 if(IsAreaOfEffectSpell(spellProto
))
8823 AuraList
const& avoidAuras
= pVictim
->GetAurasByType(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
8824 for(AuraList::const_iterator itr
= avoidAuras
.begin(); itr
!= avoidAuras
.end(); ++itr
)
8825 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
8828 // Taken/Done fixed damage bonus auras
8829 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonus(GetSpellSchoolMask(spellProto
));
8830 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
8832 // Pets just add their bonus damage to their spell damage
8833 // note that their spell damage is just gain of their own auras
8834 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
8835 DoneAdvertisedBenefit
+= ((Pet
*)this)->GetBonusDamage();
8837 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
8838 // Spellmod SpellDamage
8839 float SpellModSpellDamage
= 100.0f
;
8840 if(Player
* modOwner
= GetSpellModOwner())
8841 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
8842 SpellModSpellDamage
/= 100.0f
;
8844 // Check for table values
8845 if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
8848 if (damagetype
== DOT
)
8849 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
8851 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
8853 if (bonus
->ap_bonus
)
8854 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
) * stack
);
8856 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* SpellModSpellDamage
);
8857 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
);
8859 // Default calculation
8860 else if (DoneAdvertisedBenefit
|| TakenAdvertisedBenefit
)
8862 // Damage over Time spells bonus calculation
8863 float DotFactor
= 1.0f
;
8864 if (damagetype
== DOT
)
8866 if (!IsChanneledSpell(spellProto
))
8867 DotFactor
= GetSpellDuration(spellProto
) / 15000.0f
;
8869 if (uint16 DotTicks
= GetSpellAuraMaxTicks(spellProto
))
8871 DoneAdvertisedBenefit
= DoneAdvertisedBenefit
* int32(stack
) / DotTicks
;
8872 TakenAdvertisedBenefit
= TakenAdvertisedBenefit
* int32(stack
) / DotTicks
;
8875 // Distribute Damage over multiple effects, reduce by AoE
8876 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
8877 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
8878 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
8879 for(int j
= 0; j
< 3; ++j
)
8881 if (spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
8882 (spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&&
8883 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
))
8889 DoneTotal
+= int32(DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* SpellModSpellDamage
);
8890 TakenTotal
+= int32(TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
);
8893 float tmpDamage
= (pdamage
+ DoneTotal
) * DoneTotalMod
;
8894 // apply spellmod to Done damage (flat and pct)
8895 if(Player
* modOwner
= GetSpellModOwner())
8896 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
8898 tmpDamage
= (tmpDamage
+ TakenTotal
) * TakenTotalMod
;
8900 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
8903 int32
Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask
)
8905 int32 DoneAdvertisedBenefit
= 0;
8908 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
8909 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
8911 if (((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
8912 (*i
)->GetSpellProto()->EquippedItemClass
== -1 && // -1 == any item class (not wand then)
8913 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0) // 0 == any inventory type (not wand then)
8914 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8917 if (GetTypeId() == TYPEID_PLAYER
)
8920 DoneAdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
8922 // Damage bonus from stats
8923 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
8924 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
8926 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
8928 // stat used stored in miscValueB for this aura
8929 Stats usedStat
= Stats((*i
)->GetMiscBValue());
8930 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
8933 // ... and attack power
8934 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
8935 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
8937 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
8938 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
8942 return DoneAdvertisedBenefit
;
8945 int32
Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
8947 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8949 int32 TakenAdvertisedBenefit
= 0;
8950 // ..done (for creature type by mask) in taken
8951 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
8952 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
8954 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8955 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8959 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
8960 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
8962 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
8963 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8966 return TakenAdvertisedBenefit
;
8969 bool Unit::isSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
8971 // not critting spell
8972 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
8975 float crit_chance
= 0.0f
;
8976 switch(spellProto
->DmgClass
)
8978 case SPELL_DAMAGE_CLASS_NONE
:
8980 case SPELL_DAMAGE_CLASS_MAGIC
:
8982 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
8984 // For other schools
8985 else if (GetTypeId() == TYPEID_PLAYER
)
8986 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
8989 crit_chance
= m_baseSpellCritChance
;
8990 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
8995 if (!IsPositiveSpell(spellProto
->Id
))
8997 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
8998 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
8999 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
9000 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
9001 // Modify by player victim resilience
9002 crit_chance
-= pVictim
->GetSpellCritChanceReduction();
9005 // scripted (increase crit chance ... against ... target by x%)
9006 // scripted (Increases the critical effect chance of your .... by x% on targets ...)
9007 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9008 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9010 if (!((*i
)->isAffectedOnSpell(spellProto
)))
9012 switch((*i
)->GetModifier()->m_miscvalue
)
9014 case 849: if (pVictim
->isFrozen()) crit_chance
+= 17.0f
; break; //Shatter Rank 1
9015 case 910: if (pVictim
->isFrozen()) crit_chance
+= 34.0f
; break; //Shatter Rank 2
9016 case 911: if (pVictim
->isFrozen()) crit_chance
+= 50.0f
; break; //Shatter Rank 3
9017 case 7917: // Glyph of Shadowburn
9018 if (pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9019 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9021 case 7997: // Renewed Hope
9023 if (pVictim
->HasAura(6788))
9024 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9030 // Custom crit by class
9031 switch(spellProto
->SpellFamilyName
)
9033 case SPELLFAMILY_PRIEST
:
9035 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000800))
9037 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth()/2)
9039 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9040 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9042 // Improved Flash Heal
9043 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_PRIEST
&&
9044 (*i
)->GetSpellProto()->SpellIconID
== 2542)
9046 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9052 case SPELLFAMILY_PALADIN
:
9054 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000040000000))
9056 Aura
*aura
= pVictim
->GetDummyAura(58597);
9057 if (aura
&& aura
->GetCasterGUID() == GetGUID())
9058 crit_chance
+=aura
->GetModifier()->m_amount
;
9061 else if (spellProto
->Category
== 19)
9063 if (pVictim
->GetCreatureTypeMask() & CREATURE_TYPEMASK_DEMON_OR_UNDEAD
)
9067 case SPELLFAMILY_SHAMAN
:
9069 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000100000000000))
9072 if (Aura
*flameShock
= pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000000010000000), 0, GetGUID()))
9080 case SPELL_DAMAGE_CLASS_MELEE
:
9081 case SPELL_DAMAGE_CLASS_RANGED
:
9084 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
9086 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9093 // only players use intelligence for critical chance computations
9094 if(Player
* modOwner
= GetSpellModOwner())
9095 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
9097 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
9098 if (roll_chance_f(crit_chance
))
9103 uint32
Unit::SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9105 // Calculate critical bonus
9107 switch(spellProto
->DmgClass
)
9109 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9110 case SPELL_DAMAGE_CLASS_RANGED
:
9111 crit_bonus
= damage
;
9114 crit_bonus
= damage
/ 2; // for spells is 50%
9118 // adds additional damage to crit_bonus (from talents)
9119 if(Player
* modOwner
= GetSpellModOwner())
9120 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
9123 return damage
+= crit_bonus
;
9125 int32 critPctDamageMod
= 0;
9126 if(spellProto
->DmgClass
>= SPELL_DAMAGE_CLASS_MELEE
)
9128 if(GetWeaponAttackType(spellProto
) == RANGED_ATTACK
)
9129 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
9131 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
9134 critPctDamageMod
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_DAMAGE
,GetSpellSchoolMask(spellProto
));
9136 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, GetSpellSchoolMask(spellProto
));
9138 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9139 critPctDamageMod
+= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
);
9141 if(critPctDamageMod
!=0)
9142 crit_bonus
= int32(crit_bonus
* float((100.0f
+ critPctDamageMod
)/100.0f
));
9145 damage
+= crit_bonus
;
9150 uint32
Unit::SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9152 // Calculate critical bonus
9154 switch(spellProto
->DmgClass
)
9156 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9157 case SPELL_DAMAGE_CLASS_RANGED
:
9158 // TODO: write here full calculation for melee/ranged spells
9159 crit_bonus
= damage
;
9162 crit_bonus
= damage
/ 2; // for spells is 50%
9168 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9169 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
9173 damage
+= crit_bonus
;
9175 damage
= int32(damage
* GetTotalAuraMultiplier(SPELL_AURA_MOD_CRITICAL_HEALING_AMOUNT
));
9180 uint32
Unit::SpellHealingBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9182 // No heal amount for this class spells
9183 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9186 // For totems get healing bonus from owner (statue isn't totem in fact)
9187 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
9188 if(Unit
* owner
= GetOwner())
9189 return owner
->SpellHealingBonus(pVictim
, spellProto
, healamount
, damagetype
, stack
);
9192 // Taken/Done total percent damage auras
9193 float DoneTotalMod
= 1.0f
;
9194 float TakenTotalMod
= 1.0f
;
9195 int32 DoneTotal
= 0;
9196 int32 TakenTotal
= 0;
9198 // Healing done percent
9199 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
9200 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
9201 DoneTotalMod
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
9203 // done scripted mod (take it from owner)
9204 Unit
*owner
= GetOwner();
9205 if (!owner
) owner
= this;
9206 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9207 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9209 if (!(*i
)->isAffectedOnSpell(spellProto
))
9211 switch((*i
)->GetModifier()->m_miscvalue
)
9213 case 4415: // Increased Rejuvenation Healing
9215 case 3736: // Hateful Totem of the Third Wind / Increased Lesser Healing Wave / LK Arena (4/5/6) Totem of the Third Wind / Savage Totem of the Third Wind
9216 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
9218 case 7997: // Renewed Hope
9220 if (pVictim
->HasAura(6788))
9221 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9223 case 21: // Test of Faith
9226 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
9227 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9229 case 7798: // Glyph of Regrowth
9231 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_HEAL
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000000040)))
9232 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9235 case 8477: // Nourish Heal Boost
9237 int32 stepPercent
= (*i
)->GetModifier()->m_amount
;
9238 int32 modPercent
= 0;
9239 AuraMap
const& victimAuras
= pVictim
->GetAuras();
9240 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
9242 if (itr
->second
->GetCasterGUID()!=GetGUID())
9244 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
9245 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_DRUID
||
9246 !(m_spell
->SpellFamilyFlags
& UI64LIT(0x0000001000000050)))
9248 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
9250 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
9253 case 7871: // Glyph of Lesser Healing Wave
9255 if (pVictim
->GetAura(SPELL_AURA_DUMMY
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000040000000000), 0, GetGUID()))
9256 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9264 // Taken/Done fixed damage bonus auras
9265 int32 DoneAdvertisedBenefit
= SpellBaseHealingBonus(GetSpellSchoolMask(spellProto
));
9266 int32 TakenAdvertisedBenefit
= SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
9268 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9269 // Spellmod SpellDamage
9270 float SpellModSpellDamage
= 100.0f
;
9271 if(Player
* modOwner
= GetSpellModOwner())
9272 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_SPELL_BONUS_DAMAGE
, SpellModSpellDamage
);
9273 SpellModSpellDamage
/= 100.0f
;
9275 // Check for table values
9276 SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
);
9280 if (damagetype
== DOT
)
9281 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
9283 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
9285 if (bonus
->ap_bonus
)
9286 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
) * stack
);
9288 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* SpellModSpellDamage
);
9289 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
);
9291 // Default calculation
9292 else if (DoneAdvertisedBenefit
|| TakenAdvertisedBenefit
)
9294 // Damage over Time spells bonus calculation
9295 float DotFactor
= 1.0f
;
9296 if(damagetype
== DOT
)
9298 if(!IsChanneledSpell(spellProto
))
9299 DotFactor
= GetSpellDuration(spellProto
) / 15000.0f
;
9300 uint16 DotTicks
= GetSpellAuraMaxTicks(spellProto
);
9303 DoneAdvertisedBenefit
= DoneAdvertisedBenefit
* int32(stack
) / DotTicks
;
9304 TakenAdvertisedBenefit
= TakenAdvertisedBenefit
* int32(stack
) / DotTicks
;
9307 // Distribute Damage over multiple effects, reduce by AoE
9308 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
9309 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
9310 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
9311 for(int j
= 0; j
< 3; ++j
)
9313 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
9314 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
9320 DoneTotal
+= int32(DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* SpellModSpellDamage
* 1.88f
);
9321 TakenTotal
+= int32(TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* 1.88f
);
9324 // use float as more appropriate for negative values and percent applying
9325 float heal
= (healamount
+ DoneTotal
)*DoneTotalMod
;
9326 // apply spellmod to Done amount
9327 if(Player
* modOwner
= GetSpellModOwner())
9328 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
9331 // Healing Wave cast
9332 if (spellProto
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000040)))
9334 // Search for Healing Way on Victim
9335 Unit::AuraList
const& auraDummy
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
9336 for(Unit::AuraList::const_iterator itr
= auraDummy
.begin(); itr
!=auraDummy
.end(); ++itr
)
9337 if((*itr
)->GetId() == 29203)
9338 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9341 // Healing taken percent
9342 float minval
= pVictim
->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
9344 TakenTotalMod
*= (100.0f
+ minval
) / 100.0f
;
9346 float maxval
= pVictim
->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
9348 TakenTotalMod
*= (100.0f
+ maxval
) / 100.0f
;
9350 AuraList
const& mHealingGet
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING_RECEIVED
);
9351 for(AuraList::const_iterator i
= mHealingGet
.begin(); i
!= mHealingGet
.end(); ++i
)
9352 if ((*i
)->isAffectedOnSpell(spellProto
))
9353 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9355 heal
= (heal
+ TakenTotal
) * TakenTotalMod
;
9357 return heal
< 0 ? 0 : uint32(heal
);
9360 int32
Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask
)
9362 int32 AdvertisedBenefit
= 0;
9364 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
9365 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
9366 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9367 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9369 // Healing bonus of spirit, intellect and strength
9370 if (GetTypeId() == TYPEID_PLAYER
)
9373 AdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9375 // Healing bonus from stats
9376 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
9377 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
9379 // stat used dependent from misc value (stat index)
9380 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
9381 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9384 // ... and attack power
9385 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
9386 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
9387 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9388 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9390 return AdvertisedBenefit
;
9393 int32
Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
9395 int32 AdvertisedBenefit
= 0;
9396 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING
);
9397 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9398 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9399 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9401 return AdvertisedBenefit
;
9404 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
)
9406 //If m_immuneToSchool type contain this school type, IMMUNE damage.
9407 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9408 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9409 if (itr
->type
& shoolMask
)
9412 //If m_immuneToDamage type contain magic, IMMUNE damage.
9413 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
9414 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
9415 if (itr
->type
& shoolMask
)
9421 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
)
9426 //TODO add spellEffect immunity checks!, player with flag in bg is imune to imunity buffs from other friendly players!
9427 //SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_EFFECT];
9429 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
9430 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
9431 if (itr
->type
== spellInfo
->Dispel
)
9434 if (!(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
) && // unaffected by school immunity
9435 !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)) // can remove immune (by dispell or immune it)
9437 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9438 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9439 if (!(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
9440 (itr
->type
& GetSpellSchoolMask(spellInfo
)))
9444 if(uint32 mechanic
= spellInfo
->Mechanic
)
9446 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9447 for(SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9448 if (itr
->type
== mechanic
)
9451 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9452 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9453 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9460 bool Unit::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, uint32 index
) const
9462 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
9463 uint32 effect
= spellInfo
->Effect
[index
];
9464 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
9465 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
9466 if (itr
->type
== effect
)
9469 if(uint32 mechanic
= spellInfo
->EffectMechanic
[index
])
9471 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9472 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9473 if (itr
->type
== mechanic
)
9476 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9477 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9478 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9482 if(uint32 aura
= spellInfo
->EffectApplyAuraName
[index
])
9484 SpellImmuneList
const& list
= m_spellImmune
[IMMUNITY_STATE
];
9485 for(SpellImmuneList::const_iterator itr
= list
.begin(); itr
!= list
.end(); ++itr
)
9486 if (itr
->type
== aura
)
9489 // Check for immune to application of harmful magical effects
9490 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL
);
9491 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9492 if (spellInfo
->Dispel
== DISPEL_MAGIC
&& // Magic debuff
9493 ((*iter
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellInfo
)) && // Check school
9494 !IsPositiveEffect(spellInfo
->Id
, index
)) // Harmful
9501 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
9506 uint32 family
= spellInfo
->SpellFamilyName
;
9507 uint64 flags
= spellInfo
->SpellFamilyFlags
;
9509 if ((family
== 5 && flags
== 256) || //Searing Pain
9510 (family
== 6 && flags
== 8192) || //Mind Blast
9511 (family
== 11 && flags
== 1048576)) //Earth Shock
9517 uint32
Unit::MeleeDamageBonus(Unit
*pVictim
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
9525 // differentiate for weapon damage based spells
9526 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
9527 Item
* pWeapon
= GetTypeId() == TYPEID_PLAYER
? ((Player
*)this)->GetWeaponForAttack(attType
,true,false) : NULL
;
9528 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9529 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
9530 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
9532 // Shred also have bonus as MECHANIC_BLEED damages
9533 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
9534 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
9537 // FLAT damage bonus auras
9538 // =======================
9540 int32 TakenFlat
= 0;
9543 // ..done flat, already included in wepon damage based spells
9544 if (!isWeaponDamageBasedSpell
)
9546 AuraList
const& mModDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9547 for(AuraList::const_iterator i
= mModDamageDone
.begin(); i
!= mModDamageDone
.end(); ++i
)
9549 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9550 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9551 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9552 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
9554 DoneFlat
+= (*i
)->GetModifier()->m_amount
;
9558 // Pets just add their bonus damage to their melee damage
9559 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9560 DoneFlat
+= ((Pet
*)this)->GetBonusDamage();
9563 // ..done flat (by creature type mask)
9564 DoneFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
, creatureTypeMask
);
9566 // ..done flat (base at attack power for marked target and base at attack power for creature type)
9567 if (attType
== RANGED_ATTACK
)
9569 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
9570 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9571 TakenFlat
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
9575 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
9576 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9577 TakenFlat
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
9580 // ..taken flat (by school mask)
9581 TakenFlat
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_TAKEN
, schoolMask
);
9583 // PERCENT damage auras
9584 // ====================
9585 float DonePercent
= 1.0f
;
9586 float TakenPercent
= 1.0f
;
9588 // ..done pct, already included in weapon damage based spells
9589 if(!isWeaponDamageBasedSpell
)
9591 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
9592 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
9594 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9595 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9596 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9597 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
9599 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9603 if (attType
== OFF_ATTACK
)
9604 DonePercent
*= GetModifierValue(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_PCT
); // no school check required
9607 // ..done pct (by creature type mask)
9608 DonePercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
, creatureTypeMask
);
9610 // ..taken pct (by school mask)
9611 TakenPercent
*= pVictim
->GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
, schoolMask
);
9613 // ..taken pct (by mechanic mask)
9614 TakenPercent
*= pVictim
->GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,mechanicMask
);
9616 // ..taken pct (melee/ranged)
9617 if(attType
== RANGED_ATTACK
)
9618 TakenPercent
*= pVictim
->GetTotalAuraMultiplier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
9620 TakenPercent
*= pVictim
->GetTotalAuraMultiplier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
9622 // ..taken pct (aoe avoidance)
9623 if(spellProto
&& IsAreaOfEffectSpell(spellProto
))
9624 TakenPercent
*= pVictim
->GetTotalAuraMultiplier(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
9627 // special dummys/class sripts and other effects
9628 // =============================================
9629 Unit
*owner
= GetOwner();
9633 // ..done (class scripts)
9636 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9637 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9639 if (!(*i
)->isAffectedOnSpell(spellProto
))
9642 switch((*i
)->GetModifier()->m_miscvalue
)
9649 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
9651 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9652 DonePercent
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
9654 else // Tundra Stalker
9656 // Frost Fever (target debuff)
9657 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
9658 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9663 case 7293: // Rage of Rivendare
9665 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
9666 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9676 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
9677 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9684 // .. taken (dummy auras)
9685 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
9686 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9688 switch((*i
)->GetSpellProto()->SpellIconID
)
9692 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
9694 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
9697 float mod
= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
9698 if (mod
< (*i
)->GetModifier()->m_amount
)
9699 mod
= (*i
)->GetModifier()->m_amount
;
9701 TakenPercent
*= (mod
+ 100.0f
) / 100.0f
;
9707 // .. taken (class scripts)
9708 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9709 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
9711 switch((*i
)->GetMiscValue())
9716 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9718 Aura
* eff0
= GetAura((*i
)->GetId(), 0);
9719 if (!eff0
|| (*i
)->GetEffIndex() != 1)
9721 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
9725 // effect 0 have expected value but in negative state
9726 TakenPercent
*= (-eff0
->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9733 // final calculation
9734 // =================
9736 // scaling of non weapon based spells
9737 if (!isWeaponDamageBasedSpell
)
9739 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9741 // Check for table values
9742 if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9745 if (damagetype
== DOT
)
9746 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
9748 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
9750 if (bonus
->ap_bonus
)
9751 DoneFlat
+= bonus
->ap_bonus
* (GetTotalAttackPowerValue(BASE_ATTACK
) + APbonus
) * stack
;
9756 // Default calculation
9757 else if (DoneFlat
|| TakenFlat
)
9759 // Damage over Time spells bonus calculation
9760 float DotFactor
= 1.0f
;
9761 if(damagetype
== DOT
)
9763 if(!IsChanneledSpell(spellProto
))
9764 DotFactor
= GetSpellDuration(spellProto
) / 15000.0f
;
9765 uint16 DotTicks
= GetSpellAuraMaxTicks(spellProto
);
9768 DoneFlat
= DoneFlat
* int32(stack
) / DotTicks
;
9769 TakenFlat
= TakenFlat
* int32(stack
) / DotTicks
;
9772 // Distribute Damage over multiple effects, reduce by AoE
9773 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
9774 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
9775 DoneFlat
*= (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
;
9776 TakenFlat
*= (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
;
9779 // weapon damage based spells
9780 else if( APbonus
|| DoneFlat
)
9782 bool normalized
= spellProto
? IsSpellHaveEffect(spellProto
, SPELL_EFFECT_NORMALIZED_WEAPON_DMG
) : false;
9783 DoneFlat
+= int32(APbonus
/ 14.0f
* GetAPMultiplier(attType
,normalized
));
9785 // for weapon damage based spells we still have to apply damage done percent mods
9786 // (that are already included into pdamage) to not-yet included DoneFlat
9787 // e.g. from doneVersusCreature, apBonusVs...
9792 case BASE_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_MAINHAND
; break;
9793 case OFF_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_OFFHAND
; break;
9794 case RANGED_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_RANGED
; break;
9797 DoneFlat
*= GetModifierValue(unitMod
, TOTAL_PCT
);
9800 float tmpDamage
= float(int32(pdamage
) + DoneFlat
) * DonePercent
;
9802 // apply spellmod to Done damage
9805 if(Player
* modOwner
= GetSpellModOwner())
9806 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
9809 tmpDamage
= (tmpDamage
+ TakenFlat
) * TakenPercent
;
9811 // bonus result can be negative
9812 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9815 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
9819 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
9822 if(itr
->type
== type
)
9824 m_spellImmune
[op
].erase(itr
);
9825 next
= m_spellImmune
[op
].begin();
9829 Immune
.spellId
= spellId
;
9831 m_spellImmune
[op
].push_back(Immune
);
9835 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
9837 if(itr
->spellId
== spellId
)
9839 m_spellImmune
[op
].erase(itr
);
9847 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
9849 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
9851 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
9852 RemoveAurasWithDispelType(type
);
9855 float Unit::GetWeaponProcChance() const
9857 // normalized proc chance for weapon attack speed
9859 if (isAttackReady(BASE_ATTACK
))
9860 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
9861 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
9862 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
9867 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
9869 // proc per minute chance calculation
9870 if (PPM
<= 0.0f
) return 0.0f
;
9871 return WeaponSpeed
* PPM
/ 600.0f
; // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
9874 void Unit::Mount(uint32 mount
, uint32 spellId
)
9879 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
9881 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
9883 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
9885 if (GetTypeId() == TYPEID_PLAYER
)
9887 // Called by Taxi system / GM command
9889 ((Player
*)this)->UnsummonPetTemporaryIfAny();
9890 // Called by mount aura
9891 else if (SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellId
))
9893 // Flying case (Unsummon any pet)
9894 if (IsSpellHaveAura(spellInfo
, SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
))
9895 ((Player
*)this)->UnsummonPetTemporaryIfAny();
9896 // Normal case (Unsummon only permanent pet)
9897 else if (Pet
* pet
= GetPet())
9899 if (pet
->IsPermanentPetFor((Player
*)this) && !((Player
*)this)->InArena())
9900 ((Player
*)this)->UnsummonPetTemporaryIfAny();
9902 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,true);
9908 void Unit::Unmount()
9913 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
9915 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
9916 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
9918 // only resummon old pet if the player is already added to a map
9919 // this prevents adding a pet to a not created map which would otherwise cause a crash
9920 // (it could probably happen when logging in after a previous crash)
9921 if(GetTypeId() == TYPEID_PLAYER
)
9923 if(Pet
* pet
= GetPet())
9924 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,false);
9926 ((Player
*)this)->ResummonPetTemporaryUnSummonedIfAny();
9930 void Unit::SetInCombatWith(Unit
* enemy
)
9932 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
9933 if (eOwner
->IsPvP())
9935 SetInCombatState(true,enemy
);
9940 if (eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
9942 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
9943 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
9945 SetInCombatState(true,enemy
);
9950 SetInCombatState(false,enemy
);
9953 void Unit::SetInCombatState(bool PvP
, Unit
* enemy
)
9955 // only alive units can be in combat
9960 m_CombatTimer
= 5000;
9962 bool creatureNotInCombat
= GetTypeId()==TYPEID_UNIT
&& !HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
9964 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
9966 if (isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
9967 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
9969 if (creatureNotInCombat
)
9971 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
9973 if (((Creature
*)this)->AI())
9974 ((Creature
*)this)->AI()->EnterCombat(enemy
);
9978 void Unit::ClearInCombat()
9981 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
9983 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
9984 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
9986 // Player's state will be cleared in Player::UpdateContestedPvP
9987 if (GetTypeId() != TYPEID_PLAYER
)
9989 Creature
* creature
= (Creature
*)this;
9990 if (creature
->GetCreatureInfo() && creature
->GetCreatureInfo()->unit_flags
& UNIT_FLAG_OOC_NOT_ATTACKABLE
)
9991 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
9993 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
9996 ((Player
*)this)->UpdatePotionCooldown();
9999 bool Unit::isTargetableForAttack(bool inverseAlive
/*=false*/) const
10001 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
10004 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
10007 // to be removed if unit by any reason enter combat
10008 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
))
10011 // inversealive is needed for some spells which need to be casted at dead targets (aoe)
10012 if (isAlive() == inverseAlive
)
10015 return IsInWorld() && !hasUnitState(UNIT_STAT_DIED
) && !isInFlight();
10018 int32
Unit::ModifyHealth(int32 dVal
)
10025 int32 curHealth
= (int32
)GetHealth();
10027 int32 val
= dVal
+ curHealth
;
10034 int32 maxHealth
= (int32
)GetMaxHealth();
10036 if(val
< maxHealth
)
10039 gain
= val
- curHealth
;
10041 else if(curHealth
!= maxHealth
)
10043 SetHealth(maxHealth
);
10044 gain
= maxHealth
- curHealth
;
10050 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
10057 int32 curPower
= (int32
)GetPower(power
);
10059 int32 val
= dVal
+ curPower
;
10066 int32 maxPower
= (int32
)GetMaxPower(power
);
10070 SetPower(power
,val
);
10071 gain
= val
- curPower
;
10073 else if(curPower
!= maxPower
)
10075 SetPower(power
,maxPower
);
10076 gain
= maxPower
- curPower
;
10082 bool Unit::isVisibleForOrDetect(Unit
const* u
, WorldObject
const* viewPoint
, bool detect
, bool inVisibleList
, bool is3dDistance
) const
10084 if(!u
|| !IsInMap(u
))
10087 // Always can see self
10091 // player visible for other player if not logout and at same transport
10092 // including case when player is out of world
10093 bool at_same_transport
=
10094 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
10095 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
10096 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
10097 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
10100 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
10103 // forbidden to seen (at GM respawn command)
10104 if(m_Visibility
==VISIBILITY_RESPAWN
)
10107 Map
& _map
= *u
->GetMap();
10108 // Grid dead/alive checks
10109 if (u
->GetTypeId()==TYPEID_PLAYER
)
10111 // non visible at grid for any stealth state
10112 if(!IsVisibleInGridForPlayer((Player
*)u
))
10115 // if player is dead then he can't detect anyone in any cases
10121 // all dead creatures/players not visible for any creatures
10122 if(!u
->isAlive() || !isAlive())
10126 // always seen by far sight caster
10127 if (u
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)u
)->GetFarSight()==GetGUID())
10130 // different visible distance checks
10131 if (u
->isInFlight()) // what see player in flight
10133 // use object grey distance for all (only see objects any way)
10134 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10137 else if(!isAlive()) // distance for show body
10139 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10142 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
10144 if(u
->GetTypeId()==TYPEID_PLAYER
)
10146 // Players far than max visible distance for player or not in our map are not visible too
10147 if (!at_same_transport
&& !IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10152 // Units far than max visible distance for creature or not in our map are not visible too
10153 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10157 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
10159 // Pet/charmed far than max visible distance for player or not in our map are not visible too
10160 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10163 else // distance for show creature
10165 // Units far than max visible distance for creature or not in our map are not visible too
10166 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10170 // always seen by owner
10171 if (GetCharmerOrOwnerGUID()==u
->GetGUID())
10174 // isInvisibleForAlive() those units can only be seen by dead or if other
10175 // unit is also invisible for alive.. if an isinvisibleforalive unit dies we
10176 // should be able to see it too
10177 if (u
->isAlive() && isAlive() && isInvisibleForAlive() != u
->isInvisibleForAlive())
10178 if (u
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)u
)->isGameMaster())
10181 // Visible units, always are visible for all units, except for units under invisibility and phases
10182 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0 && InSamePhase(u
))
10185 // GMs see any players, not higher GMs and all units in any phase
10186 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
10188 if(GetTypeId() == TYPEID_PLAYER
)
10189 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
10194 // non faction visibility non-breakable for non-GMs
10195 if (m_Visibility
== VISIBILITY_OFF
)
10198 // phased visibility (both must phased in same way)
10199 if(!InSamePhase(u
))
10202 // raw invisibility
10203 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
10205 // detectable invisibility case
10207 // Invisible units, always are visible for units under same invisibility type
10208 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
10209 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
10210 u
->canDetectInvisibilityOf(this) ||
10211 // Units that can detect invisibility always are visible for units that can be detected
10212 canDetectInvisibilityOf(u
) ))
10217 // special cases for always overwrite invisibility/stealth
10218 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
10220 // non-hostile case
10221 if (!u
->IsHostileTo(this))
10223 // player see other player with stealth/invisibility only if he in same group or raid or same team (raid/team case dependent from conf setting)
10224 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
10226 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
10229 // else apply same rules as for hostile case (detecting check for stealth)
10235 // Hunter mark functionality
10236 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
10237 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
10238 if((*iter
)->GetCasterGUID()==u
->GetGUID())
10241 // else apply detecting check for stealth
10244 // none other cases for detect invisibility, so invisible
10248 // else apply stealth detecting check
10251 // unit got in stealth in this moment and must ignore old detected state
10252 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
10255 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
10256 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
10259 // NOW ONLY STEALTH CASE
10261 //if in non-detect mode then invisible for unit
10262 //mobs always detect players (detect == true)... return 'false' for those mobs which have (detect == false)
10263 //players detect players only in Player::HandleStealthedUnitsDetection()
10265 return (u
->GetTypeId() == TYPEID_PLAYER
) ? ((Player
*)u
)->HaveAtClient(this) : false;
10269 // If is attacked then stealth is lost, some creature can use stealth too
10270 if( !getAttackers().empty() )
10273 // If there is collision rogue is seen regardless of level difference
10274 if (IsWithinDist(u
,0.24f
))
10277 //If a mob or player is stunned he will not be able to detect stealth
10278 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
10282 float visibleDistance
= (u
->GetTypeId() == TYPEID_PLAYER
) ? MAX_PLAYER_STEALTH_DETECT_RANGE
: ((Creature
const*)u
)->GetAttackDistance(this);
10284 //Always invisible from back (when stealth detection is on), also filter max distance cases
10285 bool isInFront
= viewPoint
->isInFrontInMap(this, visibleDistance
);
10289 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
10290 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
10292 //Calculation if target is in front
10294 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
10295 visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
10297 //Visible distance is modified by
10298 //-Level Diff (every level diff = 1.0f in visible distance)
10299 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
10301 //This allows to check talent tree and will add addition stealth dependent on used points)
10302 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
10306 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
10307 //based on wowwiki every 5 mod we have 1 more level diff in calculation
10308 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_DETECT
)) - stealthMod
)/5.0f
;
10309 visibleDistance
= visibleDistance
> MAX_PLAYER_STEALTH_DETECT_RANGE
? MAX_PLAYER_STEALTH_DETECT_RANGE
: visibleDistance
;
10311 // recheck new distance
10312 if(visibleDistance
<= 0 || !IsWithinDist(viewPoint
,visibleDistance
))
10316 // Now check is target visible with LoS
10318 viewPoint
->GetPosition(ox
,oy
,oz
);
10319 return IsWithinLOS(ox
,oy
,oz
);
10322 void Unit::SetVisibility(UnitVisibility x
)
10330 if(GetTypeId()==TYPEID_PLAYER
)
10331 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10333 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10337 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
10339 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
10341 for(uint32 i
= 0; i
< 10; ++i
)
10343 if(((1 << i
) & mask
)==0)
10346 // find invisibility level
10347 uint32 invLevel
= 0;
10348 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
10349 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
10350 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
10351 invLevel
= (*itr
)->GetModifier()->m_amount
;
10353 // find invisibility detect level
10354 uint32 detectLevel
= 0;
10355 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
10356 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
10357 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
10358 detectLevel
= (*itr
)->GetModifier()->m_amount
;
10360 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
10362 detectLevel
= ((Player
*)this)->GetDrunkValue();
10365 if(invLevel
<= detectLevel
)
10373 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
)
10375 int32 main_speed_mod
= 0;
10376 float stack_bonus
= 1.0f
;
10377 float non_stack_bonus
= 1.0f
;
10385 if (IsMounted()) // Use on mount auras
10387 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
10388 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
10389 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
10393 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
10394 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
10395 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
10399 case MOVE_RUN_BACK
:
10403 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
10406 case MOVE_SWIM_BACK
:
10410 if (IsMounted()) // Use on mount auras
10411 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
);
10412 else // Use not mount (shapeshift for example) auras (should stack)
10413 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT
);
10414 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS
);
10415 non_stack_bonus
= (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
))/100.0f
;
10418 case MOVE_FLIGHT_BACK
:
10421 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
10425 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
10426 // now we ready for speed calculation
10427 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
10435 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
10436 // TODO: possible affect only on MOVE_RUN
10437 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
10439 // Use speed from aura
10440 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
10441 if (speed
> max_speed
)
10450 // Apply strongest slow aura mod to speed
10451 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
10454 speed
*=(100.0f
+ slow
)/100.0f
;
10455 float min_speed
= (float)GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MINIMUM_SPEED
) / 100.0f
;
10456 if (speed
< min_speed
)
10459 SetSpeed(mtype
, speed
, forced
);
10462 float Unit::GetSpeed( UnitMoveType mtype
) const
10464 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
10467 void Unit::SetSpeed(UnitMoveType mtype
, float rate
, bool forced
)
10472 // Update speed only on change
10473 if (m_speed_rate
[mtype
] == rate
)
10476 m_speed_rate
[mtype
] = rate
;
10478 propagateSpeedChange();
10486 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10489 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10491 case MOVE_RUN_BACK
:
10492 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10495 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10497 case MOVE_SWIM_BACK
:
10498 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10500 case MOVE_TURN_RATE
:
10501 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+2+4+4+4+4+4+4+4);
10504 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10506 case MOVE_FLIGHT_BACK
:
10507 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10509 case MOVE_PITCH_RATE
:
10510 data
.Initialize(MSG_MOVE_SET_PITCH_RATE
, 8+4+2+4+4+4+4+4+4+4);
10513 sLog
.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype
);
10517 data
.append(GetPackGUID());
10518 data
<< uint32(0); // movement flags
10519 data
<< uint16(0); // unk flags
10520 data
<< uint32(getMSTime());
10521 data
<< float(GetPositionX());
10522 data
<< float(GetPositionY());
10523 data
<< float(GetPositionZ());
10524 data
<< float(GetOrientation());
10525 data
<< uint32(0); // fall time
10526 data
<< float(GetSpeed(mtype
));
10527 SendMessageToSet( &data
, true );
10531 if(GetTypeId() == TYPEID_PLAYER
)
10533 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
10534 // and do it only for real sent packets and use run for run/mounted as client expected
10535 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
10541 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
10544 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
10546 case MOVE_RUN_BACK
:
10547 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
10550 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
10552 case MOVE_SWIM_BACK
:
10553 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
10555 case MOVE_TURN_RATE
:
10556 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
10559 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
10561 case MOVE_FLIGHT_BACK
:
10562 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
10564 case MOVE_PITCH_RATE
:
10565 data
.Initialize(SMSG_FORCE_PITCH_RATE_CHANGE
, 16);
10568 sLog
.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype
);
10571 data
.append(GetPackGUID());
10572 data
<< (uint32
)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
10573 if (mtype
== MOVE_RUN
)
10574 data
<< uint8(0); // new 2.1.0
10575 data
<< float(GetSpeed(mtype
));
10576 SendMessageToSet( &data
, true );
10578 if(Pet
* pet
= GetPet())
10579 pet
->SetSpeed(MOVE_RUN
, m_speed_rate
[mtype
],forced
);
10582 void Unit::SetHover(bool on
)
10585 CastSpell(this, 11010, true);
10587 RemoveAurasDueToSpell(11010);
10590 void Unit::setDeathState(DeathState s
)
10592 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
10595 DeleteThreatList();
10596 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
10598 if(IsNonMeleeSpellCasted(false))
10599 InterruptNonMeleeSpells(false);
10602 if (s
== JUST_DIED
)
10604 RemoveAllAurasOnDeath();
10606 UnsummonAllTotems();
10608 // after removing a Fearaura (in RemoveAllAurasOnDeath)
10609 // Unit::SetFeared is called and makes that creatures attack player again
10612 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
10613 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
10614 // remove aurastates allowing special moves
10615 ClearAllReactives();
10616 ClearDiminishings();
10618 else if(s
== JUST_ALIVED
)
10620 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
10623 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
10625 //_ApplyAllAuraMods();
10630 /*########################################
10632 ######## AGGRO SYSTEM ########
10634 ########################################*/
10635 bool Unit::CanHaveThreatList() const
10637 // only creatures can have threat list
10638 if( GetTypeId() != TYPEID_UNIT
)
10641 // only alive units can have threat list
10645 // totems can not have threat list
10646 if( ((Creature
*)this)->isTotem() )
10649 // vehicles can not have threat list
10650 if( ((Creature
*)this)->isVehicle() )
10653 // pets can not have a threat list, unless they are controlled by a creature
10654 if( ((Creature
*)this)->isPet() && IS_PLAYER_GUID(((Pet
*)this)->GetOwnerGUID()) )
10660 //======================================================================
10662 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
10664 if (!HasAuraType(SPELL_AURA_MOD_THREAT
))
10667 if (schoolMask
== SPELL_SCHOOL_MASK_NONE
)
10670 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
10672 return threat
* m_threatModifier
[school
];
10675 //======================================================================
10677 void Unit::AddThreat(Unit
* pVictim
, float threat
/*= 0.0f*/, bool crit
/*= false*/, SpellSchoolMask schoolMask
/*= SPELL_SCHOOL_MASK_NONE*/, SpellEntry
const *threatSpell
/*= NULL*/)
10679 // Only mobs can manage threat lists
10680 if(CanHaveThreatList())
10681 m_ThreatManager
.addThreat(pVictim
, threat
, crit
, schoolMask
, threatSpell
);
10684 //======================================================================
10686 void Unit::DeleteThreatList()
10688 if(CanHaveThreatList() && !m_ThreatManager
.isThreatListEmpty())
10690 m_ThreatManager
.clearReferences();
10693 //======================================================================
10695 void Unit::TauntApply(Unit
* taunter
)
10697 assert(GetTypeId()== TYPEID_UNIT
);
10699 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
10702 if(!CanHaveThreatList())
10705 Unit
*target
= getVictim();
10706 if(target
&& target
== taunter
)
10709 SetInFront(taunter
);
10710 if (((Creature
*)this)->AI())
10711 ((Creature
*)this)->AI()->AttackStart(taunter
);
10713 m_ThreatManager
.tauntApply(taunter
);
10716 //======================================================================
10718 void Unit::TauntFadeOut(Unit
*taunter
)
10720 assert(GetTypeId()== TYPEID_UNIT
);
10722 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
10725 if(!CanHaveThreatList())
10728 Unit
*target
= getVictim();
10729 if(!target
|| target
!= taunter
)
10732 if(m_ThreatManager
.isThreatListEmpty())
10734 if(((Creature
*)this)->AI())
10735 ((Creature
*)this)->AI()->EnterEvadeMode();
10739 m_ThreatManager
.tauntFadeOut(taunter
);
10740 target
= m_ThreatManager
.getHostileTarget();
10742 if (target
&& target
!= taunter
)
10744 SetInFront(target
);
10745 if (((Creature
*)this)->AI())
10746 ((Creature
*)this)->AI()->AttackStart(target
);
10750 //======================================================================
10752 bool Unit::SelectHostileTarget()
10754 //function provides main threat functionality
10755 //next-victim-selection algorithm and evade mode are called
10756 //threat list sorting etc.
10758 assert(GetTypeId()== TYPEID_UNIT
);
10760 if (!this->isAlive())
10762 //This function only useful once AI has been initialized
10763 if (!((Creature
*)this)->AI())
10766 Unit
* target
= NULL
;
10768 // First checking if we have some taunt on us
10769 const AuraList
& tauntAuras
= GetAurasByType(SPELL_AURA_MOD_TAUNT
);
10770 if ( !tauntAuras
.empty() )
10774 // The last taunt aura caster is alive an we are happy to attack him
10775 if ( (caster
= tauntAuras
.back()->GetCaster()) && caster
->isAlive() )
10777 else if (tauntAuras
.size() > 1)
10779 // We do not have last taunt aura caster but we have more taunt auras,
10780 // so find first available target
10782 // Auras are pushed_back, last caster will be on the end
10783 AuraList::const_iterator aura
= --tauntAuras
.end();
10787 if ( (caster
= (*aura
)->GetCaster()) &&
10788 caster
->IsInMap(this) && caster
->isTargetableForAttack() && caster
->isInAccessablePlaceFor((Creature
*)this) )
10793 }while (aura
!= tauntAuras
.begin());
10797 if ( !target
&& !m_ThreatManager
.isThreatListEmpty() )
10798 // No taunt aura or taunt aura caster is dead standart target selection
10799 target
= m_ThreatManager
.getHostileTarget();
10803 if(!hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_DIED
))
10804 SetInFront(target
);
10805 ((Creature
*)this)->AI()->AttackStart(target
);
10809 // no target but something prevent go to evade mode
10810 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
10813 // last case when creature don't must go to evade mode:
10814 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
10815 // for example at owner command to pet attack some far away creature
10816 // Note: creature not have targeted movement generator but have attacker in this case
10817 if (GetMotionMaster()->GetCurrentMovementGeneratorType() != TARGETED_MOTION_TYPE
|| hasUnitState(UNIT_STAT_FOLLOW
))
10819 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
10821 if ((*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this))
10826 // enter in evade mode in other case
10827 ((Creature
*)this)->AI()->EnterEvadeMode();
10832 //======================================================================
10833 //======================================================================
10834 //======================================================================
10836 int32
Unit::CalculateSpellDamage(SpellEntry
const* spellProto
, uint8 effect_index
, int32 effBasePoints
, Unit
const* target
)
10838 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
10840 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
10842 int32 level
= int32(getLevel());
10843 if (level
> (int32
)spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
10844 level
= (int32
)spellProto
->maxLevel
;
10845 else if (level
< (int32
)spellProto
->baseLevel
)
10846 level
= (int32
)spellProto
->baseLevel
;
10847 level
-= (int32
)spellProto
->spellLevel
;
10849 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
10850 float randomPointsPerLevel
= spellProto
->EffectDicePerLevel
[effect_index
];
10851 int32 basePoints
= int32(effBasePoints
+ level
* basePointsPerLevel
);
10852 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
] + level
* randomPointsPerLevel
);
10853 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
10855 // range can have possitive and negative values, so order its for irand
10856 int32 randvalue
= int32(spellProto
->EffectBaseDice
[effect_index
]) >= randomPoints
10857 ? irand(randomPoints
, int32(spellProto
->EffectBaseDice
[effect_index
]))
10858 : irand(int32(spellProto
->EffectBaseDice
[effect_index
]), randomPoints
);
10860 int32 value
= basePoints
+ randvalue
;
10862 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
10863 value
+= (int32
)(comboDamage
* comboPoints
);
10865 if(Player
* modOwner
= GetSpellModOwner())
10867 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_ALL_EFFECTS
, value
);
10868 switch(effect_index
)
10871 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT1
, value
);
10874 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT2
, value
);
10877 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT3
, value
);
10882 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
10883 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
10884 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
&&
10885 (spellProto
->Effect
[effect_index
] != SPELL_EFFECT_APPLY_AURA
|| spellProto
->EffectApplyAuraName
[effect_index
] != SPELL_AURA_MOD_DECREASE_SPEED
))
10886 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
10891 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, uint8 effect_index
, Unit
const* target
)
10893 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
10895 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
10897 int32 minduration
= GetSpellDuration(spellProto
);
10898 int32 maxduration
= GetSpellMaxDuration(spellProto
);
10902 if( minduration
!= -1 && minduration
!= maxduration
)
10903 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
10905 duration
= minduration
;
10909 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
10910 // Find total mod value (negative bonus)
10911 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
10912 // Modify from SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL aura (stack always ?)
10913 durationMod_always
+=target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
, spellProto
->Dispel
);
10914 // Find max mod (negative bonus)
10915 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
10917 if (!IsPositiveSpell(spellProto
->Id
))
10918 durationMod_always
+= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS
, spellProto
->DmgClass
);
10920 int32 durationMod
= 0;
10921 // Select strongest negative mod
10922 if (durationMod_always
> durationMod_not_stack
)
10923 durationMod
= durationMod_not_stack
;
10925 durationMod
= durationMod_always
;
10927 if (durationMod
!= 0)
10928 duration
= int32(int64(duration
) * (100+durationMod
) /100);
10930 if (duration
< 0) duration
= 0;
10936 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
10938 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
10940 if(i
->DRGroup
!= group
)
10944 return DIMINISHING_LEVEL_1
;
10947 return DIMINISHING_LEVEL_1
;
10949 // If last spell was casted more than 15 seconds ago - reset the count.
10950 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
10952 i
->hitCount
= DIMINISHING_LEVEL_1
;
10953 return DIMINISHING_LEVEL_1
;
10955 // or else increase the count.
10958 return DiminishingLevels(i
->hitCount
);
10961 return DIMINISHING_LEVEL_1
;
10964 void Unit::IncrDiminishing(DiminishingGroup group
)
10966 // Checking for existing in the table
10967 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
10969 if(i
->DRGroup
!= group
)
10971 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
10975 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
10978 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
, int32 limitduration
)
10980 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
10983 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
10984 if(limitduration
> 0 && duration
> limitduration
)
10986 // test pet/charm masters instead pets/charmeds
10987 Unit
const* targetOwner
= GetCharmerOrOwner();
10988 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
10990 Unit
const* target
= targetOwner
? targetOwner
: this;
10991 Unit
const* source
= casterOwner
? casterOwner
: caster
;
10993 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
10994 duration
= limitduration
;
10999 // Some diminishings applies to mobs too (for example, Stun)
11000 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
11002 DiminishingLevels diminish
= Level
;
11005 case DIMINISHING_LEVEL_1
: break;
11006 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
11007 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
11008 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
11013 duration
= int32(duration
* mod
);
11016 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
11018 // Checking for existing in the table
11019 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11021 if(i
->DRGroup
!= group
)
11029 // Remember time after last aura from group removed
11031 i
->hitTime
= getMSTime();
11037 Unit
* Unit::GetUnit(WorldObject
& object
, uint64 guid
)
11039 return ObjectAccessor::GetUnit(object
,guid
);
11042 bool Unit::isVisibleForInState( Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const
11044 return isVisibleForOrDetect(u
, viewPoint
, false, inVisibleList
, false);
11047 /// returns true if creature can't be seen by alive units
11048 bool Unit::isInvisibleForAlive() const
11050 if (m_AuraFlags
& UNIT_AURAFLAG_ALIVE_INVISIBLE
)
11052 // TODO: maybe spiritservices also have just an aura
11053 return isSpiritService();
11056 uint32
Unit::GetCreatureType() const
11058 if(GetTypeId() == TYPEID_PLAYER
)
11060 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(m_form
);
11061 if(ssEntry
&& ssEntry
->creatureType
> 0)
11062 return ssEntry
->creatureType
;
11064 return CREATURE_TYPE_HUMANOID
;
11067 return ((Creature
*)this)->GetCreatureInfo()->type
;
11070 /*#######################################
11072 ######## STAT SYSTEM ########
11074 #######################################*/
11076 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
11078 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11080 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
11086 switch(modifierType
)
11090 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
11094 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
11097 val
= (100.0f
+ amount
) / 100.0f
;
11098 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
11105 if(!CanModifyStats())
11110 case UNIT_MOD_STAT_STRENGTH
:
11111 case UNIT_MOD_STAT_AGILITY
:
11112 case UNIT_MOD_STAT_STAMINA
:
11113 case UNIT_MOD_STAT_INTELLECT
:
11114 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
11116 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
11117 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
11119 case UNIT_MOD_MANA
:
11120 case UNIT_MOD_RAGE
:
11121 case UNIT_MOD_FOCUS
:
11122 case UNIT_MOD_ENERGY
:
11123 case UNIT_MOD_HAPPINESS
:
11124 case UNIT_MOD_RUNE
:
11125 case UNIT_MOD_RUNIC_POWER
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
11127 case UNIT_MOD_RESISTANCE_HOLY
:
11128 case UNIT_MOD_RESISTANCE_FIRE
:
11129 case UNIT_MOD_RESISTANCE_NATURE
:
11130 case UNIT_MOD_RESISTANCE_FROST
:
11131 case UNIT_MOD_RESISTANCE_SHADOW
:
11132 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
11134 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
11135 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
11137 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
11138 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
11139 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
11148 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
11150 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11152 sLog
.outError("trial to access non existed modifier value from UnitMods!");
11156 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
11159 return m_auraModifiersGroup
[unitMod
][modifierType
];
11162 float Unit::GetTotalStatValue(Stats stat
) const
11164 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
11166 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11169 // value = ((base_value * base_pct) + total_value) * total_pct
11170 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
11171 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11172 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11173 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11178 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
11180 if(unitMod
>= UNIT_MOD_END
)
11182 sLog
.outError("trial to access non existed UnitMods in GetTotalAuraModValue()!");
11186 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11189 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
11190 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11191 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11192 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11197 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
11199 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
11203 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
11204 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
11205 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
11206 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
11207 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
11208 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
11217 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
11219 Stats stat
= STAT_STRENGTH
;
11223 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
11224 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
11225 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
11226 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
11227 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
11236 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
11240 case UNIT_MOD_MANA
: return POWER_MANA
;
11241 case UNIT_MOD_RAGE
: return POWER_RAGE
;
11242 case UNIT_MOD_FOCUS
: return POWER_FOCUS
;
11243 case UNIT_MOD_ENERGY
: return POWER_ENERGY
;
11244 case UNIT_MOD_HAPPINESS
: return POWER_HAPPINESS
;
11245 case UNIT_MOD_RUNE
: return POWER_RUNE
;
11246 case UNIT_MOD_RUNIC_POWER
:return POWER_RUNIC_POWER
;
11247 default: return POWER_MANA
;
11253 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
11255 if (attType
== RANGED_ATTACK
)
11257 int32 ap
= GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER_MODS
);
11260 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER
));
11264 int32 ap
= GetInt32Value(UNIT_FIELD_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_ATTACK_POWER_MODS
);
11267 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER
));
11271 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
11273 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
11276 return m_weaponDamage
[attType
][type
];
11279 void Unit::SetLevel(uint32 lvl
)
11281 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
11284 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
11285 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
11288 void Unit::SetHealth(uint32 val
)
11290 uint32 maxHealth
= GetMaxHealth();
11291 if(maxHealth
< val
)
11294 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
11297 if(GetTypeId() == TYPEID_PLAYER
)
11299 if(((Player
*)this)->GetGroup())
11300 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
11302 else if(((Creature
*)this)->isPet())
11304 Pet
*pet
= ((Pet
*)this);
11305 if(pet
->isControlled())
11307 Unit
*owner
= GetOwner();
11308 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11309 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
11314 void Unit::SetMaxHealth(uint32 val
)
11316 uint32 health
= GetHealth();
11317 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
11320 if(GetTypeId() == TYPEID_PLAYER
)
11322 if(((Player
*)this)->GetGroup())
11323 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
11325 else if(((Creature
*)this)->isPet())
11327 Pet
*pet
= ((Pet
*)this);
11328 if(pet
->isControlled())
11330 Unit
*owner
= GetOwner();
11331 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11332 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP
);
11340 void Unit::SetPower(Powers power
, uint32 val
)
11342 if(GetPower(power
) == val
)
11345 uint32 maxPower
= GetMaxPower(power
);
11349 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
11351 WorldPacket
data(SMSG_POWER_UPDATE
);
11352 data
.append(GetPackGUID());
11353 data
<< uint8(power
);
11354 data
<< uint32(val
);
11355 SendMessageToSet(&data
, GetTypeId() == TYPEID_PLAYER
? true : false);
11358 if(GetTypeId() == TYPEID_PLAYER
)
11360 if(((Player
*)this)->GetGroup())
11361 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11363 else if(((Creature
*)this)->isPet())
11365 Pet
*pet
= ((Pet
*)this);
11366 if(pet
->isControlled())
11368 Unit
*owner
= GetOwner();
11369 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11370 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11373 // Update the pet's character sheet with happiness damage bonus
11374 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
11376 pet
->UpdateDamagePhysical(BASE_ATTACK
);
11381 void Unit::SetMaxPower(Powers power
, uint32 val
)
11383 uint32 cur_power
= GetPower(power
);
11384 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
11387 if(GetTypeId() == TYPEID_PLAYER
)
11389 if(((Player
*)this)->GetGroup())
11390 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
11392 else if(((Creature
*)this)->isPet())
11394 Pet
*pet
= ((Pet
*)this);
11395 if(pet
->isControlled())
11397 Unit
*owner
= GetOwner();
11398 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11399 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
11403 if(val
< cur_power
)
11404 SetPower(power
, val
);
11407 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
11409 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
11412 if(GetTypeId() == TYPEID_PLAYER
)
11414 if(((Player
*)this)->GetGroup())
11415 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11417 else if(((Creature
*)this)->isPet())
11419 Pet
*pet
= ((Pet
*)this);
11420 if(pet
->isControlled())
11422 Unit
*owner
= GetOwner();
11423 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11424 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11429 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
11431 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
11434 if(GetTypeId() == TYPEID_PLAYER
)
11436 if(((Player
*)this)->GetGroup())
11437 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
11439 else if(((Creature
*)this)->isPet())
11441 Pet
*pet
= ((Pet
*)this);
11442 if(pet
->isControlled())
11444 Unit
*owner
= GetOwner();
11445 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11446 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
11451 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
11453 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
11455 tAuraProcTriggerDamage
.push_back(aura
);
11457 tAuraProcTriggerDamage
.remove(aura
);
11460 uint32
Unit::GetCreatePowers( Powers power
) const
11462 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
11465 case POWER_MANA
: return GetCreateMana();
11466 case POWER_RAGE
: return 1000;
11467 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
11468 case POWER_ENERGY
: return 100;
11469 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
11470 case POWER_RUNIC_POWER
: return 1000;
11471 case POWER_RUNE
: return 0;
11472 case POWER_HEALTH
: return 0;
11478 void Unit::AddToWorld()
11480 Object::AddToWorld();
11483 void Unit::RemoveFromWorld()
11489 RemoveNotOwnSingleTargetAuras();
11491 RemoveAllGameObjects();
11492 RemoveAllDynObjects();
11493 CleanupDeletedAuras();
11496 Object::RemoveFromWorld();
11499 void Unit::CleanupsBeforeDelete()
11501 if(m_uint32Values
) // only for fully created object
11503 InterruptNonMeleeSpells(true);
11504 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
11506 ClearComboPointHolders();
11507 DeleteThreatList();
11508 getHostileRefManager().setOnlineOfflineState(false);
11509 RemoveAllAuras(AURA_REMOVE_BY_DELETE
);
11510 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
11512 WorldObject::CleanupsBeforeDelete();
11515 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
11518 m_charmInfo
= new CharmInfo(charm
);
11519 return m_charmInfo
;
11522 CharmInfo::CharmInfo(Unit
* unit
)
11523 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
11525 for(int i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
11526 m_charmspells
[i
].SetActionAndType(0,ACT_DISABLED
);
11529 void CharmInfo::InitPetActionBar()
11531 // the first 3 SpellOrActions are attack, follow and stay
11532 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_START
- ACTION_BAR_INDEX_START
; ++i
)
11533 SetActionBar(ACTION_BAR_INDEX_START
+ i
,COMMAND_ATTACK
- i
,ACT_COMMAND
);
11535 // middle 4 SpellOrActions are spells/special attacks/abilities
11536 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_END
-ACTION_BAR_INDEX_PET_SPELL_START
; ++i
)
11537 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_START
+ i
,0,ACT_DISABLED
);
11539 // last 3 SpellOrActions are reactions
11540 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_END
- ACTION_BAR_INDEX_PET_SPELL_END
; ++i
)
11541 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_END
+ i
,COMMAND_ATTACK
- i
,ACT_REACTION
);
11544 void CharmInfo::InitEmptyActionBar()
11546 SetActionBar(ACTION_BAR_INDEX_START
,COMMAND_ATTACK
,ACT_COMMAND
);
11547 for(uint32 x
= ACTION_BAR_INDEX_START
+1; x
< ACTION_BAR_INDEX_END
; ++x
)
11548 SetActionBar(x
,0,ACT_PASSIVE
);
11551 void CharmInfo::InitPossessCreateSpells()
11553 InitEmptyActionBar(); //charm action bar
11555 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //possessed players don't have spells, keep the action bar empty
11558 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11560 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
11561 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
11563 AddSpellToActionBar(((Creature
*)m_unit
)->m_spells
[x
], ACT_PASSIVE
);
11567 void CharmInfo::InitCharmCreateSpells()
11569 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
11571 InitEmptyActionBar();
11575 InitPetActionBar();
11577 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11579 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
11583 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
11587 if (IsPassiveSpell(spellId
))
11589 m_unit
->CastSpell(m_unit
, spellId
, true);
11590 m_charmspells
[x
].SetActionAndType(spellId
,ACT_PASSIVE
);
11594 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
11596 ActiveStates newstate
;
11597 bool onlyselfcast
= true;
11598 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
11600 if(!spellInfo
) onlyselfcast
= false;
11601 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
11603 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
11604 onlyselfcast
= false;
11607 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
11608 newstate
= ACT_DISABLED
;
11610 newstate
= ACT_PASSIVE
;
11612 AddSpellToActionBar(spellId
, newstate
);
11617 bool CharmInfo::AddSpellToActionBar(uint32 spell_id
, ActiveStates newstate
)
11619 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
11621 // new spell rank can be already listed
11622 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11624 if (uint32 action
= PetActionBar
[i
].GetAction())
11626 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
11628 PetActionBar
[i
].SetAction(spell_id
);
11634 // or use empty slot in other case
11635 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11637 if (!PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
11639 SetActionBar(i
,spell_id
,newstate
== ACT_DECIDE
? ACT_DISABLED
: newstate
);
11646 bool CharmInfo::RemoveSpellFromActionBar(uint32 spell_id
)
11648 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
11650 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11652 if (uint32 action
= PetActionBar
[i
].GetAction())
11654 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
11656 SetActionBar(i
,0,ACT_DISABLED
);
11665 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
11667 if(IsPassiveSpell(spellid
))
11670 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11671 if(spellid
== m_charmspells
[x
].GetAction())
11672 m_charmspells
[x
].SetType(apply
? ACT_ENABLED
: ACT_DISABLED
);
11675 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
11677 m_petnumber
= petnumber
;
11679 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
11681 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
11684 void CharmInfo::LoadPetActionBar(const std::string
& data
)
11686 InitPetActionBar();
11688 Tokens tokens
= StrSplit(data
, " ");
11690 if (tokens
.size() != (ACTION_BAR_INDEX_END
-ACTION_BAR_INDEX_START
)*2)
11691 return; // non critical, will reset to default
11694 Tokens::iterator iter
;
11695 for(iter
= tokens
.begin(), index
= ACTION_BAR_INDEX_START
; index
< ACTION_BAR_INDEX_END
; ++iter
, ++index
)
11697 // use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
11698 uint8 type
= atol((*iter
).c_str());
11700 uint32 action
= atol((*iter
).c_str());
11702 PetActionBar
[index
].SetActionAndType(action
,ActiveStates(type
));
11704 // check correctness
11705 if(PetActionBar
[index
].IsActionBarForSpell() && !sSpellStore
.LookupEntry(PetActionBar
[index
].GetAction()))
11706 SetActionBar(index
,0,ACT_DISABLED
);
11710 void CharmInfo::BuildActionBar( WorldPacket
* data
)
11712 for(uint32 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11713 *data
<< uint32(PetActionBar
[i
].packedData
);
11716 void CharmInfo::SetSpellAutocast( uint32 spell_id
, bool state
)
11718 for(int i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11720 if(spell_id
== PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
11722 PetActionBar
[i
].SetType(state
? ACT_ENABLED
: ACT_DISABLED
);
11728 bool Unit::isFrozen() const
11730 return HasAuraState(AURA_STATE_FROZEN
);
11733 struct ProcTriggeredData
11735 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
11736 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
11737 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
11739 SpellProcEventEntry
const *spellProcEvent
;
11740 Aura
* triggeredByAura
;
11741 Unit::spellEffectPair triggeredByAura_SpellPair
;
11744 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
11745 typedef std::list
< uint32
> RemoveSpellList
;
11747 // List of auras that CAN be trigger but may not exist in spell_proc_event
11748 // in most case need for drop charges
11749 // in some types of aura need do additional check
11750 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
11751 bool InitTriggerAuraData()
11753 for (int i
=0;i
<TOTAL_AURAS
;++i
)
11755 isTriggerAura
[i
]=false;
11756 isNonTriggerAura
[i
] = false;
11758 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
11759 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
11760 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
11761 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
11762 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
11763 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
11764 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
11765 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
11766 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
11767 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
11768 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
11769 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
11770 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
] = true;
11771 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
11772 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
11773 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
11774 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
11775 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
11776 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
11777 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
11778 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
11779 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
11780 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
11781 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
11782 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
11783 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
11784 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
11785 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
] = true;
11786 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_FROM_CASTER
] = true;
11787 isTriggerAura
[SPELL_AURA_MOD_SPELL_CRIT_CHANCE
] = true;
11788 isTriggerAura
[SPELL_AURA_MAELSTROM_WEAPON
] = true;
11790 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
11791 isNonTriggerAura
[SPELL_AURA_REDUCE_PUSHBACK
]=true;
11796 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
11798 uint32 procEx
= PROC_EX_NONE
;
11799 // Check victim state
11800 if (missCondition
!=SPELL_MISS_NONE
)
11801 switch (missCondition
)
11803 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
11804 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
11805 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
11806 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
11807 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
11808 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
11809 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
11810 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
11811 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
11812 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
11813 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
11820 if (damageInfo
->blocked
)
11821 procEx
|=PROC_EX_BLOCK
;
11823 if (damageInfo
->absorb
)
11824 procEx
|=PROC_EX_ABSORB
;
11826 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
11827 procEx
|=PROC_EX_CRITICAL_HIT
;
11829 procEx
|=PROC_EX_NORMAL_HIT
;
11834 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
11836 // For melee/ranged based attack need update skills and set some Aura states
11837 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
11839 // Update skills here for players
11840 if (GetTypeId() == TYPEID_PLAYER
)
11842 // On melee based hit/miss/resist need update skill (for victim and attacker)
11843 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
11845 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
11846 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, isVictim
);
11848 // Update defence if player is victim and parry/dodge/block
11849 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
11850 ((Player
*)this)->UpdateDefense();
11852 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
11853 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
11858 // if victim and dodge attack
11859 if (procExtra
&PROC_EX_DODGE
)
11861 //Update AURA_STATE on dodge
11862 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
11864 ModifyAuraState(AURA_STATE_DEFENSE
, true);
11865 StartReactiveTimer( REACTIVE_DEFENSE
);
11868 // if victim and parry attack
11869 if (procExtra
& PROC_EX_PARRY
)
11871 // For Hunters only Counterattack (skip Mongoose bite)
11872 if (getClass() == CLASS_HUNTER
)
11874 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
11875 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
11879 ModifyAuraState(AURA_STATE_DEFENSE
, true);
11880 StartReactiveTimer( REACTIVE_DEFENSE
);
11883 // if and victim block attack
11884 if (procExtra
& PROC_EX_BLOCK
)
11886 ModifyAuraState(AURA_STATE_DEFENSE
,true);
11887 StartReactiveTimer( REACTIVE_DEFENSE
);
11890 else //For attacker
11892 // Overpower on victim dodge
11893 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
11895 ((Player
*)this)->AddComboPoints(pTarget
, 1);
11896 StartReactiveTimer( REACTIVE_OVERPOWER
);
11902 RemoveSpellList removedSpells
;
11903 ProcTriggeredList procTriggered
;
11904 // Fill procTriggered list
11905 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
11907 // skip deleted auras (possible at recursive triggered call
11908 if(itr
->second
->IsDeleted())
11911 SpellProcEventEntry
const* spellProcEvent
= NULL
;
11912 if(!IsTriggeredAtSpellProcEvent(pTarget
, itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
11915 itr
->second
->SetInUse(true); // prevent aura deletion
11916 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
11920 if (procTriggered
.empty())
11923 // Handle effects proceed this time
11924 for(ProcTriggeredList::const_iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
11926 // Some auras can be deleted in function called in this loop (except first, ofc)
11927 Aura
*triggeredByAura
= i
->triggeredByAura
;
11928 if(triggeredByAura
->IsDeleted())
11931 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
11932 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
11933 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
11934 bool useCharges
= triggeredByAura
->GetAuraCharges() > 0;
11935 // For players set spell cooldown if need
11936 uint32 cooldown
= 0;
11937 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
11938 cooldown
= spellProcEvent
->cooldown
;
11940 switch(auraModifier
->m_auraname
)
11942 case SPELL_AURA_PROC_TRIGGER_SPELL
:
11944 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
11945 // Don`t drop charge or add cooldown for not started trigger
11946 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
11948 triggeredByAura
->SetInUse(false);
11953 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
11955 sLog
.outDebug("ProcDamageAndSpell: doing %u damage from spell id %u (triggered by %s aura of spell %u)", auraModifier
->m_amount
, spellInfo
->Id
, (isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
11956 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, spellInfo
->SchoolMask
);
11957 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
11958 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
11959 SendSpellNonMeleeDamageLog(&damageInfo
);
11960 DealSpellDamage(&damageInfo
, true);
11963 case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
:
11964 case SPELL_AURA_MANA_SHIELD
:
11965 case SPELL_AURA_OBS_MOD_MANA
:
11966 case SPELL_AURA_DUMMY
:
11968 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
11969 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
11971 triggeredByAura
->SetInUse(false);
11976 case SPELL_AURA_MOD_HASTE
:
11978 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
11979 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
11981 triggeredByAura
->SetInUse(false);
11986 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
11988 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
11989 if (!HandleOverrideClassScriptAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, cooldown
))
11991 triggeredByAura
->SetInUse(false);
11996 case SPELL_AURA_PRAYER_OF_MENDING
:
11998 sLog
.outDebug("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
11999 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
12001 HandleMendingAuraProc(triggeredByAura
);
12004 case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
:
12006 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered with value by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12008 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12010 triggeredByAura
->SetInUse(false);
12015 case SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
:
12016 // Skip melee hits or instant cast spells
12017 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
12019 triggeredByAura
->SetInUse(false);
12023 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
12024 // Skip Melee hits and spells ws wrong school
12025 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
12027 triggeredByAura
->SetInUse(false);
12031 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
12032 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
12033 // Skip melee hits and spells ws wrong school or zero cost
12034 if (procSpell
== NULL
||
12035 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
12036 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
12038 triggeredByAura
->SetInUse(false);
12042 case SPELL_AURA_MECHANIC_IMMUNITY
:
12043 // Compare mechanic
12044 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12046 triggeredByAura
->SetInUse(false);
12050 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
12051 // Compare mechanic
12052 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12054 triggeredByAura
->SetInUse(false);
12058 case SPELL_AURA_MOD_DAMAGE_FROM_CASTER
:
12060 if (triggeredByAura
->GetCasterGUID() != pTarget
->GetGUID())
12062 triggeredByAura
->SetInUse(false);
12066 case SPELL_AURA_MOD_SPELL_CRIT_CHANCE
:
12069 triggeredByAura
->SetInUse(false);
12072 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s spell crit chance aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12073 if (!HandleSpellCritChanceAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12075 triggeredByAura
->SetInUse(false);
12079 case SPELL_AURA_MAELSTROM_WEAPON
:
12080 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s maelstrom aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12082 // remove all stack;
12083 RemoveSpellsCausingAura(SPELL_AURA_MAELSTROM_WEAPON
);
12084 triggeredByAura
->SetInUse(false); // this safe, aura locked
12085 continue; // avoid re-remove attempts
12087 // nothing do, just charges counter
12091 // Remove charge (aura can be removed by triggers)
12092 if(useCharges
&& !triggeredByAura
->IsDeleted())
12094 // If last charge dropped add spell to remove list
12095 if(triggeredByAura
->DropAuraCharge())
12096 removedSpells
.push_back(triggeredByAura
->GetId());
12099 triggeredByAura
->SetInUse(false);
12101 if (!removedSpells
.empty())
12103 // Sort spells and remove dublicates
12104 removedSpells
.sort();
12105 removedSpells
.unique();
12106 // Remove auras from removedAuras
12107 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();++i
)
12108 RemoveSingleSpellAurasFromStack(*i
);
12112 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
12114 return SPELL_SCHOOL_MASK_NORMAL
;
12117 Player
* Unit::GetSpellModOwner()
12119 if(GetTypeId()==TYPEID_PLAYER
)
12120 return (Player
*)this;
12121 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
12123 Unit
* owner
= GetOwner();
12124 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
12125 return (Player
*)owner
;
12130 ///----------Pet responses methods-----------------
12131 void Unit::SendPetCastFail(uint32 spellid
, SpellCastResult msg
)
12133 if(msg
== SPELL_CAST_OK
)
12136 Unit
*owner
= GetCharmerOrOwner();
12137 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12140 WorldPacket
data(SMSG_PET_CAST_FAILED
, 1 + 4 + 1);
12141 data
<< uint8(0); // cast count?
12142 data
<< uint32(spellid
);
12143 data
<< uint8(msg
);
12144 // uint32 for some reason
12145 // uint32 for some reason
12146 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12149 void Unit::SendPetActionFeedback (uint8 msg
)
12151 Unit
* owner
= GetOwner();
12152 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12155 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
12156 data
<< uint8(msg
);
12157 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12160 void Unit::SendPetTalk (uint32 pettalk
)
12162 Unit
* owner
= GetOwner();
12163 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12166 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8 + 4);
12167 data
<< uint64(GetGUID());
12168 data
<< uint32(pettalk
);
12169 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12172 void Unit::SendPetAIReaction(uint64 guid
)
12174 Unit
* owner
= GetOwner();
12175 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12178 WorldPacket
data(SMSG_AI_REACTION
, 8 + 4);
12179 data
<< uint64(guid
);
12180 data
<< uint32(AI_REACTION_AGGRO
);
12181 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12184 ///----------End of Pet responses methods----------
12186 void Unit::StopMoving()
12188 clearUnitState(UNIT_STAT_MOVING
);
12190 // send explicit stop packet
12191 // player expected for correct work MONSTER_MOVE_WALK
12192 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, GetTypeId()==TYPEID_PLAYER
? MONSTER_MOVE_WALK
: MONSTER_MOVE_NONE
, 0);
12194 // update position and orientation for near players
12196 BuildHeartBeatMsg(&data
);
12197 SendMessageToSet(&data
,false);
12200 void Unit::SetFeared(bool apply
, uint64
const& casterGUID
, uint32 spellID
, uint32 time
)
12204 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
12207 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12209 GetMotionMaster()->MovementExpired(false);
12210 CastStop(GetGUID()==casterGUID
? spellID
: 0);
12212 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
12214 GetMotionMaster()->MoveFleeing(caster
, time
); // caster==NULL processed in MoveFleeing
12218 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12220 GetMotionMaster()->MovementExpired(false);
12222 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
12224 // restore appropriate movement generator
12226 GetMotionMaster()->MoveChase(getVictim());
12228 GetMotionMaster()->Initialize();
12230 // attack caster if can
12231 Unit
* caster
= Unit::GetUnit(*this, casterGUID
);
12232 if(caster
&& ((Creature
*)this)->AI())
12233 ((Creature
*)this)->AI()->AttackedBy(caster
);
12237 if (GetTypeId() == TYPEID_PLAYER
)
12238 ((Player
*)this)->SetClientControl(this, !apply
);
12241 void Unit::SetConfused(bool apply
, uint64
const& casterGUID
, uint32 spellID
)
12245 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12247 CastStop(GetGUID()==casterGUID
? spellID
: 0);
12249 GetMotionMaster()->MoveConfused();
12253 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12255 GetMotionMaster()->MovementExpired(false);
12257 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12259 // restore appropriate movement generator
12261 GetMotionMaster()->MoveChase(getVictim());
12263 GetMotionMaster()->Initialize();
12267 if(GetTypeId() == TYPEID_PLAYER
)
12268 ((Player
*)this)->SetClientControl(this, !apply
);
12271 void Unit::SetFeignDeath(bool apply
, uint64
const& casterGUID
, uint32 spellID
)
12276 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12279 SendMessageToSet(&data,true);
12282 if(GetTypeId() != TYPEID_PLAYER
)
12285 ((Player
*)this)->m_movementInfo
.SetMovementFlags(MOVEMENTFLAG_NONE
);
12287 // blizz like 2.0.x
12288 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12289 // blizz like 2.0.x
12290 SetFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12291 // blizz like 2.0.x
12292 SetFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12294 addUnitState(UNIT_STAT_DIED
);
12296 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION
);
12298 // prevent interrupt message
12299 if (casterGUID
== GetGUID())
12300 FinishSpell(CURRENT_GENERIC_SPELL
,false);
12301 InterruptNonMeleeSpells(true);
12302 getHostileRefManager().deleteReferences();
12307 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12310 SendMessageToSet(&data,true);
12312 // blizz like 2.0.x
12313 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12314 // blizz like 2.0.x
12315 RemoveFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12316 // blizz like 2.0.x
12317 RemoveFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12319 clearUnitState(UNIT_STAT_DIED
);
12321 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12323 // restore appropriate movement generator
12325 GetMotionMaster()->MoveChase(getVictim());
12327 GetMotionMaster()->Initialize();
12333 bool Unit::IsSitState() const
12335 uint8 s
= getStandState();
12337 s
== UNIT_STAND_STATE_SIT_CHAIR
|| s
== UNIT_STAND_STATE_SIT_LOW_CHAIR
||
12338 s
== UNIT_STAND_STATE_SIT_MEDIUM_CHAIR
|| s
== UNIT_STAND_STATE_SIT_HIGH_CHAIR
||
12339 s
== UNIT_STAND_STATE_SIT
;
12342 bool Unit::IsStandState() const
12344 uint8 s
= getStandState();
12345 return !IsSitState() && s
!= UNIT_STAND_STATE_SLEEP
&& s
!= UNIT_STAND_STATE_KNEEL
;
12348 void Unit::SetStandState(uint8 state
)
12350 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
12352 if (IsStandState())
12353 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
12355 if(GetTypeId()==TYPEID_PLAYER
)
12357 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
12358 data
<< (uint8
)state
;
12359 ((Player
*)this)->GetSession()->SendPacket(&data
);
12363 bool Unit::IsPolymorphed() const
12365 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
12368 void Unit::SetDisplayId(uint32 modelId
)
12370 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
12372 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
12374 Pet
*pet
= ((Pet
*)this);
12375 if(!pet
->isControlled())
12377 Unit
*owner
= GetOwner();
12378 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12379 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
12383 void Unit::ClearComboPointHolders()
12385 while(!m_ComboPointHolders
.empty())
12387 uint32 lowguid
= *m_ComboPointHolders
.begin();
12389 Player
* plr
= sObjectMgr
.GetPlayer(MAKE_NEW_GUID(lowguid
, 0, HIGHGUID_PLAYER
));
12390 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
12391 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
12393 m_ComboPointHolders
.erase(lowguid
); // or remove manually
12397 void Unit::ClearAllReactives()
12399 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
12400 m_reactiveTimer
[i
] = 0;
12402 if (HasAuraState( AURA_STATE_DEFENSE
))
12403 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12404 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
12405 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12406 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12407 ((Player
*)this)->ClearComboPoints();
12410 void Unit::UpdateReactives( uint32 p_time
)
12412 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
12414 ReactiveType reactive
= ReactiveType(i
);
12416 if(!m_reactiveTimer
[reactive
])
12419 if ( m_reactiveTimer
[reactive
] <= p_time
)
12421 m_reactiveTimer
[reactive
] = 0;
12423 switch ( reactive
)
12425 case REACTIVE_DEFENSE
:
12426 if (HasAuraState(AURA_STATE_DEFENSE
))
12427 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12429 case REACTIVE_HUNTER_PARRY
:
12430 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
12431 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12433 case REACTIVE_OVERPOWER
:
12434 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12435 ((Player
*)this)->ClearComboPoints();
12443 m_reactiveTimer
[reactive
] -= p_time
;
12448 Unit
* Unit::SelectNearbyTarget(Unit
* except
/*= NULL*/) const
12450 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
12452 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
12453 cell
.SetNoCreate();
12455 std::list
<Unit
*> targets
;
12458 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, ATTACK_DISTANCE
);
12459 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
12461 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
12462 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
12464 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
12465 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *GetMap(), *this, ATTACK_DISTANCE
);
12466 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *GetMap(), *this, ATTACK_DISTANCE
);
12469 // remove current target
12471 targets
.remove(except
);
12473 // remove not LoS targets
12474 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
12476 if(!IsWithinLOSInMap(*tIter
))
12478 std::list
<Unit
*>::iterator tIter2
= tIter
;
12480 targets
.erase(tIter2
);
12486 // no appropriate targets
12487 if(targets
.empty())
12491 uint32 rIdx
= urand(0,targets
.size()-1);
12492 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
12493 for(uint32 i
= 0; i
< rIdx
; ++i
)
12499 bool Unit::hasNegativeAuraWithInterruptFlag(uint32 flag
)
12501 for (AuraMap::const_iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); ++iter
)
12503 if (!iter
->second
->IsPositive() && iter
->second
->GetSpellProto()->AuraInterruptFlags
& flag
)
12509 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
12513 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
12514 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
12518 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
12519 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
12523 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
12526 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
12528 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
12531 uint32
Unit::GetCastingTimeForBonus( SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 CastingTime
)
12533 // Not apply this to creature casted spells with casttime==0
12534 if(CastingTime
==0 && GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
12537 if (CastingTime
> 7000) CastingTime
= 7000;
12538 if (CastingTime
< 1500) CastingTime
= 1500;
12540 if(damagetype
== DOT
&& !IsChanneledSpell(spellProto
))
12541 CastingTime
= 3500;
12543 int32 overTime
= 0;
12545 bool DirectDamage
= false;
12546 bool AreaEffect
= false;
12548 for ( uint32 i
=0; i
<3;++i
)
12550 switch ( spellProto
->Effect
[i
] )
12552 case SPELL_EFFECT_SCHOOL_DAMAGE
:
12553 case SPELL_EFFECT_POWER_DRAIN
:
12554 case SPELL_EFFECT_HEALTH_LEECH
:
12555 case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
:
12556 case SPELL_EFFECT_POWER_BURN
:
12557 case SPELL_EFFECT_HEAL
:
12558 DirectDamage
= true;
12560 case SPELL_EFFECT_APPLY_AURA
:
12561 switch ( spellProto
->EffectApplyAuraName
[i
] )
12563 case SPELL_AURA_PERIODIC_DAMAGE
:
12564 case SPELL_AURA_PERIODIC_HEAL
:
12565 case SPELL_AURA_PERIODIC_LEECH
:
12566 if ( GetSpellDuration(spellProto
) )
12567 overTime
= GetSpellDuration(spellProto
);
12570 // -5% per additional effect
12578 if(IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetA
[i
])) || IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetB
[i
])))
12582 // Combined Spells with Both Over Time and Direct Damage
12583 if ( overTime
> 0 && CastingTime
> 0 && DirectDamage
)
12585 // mainly for DoTs which are 3500 here otherwise
12586 uint32 OriginalCastTime
= GetSpellCastTime(spellProto
);
12587 if (OriginalCastTime
> 7000) OriginalCastTime
= 7000;
12588 if (OriginalCastTime
< 1500) OriginalCastTime
= 1500;
12589 // Portion to Over Time
12590 float PtOT
= (overTime
/ 15000.0f
) / ((overTime
/ 15000.0f
) + (OriginalCastTime
/ 3500.0f
));
12592 if ( damagetype
== DOT
)
12593 CastingTime
= uint32(CastingTime
* PtOT
);
12594 else if ( PtOT
< 1.0f
)
12595 CastingTime
= uint32(CastingTime
* (1 - PtOT
));
12600 // Area Effect Spells receive only half of bonus
12604 // -5% of total per any additional effect
12605 for ( uint8 i
=0; i
<effects
; ++i
)
12607 if ( CastingTime
> 175 )
12609 CastingTime
-= 175;
12618 return CastingTime
;
12621 void Unit::UpdateAuraForGroup(uint8 slot
)
12623 if(GetTypeId() == TYPEID_PLAYER
)
12625 Player
* player
= (Player
*)this;
12626 if(player
->GetGroup())
12628 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
12629 player
->SetAuraUpdateMask(slot
);
12632 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
12634 Pet
*pet
= ((Pet
*)this);
12635 if(pet
->isControlled())
12637 Unit
*owner
= GetOwner();
12638 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12640 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
12641 pet
->SetAuraUpdateMask(slot
);
12647 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
12649 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
12650 return float(GetAttackTime(attType
))/1000.0f
;
12652 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
, true, false);
12654 return 2.4; // fist attack
12656 switch (Weapon
->GetProto()->InventoryType
)
12658 case INVTYPE_2HWEAPON
:
12660 case INVTYPE_RANGED
:
12661 case INVTYPE_RANGEDRIGHT
:
12662 case INVTYPE_THROWN
:
12664 case INVTYPE_WEAPON
:
12665 case INVTYPE_WEAPONMAINHAND
:
12666 case INVTYPE_WEAPONOFFHAND
:
12668 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7 : 2.4;
12672 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
12674 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
12675 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
12676 if ((*itr
)->GetId() == spell_id
)
12682 void Unit::SetContestedPvP(Player
*attackedPlayer
)
12684 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
12686 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
12689 player
->SetContestedPvPTimer(30000);
12690 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
12692 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
12693 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
12694 // call MoveInLineOfSight for nearby contested guards
12695 SetVisibility(GetVisibility());
12697 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
12699 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
12700 // call MoveInLineOfSight for nearby contested guards
12701 SetVisibility(GetVisibility());
12705 void Unit::AddPetAura(PetAura
const* petSpell
)
12707 m_petAuras
.insert(petSpell
);
12708 if(Pet
* pet
= GetPet())
12709 pet
->CastPetAura(petSpell
);
12712 void Unit::RemovePetAura(PetAura
const* petSpell
)
12714 m_petAuras
.erase(petSpell
);
12715 if(Pet
* pet
= GetPet())
12716 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
12719 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
12721 Pet
* pet
= new Pet(HUNTER_PET
);
12723 if(!pet
->CreateBaseAtCreature(creatureTarget
))
12729 pet
->SetOwnerGUID(GetGUID());
12730 pet
->SetCreatorGUID(GetGUID());
12731 pet
->setFaction(getFaction());
12732 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
12734 if(GetTypeId()==TYPEID_PLAYER
)
12735 pet
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
12740 uint32 level
= (creatureTarget
->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget
->getLevel();
12742 if(!pet
->InitStatsForLevel(level
))
12744 sLog
.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
12749 pet
->GetCharmInfo()->SetPetNumber(sObjectMgr
.GeneratePetNumber(), true);
12750 // this enables pet details window (Shift+P)
12751 pet
->AIM_Initialize();
12752 pet
->InitPetCreateSpells();
12753 pet
->InitLevelupSpellsForLevel();
12754 pet
->InitTalentForLevel();
12755 pet
->SetHealth(pet
->GetMaxHealth());
12760 bool Unit::IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
12762 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
12764 // Get proc Event Entry
12765 spellProcEvent
= sSpellMgr
.GetSpellProcEvent(spellProto
->Id
);
12767 // Aura info stored here
12768 Modifier
*mod
= aura
->GetModifier();
12770 if (isNonTriggerAura
[mod
->m_auraname
])
12772 // If not trigger by default and spellProcEvent==NULL - skip
12773 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
12776 // Get EventProcFlag
12777 uint32 EventProcFlag
;
12778 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
12779 EventProcFlag
= spellProcEvent
->procFlags
;
12781 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
12782 // Continue if no trigger exist
12783 if (!EventProcFlag
)
12786 // Check spellProcEvent data requirements
12787 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
12790 // In most cases req get honor or XP from kill
12791 if (EventProcFlag
& PROC_FLAG_KILL
&& GetTypeId() == TYPEID_PLAYER
)
12793 bool allow
= ((Player
*)this)->isHonorOrXPTarget(pVictim
);
12794 // Shadow Word: Death - can trigger from every kill
12795 if (aura
->GetId() == 32409)
12800 // Aura added by spell can`t trogger from self (prevent drop charges/do triggers)
12801 // But except periodic triggers (can triggered from self)
12802 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
& PROC_FLAG_ON_TAKE_PERIODIC
))
12805 // Check if current equipment allows aura to proc
12806 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
12808 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
12811 if(attType
== BASE_ATTACK
)
12812 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
12813 else if (attType
== OFF_ATTACK
)
12814 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
12816 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
12818 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
12821 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
12823 // Check if player is wearing shield
12824 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
12825 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
12829 // Get chance from spell
12830 float chance
= (float)spellProto
->procChance
;
12831 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
12832 if(spellProcEvent
&& spellProcEvent
->customChance
)
12833 chance
= spellProcEvent
->customChance
;
12834 // If PPM exist calculate chance from PPM
12835 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
12837 uint32 WeaponSpeed
= GetAttackTime(attType
);
12838 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
12840 // Apply chance modifer aura
12841 if(Player
* modOwner
= GetSpellModOwner())
12843 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
12844 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_FREQUENCY_OF_SUCCESS
,chance
);
12847 return roll_chance_f(chance
);
12850 bool Unit::HandleMendingAuraProc( Aura
* triggeredByAura
)
12852 // aura can be deleted at casts
12853 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
12854 uint32 effIdx
= triggeredByAura
->GetEffIndex();
12855 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
12856 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
12859 int32 jumps
= triggeredByAura
->GetAuraCharges()-1;
12861 // current aura expire
12862 triggeredByAura
->SetAuraCharges(1); // will removed at next charges decrease
12864 // next target selection
12865 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
12868 if (spellProto
->EffectRadiusIndex
[effIdx
])
12869 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
12871 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
12873 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
12875 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
12877 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
12879 // aura will applied from caster, but spell casted from current aura holder
12880 SpellModifier
*mod
= new SpellModifier(SPELLMOD_CHARGES
,SPELLMOD_FLAT
,jumps
-5,spellProto
->Id
,spellProto
->SpellFamilyFlags
,spellProto
->SpellFamilyFlags2
);
12882 // remove before apply next (locked against deleted)
12883 triggeredByAura
->SetInUse(true);
12884 RemoveAurasByCasterSpell(spellProto
->Id
,caster
->GetGUID());
12886 caster
->AddSpellMod(mod
, true);
12887 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
12888 caster
->AddSpellMod(mod
, false);
12889 triggeredByAura
->SetInUse(false);
12895 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
12899 void Unit::RemoveAurasAtMechanicImmunity(uint32 mechMask
, uint32 exceptSpellId
, bool non_positive
/*= false*/)
12901 Unit::AuraMap
& auras
= GetAuras();
12902 for(Unit::AuraMap::iterator iter
= auras
.begin(); iter
!= auras
.end();)
12904 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
12905 if (spell
->Id
== exceptSpellId
)
12907 else if (non_positive
&& iter
->second
->IsPositive())
12909 else if (spell
->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
)
12911 else if (GetSpellMechanicMask(spell
, iter
->second
->GetEffIndex()) & mechMask
)
12913 RemoveAurasDueToSpell(spell
->Id
);
12917 iter
= auras
.begin();
12924 void Unit::SetPhaseMask(uint32 newPhaseMask
, bool update
)
12926 if(newPhaseMask
==GetPhaseMask())
12930 RemoveNotOwnSingleTargetAuras(newPhaseMask
); // we can lost access to caster or target
12932 WorldObject::SetPhaseMask(newPhaseMask
,update
);
12935 if(Pet
* pet
= GetPet())
12936 pet
->SetPhaseMask(newPhaseMask
,true);
12939 void Unit::NearTeleportTo( float x
, float y
, float z
, float orientation
, bool casting
/*= false*/ )
12941 if(GetTypeId() == TYPEID_PLAYER
)
12942 ((Player
*)this)->TeleportTo(GetMapId(), x
, y
, z
, orientation
, TELE_TO_NOT_LEAVE_TRANSPORT
| TELE_TO_NOT_LEAVE_COMBAT
| TELE_TO_NOT_UNSUMMON_PET
| (casting
? TELE_TO_SPELL
: 0));
12945 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, orientation
);
12948 BuildHeartBeatMsg(&data
);
12949 SendMessageToSet(&data
, false);
12953 void Unit::SetPvP( bool state
)
12956 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
12958 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
12960 if(Pet
* pet
= GetPet())
12961 pet
->SetPvP(state
);
12962 if(Unit
* charmed
= GetCharm())
12963 charmed
->SetPvP(state
);
12965 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
12967 if(Creature
*totem
= GetMap()->GetCreature(m_TotemSlot
[i
]))
12968 totem
->SetPvP(state
);
12971 void Unit::KnockBackFrom(Unit
* target
, float horizintalSpeed
, float verticalSpeed
)
12973 float angle
= this == target
? GetOrientation() + M_PI
: target
->GetAngle(this);
12974 float vsin
= sin(angle
);
12975 float vcos
= cos(angle
);
12977 // Effect propertly implemented only for players
12978 if(GetTypeId()==TYPEID_PLAYER
)
12980 WorldPacket
data(SMSG_MOVE_KNOCK_BACK
, 8+4+4+4+4+4);
12981 data
.append(GetPackGUID());
12982 data
<< uint32(0); // Sequence
12983 data
<< float(vcos
); // x direction
12984 data
<< float(vsin
); // y direction
12985 data
<< float(horizintalSpeed
); // Horizontal speed
12986 data
<< float(-verticalSpeed
); // Z Movement speed (vertical)
12987 ((Player
*)this)->GetSession()->SendPacket(&data
);
12991 float dis
= horizintalSpeed
;
12994 GetPosition(ox
, oy
, oz
);
12996 float fx
= ox
+ dis
* vcos
;
12997 float fy
= oy
+ dis
* vsin
;
13000 float fx2
, fy2
, fz2
; // getObjectHitPos overwrite last args in any result case
13001 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), ox
,oy
,oz
+0.5, fx
,fy
,oz
+0.5,fx2
,fy2
,fz2
, -0.5))
13006 UpdateGroundPositionZ(fx
, fy
, fz
);
13009 //FIXME: this mostly hack, must exist some packet for proper creature move at client side
13010 // with CreatureRelocation at server side
13011 NearTeleportTo(fx
, fy
, fz
, GetOrientation(), this == target
);
13015 float Unit::GetCombatRatingReduction(CombatRating cr
) const
13017 if (GetTypeId() == TYPEID_PLAYER
)
13018 return ((Player
const*)this)->GetRatingBonusValue(cr
);
13019 else if (((Creature
const*)this)->isPet())
13021 // Player's pet have 0.4 resilience from owner
13022 if (Unit
* owner
= GetOwner())
13023 if(owner
->GetTypeId() == TYPEID_PLAYER
)
13024 return ((Player
*)owner
)->GetRatingBonusValue(cr
) * 0.4f
;
13030 uint32
Unit::GetCombatRatingDamageReduction(CombatRating cr
, float rate
, float cap
, uint32 damage
) const
13032 float percent
= GetCombatRatingReduction(cr
) * rate
;
13035 return uint32 (percent
* damage
/ 100.0f
);
13038 void Unit::SendThreatUpdate()
13040 ThreatList
const& tlist
= getThreatManager().getThreatList();
13041 if (uint32 count
= tlist
.size())
13043 sLog
.outDebug( "WORLD: Send SMSG_THREAT_UPDATE Message" );
13044 WorldPacket
data(SMSG_THREAT_UPDATE
, 8 + count
* 8);
13045 data
.append(GetPackGUID());
13046 data
<< uint32(count
);
13047 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13049 data
.appendPackGUID((*itr
)->getUnitGuid());
13050 data
<< uint32((*itr
)->getThreat());
13052 SendMessageToSet(&data
, false);
13056 void Unit::SendHighestThreatUpdate(HostileReference
* pHostilReference
)
13058 ThreatList
const& tlist
= getThreatManager().getThreatList();
13059 if (uint32 count
= tlist
.size())
13061 sLog
.outDebug( "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message" );
13062 WorldPacket
data(SMSG_HIGHEST_THREAT_UPDATE
, 8 + 8 + count
* 8);
13063 data
.append(GetPackGUID());
13064 data
.appendPackGUID(pHostilReference
->getUnitGuid());
13065 data
<< uint32(count
);
13066 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13068 data
.appendPackGUID((*itr
)->getUnitGuid());
13069 data
<< uint32((*itr
)->getThreat());
13071 SendMessageToSet(&data
, false);
13075 void Unit::SendThreatClear()
13077 sLog
.outDebug( "WORLD: Send SMSG_THREAT_CLEAR Message" );
13078 WorldPacket
data(SMSG_THREAT_CLEAR
, 8);
13079 data
.append(GetPackGUID());
13080 SendMessageToSet(&data
, false);
13083 void Unit::SendThreatRemove(HostileReference
* pHostileReference
)
13085 sLog
.outDebug( "WORLD: Send SMSG_THREAT_REMOVE Message" );
13086 WorldPacket
data(SMSG_THREAT_REMOVE
, 8 + 8);
13087 data
.append(GetPackGUID());
13088 data
.appendPackGUID(pHostileReference
->getUnitGuid());
13089 SendMessageToSet(&data
, false);
13092 void Unit::StopAttackFaction(uint32 faction_id
)
13094 if (Unit
* victim
= getVictim())
13096 if (victim
->getFactionTemplateEntry()->faction
==faction_id
)
13099 if (IsNonMeleeSpellCasted(false))
13100 InterruptNonMeleeSpells(false);
13102 // melee and ranged forced attack cancel
13103 if (GetTypeId() == TYPEID_PLAYER
)
13104 ((Player
*)this)->SendAttackSwingCancelAttack();
13108 AttackerSet
const& attackers
= getAttackers();
13109 for(AttackerSet::const_iterator itr
= attackers
.begin(); itr
!= attackers
.end();)
13111 if ((*itr
)->getFactionTemplateEntry()->faction
==faction_id
)
13113 (*itr
)->AttackStop();
13114 itr
= attackers
.begin();
13120 getHostileRefManager().deleteReferencesForFaction(faction_id
);
13122 if(Pet
* pet
= GetPet())
13123 pet
->StopAttackFaction(faction_id
);
13124 if(Unit
* charm
= GetCharm())
13125 charm
->StopAttackFaction(faction_id
);
13127 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
13128 if(Unit
* guardian
= Unit::GetUnit(*this,*itr
))
13129 guardian
->StopAttackFaction(faction_id
);
13132 void Unit::CleanupDeletedAuras()
13134 // really delete auras "deleted" while processing its ApplyModify code
13135 for(AuraList::const_iterator itr
= m_deletedAuras
.begin(); itr
!= m_deletedAuras
.end(); ++itr
)
13137 m_deletedAuras
.clear();