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 "ObjectGuid.h"
34 #include "SpellAuras.h"
35 #include "MapManager.h"
36 #include "ObjectAccessor.h"
37 #include "CreatureAI.h"
38 #include "TemporarySummon.h"
43 #include "BattleGround.h"
44 #include "InstanceSaveMgr.h"
45 #include "GridNotifiersImpl.h"
48 #include "Traveller.h"
49 #include "VMapFactory.h"
50 #include "MovementGenerator.h"
55 float baseMoveSpeed
[MAX_MOVE_TYPE
] =
59 2.5f
, // MOVE_RUN_BACK
60 4.722222f
, // MOVE_SWIM
61 4.5f
, // MOVE_SWIM_BACK
62 3.141594f
, // MOVE_TURN_RATE
64 4.5f
, // MOVE_FLIGHT_BACK
65 3.14f
// MOVE_PITCH_RATE
68 // Used for prepare can/can`t trigger aura
69 static bool InitTriggerAuraData();
70 // Define can trigger auras
71 static bool isTriggerAura
[TOTAL_AURAS
];
72 // Define can`t trigger auras (need for disable second trigger)
73 static bool isNonTriggerAura
[TOTAL_AURAS
];
75 static bool procPrepared
= InitTriggerAuraData();
77 void MovementInfo::Read(ByteBuffer
&data
)
87 if(HasMovementFlag(MOVEFLAG_ONTRANSPORT
))
89 data
>> t_guid
.ReadAsPacked();
97 if(moveFlags2
& MOVEFLAG2_INTERP_MOVEMENT
)
101 if((HasMovementFlag(MovementFlags(MOVEFLAG_SWIMMING
| MOVEFLAG_FLYING
))) || (moveFlags2
& MOVEFLAG2_ALLOW_PITCHING
))
108 if(HasMovementFlag(MOVEFLAG_FALLING
))
116 if(HasMovementFlag(MOVEFLAG_SPLINE_ELEVATION
))
122 void MovementInfo::Write(ByteBuffer
&data
) const
132 if(HasMovementFlag(MOVEFLAG_ONTRANSPORT
))
134 data
<< t_guid
.WriteAsPacked();
142 if(moveFlags2
& MOVEFLAG2_INTERP_MOVEMENT
)
146 if((HasMovementFlag(MovementFlags(MOVEFLAG_SWIMMING
| MOVEFLAG_FLYING
))) || (moveFlags2
& MOVEFLAG2_ALLOW_PITCHING
))
153 if(HasMovementFlag(MOVEFLAG_FALLING
))
161 if(HasMovementFlag(MOVEFLAG_SPLINE_ELEVATION
))
168 : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostileRefManager(this)
170 m_objectType
|= TYPEMASK_UNIT
;
171 m_objectTypeId
= TYPEID_UNIT
;
173 m_updateFlag
= (UPDATEFLAG_HIGHGUID
| UPDATEFLAG_LIVING
| UPDATEFLAG_HAS_POSITION
);
175 m_attackTimer
[BASE_ATTACK
] = 0;
176 m_attackTimer
[OFF_ATTACK
] = 0;
177 m_attackTimer
[RANGED_ATTACK
] = 0;
178 m_modAttackSpeedPct
[BASE_ATTACK
] = 1.0f
;
179 m_modAttackSpeedPct
[OFF_ATTACK
] = 1.0f
;
180 m_modAttackSpeedPct
[RANGED_ATTACK
] = 1.0f
;
186 m_deathState
= ALIVE
;
188 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
189 m_currentSpells
[i
] = NULL
;
195 for(int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
198 m_ObjectSlot
[0] = m_ObjectSlot
[1] = m_ObjectSlot
[2] = m_ObjectSlot
[3] = 0;
200 //m_AurasCheck = 2000;
201 //m_removeAuraTimer = 4;
202 m_AurasUpdateIterator
= m_Auras
.end();
205 m_Visibility
= VISIBILITY_ON
;
207 m_detectInvisibilityMask
= 0;
208 m_invisibilityMask
= 0;
210 m_ShapeShiftFormSpellId
= 0;
211 m_canModifyStats
= false;
213 for (int i
= 0; i
< MAX_SPELL_IMMUNITY
; ++i
)
214 m_spellImmune
[i
].clear();
215 for (int i
= 0; i
< UNIT_MOD_END
; ++i
)
217 m_auraModifiersGroup
[i
][BASE_VALUE
] = 0.0f
;
218 m_auraModifiersGroup
[i
][BASE_PCT
] = 1.0f
;
219 m_auraModifiersGroup
[i
][TOTAL_VALUE
] = 0.0f
;
220 m_auraModifiersGroup
[i
][TOTAL_PCT
] = 1.0f
;
222 // implement 50% base damage from offhand
223 m_auraModifiersGroup
[UNIT_MOD_DAMAGE_OFFHAND
][TOTAL_PCT
] = 0.5f
;
225 for (int i
= 0; i
< MAX_ATTACK
; ++i
)
227 m_weaponDamage
[i
][MINDAMAGE
] = BASE_MINDAMAGE
;
228 m_weaponDamage
[i
][MAXDAMAGE
] = BASE_MAXDAMAGE
;
230 for (int i
= 0; i
< MAX_STATS
; ++i
)
231 m_createStats
[i
] = 0.0f
;
234 m_modMeleeHitChance
= 0.0f
;
235 m_modRangedHitChance
= 0.0f
;
236 m_modSpellHitChance
= 0.0f
;
237 m_baseSpellCritChance
= 5;
240 m_lastManaUseTimer
= 0;
242 //m_victimThreat = 0.0f;
243 for (int i
= 0; i
< MAX_SPELL_SCHOOL
; ++i
)
244 m_threatModifier
[i
] = 1.0f
;
246 for (int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
247 m_speed_rate
[i
] = 1.0f
;
251 // remove aurastates allowing special moves
252 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
253 m_reactiveTimer
[i
] = 0;
258 // set current spells as deletable
259 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
261 if (m_currentSpells
[i
])
263 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
264 m_currentSpells
[i
] = NULL
;
271 // those should be already removed at "RemoveFromWorld()" call
272 ASSERT(m_gameObj
.size() == 0);
273 ASSERT(m_dynObjGUIDs
.size() == 0);
274 ASSERT(m_deletedAuras
.size() == 0);
277 void Unit::Update( uint32 p_time
)
282 /*if(p_time > m_AurasCheck)
287 m_AurasCheck -= p_time;*/
289 // WARNING! Order of execution here is important, do not change.
290 // Spells must be processed with event system BEFORE they go to _UpdateSpells.
291 // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
292 m_Events
.Update( p_time
);
293 _UpdateSpells( p_time
);
295 CleanupDeletedAuras();
297 if (m_lastManaUseTimer
)
299 if (p_time
>= m_lastManaUseTimer
)
300 m_lastManaUseTimer
= 0;
302 m_lastManaUseTimer
-= p_time
;
305 if (CanHaveThreatList())
306 getThreatManager().UpdateForClient(p_time
);
308 // update combat timer only for players and pets
309 if (isInCombat() && (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet() || ((Creature
*)this)->isCharmed()))
311 // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away
312 // targets without stopping half way there and running off.
313 // These flags are reset after target dies or another command is given.
314 if (m_HostileRefManager
.isEmpty())
316 // m_CombatTimer set at aura start and it will be freeze until aura removing
317 if (m_CombatTimer
<= p_time
)
320 m_CombatTimer
-= p_time
;
324 if (uint32 base_att
= getAttackTimer(BASE_ATTACK
))
326 setAttackTimer(BASE_ATTACK
, (p_time
>= base_att
? 0 : base_att
- p_time
) );
329 // update abilities available only for fraction of time
330 UpdateReactives( p_time
);
332 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, GetHealth() < GetMaxHealth()*0.20f
);
333 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, GetHealth() < GetMaxHealth()*0.35f
);
334 ModifyAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT
, GetHealth() > GetMaxHealth()*0.75f
);
336 i_motionMaster
.UpdateMotion(p_time
);
339 bool Unit::haveOffhandWeapon() const
341 if(GetTypeId() == TYPEID_PLAYER
)
342 return ((Player
*)this)->GetWeaponForAttack(OFF_ATTACK
,true,true);
347 void Unit::SendMonsterMove(float NewPosX
, float NewPosY
, float NewPosZ
, SplineType type
, SplineFlags flags
, uint32 Time
, Player
* player
, ...)
351 va_start(vargs
,player
);
353 float moveTime
= (float)Time
;
355 WorldPacket
data( SMSG_MONSTER_MOVE
, (41 + GetPackGUID().size()) );
356 data
<< GetPackGUID();
357 data
<< uint8(0); // new in 3.1 bool, used to toggle MOVEFLAG2_UNK4 = 0x0040 on client side
358 data
<< GetPositionX() << GetPositionY() << GetPositionZ();
359 data
<< uint32(getMSTime());
361 data
<< uint8(type
); // unknown
364 case SPLINETYPE_NORMAL
: // normal packet
366 case SPLINETYPE_STOP
: // stop packet (raw pos?)
368 SendMessageToSet( &data
, true );
370 case SPLINETYPE_FACINGSPOT
: // facing spot, not used currently
372 data
<< float(va_arg(vargs
,double));
373 data
<< float(va_arg(vargs
,double));
374 data
<< float(va_arg(vargs
,double));
377 case SPLINETYPE_FACINGTARGET
:
378 data
<< uint64(va_arg(vargs
,uint64
));
380 case SPLINETYPE_FACINGANGLE
: // not used currently
381 data
<< float(va_arg(vargs
,double)); // facing angle
385 data
<< uint32(flags
);
387 // enable me if things goes wrong or looks ugly, it is however an old hack
388 // if(flags & SPLINEFLAG_WALKMODE)
389 // moveTime *= 1.05f;
391 data
<< uint32(moveTime
); // Time in between points
392 data
<< uint32(1); // 1 single waypoint
393 data
<< NewPosX
<< NewPosY
<< NewPosZ
; // the single waypoint Point B
398 player
->GetSession()->SendPacket(&data
);
400 SendMessageToSet( &data
, true );
403 void Unit::SendMonsterMoveWithSpeed(float x
, float y
, float z
, uint32 transitTime
, Player
* player
)
407 if(GetTypeId()==TYPEID_PLAYER
)
409 Traveller
<Player
> traveller(*(Player
*)this);
410 transitTime
= traveller
.GetTotalTrevelTimeTo(x
, y
, z
);
414 Traveller
<Creature
> traveller(*(Creature
*)this);
415 transitTime
= traveller
.GetTotalTrevelTimeTo(x
, y
, z
);
418 //float orientation = (float)atan2((double)dy, (double)dx);
419 SplineFlags flags
= GetTypeId() == TYPEID_PLAYER
? SPLINEFLAG_WALKMODE
: ((Creature
*)this)->GetSplineFlags();
420 SendMonsterMove(x
, y
, z
, SPLINETYPE_NORMAL
, flags
, transitTime
, player
);
423 void Unit::BuildHeartBeatMsg(WorldPacket
*data
) const
425 MovementFlags move_flags
= GetTypeId()==TYPEID_PLAYER
426 ? ((Player
const*)this)->m_movementInfo
.GetMovementFlags()
429 data
->Initialize(MSG_MOVE_HEARTBEAT
, 32);
430 *data
<< GetPackGUID();
431 *data
<< uint32(move_flags
); // movement flags
432 *data
<< uint16(0); // 2.3.0
433 *data
<< uint32(getMSTime()); // time
434 *data
<< float(GetPositionX());
435 *data
<< float(GetPositionY());
436 *data
<< float(GetPositionZ());
437 *data
<< float(GetOrientation());
441 void Unit::resetAttackTimer(WeaponAttackType type
)
443 m_attackTimer
[type
] = uint32(GetAttackTime(type
) * m_modAttackSpeedPct
[type
]);
446 bool Unit::canReachWithAttack(Unit
*pVictim
) const
449 float reach
= GetFloatValue(UNIT_FIELD_COMBATREACH
);
452 return IsWithinDistInMap(pVictim
, reach
);
455 void Unit::RemoveSpellsCausingAura(AuraType auraType
)
457 if (auraType
>= TOTAL_AURAS
) return;
458 AuraList::const_iterator iter
, next
;
459 for (iter
= m_modAuras
[auraType
].begin(); iter
!= m_modAuras
[auraType
].end(); iter
= next
)
466 RemoveAurasDueToSpell((*iter
)->GetId());
467 if (!m_modAuras
[auraType
].empty())
468 next
= m_modAuras
[auraType
].begin();
475 bool Unit::HasAuraType(AuraType auraType
) const
477 return (!m_modAuras
[auraType
].empty());
480 /* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */
481 void Unit::RemoveSpellbyDamageTaken(AuraType auraType
, uint32 damage
)
483 if(!HasAuraType(auraType
))
486 // The chance to dispel an aura depends on the damage taken with respect to the casters level.
487 uint32 max_dmg
= getLevel() > 8 ? 25 * getLevel() - 150 : 50;
488 float chance
= float(damage
) / max_dmg
* 100.0f
;
489 if (roll_chance_f(chance
))
490 RemoveSpellsCausingAura(auraType
);
493 void Unit::DealDamageMods(Unit
*pVictim
, uint32
&damage
, uint32
* absorb
)
495 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
503 //You don't lose health from damage taken from another player while in a sanctuary
504 //You still see it in the combat log though
505 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
507 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
508 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) //sanctuary
516 uint32 originalDamage
= damage
;
518 //Script Event damage Deal
519 if( GetTypeId()== TYPEID_UNIT
&& ((Creature
*)this)->AI())
520 ((Creature
*)this)->AI()->DamageDeal(pVictim
, damage
);
521 //Script Event damage taken
522 if( pVictim
->GetTypeId()== TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI() )
523 ((Creature
*)pVictim
)->AI()->DamageTaken(this, damage
);
525 if(absorb
&& originalDamage
> damage
)
526 *absorb
+= (originalDamage
- damage
);
529 uint32
Unit::DealDamage(Unit
*pVictim
, uint32 damage
, CleanDamage
const* cleanDamage
, DamageEffectType damagetype
, SpellSchoolMask damageSchoolMask
, SpellEntry
const *spellProto
, bool durabilityLoss
)
531 // remove affects from victim (including from 0 damage and DoTs)
533 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
535 // remove affects from attacker at any non-DoT damage (including 0 damage)
536 if( damagetype
!= DOT
)
538 RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
539 RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
542 RemoveSpellsCausingAura(SPELL_AURA_MOD_INVISIBILITY
);
544 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->IsStandState() && !pVictim
->hasUnitState(UNIT_STAT_STUNNED
))
545 pVictim
->SetStandState(UNIT_STAND_STATE_STAND
);
550 // Rage from physical damage received .
551 if(cleanDamage
&& cleanDamage
->damage
&& (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
) && pVictim
->GetTypeId() == TYPEID_PLAYER
&& (pVictim
->getPowerType() == POWER_RAGE
))
552 ((Player
*)pVictim
)->RewardRage(cleanDamage
->damage
, 0, false);
556 if (!spellProto
|| !IsSpellHaveAura(spellProto
,SPELL_AURA_MOD_FEAR
))
557 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_FEAR
, damage
);
558 // root type spells do not dispel the root effect
559 if (!spellProto
|| !(spellProto
->Mechanic
== MECHANIC_ROOT
|| IsSpellHaveAura(spellProto
,SPELL_AURA_MOD_ROOT
)))
560 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_ROOT
, damage
);
562 // no xp,health if type 8 /critters/
563 if(pVictim
->GetTypeId() != TYPEID_PLAYER
&& pVictim
->GetCreatureType() == CREATURE_TYPE_CRITTER
)
565 pVictim
->setDeathState(JUST_DIED
);
566 pVictim
->SetHealth(0);
568 // allow loot only if has loot_id in creature_template
569 ((Creature
*)pVictim
)->PrepareBodyLootState();
571 // some critters required for quests (need normal entry instead possible heroic in any cases)
572 if(GetTypeId() == TYPEID_PLAYER
)
573 if(CreatureInfo
const* normalInfo
= ObjectMgr::GetCreatureTemplate(pVictim
->GetEntry()))
574 ((Player
*)this)->KilledMonster(normalInfo
,pVictim
->GetObjectGuid());
579 DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE
,"DealDamageStart");
581 uint32 health
= pVictim
->GetHealth();
582 DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE
,"deal dmg:%d to health:%d ",damage
,health
);
584 // duel ends when player has 1 or less hp
585 bool duel_hasEnded
= false;
586 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->duel
&& damage
>= (health
-1))
588 // prevent kill only if killed in duel and killed by opponent or opponent controlled creature
589 if(((Player
*)pVictim
)->duel
->opponent
==this || ((Player
*)pVictim
)->duel
->opponent
->GetGUID() == GetOwnerGUID())
592 duel_hasEnded
= true;
595 if(pVictim
!= this && damagetype
!= DOT
)
597 SetInCombatWith(pVictim
);
598 pVictim
->SetInCombatWith(this);
600 if(Player
* attackedPlayer
= pVictim
->GetCharmerOrOwnerPlayerOrPlayerItself())
601 SetContestedPvP(attackedPlayer
);
604 // Rage from Damage made (only from direct weapon damage)
605 if( cleanDamage
&& damagetype
==DIRECT_DAMAGE
&& this != pVictim
&& GetTypeId() == TYPEID_PLAYER
&& (getPowerType() == POWER_RAGE
))
607 uint32 weaponSpeedHitFactor
;
609 switch(cleanDamage
->attackType
)
613 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
614 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 7);
616 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
618 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
624 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
625 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
627 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 1.75f
);
629 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
638 if (GetTypeId() == TYPEID_PLAYER
&& this != pVictim
)
640 Player
*killer
= ((Player
*)this);
642 // in bg, count dmg if victim is also a player
643 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
645 if (BattleGround
*bg
= killer
->GetBattleGround())
647 // FIXME: kept by compatibility. don't know in BG if the restriction apply.
648 bg
->UpdatePlayerScore(killer
, SCORE_DAMAGE_DONE
, damage
);
652 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DAMAGE_DONE
, damage
, 0, pVictim
);
653 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_DEALT
, damage
);
656 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
657 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_RECEIVED
, damage
);
659 if (pVictim
->GetTypeId() == TYPEID_UNIT
&& !((Creature
*)pVictim
)->isPet() && !((Creature
*)pVictim
)->HasLootRecipient())
660 ((Creature
*)pVictim
)->SetLootRecipient(this);
662 if (health
<= damage
)
664 DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE
,"DealDamage: victim just died");
666 // find player: owner of controlled `this` or `this` itself maybe
667 // for loot will be sued only if group_tap==NULL
668 Player
*player_tap
= GetCharmerOrOwnerPlayerOrPlayerItself();
669 Group
*group_tap
= NULL
;
671 // find owner of pVictim, used for creature cases, AI calls
672 Unit
* pOwner
= pVictim
->GetCharmerOrOwner();
674 // in creature kill case group/player tap stored for creature
675 if (pVictim
->GetTypeId() == TYPEID_UNIT
)
677 group_tap
= ((Creature
*)pVictim
)->GetGroupLootRecipient();
679 if (Player
* recipient
= ((Creature
*)pVictim
)->GetOriginalLootRecipient())
680 player_tap
= recipient
;
682 // in player kill case group tap selected by player_tap (killer-player itself, or charmer, or owner, etc)
686 group_tap
= player_tap
->GetGroup();
689 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
691 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, health
);
693 player_tap
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_SPECIAL_PVP_KILL
,1,0,pVictim
);
696 // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop)
697 if(player_tap
&& player_tap
!= pVictim
)
699 player_tap
->ProcDamageAndSpell(pVictim
, PROC_FLAG_KILL
, PROC_FLAG_KILLED
, PROC_EX_NONE
, 0);
701 WorldPacket
data(SMSG_PARTYKILLLOG
, (8+8)); //send event PARTY_KILL
702 data
<< player_tap
->GetObjectGuid(); //player with killing blow
703 data
<< pVictim
->GetObjectGuid(); //victim
706 group_tap
->BroadcastPacket(&data
, false, group_tap
->GetMemberGroup(player_tap
->GetGUID()),player_tap
->GetGUID());
708 player_tap
->SendDirectMessage(&data
);
711 // Reward player, his pets, and group/raid members
712 if (player_tap
!= pVictim
)
715 group_tap
->RewardGroupAtKill(pVictim
, player_tap
);
717 player_tap
->RewardSinglePlayerAtKill(pVictim
);
720 DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE
,"DealDamageAttackStop");
723 pVictim
->CombatStop();
724 pVictim
->getHostileRefManager().deleteReferences();
726 bool damageFromSpiritOfRedemtionTalent
= spellProto
&& spellProto
->Id
== 27795;
728 // if talent known but not triggered (check priest class for speedup check)
729 Aura
* spiritOfRedemtionTalentReady
= NULL
;
730 if( !damageFromSpiritOfRedemtionTalent
&& // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION
731 pVictim
->GetTypeId()==TYPEID_PLAYER
&& pVictim
->getClass()==CLASS_PRIEST
)
733 AuraList
const& vDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
734 for(AuraList::const_iterator itr
= vDummyAuras
.begin(); itr
!= vDummyAuras
.end(); ++itr
)
736 if((*itr
)->GetSpellProto()->SpellIconID
==1654)
738 spiritOfRedemtionTalentReady
= *itr
;
744 DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE
,"SET JUST_DIED");
745 if(!spiritOfRedemtionTalentReady
)
746 pVictim
->setDeathState(JUST_DIED
);
748 DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE
,"DealDamageHealth1");
750 if(spiritOfRedemtionTalentReady
)
752 // save value before aura remove
753 uint32 ressSpellId
= pVictim
->GetUInt32Value(PLAYER_SELF_RES_SPELL
);
755 ressSpellId
= ((Player
*)pVictim
)->GetResurrectionSpellId();
757 //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers)
758 pVictim
->RemoveAllAurasOnDeath();
760 // restore for use at real death
761 pVictim
->SetUInt32Value(PLAYER_SELF_RES_SPELL
,ressSpellId
);
763 // FORM_SPIRITOFREDEMPTION and related auras
764 pVictim
->CastSpell(pVictim
,27827,true,NULL
,spiritOfRedemtionTalentReady
);
767 pVictim
->SetHealth(0);
769 // remember victim PvP death for corpse type and corpse reclaim delay
770 // at original death (not at SpiritOfRedemtionTalent timeout)
771 if( pVictim
->GetTypeId()==TYPEID_PLAYER
&& !damageFromSpiritOfRedemtionTalent
)
772 ((Player
*)pVictim
)->SetPvPDeath(player_tap
!= NULL
);
774 // Call KilledUnit for creatures
775 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->AI())
776 ((Creature
*)this)->AI()->KilledUnit(pVictim
);
779 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
781 if (GetTypeId() == TYPEID_UNIT
)
782 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE
, GetEntry());
783 else if(GetTypeId() == TYPEID_PLAYER
&& pVictim
!= this)
784 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER
, 1, ((Player
*)this)->GetTeam());
787 // 10% durability loss on death
788 // clean InHateListOf
789 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
791 // only if not player and not controlled by player pet. And not at BG
792 if (durabilityLoss
&& !player_tap
&& !((Player
*)pVictim
)->InBattleGround())
794 DEBUG_LOG("We are dead, loosing 10 percents durability");
795 ((Player
*)pVictim
)->DurabilityLossAll(0.10f
,false);
796 // durability lost message
797 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
798 ((Player
*)pVictim
)->GetSession()->SendPacket(&data
);
801 else // creature died
803 DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE
,"DealDamageNotPlayer");
804 Creature
*cVictim
= (Creature
*)pVictim
;
806 if(!cVictim
->isPet())
808 cVictim
->DeleteThreatList();
809 // only lootable if it has loot or can drop gold
810 cVictim
->PrepareBodyLootState();
812 // Call creature just died function
814 cVictim
->AI()->JustDied(this);
816 if (cVictim
->isTemporarySummon())
818 TemporarySummon
* pSummon
= (TemporarySummon
*)cVictim
;
819 if (pSummon
->GetSummonerGuid().IsCreature())
820 if(Creature
* pSummoner
= cVictim
->GetMap()->GetCreature(pSummon
->GetSummonerGuid()))
822 pSummoner
->AI()->SummonedCreatureJustDied(cVictim
);
824 else if (pOwner
&& pOwner
->GetTypeId() == TYPEID_UNIT
)
826 if (((Creature
*)pOwner
)->AI())
827 ((Creature
*)pOwner
)->AI()->SummonedCreatureJustDied(cVictim
);
830 // Dungeon specific stuff, only applies to players killing creatures
831 if(cVictim
->GetInstanceId())
833 Map
*m
= cVictim
->GetMap();
834 Player
*creditedPlayer
= GetCharmerOrOwnerPlayerOrPlayerItself();
835 // TODO: do instance binding anyway if the charmer/owner is offline
837 if(m
->IsDungeon() && creditedPlayer
)
839 if (m
->IsRaidOrHeroicDungeon())
841 if(cVictim
->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
842 ((InstanceMap
*)m
)->PermBindAllPlayers(creditedPlayer
);
846 // the reset time is set but not added to the scheduler
847 // until the players leave the instance
848 time_t resettime
= cVictim
->GetRespawnTimeEx() + 2 * HOUR
;
849 if(InstanceSave
*save
= sInstanceSaveMgr
.GetInstanceSave(cVictim
->GetInstanceId()))
850 if(save
->GetResetTime() < resettime
) save
->SetResetTime(resettime
);
856 // last damage from non duel opponent or opponent controlled creature
859 ASSERT(pVictim
->GetTypeId()==TYPEID_PLAYER
);
860 Player
*he
= (Player
*)pVictim
;
864 he
->duel
->opponent
->CombatStopWithPets(true);
865 he
->CombatStopWithPets(true);
867 he
->DuelComplete(DUEL_INTERUPTED
);
870 // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill)
871 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->InBattleGround())
873 Player
*killed
= ((Player
*)pVictim
);
874 if(BattleGround
*bg
= killed
->GetBattleGround())
876 bg
->HandleKillPlayer(killed
, player_tap
);
878 else if(pVictim
->GetTypeId() == TYPEID_UNIT
)
881 if (BattleGround
*bg
= player_tap
->GetBattleGround())
882 bg
->HandleKillUnit((Creature
*)pVictim
, player_tap
);
885 else // if (health <= damage)
887 DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE
,"DealDamageAlive");
889 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
890 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, damage
);
892 pVictim
->ModifyHealth(- (int32
)damage
);
894 if(damagetype
!= DOT
)
898 // if not have main target then attack state with target (including AI call)
899 //start melee attacks only after melee hit
900 Attack(pVictim
,(damagetype
== DIRECT_DAMAGE
));
903 // if damage pVictim call AI reaction
904 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
905 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
908 // polymorphed, hex and other negative transformed cases
909 uint32 morphSpell
= pVictim
->getTransForm();
910 if (morphSpell
&& !IsPositiveSpell(morphSpell
))
912 if (SpellEntry
const* morphEntry
= sSpellStore
.LookupEntry(morphSpell
))
914 if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_CONFUSE
))
915 pVictim
->RemoveAurasDueToSpell(morphSpell
);
916 else if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_PACIFY_SILENCE
))
917 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_PACIFY_SILENCE
, damage
);
921 if(damagetype
== DIRECT_DAMAGE
|| damagetype
== SPELL_DIRECT_DAMAGE
)
923 if (!spellProto
|| !(spellProto
->AuraInterruptFlags
&AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
))
924 pVictim
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
);
926 if (pVictim
->GetTypeId() != TYPEID_PLAYER
)
928 if(spellProto
&& IsDamageToThreatSpell(spellProto
))
929 pVictim
->AddThreat(this, float(damage
*2), (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
931 pVictim
->AddThreat(this, float(damage
), (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
933 else // victim is a player
935 // Rage from damage received
936 if(this != pVictim
&& pVictim
->getPowerType() == POWER_RAGE
)
938 uint32 rage_damage
= damage
+ (cleanDamage
? cleanDamage
->damage
: 0);
939 ((Player
*)pVictim
)->RewardRage(rage_damage
, 0, false);
942 // random durability for items (HIT TAKEN)
943 if (roll_chance_f(sWorld
.getConfig(CONFIG_FLOAT_RATE_DURABILITY_LOSS_DAMAGE
)))
945 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
946 ((Player
*)pVictim
)->DurabilityPointLossForEquipSlot(slot
);
950 if(GetTypeId()==TYPEID_PLAYER
)
952 // random durability for items (HIT DONE)
953 if (roll_chance_f(sWorld
.getConfig(CONFIG_FLOAT_RATE_DURABILITY_LOSS_DAMAGE
)))
955 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
956 ((Player
*)this)->DurabilityPointLossForEquipSlot(slot
);
960 // TODO: Store auras by interrupt flag to speed this up.
961 AuraMap
& vAuras
= pVictim
->GetAuras();
962 for (AuraMap::const_iterator i
= vAuras
.begin(), next
; i
!= vAuras
.end(); i
= next
)
964 const SpellEntry
*se
= i
->second
->GetSpellProto();
966 if (spellProto
&& spellProto
->Id
== se
->Id
) // Not drop auras added by self
968 if( se
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_DAMAGE
)
971 if (se
->procFlags
& (1<<3))
973 if (!roll_chance_i(se
->procChance
))
978 pVictim
->RemoveAurasDueToSpell(i
->second
->GetId());
979 // FIXME: this may cause the auras with proc chance to be rerolled several times
980 next
= vAuras
.begin();
985 if (damagetype
!= NODAMAGE
&& damage
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
987 if( damagetype
!= DOT
)
989 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
991 // skip channeled spell (processed differently below)
992 if (i
== CURRENT_CHANNELED_SPELL
)
995 if(Spell
* spell
= pVictim
->GetCurrentSpell(CurrentSpellTypes(i
)))
997 if(spell
->getState() == SPELL_STATE_PREPARING
)
999 if(spell
->m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_ABORT_ON_DMG
)
1000 pVictim
->InterruptSpell(CurrentSpellTypes(i
));
1008 if(Spell
* spell
= pVictim
->m_currentSpells
[CURRENT_CHANNELED_SPELL
])
1010 if (spell
->getState() == SPELL_STATE_CASTING
)
1012 uint32 channelInterruptFlags
= spell
->m_spellInfo
->ChannelInterruptFlags
;
1013 if( channelInterruptFlags
& CHANNEL_FLAG_DELAY
)
1015 if(pVictim
!=this) //don't shorten the duration of channeling if you damage yourself
1016 spell
->DelayedChannel();
1018 else if( (channelInterruptFlags
& (CHANNEL_FLAG_DAMAGE
| CHANNEL_FLAG_DAMAGE2
)) )
1020 DETAIL_LOG("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
1021 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
1024 else if (spell
->getState() == SPELL_STATE_DELAYED
)
1025 // break channeled spell in delayed state on damage
1027 DETAIL_LOG("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
1028 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
1033 // last damage from duel opponent
1036 ASSERT(pVictim
->GetTypeId()==TYPEID_PLAYER
);
1037 Player
*he
= (Player
*)pVictim
;
1043 he
->duel
->opponent
->CombatStopWithPets(true);
1044 he
->CombatStopWithPets(true);
1046 he
->CastSpell(he
, 7267, true); // beg
1047 he
->DuelComplete(DUEL_WON
);
1051 DEBUG_FILTER_LOG(LOG_FILTER_DAMAGE
,"DealDamageEnd returned %d damage", damage
);
1056 void Unit::CastStop(uint32 except_spellid
)
1058 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
1059 if (m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
!=except_spellid
)
1060 InterruptSpell(CurrentSpellTypes(i
),false);
1063 void Unit::CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1065 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1069 sLog
.outError("CastSpell: unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1073 CastSpell(Victim
, spellInfo
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1076 void Unit::CastSpell(Unit
* Victim
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1080 sLog
.outError("CastSpell: unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1085 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "WORLD: cast Item spellId - %i", spellInfo
->Id
);
1087 if(originalCaster
.IsEmpty() && triggeredByAura
)
1088 originalCaster
= triggeredByAura
->GetCasterGUID();
1090 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1092 SpellCastTargets targets
;
1093 targets
.setUnitTarget( Victim
);
1094 spell
->m_CastItem
= castItem
;
1095 spell
->prepare(&targets
, triggeredByAura
);
1098 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1100 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1104 sLog
.outError("CastCustomSpell: unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1108 CastCustomSpell(Victim
, spellInfo
, bp0
, bp1
, bp2
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1111 void Unit::CastCustomSpell(Unit
* Victim
, SpellEntry
const *spellInfo
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1115 sLog
.outError("CastCustomSpell: unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1120 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "WORLD: cast Item spellId - %i", spellInfo
->Id
);
1122 if(originalCaster
.IsEmpty() && triggeredByAura
)
1123 originalCaster
= triggeredByAura
->GetCasterGUID();
1125 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1128 spell
->m_currentBasePoints
[EFFECT_INDEX_0
] = *bp0
;
1131 spell
->m_currentBasePoints
[EFFECT_INDEX_1
] = *bp1
;
1134 spell
->m_currentBasePoints
[EFFECT_INDEX_2
] = *bp2
;
1136 SpellCastTargets targets
;
1137 targets
.setUnitTarget( Victim
);
1138 spell
->m_CastItem
= castItem
;
1139 spell
->prepare(&targets
, triggeredByAura
);
1142 // used for scripting
1143 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1145 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1149 sLog
.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1153 CastSpell(x
, y
, z
, spellInfo
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1156 // used for scripting
1157 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1161 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1166 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "WORLD: cast Item spellId - %i", spellInfo
->Id
);
1168 if(originalCaster
.IsEmpty() && triggeredByAura
)
1169 originalCaster
= triggeredByAura
->GetCasterGUID();
1171 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1173 SpellCastTargets targets
;
1174 targets
.setDestination(x
, y
, z
);
1175 spell
->m_CastItem
= castItem
;
1176 spell
->prepare(&targets
, triggeredByAura
);
1179 // Obsolete func need remove, here only for comotability vs another patches
1180 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
)
1182 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
1183 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, spellInfo
->SchoolMask
);
1184 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
1185 damageInfo
.target
->CalculateAbsorbResistBlock(this, &damageInfo
, spellInfo
);
1186 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
1187 SendSpellNonMeleeDamageLog(&damageInfo
);
1188 DealSpellDamage(&damageInfo
, true);
1189 return damageInfo
.damage
;
1192 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
1194 SpellSchoolMask damageSchoolMask
= SpellSchoolMask(damageInfo
->schoolMask
);
1195 Unit
*pVictim
= damageInfo
->target
;
1200 if(!this || !pVictim
)
1202 if(!this->isAlive() || !pVictim
->isAlive())
1205 // Check spell crit chance
1206 bool crit
= IsSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
1208 // damage bonus (per damage class)
1209 switch (spellInfo
->DmgClass
)
1211 // Melee and Ranged Spells
1212 case SPELL_DAMAGE_CLASS_RANGED
:
1213 case SPELL_DAMAGE_CLASS_MELEE
:
1215 //Calculate damage bonus
1216 damage
= MeleeDamageBonusDone(pVictim
, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1217 damage
= pVictim
->MeleeDamageBonusTaken(this, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1219 // if crit add critical bonus
1222 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1223 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1224 // Resilience - reduce crit damage
1225 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1226 if (attackType
!= RANGED_ATTACK
)
1227 damage
-= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1229 damage
-= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1234 case SPELL_DAMAGE_CLASS_NONE
:
1235 case SPELL_DAMAGE_CLASS_MAGIC
:
1237 // Calculate damage bonus
1238 damage
= SpellDamageBonusDone(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1239 damage
= pVictim
->SpellDamageBonusTaken(this, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1241 // If crit add critical bonus
1244 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1245 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1246 // Resilience - reduce crit damage
1247 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1248 damage
-= pVictim
->GetSpellCritDamageReduction(redunction_affected_damage
);
1254 // only from players
1255 if (GetTypeId() == TYPEID_PLAYER
)
1257 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1258 damage
-= pVictim
->GetSpellDamageReduction(redunction_affected_damage
);
1261 // damage mitigation
1264 // physical damage => armor
1265 if (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
1267 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1268 damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(pVictim
, armor_affected_damage
);
1273 damageInfo
->damage
= damage
;
1276 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1281 Unit
*pVictim
= damageInfo
->target
;
1283 if(!this || !pVictim
)
1286 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1289 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1290 if (spellProto
== NULL
)
1292 sLog
.outError("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1296 //You don't lose health from damage taken from another player while in a sanctuary
1297 //You still see it in the combat log though
1298 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1300 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1301 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1305 // Call default DealDamage (send critical in hit info for threat calculation)
1306 CleanDamage
cleanDamage(0, BASE_ATTACK
, damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
? MELEE_HIT_CRIT
: MELEE_HIT_NORMAL
);
1307 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->schoolMask
), spellProto
, durabilityLoss
);
1310 //TODO for melee need create structure as in
1311 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1313 damageInfo
->attacker
= this;
1314 damageInfo
->target
= pVictim
;
1315 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1316 damageInfo
->attackType
= attackType
;
1317 damageInfo
->damage
= 0;
1318 damageInfo
->cleanDamage
= 0;
1319 damageInfo
->absorb
= 0;
1320 damageInfo
->resist
= 0;
1321 damageInfo
->blocked_amount
= 0;
1323 damageInfo
->TargetState
= 0;
1324 damageInfo
->HitInfo
= 0;
1325 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1326 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1327 damageInfo
->procEx
= PROC_EX_NONE
;
1328 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1330 if(!this || !pVictim
)
1332 if(!this->isAlive() || !pVictim
->isAlive())
1335 // Select HitInfo/procAttacker/procVictim flag based on attack type
1339 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
;
1340 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1341 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1344 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1345 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1346 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1349 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1350 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1351 damageInfo
->HitInfo
= 0x08;// test
1357 // Physical Immune check
1358 if (damageInfo
->target
->IsImmunedToDamage(damageInfo
->damageSchoolMask
))
1360 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1361 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1363 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1364 damageInfo
->damage
= 0;
1365 damageInfo
->cleanDamage
= 0;
1368 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1369 // Add melee damage bonus
1370 damage
= MeleeDamageBonusDone(damageInfo
->target
, damage
, damageInfo
->attackType
);
1371 damage
= damageInfo
->target
->MeleeDamageBonusTaken(this, damage
, damageInfo
->attackType
);
1372 // Calculate armor reduction
1374 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageInfo
->damageSchoolMask
);
1375 damageInfo
->damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(damageInfo
->target
, armor_affected_damage
);
1376 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1378 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1380 // Disable parry or dodge for ranged attack
1381 if (damageInfo
->attackType
== RANGED_ATTACK
)
1383 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1384 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1387 switch(damageInfo
->hitOutCome
)
1389 case MELEE_HIT_EVADE
:
1391 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1392 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1394 damageInfo
->procEx
|=PROC_EX_EVADE
;
1395 damageInfo
->damage
= 0;
1396 damageInfo
->cleanDamage
= 0;
1399 case MELEE_HIT_MISS
:
1401 damageInfo
->HitInfo
|= HITINFO_MISS
;
1402 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1404 damageInfo
->procEx
|=PROC_EX_MISS
;
1405 damageInfo
->damage
= 0;
1406 damageInfo
->cleanDamage
= 0;
1409 case MELEE_HIT_NORMAL
:
1410 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1411 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1413 case MELEE_HIT_CRIT
:
1415 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1416 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1418 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1420 damageInfo
->damage
+= damageInfo
->damage
;
1422 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1423 if(damageInfo
->attackType
== RANGED_ATTACK
)
1424 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1426 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1428 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, SPELL_SCHOOL_MASK_NORMAL
);
1430 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1432 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1433 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1435 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1437 // Resilience - reduce crit damage
1438 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1439 uint32 resilienceReduction
;
1440 if (attackType
!= RANGED_ATTACK
)
1441 resilienceReduction
= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1443 resilienceReduction
= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1445 damageInfo
->damage
-= resilienceReduction
;
1446 damageInfo
->cleanDamage
+= resilienceReduction
;
1449 case MELEE_HIT_PARRY
:
1450 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1451 damageInfo
->procEx
|= PROC_EX_PARRY
;
1452 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1453 damageInfo
->damage
= 0;
1456 case MELEE_HIT_DODGE
:
1457 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1458 damageInfo
->procEx
|=PROC_EX_DODGE
;
1459 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1460 damageInfo
->damage
= 0;
1462 case MELEE_HIT_BLOCK
:
1464 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1465 damageInfo
->HitInfo
|= HITINFO_BLOCK
;
1466 damageInfo
->procEx
|= PROC_EX_BLOCK
;
1467 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1469 // Target has a chance to double the blocked amount if it has SPELL_AURA_MOD_BLOCK_CRIT_CHANCE
1470 if (roll_chance_i(pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_CRIT_CHANCE
)))
1471 damageInfo
->blocked_amount
*= 2;
1473 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1475 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1476 damageInfo
->blocked_amount
= damageInfo
->damage
;
1477 damageInfo
->procEx
|= PROC_EX_FULL_BLOCK
;
1480 damageInfo
->procEx
|= PROC_EX_NORMAL_HIT
; // Partial blocks can still cause attacker procs
1482 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1483 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1486 case MELEE_HIT_GLANCING
:
1488 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1489 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1490 damageInfo
->procEx
|= PROC_EX_NORMAL_HIT
;
1491 float reducePercent
= 1.0f
; //damage factor
1492 // calculate base values and mods
1493 float baseLowEnd
= 1.3f
;
1494 float baseHighEnd
= 1.2f
;
1495 switch(getClass()) // lowering base values for casters
1503 baseHighEnd
-= 0.3f
;
1507 float maxLowEnd
= 0.6f
;
1508 switch(getClass()) // upper for melee classes
1512 maxLowEnd
= 0.91f
; //If the attacker is a melee class then instead the lower value of 0.91
1516 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1517 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1518 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1520 // apply max/min bounds
1521 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1523 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1526 if ( highEnd
< 0.2f
) //high end limits
1528 if ( highEnd
> 0.99f
)
1531 if(lowEnd
> highEnd
) // prevent negative range size
1534 reducePercent
= lowEnd
+ rand_norm_f() * ( highEnd
- lowEnd
);
1536 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1537 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1540 case MELEE_HIT_CRUSHING
:
1542 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1543 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1544 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1545 // 150% normal damage
1546 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1554 // only from players
1555 if (GetTypeId() == TYPEID_PLAYER
)
1557 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1558 uint32 resilienceReduction
;
1559 if (attackType
!= RANGED_ATTACK
)
1560 resilienceReduction
= pVictim
->GetMeleeDamageReduction(redunction_affected_damage
);
1562 resilienceReduction
= pVictim
->GetRangedDamageReduction(redunction_affected_damage
);
1563 damageInfo
->damage
-= resilienceReduction
;
1564 damageInfo
->cleanDamage
+= resilienceReduction
;
1567 // Calculate absorb resist
1568 if(int32(damageInfo
->damage
) > 0)
1570 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1572 // Calculate absorb & resists
1573 uint32 absorb_affected_damage
= CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1574 damageInfo
->target
->CalculateAbsorbAndResist(this, damageInfo
->damageSchoolMask
, DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, true);
1575 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1576 if (damageInfo
->absorb
)
1578 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1579 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1581 if (damageInfo
->resist
)
1582 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1585 else // Umpossible get negative result but....
1586 damageInfo
->damage
= 0;
1589 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1591 if (damageInfo
==0) return;
1592 Unit
*pVictim
= damageInfo
->target
;
1594 if(!this || !pVictim
)
1597 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1600 //You don't lose health from damage taken from another player while in a sanctuary
1601 //You still see it in the combat log though
1602 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1604 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1605 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1609 // Hmmmm dont like this emotes client must by self do all animations
1610 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1611 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1612 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1613 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1615 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1617 // Get attack timers
1618 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1619 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1620 // Reduce attack time
1621 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1623 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20f
;
1624 float percent60
= 3.0f
* percent20
;
1625 if(offtime
> percent20
&& offtime
<= percent60
)
1627 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1629 else if(offtime
> percent60
)
1631 offtime
-= 2.0f
* percent20
;
1632 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1637 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20f
;
1638 float percent60
= 3.0f
* percent20
;
1639 if(basetime
> percent20
&& basetime
<= percent60
)
1641 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1643 else if(basetime
> percent60
)
1645 basetime
-= 2.0f
* percent20
;
1646 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1651 // Call default DealDamage
1652 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1653 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, damageInfo
->damageSchoolMask
, NULL
, durabilityLoss
);
1655 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1656 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1657 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI_F
, this) )
1659 // -probability is between 0% and 40%
1661 float Probability
= 20.0f
;
1663 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1664 if( pVictim
->getLevel() < 30 )
1665 Probability
= 0.65f
*pVictim
->getLevel()+0.5f
;
1667 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1668 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1670 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1672 if(Probability
> 40.0f
)
1673 Probability
= 40.0f
;
1675 if(roll_chance_f(Probability
))
1676 CastSpell(pVictim
, 1604, true);
1680 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1682 // on weapon hit casts
1683 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1684 ((Player
*)this)->CastItemCombatSpell(pVictim
, damageInfo
->attackType
);
1686 // victim's damage shield
1687 std::set
<Aura
*> alreadyDone
;
1688 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1689 for(AuraList::const_iterator i
= vDamageShields
.begin(); i
!= vDamageShields
.end();)
1691 if (alreadyDone
.find(*i
) == alreadyDone
.end())
1693 alreadyDone
.insert(*i
);
1694 uint32 damage
=(*i
)->GetModifier()->m_amount
;
1695 SpellEntry
const *i_spellProto
= (*i
)->GetSpellProto();
1696 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
1699 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1700 //damage-=absorb + resist;
1702 pVictim
->DealDamageMods(this,damage
,NULL
);
1704 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4+4+4));
1705 data
<< uint64(pVictim
->GetGUID());
1706 data
<< uint64(GetGUID());
1707 data
<< uint32(i_spellProto
->Id
);
1708 data
<< uint32(damage
); // Damage
1709 data
<< uint32(0); // Overkill
1710 data
<< uint32(i_spellProto
->SchoolMask
);
1711 pVictim
->SendMessageToSet(&data
, true );
1713 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(i_spellProto
), i_spellProto
, true);
1715 i
= vDamageShields
.begin();
1724 void Unit::HandleEmoteCommand(uint32 anim_id
)
1726 WorldPacket
data( SMSG_EMOTE
, 4 + 8 );
1727 data
<< uint32(anim_id
);
1728 data
<< uint64(GetGUID());
1729 SendMessageToSet(&data
, true);
1732 void Unit::HandleEmoteState(uint32 anim_id
)
1734 SetUInt32Value(UNIT_NPC_EMOTESTATE
, anim_id
);
1737 void Unit::HandleEmote(uint32 anim_id
)
1740 HandleEmoteState(0);
1741 else if (EmotesEntry
const* emoteEntry
= sEmotesStore
.LookupEntry(anim_id
))
1743 if (emoteEntry
->EmoteType
) // 1,2 states, 0 command
1744 HandleEmoteState(anim_id
);
1746 HandleEmoteCommand(anim_id
);
1750 uint32
Unit::CalcNotIgnoreAbsorbDamage( uint32 damage
, SpellSchoolMask damageSchoolMask
, SpellEntry
const* spellInfo
/*= NULL*/)
1752 float absorb_affected_rate
= 1.0f
;
1753 Unit::AuraList
const& ignoreAbsorbSchool
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_SCHOOL
);
1754 for(Unit::AuraList::const_iterator i
= ignoreAbsorbSchool
.begin(); i
!= ignoreAbsorbSchool
.end(); ++i
)
1755 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1756 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1760 Unit::AuraList
const& ignoreAbsorbForSpell
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL
);
1761 for(Unit::AuraList::const_iterator citr
= ignoreAbsorbForSpell
.begin(); citr
!= ignoreAbsorbForSpell
.end(); ++citr
)
1762 if ((*citr
)->isAffectedOnSpell(spellInfo
))
1763 absorb_affected_rate
*= (100.0f
- (*citr
)->GetModifier()->m_amount
)/100.0f
;
1766 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1769 uint32
Unit::CalcNotIgnoreDamageRedunction( uint32 damage
, SpellSchoolMask damageSchoolMask
)
1771 float absorb_affected_rate
= 1.0f
;
1772 Unit::AuraList
const& ignoreAbsorb
= GetAurasByType(SPELL_AURA_MOD_IGNORE_DAMAGE_REDUCTION_SCHOOL
);
1773 for(Unit::AuraList::const_iterator i
= ignoreAbsorb
.begin(); i
!= ignoreAbsorb
.end(); ++i
)
1774 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1775 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1777 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1780 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
1782 uint32 newdamage
= 0;
1783 float armor
= (float)pVictim
->GetArmor();
1785 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
1786 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
1788 // Apply Player CR_ARMOR_PENETRATION rating and percent talents
1789 if (GetTypeId()==TYPEID_PLAYER
)
1790 armor
*= 1.0f
- ((Player
*)this)->GetArmorPenetrationPct() / 100.0f
;
1795 float levelModifier
= (float)getLevel();
1796 if (levelModifier
> 59)
1797 levelModifier
= levelModifier
+ (4.5f
* (levelModifier
-59));
1799 float tmpvalue
= 0.1f
* armor
/ (8.5f
* levelModifier
+ 40);
1800 tmpvalue
= tmpvalue
/(1.0f
+ tmpvalue
);
1802 if (tmpvalue
< 0.0f
)
1804 if (tmpvalue
> 0.75f
)
1807 newdamage
= uint32(damage
- (damage
* tmpvalue
));
1809 return (newdamage
> 1) ? newdamage
: 1;
1812 void Unit::CalculateAbsorbAndResist(Unit
*pCaster
, SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
, bool canReflect
)
1814 if(!pCaster
|| !isAlive() || !damage
)
1817 // Magic damage, check for resists
1818 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
1820 // Get base victim resistance for school
1821 float tmpvalue2
= (float)GetResistance(GetFirstSchoolInMask(schoolMask
));
1822 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
1823 tmpvalue2
+= (float)pCaster
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
1825 tmpvalue2
*= (float)(0.15f
/ getLevel());
1826 if (tmpvalue2
< 0.0f
)
1828 if (tmpvalue2
> 0.75f
)
1830 uint32 ran
= urand(0, 100);
1831 float faq
[4] = {24.0f
,6.0f
,4.0f
,6.0f
};
1834 for (uint8 i
= 0; i
< 4; ++i
)
1836 Binom
+= 2400 *( powf(tmpvalue2
, float(i
)) * powf( (1-tmpvalue2
), float(4-i
)))/faq
[i
];
1842 if (damagetype
== DOT
&& m
== 4)
1843 *resist
+= uint32(damage
- 1);
1845 *resist
+= uint32(damage
* m
/ 4);
1846 if(*resist
> damage
)
1852 int32 RemainingDamage
= damage
- *resist
;
1854 // Get unit state (need for some absorb check)
1855 uint32 unitflag
= GetUInt32Value(UNIT_FIELD_FLAGS
);
1856 // Reflect damage spells (not cast any damage spell in aura lookup)
1857 uint32 reflectSpell
= 0;
1858 int32 reflectDamage
= 0;
1859 Aura
* reflectTriggeredBy
= NULL
; // expected as not expired at reflect as in current cases
1860 // Death Prevention Aura
1861 SpellEntry
const* preventDeathSpell
= NULL
;
1862 int32 preventDeathAmount
= 0;
1864 // full absorb cases (by chance)
1865 AuraList
const& vAbsorb
= GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1866 for(AuraList::const_iterator i
= vAbsorb
.begin(); i
!= vAbsorb
.end() && RemainingDamage
> 0; ++i
)
1868 // only work with proper school mask damage
1869 Modifier
* i_mod
= (*i
)->GetModifier();
1870 if (!(i_mod
->m_miscvalue
& schoolMask
))
1873 SpellEntry
const* i_spellProto
= (*i
)->GetSpellProto();
1874 // Fire Ward or Frost Ward
1875 if(i_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& i_spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000108))
1878 Unit::AuraList
const& auras
= GetAurasByType(SPELL_AURA_ADD_PCT_MODIFIER
);
1879 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
1881 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
1882 // Frost Warding (chance full absorb)
1883 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& itr_spellProto
->SpellIconID
== 501)
1885 // chance stored in next dummy effect
1886 chance
= itr_spellProto
->CalculateSimpleValue(EFFECT_INDEX_1
);
1890 if(roll_chance_i(chance
))
1892 int32 amount
= RemainingDamage
;
1893 RemainingDamage
= 0;
1895 // Frost Warding (mana regen)
1896 CastCustomSpell(this, 57776, &amount
, NULL
, NULL
, true, NULL
, *i
);
1902 // Need remove expired auras after
1903 bool existExpired
= false;
1905 // Incanter's Absorption, for converting to spell power
1906 int32 incanterAbsorption
= 0;
1908 // absorb without mana cost
1909 AuraList
const& vSchoolAbsorb
= GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1910 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; ++i
)
1912 Modifier
* mod
= (*i
)->GetModifier();
1913 if (!(mod
->m_miscvalue
& schoolMask
))
1916 SpellEntry
const* spellProto
= (*i
)->GetSpellProto();
1918 // Max Amount can be absorbed by this aura
1919 int32 currentAbsorb
= mod
->m_amount
;
1921 // Found empty aura (impossible but..)
1922 if (currentAbsorb
<=0)
1924 existExpired
= true;
1927 // Handle custom absorb auras
1928 // TODO: try find better way
1929 switch(spellProto
->SpellFamilyName
)
1931 case SPELLFAMILY_GENERIC
:
1934 if (spellProto
->SpellIconID
== 3066)
1936 //reduces all damage taken while stun, fear or silence
1937 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1938 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1942 if (spellProto
->SpellIconID
== 2115)
1944 // while affected by Stun and Fear
1945 if (unitflag
&(UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
))
1946 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1950 if (spellProto
->SpellIconID
== 3006)
1952 // You have a chance equal to your Parry chance
1953 if (damagetype
== DIRECT_DAMAGE
&& // Only for direct damage
1954 roll_chance_f(GetUnitParryChance())) // Roll chance
1955 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1958 // Reflective Shield (Lady Malande boss)
1959 if (spellProto
->Id
== 41475 && canReflect
)
1961 if(RemainingDamage
< currentAbsorb
)
1962 reflectDamage
= RemainingDamage
/ 2;
1964 reflectDamage
= currentAbsorb
/ 2;
1965 reflectSpell
= 33619;
1966 reflectTriggeredBy
= *i
;
1969 if (spellProto
->Id
== 39228 || // Argussian Compass
1970 spellProto
->Id
== 60218) // Essence of Gossamer
1972 // Max absorb stored in 1 dummy effect
1973 int32 max_absorb
= spellProto
->CalculateSimpleValue(EFFECT_INDEX_1
);
1974 if (max_absorb
< currentAbsorb
)
1975 currentAbsorb
= max_absorb
;
1980 case SPELLFAMILY_DRUID
:
1983 if (spellProto
->SpellIconID
== 2253)
1985 //reduces all damage taken while Stunned and in Cat Form
1986 if (m_form
== FORM_CAT
&& (unitflag
& UNIT_FLAG_STUNNED
))
1987 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1992 case SPELLFAMILY_ROGUE
:
1994 // Cheat Death (make less prio with Guardian Spirit case)
1995 if (!preventDeathSpell
&& spellProto
->SpellIconID
== 2109 &&
1996 GetTypeId()==TYPEID_PLAYER
&& // Only players
1997 !((Player
*)this)->HasSpellCooldown(31231) &&
1998 // Only if no cooldown
1999 roll_chance_i((*i
)->GetModifier()->m_amount
))
2002 preventDeathSpell
= (*i
)->GetSpellProto();
2007 case SPELLFAMILY_PRIEST
:
2010 if (spellProto
->SpellIconID
== 2873)
2012 preventDeathSpell
= (*i
)->GetSpellProto();
2013 preventDeathAmount
= (*i
)->GetModifier()->m_amount
;
2016 // Reflective Shield
2017 if (spellProto
->SpellFamilyFlags
== 0x1 && canReflect
)
2019 if (pCaster
== this)
2021 Unit
* caster
= (*i
)->GetCaster();
2024 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
2025 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
2027 switch((*k
)->GetModifier()->m_miscvalue
)
2029 case 5065: // Rank 1
2030 case 5064: // Rank 2
2032 if(RemainingDamage
>= currentAbsorb
)
2033 reflectDamage
= (*k
)->GetModifier()->m_amount
* currentAbsorb
/100;
2035 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
2036 reflectSpell
= 33619;
2037 reflectTriggeredBy
= *i
;
2046 case SPELLFAMILY_SHAMAN
:
2049 if (spellProto
->SpellIconID
== 3066)
2051 //reduces all damage taken while stun, fear or silence
2052 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
2053 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2058 case SPELLFAMILY_DEATHKNIGHT
:
2061 if (spellProto
->SpellIconID
== 1958)
2063 // TODO: absorb only while transform
2066 // Anti-Magic Shell (on self)
2067 if (spellProto
->Id
== 48707)
2069 // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power.
2070 // This, if I'm not mistaken, shows that we get back ~2% of the absorbed damage as runic power.
2071 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
2072 int32 regen
= absorbed
* 2 / 10;
2073 CastCustomSpell(this, 49088, ®en
, NULL
, NULL
, true, NULL
, *i
);
2074 RemainingDamage
-= absorbed
;
2077 // Anti-Magic Shell (on single party/raid member)
2078 if (spellProto
->Id
== 50462)
2080 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2084 if (spellProto
->Id
== 50461)
2086 Unit
* caster
= (*i
)->GetCaster();
2089 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
2090 int32 canabsorb
= caster
->GetHealth();
2091 if (canabsorb
< absorbed
)
2092 absorbed
= canabsorb
;
2094 RemainingDamage
-= absorbed
;
2096 uint32 ab_damage
= absorbed
;
2097 pCaster
->DealDamageMods(caster
,ab_damage
,NULL
);
2098 pCaster
->DealDamage(caster
, ab_damage
, NULL
, damagetype
, schoolMask
, 0, false);
2107 // currentAbsorb - damage can be absorbed by shield
2108 // If need absorb less damage
2109 if (RemainingDamage
< currentAbsorb
)
2110 currentAbsorb
= RemainingDamage
;
2112 RemainingDamage
-= currentAbsorb
;
2114 // Fire Ward or Frost Ward or Ice Barrier (or Mana Shield)
2115 // for Incanter's Absorption converting to spell power
2116 if (spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& spellProto
->SpellFamilyFlags2
& 0x000008)
2117 incanterAbsorption
+= currentAbsorb
;
2119 // Reduce shield amount
2120 mod
->m_amount
-=currentAbsorb
;
2121 if((*i
)->DropAuraCharge())
2123 // Need remove it later
2124 if (mod
->m_amount
<=0)
2125 existExpired
= true;
2128 // Remove all expired absorb auras
2131 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end();)
2133 if ((*i
)->GetModifier()->m_amount
<=0)
2135 RemoveAurasDueToSpell((*i
)->GetId());
2136 i
= vSchoolAbsorb
.begin();
2143 // Cast back reflect damage spell
2144 if (canReflect
&& reflectSpell
)
2145 CastCustomSpell(pCaster
, reflectSpell
, &reflectDamage
, NULL
, NULL
, true, NULL
, reflectTriggeredBy
);
2147 // absorb by mana cost
2148 AuraList
const& vManaShield
= GetAurasByType(SPELL_AURA_MANA_SHIELD
);
2149 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
2153 // check damage school mask
2154 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2157 int32 currentAbsorb
;
2158 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2159 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2161 currentAbsorb
= RemainingDamage
;
2163 if (float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()])
2165 if(Player
*modOwner
= GetSpellModOwner())
2166 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
2168 int32 maxAbsorb
= int32(GetPower(POWER_MANA
) / manaMultiplier
);
2169 if (currentAbsorb
> maxAbsorb
)
2170 currentAbsorb
= maxAbsorb
;
2172 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
2173 ApplyPowerMod(POWER_MANA
, manaReduction
, false);
2176 // Mana Shield (or Fire Ward or Frost Ward or Ice Barrier)
2177 // for Incanter's Absorption converting to spell power
2178 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_MAGE
&& (*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x000008)
2179 incanterAbsorption
+= currentAbsorb
;
2181 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
2182 if((*i
)->GetModifier()->m_amount
<= 0)
2184 RemoveAurasDueToSpell((*i
)->GetId());
2185 next
= vManaShield
.begin();
2188 RemainingDamage
-= currentAbsorb
;
2191 // effects dependent from full absorb amount
2192 // Incanter's Absorption, if have affective absorbing
2193 if (incanterAbsorption
)
2195 Unit::AuraList
const& auras
= GetAurasByType(SPELL_AURA_DUMMY
);
2196 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
2198 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
2200 // Incanter's Absorption
2201 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_GENERIC
&&
2202 itr_spellProto
->SpellIconID
== 2941)
2205 int32 amount
= int32(incanterAbsorption
* (*itr
)->GetModifier()->m_amount
/ 100);
2207 // apply normalized part of already accumulated amount in aura
2208 if (Aura
* spdAura
= GetAura(44413, EFFECT_INDEX_0
))
2209 amount
+= spdAura
->GetModifier()->m_amount
* spdAura
->GetAuraDuration() / spdAura
->GetAuraMaxDuration();
2211 // Incanter's Absorption (triggered absorb based spell power, will replace existed if any)
2212 CastCustomSpell(this, 44413, &amount
, NULL
, NULL
, true);
2218 // only split damage if not damaging yourself
2221 AuraList
const& vSplitDamageFlat
= GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
2222 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
2226 // check damage school mask
2227 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2230 // Damage can be splitted only if aura has an alive caster
2231 Unit
*caster
= (*i
)->GetCaster();
2232 if(!caster
|| caster
== this || !caster
->IsInWorld() || !caster
->isAlive())
2235 int32 currentAbsorb
;
2236 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2237 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2239 currentAbsorb
= RemainingDamage
;
2241 RemainingDamage
-= currentAbsorb
;
2244 uint32 splitted
= currentAbsorb
;
2245 uint32 splitted_absorb
= 0;
2246 pCaster
->DealDamageMods(caster
,splitted
,&splitted_absorb
);
2248 pCaster
->SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, splitted_absorb
, 0, false, 0, false);
2250 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2251 pCaster
->DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2254 AuraList
const& vSplitDamagePct
= GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
2255 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
2259 // check damage school mask
2260 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2263 // Damage can be splitted only if aura has an alive caster
2264 Unit
*caster
= (*i
)->GetCaster();
2265 if(!caster
|| caster
== this || !caster
->IsInWorld() || !caster
->isAlive())
2268 uint32 splitted
= uint32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
2270 RemainingDamage
-= int32(splitted
);
2272 uint32 split_absorb
= 0;
2273 pCaster
->DealDamageMods(caster
,splitted
,&split_absorb
);
2275 pCaster
->SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, split_absorb
, 0, false, 0, false);
2277 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2278 pCaster
->DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2282 // Apply death prevention spells effects
2283 if (preventDeathSpell
&& RemainingDamage
>= (int32
)GetHealth())
2285 switch(preventDeathSpell
->SpellFamilyName
)
2288 case SPELLFAMILY_ROGUE
:
2291 if (preventDeathSpell
->SpellIconID
== 2109)
2293 CastSpell(this,31231,true);
2294 ((Player
*)this)->AddSpellCooldown(31231,0,time(NULL
)+60);
2295 // with health > 10% lost health until health==10%, in other case no losses
2296 uint32 health10
= GetMaxHealth()/10;
2297 RemainingDamage
= GetHealth() > health10
? GetHealth() - health10
: 0;
2302 case SPELLFAMILY_PRIEST
:
2305 if (preventDeathSpell
->SpellIconID
== 2873)
2307 int32 healAmount
= GetMaxHealth() * preventDeathAmount
/ 100;
2308 CastCustomSpell(this, 48153, &healAmount
, NULL
, NULL
, true);
2309 RemoveAurasDueToSpell(preventDeathSpell
->Id
);
2310 RemainingDamage
= 0;
2317 *absorb
= damage
- RemainingDamage
- *resist
;
2320 void Unit::CalculateAbsorbResistBlock(Unit
*pCaster
, SpellNonMeleeDamage
*damageInfo
, SpellEntry
const* spellProto
, WeaponAttackType attType
)
2322 bool blocked
= false;
2323 // Get blocked status
2324 switch (spellProto
->DmgClass
)
2326 // Melee and Ranged Spells
2327 case SPELL_DAMAGE_CLASS_RANGED
:
2328 case SPELL_DAMAGE_CLASS_MELEE
:
2329 blocked
= IsSpellBlocked(pCaster
, spellProto
, attType
);
2337 damageInfo
->blocked
= GetShieldBlockValue();
2338 if (damageInfo
->damage
< (int32
)damageInfo
->blocked
)
2339 damageInfo
->blocked
= damageInfo
->damage
;
2340 damageInfo
->damage
-=damageInfo
->blocked
;
2343 uint32 absorb_affected_damage
= pCaster
->CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,GetSpellSchoolMask(spellProto
),spellProto
);
2344 CalculateAbsorbAndResist(pCaster
, GetSpellSchoolMask(spellProto
), SPELL_DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, !(spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
));
2345 damageInfo
->damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
2348 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
2350 if(hasUnitState(UNIT_STAT_CAN_NOT_REACT
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
2353 if (!pVictim
->isAlive())
2356 if(IsNonMeleeSpellCasted(false))
2360 if (attType
== BASE_ATTACK
)
2361 hitInfo
= HITINFO_NORMALSWING2
;
2362 else if (attType
== OFF_ATTACK
)
2363 hitInfo
= HITINFO_LEFTSWING
;
2365 return; // ignore ranged case
2367 uint32 extraAttacks
= m_extraAttacks
;
2369 // melee attack spell casted at main hand attack only
2370 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
2372 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
2374 // not recent extra attack only at any non extra attack (melee spell case)
2375 if(!extra
&& extraAttacks
)
2377 while(m_extraAttacks
)
2379 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2380 if(m_extraAttacks
> 0)
2387 // attack can be redirected to another target
2388 pVictim
= SelectMagnetTarget(pVictim
);
2390 CalcDamageInfo damageInfo
;
2391 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
2392 // Send log damage message to client
2393 DealDamageMods(pVictim
,damageInfo
.damage
,&damageInfo
.absorb
);
2394 SendAttackStateUpdate(&damageInfo
);
2395 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
2396 DealMeleeDamage(&damageInfo
,true);
2398 if (GetTypeId() == TYPEID_PLAYER
)
2399 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
,"AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2400 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2402 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
,"AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2403 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2405 // if damage pVictim call AI reaction
2406 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
2407 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
2409 // extra attack only at any non extra attack (normal case)
2410 if(!extra
&& extraAttacks
)
2412 while(m_extraAttacks
)
2414 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2415 if(m_extraAttacks
> 0)
2421 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
2423 // This is only wrapper
2425 // Miss chance based on melee
2426 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
2428 // Critical hit chance
2429 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
2431 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
2432 float dodge_chance
= pVictim
->GetUnitDodgeChance();
2433 float block_chance
= pVictim
->GetUnitBlockChance();
2434 float parry_chance
= pVictim
->GetUnitParryChance();
2436 // Useful if want to specify crit & miss chances for melee, else it could be removed
2437 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
,"MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance
,crit_chance
,dodge_chance
,parry_chance
,block_chance
);
2439 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100));
2442 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const
2444 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2445 return MELEE_HIT_EVADE
;
2447 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
2448 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
2450 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
2451 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
2453 // bonus from skills is 0.04%
2454 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
2455 int32 sum
= 0, tmp
= 0;
2456 int32 roll
= urand (0, 10000);
2458 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
2459 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
2460 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
2464 if (tmp
> 0 && roll
< (sum
+= tmp
))
2466 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: MISS");
2467 return MELEE_HIT_MISS
;
2470 // always crit against a sitting target (except 0 crit chance)
2471 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
2473 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: CRIT (sitting victim)");
2474 return MELEE_HIT_CRIT
;
2479 // only players can't dodge if attacker is behind
2480 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI_F
,this))
2482 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
2486 // Reduce dodge chance by attacker expertise rating
2487 if (GetTypeId() == TYPEID_PLAYER
)
2488 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2490 dodge_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2492 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2493 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2496 if ( (tmp
> 0) // check if unit _can_ dodge
2497 && ((tmp
-= skillBonus
) > 0)
2498 && roll
< (sum
+= tmp
))
2500 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
2501 return MELEE_HIT_DODGE
;
2505 // parry & block chances
2507 // check if attack comes from behind, nobody can parry or block if attacker is behind
2508 if (!pVictim
->HasInArc(M_PI_F
,this))
2510 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: attack came from behind.");
2514 // Reduce parry chance by attacker expertise rating
2515 if (GetTypeId() == TYPEID_PLAYER
)
2516 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2518 parry_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2520 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
2522 int32 tmp2
= int32(parry_chance
);
2523 if ( (tmp2
> 0) // check if unit _can_ parry
2524 && ((tmp2
-= skillBonus
) > 0)
2525 && (roll
< (sum
+= tmp2
)))
2527 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp2
, sum
);
2528 return MELEE_HIT_PARRY
;
2532 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
2535 if ( (tmp
> 0) // check if unit _can_ block
2536 && ((tmp
-= skillBonus
) > 0)
2537 && (roll
< (sum
+= tmp
)))
2539 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
2540 return MELEE_HIT_BLOCK
;
2548 if (tmp
> 0 && roll
< (sum
+= tmp
))
2550 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
2551 return MELEE_HIT_CRIT
;
2554 // 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)
2555 if( attType
!= RANGED_ATTACK
&&
2556 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
2557 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
2558 getLevel() < pVictim
->getLevelForTarget(this) )
2560 // cap possible value (with bonuses > max skill)
2561 int32 skill
= attackerWeaponSkill
;
2562 int32 maxskill
= attackerMaxSkillValueForLevel
;
2563 skill
= (skill
> maxskill
) ? maxskill
: skill
;
2565 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
2566 tmp
= tmp
> 4000 ? 4000 : tmp
;
2567 if (roll
< (sum
+= tmp
))
2569 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
2570 return MELEE_HIT_GLANCING
;
2574 // mobs can score crushing blows if they're 4 or more levels above victim
2575 if (getLevelForTarget(pVictim
) >= pVictim
->getLevelForTarget(this) + 4 &&
2576 // can be from by creature (if can) or from controlled player that considered as creature
2577 (GetTypeId()!=TYPEID_PLAYER
&& !((Creature
*)this)->isPet() &&
2578 !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) ||
2579 GetTypeId()==TYPEID_PLAYER
&& GetCharmerOrOwnerGUID()))
2581 // when their weapon skill is 15 or more above victim's defense skill
2582 tmp
= victimDefenseSkill
;
2583 int32 tmpmax
= victimMaxSkillValueForLevel
;
2584 // having defense above your maximum (from items, talents etc.) has no effect
2585 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
2586 // tmp = mob's level * 5 - player's current defense skill
2587 tmp
= attackerMaxSkillValueForLevel
- tmp
;
2590 // add 2% chance per lacking skill point, min. is 15%
2591 tmp
= tmp
* 200 - 1500;
2592 if (roll
< (sum
+= tmp
))
2594 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
2595 return MELEE_HIT_CRUSHING
;
2600 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: NORMAL");
2601 return MELEE_HIT_NORMAL
;
2604 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
2606 float min_damage
, max_damage
;
2608 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
2609 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
2615 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
2616 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
2619 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
2620 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
2623 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
2624 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
2626 // Just for good manner
2634 if (min_damage
> max_damage
)
2636 std::swap(min_damage
,max_damage
);
2639 if(max_damage
== 0.0f
)
2642 return urand((uint32
)min_damage
, (uint32
)max_damage
);
2645 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
2647 if(spellProto
->spellLevel
<= 0)
2650 float LvlPenalty
= 0.0f
;
2652 if(spellProto
->spellLevel
< 20)
2653 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
2654 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
2655 if(LvlFactor
> 1.0f
)
2658 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
2661 void Unit::SendMeleeAttackStart(Unit
* pVictim
)
2663 WorldPacket
data( SMSG_ATTACKSTART
, 8 + 8 );
2664 data
<< uint64(GetGUID());
2665 data
<< uint64(pVictim
->GetGUID());
2667 SendMessageToSet(&data
, true);
2668 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
2671 void Unit::SendMeleeAttackStop(Unit
* victim
)
2676 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
2677 data
<< GetPackGUID();
2678 data
<< victim
->GetPackGUID(); // can be 0x00...
2679 data
<< uint32(0); // can be 0x1
2680 SendMessageToSet(&data
, true);
2681 DETAIL_FILTER_LOG(LOG_FILTER_COMBAT
, "%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER
? "player" : "creature"), GetGUIDLow(), (victim
->GetTypeId()==TYPEID_PLAYER
? "player" : "creature"),victim
->GetGUIDLow());
2683 /*if(victim->GetTypeId() == TYPEID_UNIT)
2684 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
2687 bool Unit::IsSpellBlocked(Unit
*pCaster
, SpellEntry
const * /*spellProto*/, WeaponAttackType attackType
)
2689 if (HasInArc(M_PI_F
,pCaster
))
2691 /* Currently not exist spells with ignore block
2692 // Ignore combat result aura (parry/dodge check on prepare)
2693 AuraList const& ignore = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2694 for(AuraList::const_iterator i = ignore.begin(); i != ignore.end(); ++i)
2696 if (!(*i)->isAffectedOnSpell(spellProto))
2698 if ((*i)->GetModifier()->m_miscvalue == )
2703 // Check creatures flags_extra for disable block
2704 if(GetTypeId()==TYPEID_UNIT
&&
2705 ((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
)
2708 float blockChance
= GetUnitBlockChance();
2709 blockChance
+= (int32(pCaster
->GetWeaponSkillValue(attackType
)) - int32(GetMaxSkillValueForLevel()))*0.04f
;
2710 if (roll_chance_f(blockChance
))
2716 // Melee based spells can be miss, parry or dodge on this step
2717 // Crit or block - determined on damage calculation phase! (and can be both in some time)
2718 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
2720 // Calculate hit chance (more correct for chance mod)
2723 // PvP - PvE melee chances
2724 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2725 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
2727 HitChance
= 95 - leveldif
;
2729 HitChance
= 93 - (leveldif
- 2) * lchance
;
2731 // Hit chance depends from victim auras
2732 if(attType
== RANGED_ATTACK
)
2733 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2735 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2737 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2738 if(Player
*modOwner
= GetSpellModOwner())
2739 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
2742 float miss_chance
= 100.0f
- HitChance
;
2744 // Bonuses from attacker aura and ratings
2745 if (attType
== RANGED_ATTACK
)
2746 miss_chance
-= m_modRangedHitChance
;
2748 miss_chance
-= m_modMeleeHitChance
;
2750 // bonus from skills is 0.04%
2751 miss_chance
-= skillDiff
* 0.04f
;
2753 // Limit miss chance from 0 to 60%
2754 if (miss_chance
< 0.0f
)
2756 if (miss_chance
> 60.0f
)
2761 // Melee based spells hit result calculations
2762 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2764 WeaponAttackType attType
= BASE_ATTACK
;
2766 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
2767 attType
= RANGED_ATTACK
;
2769 // bonus from skills is 0.04% per skill Diff
2770 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
2771 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
2772 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
2774 uint32 roll
= urand (0, 10000);
2776 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
2778 uint32 tmp
= missChance
;
2780 return SPELL_MISS_MISS
;
2782 // Chance resist mechanic (select max value from every mechanic spell effect)
2783 int32 resist_mech
= 0;
2784 // Get effects mechanic and chance
2785 for(int eff
= 0; eff
< MAX_EFFECT_INDEX
; ++eff
)
2787 int32 effect_mech
= GetEffectMechanic(spell
, SpellEffectIndex(eff
));
2790 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2791 if (resist_mech
< temp
*100)
2792 resist_mech
= temp
*100;
2798 return SPELL_MISS_RESIST
;
2800 bool canDodge
= true;
2801 bool canParry
= true;
2803 // Same spells cannot be parry/dodge
2804 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
2805 return SPELL_MISS_NONE
;
2807 // Ranged attack cannot be parry/dodge only deflect
2808 if (attType
== RANGED_ATTACK
)
2811 if (pVictim
->HasInArc(M_PI_F
,this))
2813 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2814 tmp
+=deflect_chance
;
2816 return SPELL_MISS_DEFLECT
;
2818 return SPELL_MISS_NONE
;
2821 // Check for attack from behind
2822 if (!pVictim
->HasInArc(M_PI_F
,this))
2824 // Can`t dodge from behind in PvP (but its possible in PvE)
2825 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
2830 // Check creatures flags_extra for disable parry
2831 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
2833 uint32 flagEx
= ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
;
2834 if( flagEx
& CREATURE_FLAG_EXTRA_NO_PARRY
)
2837 // Ignore combat result aura
2838 AuraList
const& ignore
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
2839 for(AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
2841 if (!(*i
)->isAffectedOnSpell(spell
))
2843 switch((*i
)->GetModifier()->m_miscvalue
)
2845 case MELEE_HIT_DODGE
: canDodge
= false; break;
2846 case MELEE_HIT_BLOCK
: break; // Block check in hit step
2847 case MELEE_HIT_PARRY
: canParry
= false; break;
2849 DEBUG_LOG("Spell %u SPELL_AURA_IGNORE_COMBAT_RESULT have unhandled state %d", (*i
)->GetId(), (*i
)->GetModifier()->m_miscvalue
);
2857 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
2858 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2859 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
)*100;
2860 // Reduce dodge chance by attacker expertise rating
2861 if (GetTypeId() == TYPEID_PLAYER
)
2862 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2864 dodgeChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2865 if (dodgeChance
< 0)
2870 return SPELL_MISS_DODGE
;
2876 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
2877 // Reduce parry chance by attacker expertise rating
2878 if (GetTypeId() == TYPEID_PLAYER
)
2879 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2881 parryChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2882 if (parryChance
< 0)
2887 return SPELL_MISS_PARRY
;
2890 return SPELL_MISS_NONE
;
2893 // TODO need use unit spell resistances in calculations
2894 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2896 // Can`t miss on dead target (on skinning for example)
2897 if (!pVictim
->isAlive())
2898 return SPELL_MISS_NONE
;
2900 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
2901 // PvP - PvE spell misschances per leveldif > 2
2902 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
2903 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2905 // Base hit chance from attacker and victim levels
2908 modHitChance
= 96 - leveldif
;
2910 modHitChance
= 94 - (leveldif
- 2) * lchance
;
2912 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2913 if(Player
*modOwner
= GetSpellModOwner())
2914 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
2915 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
2916 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
2917 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
2918 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
2919 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
2920 if (IsAreaOfEffectSpell(spell
))
2921 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
2922 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
2923 if (IsDispelSpell(spell
))
2924 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
2925 // Chance resist mechanic (select max value from every mechanic spell effect)
2926 int32 resist_mech
= 0;
2927 // Get effects mechanic and chance
2928 for(int eff
= 0; eff
< MAX_EFFECT_INDEX
; ++eff
)
2930 int32 effect_mech
= GetEffectMechanic(spell
, SpellEffectIndex(eff
));
2933 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2934 if (resist_mech
< temp
)
2939 modHitChance
-=resist_mech
;
2941 // Chance resist debuff
2942 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
2944 int32 HitChance
= modHitChance
* 100;
2945 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
2946 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
2948 // Decrease hit chance from victim rating bonus
2949 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2950 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
2952 if (HitChance
< 100) HitChance
= 100;
2953 if (HitChance
> 10000) HitChance
= 10000;
2955 int32 tmp
= 10000 - HitChance
;
2957 int32 rand
= irand(0,10000);
2960 return SPELL_MISS_MISS
;
2962 // cast by caster in front of victim
2963 if (pVictim
->HasInArc(M_PI_F
,this))
2965 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2966 tmp
+=deflect_chance
;
2968 return SPELL_MISS_DEFLECT
;
2971 return SPELL_MISS_NONE
;
2974 // Calculate spell hit result can be:
2975 // Every spell can: Evade/Immune/Reflect/Sucesful hit
2976 // For melee based spells:
2982 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
2984 // Return evade for units in evade mode
2985 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2986 return SPELL_MISS_EVADE
;
2989 if (pVictim
->IsImmunedToSpell(spell
))
2990 return SPELL_MISS_IMMUNE
;
2992 // All positive spells can`t miss
2993 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
2994 if (IsPositiveSpell(spell
->Id
))
2995 return SPELL_MISS_NONE
;
2998 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
)))
2999 return SPELL_MISS_IMMUNE
;
3001 // Try victim reflect spell
3004 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
3005 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
3006 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
3007 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
3008 reflectchance
+= (*i
)->GetModifier()->m_amount
;
3009 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
3011 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
3012 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
3013 return SPELL_MISS_REFLECT
;
3017 switch (spell
->DmgClass
)
3019 case SPELL_DAMAGE_CLASS_NONE
:
3020 return SPELL_MISS_NONE
;
3021 case SPELL_DAMAGE_CLASS_MAGIC
:
3022 return MagicSpellHitResult(pVictim
, spell
);
3023 case SPELL_DAMAGE_CLASS_MELEE
:
3024 case SPELL_DAMAGE_CLASS_RANGED
:
3025 return MeleeSpellHitResult(pVictim
, spell
);
3027 return SPELL_MISS_NONE
;
3030 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
3035 // Base misschance 5%
3036 float misschance
= 5.0f
;
3038 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
3039 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
3041 bool isNormal
= false;
3042 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
3044 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
3050 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
3056 // PvP : PvE melee misschances per leveldif > 2
3057 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
3059 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
3063 // Hit chance from attacker based on ratings and auras
3064 float m_modHitChance
;
3065 if (attType
== RANGED_ATTACK
)
3066 m_modHitChance
= m_modRangedHitChance
;
3068 m_modHitChance
= m_modMeleeHitChance
;
3071 misschance
+= (leveldif
- m_modHitChance
);
3073 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
3075 // Hit chance for victim based on ratings
3076 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
3078 if (attType
== RANGED_ATTACK
)
3079 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
3081 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
3084 // Modify miss chance by victim auras
3085 if(attType
== RANGED_ATTACK
)
3086 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
3088 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
3090 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
3091 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
3092 misschance
-= skillBonus
* 0.04f
;
3094 // Limit miss chance from 0 to 60%
3095 if ( misschance
< 0.0f
)
3097 if ( misschance
> 60.0f
)
3103 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
3105 if(GetTypeId() == TYPEID_PLAYER
)
3107 // in PvP use full skill instead current skill value
3108 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3109 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
3110 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
3111 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
3115 return GetUnitMeleeSkill(target
);
3118 float Unit::GetUnitDodgeChance() const
3120 if(hasUnitState(UNIT_STAT_STUNNED
))
3122 if( GetTypeId() == TYPEID_PLAYER
)
3123 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
3126 if(((Creature
const*)this)->isTotem())
3131 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
3132 return dodge
> 0.0f
? dodge
: 0.0f
;
3137 float Unit::GetUnitParryChance() const
3139 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3142 float chance
= 0.0f
;
3144 if(GetTypeId() == TYPEID_PLAYER
)
3146 Player
const* player
= (Player
const*)this;
3147 if(player
->CanParry() )
3149 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true,true);
3151 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true,true);
3154 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
3157 else if(GetTypeId() == TYPEID_UNIT
)
3159 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
3162 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
3166 return chance
> 0.0f
? chance
: 0.0f
;
3169 float Unit::GetUnitBlockChance() const
3171 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3174 if(GetTypeId() == TYPEID_PLAYER
)
3176 Player
const* player
= (Player
const*)this;
3177 if(player
->CanBlock() )
3179 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
3180 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
3181 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
3183 // is player but has no block ability or no not broken shield equipped
3188 if(((Creature
const*)this)->isTotem())
3193 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
3194 return block
> 0.0f
? block
: 0.0f
;
3199 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
3203 if(GetTypeId() == TYPEID_PLAYER
)
3208 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
3211 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
3214 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
3216 // Just for good manner
3225 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
3229 if(attackType
== RANGED_ATTACK
)
3230 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
3232 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
3234 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
3236 // reduce crit chance from Rating for players
3237 if (attackType
!= RANGED_ATTACK
)
3238 crit
-= pVictim
->GetMeleeCritChanceReduction();
3240 crit
-= pVictim
->GetRangedCritChanceReduction();
3242 // Apply crit chance from defence skill
3243 crit
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
3250 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
3253 if(GetTypeId() == TYPEID_PLAYER
)
3255 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true,true);
3257 // feral or unarmed skill only for base attack
3258 if(attType
!= BASE_ATTACK
&& !item
)
3262 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
3264 // weapon skill or (unarmed for base attack)
3265 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
3267 // in PvP use full skill instead current skill value
3268 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3269 ? ((Player
*)this)->GetMaxSkillValue(skill
)
3270 : ((Player
*)this)->GetSkillValue(skill
);
3271 // Modify value from ratings
3272 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
3275 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
3276 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
3277 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
3281 value
= GetUnitMeleeSkill(target
);
3285 void Unit::_UpdateSpells( uint32 time
)
3287 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
3288 _UpdateAutoRepeatSpell();
3290 // remove finished spells from current pointers
3291 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3293 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
3295 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
3296 m_currentSpells
[i
] = NULL
; // remove pointer
3301 // m_AurasUpdateIterator can be updated in inderect called code at aura remove to skip next planned to update but removed auras
3302 for (m_AurasUpdateIterator
= m_Auras
.begin(); m_AurasUpdateIterator
!= m_Auras
.end();)
3304 Aura
* i_aura
= m_AurasUpdateIterator
->second
;
3305 ++m_AurasUpdateIterator
; // need shift to next for allow update if need into aura update
3306 i_aura
->UpdateAura(time
);
3309 // remove expired auras
3310 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
3314 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
3323 if(!m_gameObj
.empty())
3325 GameObjectList::iterator ite1
, dnext1
;
3326 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
3329 //(*i)->Update( difftime );
3330 if( !(*ite1
)->isSpawned() )
3332 (*ite1
)->SetOwnerGUID(0);
3333 (*ite1
)->SetRespawnTime(0);
3335 dnext1
= m_gameObj
.erase(ite1
);
3343 void Unit::_UpdateAutoRepeatSpell()
3345 bool isAutoShot
= m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
== SPELL_ID_AUTOSHOT
;
3348 if (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving())
3350 // cancel wand shoot
3352 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3353 // auto shot just waits
3357 // check spell casts
3358 if (IsNonMeleeSpellCasted(false, false, true))
3360 // cancel wand shoot
3363 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3366 // auto shot is delayed by everythihng, except ranged(!) CURRENT_GENERIC_SPELL's -> recheck that
3367 else if (!(m_currentSpells
[CURRENT_GENERIC_SPELL
] && m_currentSpells
[CURRENT_GENERIC_SPELL
]->IsRangedSpell()))
3372 if (isAttackReady(RANGED_ATTACK
))
3374 // Check if able to cast
3375 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CheckCast(true) != SPELL_CAST_OK
)
3377 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3382 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
3383 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
3385 // all went good, reset attack
3386 resetAttackTimer(RANGED_ATTACK
);
3390 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
3392 ASSERT(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
3394 CurrentSpellTypes CSpellType
= pSpell
->GetCurrentContainer();
3396 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
3398 // break same type spell if it is not delayed
3399 InterruptSpell(CSpellType
,false);
3401 // special breakage effects:
3404 case CURRENT_GENERIC_SPELL
:
3406 // generic spells always break channeled not delayed spells
3407 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3409 // autorepeat breaking
3410 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3412 // break autorepeat if not Auto Shot
3413 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3414 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3418 case CURRENT_CHANNELED_SPELL
:
3420 // channel spells always break generic non-delayed and any channeled spells
3421 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3422 InterruptSpell(CURRENT_CHANNELED_SPELL
);
3424 // it also does break autorepeat if not Auto Shot
3425 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
3426 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3427 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3430 case CURRENT_AUTOREPEAT_SPELL
:
3432 // only Auto Shoot does not break anything
3433 if (pSpell
->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3435 // generic autorepeats break generic non-delayed and channeled non-delayed spells
3436 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3437 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3438 // special action: first cast delay
3439 if ( getAttackTimer(RANGED_ATTACK
) < 500 )
3440 setAttackTimer(RANGED_ATTACK
,500);
3446 // other spell types don't break anything now
3450 // current spell (if it is still here) may be safely deleted now
3451 if (m_currentSpells
[CSpellType
])
3452 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
3454 // set new current spell
3455 m_currentSpells
[CSpellType
] = pSpell
;
3456 pSpell
->SetReferencedFromCurrent(true);
3458 pSpell
->m_selfContainer
= &(m_currentSpells
[pSpell
->GetCurrentContainer()]);
3461 void Unit::InterruptSpell(CurrentSpellTypes spellType
, bool withDelayed
, bool sendAutoRepeatCancelToClient
)
3463 ASSERT(spellType
< CURRENT_MAX_SPELL
);
3465 if (m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
3467 // send autorepeat cancel message for autorepeat spells
3468 if (spellType
== CURRENT_AUTOREPEAT_SPELL
&& sendAutoRepeatCancelToClient
)
3470 if(GetTypeId() == TYPEID_PLAYER
)
3471 ((Player
*)this)->SendAutoRepeatCancel(this);
3474 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
3475 m_currentSpells
[spellType
]->cancel();
3477 // cancel can interrupt spell already (caster cancel ->target aura remove -> caster iterrupt)
3478 if (m_currentSpells
[spellType
])
3480 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
3481 m_currentSpells
[spellType
] = NULL
;
3486 void Unit::FinishSpell(CurrentSpellTypes spellType
, bool ok
/*= true*/)
3488 Spell
* spell
= m_currentSpells
[spellType
];
3492 if (spellType
== CURRENT_CHANNELED_SPELL
)
3493 spell
->SendChannelUpdate(0);
3499 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
3501 // We don't do loop here to explicitly show that melee spell is excluded.
3502 // Maybe later some special spells will be excluded too.
3504 // generic spells are casted when they are not finished and not delayed
3505 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
3506 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3507 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3510 // channeled spells may be delayed, but they are still considered casted
3511 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
3512 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
3515 // autorepeat spells may be finished or delayed, but they are still considered casted
3516 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3522 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
3524 // generic spells are interrupted if they are not finished or delayed
3525 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
3526 InterruptSpell(CURRENT_GENERIC_SPELL
,withDelayed
);
3528 // autorepeat spells are interrupted if they are not finished or delayed
3529 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
3530 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
,withDelayed
);
3532 // channeled spells are interrupted if they are not finished, even if they are delayed
3533 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
3534 InterruptSpell(CURRENT_CHANNELED_SPELL
,true);
3537 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
3539 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3540 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
3541 return m_currentSpells
[i
];
3545 void Unit::SetInFront(Unit
const* target
)
3547 SetOrientation(GetAngle(target
));
3550 void Unit::SetFacingTo(float ori
)
3552 // update orientation at server
3553 SetOrientation(ori
);
3557 BuildHeartBeatMsg(&data
);
3558 SendMessageToSet(&data
, false);
3561 // Consider move this to Creature:: since only creature appear to be able to use this
3562 void Unit::SetFacingToObject(WorldObject
* pObject
)
3564 if (GetTypeId() != TYPEID_UNIT
)
3567 // never face when already moving
3571 // TODO: figure out under what conditions creature will move towards object instead of facing it where it currently is.
3573 SetOrientation(GetAngle(pObject
));
3574 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_FACINGTARGET
, ((Creature
*)this)->GetSplineFlags(), 0, NULL
, pObject
->GetGUID());
3577 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
3580 return c
->canSwim();
3582 return c
->canWalk() || c
->canFly();
3585 bool Unit::IsInWater() const
3587 return GetBaseMap()->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
3590 bool Unit::IsUnderWater() const
3592 return GetBaseMap()->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3595 void Unit::DeMorph()
3597 SetDisplayId(GetNativeDisplayId());
3600 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3604 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3605 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3606 modifier
+= (*i
)->GetModifier()->m_amount
;
3611 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3613 float multiplier
= 1.0f
;
3615 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3616 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3617 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3622 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3626 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3627 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3628 if ((*i
)->GetModifier()->m_amount
> modifier
)
3629 modifier
= (*i
)->GetModifier()->m_amount
;
3634 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
3638 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3639 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3640 if ((*i
)->GetModifier()->m_amount
< modifier
)
3641 modifier
= (*i
)->GetModifier()->m_amount
;
3646 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3653 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3654 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3656 Modifier
* mod
= (*i
)->GetModifier();
3657 if (mod
->m_miscvalue
& misc_mask
)
3658 modifier
+= mod
->m_amount
;
3663 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3668 float multiplier
= 1.0f
;
3670 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3671 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3673 Modifier
* mod
= (*i
)->GetModifier();
3674 if (mod
->m_miscvalue
& misc_mask
)
3675 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3680 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3687 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3688 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3690 Modifier
* mod
= (*i
)->GetModifier();
3691 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
> modifier
)
3692 modifier
= mod
->m_amount
;
3698 int32
Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3705 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3706 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3708 Modifier
* mod
= (*i
)->GetModifier();
3709 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
< modifier
)
3710 modifier
= mod
->m_amount
;
3716 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3720 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3721 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3723 Modifier
* mod
= (*i
)->GetModifier();
3724 if (mod
->m_miscvalue
== misc_value
)
3725 modifier
+= mod
->m_amount
;
3730 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
3732 float multiplier
= 1.0f
;
3734 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3735 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3737 Modifier
* mod
= (*i
)->GetModifier();
3738 if (mod
->m_miscvalue
== misc_value
)
3739 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3744 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3748 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3749 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3751 Modifier
* mod
= (*i
)->GetModifier();
3752 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
3753 modifier
= mod
->m_amount
;
3759 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3763 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3764 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3766 Modifier
* mod
= (*i
)->GetModifier();
3767 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
< modifier
)
3768 modifier
= mod
->m_amount
;
3774 float Unit::GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype
, uint32 mask
) const
3779 float multiplier
= 1.0f
;
3781 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3782 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3784 Modifier
* mod
= (*i
)->GetModifier();
3785 if (mask
& (1 << (mod
->m_miscvalue
-1)))
3786 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3791 bool Unit::AddAura(Aura
*Aur
)
3793 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
3795 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
3796 if( !isAlive() && !IsDeathPersistentSpell(aurSpellInfo
) &&
3797 !IsDeathOnlySpell(aurSpellInfo
) &&
3798 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
3804 if(Aur
->GetTarget() != this)
3806 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
3807 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
3808 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
3813 // m_auraname can be modified to SPELL_AURA_NONE for area auras, this expected for this value
3814 AuraType aurName
= Aur
->GetModifier()->m_auraname
;
3816 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
3817 AuraMap::iterator i
= m_Auras
.find( spair
);
3819 // take out same spell
3820 if (i
!= m_Auras
.end())
3822 // passive and persistent auras can stack with themselves any number of times
3823 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
3825 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
3827 Aura
* aur2
= i2
->second
;
3828 if(aur2
->GetCasterGUID()==Aur
->GetCasterGUID())
3830 // Aura can stack on self -> Stack it;
3831 if(aurSpellInfo
->StackAmount
)
3833 // can be created with >1 stack by some spell mods
3834 aur2
->modStackAmount(Aur
->GetStackAmount());
3839 // Check for coexisting Weapon-proced Auras
3840 if (Aur
->isWeaponBuffCoexistableWith(aur2
))
3843 // Carry over removed Aura's remaining damage if Aura still has ticks remaining
3844 if (aur2
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_STACK_DOT_MODIFIER
&& aurName
== SPELL_AURA_PERIODIC_DAMAGE
&& aur2
->GetAuraDuration() > 0)
3846 int32 remainingTicks
= aur2
->GetAuraMaxTicks() - aur2
->GetAuraTicks();
3847 int32 remainingDamage
= aur2
->GetModifier()->m_amount
* remainingTicks
;
3849 Aur
->GetModifier()->m_amount
+= int32(remainingDamage
/ Aur
->GetAuraMaxTicks());
3851 // can be only single (this check done at _each_ aura add
3852 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3858 // m_auraname can be modified to SPELL_AURA_NONE for area auras, use original
3859 AuraType aurNameReal
= AuraType(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()]);
3864 case SPELL_AURA_DUMMY
: // allow stack
3865 case SPELL_AURA_PERIODIC_DAMAGE
:
3866 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
3867 case SPELL_AURA_PERIODIC_LEECH
:
3868 case SPELL_AURA_PERIODIC_HEAL
:
3869 case SPELL_AURA_OBS_MOD_HEALTH
:
3870 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3871 case SPELL_AURA_OBS_MOD_MANA
:
3872 case SPELL_AURA_POWER_BURN_MANA
:
3874 case SPELL_AURA_PERIODIC_ENERGIZE
: // all or self or clear non-stackable
3875 default: // not allow
3876 // can be only single (this check done at _each_ aura add
3877 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3888 // passive auras not stacable with other ranks
3889 if (!IsPassiveSpellStackableWithRanks(aurSpellInfo
))
3891 if (!RemoveNoStackAurasDueToAura(Aur
))
3894 return false; // couldn't remove conflicting aura with higher rank
3898 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
3899 if (Aur
->IsSingleTarget() && Aur
->GetTarget())
3901 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
3904 Unit
* caster
= Aur
->GetCaster();
3905 if(!caster
) // caster deleted and not required adding scAura
3908 bool restart
= false;
3909 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3910 for(AuraList::const_iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
3912 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
3913 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
3915 if ((*itr
)->IsInUse())
3917 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());
3920 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
3929 scAuras
.push_back(Aur
);
3935 // add aura, register in lists and arrays
3937 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
3938 if (aurName
< TOTAL_AURAS
)
3940 m_modAuras
[aurName
].push_back(Aur
);
3943 Aur
->ApplyModifier(true,true);
3944 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "Aura %u now is in use", aurName
);
3946 // if aura deleted before boosts apply ignore
3947 // this can be possible it it removed indirectly by triggered spell effect at ApplyModifier
3948 if (Aur
->IsDeleted())
3951 if(IsSpellLastAuraEffect(aurSpellInfo
,Aur
->GetEffIndex()))
3952 Aur
->HandleSpellSpecificBoosts(true);
3957 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
3959 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3962 AuraMap::const_iterator i
,next
;
3963 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3967 uint32 i_spellId
= (*i
).second
->GetId();
3968 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
3970 if(sSpellMgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
3972 RemoveAurasDueToSpell(i_spellId
);
3974 if( m_Auras
.empty() )
3977 next
= m_Auras
.begin();
3983 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
3988 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
3992 uint32 spellId
= Aur
->GetId();
3993 SpellEffectIndex effIndex
= Aur
->GetEffIndex();
3995 // passive spell special case (only non stackable with ranks)
3996 if(IsPassiveSpell(spellId
))
3998 if(IsPassiveSpellStackableWithRanks(spellProto
))
4002 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
4004 AuraMap::iterator i
,next
;
4005 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
4009 if (!(*i
).second
) continue;
4011 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
4016 uint32 i_spellId
= i_spellProto
->Id
;
4018 // early checks that spellId is passive non stackable spell
4019 if(IsPassiveSpell(i_spellId
))
4021 // passive non-stackable spells not stackable only for same caster
4022 if(Aur
->GetCasterGUID()!=i
->second
->GetCasterGUID())
4025 // passive non-stackable spells not stackable only with another rank of same spell
4026 if (!sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4030 SpellEffectIndex i_effIndex
= (*i
).second
->GetEffIndex();
4032 if(i_spellId
== spellId
) continue;
4034 bool is_triggered_by_spell
= false;
4035 // prevent triggering aura of removing aura that triggered it
4036 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4037 if (i_spellProto
->EffectTriggerSpell
[j
] == spellId
)
4038 is_triggered_by_spell
= true;
4040 // prevent triggered aura of removing aura that triggering it (triggered effect early some aura of parent spell
4041 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4042 if (spellProto
->EffectTriggerSpell
[j
] == i_spellId
)
4043 is_triggered_by_spell
= true;
4045 if (is_triggered_by_spell
)
4048 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
4050 // single allowed spell specific from same caster or from any caster at target
4051 bool is_spellSpecPerTargetPerCaster
= IsSingleFromSpellSpecificPerTargetPerCaster(spellId_spec
,i_spellId_spec
);
4052 bool is_spellSpecPerTarget
= IsSingleFromSpellSpecificPerTarget(spellId_spec
,i_spellId_spec
);
4053 if( is_spellSpecPerTarget
|| is_spellSpecPerTargetPerCaster
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
4055 // cannot remove higher rank
4056 if (sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4057 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4060 // Its a parent aura (create this aura in ApplyModifier)
4061 if ((*i
).second
->IsInUse())
4063 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());
4066 RemoveAurasDueToSpell(i_spellId
);
4068 if( m_Auras
.empty() )
4071 next
= m_Auras
.begin();
4076 // spell with spell specific that allow single ranks for spell from diff caster
4077 // same caster case processed or early or later
4078 bool is_spellPerTarget
= IsSingleFromSpellSpecificSpellRanksPerTarget(spellId_spec
,i_spellId_spec
);
4079 if ( is_spellPerTarget
&& Aur
->GetCasterGUID() != (*i
).second
->GetCasterGUID() && sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4081 // cannot remove higher rank
4082 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4085 // Its a parent aura (create this aura in ApplyModifier)
4086 if ((*i
).second
->IsInUse())
4088 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());
4091 RemoveAurasDueToSpell(i_spellId
);
4093 if( m_Auras
.empty() )
4096 next
= m_Auras
.begin();
4101 // non single (per caster) per target spell specific (possible single spell per target at caster)
4102 if( !is_spellSpecPerTargetPerCaster
&& !is_spellSpecPerTarget
&& sSpellMgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
4104 // Its a parent aura (create this aura in ApplyModifier)
4105 if ((*i
).second
->IsInUse())
4107 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());
4110 RemoveAurasDueToSpell(i_spellId
);
4112 if( m_Auras
.empty() )
4115 next
= m_Auras
.begin();
4120 // Potions stack aura by aura (elixirs/flask already checked)
4121 if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
4123 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
4125 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4126 return false; // cannot remove higher rank
4128 // Its a parent aura (create this aura in ApplyModifier)
4129 if ((*i
).second
->IsInUse())
4131 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());
4142 void Unit::RemoveAura(uint32 spellId
, SpellEffectIndex effindex
, Aura
* except
)
4144 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4145 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4147 if(iter
->second
!=except
)
4150 iter
= m_Auras
.lower_bound(spair
);
4157 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
)
4159 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4161 Aura
*aur
= iter
->second
;
4162 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4169 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, SpellEffectIndex effindex
, uint64 casterGUID
)
4171 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4172 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4174 Aura
*aur
= iter
->second
;
4175 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4178 iter
= m_Auras
.lower_bound(spair
);
4185 void Unit::RemoveSingleAuraDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
4187 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(spellId
);
4189 // Custom dispel cases
4190 // Unstable Affliction
4191 if(spellEntry
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x010000000000)))
4193 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
,SPELLFAMILY_WARLOCK
,UI64LIT(0x010000000000),0x00000000,casterGUID
))
4195 // use clean value for initial damage
4196 int32 damage
= dotAura
->GetSpellProto()->CalculateSimpleValue(EFFECT_INDEX_0
);
4199 // Remove spell auras from stack
4200 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4202 // backfire damage and silence
4203 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,casterGUID
);
4208 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x10000000)))
4210 Unit
* caster
= NULL
;
4211 uint32 triggeredSpell
= 0;
4213 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x10000000), 0x00000000, casterGUID
))
4214 caster
= dotAura
->GetCaster();
4216 if (caster
&& !caster
->isDead())
4218 Unit::AuraList
const& auras
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
4219 for (Unit::AuraList::const_iterator i
= auras
.begin(); i
!= auras
.end(); ++i
)
4221 switch((*i
)->GetId())
4223 case 51480: triggeredSpell
=64694; break;// Lava Flows, Rank 1
4224 case 51481: triggeredSpell
=65263; break;// Lava Flows, Rank 2
4225 case 51482: triggeredSpell
=65264; break;// Lava Flows, Rank 3
4232 // Remove spell auras from stack
4233 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4237 caster
->CastSpell(caster
, triggeredSpell
, true);
4240 // Vampiric touch (first dummy aura)
4241 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_PRIEST
&& spellEntry
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
4243 if (Aura
*dot
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000040000000000), 0x00000000, casterGUID
))
4245 if(Unit
* caster
= dot
->GetCaster())
4247 // use clean value for initial damage
4248 int32 bp0
= dot
->GetSpellProto()->CalculateSimpleValue(EFFECT_INDEX_1
);
4251 // Remove spell auras from stack
4252 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4254 CastCustomSpell(this, 64085, &bp0
, NULL
, NULL
, true, NULL
, NULL
, casterGUID
);
4260 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4263 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
4265 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4267 Aura
*aur
= iter
->second
;
4268 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4270 int32 basePoints
= aur
->GetBasePoints();
4271 // construct the new aura for the attacker - will never return NULL, it's just a wrapper for
4272 // some different constructors
4273 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
, this);
4275 // set its duration and maximum duration
4276 // max duration 2 minutes (in msecs)
4277 int32 dur
= aur
->GetAuraDuration();
4278 int32 max_dur
= 2*MINUTE
*IN_MILLISECONDS
;
4279 int32 new_max_dur
= max_dur
> dur
? dur
: max_dur
;
4280 new_aur
->SetAuraMaxDuration( new_max_dur
);
4281 new_aur
->SetAuraDuration( new_max_dur
);
4283 // set periodic to do at least one tick (for case when original aura has been at last tick preparing)
4284 int32 periodic
= aur
->GetModifier()->periodictime
;
4285 new_aur
->GetModifier()->periodictime
= periodic
< new_max_dur
? periodic
: new_max_dur
;
4287 // Unregister _before_ adding to stealer
4288 aur
->UnregisterSingleCastAura();
4290 // strange but intended behaviour: Stolen single target auras won't be treated as single targeted
4291 new_aur
->SetIsSingleTarget(false);
4293 // add the new aura to stealer
4294 stealer
->AddAura(new_aur
);
4296 // Remove aura as dispel
4297 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
4304 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
4306 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4308 if (iter
->second
->GetId() == spellId
)
4309 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
4315 void Unit::RemoveAurasWithDispelType( DispelType type
)
4317 // Create dispel mask by dispel type
4318 uint32 dispelMask
= GetDispellMask(type
);
4319 // Dispel all existing auras vs current dispel type
4320 AuraMap
& auras
= GetAuras();
4321 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
4323 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
4324 if( (1<<spell
->Dispel
) & dispelMask
)
4327 RemoveAurasDueToSpell(spell
->Id
);
4328 itr
= auras
.begin();
4335 void Unit::RemoveSingleAuraFromStack(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4337 if (i
->second
->modStackAmount(-1))
4342 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, SpellEffectIndex effindex
, AuraRemoveMode mode
)
4344 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4345 if(iter
!= m_Auras
.end())
4346 RemoveSingleAuraFromStack(iter
,mode
);
4349 void Unit::RemoveSingleSpellAurasFromStack(uint32 spellId
, AuraRemoveMode mode
)
4351 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4352 RemoveSingleAuraFromStack(spellId
, SpellEffectIndex(i
), mode
);
4355 void Unit::RemoveSingleSpellAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
, AuraRemoveMode mode
)
4357 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4358 RemoveSingleAuraByCasterSpell(spellId
, SpellEffectIndex(i
), casterGUID
, mode
);
4361 void Unit::RemoveSingleAuraByCasterSpell(uint32 spellId
, SpellEffectIndex effindex
, uint64 casterGUID
, AuraRemoveMode mode
)
4363 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4364 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
); ++iter
)
4366 Aura
*aur
= iter
->second
;
4367 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4369 RemoveSingleAuraFromStack(iter
,mode
);
4376 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
)
4378 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4379 RemoveAura(spellId
,SpellEffectIndex(i
),except
);
4382 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
4384 for (int k
=0; k
< MAX_EFFECT_INDEX
; ++k
)
4386 spellEffectPair spair
= spellEffectPair(spellId
, SpellEffectIndex(k
));
4387 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4389 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
4392 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
4400 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
4402 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4404 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
4411 void Unit::RemoveNotOwnSingleTargetAuras(uint32 newPhase
)
4413 // single target auras from other casters
4414 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4416 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
4422 Unit
* caster
= iter
->second
->GetCaster();
4423 if(!caster
|| !caster
->InSamePhase(newPhase
))
4433 // single target auras at other targets
4434 AuraList
& scAuras
= GetSingleCastAuras();
4435 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
4438 if (aura
->GetTarget() != this && !aura
->GetTarget()->InSamePhase(newPhase
))
4440 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
4441 aura
->GetTarget()->RemoveAura(aura
);
4442 iter
= scAuras
.begin();
4450 void Unit::RemoveAura(Aura
* aura
, AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4452 AuraMap::iterator i
= m_Auras
.lower_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4453 AuraMap::iterator upperBound
= m_Auras
.upper_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4454 for (; i
!= upperBound
; ++i
)
4456 if (i
->second
== aura
)
4462 DEBUG_LOG("Trying to remove aura id %u effect %u by pointer but aura not found on target", aura
->GetId(), aura
->GetEffIndex());
4465 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4467 Aura
* Aur
= i
->second
;
4468 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
4470 Aur
->UnregisterSingleCastAura();
4472 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
4473 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
4475 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
4479 Aur
->SetRemoveMode(mode
);
4481 // if unit currently update aura list then make safe update iterator shift to next
4482 if (m_AurasUpdateIterator
== i
)
4483 ++m_AurasUpdateIterator
;
4485 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
4486 // remove aura from list before to prevent deleting it before
4489 // now aura removed from from list and can't be deleted by indirect call but can be referenced from callers
4491 // Statue unsummoned at aura remove
4492 Totem
* statue
= NULL
;
4493 if(IsChanneledSpell(AurSpellInfo
))
4494 if(Unit
* caster
= Aur
->GetCaster())
4495 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
4496 statue
= ((Totem
*)caster
);
4498 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
4500 // some auras also need to apply modifier (on caster) on remove
4501 if (mode
!= AURA_REMOVE_BY_DELETE
|| Aur
->GetModifier()->m_auraname
== SPELL_AURA_MOD_POSSESS
)
4502 Aur
->ApplyModifier(false,true);
4504 if (Aur
->_RemoveAura())
4506 // last aura in stack removed
4507 if (mode
!= AURA_REMOVE_BY_DELETE
&& IsSpellLastAuraEffect(Aur
->GetSpellProto(),Aur
->GetEffIndex()))
4508 Aur
->HandleSpellSpecificBoosts(false);
4511 // If aura in use (removed from code that plan access to it data after return)
4512 // store it in aura list with delayed deletion
4514 m_deletedAuras
.push_back(Aur
);
4521 // only way correctly remove all auras from list
4522 if( m_Auras
.empty() )
4525 i
= m_Auras
.begin();
4529 void Unit::RemoveAllAuras(AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4531 while (!m_Auras
.empty())
4533 AuraMap::iterator iter
= m_Auras
.begin();
4534 RemoveAura(iter
,mode
);
4538 void Unit::RemoveArenaAuras(bool onleave
)
4540 // in join, remove positive buffs, on end, remove negative
4541 // used to remove positive visible auras in arenas
4542 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4544 if (!(iter
->second
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_UNK21
) &&
4545 // don't remove stances, shadowform, pally/hunter auras
4546 !iter
->second
->IsPassive() && // don't remove passive auras
4547 (!(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
) ||
4548 !(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNK8
)) &&
4549 // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable)
4550 (iter
->second
->IsPositive() != onleave
)) // remove positive buffs on enter, negative buffs on leave
4557 void Unit::RemoveAllAurasOnDeath()
4559 // used just after dieing to remove all visible auras
4560 // and disable the mods for the passive ones
4561 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4563 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
4564 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
4570 void Unit::DelayAura(uint32 spellId
, SpellEffectIndex effindex
, int32 delaytime
)
4572 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4573 if (iter
!= m_Auras
.end())
4575 if (iter
->second
->GetAuraDuration() < delaytime
)
4576 iter
->second
->SetAuraDuration(0);
4578 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
4579 iter
->second
->SendAuraUpdate(false);
4580 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "Aura %u partially interrupted on unit %u, new duration: %u ms",iter
->second
->GetModifier()->m_auraname
, GetGUIDLow(), iter
->second
->GetAuraDuration());
4584 void Unit::_RemoveAllAuraMods()
4586 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4588 (*i
).second
->ApplyModifier(false);
4592 void Unit::_ApplyAllAuraMods()
4594 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4596 (*i
).second
->ApplyModifier(true);
4600 Aura
* Unit::GetAura(uint32 spellId
, SpellEffectIndex effindex
)
4602 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4603 if (iter
!= m_Auras
.end())
4604 return iter
->second
;
4608 Aura
* Unit::GetAura(AuraType type
, uint32 family
, uint64 familyFlag
, uint32 familyFlag2
, uint64 casterGUID
)
4610 AuraList
const& auras
= GetAurasByType(type
);
4611 for(AuraList::const_iterator i
= auras
.begin();i
!= auras
.end(); ++i
)
4613 SpellEntry
const *spell
= (*i
)->GetSpellProto();
4614 if (spell
->SpellFamilyName
== family
&& (spell
->SpellFamilyFlags
& familyFlag
|| spell
->SpellFamilyFlags2
& familyFlag2
))
4616 if (casterGUID
&& (*i
)->GetCasterGUID()!=casterGUID
)
4624 bool Unit::HasAura(uint32 spellId
) const
4626 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4628 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, SpellEffectIndex(i
)));
4629 if (iter
!= m_Auras
.end())
4635 void Unit::AddDynObject(DynamicObject
* dynObj
)
4637 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
4640 void Unit::RemoveDynObject(uint32 spellid
)
4642 if(m_dynObjGUIDs
.empty())
4644 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4646 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4649 i
= m_dynObjGUIDs
.erase(i
);
4651 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
4654 i
= m_dynObjGUIDs
.erase(i
);
4661 void Unit::RemoveAllDynObjects()
4663 while(!m_dynObjGUIDs
.empty())
4665 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*m_dynObjGUIDs
.begin());
4668 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
4672 DynamicObject
* Unit::GetDynObject(uint32 spellId
, SpellEffectIndex effIndex
)
4674 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4676 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4679 i
= m_dynObjGUIDs
.erase(i
);
4683 if (dynObj
->GetSpellId() == spellId
&& dynObj
->GetEffIndex() == effIndex
)
4690 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
4692 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4694 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4697 i
= m_dynObjGUIDs
.erase(i
);
4701 if (dynObj
->GetSpellId() == spellId
)
4708 GameObject
* Unit::GetGameObject(uint32 spellId
) const
4710 for (GameObjectList::const_iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); ++i
)
4711 if ((*i
)->GetSpellId() == spellId
)
4717 void Unit::AddGameObject(GameObject
* gameObj
)
4719 ASSERT(gameObj
&& gameObj
->GetOwnerGUID()==0);
4720 m_gameObj
.push_back(gameObj
);
4721 gameObj
->SetOwnerGUID(GetGUID());
4723 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
4725 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
4726 // Need disable spell use for owner
4727 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4728 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4729 ((Player
*)this)->AddSpellAndCategoryCooldowns(createBySpell
,0,NULL
,true);
4733 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
4735 ASSERT(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
4737 gameObj
->SetOwnerGUID(0);
4739 // GO created by some spell
4740 if (uint32 spellid
= gameObj
->GetSpellId())
4742 RemoveAurasDueToSpell(spellid
);
4744 if (GetTypeId()==TYPEID_PLAYER
)
4746 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(spellid
);
4747 // Need activate spell use for owner
4748 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4749 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4750 ((Player
*)this)->SendCooldownEvent(createBySpell
);
4754 m_gameObj
.remove(gameObj
);
4758 gameObj
->SetRespawnTime(0);
4763 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
4765 if(m_gameObj
.empty())
4767 GameObjectList::iterator i
, next
;
4768 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
4771 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
4773 (*i
)->SetOwnerGUID(0);
4776 (*i
)->SetRespawnTime(0);
4780 next
= m_gameObj
.erase(i
);
4787 void Unit::RemoveAllGameObjects()
4789 // remove references to unit
4790 for(GameObjectList::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4792 (*i
)->SetOwnerGUID(0);
4793 (*i
)->SetRespawnTime(0);
4795 i
= m_gameObj
.erase(i
);
4799 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
4801 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+4+1+4+4+1+1+4+4+1)); // we guess size
4802 data
<< log
->target
->GetPackGUID();
4803 data
<< log
->attacker
->GetPackGUID();
4804 data
<< uint32(log
->SpellID
);
4805 data
<< uint32(log
->damage
); // damage amount
4806 data
<< uint32(log
->overkill
); // overkill
4807 data
<< uint8 (log
->schoolMask
); // damage school
4808 data
<< uint32(log
->absorb
); // AbsorbedDamage
4809 data
<< uint32(log
->resist
); // resist
4810 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
4811 data
<< uint8 (log
->unused
); // unused
4812 data
<< uint32(log
->blocked
); // blocked
4813 data
<< uint32(log
->HitInfo
);
4814 data
<< uint8 (0); // flag to use extend data
4815 SendMessageToSet( &data
, true );
4818 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
, uint32 SpellID
, uint32 Damage
, SpellSchoolMask damageSchoolMask
, uint32 AbsorbedDamage
, uint32 Resist
, bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
4820 SpellNonMeleeDamage
log(this, target
, SpellID
, damageSchoolMask
);
4821 log
.damage
= Damage
- AbsorbedDamage
- Resist
- Blocked
;
4822 log
.absorb
= AbsorbedDamage
;
4823 log
.resist
= Resist
;
4824 log
.physicalLog
= PhysicalDamage
;
4825 log
.blocked
= Blocked
;
4826 log
.HitInfo
= SPELL_HIT_TYPE_UNK1
| SPELL_HIT_TYPE_UNK3
| SPELL_HIT_TYPE_UNK6
;
4828 log
.HitInfo
|= SPELL_HIT_TYPE_CRIT
;
4829 SendSpellNonMeleeDamageLog(&log
);
4832 void Unit::SendPeriodicAuraLog(SpellPeriodicAuraLogInfo
*pInfo
)
4834 Aura
*aura
= pInfo
->aura
;
4835 Modifier
*mod
= aura
->GetModifier();
4837 WorldPacket
data(SMSG_PERIODICAURALOG
, 30);
4838 data
<< aura
->GetTarget()->GetPackGUID();
4839 data
.appendPackGUID(aura
->GetCasterGUID());
4840 data
<< uint32(aura
->GetId()); // spellId
4841 data
<< uint32(1); // count
4842 data
<< uint32(mod
->m_auraname
); // auraId
4843 switch(mod
->m_auraname
)
4845 case SPELL_AURA_PERIODIC_DAMAGE
:
4846 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
4847 data
<< uint32(pInfo
->damage
); // damage
4848 data
<< uint32(pInfo
->overDamage
); // overkill?
4849 data
<< uint32(GetSpellSchoolMask(aura
->GetSpellProto()));
4850 data
<< uint32(pInfo
->absorb
); // absorb
4851 data
<< uint32(pInfo
->resist
); // resist
4852 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4854 case SPELL_AURA_PERIODIC_HEAL
:
4855 case SPELL_AURA_OBS_MOD_HEALTH
:
4856 data
<< uint32(pInfo
->damage
); // damage
4857 data
<< uint32(pInfo
->overDamage
); // overheal?
4858 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4860 case SPELL_AURA_OBS_MOD_MANA
:
4861 case SPELL_AURA_PERIODIC_ENERGIZE
:
4862 data
<< uint32(mod
->m_miscvalue
); // power type
4863 data
<< uint32(pInfo
->damage
); // damage
4865 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4866 data
<< uint32(mod
->m_miscvalue
); // power type
4867 data
<< uint32(pInfo
->damage
); // amount
4868 data
<< float(pInfo
->multiplier
); // gain multiplier
4871 sLog
.outError("Unit::SendPeriodicAuraLog: unknown aura %u", uint32(mod
->m_auraname
));
4875 aura
->GetTarget()->SendMessageToSet(&data
, true);
4878 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
4880 // Not much to do if no flags are set.
4882 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
4883 // Now go on with a victim's events'n'auras
4884 // Not much to do if no flags are set or there is no victim
4885 if(pVictim
&& pVictim
->isAlive() && procVictim
)
4886 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4889 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4891 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4892 data
<< uint32(spellID
);
4893 data
<< uint64(GetGUID());
4894 data
<< uint8(0); // can be 0 or 1
4895 data
<< uint32(1); // target count
4896 // for(i = 0; i < target count; ++i)
4897 data
<< uint64(target
->GetGUID()); // target GUID
4898 data
<< uint8(missInfo
);
4900 SendMessageToSet(&data
, true);
4903 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4905 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4908 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, 16 + 45); // we guess size
4909 data
<< uint32(damageInfo
->HitInfo
);
4910 data
<< damageInfo
->attacker
->GetPackGUID();
4911 data
<< damageInfo
->target
->GetPackGUID();
4912 data
<< uint32(damageInfo
->damage
); // Full damage
4913 data
<< uint32(0); // overkill value
4914 data
<< uint8(count
); // Sub damage count
4916 for(uint32 i
= 0; i
< count
; ++i
)
4918 data
<< uint32(damageInfo
->damageSchoolMask
); // School of sub damage
4919 data
<< float(damageInfo
->damage
); // sub damage
4920 data
<< uint32(damageInfo
->damage
); // Sub Damage
4923 if(damageInfo
->HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4925 for(uint32 i
= 0; i
< count
; ++i
)
4926 data
<< uint32(damageInfo
->absorb
); // Absorb
4929 if(damageInfo
->HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4931 for(uint32 i
= 0; i
< count
; ++i
)
4932 data
<< uint32(damageInfo
->resist
); // Resist
4935 data
<< uint8(damageInfo
->TargetState
);
4939 if(damageInfo
->HitInfo
& HITINFO_BLOCK
)
4940 data
<< uint32(damageInfo
->blocked_amount
);
4942 if(damageInfo
->HitInfo
& HITINFO_UNK3
)
4945 if(damageInfo
->HitInfo
& HITINFO_UNK1
)
4956 for(uint8 i
= 0; i
< 5; ++i
)
4964 SendMessageToSet( &data
, true );
4967 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8
/*SwingType*/, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4969 CalcDamageInfo dmgInfo
;
4970 dmgInfo
.HitInfo
= HitInfo
;
4971 dmgInfo
.attacker
= this;
4972 dmgInfo
.target
= target
;
4973 dmgInfo
.damage
= Damage
- AbsorbDamage
- Resist
- BlockedAmount
;
4974 dmgInfo
.damageSchoolMask
= damageSchoolMask
;
4975 dmgInfo
.absorb
= AbsorbDamage
;
4976 dmgInfo
.resist
= Resist
;
4977 dmgInfo
.TargetState
= TargetState
;
4978 dmgInfo
.blocked_amount
= BlockedAmount
;
4979 SendAttackStateUpdate(&dmgInfo
);
4982 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4984 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
4986 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4987 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4989 uint32 triggered_spell_id
= 0;
4990 Unit
* target
= pVictim
;
4991 int32 basepoints0
= 0;
4993 switch(hasteSpell
->SpellFamilyName
)
4995 case SPELLFAMILY_ROGUE
:
4997 switch(hasteSpell
->Id
)
5003 target
= SelectRandomUnfriendlyTarget(pVictim
);
5006 basepoints0
= damage
;
5007 triggered_spell_id
= 22482;
5015 // processed charge only counting case
5016 if(!triggered_spell_id
)
5019 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5023 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
5028 if(!target
|| target
!=this && !target
->isAlive())
5031 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5035 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5037 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5039 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5040 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5045 bool Unit::HandleSpellCritChanceAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
5047 SpellEntry
const *triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
5049 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5050 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5052 uint32 triggered_spell_id
= 0;
5053 Unit
* target
= pVictim
;
5054 int32 basepoints0
= 0;
5056 switch(triggeredByAuraSpell
->SpellFamilyName
)
5058 case SPELLFAMILY_MAGE
:
5060 switch(triggeredByAuraSpell
->Id
)
5065 Unit
* caster
= triggeredByAura
->GetCaster();
5069 triggered_spell_id
= 54648;
5077 // processed charge only counting case
5078 if(!triggered_spell_id
)
5081 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5085 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",triggeredByAuraSpell
->Id
,triggered_spell_id
);
5090 if(!target
|| target
!=this && !target
->isAlive())
5093 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5097 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5099 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5101 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5102 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5107 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
5109 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
5110 SpellEffectIndex effIndex
= triggeredByAura
->GetEffIndex();
5111 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
5113 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5114 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5116 uint32 triggered_spell_id
= 0;
5117 Unit
* target
= pVictim
;
5118 int32 basepoints
[MAX_EFFECT_INDEX
] = {0, 0, 0};
5120 switch(dummySpell
->SpellFamilyName
)
5122 case SPELLFAMILY_GENERIC
:
5124 switch (dummySpell
->Id
)
5130 // return damage % to attacker but < 50% own total health
5131 basepoints
[0] = triggerAmount
*int32(damage
)/100;
5132 if (basepoints
[0] > (int32
)GetMaxHealth()/2)
5133 basepoints
[0] = (int32
)GetMaxHealth()/2;
5135 triggered_spell_id
= 25997;
5138 // Sweeping Strikes (NPC spells may be)
5142 // prevent chain of triggered spell from same triggered spell
5143 if (procSpell
&& procSpell
->Id
== 26654)
5146 target
= SelectRandomUnfriendlyTarget(pVictim
);
5150 triggered_spell_id
= 26654;
5153 // Twisted Reflection (boss spell)
5155 triggered_spell_id
= 21064;
5160 if (!procSpell
|| procSpell
->Id
== 24659)
5162 // Need remove one 24659 aura
5163 RemoveSingleSpellAurasFromStack(24659);
5166 // Restless Strength
5169 // Need remove one 24662 aura
5170 RemoveSingleSpellAurasFromStack(24662);
5173 // Adaptive Warding (Frostfire Regalia set)
5181 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
5182 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
5184 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
5186 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& UI64LIT(0x10000000)))
5196 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5198 case SPELL_SCHOOL_NORMAL
:
5199 case SPELL_SCHOOL_HOLY
:
5200 return false; // ignored
5201 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
5202 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
5203 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
5204 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
5205 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
5213 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
5219 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5221 case SPELL_SCHOOL_NORMAL
:
5222 return false; // ignore
5223 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
5224 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
5225 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
5226 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
5227 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
5228 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
5236 // Mana Leech (Passive) (Priest Pet Aura)
5240 target
= GetOwner();
5244 triggered_spell_id
= 34650;
5252 if (!roll_chance_i(triggerAmount
))
5255 // Remove any stun effect on target
5256 AuraMap
& Auras
= pVictim
->GetAuras();
5257 for(AuraMap::const_iterator iter
= Auras
.begin(); iter
!= Auras
.end();)
5259 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
5260 if( spell
->Mechanic
== MECHANIC_STUN
||
5261 spell
->EffectMechanic
[iter
->second
->GetEffIndex()] == MECHANIC_STUN
)
5263 pVictim
->RemoveAurasDueToSpell(spell
->Id
);
5264 iter
= Auras
.begin();
5274 // Cast finish spell at last charge
5275 if (triggeredByAura
->GetAuraCharges() > 1)
5279 triggered_spell_id
= 33494;
5282 // Vampiric Aura (boss spell)
5285 basepoints
[0] = 3 * damage
; // 300%
5286 if (basepoints
[0] < 0)
5289 triggered_spell_id
= 31285;
5293 // Aura of Madness (Darkmoon Card: Madness trinket)
5294 //=====================================================
5295 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
5296 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
5297 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
5298 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5299 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
5300 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
5301 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
5302 // 41011 Martyr Complex: +35 stamina (All classes)
5303 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5304 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5307 if(GetTypeId() != TYPEID_PLAYER
)
5310 // Select class defined buff
5313 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5314 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5316 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
5317 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5320 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
5321 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
5323 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
5324 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5327 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
5328 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
5329 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
5330 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
5332 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
5333 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5336 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
5338 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
5339 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5347 if (roll_chance_i(10))
5348 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
5351 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
5352 // cast 45479 Light's Wrath if Exalted by Aldor
5353 // cast 45429 Arcane Bolt if Exalted by Scryers
5356 if(GetTypeId() != TYPEID_PLAYER
)
5359 // Get Aldor reputation rank
5360 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5363 triggered_spell_id
= 45479;
5366 // Get Scryers reputation rank
5367 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5369 // triggered at positive/self casts also, current attack target used then
5370 if(IsFriendlyTo(target
))
5372 target
= getVictim();
5375 uint64 selected_guid
= ((Player
*)this)->GetSelection();
5376 target
= ObjectAccessor::GetUnit(*this,selected_guid
);
5380 if(IsFriendlyTo(target
))
5384 triggered_spell_id
= 45429;
5389 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
5390 // cast 45480 Light's Strength if Exalted by Aldor
5391 // cast 45428 Arcane Strike if Exalted by Scryers
5394 if(GetTypeId() != TYPEID_PLAYER
)
5397 // Get Aldor reputation rank
5398 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5401 triggered_spell_id
= 45480;
5404 // Get Scryers reputation rank
5405 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5407 triggered_spell_id
= 45428;
5412 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
5413 // cast 45431 Arcane Insight if Exalted by Aldor
5414 // cast 45432 Light's Ward if Exalted by Scryers
5417 if(GetTypeId() != TYPEID_PLAYER
)
5420 // Get Aldor reputation rank
5421 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5424 triggered_spell_id
= 45432;
5427 // Get Scryers reputation rank
5428 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5431 triggered_spell_id
= 45431;
5436 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
5437 // cast 45478 Light's Salvation if Exalted by Aldor
5438 // cast 45430 Arcane Surge if Exalted by Scryers
5441 if(GetTypeId() != TYPEID_PLAYER
)
5444 // Get Aldor reputation rank
5445 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5448 triggered_spell_id
= 45478;
5451 // Get Scryers reputation rank
5452 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5454 triggered_spell_id
= 45430;
5460 // Sunwell Exalted Caster Neck (??? neck)
5461 // cast ??? Light's Wrath if Exalted by Aldor
5462 // cast ??? Arcane Bolt if Exalted by Scryers*/
5464 return false; // old unused version
5468 triggered_spell_id
= 48503;
5469 basepoints
[0] = triggerAmount
;
5473 // Vampiric Touch (generic, used by some boss)
5477 triggered_spell_id
= 52724;
5478 basepoints
[0] = damage
/ 2;
5482 // Shadowfiend Death (Gain mana if pet dies with Glyph of Shadowfiend)
5485 Unit
*owner
= GetOwner();
5486 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
5489 // Glyph of Shadowfiend (need cast as self cast for owner, no hidden cooldown)
5490 owner
->CastSpell(owner
,58227,true,castItem
,triggeredByAura
);
5493 // Glyph of Life Tap
5495 triggered_spell_id
= 63321;
5497 // Item - Shadowmourne Legendary
5500 if (!roll_chance_i(triggerAmount
))
5503 Aura
*aur
= GetAura(71905, EFFECT_INDEX_0
);
5504 if (aur
&& uint32(aur
->GetStackAmount() + 1) >= aur
->GetSpellProto()->StackAmount
)
5506 RemoveAurasDueToSpell(71905);
5507 CastSpell(this, 71904, true); // Chaos Bane
5511 triggered_spell_id
= 71905;
5518 case SPELLFAMILY_MAGE
:
5521 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
5523 if (getPowerType() != POWER_MANA
)
5527 basepoints
[0] = (triggerAmount
* GetMaxPower(POWER_MANA
) / 100);
5529 triggered_spell_id
= 29442;
5532 // Master of Elements
5533 if (dummySpell
->SpellIconID
== 1920)
5539 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5540 basepoints
[0] = cost
* triggerAmount
/100;
5541 if (basepoints
[0] <=0)
5545 triggered_spell_id
= 29077;
5550 if (dummySpell
->SpellIconID
== 2120)
5556 switch (dummySpell
->Id
)
5558 case 31571: triggered_spell_id
= 57529; break;
5559 case 31572: triggered_spell_id
= 57531; break;
5561 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u",dummySpell
->Id
);
5568 if (dummySpell
->SpellIconID
== 2999)
5570 if (effIndex
!= EFFECT_INDEX_0
)
5572 Aura
*counter
= GetAura(triggeredByAura
->GetId(), EFFECT_INDEX_1
);
5576 // Count spell criticals in a row in second aura
5577 Modifier
*mod
= counter
->GetModifier();
5578 if (procEx
& PROC_EX_CRITICAL_HIT
)
5581 if (mod
->m_amount
< 100) // not enough
5583 // Crititcal counted -> roll chance
5584 if (roll_chance_i(triggerAmount
))
5585 CastSpell(this, 48108, true, castItem
, triggeredByAura
);
5591 if (dummySpell
->SpellIconID
== 2998)
5596 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5597 basepoints
[0] = cost
* triggerAmount
/100;
5598 if (basepoints
[0] <=0)
5600 triggered_spell_id
= 44450;
5604 // Incanter's Regalia set (add trigger chance to Mana Shield)
5605 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5607 if (GetTypeId() != TYPEID_PLAYER
)
5611 triggered_spell_id
= 37436;
5614 switch(dummySpell
->Id
)
5623 switch (dummySpell
->Id
)
5625 case 11119: basepoints
[0] = int32(0.04f
*damage
); break;
5626 case 11120: basepoints
[0] = int32(0.08f
*damage
); break;
5627 case 12846: basepoints
[0] = int32(0.12f
*damage
); break;
5628 case 12847: basepoints
[0] = int32(0.16f
*damage
); break;
5629 case 12848: basepoints
[0] = int32(0.20f
*damage
); break;
5631 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
5635 triggered_spell_id
= 12654;
5641 //last charge and crit
5642 if (triggeredByAura
->GetAuraCharges() <= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
5643 return true; // charge counting (will removed)
5645 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
5646 return (procEx
& PROC_EX_CRITICAL_HIT
); // charge update only at crit hits, no hidden cooldowns
5648 // Glyph of Ice Block
5651 if (GetTypeId() != TYPEID_PLAYER
)
5654 // not 100% safe with client version switches but for 3.1.3 no spells with cooldown that can have mage player except Frost Nova.
5655 ((Player
*)this)->RemoveSpellCategoryCooldown(35, true);
5658 // Glyph of Polymorph
5661 if (!pVictim
|| !pVictim
->isAlive())
5664 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE
);
5665 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE_PERCENT
);
5668 // Blessing of Ancient Kings
5672 if (!IsPositiveSpell(procSpell
->Id
))
5675 triggered_spell_id
= 64413;
5676 basepoints
[0] = damage
* 15 / 100;
5682 case SPELLFAMILY_WARRIOR
:
5685 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0000000800000000))
5687 // check attack comes not from behind
5688 if (!HasInArc(M_PI_F
, pVictim
))
5691 triggered_spell_id
= 22858;
5695 if (dummySpell
->SpellIconID
== 1697)
5697 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
5698 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
5700 // Need stun or root mechanic
5701 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_STUN_MASK
))
5704 switch (dummySpell
->Id
)
5706 case 29838: triggered_spell_id
=29842; break;
5707 case 29834: triggered_spell_id
=29841; break;
5708 case 42770: triggered_spell_id
=42771; break;
5710 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
5718 if (dummySpell
->SpellIconID
== 3214)
5720 triggered_spell_id
= 59653;
5721 basepoints
[0] = GetShieldBlockValue() * triggerAmount
/ 100;
5726 if (dummySpell
->Id
== 12328)
5728 // prevent chain of triggered spell from same triggered spell
5729 if(procSpell
&& procSpell
->Id
== 26654)
5732 target
= SelectRandomUnfriendlyTarget(pVictim
);
5736 triggered_spell_id
= 26654;
5741 case SPELLFAMILY_WARLOCK
:
5743 // Seed of Corruption
5744 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
5746 Modifier
* mod
= triggeredByAura
->GetModifier();
5747 // if damage is more than need or target die from damage deal finish spell
5748 if( mod
->m_amount
<= (int32
)damage
|| GetHealth() <= damage
)
5750 // remember guid before aura delete
5751 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5753 // Remove aura (before cast for prevent infinite loop handlers)
5754 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5756 // Cast finish spell (triggeredByAura already not exist!)
5757 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
5758 return true; // no hidden cooldown
5762 mod
->m_amount
-=damage
;
5765 // Seed of Corruption (Mobs cast) - no die req
5766 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0) && dummySpell
->SpellIconID
== 1932)
5768 Modifier
* mod
= triggeredByAura
->GetModifier();
5769 // if damage is more than need deal finish spell
5770 if( mod
->m_amount
<= (int32
)damage
)
5772 // remember guid before aura delete
5773 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5775 // Remove aura (before cast for prevent infinite loop handlers)
5776 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5778 // Cast finish spell (triggeredByAura already not exist!)
5779 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
5780 return true; // no hidden cooldown
5783 mod
->m_amount
-=damage
;
5787 if (dummySpell
->SpellIconID
== 3222)
5792 basepoints
[0] = damage
* triggerAmount
/ 100;
5793 triggered_spell_id
= 54181;
5796 switch(dummySpell
->Id
)
5798 // Nightfall & Glyph of Corruption
5804 triggered_spell_id
= 17941;
5813 basepoints
[0] = int32(damage
*triggerAmount
/100);
5815 triggered_spell_id
= 30294;
5818 // Shadowflame (Voidheart Raiment set bonus)
5821 triggered_spell_id
= 37379;
5824 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
5832 basepoints
[0] = damage
* triggerAmount
/100;
5833 triggered_spell_id
= 37382;
5836 // Shadowflame Hellfire (Voidheart Raiment set bonus)
5839 triggered_spell_id
= 37378;
5845 if (triggeredByAura
->GetEffIndex() != EFFECT_INDEX_0
)
5848 // Glyph of Siphon Life
5849 if (Aura
*aur
= GetAura(56216, EFFECT_INDEX_0
))
5850 triggerAmount
+= triggerAmount
* aur
->GetModifier()->m_amount
/ 100;
5852 basepoints
[0] = int32(damage
* triggerAmount
/ 100);
5853 triggered_spell_id
= 63106;
5859 case SPELLFAMILY_PRIEST
:
5862 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
5864 if(!pVictim
|| !pVictim
->isAlive())
5867 // pVictim is caster of aura
5868 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5871 // Energize 0.25% of max. mana
5872 pVictim
->CastSpell(pVictim
,57669,true,castItem
,triggeredByAura
);
5873 return true; // no hidden cooldown
5876 switch(dummySpell
->SpellIconID
)
5878 // Improved Shadowform
5881 if(!roll_chance_i(triggerAmount
))
5884 RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT
);
5885 RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED
);
5891 basepoints
[0] = damage
* triggerAmount
/100;
5892 triggered_spell_id
= 47753;
5901 Aura
* healingAura
= pVictim
->GetAura(procSpell
->Id
, EFFECT_INDEX_0
);
5905 int32 healingfromticks
= healingAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
);
5907 basepoints
[0] = healingfromticks
* triggerAmount
/ 100;
5908 triggered_spell_id
= 63544;
5911 // Improved Devouring Plague
5917 if (triggeredByAura
->GetEffIndex() != EFFECT_INDEX_1
)
5920 Aura
* leachAura
= pVictim
->GetAura(SPELL_AURA_PERIODIC_LEECH
, SPELLFAMILY_PRIEST
, UI64LIT(0x02000000), NULL
, GetGUID());
5924 int32 damagefromticks
= leachAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
);
5925 basepoints
[0] = damagefromticks
* triggerAmount
/ 100;
5926 triggered_spell_id
= 63675;
5931 switch(dummySpell
->Id
)
5936 // Return if self damage
5937 if (this == pVictim
)
5940 // Heal amount - Self/Team
5941 int32 team
= triggerAmount
*damage
/500;
5942 int32 self
= triggerAmount
*damage
/100 - team
;
5943 CastCustomSpell(this,15290,&team
,&self
,NULL
,true,castItem
,triggeredByAura
);
5944 return true; // no hidden cooldown
5946 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
5949 // Shadow Word: Pain
5950 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5951 triggered_spell_id
= 40441;
5953 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
5954 triggered_spell_id
= 40440;
5961 // Oracle Healing Bonus ("Garments of the Oracle" set)
5965 basepoints
[0] = int32(damage
* 10/100);
5967 triggered_spell_id
= 26170;
5970 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
5973 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
5977 basepoints
[0] = damage
* triggerAmount
/100;
5979 triggered_spell_id
= 39373;
5982 // Greater Heal (Vestments of Faith (Priest Tier 3) - 4 pieces bonus)
5985 triggered_spell_id
= 28810;
5988 // Glyph of Dispel Magic
5991 if(!target
->IsFriendlyTo(this))
5994 basepoints
[0] = int32(target
->GetMaxHealth() * triggerAmount
/ 100);
5995 triggered_spell_id
= 56131;
6001 case SPELLFAMILY_DRUID
:
6003 switch(dummySpell
->Id
)
6005 // Leader of the Pack
6008 // dummy m_amount store health percent (!=0 if Improved Leader of the Pack applied)
6009 int32 heal_percent
= triggeredByAura
->GetModifier()->m_amount
;
6013 // check explicitly only to prevent mana cast when halth cast cooldown
6014 if (cooldown
&& ((Player
*)this)->HasSpellCooldown(34299))
6018 triggered_spell_id
= 34299;
6019 basepoints
[0] = GetMaxHealth() * heal_percent
/ 100;
6023 if (triggeredByAura
->GetCasterGUID() == GetGUID())
6025 if (SpellEntry
const* manaCastEntry
= sSpellStore
.LookupEntry(60889))
6027 int32 mana_percent
= manaCastEntry
->CalculateSimpleValue(EFFECT_INDEX_0
) * heal_percent
;
6028 CastCustomSpell(this, manaCastEntry
, &mana_percent
, NULL
, NULL
, true, castItem
, triggeredByAura
);
6033 // Healing Touch (Dreamwalker Raiment set)
6037 basepoints
[0] = int32(procSpell
->manaCost
* 30 / 100);
6039 triggered_spell_id
= 28742;
6042 // Healing Touch Refund (Idol of Longevity trinket)
6046 triggered_spell_id
= 28848;
6049 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
6054 triggered_spell_id
= 37238;
6057 // Druid Tier 6 Trinket
6063 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
6065 triggered_spell_id
= 40445;
6069 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
6071 triggered_spell_id
= 40446;
6074 // Mangle (Bear) and Mangle (Cat)
6075 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000044000000000))
6077 triggered_spell_id
= 40452;
6083 if (!roll_chance_f(chance
))
6092 // Deadly Interrupt Effect
6093 triggered_spell_id
= 32747;
6096 // Glyph of Rejuvenation
6100 if (pVictim
->GetMaxHealth() < 2 * pVictim
->GetHealth())
6102 basepoints
[0] = triggerAmount
* damage
/ 100;
6103 triggered_spell_id
= 54755;
6106 // Item - Druid T10 Restoration 4P Bonus (Rejuvenation)
6109 if (!procSpell
|| GetTypeId() != TYPEID_PLAYER
)
6113 if (procSpell
->EffectRadiusIndex
[EFFECT_INDEX_0
])
6114 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(procSpell
->EffectRadiusIndex
[EFFECT_INDEX_0
]));
6116 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(procSpell
->rangeIndex
));
6118 ((Player
*)this)->ApplySpellMod(procSpell
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
6120 Unit
*second
= pVictim
->SelectRandomFriendlyTarget(pVictim
, radius
);
6125 pVictim
->CastSpell(second
, procSpell
, true, NULL
, triggeredByAura
, GetGUID());
6130 if (dummySpell
->SpellIconID
== 2856)
6134 // Only 0 aura can proc
6135 if (effIndex
!= EFFECT_INDEX_0
)
6138 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6142 if (!roll_chance_i(60))
6144 triggered_spell_id
= 48518;
6149 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
6153 triggered_spell_id
= 48517;
6160 else if (dummySpell
->SpellIconID
== 2860)
6162 triggered_spell_id
= 48504;
6163 basepoints
[0] = triggerAmount
* damage
/ 100;
6168 case SPELLFAMILY_ROGUE
:
6170 switch(dummySpell
->Id
)
6172 // Deadly Throw Interrupt
6175 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
6176 if (this == pVictim
)
6179 triggered_spell_id
= 32747;
6184 if (dummySpell
->SpellIconID
== 2909)
6186 // "refresh your Slice and Dice duration to its 5 combo point maximum"
6187 // lookup Slice and Dice
6188 AuraList
const& sd
= GetAurasByType(SPELL_AURA_MOD_HASTE
);
6189 for(AuraList::const_iterator itr
= sd
.begin(); itr
!= sd
.end(); ++itr
)
6191 SpellEntry
const *spellProto
= (*itr
)->GetSpellProto();
6192 if (spellProto
->SpellFamilyName
== SPELLFAMILY_ROGUE
&&
6193 (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000040000)))
6195 (*itr
)->SetAuraMaxDuration(GetSpellMaxDuration(spellProto
));
6196 (*itr
)->RefreshAura();
6203 if (dummySpell
->SpellIconID
== 2963)
6205 triggered_spell_id
= 44289;
6209 if (dummySpell
->SpellIconID
== 2116)
6215 basepoints
[0] = procSpell
->manaCost
* triggerAmount
/100;
6216 if (basepoints
[0] <= 0)
6220 triggered_spell_id
= 31663;
6225 case SPELLFAMILY_HUNTER
:
6227 // Aspect of the Viper
6228 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x4000000000000))
6230 uint32 maxmana
= GetMaxPower(POWER_MANA
);
6231 basepoints
[0] = int32(maxmana
* GetAttackTime(RANGED_ATTACK
)/1000.0f
/100.0f
);
6234 triggered_spell_id
= 34075;
6237 // Thrill of the Hunt
6238 if (dummySpell
->SpellIconID
== 2236)
6244 int32 mana
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
6245 basepoints
[0] = mana
* 40/100;
6246 if (basepoints
[0] <= 0)
6250 triggered_spell_id
= 34720;
6254 if (dummySpell
->SpellIconID
== 3406)
6256 triggered_spell_id
= 57669;
6261 if ( dummySpell
->SpellIconID
== 3579 )
6263 // Proc only from periodic (from trap activation proc another aura of this spell)
6264 if (!(procFlag
& PROC_FLAG_ON_DO_PERIODIC
) || !roll_chance_i(triggerAmount
))
6266 triggered_spell_id
= 56453;
6270 // Rapid Recuperation
6271 if ( dummySpell
->SpellIconID
== 3560 )
6273 // This effect only from Rapid Killing (mana regen)
6274 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0100000000000000)))
6279 switch(dummySpell
->Id
)
6281 case 53228: // Rank 1
6282 triggered_spell_id
= 56654;
6284 case 53232: // Rank 2
6285 triggered_spell_id
= 58882;
6290 // Glyph of Mend Pet
6291 if(dummySpell
->Id
== 57870)
6293 pVictim
->CastSpell(pVictim
, 57894, true, NULL
, NULL
, GetGUID());
6298 case SPELLFAMILY_PALADIN
:
6300 // Seal of Righteousness - melee proc dummy (addition ${$MWS*(0.022*$AP+0.044*$SPH)} damage)
6301 if ((dummySpell
->SpellFamilyFlags
& UI64LIT(0x000000008000000)) && effIndex
== EFFECT_INDEX_0
)
6303 triggered_spell_id
= 25742;
6304 float ap
= GetTotalAttackPowerValue(BASE_ATTACK
);
6305 int32 holy
= SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_HOLY
);
6308 basepoints
[0] = GetAttackTime(BASE_ATTACK
) * int32(ap
*0.022f
+ 0.044f
* holy
) / 1000;
6311 // Righteous Vengeance
6312 if (dummySpell
->SpellIconID
== 3025)
6315 basepoints
[0] = triggerAmount
*damage
/400;
6316 triggered_spell_id
= 61840;
6320 if (dummySpell
->SpellIconID
== 3030)
6323 basepoints
[0] = triggerAmount
*damage
/400;
6324 triggered_spell_id
= 54203;
6327 switch(dummySpell
->Id
)
6329 // Judgement of Light
6332 basepoints
[0] = int32( pVictim
->GetMaxHealth() * triggeredByAura
->GetModifier()->m_amount
/ 100 );
6333 pVictim
->CastCustomSpell(pVictim
, 20267, &basepoints
[0], NULL
, NULL
, true, NULL
, triggeredByAura
);
6336 // Judgement of Wisdom
6339 if (pVictim
->getPowerType() == POWER_MANA
)
6341 // 2% of maximum base mana
6342 basepoints
[0] = int32(pVictim
->GetCreateMana() * 2 / 100);
6343 pVictim
->CastCustomSpell(pVictim
, 20268, &basepoints
[0], NULL
, NULL
, true, NULL
, triggeredByAura
);
6347 // Heart of the Crusader (Rank 1)
6349 triggered_spell_id
= 21183;
6351 // Heart of the Crusader (Rank 2)
6353 triggered_spell_id
= 54498;
6355 // Heart of the Crusader (Rank 3)
6357 triggered_spell_id
= 54499;
6359 case 20911: // Blessing of Sanctuary
6360 case 25899: // Greater Blessing of Sanctuary
6363 switch (target
->getPowerType())
6366 triggered_spell_id
= 57319;
6373 // Holy Power (Redemption Armor set)
6379 // Set class defined buff
6380 switch (pVictim
->getClass())
6386 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6390 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6394 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
6397 triggered_spell_id
= 28790; // Increases the friendly target's armor
6404 // Spiritual Attunement
6408 // if healed by another unit (pVictim)
6409 if (this == pVictim
)
6413 basepoints
[0] = triggerAmount
*damage
/100;
6415 triggered_spell_id
= 31786;
6418 // Seal of Vengeance (damage calc on apply aura)
6421 if (effIndex
!= EFFECT_INDEX_0
) // effect 1,2 used by seal unleashing code
6424 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6425 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595) )
6426 triggered_spell_id
= 31803; // Holy Vengeance
6428 // Add 5-stack effect from Holy Vengeance
6430 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6431 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6433 if( ((*itr
)->GetId() == 31803) && (*itr
)->GetCasterGUID()==GetGUID())
6435 stacks
= (*itr
)->GetStackAmount();
6440 CastSpell(target
,42463,true,NULL
,triggeredByAura
);
6443 // Judgements of the Wise
6447 // triggered only at casted Judgement spells, not at additional Judgement effects
6448 if(!procSpell
|| procSpell
->Category
!= 1210)
6452 triggered_spell_id
= 31930;
6455 CastSpell(this, 57669, true, NULL
, triggeredByAura
);
6457 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
6465 // Flash of light/Holy light
6466 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x00000000C0000000))
6468 triggered_spell_id
= 40471;
6472 else if (GetSpellSpecific(procSpell
->Id
)==SPELL_JUDGEMENT
)
6474 triggered_spell_id
= 40472;
6480 if (!roll_chance_f(chance
))
6485 // Light's Beacon (heal target area aura)
6488 // not do bonus heal for explicit beacon focus healing
6489 if (GetGUID() == triggeredByAura
->GetCasterGUID())
6493 Unit
* beacon
= triggeredByAura
->GetCaster();
6497 // find caster main aura at beacon
6499 Unit::AuraList
const& baa
= beacon
->GetAurasByType(SPELL_AURA_PERIODIC_TRIGGER_SPELL
);
6500 for(Unit::AuraList::const_iterator i
= baa
.begin(); i
!= baa
.end(); ++i
)
6502 if ((*i
)->GetId() == 53563 && (*i
)->GetCasterGUID() == pVictim
->GetGUID())
6509 // original heal must be form beacon caster
6513 triggered_spell_id
= 53652; // Beacon of Light
6514 basepoints
[0] = triggeredByAura
->GetModifier()->m_amount
*damage
/100;
6516 // cast with original caster set but beacon to beacon for apply caster mods and avoid LoS check
6517 beacon
->CastCustomSpell(beacon
,triggered_spell_id
,&basepoints
[0],NULL
,NULL
,true,castItem
,triggeredByAura
,pVictim
->GetGUID());
6520 // Seal of Corruption (damage calc on apply aura)
6523 if (effIndex
!= EFFECT_INDEX_0
) // effect 1,2 used by seal unleashing code
6526 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6527 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595))
6528 triggered_spell_id
= 53742; // Blood Corruption
6530 // Add 5-stack effect from Blood Corruption
6532 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6533 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6535 if( ((*itr
)->GetId() == 53742) && (*itr
)->GetCasterGUID()==GetGUID())
6537 stacks
= (*itr
)->GetStackAmount();
6542 CastSpell(target
,53739,true,NULL
,triggeredByAura
);
6545 // Glyph of Holy Light
6548 triggered_spell_id
= 54968;
6549 basepoints
[0] = triggerAmount
*damage
/100;
6552 // Glyph of Divinity
6555 // Lookup base amount mana restore
6556 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
6558 if (procSpell
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
6560 int32 mana
= procSpell
->CalculateSimpleValue(SpellEffectIndex(i
));
6561 CastCustomSpell(this, 54986, NULL
, &mana
, NULL
, true, castItem
, triggeredByAura
);
6567 // Sacred Shield (buff)
6570 triggered_spell_id
= 66922;
6571 SpellEntry
const* triggeredEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6572 if (!triggeredEntry
)
6575 basepoints
[0] = int32(damage
/ (GetSpellDuration(triggeredEntry
) / triggeredEntry
->EffectAmplitude
[EFFECT_INDEX_0
]));
6579 // Sacred Shield (talent rank)
6582 triggered_spell_id
= 58597;
6589 case SPELLFAMILY_SHAMAN
:
6591 switch(dummySpell
->Id
)
6593 // Totemic Power (The Earthshatterer set)
6599 // Set class defined buff
6600 switch (pVictim
->getClass())
6606 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6610 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6614 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
6617 triggered_spell_id
= 28827; // Increases the friendly target's armor
6624 // Lesser Healing Wave (Totem of Flowing Water Relic)
6628 triggered_spell_id
= 28850;
6631 // Windfury Weapon (Passive) 1-5 Ranks
6634 if(GetTypeId()!=TYPEID_PLAYER
)
6637 if(!castItem
|| !castItem
->IsEquipped())
6640 // custom cooldown processing case
6641 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6644 // Now amount of extra power stored in 1 effect of Enchant spell
6645 // Get it by item enchant id
6647 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
6649 case 283: spellId
= 8232; break; // 1 Rank
6650 case 284: spellId
= 8235; break; // 2 Rank
6651 case 525: spellId
= 10486; break; // 3 Rank
6652 case 1669:spellId
= 16362; break; // 4 Rank
6653 case 2636:spellId
= 25505; break; // 5 Rank
6654 case 3785:spellId
= 58801; break; // 6 Rank
6655 case 3786:spellId
= 58803; break; // 7 Rank
6656 case 3787:spellId
= 58804; break; // 8 Rank
6659 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
6660 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
6665 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
6666 if(!windfurySpellEntry
)
6668 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
6672 int32 extra_attack_power
= CalculateSpellDamage(pVictim
, windfurySpellEntry
, EFFECT_INDEX_1
);
6675 if (castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
6677 // Value gained from additional AP
6678 basepoints
[0] = int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
6679 triggered_spell_id
= 33750;
6684 // Value gained from additional AP
6685 basepoints
[0] = int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
6686 triggered_spell_id
= 25504;
6689 // apply cooldown before cast to prevent processing itself
6691 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6694 for ( uint32 i
= 0; i
<2; ++i
)
6695 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints
[0],NULL
,NULL
,true,castItem
,triggeredByAura
);
6699 // Shaman Tier 6 Trinket
6706 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6708 triggered_spell_id
= 40465; // Lightning Bolt
6711 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080))
6713 triggered_spell_id
= 40465; // Lesser Healing Wave
6716 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
6718 triggered_spell_id
= 40466; // Stormstrike
6724 if (!roll_chance_f(chance
))
6730 // Glyph of Healing Wave
6733 // Not proc from self heals
6736 basepoints
[0] = triggerAmount
* damage
/ 100;
6738 triggered_spell_id
= 55533;
6745 target
= GetOwner();
6748 basepoints
[0] = triggerAmount
* damage
/ 100;
6749 triggered_spell_id
= 58879;
6752 // Glyph of Totem of Wrath
6755 Totem
* totem
= GetTotem(TOTEM_SLOT_FIRE
);
6759 // find totem aura bonus
6760 AuraList
const& spellPower
= totem
->GetAurasByType(SPELL_AURA_NONE
);
6761 for(AuraList::const_iterator i
= spellPower
.begin();i
!= spellPower
.end(); ++i
)
6763 // select proper aura for format aura type in spell proto
6764 if ((*i
)->GetTarget()==totem
&& (*i
)->GetSpellProto()->EffectApplyAuraName
[(*i
)->GetEffIndex()] == SPELL_AURA_MOD_HEALING_DONE
&&
6765 (*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000004000000))
6767 basepoints
[0] = triggerAmount
* (*i
)->GetModifier()->m_amount
/ 100;
6775 basepoints
[1] = basepoints
[0];
6776 triggered_spell_id
= 63283; // Totem of Wrath, caster bonus
6780 // Shaman T8 Elemental 4P Bonus
6783 basepoints
[0] = int32( triggerAmount
* damage
/ 100 );
6784 triggered_spell_id
= 64930; // Electrified
6787 // Shaman T9 Elemental 4P Bonus
6790 basepoints
[0] = int32( triggerAmount
* damage
/ 100 );
6791 triggered_spell_id
= 71824;
6795 // Storm, Earth and Fire
6796 if (dummySpell
->SpellIconID
== 3063)
6798 // Earthbind Totem summon only
6799 if(procSpell
->Id
!= 2484)
6802 if (!roll_chance_i(triggerAmount
))
6805 triggered_spell_id
= 64695;
6808 // Ancestral Awakening
6809 if (dummySpell
->SpellIconID
== 3065)
6811 triggered_spell_id
= 52759;
6812 basepoints
[0] = triggerAmount
* damage
/ 100;
6817 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
6820 basepoints
[0] = triggerAmount
;
6822 // Glyph of Earth Shield
6823 if (Aura
* aur
= GetDummyAura(63279))
6825 int32 aur_mod
= aur
->GetModifier()->m_amount
;
6826 basepoints
[0] = int32(basepoints
[0] * (aur_mod
+ 100.0f
) / 100.0f
);
6829 triggered_spell_id
= 379;
6832 // Improved Water Shield
6833 if (dummySpell
->SpellIconID
== 2287)
6835 // Lesser Healing Wave need aditional 60% roll
6836 if ((procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)) && !roll_chance_i(60))
6838 // lookup water shield
6839 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6840 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6842 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6843 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000002000000000)))
6845 uint32 spell
= (*itr
)->GetSpellProto()->EffectTriggerSpell
[(*itr
)->GetEffIndex()];
6846 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
6847 if ((*itr
)->DropAuraCharge())
6848 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6855 // Lightning Overload
6856 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
6858 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
6861 // custom cooldown processing case
6862 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6866 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
6867 switch (procSpell
->Id
)
6870 case 403: spellId
= 45284; break; // Rank 1
6871 case 529: spellId
= 45286; break; // Rank 2
6872 case 548: spellId
= 45287; break; // Rank 3
6873 case 915: spellId
= 45288; break; // Rank 4
6874 case 943: spellId
= 45289; break; // Rank 5
6875 case 6041: spellId
= 45290; break; // Rank 6
6876 case 10391: spellId
= 45291; break; // Rank 7
6877 case 10392: spellId
= 45292; break; // Rank 8
6878 case 15207: spellId
= 45293; break; // Rank 9
6879 case 15208: spellId
= 45294; break; // Rank 10
6880 case 25448: spellId
= 45295; break; // Rank 11
6881 case 25449: spellId
= 45296; break; // Rank 12
6882 case 49237: spellId
= 49239; break; // Rank 13
6883 case 49238: spellId
= 49240; break; // Rank 14
6885 case 421: spellId
= 45297; break; // Rank 1
6886 case 930: spellId
= 45298; break; // Rank 2
6887 case 2860: spellId
= 45299; break; // Rank 3
6888 case 10605: spellId
= 45300; break; // Rank 4
6889 case 25439: spellId
= 45301; break; // Rank 5
6890 case 25442: spellId
= 45302; break; // Rank 6
6891 case 49270: spellId
= 49268; break; // Rank 7
6892 case 49271: spellId
= 49269; break; // Rank 8
6894 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
6897 // No thread generated mod
6898 // TODO: exist special flag in spell attributes for this, need found and use!
6899 SpellModifier
*mod
= new SpellModifier(SPELLMOD_THREAT
,SPELLMOD_PCT
,-100,triggeredByAura
);
6901 ((Player
*)this)->AddSpellMod(mod
, true);
6903 // Remove cooldown (Chain Lightning - have Category Recovery time)
6904 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000002))
6905 ((Player
*)this)->RemoveSpellCooldown(spellId
);
6907 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
6909 ((Player
*)this)->AddSpellMod(mod
, false);
6911 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6912 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6917 if(dummySpell
->SpellIconID
== 3059)
6919 // lookup Lightning Shield
6920 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6921 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6923 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6924 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000400)))
6927 switch ((*itr
)->GetId())
6929 case 324: spell
= 26364; break;
6930 case 325: spell
= 26365; break;
6931 case 905: spell
= 26366; break;
6932 case 945: spell
= 26367; break;
6933 case 8134: spell
= 26369; break;
6934 case 10431: spell
= 26370; break;
6935 case 10432: spell
= 26363; break;
6936 case 25469: spell
= 26371; break;
6937 case 25472: spell
= 26372; break;
6938 case 49280: spell
= 49278; break;
6939 case 49281: spell
= 49279; break;
6943 CastSpell(target
, spell
, true, castItem
, triggeredByAura
);
6944 if ((*itr
)->DropAuraCharge())
6945 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6952 if (dummySpell
->SpellIconID
== 3780)
6954 Unit
*caster
= triggeredByAura
->GetCaster();
6956 if (!procSpell
|| !caster
)
6959 float distance
= caster
->GetDistance(pVictim
);
6960 int32 chance
= triggerAmount
;
6962 if (distance
< 15.0f
|| !roll_chance_i(chance
))
6965 // make triggered cast apply after current damage spell processing for prevent remove by it
6966 if(Spell
* spell
= GetCurrentSpell(CURRENT_GENERIC_SPELL
))
6967 spell
->AddTriggeredSpell(63685);
6972 case SPELLFAMILY_DEATHKNIGHT
:
6975 if (dummySpell
->SpellIconID
== 2664)
6977 basepoints
[0] = triggerAmount
;
6978 triggered_spell_id
= 50163;
6982 // Dancing Rune Weapon
6983 if (dummySpell
->Id
== 49028)
6985 // 1 dummy aura for dismiss rune blade
6986 if (effIndex
!= EFFECT_INDEX_2
)
6988 // TODO: wite script for this "fights on its own, doing the same attacks"
6989 // NOTE: Trigger here on every attack and spell cast
6993 if (dummySpell
->Id
== 49005)
6995 // TODO: need more info (cooldowns/PPM)
6996 triggered_spell_id
= 61607;
7000 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000010000))
7002 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
7003 triggered_spell_id
= 50181;
7008 if (dummySpell
->SpellIconID
== 2709)
7010 basepoints
[0] = triggerAmount
* damage
/ 100;
7011 triggered_spell_id
= 51460;
7014 // Threat of Thassarian
7015 if (dummySpell
->SpellIconID
== 2023)
7018 if (!procSpell
|| !haveOffhandWeapon())
7020 // Chance as basepoints for dummy aura
7021 if (!roll_chance_i(triggerAmount
))
7024 switch (procSpell
->Id
)
7027 case 49020: // Rank 1
7028 triggered_spell_id
= 66198; break;
7029 case 51423: // Rank 2
7030 triggered_spell_id
= 66972; break;
7031 case 51424: // Rank 3
7032 triggered_spell_id
= 66973; break;
7033 case 51425: // Rank 4
7034 triggered_spell_id
= 66974; break;
7036 case 49143: // Rank 1
7037 triggered_spell_id
= 66196; break;
7038 case 51416: // Rank 2
7039 triggered_spell_id
= 66958; break;
7040 case 51417: // Rank 3
7041 triggered_spell_id
= 66959; break;
7042 case 51418: // Rank 4
7043 triggered_spell_id
= 66960; break;
7044 case 51419: // Rank 5
7045 triggered_spell_id
= 66961; break;
7046 case 55268: // Rank 6
7047 triggered_spell_id
= 66962; break;
7049 case 45462: // Rank 1
7050 triggered_spell_id
= 66216; break;
7051 case 49917: // Rank 2
7052 triggered_spell_id
= 66988; break;
7053 case 49918: // Rank 3
7054 triggered_spell_id
= 66989; break;
7055 case 49919: // Rank 4
7056 triggered_spell_id
= 66990; break;
7057 case 49920: // Rank 5
7058 triggered_spell_id
= 66991; break;
7059 case 49921: // Rank 6
7060 triggered_spell_id
= 66992; break;
7062 case 49998: // Rank 1
7063 triggered_spell_id
= 66188; break;
7064 case 49999: // Rank 2
7065 triggered_spell_id
= 66950; break;
7066 case 45463: // Rank 3
7067 triggered_spell_id
= 66951; break;
7068 case 49923: // Rank 4
7069 triggered_spell_id
= 66952; break;
7070 case 49924: // Rank 5
7071 triggered_spell_id
= 66953; break;
7074 triggered_spell_id
= 66217; break;
7076 case 45902: // Rank 1
7077 triggered_spell_id
= 66215; break;
7078 case 49926: // Rank 2
7079 triggered_spell_id
= 66975; break;
7080 case 49927: // Rank 3
7081 triggered_spell_id
= 66976; break;
7082 case 49928: // Rank 4
7083 triggered_spell_id
= 66977; break;
7084 case 49929: // Rank 5
7085 triggered_spell_id
= 66978; break;
7086 case 49930: // Rank 6
7087 triggered_spell_id
= 66979; break;
7093 // Runic Power Back on Snare/Root
7094 if (dummySpell
->Id
== 61257)
7096 // only for spells and hit/crit (trigger start always) and not start from self casted spells
7097 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7099 // Need snare or root mechanic
7100 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_SNARE_MASK
))
7102 triggered_spell_id
= 61258;
7107 if (dummySpell
->SpellIconID
== 1614)
7109 if (!roll_chance_f(GetUnitCriticalChance(BASE_ATTACK
, pVictim
)))
7111 basepoints
[0] = triggerAmount
* damage
/ 100;
7112 triggered_spell_id
= 50526;
7115 // Blood-Caked Blade
7116 if (dummySpell
->SpellIconID
== 138)
7118 triggered_spell_id
= dummySpell
->EffectTriggerSpell
[effIndex
];
7127 // processed charge only counting case
7128 if(!triggered_spell_id
)
7131 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
7135 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
7140 if(!target
|| target
!=this && !target
->isAlive())
7143 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
7146 if (basepoints
[EFFECT_INDEX_0
] || basepoints
[EFFECT_INDEX_1
] || basepoints
[EFFECT_INDEX_2
])
7147 CastCustomSpell(target
, triggered_spell_id
,
7148 basepoints
[EFFECT_INDEX_0
] ? &basepoints
[EFFECT_INDEX_0
] : NULL
,
7149 basepoints
[EFFECT_INDEX_1
] ? &basepoints
[EFFECT_INDEX_1
] : NULL
,
7150 basepoints
[EFFECT_INDEX_2
] ? &basepoints
[EFFECT_INDEX_2
] : NULL
,
7151 true, castItem
, triggeredByAura
);
7153 CastSpell(target
, triggered_spell_id
, true, castItem
, triggeredByAura
);
7155 if (cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7156 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
7161 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
7163 // Get triggered aura spell info
7164 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
7166 // Basepoints of trigger aura
7167 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7169 // Set trigger spell id, target, custom basepoints
7170 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
7171 Unit
* target
= NULL
;
7172 int32 basepoints
[MAX_EFFECT_INDEX
] = {0, 0, 0};
7174 if(triggeredByAura
->GetModifier()->m_auraname
== SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
)
7175 basepoints
[0] = triggerAmount
;
7177 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7178 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7180 // Try handle unknown trigger spells
7181 // Custom requirements (not listed in procEx) Warning! damage dealing after this
7182 // Custom triggered spells
7183 switch (auraSpellInfo
->SpellFamilyName
)
7185 case SPELLFAMILY_GENERIC
:
7186 switch(auraSpellInfo
->Id
)
7188 //case 191: // Elemental Response
7189 // switch (procSpell->School)
7191 // case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192; break;
7192 // case SPELL_SCHOOL_FROST: trigger_spell_id = 34193; break;
7193 // case SPELL_SCHOOL_ARCANE:trigger_spell_id = 34194; break;
7194 // case SPELL_SCHOOL_NATURE:trigger_spell_id = 34195; break;
7195 // case SPELL_SCHOOL_SHADOW:trigger_spell_id = 34196; break;
7196 // case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197; break;
7197 // case SPELL_SCHOOL_NORMAL:trigger_spell_id = 34198; break;
7200 //case 5301: break; // Defensive State (DND)
7201 //case 7137: break: // Shadow Charge (Rank 1)
7202 //case 7377: break: // Take Immune Periodic Damage <Not Working>
7203 //case 13358: break; // Defensive State (DND)
7204 //case 16092: break; // Defensive State (DND)
7205 //case 18943: break; // Double Attack
7206 //case 19194: break; // Double Attack
7207 //case 19817: break; // Double Attack
7208 //case 19818: break; // Double Attack
7209 //case 22835: break; // Drunken Rage
7210 // trigger_spell_id = 14822; break;
7211 case 23780: // Aegis of Preservation (Aegis of Preservation trinket)
7212 trigger_spell_id
= 23781;
7214 //case 24949: break; // Defensive State 2 (DND)
7215 case 27522: // Mana Drain Trigger
7216 case 40336: // Mana Drain Trigger
7217 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
7219 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
7220 if (pVictim
&& pVictim
->isAlive())
7221 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
7223 case 31255: // Deadly Swiftness (Rank 1)
7224 // whenever you deal damage to a target who is below 20% health.
7225 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
7229 trigger_spell_id
= 22588;
7231 //case 33207: break; // Gossip NPC Periodic - Fidget
7232 case 33896: // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
7233 trigger_spell_id
= 33898;
7235 //case 34082: break; // Advantaged State (DND)
7236 //case 34783: break: // Spell Reflection
7237 //case 35205: break: // Vanish
7238 //case 35321: break; // Gushing Wound
7239 //case 36096: break: // Spell Reflection
7240 //case 36207: break: // Steal Weapon
7241 //case 36576: break: // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
7242 //case 37030: break; // Chaotic Temperament
7243 //case 38363: break; // Gushing Wound
7244 //case 39215: break; // Gushing Wound
7245 //case 40250: break; // Improved Duration
7246 //case 40329: break; // Demo Shout Sensor
7247 //case 40364: break; // Entangling Roots Sensor
7248 //case 41054: break; // Copy Weapon
7249 // trigger_spell_id = 41055; break;
7250 //case 41248: break; // Consuming Strikes
7251 // trigger_spell_id = 41249; break;
7252 //case 42730: break: // Woe Strike
7253 //case 43453: break: // Rune Ward
7254 //case 43504: break; // Alterac Valley OnKill Proc Aura
7255 //case 44326: break: // Pure Energy Passive
7256 //case 44526: break; // Hate Monster (Spar) (30 sec)
7257 //case 44527: break; // Hate Monster (Spar Buddy) (30 sec)
7258 //case 44819: break; // Hate Monster (Spar Buddy) (>30% Health)
7259 //case 44820: break; // Hate Monster (Spar) (<30%)
7260 case 45057: // Evasive Maneuvers (Commendation of Kael`thas trinket)
7261 // reduce you below $s1% health
7262 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
7265 //case 45903: break: // Offensive State
7266 //case 46146: break: // [PH] Ahune Spanky Hands
7267 //case 46939: break; // Black Bow of the Betrayer
7268 // trigger_spell_id = 29471; - gain mana
7269 // 27526; - drain mana if possible
7270 case 43820: // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
7271 // Pct value stored in dummy
7272 basepoints
[0] = pVictim
->GetCreateHealth() * auraSpellInfo
->CalculateSimpleValue(EFFECT_INDEX_1
) / 100;
7275 //case 45205: break; // Copy Offhand Weapon
7276 //case 45343: break; // Dark Flame Aura
7277 //case 47300: break; // Dark Flame Aura
7278 //case 48876: break; // Beast's Mark
7279 // trigger_spell_id = 48877; break;
7280 //case 49059: break; // Horde, Hate Monster (Spar Buddy) (>30% Health)
7281 //case 50051: break; // Ethereal Pet Aura
7282 //case 50689: break; // Blood Presence (Rank 1)
7283 //case 50844: break; // Blood Mirror
7284 //case 52856: break; // Charge
7285 //case 54072: break; // Knockback Ball Passive
7286 //case 54476: break; // Blood Presence
7287 //case 54775: break; // Abandon Vehicle on Poly
7288 case 57345: // Darkmoon Card: Greatness
7292 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 60229;stat
= GetStat(STAT_STRENGTH
); }
7294 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 60233;stat
= GetStat(STAT_AGILITY
); }
7296 if (GetStat(STAT_INTELLECT
)> stat
) { trigger_spell_id
= 60234;stat
= GetStat(STAT_INTELLECT
);}
7298 if (GetStat(STAT_SPIRIT
) > stat
) { trigger_spell_id
= 60235; }
7301 //case 55580: break: // Mana Link
7302 //case 57587: break: // Steal Ranged ()
7303 //case 57594: break; // Copy Ranged Weapon
7304 //case 59237: break; // Beast's Mark
7305 // trigger_spell_id = 59233; break;
7306 //case 59288: break; // Infra-Green Shield
7307 //case 59532: break; // Abandon Passengers on Poly
7308 //case 59735: break: // Woe Strike
7309 case 64415: // // Val'anyr Hammer of Ancient Kings - Equip Effect
7312 if (!IsPositiveSpell(procSpell
->Id
))
7316 case 67702: // Death's Choice, Item - Coliseum 25 Normal Melee Trinket
7320 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67708;stat
= GetStat(STAT_STRENGTH
); }
7322 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67703; }
7325 case 67771: // Death's Choice (heroic), Item - Coliseum 25 Heroic Melee Trinket
7329 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67773;stat
= GetStat(STAT_STRENGTH
); }
7331 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67772; }
7336 case SPELLFAMILY_MAGE
:
7337 if (auraSpellInfo
->SpellIconID
== 2127) // Blazing Speed
7339 switch (auraSpellInfo
->Id
)
7341 case 31641: // Rank 1
7342 case 31642: // Rank 2
7343 trigger_spell_id
= 31643;
7346 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
7350 // Persistent Shield (Scarab Brooch trinket)
7351 else if(auraSpellInfo
->Id
== 26467)
7353 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
7354 basepoints
[0] = damage
* 15 / 100;
7356 trigger_spell_id
= 26470;
7359 case SPELLFAMILY_WARRIOR
:
7360 // Deep Wounds (replace triggered spells to directly apply DoT), dot spell have finilyflags
7361 if (auraSpellInfo
->SpellFamilyFlags
== UI64LIT(0x0) && auraSpellInfo
->SpellIconID
== 243)
7364 // DW should benefit of attack power, damage percent mods etc.
7365 // TODO: check if using offhand damage is correct and if it should be divided by 2
7366 if (haveOffhandWeapon() && getAttackTimer(BASE_ATTACK
) > getAttackTimer(OFF_ATTACK
))
7367 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
))/2;
7369 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXDAMAGE
))/2;
7371 switch (auraSpellInfo
->Id
)
7373 case 12834: basepoints
[0] = int32(weaponDamage
* 16 / 100); break;
7374 case 12849: basepoints
[0] = int32(weaponDamage
* 32 / 100); break;
7375 case 12867: basepoints
[0] = int32(weaponDamage
* 48 / 100); break;
7378 sLog
.outError("Unit::HandleProcTriggerSpell: DW unknown spell rank %u",auraSpellInfo
->Id
);
7382 // 1 tick/sec * 6 sec = 6 ticks
7385 trigger_spell_id
= 12721;
7388 if (auraSpellInfo
->Id
== 50421) // Scent of Blood
7389 trigger_spell_id
= 50422;
7391 case SPELLFAMILY_WARLOCK
:
7394 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
7396 // search for "Improved Drain Soul" dummy aura
7397 Unit::AuraList
const& mDummyAura
= GetAurasByType(SPELL_AURA_DUMMY
);
7398 for(Unit::AuraList::const_iterator i
= mDummyAura
.begin(); i
!= mDummyAura
.end(); ++i
)
7400 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
7402 // basepoints of trigger spell stored in dummyeffect of spellProto
7403 int32 basepoints
= GetMaxPower(POWER_MANA
) * (*i
)->GetSpellProto()->CalculateSimpleValue(EFFECT_INDEX_2
) / 100;
7404 CastCustomSpell(this, 18371, &basepoints
, NULL
, NULL
, true, castItem
, triggeredByAura
);
7408 // Not remove charge (aura removed on death in any cases)
7409 // Need for correct work Drain Soul SPELL_AURA_CHANNEL_DEATH_ITEM aura
7412 // Nether Protection
7413 else if (auraSpellInfo
->SpellIconID
== 1985)
7417 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7419 case SPELL_SCHOOL_NORMAL
:
7420 return false; // ignore
7421 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 54370; break;
7422 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 54371; break;
7423 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 54375; break;
7424 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 54372; break;
7425 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 54374; break;
7426 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
7432 else if (auraSpellInfo
->Id
== 28845)
7434 // When your health drops below 20% ....
7435 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
7439 else if (auraSpellInfo
->Id
== 63156 || auraSpellInfo
->Id
== 63158)
7441 // Looking for dummy effect
7442 Aura
*aur
= GetAura(auraSpellInfo
->Id
, EFFECT_INDEX_1
);
7446 // If target's health is not below equal certain value (35%) not proc
7447 if (int32(pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth()) > aur
->GetModifier()->m_amount
)
7452 case SPELLFAMILY_PRIEST
:
7454 // Greater Heal Refund (Avatar Raiment set)
7455 if (auraSpellInfo
->Id
==37594)
7457 // Not give if target already have full health
7458 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
7460 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
7461 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
7463 trigger_spell_id
= 37595;
7466 else if (auraSpellInfo
->SpellIconID
== 1875)
7468 switch (auraSpellInfo
->Id
)
7470 case 27811: trigger_spell_id
= 27813; break;
7471 case 27815: trigger_spell_id
= 27817; break;
7472 case 27816: trigger_spell_id
= 27818; break;
7474 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
7477 basepoints
[0] = damage
* triggerAmount
/ 100 / 3;
7482 case SPELLFAMILY_DRUID
:
7484 // Druid Forms Trinket
7485 if (auraSpellInfo
->Id
==37336)
7489 case FORM_NONE
: trigger_spell_id
= 37344;break;
7490 case FORM_CAT
: trigger_spell_id
= 37341;break;
7492 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
7493 case FORM_TREE
: trigger_spell_id
= 37342;break;
7494 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
7499 // Druid T9 Feral Relic (Lacerate, Swipe, Mangle, and Shred)
7500 else if (auraSpellInfo
->Id
==67353)
7504 case FORM_CAT
: trigger_spell_id
= 67355; break;
7506 case FORM_DIREBEAR
: trigger_spell_id
= 67354; break;
7513 case SPELLFAMILY_HUNTER
:
7515 if (auraSpellInfo
->SpellIconID
== 3247 && auraSpellInfo
->SpellVisual
[0] == 0)
7517 basepoints
[0] = damage
* triggerAmount
/ 100 / 8;
7518 trigger_spell_id
= 63468;
7521 // Rapid Recuperation
7522 else if (auraSpellInfo
->Id
== 53228 || auraSpellInfo
->Id
== 53232)
7524 // This effect only from Rapid Fire (ability cast)
7525 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000020)))
7529 case SPELLFAMILY_PALADIN
:
7533 if (auraSpellInfo->SpellIconID == 2137)
7535 switch (auraSpellInfo->Id)
7537 case 31828: // Rank 1
7538 case 31829: // Rank 2
7539 case 31830: // Rank 3
7542 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
7548 if (auraSpellInfo
->Id
==37705)
7550 trigger_spell_id
= 37706;
7554 if (auraSpellInfo
->Id
==60510)
7556 trigger_spell_id
= 60515;
7560 else if (auraSpellInfo
->SpellIconID
==241)
7564 // procspell is triggered spell but we need mana cost of original casted spell
7565 uint32 originalSpellId
= procSpell
->Id
;
7567 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0001000000000000))
7569 switch(procSpell
->Id
)
7571 case 25914: originalSpellId
= 20473; break;
7572 case 25913: originalSpellId
= 20929; break;
7573 case 25903: originalSpellId
= 20930; break;
7574 case 27175: originalSpellId
= 27174; break;
7575 case 33074: originalSpellId
= 33072; break;
7576 case 48820: originalSpellId
= 48824; break;
7577 case 48821: originalSpellId
= 48825; break;
7579 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
7583 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
7586 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
7589 // percent stored in effect 1 (class scripts) base points
7590 int32 cost
= originalSpell
->manaCost
+ originalSpell
->ManaCostPercentage
* GetCreateMana() / 100;
7591 basepoints
[0] = cost
*auraSpellInfo
->CalculateSimpleValue(EFFECT_INDEX_1
)/100;
7592 trigger_spell_id
= 20272;
7595 // Lightning Capacitor
7596 else if (auraSpellInfo
->Id
==37657)
7598 if(!pVictim
|| !pVictim
->isAlive())
7601 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
7603 Aura
* dummy
= GetDummyAura(37658);
7604 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7605 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7608 RemoveAurasDueToSpell(37658);
7609 trigger_spell_id
= 37661;
7612 // Bonus Healing (Crystal Spire of Karabor mace)
7613 else if (auraSpellInfo
->Id
== 40971)
7615 // If your target is below $s1% health
7616 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
7619 // Thunder Capacitor
7620 else if (auraSpellInfo
->Id
== 54841)
7622 if(!pVictim
|| !pVictim
->isAlive())
7625 CastSpell(this, 54842, true, NULL
, triggeredByAura
);
7628 Aura
* dummy
= GetDummyAura(54842);
7629 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7630 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7633 RemoveAurasDueToSpell(54842);
7634 trigger_spell_id
= 54843;
7639 case SPELLFAMILY_SHAMAN
:
7641 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc
7642 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000400))
7644 switch(auraSpellInfo
->Id
)
7647 trigger_spell_id
= 26364; break;
7649 trigger_spell_id
= 26365; break;
7651 trigger_spell_id
= 26366; break;
7653 trigger_spell_id
= 26367; break;
7654 case 8134: // Rank 5
7655 trigger_spell_id
= 26369; break;
7656 case 10431: // Rank 6
7657 trigger_spell_id
= 26370; break;
7658 case 10432: // Rank 7
7659 trigger_spell_id
= 26363; break;
7660 case 25469: // Rank 8
7661 trigger_spell_id
= 26371; break;
7662 case 25472: // Rank 9
7663 trigger_spell_id
= 26372; break;
7664 case 49280: // Rank 10
7665 trigger_spell_id
= 49278; break;
7666 case 49281: // Rank 11
7667 trigger_spell_id
= 49279; break;
7669 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
7673 // Lightning Shield (The Ten Storms set)
7674 else if (auraSpellInfo
->Id
== 23551)
7676 trigger_spell_id
= 23552;
7679 // Damage from Lightning Shield (The Ten Storms set)
7680 else if (auraSpellInfo
->Id
== 23552)
7681 trigger_spell_id
= 27635;
7682 // Mana Surge (The Earthfury set)
7683 else if (auraSpellInfo
->Id
== 23572)
7687 basepoints
[0] = procSpell
->manaCost
* 35 / 100;
7688 trigger_spell_id
= 23571;
7691 // Nature's Guardian
7692 else if (auraSpellInfo
->SpellIconID
== 2013)
7694 // Check health condition - should drop to less 30% (damage deal after this!)
7695 if (!(10*(int32(GetHealth() - damage
)) < int32(3 * GetMaxHealth())))
7698 if(pVictim
&& pVictim
->isAlive())
7699 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
7701 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
7702 trigger_spell_id
= 31616;
7707 case SPELLFAMILY_DEATHKNIGHT
:
7710 if (auraSpellInfo
->SpellIconID
== 1930)
7714 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7716 case SPELL_SCHOOL_NORMAL
:
7717 return false; // ignore
7718 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 50490; break;
7719 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 50362; break;
7720 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 50488; break;
7721 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 50485; break;
7722 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 50489; break;
7723 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 50486; break;
7729 else if (auraSpellInfo
->SpellIconID
== 85)
7731 if (GetTypeId() != TYPEID_PLAYER
|| getClass() != CLASS_DEATH_KNIGHT
||
7732 !((Player
*)this)->IsBaseRuneSlotsOnCooldown(RUNE_BLOOD
))
7735 // Improved Blood Presence
7736 else if (auraSpellInfo
->Id
== 63611)
7738 if (GetTypeId() != TYPEID_PLAYER
|| !((Player
*)this)->isHonorOrXPTarget(pVictim
) || !damage
)
7740 basepoints
[0] = triggerAmount
* damage
/ 100;
7741 trigger_spell_id
= 50475;
7749 // All ok. Check current trigger spell
7750 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
7753 // Not cast unknown spell
7754 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
7758 // not allow proc extra attack spell at extra attack
7759 if (m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
))
7762 // Custom basepoints/target for exist spell
7763 // dummy basepoints or other customs
7764 switch(trigger_spell_id
)
7766 // Cast positive spell on enemy target
7767 case 7099: // Curse of Mending
7768 case 39647: // Curse of Mending
7769 case 29494: // Temptation
7770 case 20233: // Improved Lay on Hands (cast on target)
7775 // Combo points add triggers (need add combopoint only for main target, and after possible combopoints reset)
7776 case 15250: // Rogue Setup
7778 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
7780 break; // continue normal case
7782 // Finish movies that add combo
7783 case 14189: // Seal Fate (Netherblade set)
7784 case 14157: // Ruthlessness
7786 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
7789 // Bloodthirst (($m/100)% of max health)
7792 basepoints
[0] = int32(GetMaxHealth() * triggerAmount
/ 100);
7795 // Shamanistic Rage triggered spell
7798 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7801 // Enlightenment (trigger only from mana cost spells)
7804 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
7811 // As the spell is proced from pet's attack - find owner
7812 Unit
* owner
= GetOwner();
7813 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
7816 // This spell doesn't stack, but refreshes duration. So we receive current bonuses to minus them later.
7818 if (Aura
* aur
= owner
->GetAura(48090, EFFECT_INDEX_0
))
7819 curBonus
= aur
->GetModifier()->m_amount
;
7820 int32 spellDamage
= owner
->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_MAGIC
) - curBonus
;
7821 if(spellDamage
<= 0)
7824 // percent stored in owner talent dummy
7825 AuraList
const& dummyAuras
= owner
->GetAurasByType(SPELL_AURA_DUMMY
);
7826 for (AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
7828 if ((*i
)->GetSpellProto()->SpellIconID
== 3220)
7830 basepoints
[0] = basepoints
[1] = int32(spellDamage
* (*i
)->GetModifier()->m_amount
/ 100);
7839 // Remove cooldown on Shield Slam
7840 if (GetTypeId() == TYPEID_PLAYER
)
7841 ((Player
*)this)->RemoveSpellCategoryCooldown(1209, true);
7847 // have rank dependent proc chance, ignore too often cases
7848 // PPM = 2.5 * (rank of talent),
7849 uint32 rank
= sSpellMgr
.GetSpellRank(auraSpellInfo
->Id
);
7850 // 5 rank -> 100% 4 rank -> 80% and etc from full rate
7851 if(!roll_chance_i(20*rank
))
7860 // For trigger from Blizzard need exist Improved Blizzard
7861 if (procSpell
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)))
7864 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7865 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7867 int32 script
= (*i
)->GetModifier()->m_miscvalue
;
7868 if(script
==836 || script
==988 || script
==989)
7882 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7885 // Need stun, fear or silence mechanic
7886 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_SILENCE_AND_STUN_AND_FEAR_MASK
))
7890 // Burning Determination
7895 // Need Interrupt or Silenced mechanic
7896 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_INTERRUPT_AND_SILENCE_MASK
))
7903 // Proc only from trap activation (from periodic proc another aura of this spell)
7904 if (!(procFlags
& PROC_FLAG_ON_TRAP_ACTIVATION
) || !roll_chance_i(triggerAmount
))
7908 // Freezing Fog (Rime triggered)
7911 // Howling Blast cooldown reset
7912 if (GetTypeId() == TYPEID_PLAYER
)
7913 ((Player
*)this)->RemoveSpellCategoryCooldown(1248, true);
7916 // Druid - Savage Defense
7919 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7924 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
7927 // try detect target manually if not set
7929 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
7932 if (!target
|| target
!=this && !target
->isAlive())
7935 if (basepoints
[EFFECT_INDEX_0
] || basepoints
[EFFECT_INDEX_1
] || basepoints
[EFFECT_INDEX_2
])
7936 CastCustomSpell(target
,trigger_spell_id
,
7937 basepoints
[EFFECT_INDEX_0
] ? &basepoints
[EFFECT_INDEX_0
] : NULL
,
7938 basepoints
[EFFECT_INDEX_1
] ? &basepoints
[EFFECT_INDEX_1
] : NULL
,
7939 basepoints
[EFFECT_INDEX_2
] ? &basepoints
[EFFECT_INDEX_2
] : NULL
,
7940 true, castItem
, triggeredByAura
);
7942 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
7944 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7945 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
7950 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
7952 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
7954 if(!pVictim
|| !pVictim
->isAlive())
7957 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7958 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7960 // Basepoints of trigger aura
7961 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7963 uint32 triggered_spell_id
= 0;
7967 case 836: // Improved Blizzard (Rank 1)
7969 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7971 triggered_spell_id
= 12484;
7974 case 988: // Improved Blizzard (Rank 2)
7976 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7978 triggered_spell_id
= 12485;
7981 case 989: // Improved Blizzard (Rank 3)
7983 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7985 triggered_spell_id
= 12486;
7988 case 4086: // Improved Mend Pet (Rank 1)
7989 case 4087: // Improved Mend Pet (Rank 2)
7991 if(!roll_chance_i(triggerAmount
))
7994 triggered_spell_id
= 24406;
7997 case 4533: // Dreamwalker Raiment 2 pieces bonus
8000 if (!roll_chance_i(50))
8003 switch (pVictim
->getPowerType())
8005 case POWER_MANA
: triggered_spell_id
= 28722; break;
8006 case POWER_RAGE
: triggered_spell_id
= 28723; break;
8007 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
8013 case 4537: // Dreamwalker Raiment 6 pieces bonus
8014 triggered_spell_id
= 28750; // Blessing of the Claw
8016 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
8017 triggered_spell_id
= 37445; // Mana Surge
8019 case 6953: // Warbringer
8020 RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK
,0,true);
8022 case 7010: // Revitalize (rank 1)
8023 case 7011: // Revitalize (rank 2)
8024 case 7012: // Revitalize (rank 3)
8026 if(!roll_chance_i(triggerAmount
))
8029 switch( pVictim
->getPowerType() )
8031 case POWER_MANA
: triggered_spell_id
= 48542; break;
8032 case POWER_RAGE
: triggered_spell_id
= 48541; break;
8033 case POWER_ENERGY
: triggered_spell_id
= 48540; break;
8034 case POWER_RUNIC_POWER
: triggered_spell_id
= 48543; break;
8035 default: return false;
8042 if(!triggered_spell_id
)
8045 // standard non-dummy case
8046 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
8050 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
8054 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
8057 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
8059 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
8060 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
8065 void Unit::setPowerType(Powers new_powertype
)
8067 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
8069 if(GetTypeId() == TYPEID_PLAYER
)
8071 if(((Player
*)this)->GetGroup())
8072 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
8074 else if(((Creature
*)this)->isPet())
8076 Pet
*pet
= ((Pet
*)this);
8077 if(pet
->isControlled())
8079 Unit
*owner
= GetOwner();
8080 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
8081 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
8085 switch(new_powertype
)
8091 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
8092 SetPower( POWER_RAGE
,0);
8095 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
8096 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
8099 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
8101 case POWER_HAPPINESS
:
8102 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
8103 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
8108 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
8110 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
8113 static uint64 guid
= 0; // prevent repeating spam same faction problem
8115 if(GetGUID() != guid
)
8117 if(GetTypeId() == TYPEID_PLAYER
)
8118 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
8120 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
8127 bool Unit::IsHostileTo(Unit
const* unit
) const
8129 // always non-hostile to self
8133 // always non-hostile to GM in GM mode
8134 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
8137 // always hostile to enemy
8138 if(getVictim()==unit
|| unit
->getVictim()==this)
8141 // test pet/charm masters instead pers/charmeds
8142 Unit
const* testerOwner
= GetCharmerOrOwner();
8143 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
8145 // always hostile to owner's enemy
8146 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
8149 // always hostile to enemy owner
8150 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
8153 // always hostile to owner of owner's enemy
8154 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
8157 Unit
const* tester
= testerOwner
? testerOwner
: this;
8158 Unit
const* target
= targetOwner
? targetOwner
: unit
;
8160 // always non-hostile to target with common owner, or to owner/pet
8164 // special cases (Duel, etc)
8165 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
8167 Player
const* pTester
= (Player
const*)tester
;
8168 Player
const* pTarget
= (Player
const*)target
;
8171 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
8175 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
8179 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
8183 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
8187 // Green/Blue (can't attack)
8188 if(pTester
->GetTeam()==pTarget
->GetTeam())
8191 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
8192 return pTester
->IsPvP() && pTarget
->IsPvP();
8195 // faction base cases
8196 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8197 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8198 if(!tester_faction
|| !target_faction
)
8201 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8204 // PvC forced reaction and reputation case
8205 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8208 if(target_faction
->faction
)
8210 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8211 return *force
<= REP_HOSTILE
;
8213 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
8214 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8215 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8216 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8219 // CvP forced reaction and reputation case
8220 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8223 if(tester_faction
->faction
)
8225 if(ReputationRank
const* force
= ((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8226 return *force
<= REP_HOSTILE
;
8228 // apply reputation state
8229 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
8230 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
8231 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) <= REP_HOSTILE
;
8235 // common faction based case (CvC,PvC,CvP)
8236 return tester_faction
->IsHostileTo(*target_faction
);
8239 bool Unit::IsFriendlyTo(Unit
const* unit
) const
8241 // always friendly to self
8245 // always friendly to GM in GM mode
8246 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
8249 // always non-friendly to enemy
8250 if(getVictim()==unit
|| unit
->getVictim()==this)
8253 // test pet/charm masters instead pers/charmeds
8254 Unit
const* testerOwner
= GetCharmerOrOwner();
8255 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
8257 // always non-friendly to owner's enemy
8258 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
8261 // always non-friendly to enemy owner
8262 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
8265 // always non-friendly to owner of owner's enemy
8266 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
8269 Unit
const* tester
= testerOwner
? testerOwner
: this;
8270 Unit
const* target
= targetOwner
? targetOwner
: unit
;
8272 // always friendly to target with common owner, or to owner/pet
8276 // special cases (Duel)
8277 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
8279 Player
const* pTester
= (Player
const*)tester
;
8280 Player
const* pTarget
= (Player
const*)target
;
8283 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
8287 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
8291 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
8295 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
8299 // Green/Blue (non-attackable)
8300 if(pTester
->GetTeam()==pTarget
->GetTeam())
8303 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
8304 return !pTarget
->IsPvP();
8307 // faction base cases
8308 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8309 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8310 if(!tester_faction
|| !target_faction
)
8313 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8316 // PvC forced reaction and reputation case
8317 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8320 if(target_faction
->faction
)
8322 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8323 return *force
>= REP_FRIENDLY
;
8325 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
8326 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8327 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8328 return !(factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8331 // CvP forced reaction and reputation case
8332 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8335 if(tester_faction
->faction
)
8337 if(ReputationRank
const* force
=((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8338 return *force
>= REP_FRIENDLY
;
8340 // apply reputation state
8341 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
8342 if(raw_tester_faction
->reputationListID
>=0 )
8343 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) >= REP_FRIENDLY
;
8347 // common faction based case (CvC,PvC,CvP)
8348 return tester_faction
->IsFriendlyTo(*target_faction
);
8351 bool Unit::IsHostileToPlayers() const
8353 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8354 if(!my_faction
|| !my_faction
->faction
)
8357 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8358 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8361 return my_faction
->IsHostileToPlayers();
8364 bool Unit::IsNeutralToAll() const
8366 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8367 if(!my_faction
|| !my_faction
->faction
)
8370 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8371 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8374 return my_faction
->IsNeutralToAll();
8377 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
8379 if(!victim
|| victim
== this)
8382 // dead units can neither attack nor be attacked
8383 if(!isAlive() || !victim
->IsInWorld() || !victim
->isAlive())
8386 // player cannot attack in mount state
8387 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
8390 // nobody can attack GM in GM-mode
8391 if(victim
->GetTypeId()==TYPEID_PLAYER
)
8393 if(((Player
*)victim
)->isGameMaster())
8398 if(((Creature
*)victim
)->IsInEvadeMode())
8402 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
8403 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
8404 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
8406 // in fighting already
8409 if (m_attacking
== victim
)
8411 // switch to melee attack from ranged/magic
8412 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
8414 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8415 SendMeleeAttackStart(victim
);
8421 // remove old target data
8427 // set position before any AI calls/assistance
8428 if(GetTypeId()==TYPEID_UNIT
)
8429 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
8433 SetTargetGUID(victim
->GetGUID());
8436 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8438 m_attacking
= victim
;
8439 m_attacking
->_addAttacker(this);
8441 if (GetTypeId() == TYPEID_UNIT
)
8443 ((Creature
*)this)->SendAIReaction(AI_REACTION_HOSTILE
);
8444 ((Creature
*)this)->CallAssistance();
8447 // delay offhand weapon attack to next attack time
8448 if(haveOffhandWeapon())
8449 resetAttackTimer(OFF_ATTACK
);
8452 SendMeleeAttackStart(victim
);
8457 bool Unit::AttackStop(bool targetSwitch
/*=false*/)
8462 Unit
* victim
= m_attacking
;
8464 m_attacking
->_removeAttacker(this);
8470 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
8472 InterruptSpell(CURRENT_MELEE_SPELL
);
8474 // reset only at real combat stop
8475 if(!targetSwitch
&& GetTypeId()==TYPEID_UNIT
)
8477 ((Creature
*)this)->SetNoCallAssistance(false);
8479 if (((Creature
*)this)->HasSearchedAssistance())
8481 ((Creature
*)this)->SetNoSearchAssistance(false);
8482 UpdateSpeed(MOVE_RUN
, false);
8486 SendMeleeAttackStop(victim
);
8491 void Unit::CombatStop(bool includingCast
)
8493 if (includingCast
&& IsNonMeleeSpellCasted(false))
8494 InterruptNonMeleeSpells(false);
8497 RemoveAllAttackers();
8498 if( GetTypeId()==TYPEID_PLAYER
)
8499 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
8503 struct CombatStopWithPetsHelper
8505 explicit CombatStopWithPetsHelper(bool _includingCast
) : includingCast(_includingCast
) {}
8506 void operator()(Unit
* unit
) const { unit
->CombatStop(includingCast
); }
8510 void Unit::CombatStopWithPets(bool includingCast
)
8512 CombatStop(includingCast
);
8513 CallForAllControlledUnits(CombatStopWithPetsHelper(includingCast
),false,true,true);
8516 struct IsAttackingPlayerHelper
8518 explicit IsAttackingPlayerHelper() {}
8519 bool operator()(Unit
* unit
) const { return unit
->isAttackingPlayer(); }
8522 bool Unit::isAttackingPlayer() const
8524 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
8527 return CheckAllControlledUnits(IsAttackingPlayerHelper(),true,true,true);
8530 void Unit::RemoveAllAttackers()
8532 while (!m_attackers
.empty())
8534 AttackerSet::iterator iter
= m_attackers
.begin();
8535 if(!(*iter
)->AttackStop())
8537 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
8538 m_attackers
.erase(iter
);
8543 bool Unit::HasAuraStateForCaster(AuraState flag
, uint64 caster
) const
8545 if(!HasAuraState(flag
))
8548 // single per-caster aura state
8549 if(flag
== AURA_STATE_CONFLAGRATE
)
8551 Unit::AuraList
const& dotList
= GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
8552 for(Unit::AuraList::const_iterator i
= dotList
.begin(); i
!= dotList
.end(); ++i
)
8554 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
8555 (*i
)->GetCasterGUID() == caster
&&
8557 (((*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000004)) ||
8559 ((*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x00000002)))
8571 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
8575 if (!HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)))
8577 SetFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8578 if(GetTypeId() == TYPEID_PLAYER
)
8580 const PlayerSpellMap
& sp_list
= ((Player
*)this)->GetSpellMap();
8581 for (PlayerSpellMap::const_iterator itr
= sp_list
.begin(); itr
!= sp_list
.end(); ++itr
)
8583 if(itr
->second
.state
== PLAYERSPELL_REMOVED
) continue;
8584 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
8585 if (!spellInfo
|| !IsPassiveSpell(itr
->first
)) continue;
8586 if (spellInfo
->CasterAuraState
== flag
)
8587 CastSpell(this, itr
->first
, true, NULL
);
8594 if (HasFlag(UNIT_FIELD_AURASTATE
,1<<(flag
-1)))
8596 RemoveFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8598 if (flag
!= AURA_STATE_ENRAGE
) // enrage aura state triggering continues auras
8600 Unit::AuraMap
& tAuras
= GetAuras();
8601 for (Unit::AuraMap::iterator itr
= tAuras
.begin(); itr
!= tAuras
.end();)
8603 SpellEntry
const* spellProto
= (*itr
).second
->GetSpellProto();
8604 if (spellProto
->CasterAuraState
== flag
)
8614 Unit
*Unit::GetOwner() const
8616 if(uint64 ownerid
= GetOwnerGUID())
8617 return ObjectAccessor::GetUnit(*this, ownerid
);
8621 Unit
*Unit::GetCharmer() const
8623 if(uint64 charmerid
= GetCharmerGUID())
8624 return ObjectAccessor::GetUnit(*this, charmerid
);
8628 bool Unit::IsCharmerOrOwnerPlayerOrPlayerItself() const
8630 if (GetTypeId()==TYPEID_PLAYER
)
8633 return IS_PLAYER_GUID(GetCharmerOrOwnerGUID());
8636 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
8638 uint64 guid
= GetCharmerOrOwnerGUID();
8639 if(IS_PLAYER_GUID(guid
))
8640 return ObjectAccessor::FindPlayer(guid
);
8642 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
8645 Pet
* Unit::GetPet() const
8647 if(uint64 pet_guid
= GetPetGUID())
8649 if(Pet
* pet
= GetMap()->GetPet(pet_guid
))
8652 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
8653 const_cast<Unit
*>(this)->SetPet(0);
8659 Unit
* Unit::GetCharm() const
8661 if (uint64 charm_guid
= GetCharmGUID())
8663 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
8666 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
8667 const_cast<Unit
*>(this)->SetCharm(NULL
);
8673 void Unit::Uncharm()
8675 if (Unit
* charm
= GetCharm())
8677 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM
);
8678 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS
);
8682 float Unit::GetCombatDistance( const Unit
* target
) const
8684 float radius
= target
->GetFloatValue(UNIT_FIELD_COMBATREACH
) + GetFloatValue(UNIT_FIELD_COMBATREACH
);
8685 float dx
= GetPositionX() - target
->GetPositionX();
8686 float dy
= GetPositionY() - target
->GetPositionY();
8687 float dz
= GetPositionZ() - target
->GetPositionZ();
8688 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - radius
;
8689 return ( dist
> 0 ? dist
: 0);
8692 void Unit::SetPet(Pet
* pet
)
8694 SetPetGUID(pet
? pet
->GetGUID() : 0);
8696 if(pet
&& GetTypeId() == TYPEID_PLAYER
)
8697 ((Player
*)this)->SendPetGUIDs();
8700 void Unit::SetCharm(Unit
* pet
)
8702 SetCharmGUID(pet
? pet
->GetGUID() : 0);
8705 void Unit::AddGuardian( Pet
* pet
)
8707 m_guardianPets
.insert(pet
->GetGUID());
8710 void Unit::RemoveGuardian( Pet
* pet
)
8712 m_guardianPets
.erase(pet
->GetGUID());
8715 void Unit::RemoveGuardians()
8717 while(!m_guardianPets
.empty())
8719 uint64 guid
= *m_guardianPets
.begin();
8720 if(Pet
* pet
= GetMap()->GetPet(guid
))
8721 pet
->Remove(PET_SAVE_AS_DELETED
);
8723 m_guardianPets
.erase(guid
);
8727 Pet
* Unit::FindGuardianWithEntry(uint32 entry
)
8729 // pet guid middle part is entry (and creature also)
8730 // and in guardian list must be guardians with same entry _always_
8731 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
8732 if(Pet
* pet
= GetMap()->GetPet(*itr
))
8733 if (pet
->GetEntry() == entry
)
8739 Unit
* Unit::_GetTotem(TotemSlot slot
) const
8741 return GetTotem(slot
);
8744 Totem
* Unit::GetTotem(TotemSlot slot
) const
8746 if(slot
>= MAX_TOTEM_SLOT
|| !IsInWorld())
8749 Creature
*totem
= GetMap()->GetCreature(m_TotemSlot
[slot
]);
8750 return totem
&& totem
->isTotem() ? (Totem
*)totem
: NULL
;
8753 bool Unit::IsAllTotemSlotsUsed() const
8755 for (int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8756 if (!m_TotemSlot
[i
])
8761 void Unit::_AddTotem(TotemSlot slot
, Totem
* totem
)
8763 m_TotemSlot
[slot
] = totem
->GetGUID();
8766 void Unit::_RemoveTotem(Totem
* totem
)
8768 for(int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8770 if (m_TotemSlot
[i
] == totem
->GetGUID())
8780 void Unit::UnsummonAllTotems()
8782 for (int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8783 if (Totem
* totem
= GetTotem(TotemSlot(i
)))
8787 int32
Unit::DealHeal(Unit
*pVictim
, uint32 addhealth
, SpellEntry
const *spellProto
, bool critical
)
8789 int32 gain
= pVictim
->ModifyHealth(int32(addhealth
));
8793 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8796 if (unit
->GetTypeId()==TYPEID_PLAYER
)
8798 // overheal = addhealth - gain
8799 unit
->SendHealSpellLog(pVictim
, spellProto
->Id
, addhealth
, addhealth
- gain
, critical
);
8801 if (BattleGround
*bg
= ((Player
*)unit
)->GetBattleGround())
8802 bg
->UpdatePlayerScore((Player
*)unit
, SCORE_HEALING_DONE
, gain
);
8804 // use the actual gain, as the overheal shall not be counted, skip gain 0 (it ignored anyway in to criteria)
8806 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE
, gain
, 0, pVictim
);
8808 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED
, addhealth
);
8811 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
8813 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED
, gain
);
8814 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED
, addhealth
);
8820 Unit
* Unit::SelectMagnetTarget(Unit
*victim
, SpellEntry
const *spellInfo
)
8826 if(spellInfo
&& (spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
|| spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
))
8828 Unit::AuraList
const& magnetAuras
= victim
->GetAurasByType(SPELL_AURA_SPELL_MAGNET
);
8829 for(Unit::AuraList::const_iterator itr
= magnetAuras
.begin(); itr
!= magnetAuras
.end(); ++itr
)
8830 if(Unit
* magnet
= (*itr
)->GetCaster())
8831 if(magnet
->IsWithinLOSInMap(this) && magnet
->isAlive())
8834 // Melee && ranged case
8837 AuraList
const& hitTriggerAuras
= victim
->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER
);
8838 for(AuraList::const_iterator i
= hitTriggerAuras
.begin(); i
!= hitTriggerAuras
.end(); ++i
)
8839 if(Unit
* magnet
= (*i
)->GetCaster())
8840 if(magnet
->isAlive() && magnet
->IsWithinLOSInMap(this))
8841 if(roll_chance_i((*i
)->GetModifier()->m_amount
))
8848 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, uint32 OverHeal
, bool critical
)
8851 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
8852 data
<< pVictim
->GetPackGUID();
8853 data
<< GetPackGUID();
8854 data
<< uint32(SpellID
);
8855 data
<< uint32(Damage
);
8856 data
<< uint32(OverHeal
);
8857 data
<< uint8(critical
? 1 : 0);
8858 data
<< uint8(0); // unused in client?
8859 SendMessageToSet(&data
, true);
8862 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8864 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
8865 data
<< pVictim
->GetPackGUID();
8866 data
<< GetPackGUID();
8867 data
<< uint32(SpellID
);
8868 data
<< uint32(powertype
);
8869 data
<< uint32(Damage
);
8870 SendMessageToSet(&data
, true);
8873 void Unit::EnergizeBySpell(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8875 SendEnergizeSpellLog(pVictim
, SpellID
, Damage
, powertype
);
8876 // needs to be called after sending spell log
8877 pVictim
->ModifyPower(powertype
, Damage
);
8880 int32
Unit::SpellBonusWithCoeffs(SpellEntry
const *spellProto
, int32 total
, int32 benefit
, int32 ap_benefit
, DamageEffectType damagetype
, bool donePart
, float defCoeffMod
)
8882 // Distribute Damage over multiple effects, reduce by AoE
8885 // Not apply this to creature casted spells
8886 if (GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
8888 // Check for table values
8889 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
8891 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
8893 // apply ap bonus at done part calculation only (it flat total mod so common with taken)
8894 if (donePart
&& bonus
->ap_bonus
)
8895 total
+= int32(bonus
->ap_bonus
* (GetTotalAttackPowerValue(BASE_ATTACK
) + ap_benefit
));
8897 // Default calculation
8899 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
) * defCoeffMod
;
8903 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
8905 // Spellmod SpellDamage
8906 if(Player
* modOwner
= GetSpellModOwner())
8909 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
, coeff
);
8913 total
+= int32(benefit
* coeff
* LvlPenalty
);
8920 * Calculates caster part of spell damage bonuses,
8921 * also includes different bonuses dependent from target auras
8923 uint32
Unit::SpellDamageBonusDone(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
8925 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
8928 // For totems get damage bonus from owner (statue isn't totem in fact)
8929 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8931 if(Unit
* owner
= GetOwner())
8932 return owner
->SpellDamageBonusDone(pVictim
, spellProto
, pdamage
, damagetype
);
8935 float DoneTotalMod
= 1.0f
;
8936 int32 DoneTotal
= 0;
8939 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
8940 DoneTotalMod
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
8942 if (!(spellProto
->AttributesEx6
& SPELL_ATTR_EX6_NO_DMG_PERCENT_MODS
))
8944 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
8945 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
8947 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
8948 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
8949 // -1 == any item class (not wand then)
8950 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
8951 // 0 == any inventory type (not wand then)
8953 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8958 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8959 // Add flat bonus from spell damage versus
8960 DoneTotal
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
8961 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
8962 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
8963 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8964 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8966 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
8967 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
8969 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8970 DoneTotalMod
+= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8973 // done scripted mod (take it from owner)
8974 Unit
*owner
= GetOwner();
8975 if (!owner
) owner
= this;
8976 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8977 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
8979 if (!(*i
)->isAffectedOnSpell(spellProto
))
8981 switch((*i
)->GetModifier()->m_miscvalue
)
8983 case 4920: // Molten Fury
8985 case 6917: // Death's Embrace
8989 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8990 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8997 // effect 1 m_amount
8998 int32 maxPercent
= (*i
)->GetModifier()->m_amount
;
8999 // effect 0 m_amount
9000 int32 stepPercent
= CalculateSpellDamage(this, (*i
)->GetSpellProto(), EFFECT_INDEX_0
);
9001 // count affliction effects and calc additional damage in percentage
9002 int32 modPercent
= 0;
9003 AuraMap
const& victimAuras
= pVictim
->GetAuras();
9004 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
9006 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
9007 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_WARLOCK
|| !(m_spell
->SpellFamilyFlags
& UI64LIT(0x0004071B8044C402)))
9009 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
9010 if (modPercent
>= maxPercent
)
9012 modPercent
= maxPercent
;
9016 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
9019 case 6916: // Death's Embrace
9022 if (HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
))
9023 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
9025 case 5481: // Starfire Bonus
9027 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000200002)))
9028 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9031 case 4418: // Increased Shock Damage
9032 case 4554: // Increased Lightning Damage
9033 case 4555: // Improved Moonfire
9034 case 5142: // Increased Lightning Damage
9035 case 5147: // Improved Consecration / Libram of Resurgence
9036 case 5148: // Idol of the Shooting Star
9037 case 6008: // Increased Lightning Damage
9038 case 8627: // Totem of Hex
9040 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
9048 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
9050 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9051 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
9053 else // Tundra Stalker
9055 // Frost Fever (target debuff)
9056 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
9057 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9062 case 7293: // Rage of Rivendare
9064 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
9065 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9071 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000000000008000), 0, GetGUID()))
9072 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9082 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
9083 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9089 // Custom scripted damage
9090 switch(spellProto
->SpellFamilyName
)
9092 case SPELLFAMILY_MAGE
:
9095 if (spellProto
->SpellIconID
== 186)
9097 if (pVictim
->isFrozen())
9099 float multiplier
= 3.0f
;
9101 // if target have higher level
9102 if (pVictim
->getLevel() > getLevel())
9103 // Glyph of Ice Lance
9104 if (Aura
* glyph
= GetDummyAura(56377))
9105 multiplier
= glyph
->GetModifier()->m_amount
;
9107 DoneTotalMod
*= multiplier
;
9110 // Torment the weak affected (Arcane Barrage, Arcane Blast, Frostfire Bolt, Arcane Missiles, Fireball)
9111 if ((spellProto
->SpellFamilyFlags
& UI64LIT(0x0000900020200021)) &&
9112 (pVictim
->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED
) || pVictim
->HasAuraType(SPELL_AURA_HASTE_ALL
)))
9114 //Search for Torment the weak dummy aura
9115 Unit::AuraList
const& ttw
= GetAurasByType(SPELL_AURA_DUMMY
);
9116 for(Unit::AuraList::const_iterator i
= ttw
.begin(); i
!= ttw
.end(); ++i
)
9118 if ((*i
)->GetSpellProto()->SpellIconID
== 3263)
9120 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9127 case SPELLFAMILY_WARLOCK
:
9130 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
9132 if (pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth() <= 25)
9137 case SPELLFAMILY_PRIEST
:
9140 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x00000080))
9143 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x00100000), NULL
))
9144 if (Aura
*aur
= GetAura(55692, EFFECT_INDEX_0
))
9145 DoneTotalMod
*= (aur
->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9149 case SPELLFAMILY_DRUID
:
9151 // Improved Insect Swarm (Wrath part)
9152 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
9154 // if Insect Swarm on target
9155 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x000000000200000), 0, GetGUID()))
9157 Unit::AuraList
const& improvedSwarm
= GetAurasByType(SPELL_AURA_DUMMY
);
9158 for(Unit::AuraList::const_iterator iter
= improvedSwarm
.begin(); iter
!= improvedSwarm
.end(); ++iter
)
9160 if ((*iter
)->GetSpellProto()->SpellIconID
== 1771)
9162 DoneTotalMod
*= ((*iter
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9170 case SPELLFAMILY_DEATHKNIGHT
:
9172 // Icy Touch and Howling Blast
9173 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000200000002))
9177 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
9178 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
9180 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
9189 // search for Glacier Rot dummy aura
9190 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9191 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
9193 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
9195 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9206 // Done fixed damage bonus auras
9207 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonusDone(GetSpellSchoolMask(spellProto
));
9209 // Pets just add their bonus damage to their spell damage
9210 // note that their spell damage is just gain of their own auras
9211 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9212 DoneAdvertisedBenefit
+= ((Pet
*)this)->GetBonusDamage();
9214 // apply ap bonus and benefit affected by spell power implicit coeffs and spell level penalties
9215 DoneTotal
= SpellBonusWithCoeffs(spellProto
, DoneTotal
, DoneAdvertisedBenefit
, 0, damagetype
, true);
9217 float tmpDamage
= (int32(pdamage
) + DoneTotal
* int32(stack
)) * DoneTotalMod
;
9218 // apply spellmod to Done damage (flat and pct)
9219 if(Player
* modOwner
= GetSpellModOwner())
9220 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
9222 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9226 * Calculates target part of spell damage bonuses,
9227 * will be called on each tick for periodic damage over time auras
9229 uint32
Unit::SpellDamageBonusTaken(Unit
*pCaster
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
9231 if(!spellProto
|| !pCaster
|| damagetype
==DIRECT_DAMAGE
)
9234 // Taken total percent damage auras
9235 float TakenTotalMod
= 1.0f
;
9236 int32 TakenTotal
= 0;
9239 AuraList
const& mModDamagePercentTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
9240 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
9242 if ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
))
9243 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9246 // .. taken pct: dummy auras
9247 if (GetTypeId() == TYPEID_PLAYER
)
9250 if (Aura
*dummy
= GetDummyAura(45182))
9252 float mod
= -((Player
*)this)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
9253 if (mod
< float(dummy
->GetModifier()->m_amount
))
9254 mod
= float(dummy
->GetModifier()->m_amount
);
9255 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
9259 // From caster spells
9260 AuraList
const& mOwnerTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_FROM_CASTER
);
9261 for(AuraList::const_iterator i
= mOwnerTaken
.begin(); i
!= mOwnerTaken
.end(); ++i
)
9263 if ((*i
)->GetCasterGUID() == pCaster
->GetGUID() && (*i
)->isAffectedOnSpell(spellProto
))
9264 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9267 // Mod damage from spell mechanic
9268 TakenTotalMod
*= GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,GetAllSpellMechanicMask(spellProto
));
9270 // Mod damage taken from AoE spells
9271 if(IsAreaOfEffectSpell(spellProto
))
9273 AuraList
const& avoidAuras
= GetAurasByType(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
9274 for(AuraList::const_iterator itr
= avoidAuras
.begin(); itr
!= avoidAuras
.end(); ++itr
)
9275 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9278 // Taken fixed damage bonus auras
9279 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusTaken(GetSpellSchoolMask(spellProto
));
9281 // apply benefit affected by spell power implicit coeffs and spell level penalties
9282 TakenTotal
= SpellBonusWithCoeffs(spellProto
, TakenTotal
, TakenAdvertisedBenefit
, 0, damagetype
, false);
9284 float tmpDamage
= (int32(pdamage
) + TakenTotal
* int32(stack
)) * TakenTotalMod
;
9286 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9289 int32
Unit::SpellBaseDamageBonusDone(SpellSchoolMask schoolMask
)
9291 int32 DoneAdvertisedBenefit
= 0;
9294 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9295 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
9297 if (((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
9298 (*i
)->GetSpellProto()->EquippedItemClass
== -1 && // -1 == any item class (not wand then)
9299 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0) // 0 == any inventory type (not wand then)
9300 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9303 if (GetTypeId() == TYPEID_PLAYER
)
9306 DoneAdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9308 // Damage bonus from stats
9309 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
9310 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
9312 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9314 // stat used stored in miscValueB for this aura
9315 Stats usedStat
= Stats((*i
)->GetMiscBValue());
9316 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9319 // ... and attack power
9320 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
9321 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
9323 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9324 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9328 return DoneAdvertisedBenefit
;
9331 int32
Unit::SpellBaseDamageBonusTaken(SpellSchoolMask schoolMask
)
9333 int32 TakenAdvertisedBenefit
= 0;
9336 AuraList
const& mDamageTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
9337 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9339 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9340 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9343 return TakenAdvertisedBenefit
;
9346 bool Unit::IsSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
9348 // not critting spell
9349 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
9352 float crit_chance
= 0.0f
;
9353 switch(spellProto
->DmgClass
)
9355 case SPELL_DAMAGE_CLASS_NONE
:
9357 case SPELL_DAMAGE_CLASS_MAGIC
:
9359 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
9361 // For other schools
9362 else if (GetTypeId() == TYPEID_PLAYER
)
9363 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
9366 crit_chance
= float(m_baseSpellCritChance
);
9367 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9372 if (!IsPositiveSpell(spellProto
->Id
))
9374 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
9375 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
9376 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
9377 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
9378 // Modify by player victim resilience
9379 crit_chance
-= pVictim
->GetSpellCritChanceReduction();
9382 // scripted (increase crit chance ... against ... target by x%)
9383 // scripted (Increases the critical effect chance of your .... by x% on targets ...)
9384 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9385 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9387 if (!((*i
)->isAffectedOnSpell(spellProto
)))
9389 switch((*i
)->GetModifier()->m_miscvalue
)
9391 case 849: if (pVictim
->isFrozen()) crit_chance
+= 17.0f
; break; //Shatter Rank 1
9392 case 910: if (pVictim
->isFrozen()) crit_chance
+= 34.0f
; break; //Shatter Rank 2
9393 case 911: if (pVictim
->isFrozen()) crit_chance
+= 50.0f
; break; //Shatter Rank 3
9394 case 7917: // Glyph of Shadowburn
9395 if (pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9396 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9398 case 7997: // Renewed Hope
9400 if (pVictim
->HasAura(6788))
9401 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9407 // Custom crit by class
9408 switch(spellProto
->SpellFamilyName
)
9410 case SPELLFAMILY_PRIEST
:
9412 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000800))
9414 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth()/2)
9416 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9417 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9419 // Improved Flash Heal
9420 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_PRIEST
&&
9421 (*i
)->GetSpellProto()->SpellIconID
== 2542)
9423 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9429 case SPELLFAMILY_DRUID
:
9430 // Improved Insect Swarm (Starfire part)
9431 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
9433 // search for Moonfire on target
9434 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x000000000000002), 0, GetGUID()))
9436 Unit::AuraList
const& improvedSwarm
= GetAurasByType(SPELL_AURA_DUMMY
);
9437 for(Unit::AuraList::const_iterator iter
= improvedSwarm
.begin(); iter
!= improvedSwarm
.end(); ++iter
)
9439 if ((*iter
)->GetSpellProto()->SpellIconID
== 1771)
9441 crit_chance
+= (*iter
)->GetModifier()->m_amount
;
9448 case SPELLFAMILY_PALADIN
:
9450 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000040000000))
9452 Aura
*aura
= pVictim
->GetDummyAura(58597);
9453 if (aura
&& aura
->GetCasterGUID() == GetGUID())
9454 crit_chance
+=aura
->GetModifier()->m_amount
;
9457 else if (spellProto
->Category
== 19)
9459 if (pVictim
->GetCreatureTypeMask() & CREATURE_TYPEMASK_DEMON_OR_UNDEAD
)
9463 case SPELLFAMILY_SHAMAN
:
9465 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000100000000000))
9468 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000000010000000), 0, GetGUID()))
9476 case SPELL_DAMAGE_CLASS_MELEE
:
9477 case SPELL_DAMAGE_CLASS_RANGED
:
9480 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
9482 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9489 // only players use intelligence for critical chance computations
9490 if(Player
* modOwner
= GetSpellModOwner())
9491 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
9493 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
9494 if (roll_chance_f(crit_chance
))
9499 uint32
Unit::SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9501 // Calculate critical bonus
9503 switch(spellProto
->DmgClass
)
9505 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9506 case SPELL_DAMAGE_CLASS_RANGED
:
9507 crit_bonus
= damage
;
9510 crit_bonus
= damage
/ 2; // for spells is 50%
9514 // adds additional damage to crit_bonus (from talents)
9515 if(Player
* modOwner
= GetSpellModOwner())
9516 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
9519 return damage
+= crit_bonus
;
9521 int32 critPctDamageMod
= 0;
9522 if(spellProto
->DmgClass
>= SPELL_DAMAGE_CLASS_MELEE
)
9524 if(GetWeaponAttackType(spellProto
) == RANGED_ATTACK
)
9525 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
9527 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
9530 critPctDamageMod
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_DAMAGE
,GetSpellSchoolMask(spellProto
));
9532 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, GetSpellSchoolMask(spellProto
));
9534 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9535 critPctDamageMod
+= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
);
9537 if(critPctDamageMod
!=0)
9538 crit_bonus
= int32(crit_bonus
* float((100.0f
+ critPctDamageMod
)/100.0f
));
9541 damage
+= crit_bonus
;
9546 uint32
Unit::SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9548 // Calculate critical bonus
9550 switch(spellProto
->DmgClass
)
9552 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9553 case SPELL_DAMAGE_CLASS_RANGED
:
9554 // TODO: write here full calculation for melee/ranged spells
9555 crit_bonus
= damage
;
9558 crit_bonus
= damage
/ 2; // for spells is 50%
9564 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9565 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
9569 damage
+= crit_bonus
;
9571 damage
= int32(damage
* GetTotalAuraMultiplier(SPELL_AURA_MOD_CRITICAL_HEALING_AMOUNT
));
9577 * Calculates caster part of healing spell bonuses,
9578 * also includes different bonuses dependent from target auras
9580 uint32
Unit::SpellHealingBonusDone(Unit
*pVictim
, SpellEntry
const *spellProto
, int32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9582 // For totems get healing bonus from owner (statue isn't totem in fact)
9583 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
9584 if(Unit
* owner
= GetOwner())
9585 return owner
->SpellHealingBonusDone(pVictim
, spellProto
, healamount
, damagetype
, stack
);
9587 // No heal amount for this class spells
9588 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9589 return healamount
< 0 ? 0 : healamount
;
9592 // Done total percent damage auras
9593 float DoneTotalMod
= 1.0f
;
9594 int32 DoneTotal
= 0;
9596 // Healing done percent
9597 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
9598 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
9599 DoneTotalMod
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
9601 // done scripted mod (take it from owner)
9602 Unit
*owner
= GetOwner();
9603 if (!owner
) owner
= this;
9604 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9605 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9607 if (!(*i
)->isAffectedOnSpell(spellProto
))
9609 switch((*i
)->GetModifier()->m_miscvalue
)
9611 case 4415: // Increased Rejuvenation Healing
9613 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
9614 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
9616 case 7997: // Renewed Hope
9618 if (pVictim
->HasAura(6788))
9619 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9621 case 21: // Test of Faith
9624 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
9625 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9627 case 7798: // Glyph of Regrowth
9629 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_HEAL
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000000040)))
9630 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9633 case 8477: // Nourish Heal Boost
9635 int32 stepPercent
= (*i
)->GetModifier()->m_amount
;
9637 int ownHotCount
= 0; // counted HoT types amount, not stacks
9639 Unit::AuraList
const& RejorRegr
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_HEAL
);
9640 for(Unit::AuraList::const_iterator i
= RejorRegr
.begin(); i
!= RejorRegr
.end(); ++i
)
9641 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_DRUID
&&
9642 (*i
)->GetCasterGUID() == GetGUID())
9646 DoneTotalMod
*= (stepPercent
* ownHotCount
+ 100.0f
) / 100.0f
;
9649 case 7871: // Glyph of Lesser Healing Wave
9651 if (pVictim
->GetAura(SPELL_AURA_DUMMY
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000040000000000), 0, GetGUID()))
9652 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9660 // Nourish 20% of heal increase if target is affected by Druids HOTs
9661 if (spellProto
->SpellFamilyName
== SPELLFAMILY_DRUID
&& (spellProto
->SpellFamilyFlags
& UI64LIT(0x0200000000000000)))
9663 int ownHotCount
= 0; // counted HoT types amount, not stacks
9664 Unit::AuraList
const& RejorRegr
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_HEAL
);
9665 for(Unit::AuraList::const_iterator i
= RejorRegr
.begin(); i
!= RejorRegr
.end(); ++i
)
9666 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_DRUID
&&
9667 (*i
)->GetCasterGUID() == GetGUID())
9672 DoneTotalMod
*= 1.2f
; // base bonus at HoTs
9674 if (Aura
* glyph
= GetAura(62971, EFFECT_INDEX_0
))// Glyph of Nourish
9675 DoneTotalMod
*= (glyph
->GetModifier()->m_amount
* ownHotCount
+ 100.0f
) / 100.0f
;
9679 // Done fixed damage bonus auras
9680 int32 DoneAdvertisedBenefit
= SpellBaseHealingBonusDone(GetSpellSchoolMask(spellProto
));
9682 // apply ap bonus and benefit affected by spell power implicit coeffs and spell level penalties
9683 DoneTotal
= SpellBonusWithCoeffs(spellProto
, DoneTotal
, DoneAdvertisedBenefit
, 0, damagetype
, true, 1.88f
);
9685 // use float as more appropriate for negative values and percent applying
9686 float heal
= (healamount
+ DoneTotal
* int32(stack
))*DoneTotalMod
;
9687 // apply spellmod to Done amount
9688 if(Player
* modOwner
= GetSpellModOwner())
9689 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
9691 return heal
< 0 ? 0 : uint32(heal
);
9695 * Calculates target part of healing spell bonuses,
9696 * will be called on each tick for periodic damage over time auras
9698 uint32
Unit::SpellHealingBonusTaken(Unit
*pCaster
, SpellEntry
const *spellProto
, int32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9700 float TakenTotalMod
= 1.0f
;
9702 // Healing taken percent
9703 float minval
= float(GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
));
9705 TakenTotalMod
*= (100.0f
+ minval
) / 100.0f
;
9707 float maxval
= float(GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
));
9709 TakenTotalMod
*= (100.0f
+ maxval
) / 100.0f
;
9711 // No heal amount for this class spells
9712 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9714 healamount
= int32(healamount
* TakenTotalMod
);
9715 return healamount
< 0 ? 0 : healamount
;
9719 // Done total percent damage auras
9720 int32 TakenTotal
= 0;
9722 // Taken fixed damage bonus auras
9723 int32 TakenAdvertisedBenefit
= SpellBaseHealingBonusTaken(GetSpellSchoolMask(spellProto
));
9725 // apply benefit affected by spell power implicit coeffs and spell level penalties
9726 TakenTotal
= SpellBonusWithCoeffs(spellProto
, TakenTotal
, TakenAdvertisedBenefit
, 0, damagetype
, false, 1.88f
);
9728 AuraList
const& mHealingGet
= GetAurasByType(SPELL_AURA_MOD_HEALING_RECEIVED
);
9729 for(AuraList::const_iterator i
= mHealingGet
.begin(); i
!= mHealingGet
.end(); ++i
)
9730 if ((*i
)->isAffectedOnSpell(spellProto
))
9731 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9733 // use float as more appropriate for negative values and percent applying
9734 float heal
= (healamount
+ TakenTotal
* int32(stack
)) * TakenTotalMod
;
9736 return heal
< 0 ? 0 : uint32(heal
);
9739 int32
Unit::SpellBaseHealingBonusDone(SpellSchoolMask schoolMask
)
9741 int32 AdvertisedBenefit
= 0;
9743 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
9744 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
9745 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9746 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9748 // Healing bonus of spirit, intellect and strength
9749 if (GetTypeId() == TYPEID_PLAYER
)
9752 AdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9754 // Healing bonus from stats
9755 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
9756 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
9758 // stat used dependent from misc value (stat index)
9759 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
9760 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9763 // ... and attack power
9764 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
9765 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
9766 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9767 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9769 return AdvertisedBenefit
;
9772 int32
Unit::SpellBaseHealingBonusTaken(SpellSchoolMask schoolMask
)
9774 int32 AdvertisedBenefit
= 0;
9775 AuraList
const& mDamageTaken
= GetAurasByType(SPELL_AURA_MOD_HEALING
);
9776 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9777 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9778 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9780 return AdvertisedBenefit
;
9783 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
)
9785 //If m_immuneToSchool type contain this school type, IMMUNE damage.
9786 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9787 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9788 if (itr
->type
& shoolMask
)
9791 //If m_immuneToDamage type contain magic, IMMUNE damage.
9792 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
9793 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
9794 if (itr
->type
& shoolMask
)
9800 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
)
9805 //TODO add spellEffect immunity checks!, player with flag in bg is imune to imunity buffs from other friendly players!
9806 //SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_EFFECT];
9808 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
9809 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
9810 if (itr
->type
== spellInfo
->Dispel
)
9813 if (!(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
) && // unaffected by school immunity
9814 !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)) // can remove immune (by dispell or immune it)
9816 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9817 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9818 if (!(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
9819 (itr
->type
& GetSpellSchoolMask(spellInfo
)))
9823 if(uint32 mechanic
= spellInfo
->Mechanic
)
9825 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9826 for(SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9827 if (itr
->type
== mechanic
)
9830 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9831 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9832 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9839 bool Unit::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, SpellEffectIndex index
) const
9841 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
9842 uint32 effect
= spellInfo
->Effect
[index
];
9843 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
9844 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
9845 if (itr
->type
== effect
)
9848 if(uint32 mechanic
= spellInfo
->EffectMechanic
[index
])
9850 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9851 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9852 if (itr
->type
== mechanic
)
9855 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9856 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9857 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9861 if(uint32 aura
= spellInfo
->EffectApplyAuraName
[index
])
9863 SpellImmuneList
const& list
= m_spellImmune
[IMMUNITY_STATE
];
9864 for(SpellImmuneList::const_iterator itr
= list
.begin(); itr
!= list
.end(); ++itr
)
9865 if (itr
->type
== aura
)
9868 // Check for immune to application of harmful magical effects
9869 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL
);
9870 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9871 if (spellInfo
->Dispel
== DISPEL_MAGIC
&& // Magic debuff
9872 ((*iter
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellInfo
)) && // Check school
9873 !IsPositiveEffect(spellInfo
->Id
, index
)) // Harmful
9880 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
9885 uint32 family
= spellInfo
->SpellFamilyName
;
9886 uint64 flags
= spellInfo
->SpellFamilyFlags
;
9888 if ((family
== 5 && flags
== 256) || //Searing Pain
9889 (family
== 6 && flags
== 8192) || //Mind Blast
9890 (family
== 11 && flags
== 1048576)) //Earth Shock
9897 * Calculates caster part of melee damage bonuses,
9898 * also includes different bonuses dependent from target auras
9900 uint32
Unit::MeleeDamageBonusDone(Unit
*pVictim
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
9908 // differentiate for weapon damage based spells
9909 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
9910 Item
* pWeapon
= GetTypeId() == TYPEID_PLAYER
? ((Player
*)this)->GetWeaponForAttack(attType
,true,false) : NULL
;
9911 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9912 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
9913 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
9915 // Shred also have bonus as MECHANIC_BLEED damages
9916 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
9917 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
9920 // FLAT damage bonus auras
9921 // =======================
9925 // ..done flat, already included in wepon damage based spells
9926 if (!isWeaponDamageBasedSpell
)
9928 AuraList
const& mModDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9929 for(AuraList::const_iterator i
= mModDamageDone
.begin(); i
!= mModDamageDone
.end(); ++i
)
9931 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9932 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9933 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9934 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
9936 DoneFlat
+= (*i
)->GetModifier()->m_amount
;
9940 // Pets just add their bonus damage to their melee damage
9941 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9942 DoneFlat
+= ((Pet
*)this)->GetBonusDamage();
9945 // ..done flat (by creature type mask)
9946 DoneFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
, creatureTypeMask
);
9948 // ..done flat (base at attack power for marked target and base at attack power for creature type)
9949 if (attType
== RANGED_ATTACK
)
9951 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
9952 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9956 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
9957 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9960 // PERCENT damage auras
9961 // ====================
9962 float DonePercent
= 1.0f
;
9964 // ..done pct, already included in weapon damage based spells
9965 if(!isWeaponDamageBasedSpell
)
9967 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
9968 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
9970 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9971 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9972 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9973 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
9975 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9979 if (attType
== OFF_ATTACK
)
9980 DonePercent
*= GetModifierValue(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_PCT
); // no school check required
9983 // ..done pct (by creature type mask)
9984 DonePercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
, creatureTypeMask
);
9986 // special dummys/class sripts and other effects
9987 // =============================================
9988 Unit
*owner
= GetOwner();
9992 // ..done (class scripts)
9995 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9996 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9998 if (!(*i
)->isAffectedOnSpell(spellProto
))
10001 switch((*i
)->GetModifier()->m_miscvalue
)
10004 // Merciless Combat
10007 // Merciless Combat
10008 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
10010 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
10011 DonePercent
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
10013 else // Tundra Stalker
10015 // Frost Fever (target debuff)
10016 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
10017 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10022 case 7293: // Rage of Rivendare
10024 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
10025 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10028 // Marked for Death
10035 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
10036 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10043 // .. done (class scripts)
10044 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
10045 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
10047 switch((*i
)->GetMiscValue())
10052 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
10054 Aura
* eff0
= GetAura((*i
)->GetId(), EFFECT_INDEX_0
);
10055 if (!eff0
|| (*i
)->GetEffIndex() != EFFECT_INDEX_1
)
10057 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
10061 // effect 0 have expected value but in negative state
10062 DonePercent
*= (-eff0
->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
10069 if (spellProto
&& spellProto
->SpellFamilyName
== SPELLFAMILY_DEATHKNIGHT
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000400000000))
10072 bool found
= false;
10073 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
10074 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
10076 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
10085 // search for Glacier Rot dummy aura
10086 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
10087 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
10089 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
10091 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
10099 // final calculation
10100 // =================
10102 float DoneTotal
= 0.0f
;
10104 // scaling of non weapon based spells
10105 if (!isWeaponDamageBasedSpell
)
10107 // apply ap bonus and benefit affected by spell power implicit coeffs and spell level penalties
10108 DoneTotal
= SpellBonusWithCoeffs(spellProto
, DoneTotal
, DoneFlat
, APbonus
, damagetype
, true);
10110 // weapon damage based spells
10111 else if( APbonus
|| DoneFlat
)
10113 bool normalized
= spellProto
? IsSpellHaveEffect(spellProto
, SPELL_EFFECT_NORMALIZED_WEAPON_DMG
) : false;
10114 DoneTotal
+= int32(APbonus
/ 14.0f
* GetAPMultiplier(attType
,normalized
));
10116 // for weapon damage based spells we still have to apply damage done percent mods
10117 // (that are already included into pdamage) to not-yet included DoneFlat
10118 // e.g. from doneVersusCreature, apBonusVs...
10123 case BASE_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_MAINHAND
; break;
10124 case OFF_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_OFFHAND
; break;
10125 case RANGED_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_RANGED
; break;
10128 DoneTotal
+= DoneFlat
;
10130 DoneTotal
*= GetModifierValue(unitMod
, TOTAL_PCT
);
10133 float tmpDamage
= float(int32(pdamage
) + DoneTotal
* int32(stack
)) * DonePercent
;
10135 // apply spellmod to Done damage
10138 if(Player
* modOwner
= GetSpellModOwner())
10139 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
10142 // bonus result can be negative
10143 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
10147 * Calculates target part of melee damage bonuses,
10148 * will be called on each tick for periodic damage over time auras
10150 uint32
Unit::MeleeDamageBonusTaken(Unit
*pCaster
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
10158 // differentiate for weapon damage based spells
10159 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
10160 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
10161 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
10163 // Shred also have bonus as MECHANIC_BLEED damages
10164 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
10165 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
10168 // FLAT damage bonus auras
10169 // =======================
10170 int32 TakenFlat
= 0;
10172 // ..taken flat (base at attack power for marked target and base at attack power for creature type)
10173 if (attType
== RANGED_ATTACK
)
10174 TakenFlat
+= GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
10176 TakenFlat
+= GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
10178 // ..taken flat (by school mask)
10179 TakenFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_TAKEN
, schoolMask
);
10181 // PERCENT damage auras
10182 // ====================
10183 float TakenPercent
= 1.0f
;
10185 // ..taken pct (by school mask)
10186 TakenPercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
, schoolMask
);
10188 // ..taken pct (by mechanic mask)
10189 TakenPercent
*= GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,mechanicMask
);
10191 // ..taken pct (melee/ranged)
10192 if(attType
== RANGED_ATTACK
)
10193 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
10195 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
10197 // ..taken pct (aoe avoidance)
10198 if(spellProto
&& IsAreaOfEffectSpell(spellProto
))
10199 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
10202 // special dummys/class scripts and other effects
10203 // =============================================
10205 // .. taken (dummy auras)
10206 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
10207 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
10209 switch((*i
)->GetSpellProto()->SpellIconID
)
10213 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
10215 if(GetTypeId() != TYPEID_PLAYER
)
10218 float mod
= ((Player
*)this)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
10219 if (mod
< float((*i
)->GetModifier()->m_amount
))
10220 mod
= float((*i
)->GetModifier()->m_amount
);
10222 TakenPercent
*= (mod
+ 100.0f
) / 100.0f
;
10228 // final calculation
10229 // =================
10231 // scaling of non weapon based spells
10232 if (!isWeaponDamageBasedSpell
)
10234 // apply benefit affected by spell power implicit coeffs and spell level penalties
10235 TakenFlat
= SpellBonusWithCoeffs(spellProto
, 0, TakenFlat
, 0, damagetype
, false);
10238 float tmpDamage
= float(int32(pdamage
) + TakenFlat
* int32(stack
)) * TakenPercent
;
10240 // bonus result can be negative
10241 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
10244 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
10248 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
10250 next
= itr
; ++next
;
10251 if(itr
->type
== type
)
10253 m_spellImmune
[op
].erase(itr
);
10254 next
= m_spellImmune
[op
].begin();
10257 SpellImmune Immune
;
10258 Immune
.spellId
= spellId
;
10259 Immune
.type
= type
;
10260 m_spellImmune
[op
].push_back(Immune
);
10264 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
10266 if(itr
->spellId
== spellId
)
10268 m_spellImmune
[op
].erase(itr
);
10276 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
10278 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
10280 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
10281 RemoveAurasWithDispelType(type
);
10284 float Unit::GetWeaponProcChance() const
10286 // normalized proc chance for weapon attack speed
10287 // (odd formula...)
10288 if (isAttackReady(BASE_ATTACK
))
10289 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
10290 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
10291 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
10296 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
10298 // proc per minute chance calculation
10301 return WeaponSpeed
* PPM
/ 600.0f
; // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
10304 void Unit::Mount(uint32 mount
, uint32 spellId
)
10309 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
10311 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
10313 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
10315 if (GetTypeId() == TYPEID_PLAYER
)
10317 // Called by Taxi system / GM command
10319 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10320 // Called by mount aura
10321 else if (SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellId
))
10323 // Flying case (Unsummon any pet)
10324 if (IsSpellHaveAura(spellInfo
, SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED
))
10325 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10326 // Normal case (Unsummon only permanent pet)
10327 else if (Pet
* pet
= GetPet())
10329 if (pet
->IsPermanentPetFor((Player
*)this) && !((Player
*)this)->InArena())
10330 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10332 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,true);
10338 void Unit::Unmount()
10343 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
10345 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
10346 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
10348 // only resummon old pet if the player is already added to a map
10349 // this prevents adding a pet to a not created map which would otherwise cause a crash
10350 // (it could probably happen when logging in after a previous crash)
10351 if(GetTypeId() == TYPEID_PLAYER
)
10353 if(Pet
* pet
= GetPet())
10354 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,false);
10356 ((Player
*)this)->ResummonPetTemporaryUnSummonedIfAny();
10360 void Unit::SetInCombatWith(Unit
* enemy
)
10362 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
10363 if (eOwner
->IsPvP())
10365 SetInCombatState(true,enemy
);
10370 if (eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
10372 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
10373 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
10375 SetInCombatState(true,enemy
);
10380 SetInCombatState(false,enemy
);
10383 void Unit::SetInCombatState(bool PvP
, Unit
* enemy
)
10385 // only alive units can be in combat
10390 m_CombatTimer
= 5000;
10392 bool creatureNotInCombat
= GetTypeId()==TYPEID_UNIT
&& !HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10394 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10396 if (isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10397 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10399 if (creatureNotInCombat
)
10401 // should probably be removed for the attacked (+ it's party/group) only, not global
10402 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10404 if (((Creature
*)this)->AI())
10405 ((Creature
*)this)->AI()->EnterCombat(enemy
);
10409 void Unit::ClearInCombat()
10412 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10414 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10415 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10417 // Player's state will be cleared in Player::UpdateContestedPvP
10418 if (GetTypeId() != TYPEID_PLAYER
)
10420 Creature
* creature
= (Creature
*)this;
10421 if (creature
->GetCreatureInfo() && creature
->GetCreatureInfo()->unit_flags
& UNIT_FLAG_OOC_NOT_ATTACKABLE
)
10422 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10424 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
10427 ((Player
*)this)->UpdatePotionCooldown();
10430 bool Unit::isTargetableForAttack(bool inverseAlive
/*=false*/) const
10432 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
10435 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
10438 // to be removed if unit by any reason enter combat
10439 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
))
10442 // inversealive is needed for some spells which need to be casted at dead targets (aoe)
10443 if (isAlive() == inverseAlive
)
10446 return IsInWorld() && !hasUnitState(UNIT_STAT_DIED
) && !isInFlight();
10449 int32
Unit::ModifyHealth(int32 dVal
)
10456 int32 curHealth
= (int32
)GetHealth();
10458 int32 val
= dVal
+ curHealth
;
10465 int32 maxHealth
= (int32
)GetMaxHealth();
10467 if(val
< maxHealth
)
10470 gain
= val
- curHealth
;
10472 else if(curHealth
!= maxHealth
)
10474 SetHealth(maxHealth
);
10475 gain
= maxHealth
- curHealth
;
10481 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
10488 int32 curPower
= (int32
)GetPower(power
);
10490 int32 val
= dVal
+ curPower
;
10497 int32 maxPower
= (int32
)GetMaxPower(power
);
10501 SetPower(power
,val
);
10502 gain
= val
- curPower
;
10504 else if(curPower
!= maxPower
)
10506 SetPower(power
,maxPower
);
10507 gain
= maxPower
- curPower
;
10513 bool Unit::isVisibleForOrDetect(Unit
const* u
, WorldObject
const* viewPoint
, bool detect
, bool inVisibleList
, bool is3dDistance
) const
10515 if(!u
|| !IsInMap(u
))
10518 // Always can see self
10522 // player visible for other player if not logout and at same transport
10523 // including case when player is out of world
10524 bool at_same_transport
=
10525 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
10526 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
10527 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
10528 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
10531 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
10534 // forbidden to seen (at GM respawn command)
10535 if(m_Visibility
==VISIBILITY_RESPAWN
)
10538 Map
& _map
= *u
->GetMap();
10539 // Grid dead/alive checks
10540 if (u
->GetTypeId()==TYPEID_PLAYER
)
10542 // non visible at grid for any stealth state
10543 if(!IsVisibleInGridForPlayer((Player
*)u
))
10546 // if player is dead then he can't detect anyone in any cases
10552 // all dead creatures/players not visible for any creatures
10553 if(!u
->isAlive() || !isAlive())
10557 // always seen by far sight caster
10558 if (u
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)u
)->GetFarSight()==GetGUID())
10561 // different visible distance checks
10562 if (u
->isInFlight()) // what see player in flight
10564 // use object grey distance for all (only see objects any way)
10565 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10568 else if(!isAlive()) // distance for show body
10570 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10573 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
10575 if(u
->GetTypeId()==TYPEID_PLAYER
)
10577 // Players far than max visible distance for player or not in our map are not visible too
10578 if (!at_same_transport
&& !IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10583 // Units far than max visible distance for creature or not in our map are not visible too
10584 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10588 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
10590 // Pet/charmed far than max visible distance for player or not in our map are not visible too
10591 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10594 else // distance for show creature
10596 // Units far than max visible distance for creature or not in our map are not visible too
10597 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10601 // always seen by owner
10602 if (GetCharmerOrOwnerGUID()==u
->GetGUID())
10605 // isInvisibleForAlive() those units can only be seen by dead or if other
10606 // unit is also invisible for alive.. if an isinvisibleforalive unit dies we
10607 // should be able to see it too
10608 if (u
->isAlive() && isAlive() && isInvisibleForAlive() != u
->isInvisibleForAlive())
10609 if (u
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)u
)->isGameMaster())
10612 // Visible units, always are visible for all units, except for units under invisibility and phases
10613 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0 && InSamePhase(u
))
10616 // GMs see any players, not higher GMs and all units in any phase
10617 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
10619 if(GetTypeId() == TYPEID_PLAYER
)
10620 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
10625 // non faction visibility non-breakable for non-GMs
10626 if (m_Visibility
== VISIBILITY_OFF
)
10629 // phased visibility (both must phased in same way)
10630 if(!InSamePhase(u
))
10633 // raw invisibility
10634 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
10636 // detectable invisibility case
10638 // Invisible units, always are visible for units under same invisibility type
10639 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
10640 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
10641 u
->canDetectInvisibilityOf(this) ||
10642 // Units that can detect invisibility always are visible for units that can be detected
10643 canDetectInvisibilityOf(u
) ))
10648 // special cases for always overwrite invisibility/stealth
10649 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
10651 // non-hostile case
10652 if (!u
->IsHostileTo(this))
10654 // 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)
10655 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
10657 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
10660 // else apply same rules as for hostile case (detecting check for stealth)
10666 // Hunter mark functionality
10667 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
10668 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
10669 if((*iter
)->GetCasterGUID()==u
->GetGUID())
10672 // else apply detecting check for stealth
10675 // none other cases for detect invisibility, so invisible
10679 // else apply stealth detecting check
10682 // unit got in stealth in this moment and must ignore old detected state
10683 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
10686 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
10687 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
10690 // NOW ONLY STEALTH CASE
10692 //if in non-detect mode then invisible for unit
10693 //mobs always detect players (detect == true)... return 'false' for those mobs which have (detect == false)
10694 //players detect players only in Player::HandleStealthedUnitsDetection()
10696 return (u
->GetTypeId() == TYPEID_PLAYER
) ? ((Player
*)u
)->HaveAtClient(this) : false;
10700 // If is attacked then stealth is lost, some creature can use stealth too
10701 if( !getAttackers().empty() )
10704 // If there is collision rogue is seen regardless of level difference
10705 if (IsWithinDist(u
,0.24f
))
10708 //If a mob or player is stunned he will not be able to detect stealth
10709 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
10713 float visibleDistance
= (u
->GetTypeId() == TYPEID_PLAYER
) ? MAX_PLAYER_STEALTH_DETECT_RANGE
: ((Creature
const*)u
)->GetAttackDistance(this);
10715 //Always invisible from back (when stealth detection is on), also filter max distance cases
10716 bool isInFront
= viewPoint
->isInFrontInMap(this, visibleDistance
);
10720 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
10721 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
10723 //Calculation if target is in front
10725 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
10726 visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
10728 //Visible distance is modified by
10729 //-Level Diff (every level diff = 1.0f in visible distance)
10730 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
10732 //This allows to check talent tree and will add addition stealth dependent on used points)
10733 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
10737 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
10738 //based on wowwiki every 5 mod we have 1 more level diff in calculation
10739 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_DETECT
)) - stealthMod
)/5.0f
;
10740 visibleDistance
= visibleDistance
> MAX_PLAYER_STEALTH_DETECT_RANGE
? MAX_PLAYER_STEALTH_DETECT_RANGE
: visibleDistance
;
10742 // recheck new distance
10743 if(visibleDistance
<= 0 || !IsWithinDist(viewPoint
,visibleDistance
))
10747 // Now check is target visible with LoS
10749 viewPoint
->GetPosition(ox
,oy
,oz
);
10750 return IsWithinLOS(ox
,oy
,oz
);
10753 void Unit::SetVisibility(UnitVisibility x
)
10761 if(GetTypeId()==TYPEID_PLAYER
)
10762 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10764 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10768 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
10770 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
10772 for(uint32 i
= 0; i
< 10; ++i
)
10774 if(((1 << i
) & mask
)==0)
10777 // find invisibility level
10778 int32 invLevel
= 0;
10779 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
10780 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
10781 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
10782 invLevel
= (*itr
)->GetModifier()->m_amount
;
10784 // find invisibility detect level
10785 int32 detectLevel
= 0;
10786 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
10787 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
10788 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
10789 detectLevel
= (*itr
)->GetModifier()->m_amount
;
10791 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
10793 detectLevel
= ((Player
*)this)->GetDrunkValue();
10796 if(invLevel
<= detectLevel
)
10804 struct UpdateWalkModeHelper
10806 explicit UpdateWalkModeHelper(Unit
* _source
) : source(_source
) {}
10807 void operator()(Unit
* unit
) const { unit
->UpdateWalkMode(source
, true); }
10811 void Unit::UpdateWalkMode(Unit
* source
, bool self
)
10813 if (GetTypeId() == TYPEID_PLAYER
)
10814 ((Player
*)this)->CallForAllControlledUnits(UpdateWalkModeHelper(source
), false, true, true, true);
10817 bool on
= source
->GetTypeId() == TYPEID_PLAYER
10818 ? ((Player
*)source
)->HasMovementFlag(MOVEFLAG_WALK_MODE
)
10819 : ((Creature
*)source
)->HasSplineFlag(SPLINEFLAG_WALKMODE
);
10823 if (((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10824 ((Creature
*)this)->AddSplineFlag(SPLINEFLAG_WALKMODE
);
10828 if (((Creature
*)this)->isPet())
10829 ((Creature
*)this)->RemoveSplineFlag(SPLINEFLAG_WALKMODE
);
10833 CallForAllControlledUnits(UpdateWalkModeHelper(source
), false, true, true);
10836 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
, float ratio
)
10838 // not in combat pet have same speed as owner
10844 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10846 if(Unit
* owner
= GetOwner())
10848 SetSpeedRate(mtype
, owner
->GetSpeedRate(mtype
), forced
);
10855 int32 main_speed_mod
= 0;
10856 float stack_bonus
= 1.0f
;
10857 float non_stack_bonus
= 1.0f
;
10865 if (IsMounted()) // Use on mount auras
10867 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
10868 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
10869 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
10873 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
10874 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
10875 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
10879 case MOVE_RUN_BACK
:
10883 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
10886 case MOVE_SWIM_BACK
:
10890 if (IsMounted()) // Use on mount auras
10892 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED
);
10893 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED_STACKING
);
10894 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED_NOT_STACKING
))/100.0f
;
10896 else // Use not mount (shapeshift for example) auras (should stack)
10898 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED
);
10899 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_STACKING
);
10900 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACKING
))/100.0f
;
10904 case MOVE_FLIGHT_BACK
:
10907 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
10911 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
10912 // now we ready for speed calculation
10913 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
10921 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
10922 // TODO: possible affect only on MOVE_RUN
10923 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
10925 // Use speed from aura
10926 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
10927 if (speed
> max_speed
)
10936 // for creature case, we check explicit if mob searched for assistance
10937 if (GetTypeId() == TYPEID_UNIT
)
10939 if (((Creature
*)this)->HasSearchedAssistance())
10940 speed
*= 0.66f
; // best guessed value, so this will be 33% reduction. Based off initial speed, mob can then "run", "walk fast" or "walk".
10943 // Apply strongest slow aura mod to speed
10944 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
10947 speed
*=(100.0f
+ slow
)/100.0f
;
10948 float min_speed
= (float)GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MINIMUM_SPEED
) / 100.0f
;
10949 if (speed
< min_speed
)
10952 SetSpeedRate(mtype
, speed
* ratio
, forced
);
10955 float Unit::GetSpeed( UnitMoveType mtype
) const
10957 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
10960 struct SetSpeedRateHelper
10962 explicit SetSpeedRateHelper(UnitMoveType _mtype
, bool _forced
) : mtype(_mtype
), forced(_forced
) {}
10963 void operator()(Unit
* unit
) const { unit
->UpdateSpeed(mtype
,forced
); }
10964 UnitMoveType mtype
;
10968 void Unit::SetSpeedRate(UnitMoveType mtype
, float rate
, bool forced
)
10973 // Update speed only on change
10974 if (m_speed_rate
[mtype
] == rate
)
10977 m_speed_rate
[mtype
] = rate
;
10979 propagateSpeedChange();
10987 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10990 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10992 case MOVE_RUN_BACK
:
10993 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10996 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10998 case MOVE_SWIM_BACK
:
10999 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11001 case MOVE_TURN_RATE
:
11002 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+2+4+4+4+4+4+4+4);
11005 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11007 case MOVE_FLIGHT_BACK
:
11008 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11010 case MOVE_PITCH_RATE
:
11011 data
.Initialize(MSG_MOVE_SET_PITCH_RATE
, 8+4+2+4+4+4+4+4+4+4);
11014 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
11018 data
<< GetPackGUID();
11019 data
<< uint32(0); // movement flags
11020 data
<< uint16(0); // unk flags
11021 data
<< uint32(getMSTime());
11022 data
<< float(GetPositionX());
11023 data
<< float(GetPositionY());
11024 data
<< float(GetPositionZ());
11025 data
<< float(GetOrientation());
11026 data
<< uint32(0); // fall time
11027 data
<< float(GetSpeed(mtype
));
11028 SendMessageToSet( &data
, true );
11032 if(GetTypeId() == TYPEID_PLAYER
)
11034 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
11035 // and do it only for real sent packets and use run for run/mounted as client expected
11036 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
11042 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
11045 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
11047 case MOVE_RUN_BACK
:
11048 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
11051 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
11053 case MOVE_SWIM_BACK
:
11054 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
11056 case MOVE_TURN_RATE
:
11057 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
11060 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
11062 case MOVE_FLIGHT_BACK
:
11063 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
11065 case MOVE_PITCH_RATE
:
11066 data
.Initialize(SMSG_FORCE_PITCH_RATE_CHANGE
, 16);
11069 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
11072 data
<< GetPackGUID();
11073 data
<< (uint32
)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
11074 if (mtype
== MOVE_RUN
)
11075 data
<< uint8(0); // new 2.1.0
11076 data
<< float(GetSpeed(mtype
));
11077 SendMessageToSet( &data
, true );
11080 if (GetTypeId() == TYPEID_PLAYER
) // need include minpet
11081 ((Player
*)this)->CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true,true);
11083 CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true);
11086 void Unit::SetHover(bool on
)
11089 CastSpell(this, 11010, true);
11091 RemoveAurasDueToSpell(11010);
11094 void Unit::setDeathState(DeathState s
)
11096 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
11099 DeleteThreatList();
11100 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
11102 if(IsNonMeleeSpellCasted(false))
11103 InterruptNonMeleeSpells(false);
11106 if (s
== JUST_DIED
)
11108 RemoveAllAurasOnDeath();
11110 UnsummonAllTotems();
11112 // after removing a Fearaura (in RemoveAllAurasOnDeath)
11113 // Unit::SetFeared is called and makes that creatures attack player again
11116 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
11117 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
11118 // remove aurastates allowing special moves
11119 ClearAllReactives();
11120 ClearDiminishings();
11122 else if(s
== JUST_ALIVED
)
11124 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
11127 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
11129 //_ApplyAllAuraMods();
11134 /*########################################
11136 ######## AGGRO SYSTEM ########
11138 ########################################*/
11139 bool Unit::CanHaveThreatList() const
11141 // only creatures can have threat list
11142 if( GetTypeId() != TYPEID_UNIT
)
11145 // only alive units can have threat list
11149 // totems can not have threat list
11150 if( ((Creature
*)this)->isTotem() )
11153 // vehicles can not have threat list
11154 if( ((Creature
*)this)->isVehicle() )
11157 // pets can not have a threat list, unless they are controlled by a creature
11158 if( ((Creature
*)this)->isPet() && IS_PLAYER_GUID(((Pet
*)this)->GetOwnerGUID()) )
11164 //======================================================================
11166 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
11168 if (!HasAuraType(SPELL_AURA_MOD_THREAT
))
11171 if (schoolMask
== SPELL_SCHOOL_MASK_NONE
)
11174 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
11176 return threat
* m_threatModifier
[school
];
11179 //======================================================================
11181 void Unit::AddThreat(Unit
* pVictim
, float threat
/*= 0.0f*/, bool crit
/*= false*/, SpellSchoolMask schoolMask
/*= SPELL_SCHOOL_MASK_NONE*/, SpellEntry
const *threatSpell
/*= NULL*/)
11183 // Only mobs can manage threat lists
11184 if(CanHaveThreatList())
11185 m_ThreatManager
.addThreat(pVictim
, threat
, crit
, schoolMask
, threatSpell
);
11188 //======================================================================
11190 void Unit::DeleteThreatList()
11192 if(CanHaveThreatList() && !m_ThreatManager
.isThreatListEmpty())
11194 m_ThreatManager
.clearReferences();
11197 //======================================================================
11199 void Unit::TauntApply(Unit
* taunter
)
11201 ASSERT(GetTypeId()== TYPEID_UNIT
);
11203 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
11206 if(!CanHaveThreatList())
11209 Unit
*target
= getVictim();
11210 if(target
&& target
== taunter
)
11213 SetInFront(taunter
);
11214 if (((Creature
*)this)->AI())
11215 ((Creature
*)this)->AI()->AttackStart(taunter
);
11217 m_ThreatManager
.tauntApply(taunter
);
11220 //======================================================================
11222 void Unit::TauntFadeOut(Unit
*taunter
)
11224 ASSERT(GetTypeId()== TYPEID_UNIT
);
11226 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
11229 if(!CanHaveThreatList())
11232 Unit
*target
= getVictim();
11233 if(!target
|| target
!= taunter
)
11236 if(m_ThreatManager
.isThreatListEmpty())
11238 if(((Creature
*)this)->AI())
11239 ((Creature
*)this)->AI()->EnterEvadeMode();
11243 m_ThreatManager
.tauntFadeOut(taunter
);
11244 target
= m_ThreatManager
.getHostileTarget();
11246 if (target
&& target
!= taunter
)
11248 SetInFront(target
);
11249 if (((Creature
*)this)->AI())
11250 ((Creature
*)this)->AI()->AttackStart(target
);
11254 //======================================================================
11256 bool Unit::SelectHostileTarget()
11258 //function provides main threat functionality
11259 //next-victim-selection algorithm and evade mode are called
11260 //threat list sorting etc.
11262 ASSERT(GetTypeId()== TYPEID_UNIT
);
11264 if (!this->isAlive())
11266 //This function only useful once AI has been initialized
11267 if (!((Creature
*)this)->AI())
11270 Unit
* target
= NULL
;
11272 // First checking if we have some taunt on us
11273 const AuraList
& tauntAuras
= GetAurasByType(SPELL_AURA_MOD_TAUNT
);
11274 if ( !tauntAuras
.empty() )
11278 // The last taunt aura caster is alive an we are happy to attack him
11279 if ( (caster
= tauntAuras
.back()->GetCaster()) && caster
->isAlive() )
11281 else if (tauntAuras
.size() > 1)
11283 // We do not have last taunt aura caster but we have more taunt auras,
11284 // so find first available target
11286 // Auras are pushed_back, last caster will be on the end
11287 AuraList::const_iterator aura
= --tauntAuras
.end();
11291 if ( (caster
= (*aura
)->GetCaster()) &&
11292 caster
->IsInMap(this) && caster
->isTargetableForAttack() && caster
->isInAccessablePlaceFor((Creature
*)this) )
11297 }while (aura
!= tauntAuras
.begin());
11301 if ( !target
&& !m_ThreatManager
.isThreatListEmpty() )
11302 // No taunt aura or taunt aura caster is dead standart target selection
11303 target
= m_ThreatManager
.getHostileTarget();
11307 if (!hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_DIED
))
11309 SetInFront(target
);
11310 ((Creature
*)this)->AI()->AttackStart(target
);
11315 // no target but something prevent go to evade mode
11316 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
11319 // last case when creature don't must go to evade mode:
11320 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
11321 // for example at owner command to pet attack some far away creature
11322 // Note: creature not have targeted movement generator but have attacker in this case
11323 if (GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE
)
11325 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
11327 if ((*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this))
11332 // enter in evade mode in other case
11333 ((Creature
*)this)->AI()->EnterEvadeMode();
11338 //======================================================================
11339 //======================================================================
11340 //======================================================================
11342 int32
Unit::CalculateSpellDamage(Unit
const* target
, SpellEntry
const* spellProto
, SpellEffectIndex effect_index
, int32
const* effBasePoints
)
11344 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
11346 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
11348 int32 level
= int32(getLevel());
11349 if (level
> (int32
)spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
11350 level
= (int32
)spellProto
->maxLevel
;
11351 else if (level
< (int32
)spellProto
->baseLevel
)
11352 level
= (int32
)spellProto
->baseLevel
;
11353 level
-= (int32
)spellProto
->spellLevel
;
11355 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
11356 int32 basePoints
= effBasePoints
? *effBasePoints
- 1 : spellProto
->EffectBasePoints
[effect_index
];
11357 basePoints
+= int32(level
* basePointsPerLevel
);
11358 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
]);
11359 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
11361 switch(randomPoints
)
11363 case 0: // not used
11364 case 1: basePoints
+= 1; break; // range 1..1
11366 // range can have positive (1..rand) and negative (rand..1) values, so order its for irand
11367 int32 randvalue
= (randomPoints
>= 1)
11368 ? irand(1, randomPoints
)
11369 : irand(randomPoints
, 1);
11371 basePoints
+= randvalue
;
11375 int32 value
= basePoints
;
11378 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
11379 value
+= (int32
)(comboDamage
* comboPoints
);
11381 if(Player
* modOwner
= GetSpellModOwner())
11383 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_ALL_EFFECTS
, value
);
11384 switch(effect_index
)
11387 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT1
, value
);
11390 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT2
, value
);
11393 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT3
, value
);
11398 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
11399 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
11400 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
&&
11401 (spellProto
->Effect
[effect_index
] != SPELL_EFFECT_APPLY_AURA
|| spellProto
->EffectApplyAuraName
[effect_index
] != SPELL_AURA_MOD_DECREASE_SPEED
))
11402 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
11407 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, SpellEffectIndex effect_index
, Unit
const* target
)
11409 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
11411 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
11413 int32 minduration
= GetSpellDuration(spellProto
);
11414 int32 maxduration
= GetSpellMaxDuration(spellProto
);
11418 if( minduration
!= -1 && minduration
!= maxduration
)
11419 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
11421 duration
= minduration
;
11425 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
11426 // Find total mod value (negative bonus)
11427 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
11428 // Modify from SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL aura for negatve effects (stack always ?)
11429 if (!IsPositiveEffect(spellProto
->Id
, effect_index
))
11430 durationMod_always
+=target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
, spellProto
->Dispel
);
11431 // Find max mod (negative bonus)
11432 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
11434 if (!IsPositiveSpell(spellProto
->Id
))
11435 durationMod_always
+= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS
, spellProto
->DmgClass
);
11437 int32 durationMod
= 0;
11438 // Select strongest negative mod
11439 if (durationMod_always
> durationMod_not_stack
)
11440 durationMod
= durationMod_not_stack
;
11442 durationMod
= durationMod_always
;
11444 if (durationMod
!= 0)
11445 duration
= int32(int64(duration
) * (100+durationMod
) /100);
11447 if (duration
< 0) duration
= 0;
11453 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
11455 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11457 if(i
->DRGroup
!= group
)
11461 return DIMINISHING_LEVEL_1
;
11464 return DIMINISHING_LEVEL_1
;
11466 // If last spell was casted more than 15 seconds ago - reset the count.
11467 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
11469 i
->hitCount
= DIMINISHING_LEVEL_1
;
11470 return DIMINISHING_LEVEL_1
;
11472 // or else increase the count.
11475 return DiminishingLevels(i
->hitCount
);
11478 return DIMINISHING_LEVEL_1
;
11481 void Unit::IncrDiminishing(DiminishingGroup group
)
11483 // Checking for existing in the table
11484 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11486 if(i
->DRGroup
!= group
)
11488 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
11492 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
11495 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
, int32 limitduration
)
11497 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
11500 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
11501 if(limitduration
> 0 && duration
> limitduration
)
11503 // test pet/charm masters instead pets/charmeds
11504 Unit
const* targetOwner
= GetCharmerOrOwner();
11505 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
11507 Unit
const* target
= targetOwner
? targetOwner
: this;
11508 Unit
const* source
= casterOwner
? casterOwner
: caster
;
11510 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
11511 duration
= limitduration
;
11516 // Some diminishings applies to mobs too (for example, Stun)
11517 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
11519 DiminishingLevels diminish
= Level
;
11522 case DIMINISHING_LEVEL_1
: break;
11523 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
11524 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
11525 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
11530 duration
= int32(duration
* mod
);
11533 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
11535 // Checking for existing in the table
11536 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11538 if(i
->DRGroup
!= group
)
11546 // Remember time after last aura from group removed
11548 i
->hitTime
= getMSTime();
11554 Unit
* Unit::GetUnit(WorldObject
const& object
, uint64 guid
)
11556 return ObjectAccessor::GetUnit(object
,guid
);
11559 bool Unit::isVisibleForInState( Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const
11561 return isVisibleForOrDetect(u
, viewPoint
, false, inVisibleList
, false);
11564 /// returns true if creature can't be seen by alive units
11565 bool Unit::isInvisibleForAlive() const
11567 if (m_AuraFlags
& UNIT_AURAFLAG_ALIVE_INVISIBLE
)
11569 // TODO: maybe spiritservices also have just an aura
11570 return isSpiritService();
11573 uint32
Unit::GetCreatureType() const
11575 if(GetTypeId() == TYPEID_PLAYER
)
11577 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(m_form
);
11578 if(ssEntry
&& ssEntry
->creatureType
> 0)
11579 return ssEntry
->creatureType
;
11581 return CREATURE_TYPE_HUMANOID
;
11584 return ((Creature
*)this)->GetCreatureInfo()->type
;
11587 /*#######################################
11589 ######## STAT SYSTEM ########
11591 #######################################*/
11593 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
11595 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11597 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
11603 switch(modifierType
)
11607 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
11611 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
11614 val
= (100.0f
+ amount
) / 100.0f
;
11615 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
11622 if(!CanModifyStats())
11627 case UNIT_MOD_STAT_STRENGTH
:
11628 case UNIT_MOD_STAT_AGILITY
:
11629 case UNIT_MOD_STAT_STAMINA
:
11630 case UNIT_MOD_STAT_INTELLECT
:
11631 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
11633 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
11634 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
11636 case UNIT_MOD_MANA
:
11637 case UNIT_MOD_RAGE
:
11638 case UNIT_MOD_FOCUS
:
11639 case UNIT_MOD_ENERGY
:
11640 case UNIT_MOD_HAPPINESS
:
11641 case UNIT_MOD_RUNE
:
11642 case UNIT_MOD_RUNIC_POWER
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
11644 case UNIT_MOD_RESISTANCE_HOLY
:
11645 case UNIT_MOD_RESISTANCE_FIRE
:
11646 case UNIT_MOD_RESISTANCE_NATURE
:
11647 case UNIT_MOD_RESISTANCE_FROST
:
11648 case UNIT_MOD_RESISTANCE_SHADOW
:
11649 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
11651 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
11652 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
11654 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
11655 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
11656 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
11665 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
11667 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11669 sLog
.outError("trial to access non existed modifier value from UnitMods!");
11673 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
11676 return m_auraModifiersGroup
[unitMod
][modifierType
];
11679 float Unit::GetTotalStatValue(Stats stat
) const
11681 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
11683 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11686 // value = ((base_value * base_pct) + total_value) * total_pct
11687 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
11688 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11689 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11690 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11695 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
11697 if(unitMod
>= UNIT_MOD_END
)
11699 sLog
.outError("trial to access non existed UnitMods in GetTotalAuraModValue()!");
11703 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11706 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
11707 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11708 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11709 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11714 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
11716 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
11720 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
11721 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
11722 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
11723 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
11724 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
11725 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
11734 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
11736 Stats stat
= STAT_STRENGTH
;
11740 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
11741 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
11742 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
11743 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
11744 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
11753 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
11757 case UNIT_MOD_MANA
: return POWER_MANA
;
11758 case UNIT_MOD_RAGE
: return POWER_RAGE
;
11759 case UNIT_MOD_FOCUS
: return POWER_FOCUS
;
11760 case UNIT_MOD_ENERGY
: return POWER_ENERGY
;
11761 case UNIT_MOD_HAPPINESS
: return POWER_HAPPINESS
;
11762 case UNIT_MOD_RUNE
: return POWER_RUNE
;
11763 case UNIT_MOD_RUNIC_POWER
:return POWER_RUNIC_POWER
;
11764 default: return POWER_MANA
;
11770 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
11772 if (attType
== RANGED_ATTACK
)
11774 int32 ap
= GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER_MODS
);
11777 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER
));
11781 int32 ap
= GetInt32Value(UNIT_FIELD_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_ATTACK_POWER_MODS
);
11784 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER
));
11788 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
11790 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
11793 return m_weaponDamage
[attType
][type
];
11796 void Unit::SetLevel(uint32 lvl
)
11798 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
11801 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
11802 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
11805 void Unit::SetHealth(uint32 val
)
11807 uint32 maxHealth
= GetMaxHealth();
11808 if(maxHealth
< val
)
11811 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
11814 if(GetTypeId() == TYPEID_PLAYER
)
11816 if(((Player
*)this)->GetGroup())
11817 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
11819 else if(((Creature
*)this)->isPet())
11821 Pet
*pet
= ((Pet
*)this);
11822 if(pet
->isControlled())
11824 Unit
*owner
= GetOwner();
11825 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11826 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
11831 void Unit::SetMaxHealth(uint32 val
)
11833 uint32 health
= GetHealth();
11834 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
11837 if(GetTypeId() == TYPEID_PLAYER
)
11839 if(((Player
*)this)->GetGroup())
11840 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
11842 else if(((Creature
*)this)->isPet())
11844 Pet
*pet
= ((Pet
*)this);
11845 if(pet
->isControlled())
11847 Unit
*owner
= GetOwner();
11848 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11849 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP
);
11857 void Unit::SetHealthPercent(float percent
)
11859 uint32 newHealth
= GetMaxHealth() * percent
/100.0f
;
11860 SetHealth(newHealth
);
11863 void Unit::SetPower(Powers power
, uint32 val
)
11865 if(GetPower(power
) == val
)
11868 uint32 maxPower
= GetMaxPower(power
);
11872 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
11874 WorldPacket
data(SMSG_POWER_UPDATE
);
11875 data
<< GetPackGUID();
11876 data
<< uint8(power
);
11877 data
<< uint32(val
);
11878 SendMessageToSet(&data
, GetTypeId() == TYPEID_PLAYER
? true : false);
11881 if(GetTypeId() == TYPEID_PLAYER
)
11883 if(((Player
*)this)->GetGroup())
11884 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11886 else if(((Creature
*)this)->isPet())
11888 Pet
*pet
= ((Pet
*)this);
11889 if(pet
->isControlled())
11891 Unit
*owner
= GetOwner();
11892 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11893 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11896 // Update the pet's character sheet with happiness damage bonus
11897 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
11899 pet
->UpdateDamagePhysical(BASE_ATTACK
);
11904 void Unit::SetMaxPower(Powers power
, uint32 val
)
11906 uint32 cur_power
= GetPower(power
);
11907 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
11910 if(GetTypeId() == TYPEID_PLAYER
)
11912 if(((Player
*)this)->GetGroup())
11913 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
11915 else if(((Creature
*)this)->isPet())
11917 Pet
*pet
= ((Pet
*)this);
11918 if(pet
->isControlled())
11920 Unit
*owner
= GetOwner();
11921 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11922 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
11926 if(val
< cur_power
)
11927 SetPower(power
, val
);
11930 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
11932 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
11935 if(GetTypeId() == TYPEID_PLAYER
)
11937 if(((Player
*)this)->GetGroup())
11938 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11940 else if(((Creature
*)this)->isPet())
11942 Pet
*pet
= ((Pet
*)this);
11943 if(pet
->isControlled())
11945 Unit
*owner
= GetOwner();
11946 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11947 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11952 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
11954 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
11957 if(GetTypeId() == TYPEID_PLAYER
)
11959 if(((Player
*)this)->GetGroup())
11960 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
11962 else if(((Creature
*)this)->isPet())
11964 Pet
*pet
= ((Pet
*)this);
11965 if(pet
->isControlled())
11967 Unit
*owner
= GetOwner();
11968 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11969 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
11974 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
11976 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
11978 tAuraProcTriggerDamage
.push_back(aura
);
11980 tAuraProcTriggerDamage
.remove(aura
);
11983 uint32
Unit::GetCreatePowers( Powers power
) const
11985 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
11988 case POWER_HEALTH
: return 0;
11989 case POWER_MANA
: return GetCreateMana();
11990 case POWER_RAGE
: return 1000;
11991 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
11992 case POWER_ENERGY
: return 100;
11993 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
11994 case POWER_RUNIC_POWER
: return 1000;
11995 case POWER_RUNE
: return 0;
12001 void Unit::AddToWorld()
12003 Object::AddToWorld();
12006 void Unit::RemoveFromWorld()
12012 RemoveNotOwnSingleTargetAuras();
12014 RemoveAllGameObjects();
12015 RemoveAllDynObjects();
12016 CleanupDeletedAuras();
12019 Object::RemoveFromWorld();
12022 void Unit::CleanupsBeforeDelete()
12024 if(m_uint32Values
) // only for fully created object
12026 InterruptNonMeleeSpells(true);
12027 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
12029 ClearComboPointHolders();
12030 DeleteThreatList();
12031 getHostileRefManager().setOnlineOfflineState(false);
12032 RemoveAllAuras(AURA_REMOVE_BY_DELETE
);
12033 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
12035 WorldObject::CleanupsBeforeDelete();
12038 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
12041 m_charmInfo
= new CharmInfo(charm
);
12042 return m_charmInfo
;
12045 CharmInfo::CharmInfo(Unit
* unit
)
12046 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
12048 for(int i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
12049 m_charmspells
[i
].SetActionAndType(0,ACT_DISABLED
);
12052 void CharmInfo::InitPetActionBar()
12054 // the first 3 SpellOrActions are attack, follow and stay
12055 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_START
- ACTION_BAR_INDEX_START
; ++i
)
12056 SetActionBar(ACTION_BAR_INDEX_START
+ i
,COMMAND_ATTACK
- i
,ACT_COMMAND
);
12058 // middle 4 SpellOrActions are spells/special attacks/abilities
12059 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_END
-ACTION_BAR_INDEX_PET_SPELL_START
; ++i
)
12060 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_START
+ i
,0,ACT_DISABLED
);
12062 // last 3 SpellOrActions are reactions
12063 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_END
- ACTION_BAR_INDEX_PET_SPELL_END
; ++i
)
12064 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_END
+ i
,COMMAND_ATTACK
- i
,ACT_REACTION
);
12067 void CharmInfo::InitEmptyActionBar()
12069 SetActionBar(ACTION_BAR_INDEX_START
,COMMAND_ATTACK
,ACT_COMMAND
);
12070 for(uint32 x
= ACTION_BAR_INDEX_START
+1; x
< ACTION_BAR_INDEX_END
; ++x
)
12071 SetActionBar(x
,0,ACT_PASSIVE
);
12074 void CharmInfo::InitPossessCreateSpells()
12076 InitEmptyActionBar(); //charm action bar
12078 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //possessed players don't have spells, keep the action bar empty
12081 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12083 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
12084 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
12086 AddSpellToActionBar(((Creature
*)m_unit
)->m_spells
[x
], ACT_PASSIVE
);
12090 void CharmInfo::InitCharmCreateSpells()
12092 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
12094 InitEmptyActionBar();
12098 InitPetActionBar();
12100 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12102 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
12106 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
12110 if (IsPassiveSpell(spellId
))
12112 m_unit
->CastSpell(m_unit
, spellId
, true);
12113 m_charmspells
[x
].SetActionAndType(spellId
,ACT_PASSIVE
);
12117 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
12119 ActiveStates newstate
;
12120 bool onlyselfcast
= true;
12121 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
12123 if(!spellInfo
) onlyselfcast
= false;
12124 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
12126 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
12127 onlyselfcast
= false;
12130 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
12131 newstate
= ACT_DISABLED
;
12133 newstate
= ACT_PASSIVE
;
12135 AddSpellToActionBar(spellId
, newstate
);
12140 bool CharmInfo::AddSpellToActionBar(uint32 spell_id
, ActiveStates newstate
)
12142 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
12144 // new spell rank can be already listed
12145 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12147 if (uint32 action
= PetActionBar
[i
].GetAction())
12149 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
12151 PetActionBar
[i
].SetAction(spell_id
);
12157 // or use empty slot in other case
12158 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12160 if (!PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
12162 SetActionBar(i
,spell_id
,newstate
== ACT_DECIDE
? ACT_DISABLED
: newstate
);
12169 bool CharmInfo::RemoveSpellFromActionBar(uint32 spell_id
)
12171 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
12173 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12175 if (uint32 action
= PetActionBar
[i
].GetAction())
12177 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
12179 SetActionBar(i
,0,ACT_DISABLED
);
12188 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
12190 if(IsPassiveSpell(spellid
))
12193 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12194 if(spellid
== m_charmspells
[x
].GetAction())
12195 m_charmspells
[x
].SetType(apply
? ACT_ENABLED
: ACT_DISABLED
);
12198 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
12200 m_petnumber
= petnumber
;
12202 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
12204 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
12207 void CharmInfo::LoadPetActionBar(const std::string
& data
)
12209 InitPetActionBar();
12211 Tokens tokens
= StrSplit(data
, " ");
12213 if (tokens
.size() != (ACTION_BAR_INDEX_END
-ACTION_BAR_INDEX_START
)*2)
12214 return; // non critical, will reset to default
12217 Tokens::iterator iter
;
12218 for(iter
= tokens
.begin(), index
= ACTION_BAR_INDEX_START
; index
< ACTION_BAR_INDEX_END
; ++iter
, ++index
)
12220 // use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
12221 uint8 type
= (uint8
)atol((*iter
).c_str());
12223 uint32 action
= atol((*iter
).c_str());
12225 PetActionBar
[index
].SetActionAndType(action
,ActiveStates(type
));
12227 // check correctness
12228 if(PetActionBar
[index
].IsActionBarForSpell() && !sSpellStore
.LookupEntry(PetActionBar
[index
].GetAction()))
12229 SetActionBar(index
,0,ACT_DISABLED
);
12233 void CharmInfo::BuildActionBar( WorldPacket
* data
)
12235 for(uint32 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12236 *data
<< uint32(PetActionBar
[i
].packedData
);
12239 void CharmInfo::SetSpellAutocast( uint32 spell_id
, bool state
)
12241 for(int i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12243 if(spell_id
== PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
12245 PetActionBar
[i
].SetType(state
? ACT_ENABLED
: ACT_DISABLED
);
12251 bool Unit::isFrozen() const
12253 return HasAuraState(AURA_STATE_FROZEN
);
12256 struct ProcTriggeredData
12258 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
12259 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
12260 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
12262 SpellProcEventEntry
const *spellProcEvent
;
12263 Aura
* triggeredByAura
;
12264 Unit::spellEffectPair triggeredByAura_SpellPair
;
12267 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
12268 typedef std::list
< uint32
> RemoveSpellList
;
12270 // List of auras that CAN be trigger but may not exist in spell_proc_event
12271 // in most case need for drop charges
12272 // in some types of aura need do additional check
12273 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
12274 bool InitTriggerAuraData()
12276 for (int i
=0;i
<TOTAL_AURAS
;++i
)
12278 isTriggerAura
[i
]=false;
12279 isNonTriggerAura
[i
] = false;
12281 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
12282 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
12283 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
12284 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
12285 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
12286 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
12287 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
12288 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
12289 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
12290 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
12291 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
12292 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
12293 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
] = true;
12294 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
12295 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
12296 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
12297 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
12298 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
12299 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
12300 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
12301 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
12302 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
12303 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
12304 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
12305 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
12306 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
12307 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
12308 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
] = true;
12309 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_FROM_CASTER
] = true;
12310 isTriggerAura
[SPELL_AURA_MOD_SPELL_CRIT_CHANCE
] = true;
12311 isTriggerAura
[SPELL_AURA_MAELSTROM_WEAPON
] = true;
12313 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
12314 isNonTriggerAura
[SPELL_AURA_REDUCE_PUSHBACK
]=true;
12319 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
12321 uint32 procEx
= PROC_EX_NONE
;
12322 // Check victim state
12323 if (missCondition
!=SPELL_MISS_NONE
)
12324 switch (missCondition
)
12326 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
12327 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
12328 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
12329 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
12330 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
12331 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
12332 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
12333 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
12334 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
12335 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
12336 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
12343 if (damageInfo
->blocked
)
12344 procEx
|=PROC_EX_BLOCK
;
12346 if (damageInfo
->absorb
)
12347 procEx
|=PROC_EX_ABSORB
;
12349 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
12350 procEx
|=PROC_EX_CRITICAL_HIT
;
12352 procEx
|=PROC_EX_NORMAL_HIT
;
12357 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
12359 // For melee/ranged based attack need update skills and set some Aura states
12360 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
12362 // Update skills here for players
12363 if (GetTypeId() == TYPEID_PLAYER
)
12365 // On melee based hit/miss/resist need update skill (for victim and attacker)
12366 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
12368 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
12369 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, isVictim
);
12371 // Update defence if player is victim and parry/dodge/block
12372 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
12373 ((Player
*)this)->UpdateDefense();
12375 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
12376 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
12381 // if victim and dodge attack
12382 if (procExtra
&PROC_EX_DODGE
)
12384 //Update AURA_STATE on dodge
12385 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
12387 ModifyAuraState(AURA_STATE_DEFENSE
, true);
12388 StartReactiveTimer( REACTIVE_DEFENSE
);
12391 // if victim and parry attack
12392 if (procExtra
& PROC_EX_PARRY
)
12394 // For Hunters only Counterattack (skip Mongoose bite)
12395 if (getClass() == CLASS_HUNTER
)
12397 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
12398 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
12402 ModifyAuraState(AURA_STATE_DEFENSE
, true);
12403 StartReactiveTimer( REACTIVE_DEFENSE
);
12406 // if and victim block attack
12407 if (procExtra
& PROC_EX_BLOCK
)
12409 ModifyAuraState(AURA_STATE_DEFENSE
,true);
12410 StartReactiveTimer( REACTIVE_DEFENSE
);
12413 else //For attacker
12415 // Overpower on victim dodge
12416 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
12418 ((Player
*)this)->AddComboPoints(pTarget
, 1);
12419 StartReactiveTimer( REACTIVE_OVERPOWER
);
12425 RemoveSpellList removedSpells
;
12426 ProcTriggeredList procTriggered
;
12427 // Fill procTriggered list
12428 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
12430 // skip deleted auras (possible at recursive triggered call
12431 if(itr
->second
->IsDeleted())
12434 SpellProcEventEntry
const* spellProcEvent
= NULL
;
12435 if(!IsTriggeredAtSpellProcEvent(pTarget
, itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
12438 itr
->second
->SetInUse(true); // prevent aura deletion
12439 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
12443 if (procTriggered
.empty())
12446 // Handle effects proceed this time
12447 for(ProcTriggeredList::const_iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
12449 // Some auras can be deleted in function called in this loop (except first, ofc)
12450 Aura
*triggeredByAura
= i
->triggeredByAura
;
12451 if(triggeredByAura
->IsDeleted())
12454 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
12455 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
12456 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
12457 bool useCharges
= triggeredByAura
->GetAuraCharges() > 0;
12458 // For players set spell cooldown if need
12459 uint32 cooldown
= 0;
12460 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
12461 cooldown
= spellProcEvent
->cooldown
;
12463 switch(auraModifier
->m_auraname
)
12465 case SPELL_AURA_PROC_TRIGGER_SPELL
:
12467 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12468 // Don`t drop charge or add cooldown for not started trigger
12469 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12471 triggeredByAura
->SetInUse(false);
12476 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
12478 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "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());
12479 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, spellInfo
->SchoolMask
);
12480 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
12481 damageInfo
.target
->CalculateAbsorbResistBlock(this, &damageInfo
, spellInfo
);
12482 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
12483 SendSpellNonMeleeDamageLog(&damageInfo
);
12484 DealSpellDamage(&damageInfo
, true);
12487 case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
:
12488 case SPELL_AURA_MANA_SHIELD
:
12489 case SPELL_AURA_OBS_MOD_MANA
:
12490 case SPELL_AURA_ADD_PCT_MODIFIER
:
12491 case SPELL_AURA_DUMMY
:
12493 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12494 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12496 triggeredByAura
->SetInUse(false);
12501 case SPELL_AURA_MOD_HASTE
:
12503 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12504 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12506 triggeredByAura
->SetInUse(false);
12511 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
12513 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12514 if (!HandleOverrideClassScriptAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, cooldown
))
12516 triggeredByAura
->SetInUse(false);
12521 case SPELL_AURA_PRAYER_OF_MENDING
:
12523 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
12524 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
12526 HandleMendingAuraProc(triggeredByAura
);
12529 case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
:
12531 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "ProcDamageAndSpell: casting spell %u (triggered with value by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12533 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12535 triggeredByAura
->SetInUse(false);
12540 case SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
:
12541 // Skip melee hits or instant cast spells
12542 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
12544 triggeredByAura
->SetInUse(false);
12548 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
12549 // Skip Melee hits and spells ws wrong school
12550 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
12552 triggeredByAura
->SetInUse(false);
12556 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
12557 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
12558 // Skip melee hits and spells ws wrong school or zero cost
12559 if (procSpell
== NULL
||
12560 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
12561 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
12563 triggeredByAura
->SetInUse(false);
12567 case SPELL_AURA_MECHANIC_IMMUNITY
:
12568 // Compare mechanic
12569 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12571 triggeredByAura
->SetInUse(false);
12575 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
12576 // Compare mechanic
12577 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12579 triggeredByAura
->SetInUse(false);
12583 case SPELL_AURA_MOD_DAMAGE_FROM_CASTER
:
12585 if (triggeredByAura
->GetCasterGUID() != pTarget
->GetGUID())
12587 triggeredByAura
->SetInUse(false);
12591 case SPELL_AURA_MOD_SPELL_CRIT_CHANCE
:
12594 triggeredByAura
->SetInUse(false);
12597 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "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());
12598 if (!HandleSpellCritChanceAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12600 triggeredByAura
->SetInUse(false);
12604 case SPELL_AURA_MAELSTROM_WEAPON
:
12605 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "ProcDamageAndSpell: casting spell id %u (triggered by %s maelstrom aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12607 // remove all stack;
12608 RemoveSpellsCausingAura(SPELL_AURA_MAELSTROM_WEAPON
);
12609 triggeredByAura
->SetInUse(false); // this safe, aura locked
12610 continue; // avoid re-remove attempts
12612 // nothing do, just charges counter
12616 // Remove charge (aura can be removed by triggers)
12617 if(useCharges
&& !triggeredByAura
->IsDeleted())
12619 // If last charge dropped add spell to remove list
12620 if(triggeredByAura
->DropAuraCharge())
12621 removedSpells
.push_back(triggeredByAura
->GetId());
12624 triggeredByAura
->SetInUse(false);
12626 if (!removedSpells
.empty())
12628 // Sort spells and remove dublicates
12629 removedSpells
.sort();
12630 removedSpells
.unique();
12631 // Remove auras from removedAuras
12632 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();++i
)
12633 RemoveSingleSpellAurasFromStack(*i
);
12637 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
12639 return SPELL_SCHOOL_MASK_NORMAL
;
12642 Player
* Unit::GetSpellModOwner()
12644 if(GetTypeId()==TYPEID_PLAYER
)
12645 return (Player
*)this;
12646 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
12648 Unit
* owner
= GetOwner();
12649 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
12650 return (Player
*)owner
;
12655 ///----------Pet responses methods-----------------
12656 void Unit::SendPetCastFail(uint32 spellid
, SpellCastResult msg
)
12658 if(msg
== SPELL_CAST_OK
)
12661 Unit
*owner
= GetCharmerOrOwner();
12662 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12665 WorldPacket
data(SMSG_PET_CAST_FAILED
, 1 + 4 + 1);
12666 data
<< uint8(0); // cast count?
12667 data
<< uint32(spellid
);
12668 data
<< uint8(msg
);
12669 // uint32 for some reason
12670 // uint32 for some reason
12671 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12674 void Unit::SendPetActionFeedback (uint8 msg
)
12676 Unit
* owner
= GetOwner();
12677 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12680 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
12681 data
<< uint8(msg
);
12682 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12685 void Unit::SendPetTalk (uint32 pettalk
)
12687 Unit
* owner
= GetOwner();
12688 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12691 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8 + 4);
12692 data
<< uint64(GetGUID());
12693 data
<< uint32(pettalk
);
12694 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12697 void Unit::SendPetAIReaction(uint64 guid
)
12699 Unit
* owner
= GetOwner();
12700 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12703 WorldPacket
data(SMSG_AI_REACTION
, 8 + 4);
12704 data
<< uint64(guid
);
12705 data
<< uint32(AI_REACTION_HOSTILE
);
12706 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12709 ///----------End of Pet responses methods----------
12711 void Unit::StopMoving()
12713 clearUnitState(UNIT_STAT_MOVING
);
12715 // send explicit stop packet
12716 // player expected for correct work SPLINEFLAG_WALKMODE
12717 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_NORMAL
, GetTypeId() == TYPEID_PLAYER
? SPLINEFLAG_WALKMODE
: SPLINEFLAG_NONE
, 0);
12719 // update position and orientation for near players
12721 BuildHeartBeatMsg(&data
);
12722 SendMessageToSet(&data
, false);
12725 void Unit::SetFeared(bool apply
, uint64
const& casterGUID
, uint32 spellID
, uint32 time
)
12729 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
12732 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12734 GetMotionMaster()->MovementExpired(false);
12735 CastStop(GetGUID() == casterGUID
? spellID
: 0);
12737 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
12739 GetMotionMaster()->MoveFleeing(caster
, time
); // caster==NULL processed in MoveFleeing
12743 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12745 GetMotionMaster()->MovementExpired(false);
12747 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
12749 // restore appropriate movement generator
12751 GetMotionMaster()->MoveChase(getVictim());
12753 GetMotionMaster()->Initialize();
12755 // attack caster if can
12756 Unit
* caster
= Unit::GetUnit(*this, casterGUID
);
12757 if(caster
&& ((Creature
*)this)->AI())
12758 ((Creature
*)this)->AI()->AttackedBy(caster
);
12762 if (GetTypeId() == TYPEID_PLAYER
)
12763 ((Player
*)this)->SetClientControl(this, !apply
);
12766 void Unit::SetConfused(bool apply
, uint64
const& casterGUID
, uint32 spellID
)
12770 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12772 CastStop(GetGUID()==casterGUID
? spellID
: 0);
12774 GetMotionMaster()->MoveConfused();
12778 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12780 GetMotionMaster()->MovementExpired(false);
12782 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12784 // restore appropriate movement generator
12786 GetMotionMaster()->MoveChase(getVictim());
12788 GetMotionMaster()->Initialize();
12792 if(GetTypeId() == TYPEID_PLAYER
)
12793 ((Player
*)this)->SetClientControl(this, !apply
);
12796 void Unit::SetFeignDeath(bool apply
, uint64
const& casterGUID
, uint32
/*spellID*/)
12801 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12804 SendMessageToSet(&data,true);
12807 if(GetTypeId() != TYPEID_PLAYER
)
12810 ((Player
*)this)->m_movementInfo
.SetMovementFlags(MOVEFLAG_NONE
);
12812 // blizz like 2.0.x
12813 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12814 // blizz like 2.0.x
12815 SetFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12816 // blizz like 2.0.x
12817 SetFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12819 addUnitState(UNIT_STAT_DIED
);
12821 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION
);
12823 // prevent interrupt message
12824 if (casterGUID
== GetGUID())
12825 FinishSpell(CURRENT_GENERIC_SPELL
,false);
12826 InterruptNonMeleeSpells(true);
12827 getHostileRefManager().deleteReferences();
12832 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12835 SendMessageToSet(&data,true);
12837 // blizz like 2.0.x
12838 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12839 // blizz like 2.0.x
12840 RemoveFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12841 // blizz like 2.0.x
12842 RemoveFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12844 clearUnitState(UNIT_STAT_DIED
);
12846 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12848 // restore appropriate movement generator
12850 GetMotionMaster()->MoveChase(getVictim());
12852 GetMotionMaster()->Initialize();
12858 bool Unit::IsSitState() const
12860 uint8 s
= getStandState();
12862 s
== UNIT_STAND_STATE_SIT_CHAIR
|| s
== UNIT_STAND_STATE_SIT_LOW_CHAIR
||
12863 s
== UNIT_STAND_STATE_SIT_MEDIUM_CHAIR
|| s
== UNIT_STAND_STATE_SIT_HIGH_CHAIR
||
12864 s
== UNIT_STAND_STATE_SIT
;
12867 bool Unit::IsStandState() const
12869 uint8 s
= getStandState();
12870 return !IsSitState() && s
!= UNIT_STAND_STATE_SLEEP
&& s
!= UNIT_STAND_STATE_KNEEL
;
12873 void Unit::SetStandState(uint8 state
)
12875 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
12877 if (IsStandState())
12878 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
12880 if(GetTypeId()==TYPEID_PLAYER
)
12882 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
12883 data
<< (uint8
)state
;
12884 ((Player
*)this)->GetSession()->SendPacket(&data
);
12888 bool Unit::IsPolymorphed() const
12890 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
12893 void Unit::SetDisplayId(uint32 modelId
)
12895 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
12897 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
12899 Pet
*pet
= ((Pet
*)this);
12900 if(!pet
->isControlled())
12902 Unit
*owner
= GetOwner();
12903 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12904 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
12908 void Unit::ClearComboPointHolders()
12910 while(!m_ComboPointHolders
.empty())
12912 uint32 lowguid
= *m_ComboPointHolders
.begin();
12914 Player
* plr
= sObjectMgr
.GetPlayer(ObjectGuid(HIGHGUID_PLAYER
, lowguid
));
12915 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
12916 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
12918 m_ComboPointHolders
.erase(lowguid
); // or remove manually
12922 void Unit::ClearAllReactives()
12924 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
12925 m_reactiveTimer
[i
] = 0;
12927 if (HasAuraState( AURA_STATE_DEFENSE
))
12928 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12929 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
12930 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12931 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12932 ((Player
*)this)->ClearComboPoints();
12935 void Unit::UpdateReactives( uint32 p_time
)
12937 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
12939 ReactiveType reactive
= ReactiveType(i
);
12941 if(!m_reactiveTimer
[reactive
])
12944 if ( m_reactiveTimer
[reactive
] <= p_time
)
12946 m_reactiveTimer
[reactive
] = 0;
12948 switch ( reactive
)
12950 case REACTIVE_DEFENSE
:
12951 if (HasAuraState(AURA_STATE_DEFENSE
))
12952 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12954 case REACTIVE_HUNTER_PARRY
:
12955 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
12956 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12958 case REACTIVE_OVERPOWER
:
12959 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12960 ((Player
*)this)->ClearComboPoints();
12968 m_reactiveTimer
[reactive
] -= p_time
;
12973 Unit
* Unit::SelectRandomUnfriendlyTarget(Unit
* except
/*= NULL*/, float radius
/*= ATTACK_DISTANCE*/) const
12975 std::list
<Unit
*> targets
;
12977 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, radius
);
12978 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
12979 Cell::VisitAllObjects(this, searcher
, radius
);
12981 // remove current target
12983 targets
.remove(except
);
12985 // remove not LoS targets
12986 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
12988 if(!IsWithinLOSInMap(*tIter
))
12990 std::list
<Unit
*>::iterator tIter2
= tIter
;
12992 targets
.erase(tIter2
);
12998 // no appropriate targets
12999 if(targets
.empty())
13003 uint32 rIdx
= urand(0,targets
.size()-1);
13004 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
13005 for(uint32 i
= 0; i
< rIdx
; ++i
)
13011 Unit
* Unit::SelectRandomFriendlyTarget(Unit
* except
/*= NULL*/, float radius
/*= ATTACK_DISTANCE*/) const
13013 std::list
<Unit
*> targets
;
13015 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(this, radius
);
13016 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
13018 Cell::VisitAllObjects(this, searcher
, radius
);
13019 // remove current target
13021 targets
.remove(except
);
13023 // remove not LoS targets
13024 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
13026 if(!IsWithinLOSInMap(*tIter
))
13028 std::list
<Unit
*>::iterator tIter2
= tIter
;
13030 targets
.erase(tIter2
);
13036 // no appropriate targets
13037 if(targets
.empty())
13041 uint32 rIdx
= urand(0,targets
.size()-1);
13042 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
13043 for(uint32 i
= 0; i
< rIdx
; ++i
)
13049 bool Unit::hasNegativeAuraWithInterruptFlag(uint32 flag
)
13051 for (AuraMap::const_iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); ++iter
)
13053 if (!iter
->second
->IsPositive() && iter
->second
->GetSpellProto()->AuraInterruptFlags
& flag
)
13059 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
13063 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
13064 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
13068 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
13069 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
13073 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
13076 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
13078 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
13081 void Unit::UpdateAuraForGroup(uint8 slot
)
13083 if(GetTypeId() == TYPEID_PLAYER
)
13085 Player
* player
= (Player
*)this;
13086 if(player
->GetGroup())
13088 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
13089 player
->SetAuraUpdateMask(slot
);
13092 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
13094 Pet
*pet
= ((Pet
*)this);
13095 if(pet
->isControlled())
13097 Unit
*owner
= GetOwner();
13098 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
13100 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
13101 pet
->SetAuraUpdateMask(slot
);
13107 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
13109 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
13110 return float(GetAttackTime(attType
))/1000.0f
;
13112 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
, true, false);
13114 return 2.4f
; // fist attack
13116 switch (Weapon
->GetProto()->InventoryType
)
13118 case INVTYPE_2HWEAPON
:
13120 case INVTYPE_RANGED
:
13121 case INVTYPE_RANGEDRIGHT
:
13122 case INVTYPE_THROWN
:
13124 case INVTYPE_WEAPON
:
13125 case INVTYPE_WEAPONMAINHAND
:
13126 case INVTYPE_WEAPONOFFHAND
:
13128 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7f
: 2.4f
;
13132 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
13134 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
13135 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
13136 if ((*itr
)->GetId() == spell_id
)
13142 void Unit::SetContestedPvP(Player
*attackedPlayer
)
13144 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
13146 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
13149 player
->SetContestedPvPTimer(30000);
13150 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
13152 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
13153 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
13154 // call MoveInLineOfSight for nearby contested guards
13155 SetVisibility(GetVisibility());
13157 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
13159 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
13160 // call MoveInLineOfSight for nearby contested guards
13161 SetVisibility(GetVisibility());
13165 void Unit::AddPetAura(PetAura
const* petSpell
)
13167 m_petAuras
.insert(petSpell
);
13168 if(Pet
* pet
= GetPet())
13169 pet
->CastPetAura(petSpell
);
13172 void Unit::RemovePetAura(PetAura
const* petSpell
)
13174 m_petAuras
.erase(petSpell
);
13175 if(Pet
* pet
= GetPet())
13176 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
13179 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
13181 Pet
* pet
= new Pet(HUNTER_PET
);
13183 if(!pet
->CreateBaseAtCreature(creatureTarget
))
13189 pet
->SetOwnerGUID(GetGUID());
13190 pet
->SetCreatorGUID(GetGUID());
13191 pet
->setFaction(getFaction());
13192 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
13194 if(GetTypeId()==TYPEID_PLAYER
)
13195 pet
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
13201 pet
->SetFFAPvP(true);
13203 uint32 level
= (creatureTarget
->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget
->getLevel();
13205 if(!pet
->InitStatsForLevel(level
))
13207 sLog
.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
13212 pet
->GetCharmInfo()->SetPetNumber(sObjectMgr
.GeneratePetNumber(), true);
13213 // this enables pet details window (Shift+P)
13214 pet
->AIM_Initialize();
13215 pet
->InitPetCreateSpells();
13216 pet
->InitLevelupSpellsForLevel();
13217 pet
->InitTalentForLevel();
13218 pet
->SetHealth(pet
->GetMaxHealth());
13223 bool Unit::IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
13225 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
13227 // Get proc Event Entry
13228 spellProcEvent
= sSpellMgr
.GetSpellProcEvent(spellProto
->Id
);
13230 // Aura info stored here
13231 Modifier
*mod
= aura
->GetModifier();
13233 if (isNonTriggerAura
[mod
->m_auraname
])
13235 // If not trigger by default and spellProcEvent==NULL - skip
13236 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
13239 // Get EventProcFlag
13240 uint32 EventProcFlag
;
13241 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
13242 EventProcFlag
= spellProcEvent
->procFlags
;
13244 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
13245 // Continue if no trigger exist
13246 if (!EventProcFlag
)
13249 // Check spellProcEvent data requirements
13250 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
13253 // In most cases req get honor or XP from kill
13254 if (EventProcFlag
& PROC_FLAG_KILL
&& GetTypeId() == TYPEID_PLAYER
)
13256 bool allow
= ((Player
*)this)->isHonorOrXPTarget(pVictim
);
13257 // Shadow Word: Death - can trigger from every kill
13258 if (aura
->GetId() == 32409)
13263 // Aura added by spell can`t trogger from self (prevent drop charges/do triggers)
13264 // But except periodic triggers (can triggered from self)
13265 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
& PROC_FLAG_ON_TAKE_PERIODIC
))
13268 // Check if current equipment allows aura to proc
13269 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
13271 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
13274 if(attType
== BASE_ATTACK
)
13275 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
13276 else if (attType
== OFF_ATTACK
)
13277 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
13279 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
13281 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
13284 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
13286 // Check if player is wearing shield
13287 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
13288 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
13292 // Get chance from spell
13293 float chance
= (float)spellProto
->procChance
;
13294 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
13295 if(spellProcEvent
&& spellProcEvent
->customChance
)
13296 chance
= spellProcEvent
->customChance
;
13297 // If PPM exist calculate chance from PPM
13298 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
13300 uint32 WeaponSpeed
= GetAttackTime(attType
);
13301 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
13303 // Apply chance modifer aura
13304 if(Player
* modOwner
= GetSpellModOwner())
13306 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
13307 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_FREQUENCY_OF_SUCCESS
,chance
);
13310 return roll_chance_f(chance
);
13313 bool Unit::HandleMendingAuraProc( Aura
* triggeredByAura
)
13315 // aura can be deleted at casts
13316 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
13317 SpellEffectIndex effIdx
= triggeredByAura
->GetEffIndex();
13318 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
13319 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
13322 int32 jumps
= triggeredByAura
->GetAuraCharges()-1;
13324 // current aura expire
13325 triggeredByAura
->SetAuraCharges(1); // will removed at next charges decrease
13327 // next target selection
13328 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
13331 if (spellProto
->EffectRadiusIndex
[effIdx
])
13332 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
13334 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
13336 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
13338 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
13340 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
13342 // aura will applied from caster, but spell casted from current aura holder
13343 SpellModifier
*mod
= new SpellModifier(SPELLMOD_CHARGES
,SPELLMOD_FLAT
,jumps
-5,spellProto
->Id
,spellProto
->SpellFamilyFlags
,spellProto
->SpellFamilyFlags2
);
13345 // remove before apply next (locked against deleted)
13346 triggeredByAura
->SetInUse(true);
13347 RemoveAurasByCasterSpell(spellProto
->Id
,caster
->GetGUID());
13349 caster
->AddSpellMod(mod
, true);
13350 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
13351 caster
->AddSpellMod(mod
, false);
13352 triggeredByAura
->SetInUse(false);
13358 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
13362 void Unit::RemoveAurasAtMechanicImmunity(uint32 mechMask
, uint32 exceptSpellId
, bool non_positive
/*= false*/)
13364 Unit::AuraMap
& auras
= GetAuras();
13365 for(Unit::AuraMap::iterator iter
= auras
.begin(); iter
!= auras
.end();)
13367 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
13368 if (spell
->Id
== exceptSpellId
)
13370 else if (non_positive
&& iter
->second
->IsPositive())
13372 else if (spell
->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
)
13374 else if (GetSpellMechanicMask(spell
, iter
->second
->GetEffIndex()) & mechMask
)
13376 RemoveAurasDueToSpell(spell
->Id
);
13380 iter
= auras
.begin();
13387 void Unit::SetPhaseMask(uint32 newPhaseMask
, bool update
)
13389 if(newPhaseMask
==GetPhaseMask())
13393 RemoveNotOwnSingleTargetAuras(newPhaseMask
); // we can lost access to caster or target
13395 WorldObject::SetPhaseMask(newPhaseMask
,update
);
13398 if(Pet
* pet
= GetPet())
13399 pet
->SetPhaseMask(newPhaseMask
,true);
13402 void Unit::NearTeleportTo( float x
, float y
, float z
, float orientation
, bool casting
/*= false*/ )
13404 if(GetTypeId() == TYPEID_PLAYER
)
13405 ((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));
13408 Creature
* c
= (Creature
*)this;
13409 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13410 if (!c
->GetMotionMaster()->empty())
13411 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13412 movgen
->Interrupt(*c
);
13414 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, orientation
);
13417 BuildHeartBeatMsg(&data
);
13418 SendMessageToSet(&data
, false);
13419 // finished relocation, movegen can different from top before creature relocation,
13420 // but apply Reset expected to be safe in any case
13421 if (!c
->GetMotionMaster()->empty())
13422 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13427 void Unit::MonsterMove(float x
, float y
, float z
, uint32 transitTime
)
13429 SplineFlags flags
= GetTypeId() == TYPEID_PLAYER
? SPLINEFLAG_WALKMODE
: ((Creature
*)this)->GetSplineFlags();
13430 SendMonsterMove(x
, y
, z
, SPLINETYPE_NORMAL
, flags
, transitTime
);
13432 if (GetTypeId() != TYPEID_PLAYER
)
13434 Creature
* c
= (Creature
*)this;
13435 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13436 if (!c
->GetMotionMaster()->empty())
13437 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13438 movgen
->Interrupt(*c
);
13440 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, 0.0f
);
13442 // finished relocation, movegen can different from top before creature relocation,
13443 // but apply Reset expected to be safe in any case
13444 if (!c
->GetMotionMaster()->empty())
13445 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13450 void Unit::MonsterMoveWithSpeed(float x
, float y
, float z
, uint32 transitTime
)
13452 SendMonsterMoveWithSpeed(x
, y
, z
, transitTime
);
13454 if (GetTypeId() != TYPEID_PLAYER
)
13456 Creature
* c
= (Creature
*)this;
13457 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13458 if (!c
->GetMotionMaster()->empty())
13459 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13460 movgen
->Interrupt(*c
);
13462 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, 0.0f
);
13464 // finished relocation, movegen can different from top before creature relocation,
13465 // but apply Reset expected to be safe in any case
13466 if (!c
->GetMotionMaster()->empty())
13467 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13472 struct SetPvPHelper
13474 explicit SetPvPHelper(bool _state
) : state(_state
) {}
13475 void operator()(Unit
* unit
) const { unit
->SetPvP(state
); }
13479 void Unit::SetPvP( bool state
)
13482 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13484 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13486 CallForAllControlledUnits(SetPvPHelper(state
),true,true,true);
13489 struct SetFFAPvPHelper
13491 explicit SetFFAPvPHelper(bool _state
) : state(_state
) {}
13492 void operator()(Unit
* unit
) const { unit
->SetFFAPvP(state
); }
13496 void Unit::SetFFAPvP( bool state
)
13499 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13501 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13503 CallForAllControlledUnits(SetFFAPvPHelper(state
),true,true,true);
13506 void Unit::KnockBackFrom(Unit
* target
, float horizontalSpeed
, float verticalSpeed
)
13508 float angle
= this == target
? GetOrientation() + M_PI_F
: target
->GetAngle(this);
13509 float vsin
= sin(angle
);
13510 float vcos
= cos(angle
);
13512 // Effect propertly implemented only for players
13513 if(GetTypeId()==TYPEID_PLAYER
)
13515 WorldPacket
data(SMSG_MOVE_KNOCK_BACK
, 8+4+4+4+4+4);
13516 data
<< GetPackGUID();
13517 data
<< uint32(0); // Sequence
13518 data
<< float(vcos
); // x direction
13519 data
<< float(vsin
); // y direction
13520 data
<< float(horizontalSpeed
); // Horizontal speed
13521 data
<< float(-verticalSpeed
); // Z Movement speed (vertical)
13522 ((Player
*)this)->GetSession()->SendPacket(&data
);
13526 float dis
= horizontalSpeed
;
13529 GetPosition(ox
, oy
, oz
);
13531 float fx
= ox
+ dis
* vcos
;
13532 float fy
= oy
+ dis
* vsin
;
13535 float fx2
, fy2
, fz2
; // getObjectHitPos overwrite last args in any result case
13536 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), ox
,oy
,oz
+0.5f
, fx
,fy
,oz
+0.5f
,fx2
,fy2
,fz2
, -0.5f
))
13543 UpdateGroundPositionZ(fx
, fy
, fz
);
13545 //FIXME: this mostly hack, must exist some packet for proper creature move at client side
13546 // with CreatureRelocation at server side
13547 NearTeleportTo(fx
, fy
, fz
, GetOrientation(), this == target
);
13551 float Unit::GetCombatRatingReduction(CombatRating cr
) const
13553 if (GetTypeId() == TYPEID_PLAYER
)
13554 return ((Player
const*)this)->GetRatingBonusValue(cr
);
13555 else if (((Creature
const*)this)->isPet())
13557 // Player's pet have 0.4 resilience from owner
13558 if (Unit
* owner
= GetOwner())
13559 if(owner
->GetTypeId() == TYPEID_PLAYER
)
13560 return ((Player
*)owner
)->GetRatingBonusValue(cr
) * 0.4f
;
13566 uint32
Unit::GetCombatRatingDamageReduction(CombatRating cr
, float rate
, float cap
, uint32 damage
) const
13568 float percent
= GetCombatRatingReduction(cr
) * rate
;
13571 return uint32 (percent
* damage
/ 100.0f
);
13574 void Unit::SendThreatUpdate()
13576 ThreatList
const& tlist
= getThreatManager().getThreatList();
13577 if (uint32 count
= tlist
.size())
13579 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "WORLD: Send SMSG_THREAT_UPDATE Message");
13580 WorldPacket
data(SMSG_THREAT_UPDATE
, 8 + count
* 8);
13581 data
<< GetPackGUID();
13582 data
<< uint32(count
);
13583 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13585 data
.appendPackGUID((*itr
)->getUnitGuid());
13586 data
<< uint32((*itr
)->getThreat());
13588 SendMessageToSet(&data
, false);
13592 void Unit::SendHighestThreatUpdate(HostileReference
* pHostilReference
)
13594 ThreatList
const& tlist
= getThreatManager().getThreatList();
13595 if (uint32 count
= tlist
.size())
13597 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message");
13598 WorldPacket
data(SMSG_HIGHEST_THREAT_UPDATE
, 8 + 8 + count
* 8);
13599 data
<< GetPackGUID();
13600 data
.appendPackGUID(pHostilReference
->getUnitGuid());
13601 data
<< uint32(count
);
13602 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13604 data
.appendPackGUID((*itr
)->getUnitGuid());
13605 data
<< uint32((*itr
)->getThreat());
13607 SendMessageToSet(&data
, false);
13611 void Unit::SendThreatClear()
13613 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "WORLD: Send SMSG_THREAT_CLEAR Message");
13614 WorldPacket
data(SMSG_THREAT_CLEAR
, 8);
13615 data
<< GetPackGUID();
13616 SendMessageToSet(&data
, false);
13619 void Unit::SendThreatRemove(HostileReference
* pHostileReference
)
13621 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "WORLD: Send SMSG_THREAT_REMOVE Message");
13622 WorldPacket
data(SMSG_THREAT_REMOVE
, 8 + 8);
13623 data
<< GetPackGUID();
13624 data
.appendPackGUID(pHostileReference
->getUnitGuid());
13625 SendMessageToSet(&data
, false);
13628 struct StopAttackFactionHelper
13630 explicit StopAttackFactionHelper(uint32 _faction_id
) : faction_id(_faction_id
) {}
13631 void operator()(Unit
* unit
) const { unit
->StopAttackFaction(faction_id
); }
13635 void Unit::StopAttackFaction(uint32 faction_id
)
13637 if (Unit
* victim
= getVictim())
13639 if (victim
->getFactionTemplateEntry()->faction
==faction_id
)
13642 if (IsNonMeleeSpellCasted(false))
13643 InterruptNonMeleeSpells(false);
13645 // melee and ranged forced attack cancel
13646 if (GetTypeId() == TYPEID_PLAYER
)
13647 ((Player
*)this)->SendAttackSwingCancelAttack();
13651 AttackerSet
const& attackers
= getAttackers();
13652 for(AttackerSet::const_iterator itr
= attackers
.begin(); itr
!= attackers
.end();)
13654 if ((*itr
)->getFactionTemplateEntry()->faction
==faction_id
)
13656 (*itr
)->AttackStop();
13657 itr
= attackers
.begin();
13663 getHostileRefManager().deleteReferencesForFaction(faction_id
);
13665 CallForAllControlledUnits(StopAttackFactionHelper(faction_id
),false,true,true);
13668 void Unit::CleanupDeletedAuras()
13670 // really delete auras "deleted" while processing its ApplyModify code
13671 for(AuraList::const_iterator itr
= m_deletedAuras
.begin(); itr
!= m_deletedAuras
.end(); ++itr
)
13673 m_deletedAuras
.clear();
13676 bool Unit::CheckAndIncreaseCastCounter()
13678 uint32 maxCasts
= sWorld
.getConfig(CONFIG_UINT32_MAX_SPELL_CASTS_IN_CHAIN
);
13680 if (maxCasts
&& m_castCounter
>= maxCasts
)