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 if (triggeredByAura
)
1070 sLog
.outError("CastSpell: unknown spell id %i by caster: %s triggered by aura %u (eff %u)", spellId
, GetObjectGuid().GetString().c_str(), triggeredByAura
->GetId(), triggeredByAura
->GetEffIndex());
1072 sLog
.outError("CastSpell: unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1076 CastSpell(Victim
, spellInfo
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1079 void Unit::CastSpell(Unit
* Victim
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1083 if (triggeredByAura
)
1084 sLog
.outError("CastSpell: unknown spell by caster: %s triggered by aura %u (eff %u)", GetObjectGuid().GetString().c_str(), triggeredByAura
->GetId(), triggeredByAura
->GetEffIndex());
1086 sLog
.outError("CastSpell: unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1091 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "WORLD: cast Item spellId - %i", spellInfo
->Id
);
1093 if(originalCaster
.IsEmpty() && triggeredByAura
)
1094 originalCaster
= triggeredByAura
->GetCasterGUID();
1096 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1098 SpellCastTargets targets
;
1099 targets
.setUnitTarget( Victim
);
1100 spell
->m_CastItem
= castItem
;
1101 spell
->prepare(&targets
, triggeredByAura
);
1104 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1106 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1110 if (triggeredByAura
)
1111 sLog
.outError("CastCustomSpell: unknown spell id %i by caster: %s triggered by aura %u (eff %u)", spellId
, GetObjectGuid().GetString().c_str(), triggeredByAura
->GetId(), triggeredByAura
->GetEffIndex());
1113 sLog
.outError("CastCustomSpell: unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1117 CastCustomSpell(Victim
, spellInfo
, bp0
, bp1
, bp2
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1120 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
)
1124 if (triggeredByAura
)
1125 sLog
.outError("CastCustomSpell: unknown spell by caster: %s triggered by aura %u (eff %u)", GetObjectGuid().GetString().c_str(), triggeredByAura
->GetId(), triggeredByAura
->GetEffIndex());
1127 sLog
.outError("CastCustomSpell: unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1132 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "WORLD: cast Item spellId - %i", spellInfo
->Id
);
1134 if(originalCaster
.IsEmpty() && triggeredByAura
)
1135 originalCaster
= triggeredByAura
->GetCasterGUID();
1137 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1140 spell
->m_currentBasePoints
[EFFECT_INDEX_0
] = *bp0
;
1143 spell
->m_currentBasePoints
[EFFECT_INDEX_1
] = *bp1
;
1146 spell
->m_currentBasePoints
[EFFECT_INDEX_2
] = *bp2
;
1148 SpellCastTargets targets
;
1149 targets
.setUnitTarget( Victim
);
1150 spell
->m_CastItem
= castItem
;
1151 spell
->prepare(&targets
, triggeredByAura
);
1154 // used for scripting
1155 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1157 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1161 if (triggeredByAura
)
1162 sLog
.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s triggered by aura %u (eff %u)", spellId
, GetObjectGuid().GetString().c_str(), triggeredByAura
->GetId(), triggeredByAura
->GetEffIndex());
1164 sLog
.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1168 CastSpell(x
, y
, z
, spellInfo
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1171 // used for scripting
1172 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1176 if (triggeredByAura
)
1177 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s triggered by aura %u (eff %u)", GetObjectGuid().GetString().c_str(), triggeredByAura
->GetId(), triggeredByAura
->GetEffIndex());
1179 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1184 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "WORLD: cast Item spellId - %i", spellInfo
->Id
);
1186 if(originalCaster
.IsEmpty() && triggeredByAura
)
1187 originalCaster
= triggeredByAura
->GetCasterGUID();
1189 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1191 SpellCastTargets targets
;
1192 targets
.setDestination(x
, y
, z
);
1193 spell
->m_CastItem
= castItem
;
1194 spell
->prepare(&targets
, triggeredByAura
);
1197 // Obsolete func need remove, here only for comotability vs another patches
1198 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
)
1200 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
1201 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, SpellSchoolMask(spellInfo
->SchoolMask
));
1202 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
1203 damageInfo
.target
->CalculateAbsorbResistBlock(this, &damageInfo
, spellInfo
);
1204 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
1205 SendSpellNonMeleeDamageLog(&damageInfo
);
1206 DealSpellDamage(&damageInfo
, true);
1207 return damageInfo
.damage
;
1210 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
1212 SpellSchoolMask damageSchoolMask
= damageInfo
->schoolMask
;
1213 Unit
*pVictim
= damageInfo
->target
;
1218 if(!this || !pVictim
)
1220 if(!this->isAlive() || !pVictim
->isAlive())
1223 // Check spell crit chance
1224 bool crit
= IsSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
1226 // damage bonus (per damage class)
1227 switch (spellInfo
->DmgClass
)
1229 // Melee and Ranged Spells
1230 case SPELL_DAMAGE_CLASS_RANGED
:
1231 case SPELL_DAMAGE_CLASS_MELEE
:
1233 //Calculate damage bonus
1234 damage
= MeleeDamageBonusDone(pVictim
, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1235 damage
= pVictim
->MeleeDamageBonusTaken(this, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1237 // if crit add critical bonus
1240 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1241 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1242 // Resilience - reduce crit damage
1243 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1244 if (attackType
!= RANGED_ATTACK
)
1245 damage
-= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1247 damage
-= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1252 case SPELL_DAMAGE_CLASS_NONE
:
1253 case SPELL_DAMAGE_CLASS_MAGIC
:
1255 // Calculate damage bonus
1256 damage
= SpellDamageBonusDone(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1257 damage
= pVictim
->SpellDamageBonusTaken(this, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1259 // If crit add critical bonus
1262 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1263 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1264 // Resilience - reduce crit damage
1265 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1266 damage
-= pVictim
->GetSpellCritDamageReduction(redunction_affected_damage
);
1272 // only from players
1273 if (GetTypeId() == TYPEID_PLAYER
)
1275 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1276 damage
-= pVictim
->GetSpellDamageReduction(redunction_affected_damage
);
1279 // damage mitigation
1282 // physical damage => armor
1283 if (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
1285 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1286 damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(pVictim
, armor_affected_damage
);
1291 damageInfo
->damage
= damage
;
1294 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1299 Unit
*pVictim
= damageInfo
->target
;
1301 if(!this || !pVictim
)
1304 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1307 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1308 if (spellProto
== NULL
)
1310 sLog
.outError("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1314 //You don't lose health from damage taken from another player while in a sanctuary
1315 //You still see it in the combat log though
1316 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1318 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1319 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1323 // Call default DealDamage (send critical in hit info for threat calculation)
1324 CleanDamage
cleanDamage(0, BASE_ATTACK
, damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
? MELEE_HIT_CRIT
: MELEE_HIT_NORMAL
);
1325 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, damageInfo
->schoolMask
, spellProto
, durabilityLoss
);
1328 //TODO for melee need create structure as in
1329 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1331 damageInfo
->attacker
= this;
1332 damageInfo
->target
= pVictim
;
1333 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1334 damageInfo
->attackType
= attackType
;
1335 damageInfo
->damage
= 0;
1336 damageInfo
->cleanDamage
= 0;
1337 damageInfo
->absorb
= 0;
1338 damageInfo
->resist
= 0;
1339 damageInfo
->blocked_amount
= 0;
1341 damageInfo
->TargetState
= 0;
1342 damageInfo
->HitInfo
= 0;
1343 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1344 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1345 damageInfo
->procEx
= PROC_EX_NONE
;
1346 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1348 if(!this || !pVictim
)
1350 if(!this->isAlive() || !pVictim
->isAlive())
1353 // Select HitInfo/procAttacker/procVictim flag based on attack type
1357 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
;
1358 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1359 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1362 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1363 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1364 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1367 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1368 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1369 damageInfo
->HitInfo
= 0x08;// test
1375 // Physical Immune check
1376 if (damageInfo
->target
->IsImmunedToDamage(damageInfo
->damageSchoolMask
))
1378 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1379 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1381 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1382 damageInfo
->damage
= 0;
1383 damageInfo
->cleanDamage
= 0;
1386 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1387 // Add melee damage bonus
1388 damage
= MeleeDamageBonusDone(damageInfo
->target
, damage
, damageInfo
->attackType
);
1389 damage
= damageInfo
->target
->MeleeDamageBonusTaken(this, damage
, damageInfo
->attackType
);
1390 // Calculate armor reduction
1392 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageInfo
->damageSchoolMask
);
1393 damageInfo
->damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(damageInfo
->target
, armor_affected_damage
);
1394 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1396 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1398 // Disable parry or dodge for ranged attack
1399 if (damageInfo
->attackType
== RANGED_ATTACK
)
1401 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1402 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1405 switch(damageInfo
->hitOutCome
)
1407 case MELEE_HIT_EVADE
:
1409 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1410 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1412 damageInfo
->procEx
|=PROC_EX_EVADE
;
1413 damageInfo
->damage
= 0;
1414 damageInfo
->cleanDamage
= 0;
1417 case MELEE_HIT_MISS
:
1419 damageInfo
->HitInfo
|= HITINFO_MISS
;
1420 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1422 damageInfo
->procEx
|=PROC_EX_MISS
;
1423 damageInfo
->damage
= 0;
1424 damageInfo
->cleanDamage
= 0;
1427 case MELEE_HIT_NORMAL
:
1428 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1429 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1431 case MELEE_HIT_CRIT
:
1433 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1434 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1436 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1438 damageInfo
->damage
+= damageInfo
->damage
;
1440 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1441 if(damageInfo
->attackType
== RANGED_ATTACK
)
1442 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1444 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1446 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, SPELL_SCHOOL_MASK_NORMAL
);
1448 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1450 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1451 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1453 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1455 // Resilience - reduce crit damage
1456 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1457 uint32 resilienceReduction
;
1458 if (attackType
!= RANGED_ATTACK
)
1459 resilienceReduction
= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1461 resilienceReduction
= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1463 damageInfo
->damage
-= resilienceReduction
;
1464 damageInfo
->cleanDamage
+= resilienceReduction
;
1467 case MELEE_HIT_PARRY
:
1468 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1469 damageInfo
->procEx
|= PROC_EX_PARRY
;
1470 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1471 damageInfo
->damage
= 0;
1474 case MELEE_HIT_DODGE
:
1475 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1476 damageInfo
->procEx
|=PROC_EX_DODGE
;
1477 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1478 damageInfo
->damage
= 0;
1480 case MELEE_HIT_BLOCK
:
1482 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1483 damageInfo
->HitInfo
|= HITINFO_BLOCK
;
1484 damageInfo
->procEx
|= PROC_EX_BLOCK
;
1485 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1487 // Target has a chance to double the blocked amount if it has SPELL_AURA_MOD_BLOCK_CRIT_CHANCE
1488 if (roll_chance_i(pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_CRIT_CHANCE
)))
1489 damageInfo
->blocked_amount
*= 2;
1491 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1493 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1494 damageInfo
->blocked_amount
= damageInfo
->damage
;
1495 damageInfo
->procEx
|= PROC_EX_FULL_BLOCK
;
1498 damageInfo
->procEx
|= PROC_EX_NORMAL_HIT
; // Partial blocks can still cause attacker procs
1500 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1501 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1504 case MELEE_HIT_GLANCING
:
1506 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1507 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1508 damageInfo
->procEx
|= PROC_EX_NORMAL_HIT
;
1509 float reducePercent
= 1.0f
; //damage factor
1510 // calculate base values and mods
1511 float baseLowEnd
= 1.3f
;
1512 float baseHighEnd
= 1.2f
;
1513 switch(getClass()) // lowering base values for casters
1521 baseHighEnd
-= 0.3f
;
1525 float maxLowEnd
= 0.6f
;
1526 switch(getClass()) // upper for melee classes
1530 maxLowEnd
= 0.91f
; //If the attacker is a melee class then instead the lower value of 0.91
1534 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1535 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1536 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1538 // apply max/min bounds
1539 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1541 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1544 if ( highEnd
< 0.2f
) //high end limits
1546 if ( highEnd
> 0.99f
)
1549 if(lowEnd
> highEnd
) // prevent negative range size
1552 reducePercent
= lowEnd
+ rand_norm_f() * ( highEnd
- lowEnd
);
1554 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1555 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1558 case MELEE_HIT_CRUSHING
:
1560 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1561 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1562 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1563 // 150% normal damage
1564 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1572 // only from players
1573 if (GetTypeId() == TYPEID_PLAYER
)
1575 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1576 uint32 resilienceReduction
;
1577 if (attackType
!= RANGED_ATTACK
)
1578 resilienceReduction
= pVictim
->GetMeleeDamageReduction(redunction_affected_damage
);
1580 resilienceReduction
= pVictim
->GetRangedDamageReduction(redunction_affected_damage
);
1581 damageInfo
->damage
-= resilienceReduction
;
1582 damageInfo
->cleanDamage
+= resilienceReduction
;
1585 // Calculate absorb resist
1586 if(int32(damageInfo
->damage
) > 0)
1588 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1590 // Calculate absorb & resists
1591 uint32 absorb_affected_damage
= CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1592 damageInfo
->target
->CalculateAbsorbAndResist(this, damageInfo
->damageSchoolMask
, DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, true);
1593 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1594 if (damageInfo
->absorb
)
1596 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1597 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1599 if (damageInfo
->resist
)
1600 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1603 else // Umpossible get negative result but....
1604 damageInfo
->damage
= 0;
1607 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1609 if (damageInfo
==0) return;
1610 Unit
*pVictim
= damageInfo
->target
;
1612 if(!this || !pVictim
)
1615 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1618 //You don't lose health from damage taken from another player while in a sanctuary
1619 //You still see it in the combat log though
1620 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1622 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1623 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1627 // Hmmmm dont like this emotes client must by self do all animations
1628 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1629 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1630 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1631 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1633 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1635 // Get attack timers
1636 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1637 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1638 // Reduce attack time
1639 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1641 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20f
;
1642 float percent60
= 3.0f
* percent20
;
1643 if(offtime
> percent20
&& offtime
<= percent60
)
1645 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1647 else if(offtime
> percent60
)
1649 offtime
-= 2.0f
* percent20
;
1650 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1655 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20f
;
1656 float percent60
= 3.0f
* percent20
;
1657 if(basetime
> percent20
&& basetime
<= percent60
)
1659 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1661 else if(basetime
> percent60
)
1663 basetime
-= 2.0f
* percent20
;
1664 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1669 // Call default DealDamage
1670 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1671 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, damageInfo
->damageSchoolMask
, NULL
, durabilityLoss
);
1673 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1674 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1675 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI_F
, this) )
1677 // -probability is between 0% and 40%
1679 float Probability
= 20.0f
;
1681 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1682 if( pVictim
->getLevel() < 30 )
1683 Probability
= 0.65f
*pVictim
->getLevel()+0.5f
;
1685 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1686 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1688 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1690 if(Probability
> 40.0f
)
1691 Probability
= 40.0f
;
1693 if(roll_chance_f(Probability
))
1694 CastSpell(pVictim
, 1604, true);
1698 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1700 // on weapon hit casts
1701 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1702 ((Player
*)this)->CastItemCombatSpell(pVictim
, damageInfo
->attackType
);
1704 // victim's damage shield
1705 std::set
<Aura
*> alreadyDone
;
1706 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1707 for(AuraList::const_iterator i
= vDamageShields
.begin(); i
!= vDamageShields
.end();)
1709 if (alreadyDone
.find(*i
) == alreadyDone
.end())
1711 alreadyDone
.insert(*i
);
1712 uint32 damage
=(*i
)->GetModifier()->m_amount
;
1713 SpellEntry
const *i_spellProto
= (*i
)->GetSpellProto();
1714 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
1717 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1718 //damage-=absorb + resist;
1720 pVictim
->DealDamageMods(this,damage
,NULL
);
1722 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4+4+4));
1723 data
<< uint64(pVictim
->GetGUID());
1724 data
<< uint64(GetGUID());
1725 data
<< uint32(i_spellProto
->Id
);
1726 data
<< uint32(damage
); // Damage
1727 data
<< uint32(0); // Overkill
1728 data
<< uint32(i_spellProto
->SchoolMask
);
1729 pVictim
->SendMessageToSet(&data
, true );
1731 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(i_spellProto
), i_spellProto
, true);
1733 i
= vDamageShields
.begin();
1742 void Unit::HandleEmoteCommand(uint32 anim_id
)
1744 WorldPacket
data( SMSG_EMOTE
, 4 + 8 );
1745 data
<< uint32(anim_id
);
1746 data
<< uint64(GetGUID());
1747 SendMessageToSet(&data
, true);
1750 void Unit::HandleEmoteState(uint32 anim_id
)
1752 SetUInt32Value(UNIT_NPC_EMOTESTATE
, anim_id
);
1755 void Unit::HandleEmote(uint32 anim_id
)
1758 HandleEmoteState(0);
1759 else if (EmotesEntry
const* emoteEntry
= sEmotesStore
.LookupEntry(anim_id
))
1761 if (emoteEntry
->EmoteType
) // 1,2 states, 0 command
1762 HandleEmoteState(anim_id
);
1764 HandleEmoteCommand(anim_id
);
1768 uint32
Unit::CalcNotIgnoreAbsorbDamage( uint32 damage
, SpellSchoolMask damageSchoolMask
, SpellEntry
const* spellInfo
/*= NULL*/)
1770 float absorb_affected_rate
= 1.0f
;
1771 Unit::AuraList
const& ignoreAbsorbSchool
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_SCHOOL
);
1772 for(Unit::AuraList::const_iterator i
= ignoreAbsorbSchool
.begin(); i
!= ignoreAbsorbSchool
.end(); ++i
)
1773 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1774 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1778 Unit::AuraList
const& ignoreAbsorbForSpell
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL
);
1779 for(Unit::AuraList::const_iterator citr
= ignoreAbsorbForSpell
.begin(); citr
!= ignoreAbsorbForSpell
.end(); ++citr
)
1780 if ((*citr
)->isAffectedOnSpell(spellInfo
))
1781 absorb_affected_rate
*= (100.0f
- (*citr
)->GetModifier()->m_amount
)/100.0f
;
1784 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1787 uint32
Unit::CalcNotIgnoreDamageRedunction( uint32 damage
, SpellSchoolMask damageSchoolMask
)
1789 float absorb_affected_rate
= 1.0f
;
1790 Unit::AuraList
const& ignoreAbsorb
= GetAurasByType(SPELL_AURA_MOD_IGNORE_DAMAGE_REDUCTION_SCHOOL
);
1791 for(Unit::AuraList::const_iterator i
= ignoreAbsorb
.begin(); i
!= ignoreAbsorb
.end(); ++i
)
1792 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1793 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1795 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1798 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
1800 uint32 newdamage
= 0;
1801 float armor
= (float)pVictim
->GetArmor();
1803 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
1804 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
1806 // Apply Player CR_ARMOR_PENETRATION rating and percent talents
1807 if (GetTypeId()==TYPEID_PLAYER
)
1808 armor
*= 1.0f
- ((Player
*)this)->GetArmorPenetrationPct() / 100.0f
;
1813 float levelModifier
= (float)getLevel();
1814 if (levelModifier
> 59)
1815 levelModifier
= levelModifier
+ (4.5f
* (levelModifier
-59));
1817 float tmpvalue
= 0.1f
* armor
/ (8.5f
* levelModifier
+ 40);
1818 tmpvalue
= tmpvalue
/(1.0f
+ tmpvalue
);
1820 if (tmpvalue
< 0.0f
)
1822 if (tmpvalue
> 0.75f
)
1825 newdamage
= uint32(damage
- (damage
* tmpvalue
));
1827 return (newdamage
> 1) ? newdamage
: 1;
1830 void Unit::CalculateAbsorbAndResist(Unit
*pCaster
, SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
, bool canReflect
)
1832 if(!pCaster
|| !isAlive() || !damage
)
1835 // Magic damage, check for resists
1836 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
1838 // Get base victim resistance for school
1839 float tmpvalue2
= (float)GetResistance(GetFirstSchoolInMask(schoolMask
));
1840 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
1841 tmpvalue2
+= (float)pCaster
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
1843 tmpvalue2
*= (float)(0.15f
/ getLevel());
1844 if (tmpvalue2
< 0.0f
)
1846 if (tmpvalue2
> 0.75f
)
1848 uint32 ran
= urand(0, 100);
1849 float faq
[4] = {24.0f
,6.0f
,4.0f
,6.0f
};
1852 for (uint8 i
= 0; i
< 4; ++i
)
1854 Binom
+= 2400 *( powf(tmpvalue2
, float(i
)) * powf( (1-tmpvalue2
), float(4-i
)))/faq
[i
];
1860 if (damagetype
== DOT
&& m
== 4)
1861 *resist
+= uint32(damage
- 1);
1863 *resist
+= uint32(damage
* m
/ 4);
1864 if(*resist
> damage
)
1870 int32 RemainingDamage
= damage
- *resist
;
1872 // Get unit state (need for some absorb check)
1873 uint32 unitflag
= GetUInt32Value(UNIT_FIELD_FLAGS
);
1874 // Reflect damage spells (not cast any damage spell in aura lookup)
1875 uint32 reflectSpell
= 0;
1876 int32 reflectDamage
= 0;
1877 Aura
* reflectTriggeredBy
= NULL
; // expected as not expired at reflect as in current cases
1878 // Death Prevention Aura
1879 SpellEntry
const* preventDeathSpell
= NULL
;
1880 int32 preventDeathAmount
= 0;
1882 // full absorb cases (by chance)
1883 AuraList
const& vAbsorb
= GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1884 for(AuraList::const_iterator i
= vAbsorb
.begin(); i
!= vAbsorb
.end() && RemainingDamage
> 0; ++i
)
1886 // only work with proper school mask damage
1887 Modifier
* i_mod
= (*i
)->GetModifier();
1888 if (!(i_mod
->m_miscvalue
& schoolMask
))
1891 SpellEntry
const* i_spellProto
= (*i
)->GetSpellProto();
1892 // Fire Ward or Frost Ward
1893 if(i_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& i_spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000108))
1896 Unit::AuraList
const& auras
= GetAurasByType(SPELL_AURA_ADD_PCT_MODIFIER
);
1897 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
1899 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
1900 // Frost Warding (chance full absorb)
1901 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& itr_spellProto
->SpellIconID
== 501)
1903 // chance stored in next dummy effect
1904 chance
= itr_spellProto
->CalculateSimpleValue(EFFECT_INDEX_1
);
1908 if(roll_chance_i(chance
))
1910 int32 amount
= RemainingDamage
;
1911 RemainingDamage
= 0;
1913 // Frost Warding (mana regen)
1914 CastCustomSpell(this, 57776, &amount
, NULL
, NULL
, true, NULL
, *i
);
1920 // Need remove expired auras after
1921 bool existExpired
= false;
1923 // Incanter's Absorption, for converting to spell power
1924 int32 incanterAbsorption
= 0;
1926 // absorb without mana cost
1927 AuraList
const& vSchoolAbsorb
= GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1928 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; ++i
)
1930 Modifier
* mod
= (*i
)->GetModifier();
1931 if (!(mod
->m_miscvalue
& schoolMask
))
1934 SpellEntry
const* spellProto
= (*i
)->GetSpellProto();
1936 // Max Amount can be absorbed by this aura
1937 int32 currentAbsorb
= mod
->m_amount
;
1939 // Found empty aura (impossible but..)
1940 if (currentAbsorb
<=0)
1942 existExpired
= true;
1945 // Handle custom absorb auras
1946 // TODO: try find better way
1947 switch(spellProto
->SpellFamilyName
)
1949 case SPELLFAMILY_GENERIC
:
1952 if (spellProto
->SpellIconID
== 3066)
1954 //reduces all damage taken while stun, fear or silence
1955 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1956 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1960 if (spellProto
->SpellIconID
== 2115)
1962 // while affected by Stun and Fear
1963 if (unitflag
&(UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
))
1964 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1968 if (spellProto
->SpellIconID
== 3006)
1970 // You have a chance equal to your Parry chance
1971 if (damagetype
== SPELL_DIRECT_DAMAGE
&& // Only for direct spell damage
1972 roll_chance_f(GetUnitParryChance())) // Roll chance
1973 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1976 // Reflective Shield (Lady Malande boss)
1977 if (spellProto
->Id
== 41475 && canReflect
)
1979 if(RemainingDamage
< currentAbsorb
)
1980 reflectDamage
= RemainingDamage
/ 2;
1982 reflectDamage
= currentAbsorb
/ 2;
1983 reflectSpell
= 33619;
1984 reflectTriggeredBy
= *i
;
1987 if (spellProto
->Id
== 39228 || // Argussian Compass
1988 spellProto
->Id
== 60218) // Essence of Gossamer
1990 // Max absorb stored in 1 dummy effect
1991 int32 max_absorb
= spellProto
->CalculateSimpleValue(EFFECT_INDEX_1
);
1992 if (max_absorb
< currentAbsorb
)
1993 currentAbsorb
= max_absorb
;
1998 case SPELLFAMILY_DRUID
:
2001 if (spellProto
->SpellIconID
== 2253)
2003 //reduces all damage taken while Stunned and in Cat Form
2004 if (m_form
== FORM_CAT
&& (unitflag
& UNIT_FLAG_STUNNED
))
2005 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2010 case SPELLFAMILY_ROGUE
:
2012 // Cheat Death (make less prio with Guardian Spirit case)
2013 if (!preventDeathSpell
&& spellProto
->SpellIconID
== 2109 &&
2014 GetTypeId()==TYPEID_PLAYER
&& // Only players
2015 !((Player
*)this)->HasSpellCooldown(31231) &&
2016 // Only if no cooldown
2017 roll_chance_i((*i
)->GetModifier()->m_amount
))
2020 preventDeathSpell
= (*i
)->GetSpellProto();
2025 case SPELLFAMILY_PRIEST
:
2028 if (spellProto
->SpellIconID
== 2873)
2030 preventDeathSpell
= (*i
)->GetSpellProto();
2031 preventDeathAmount
= (*i
)->GetModifier()->m_amount
;
2034 // Reflective Shield
2035 if (spellProto
->SpellFamilyFlags
== 0x1 && canReflect
)
2037 if (pCaster
== this)
2039 Unit
* caster
= (*i
)->GetCaster();
2042 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
2043 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
2045 switch((*k
)->GetModifier()->m_miscvalue
)
2047 case 5065: // Rank 1
2048 case 5064: // Rank 2
2050 if(RemainingDamage
>= currentAbsorb
)
2051 reflectDamage
= (*k
)->GetModifier()->m_amount
* currentAbsorb
/100;
2053 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
2054 reflectSpell
= 33619;
2055 reflectTriggeredBy
= *i
;
2064 case SPELLFAMILY_SHAMAN
:
2067 if (spellProto
->SpellIconID
== 3066)
2069 //reduces all damage taken while stun, fear or silence
2070 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
2071 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2076 case SPELLFAMILY_DEATHKNIGHT
:
2079 if (spellProto
->SpellIconID
== 1958)
2081 // TODO: absorb only while transform
2084 // Anti-Magic Shell (on self)
2085 if (spellProto
->Id
== 48707)
2087 // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power.
2088 // This, if I'm not mistaken, shows that we get back ~2% of the absorbed damage as runic power.
2089 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
2090 int32 regen
= absorbed
* 2 / 10;
2091 CastCustomSpell(this, 49088, ®en
, NULL
, NULL
, true, NULL
, *i
);
2092 RemainingDamage
-= absorbed
;
2095 // Anti-Magic Shell (on single party/raid member)
2096 if (spellProto
->Id
== 50462)
2098 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2102 if (spellProto
->Id
== 50461)
2104 Unit
* caster
= (*i
)->GetCaster();
2107 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
2108 int32 canabsorb
= caster
->GetHealth();
2109 if (canabsorb
< absorbed
)
2110 absorbed
= canabsorb
;
2112 RemainingDamage
-= absorbed
;
2114 uint32 ab_damage
= absorbed
;
2115 pCaster
->DealDamageMods(caster
,ab_damage
,NULL
);
2116 pCaster
->DealDamage(caster
, ab_damage
, NULL
, damagetype
, schoolMask
, 0, false);
2125 // currentAbsorb - damage can be absorbed by shield
2126 // If need absorb less damage
2127 if (RemainingDamage
< currentAbsorb
)
2128 currentAbsorb
= RemainingDamage
;
2130 RemainingDamage
-= currentAbsorb
;
2132 // Fire Ward or Frost Ward or Ice Barrier (or Mana Shield)
2133 // for Incanter's Absorption converting to spell power
2134 if (spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& spellProto
->SpellFamilyFlags2
& 0x000008)
2135 incanterAbsorption
+= currentAbsorb
;
2137 // Reduce shield amount
2138 mod
->m_amount
-=currentAbsorb
;
2139 if((*i
)->DropAuraCharge())
2141 // Need remove it later
2142 if (mod
->m_amount
<=0)
2143 existExpired
= true;
2146 // Remove all expired absorb auras
2149 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end();)
2151 if ((*i
)->GetModifier()->m_amount
<=0)
2153 RemoveAurasDueToSpell((*i
)->GetId(), NULL
, AURA_REMOVE_BY_SHIELD_BREAK
);
2154 i
= vSchoolAbsorb
.begin();
2161 // Cast back reflect damage spell
2162 if (canReflect
&& reflectSpell
)
2163 CastCustomSpell(pCaster
, reflectSpell
, &reflectDamage
, NULL
, NULL
, true, NULL
, reflectTriggeredBy
);
2165 // absorb by mana cost
2166 AuraList
const& vManaShield
= GetAurasByType(SPELL_AURA_MANA_SHIELD
);
2167 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
2171 // check damage school mask
2172 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2175 int32 currentAbsorb
;
2176 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2177 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2179 currentAbsorb
= RemainingDamage
;
2181 if (float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()])
2183 if(Player
*modOwner
= GetSpellModOwner())
2184 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
2186 int32 maxAbsorb
= int32(GetPower(POWER_MANA
) / manaMultiplier
);
2187 if (currentAbsorb
> maxAbsorb
)
2188 currentAbsorb
= maxAbsorb
;
2190 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
2191 ApplyPowerMod(POWER_MANA
, manaReduction
, false);
2194 // Mana Shield (or Fire Ward or Frost Ward or Ice Barrier)
2195 // for Incanter's Absorption converting to spell power
2196 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_MAGE
&& (*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x000008)
2197 incanterAbsorption
+= currentAbsorb
;
2199 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
2200 if((*i
)->GetModifier()->m_amount
<= 0)
2202 RemoveAurasDueToSpell((*i
)->GetId());
2203 next
= vManaShield
.begin();
2206 RemainingDamage
-= currentAbsorb
;
2209 // effects dependent from full absorb amount
2210 // Incanter's Absorption, if have affective absorbing
2211 if (incanterAbsorption
)
2213 Unit::AuraList
const& auras
= GetAurasByType(SPELL_AURA_DUMMY
);
2214 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
2216 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
2218 // Incanter's Absorption
2219 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_GENERIC
&&
2220 itr_spellProto
->SpellIconID
== 2941)
2223 int32 amount
= int32(incanterAbsorption
* (*itr
)->GetModifier()->m_amount
/ 100);
2225 // apply normalized part of already accumulated amount in aura
2226 if (Aura
* spdAura
= GetAura(44413, EFFECT_INDEX_0
))
2227 amount
+= spdAura
->GetModifier()->m_amount
* spdAura
->GetAuraDuration() / spdAura
->GetAuraMaxDuration();
2229 // Incanter's Absorption (triggered absorb based spell power, will replace existed if any)
2230 CastCustomSpell(this, 44413, &amount
, NULL
, NULL
, true);
2236 // only split damage if not damaging yourself
2239 AuraList
const& vSplitDamageFlat
= GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
2240 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
2244 // check damage school mask
2245 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2248 // Damage can be splitted only if aura has an alive caster
2249 Unit
*caster
= (*i
)->GetCaster();
2250 if(!caster
|| caster
== this || !caster
->IsInWorld() || !caster
->isAlive())
2253 int32 currentAbsorb
;
2254 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2255 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2257 currentAbsorb
= RemainingDamage
;
2259 RemainingDamage
-= currentAbsorb
;
2262 uint32 splitted
= currentAbsorb
;
2263 uint32 splitted_absorb
= 0;
2264 pCaster
->DealDamageMods(caster
,splitted
,&splitted_absorb
);
2266 pCaster
->SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, splitted_absorb
, 0, false, 0, false);
2268 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2269 pCaster
->DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2272 AuraList
const& vSplitDamagePct
= GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
2273 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
2277 // check damage school mask
2278 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2281 // Damage can be splitted only if aura has an alive caster
2282 Unit
*caster
= (*i
)->GetCaster();
2283 if(!caster
|| caster
== this || !caster
->IsInWorld() || !caster
->isAlive())
2286 uint32 splitted
= uint32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
2288 RemainingDamage
-= int32(splitted
);
2290 uint32 split_absorb
= 0;
2291 pCaster
->DealDamageMods(caster
,splitted
,&split_absorb
);
2293 pCaster
->SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, split_absorb
, 0, false, 0, false);
2295 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2296 pCaster
->DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2300 // Apply death prevention spells effects
2301 if (preventDeathSpell
&& RemainingDamage
>= (int32
)GetHealth())
2303 switch(preventDeathSpell
->SpellFamilyName
)
2306 case SPELLFAMILY_ROGUE
:
2309 if (preventDeathSpell
->SpellIconID
== 2109)
2311 CastSpell(this,31231,true);
2312 ((Player
*)this)->AddSpellCooldown(31231,0,time(NULL
)+60);
2313 // with health > 10% lost health until health==10%, in other case no losses
2314 uint32 health10
= GetMaxHealth()/10;
2315 RemainingDamage
= GetHealth() > health10
? GetHealth() - health10
: 0;
2320 case SPELLFAMILY_PRIEST
:
2323 if (preventDeathSpell
->SpellIconID
== 2873)
2325 int32 healAmount
= GetMaxHealth() * preventDeathAmount
/ 100;
2326 CastCustomSpell(this, 48153, &healAmount
, NULL
, NULL
, true);
2327 RemoveAurasDueToSpell(preventDeathSpell
->Id
);
2328 RemainingDamage
= 0;
2335 *absorb
= damage
- RemainingDamage
- *resist
;
2338 void Unit::CalculateAbsorbResistBlock(Unit
*pCaster
, SpellNonMeleeDamage
*damageInfo
, SpellEntry
const* spellProto
, WeaponAttackType attType
)
2340 bool blocked
= false;
2341 // Get blocked status
2342 switch (spellProto
->DmgClass
)
2344 // Melee and Ranged Spells
2345 case SPELL_DAMAGE_CLASS_RANGED
:
2346 case SPELL_DAMAGE_CLASS_MELEE
:
2347 blocked
= IsSpellBlocked(pCaster
, spellProto
, attType
);
2355 damageInfo
->blocked
= GetShieldBlockValue();
2356 if (damageInfo
->damage
< (int32
)damageInfo
->blocked
)
2357 damageInfo
->blocked
= damageInfo
->damage
;
2358 damageInfo
->damage
-=damageInfo
->blocked
;
2361 uint32 absorb_affected_damage
= pCaster
->CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,GetSpellSchoolMask(spellProto
),spellProto
);
2362 CalculateAbsorbAndResist(pCaster
, GetSpellSchoolMask(spellProto
), SPELL_DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, !(spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
));
2363 damageInfo
->damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
2366 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
2368 if(hasUnitState(UNIT_STAT_CAN_NOT_REACT
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
2371 if (!pVictim
->isAlive())
2374 if(IsNonMeleeSpellCasted(false))
2378 if (attType
== BASE_ATTACK
)
2379 hitInfo
= HITINFO_NORMALSWING2
;
2380 else if (attType
== OFF_ATTACK
)
2381 hitInfo
= HITINFO_LEFTSWING
;
2383 return; // ignore ranged case
2385 uint32 extraAttacks
= m_extraAttacks
;
2387 // melee attack spell casted at main hand attack only
2388 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
2390 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
2392 // not recent extra attack only at any non extra attack (melee spell case)
2393 if(!extra
&& extraAttacks
)
2395 while(m_extraAttacks
)
2397 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2398 if(m_extraAttacks
> 0)
2405 // attack can be redirected to another target
2406 pVictim
= SelectMagnetTarget(pVictim
);
2408 CalcDamageInfo damageInfo
;
2409 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
2410 // Send log damage message to client
2411 DealDamageMods(pVictim
,damageInfo
.damage
,&damageInfo
.absorb
);
2412 SendAttackStateUpdate(&damageInfo
);
2413 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
2414 DealMeleeDamage(&damageInfo
,true);
2416 if (GetTypeId() == TYPEID_PLAYER
)
2417 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
,"AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2418 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2420 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
,"AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2421 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2423 // if damage pVictim call AI reaction
2424 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
2425 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
2427 // extra attack only at any non extra attack (normal case)
2428 if(!extra
&& extraAttacks
)
2430 while(m_extraAttacks
)
2432 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2433 if(m_extraAttacks
> 0)
2439 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
2441 // This is only wrapper
2443 // Miss chance based on melee
2444 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
2446 // Critical hit chance
2447 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
2449 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
2450 float dodge_chance
= pVictim
->GetUnitDodgeChance();
2451 float block_chance
= pVictim
->GetUnitBlockChance();
2452 float parry_chance
= pVictim
->GetUnitParryChance();
2454 // Useful if want to specify crit & miss chances for melee, else it could be removed
2455 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
);
2457 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100));
2460 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const
2462 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2463 return MELEE_HIT_EVADE
;
2465 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
2466 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
2468 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
2469 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
2471 // bonus from skills is 0.04%
2472 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
2473 int32 sum
= 0, tmp
= 0;
2474 int32 roll
= urand (0, 10000);
2476 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
2477 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
2478 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
2482 if (tmp
> 0 && roll
< (sum
+= tmp
))
2484 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: MISS");
2485 return MELEE_HIT_MISS
;
2488 // always crit against a sitting target (except 0 crit chance)
2489 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
2491 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: CRIT (sitting victim)");
2492 return MELEE_HIT_CRIT
;
2497 // only players can't dodge if attacker is behind
2498 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI_F
,this))
2500 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
2504 // Reduce dodge chance by attacker expertise rating
2505 if (GetTypeId() == TYPEID_PLAYER
)
2506 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2508 dodge_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2510 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2511 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2514 if ( (tmp
> 0) // check if unit _can_ dodge
2515 && ((tmp
-= skillBonus
) > 0)
2516 && roll
< (sum
+= tmp
))
2518 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
2519 return MELEE_HIT_DODGE
;
2523 // parry & block chances
2525 // check if attack comes from behind, nobody can parry or block if attacker is behind
2526 if (!pVictim
->HasInArc(M_PI_F
,this))
2528 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: attack came from behind.");
2532 // Reduce parry chance by attacker expertise rating
2533 if (GetTypeId() == TYPEID_PLAYER
)
2534 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2536 parry_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2538 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
2540 int32 tmp2
= int32(parry_chance
);
2541 if ( (tmp2
> 0) // check if unit _can_ parry
2542 && ((tmp2
-= skillBonus
) > 0)
2543 && (roll
< (sum
+= tmp2
)))
2545 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp2
, sum
);
2546 return MELEE_HIT_PARRY
;
2550 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
2553 if ( (tmp
> 0) // check if unit _can_ block
2554 && ((tmp
-= skillBonus
) > 0)
2555 && (roll
< (sum
+= tmp
)))
2557 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
2558 return MELEE_HIT_BLOCK
;
2566 if (tmp
> 0 && roll
< (sum
+= tmp
))
2568 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
2569 return MELEE_HIT_CRIT
;
2572 // 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)
2573 if( attType
!= RANGED_ATTACK
&&
2574 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
2575 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
2576 getLevel() < pVictim
->getLevelForTarget(this) )
2578 // cap possible value (with bonuses > max skill)
2579 int32 skill
= attackerWeaponSkill
;
2580 int32 maxskill
= attackerMaxSkillValueForLevel
;
2581 skill
= (skill
> maxskill
) ? maxskill
: skill
;
2583 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
2584 tmp
= tmp
> 4000 ? 4000 : tmp
;
2585 if (roll
< (sum
+= tmp
))
2587 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
2588 return MELEE_HIT_GLANCING
;
2592 // mobs can score crushing blows if they're 4 or more levels above victim
2593 if (getLevelForTarget(pVictim
) >= pVictim
->getLevelForTarget(this) + 4 &&
2594 // can be from by creature (if can) or from controlled player that considered as creature
2595 (GetTypeId()!=TYPEID_PLAYER
&& !((Creature
*)this)->isPet() &&
2596 !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) ||
2597 GetTypeId()==TYPEID_PLAYER
&& GetCharmerOrOwnerGUID()))
2599 // when their weapon skill is 15 or more above victim's defense skill
2600 tmp
= victimDefenseSkill
;
2601 int32 tmpmax
= victimMaxSkillValueForLevel
;
2602 // having defense above your maximum (from items, talents etc.) has no effect
2603 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
2604 // tmp = mob's level * 5 - player's current defense skill
2605 tmp
= attackerMaxSkillValueForLevel
- tmp
;
2608 // add 2% chance per lacking skill point, min. is 15%
2609 tmp
= tmp
* 200 - 1500;
2610 if (roll
< (sum
+= tmp
))
2612 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
2613 return MELEE_HIT_CRUSHING
;
2618 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "RollMeleeOutcomeAgainst: NORMAL");
2619 return MELEE_HIT_NORMAL
;
2622 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
2624 float min_damage
, max_damage
;
2626 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
2627 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
2633 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
2634 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
2637 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
2638 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
2641 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
2642 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
2644 // Just for good manner
2652 if (min_damage
> max_damage
)
2654 std::swap(min_damage
,max_damage
);
2657 if(max_damage
== 0.0f
)
2660 return urand((uint32
)min_damage
, (uint32
)max_damage
);
2663 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
2665 if(spellProto
->spellLevel
<= 0)
2668 float LvlPenalty
= 0.0f
;
2670 if(spellProto
->spellLevel
< 20)
2671 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
2672 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
2673 if(LvlFactor
> 1.0f
)
2676 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
2679 void Unit::SendMeleeAttackStart(Unit
* pVictim
)
2681 WorldPacket
data( SMSG_ATTACKSTART
, 8 + 8 );
2682 data
<< uint64(GetGUID());
2683 data
<< uint64(pVictim
->GetGUID());
2685 SendMessageToSet(&data
, true);
2686 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
2689 void Unit::SendMeleeAttackStop(Unit
* victim
)
2694 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
2695 data
<< GetPackGUID();
2696 data
<< victim
->GetPackGUID(); // can be 0x00...
2697 data
<< uint32(0); // can be 0x1
2698 SendMessageToSet(&data
, true);
2699 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());
2701 /*if(victim->GetTypeId() == TYPEID_UNIT)
2702 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
2705 bool Unit::IsSpellBlocked(Unit
*pCaster
, SpellEntry
const * /*spellProto*/, WeaponAttackType attackType
)
2707 if (HasInArc(M_PI_F
,pCaster
))
2709 /* Currently not exist spells with ignore block
2710 // Ignore combat result aura (parry/dodge check on prepare)
2711 AuraList const& ignore = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2712 for(AuraList::const_iterator i = ignore.begin(); i != ignore.end(); ++i)
2714 if (!(*i)->isAffectedOnSpell(spellProto))
2716 if ((*i)->GetModifier()->m_miscvalue == )
2721 // Check creatures flags_extra for disable block
2722 if(GetTypeId()==TYPEID_UNIT
&&
2723 ((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
)
2726 float blockChance
= GetUnitBlockChance();
2727 blockChance
+= (int32(pCaster
->GetWeaponSkillValue(attackType
)) - int32(GetMaxSkillValueForLevel()))*0.04f
;
2728 if (roll_chance_f(blockChance
))
2734 // Melee based spells can be miss, parry or dodge on this step
2735 // Crit or block - determined on damage calculation phase! (and can be both in some time)
2736 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
2738 // Calculate hit chance (more correct for chance mod)
2741 // PvP - PvE melee chances
2742 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2743 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
2745 HitChance
= 95 - leveldif
;
2747 HitChance
= 93 - (leveldif
- 2) * lchance
;
2749 // Hit chance depends from victim auras
2750 if(attType
== RANGED_ATTACK
)
2751 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2753 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2755 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2756 if(Player
*modOwner
= GetSpellModOwner())
2757 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
2760 float miss_chance
= 100.0f
- HitChance
;
2762 // Bonuses from attacker aura and ratings
2763 if (attType
== RANGED_ATTACK
)
2764 miss_chance
-= m_modRangedHitChance
;
2766 miss_chance
-= m_modMeleeHitChance
;
2768 // bonus from skills is 0.04%
2769 miss_chance
-= skillDiff
* 0.04f
;
2771 // Limit miss chance from 0 to 60%
2772 if (miss_chance
< 0.0f
)
2774 if (miss_chance
> 60.0f
)
2779 // Melee based spells hit result calculations
2780 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2782 WeaponAttackType attType
= BASE_ATTACK
;
2784 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
2785 attType
= RANGED_ATTACK
;
2787 // bonus from skills is 0.04% per skill Diff
2788 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
2789 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
2790 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
2792 uint32 roll
= urand (0, 10000);
2794 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
2796 uint32 tmp
= missChance
;
2798 return SPELL_MISS_MISS
;
2800 // Chance resist mechanic (select max value from every mechanic spell effect)
2801 int32 resist_mech
= 0;
2802 // Get effects mechanic and chance
2803 for(int eff
= 0; eff
< MAX_EFFECT_INDEX
; ++eff
)
2805 int32 effect_mech
= GetEffectMechanic(spell
, SpellEffectIndex(eff
));
2808 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2809 if (resist_mech
< temp
*100)
2810 resist_mech
= temp
*100;
2816 return SPELL_MISS_RESIST
;
2818 bool canDodge
= true;
2819 bool canParry
= true;
2821 // Same spells cannot be parry/dodge
2822 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
2823 return SPELL_MISS_NONE
;
2825 // Ranged attack cannot be parry/dodge only deflect
2826 if (attType
== RANGED_ATTACK
)
2829 if (pVictim
->HasInArc(M_PI_F
,this))
2831 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2832 tmp
+=deflect_chance
;
2834 return SPELL_MISS_DEFLECT
;
2836 return SPELL_MISS_NONE
;
2839 // Check for attack from behind
2840 if (!pVictim
->HasInArc(M_PI_F
,this))
2842 // Can`t dodge from behind in PvP (but its possible in PvE)
2843 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
2848 // Check creatures flags_extra for disable parry
2849 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
2851 uint32 flagEx
= ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
;
2852 if( flagEx
& CREATURE_FLAG_EXTRA_NO_PARRY
)
2855 // Ignore combat result aura
2856 AuraList
const& ignore
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
2857 for(AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
2859 if (!(*i
)->isAffectedOnSpell(spell
))
2861 switch((*i
)->GetModifier()->m_miscvalue
)
2863 case MELEE_HIT_DODGE
: canDodge
= false; break;
2864 case MELEE_HIT_BLOCK
: break; // Block check in hit step
2865 case MELEE_HIT_PARRY
: canParry
= false; break;
2867 DEBUG_LOG("Spell %u SPELL_AURA_IGNORE_COMBAT_RESULT have unhandled state %d", (*i
)->GetId(), (*i
)->GetModifier()->m_miscvalue
);
2875 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
2876 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2877 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
)*100;
2878 // Reduce dodge chance by attacker expertise rating
2879 if (GetTypeId() == TYPEID_PLAYER
)
2880 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2882 dodgeChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2883 if (dodgeChance
< 0)
2888 return SPELL_MISS_DODGE
;
2894 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
2895 // Reduce parry chance by attacker expertise rating
2896 if (GetTypeId() == TYPEID_PLAYER
)
2897 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2899 parryChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2900 if (parryChance
< 0)
2905 return SPELL_MISS_PARRY
;
2908 return SPELL_MISS_NONE
;
2911 // TODO need use unit spell resistances in calculations
2912 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2914 // Can`t miss on dead target (on skinning for example)
2915 if (!pVictim
->isAlive())
2916 return SPELL_MISS_NONE
;
2918 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
2919 // PvP - PvE spell misschances per leveldif > 2
2920 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
2921 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2923 // Base hit chance from attacker and victim levels
2926 modHitChance
= 96 - leveldif
;
2928 modHitChance
= 94 - (leveldif
- 2) * lchance
;
2930 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2931 if(Player
*modOwner
= GetSpellModOwner())
2932 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
2933 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
2934 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
2935 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
2936 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
2937 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
2938 if (IsAreaOfEffectSpell(spell
))
2939 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
2940 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
2941 if (IsDispelSpell(spell
))
2942 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
2943 // Chance resist mechanic (select max value from every mechanic spell effect)
2944 int32 resist_mech
= 0;
2945 // Get effects mechanic and chance
2946 for(int eff
= 0; eff
< MAX_EFFECT_INDEX
; ++eff
)
2948 int32 effect_mech
= GetEffectMechanic(spell
, SpellEffectIndex(eff
));
2951 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2952 if (resist_mech
< temp
)
2957 modHitChance
-=resist_mech
;
2959 // Chance resist debuff
2960 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
2962 int32 HitChance
= modHitChance
* 100;
2963 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
2964 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
2966 // Decrease hit chance from victim rating bonus
2967 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2968 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
2970 if (HitChance
< 100) HitChance
= 100;
2971 if (HitChance
> 10000) HitChance
= 10000;
2973 int32 tmp
= 10000 - HitChance
;
2975 int32 rand
= irand(0,10000);
2978 return SPELL_MISS_MISS
;
2980 // cast by caster in front of victim
2981 if (pVictim
->HasInArc(M_PI_F
,this))
2983 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2984 tmp
+=deflect_chance
;
2986 return SPELL_MISS_DEFLECT
;
2989 return SPELL_MISS_NONE
;
2992 // Calculate spell hit result can be:
2993 // Every spell can: Evade/Immune/Reflect/Sucesful hit
2994 // For melee based spells:
3000 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
3002 // Return evade for units in evade mode
3003 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
3004 return SPELL_MISS_EVADE
;
3007 if (pVictim
->IsImmunedToSpell(spell
))
3008 return SPELL_MISS_IMMUNE
;
3010 // All positive spells can`t miss
3011 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
3012 if (IsPositiveSpell(spell
->Id
))
3013 return SPELL_MISS_NONE
;
3016 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
)))
3017 return SPELL_MISS_IMMUNE
;
3019 // Try victim reflect spell
3022 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
3023 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
3024 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
3025 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
3026 reflectchance
+= (*i
)->GetModifier()->m_amount
;
3027 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
3029 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
3030 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
3031 return SPELL_MISS_REFLECT
;
3035 switch (spell
->DmgClass
)
3037 case SPELL_DAMAGE_CLASS_NONE
:
3038 return SPELL_MISS_NONE
;
3039 case SPELL_DAMAGE_CLASS_MAGIC
:
3040 return MagicSpellHitResult(pVictim
, spell
);
3041 case SPELL_DAMAGE_CLASS_MELEE
:
3042 case SPELL_DAMAGE_CLASS_RANGED
:
3043 return MeleeSpellHitResult(pVictim
, spell
);
3045 return SPELL_MISS_NONE
;
3048 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
3053 // Base misschance 5%
3054 float misschance
= 5.0f
;
3056 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
3057 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
3059 bool isNormal
= false;
3060 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
3062 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
3068 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
3074 // PvP : PvE melee misschances per leveldif > 2
3075 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
3077 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
3081 // Hit chance from attacker based on ratings and auras
3082 float m_modHitChance
;
3083 if (attType
== RANGED_ATTACK
)
3084 m_modHitChance
= m_modRangedHitChance
;
3086 m_modHitChance
= m_modMeleeHitChance
;
3089 misschance
+= (leveldif
- m_modHitChance
);
3091 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
3093 // Hit chance for victim based on ratings
3094 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
3096 if (attType
== RANGED_ATTACK
)
3097 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
3099 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
3102 // Modify miss chance by victim auras
3103 if(attType
== RANGED_ATTACK
)
3104 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
3106 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
3108 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
3109 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
3110 misschance
-= skillBonus
* 0.04f
;
3112 // Limit miss chance from 0 to 60%
3113 if ( misschance
< 0.0f
)
3115 if ( misschance
> 60.0f
)
3121 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
3123 if(GetTypeId() == TYPEID_PLAYER
)
3125 // in PvP use full skill instead current skill value
3126 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3127 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
3128 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
3129 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
3133 return GetUnitMeleeSkill(target
);
3136 float Unit::GetUnitDodgeChance() const
3138 if(hasUnitState(UNIT_STAT_STUNNED
))
3140 if( GetTypeId() == TYPEID_PLAYER
)
3141 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
3144 if(((Creature
const*)this)->isTotem())
3149 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
3150 return dodge
> 0.0f
? dodge
: 0.0f
;
3155 float Unit::GetUnitParryChance() const
3157 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3160 float chance
= 0.0f
;
3162 if(GetTypeId() == TYPEID_PLAYER
)
3164 Player
const* player
= (Player
const*)this;
3165 if(player
->CanParry() )
3167 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true,true);
3169 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true,true);
3172 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
3175 else if(GetTypeId() == TYPEID_UNIT
)
3177 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
3180 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
3184 return chance
> 0.0f
? chance
: 0.0f
;
3187 float Unit::GetUnitBlockChance() const
3189 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3192 if(GetTypeId() == TYPEID_PLAYER
)
3194 Player
const* player
= (Player
const*)this;
3195 if(player
->CanBlock() )
3197 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
3198 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
3199 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
3201 // is player but has no block ability or no not broken shield equipped
3206 if(((Creature
const*)this)->isTotem())
3211 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
3212 return block
> 0.0f
? block
: 0.0f
;
3217 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
3221 if(GetTypeId() == TYPEID_PLAYER
)
3226 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
3229 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
3232 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
3234 // Just for good manner
3243 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
3247 if(attackType
== RANGED_ATTACK
)
3248 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
3250 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
3252 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
3254 // reduce crit chance from Rating for players
3255 if (attackType
!= RANGED_ATTACK
)
3256 crit
-= pVictim
->GetMeleeCritChanceReduction();
3258 crit
-= pVictim
->GetRangedCritChanceReduction();
3260 // Apply crit chance from defence skill
3261 crit
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
3268 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
3271 if(GetTypeId() == TYPEID_PLAYER
)
3273 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true,true);
3275 // feral or unarmed skill only for base attack
3276 if(attType
!= BASE_ATTACK
&& !item
)
3280 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
3282 // weapon skill or (unarmed for base attack)
3283 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
3285 // in PvP use full skill instead current skill value
3286 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3287 ? ((Player
*)this)->GetMaxSkillValue(skill
)
3288 : ((Player
*)this)->GetSkillValue(skill
);
3289 // Modify value from ratings
3290 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
3293 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
3294 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
3295 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
3299 value
= GetUnitMeleeSkill(target
);
3303 void Unit::_UpdateSpells( uint32 time
)
3305 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
3306 _UpdateAutoRepeatSpell();
3308 // remove finished spells from current pointers
3309 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3311 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
3313 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
3314 m_currentSpells
[i
] = NULL
; // remove pointer
3319 // m_AurasUpdateIterator can be updated in inderect called code at aura remove to skip next planned to update but removed auras
3320 for (m_AurasUpdateIterator
= m_Auras
.begin(); m_AurasUpdateIterator
!= m_Auras
.end();)
3322 Aura
* i_aura
= m_AurasUpdateIterator
->second
;
3323 ++m_AurasUpdateIterator
; // need shift to next for allow update if need into aura update
3324 i_aura
->UpdateAura(time
);
3327 // remove expired auras
3328 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
3332 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
3333 RemoveAura(i
, AURA_REMOVE_BY_EXPIRE
);
3341 if(!m_gameObj
.empty())
3343 GameObjectList::iterator ite1
, dnext1
;
3344 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
3347 //(*i)->Update( difftime );
3348 if( !(*ite1
)->isSpawned() )
3350 (*ite1
)->SetOwnerGUID(0);
3351 (*ite1
)->SetRespawnTime(0);
3353 dnext1
= m_gameObj
.erase(ite1
);
3361 void Unit::_UpdateAutoRepeatSpell()
3363 bool isAutoShot
= m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
== SPELL_ID_AUTOSHOT
;
3366 if (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving())
3368 // cancel wand shoot
3370 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3371 // auto shot just waits
3375 // check spell casts
3376 if (IsNonMeleeSpellCasted(false, false, true))
3378 // cancel wand shoot
3381 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3384 // auto shot is delayed by everythihng, except ranged(!) CURRENT_GENERIC_SPELL's -> recheck that
3385 else if (!(m_currentSpells
[CURRENT_GENERIC_SPELL
] && m_currentSpells
[CURRENT_GENERIC_SPELL
]->IsRangedSpell()))
3390 if (isAttackReady(RANGED_ATTACK
))
3392 // Check if able to cast
3393 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CheckCast(true) != SPELL_CAST_OK
)
3395 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3400 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
3401 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
3403 // all went good, reset attack
3404 resetAttackTimer(RANGED_ATTACK
);
3408 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
3410 ASSERT(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
3412 CurrentSpellTypes CSpellType
= pSpell
->GetCurrentContainer();
3414 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
3416 // break same type spell if it is not delayed
3417 InterruptSpell(CSpellType
,false);
3419 // special breakage effects:
3422 case CURRENT_GENERIC_SPELL
:
3424 // generic spells always break channeled not delayed spells
3425 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3427 // autorepeat breaking
3428 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3430 // break autorepeat if not Auto Shot
3431 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3432 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3436 case CURRENT_CHANNELED_SPELL
:
3438 // channel spells always break generic non-delayed and any channeled spells
3439 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3440 InterruptSpell(CURRENT_CHANNELED_SPELL
);
3442 // it also does break autorepeat if not Auto Shot
3443 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
3444 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3445 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3448 case CURRENT_AUTOREPEAT_SPELL
:
3450 // only Auto Shoot does not break anything
3451 if (pSpell
->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3453 // generic autorepeats break generic non-delayed and channeled non-delayed spells
3454 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3455 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3456 // special action: first cast delay
3457 if ( getAttackTimer(RANGED_ATTACK
) < 500 )
3458 setAttackTimer(RANGED_ATTACK
,500);
3464 // other spell types don't break anything now
3468 // current spell (if it is still here) may be safely deleted now
3469 if (m_currentSpells
[CSpellType
])
3470 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
3472 // set new current spell
3473 m_currentSpells
[CSpellType
] = pSpell
;
3474 pSpell
->SetReferencedFromCurrent(true);
3476 pSpell
->m_selfContainer
= &(m_currentSpells
[pSpell
->GetCurrentContainer()]);
3479 void Unit::InterruptSpell(CurrentSpellTypes spellType
, bool withDelayed
, bool sendAutoRepeatCancelToClient
)
3481 ASSERT(spellType
< CURRENT_MAX_SPELL
);
3483 if (m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
3485 // send autorepeat cancel message for autorepeat spells
3486 if (spellType
== CURRENT_AUTOREPEAT_SPELL
&& sendAutoRepeatCancelToClient
)
3488 if(GetTypeId() == TYPEID_PLAYER
)
3489 ((Player
*)this)->SendAutoRepeatCancel(this);
3492 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
3493 m_currentSpells
[spellType
]->cancel();
3495 // cancel can interrupt spell already (caster cancel ->target aura remove -> caster iterrupt)
3496 if (m_currentSpells
[spellType
])
3498 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
3499 m_currentSpells
[spellType
] = NULL
;
3504 void Unit::FinishSpell(CurrentSpellTypes spellType
, bool ok
/*= true*/)
3506 Spell
* spell
= m_currentSpells
[spellType
];
3510 if (spellType
== CURRENT_CHANNELED_SPELL
)
3511 spell
->SendChannelUpdate(0);
3517 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
3519 // We don't do loop here to explicitly show that melee spell is excluded.
3520 // Maybe later some special spells will be excluded too.
3522 // generic spells are casted when they are not finished and not delayed
3523 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
3524 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3525 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3528 // channeled spells may be delayed, but they are still considered casted
3529 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
3530 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
3533 // autorepeat spells may be finished or delayed, but they are still considered casted
3534 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3540 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
3542 // generic spells are interrupted if they are not finished or delayed
3543 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
3544 InterruptSpell(CURRENT_GENERIC_SPELL
,withDelayed
);
3546 // autorepeat spells are interrupted if they are not finished or delayed
3547 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
3548 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
,withDelayed
);
3550 // channeled spells are interrupted if they are not finished, even if they are delayed
3551 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
3552 InterruptSpell(CURRENT_CHANNELED_SPELL
,true);
3555 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
3557 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3558 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
3559 return m_currentSpells
[i
];
3563 void Unit::SetInFront(Unit
const* target
)
3565 SetOrientation(GetAngle(target
));
3568 void Unit::SetFacingTo(float ori
)
3570 // update orientation at server
3571 SetOrientation(ori
);
3575 BuildHeartBeatMsg(&data
);
3576 SendMessageToSet(&data
, false);
3579 // Consider move this to Creature:: since only creature appear to be able to use this
3580 void Unit::SetFacingToObject(WorldObject
* pObject
)
3582 if (GetTypeId() != TYPEID_UNIT
)
3585 // never face when already moving
3589 // TODO: figure out under what conditions creature will move towards object instead of facing it where it currently is.
3591 SetOrientation(GetAngle(pObject
));
3592 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_FACINGTARGET
, ((Creature
*)this)->GetSplineFlags(), 0, NULL
, pObject
->GetGUID());
3595 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
3598 return c
->canSwim();
3600 return c
->canWalk() || c
->canFly();
3603 bool Unit::IsInWater() const
3605 return GetBaseMap()->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
3608 bool Unit::IsUnderWater() const
3610 return GetBaseMap()->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3613 void Unit::DeMorph()
3615 SetDisplayId(GetNativeDisplayId());
3618 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3622 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3623 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3624 modifier
+= (*i
)->GetModifier()->m_amount
;
3629 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3631 float multiplier
= 1.0f
;
3633 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3634 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3635 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3640 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3644 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3645 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3646 if ((*i
)->GetModifier()->m_amount
> modifier
)
3647 modifier
= (*i
)->GetModifier()->m_amount
;
3652 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
3656 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3657 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3658 if ((*i
)->GetModifier()->m_amount
< modifier
)
3659 modifier
= (*i
)->GetModifier()->m_amount
;
3664 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3671 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3672 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3674 Modifier
* mod
= (*i
)->GetModifier();
3675 if (mod
->m_miscvalue
& misc_mask
)
3676 modifier
+= mod
->m_amount
;
3681 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3686 float multiplier
= 1.0f
;
3688 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3689 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3691 Modifier
* mod
= (*i
)->GetModifier();
3692 if (mod
->m_miscvalue
& misc_mask
)
3693 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3698 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(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::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3723 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3724 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3726 Modifier
* mod
= (*i
)->GetModifier();
3727 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
< modifier
)
3728 modifier
= mod
->m_amount
;
3734 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3738 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3739 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3741 Modifier
* mod
= (*i
)->GetModifier();
3742 if (mod
->m_miscvalue
== misc_value
)
3743 modifier
+= mod
->m_amount
;
3748 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
3750 float multiplier
= 1.0f
;
3752 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3753 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3755 Modifier
* mod
= (*i
)->GetModifier();
3756 if (mod
->m_miscvalue
== misc_value
)
3757 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3762 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3766 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3767 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3769 Modifier
* mod
= (*i
)->GetModifier();
3770 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
3771 modifier
= mod
->m_amount
;
3777 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
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 (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
< modifier
)
3786 modifier
= mod
->m_amount
;
3792 float Unit::GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype
, uint32 mask
) const
3797 float multiplier
= 1.0f
;
3799 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3800 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3802 Modifier
* mod
= (*i
)->GetModifier();
3803 if (mask
& (1 << (mod
->m_miscvalue
-1)))
3804 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3809 bool Unit::AddAura(Aura
*Aur
)
3811 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
3813 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
3814 if( !isAlive() && !IsDeathPersistentSpell(aurSpellInfo
) &&
3815 !IsDeathOnlySpell(aurSpellInfo
) &&
3816 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
3822 if(Aur
->GetTarget() != this)
3824 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
3825 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
3826 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
3831 // m_auraname can be modified to SPELL_AURA_NONE for area auras, this expected for this value
3832 AuraType aurName
= Aur
->GetModifier()->m_auraname
;
3834 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
3835 AuraMap::iterator i
= m_Auras
.find( spair
);
3837 // take out same spell
3838 if (i
!= m_Auras
.end())
3840 // passive and persistent auras can stack with themselves any number of times
3841 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
3843 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
3845 Aura
* aur2
= i2
->second
;
3846 if(aur2
->GetCasterGUID()==Aur
->GetCasterGUID())
3848 // Aura can stack on self -> Stack it;
3849 if(aurSpellInfo
->StackAmount
)
3851 // can be created with >1 stack by some spell mods
3852 aur2
->modStackAmount(Aur
->GetStackAmount());
3857 // Check for coexisting Weapon-proced Auras
3858 if (Aur
->isWeaponBuffCoexistableWith(aur2
))
3861 // Carry over removed Aura's remaining damage if Aura still has ticks remaining
3862 if (aur2
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_STACK_DOT_MODIFIER
&& aurName
== SPELL_AURA_PERIODIC_DAMAGE
&& aur2
->GetAuraDuration() > 0)
3864 int32 remainingTicks
= aur2
->GetAuraMaxTicks() - aur2
->GetAuraTicks();
3865 int32 remainingDamage
= aur2
->GetModifier()->m_amount
* remainingTicks
;
3867 Aur
->GetModifier()->m_amount
+= int32(remainingDamage
/ Aur
->GetAuraMaxTicks());
3869 // can be only single (this check done at _each_ aura add
3870 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3876 // m_auraname can be modified to SPELL_AURA_NONE for area auras, use original
3877 AuraType aurNameReal
= AuraType(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()]);
3882 case SPELL_AURA_DUMMY
: // allow stack
3883 case SPELL_AURA_PERIODIC_DAMAGE
:
3884 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
3885 case SPELL_AURA_PERIODIC_LEECH
:
3886 case SPELL_AURA_PERIODIC_HEAL
:
3887 case SPELL_AURA_OBS_MOD_HEALTH
:
3888 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3889 case SPELL_AURA_OBS_MOD_MANA
:
3890 case SPELL_AURA_POWER_BURN_MANA
:
3892 case SPELL_AURA_PERIODIC_ENERGIZE
: // all or self or clear non-stackable
3893 default: // not allow
3894 // can be only single (this check done at _each_ aura add
3895 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3906 // passive auras not stacable with other ranks
3907 if (!IsPassiveSpellStackableWithRanks(aurSpellInfo
))
3909 if (!RemoveNoStackAurasDueToAura(Aur
))
3912 return false; // couldn't remove conflicting aura with higher rank
3916 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
3917 if (Aur
->IsSingleTarget() && Aur
->GetTarget())
3919 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
3922 Unit
* caster
= Aur
->GetCaster();
3923 if(!caster
) // caster deleted and not required adding scAura
3926 bool restart
= false;
3927 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3928 for(AuraList::const_iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
3930 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
3931 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
3933 if ((*itr
)->IsInUse())
3935 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());
3938 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
3947 scAuras
.push_back(Aur
);
3953 // add aura, register in lists and arrays
3955 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
3956 if (aurName
< TOTAL_AURAS
)
3958 m_modAuras
[aurName
].push_back(Aur
);
3961 Aur
->ApplyModifier(true,true);
3962 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "Aura %u now is in use", aurName
);
3964 // if aura deleted before boosts apply ignore
3965 // this can be possible it it removed indirectly by triggered spell effect at ApplyModifier
3966 if (Aur
->IsDeleted())
3969 if(IsSpellLastAuraEffect(aurSpellInfo
,Aur
->GetEffIndex()))
3970 Aur
->HandleSpellSpecificBoosts(true);
3975 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
3977 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3980 AuraMap::const_iterator i
,next
;
3981 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3985 uint32 i_spellId
= (*i
).second
->GetId();
3986 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
3988 if(sSpellMgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
3990 RemoveAurasDueToSpell(i_spellId
);
3992 if( m_Auras
.empty() )
3995 next
= m_Auras
.begin();
4001 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
4006 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
4010 uint32 spellId
= Aur
->GetId();
4011 SpellEffectIndex effIndex
= Aur
->GetEffIndex();
4013 // passive spell special case (only non stackable with ranks)
4014 if(IsPassiveSpell(spellId
))
4016 if(IsPassiveSpellStackableWithRanks(spellProto
))
4020 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
4022 AuraMap::iterator i
,next
;
4023 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
4027 if (!(*i
).second
) continue;
4029 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
4034 uint32 i_spellId
= i_spellProto
->Id
;
4036 // early checks that spellId is passive non stackable spell
4037 if(IsPassiveSpell(i_spellId
))
4039 // passive non-stackable spells not stackable only for same caster
4040 if(Aur
->GetCasterGUID()!=i
->second
->GetCasterGUID())
4043 // passive non-stackable spells not stackable only with another rank of same spell
4044 if (!sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4048 SpellEffectIndex i_effIndex
= (*i
).second
->GetEffIndex();
4050 if(i_spellId
== spellId
) continue;
4052 bool is_triggered_by_spell
= false;
4053 // prevent triggering aura of removing aura that triggered it
4054 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4055 if (i_spellProto
->EffectTriggerSpell
[j
] == spellId
)
4056 is_triggered_by_spell
= true;
4058 // prevent triggered aura of removing aura that triggering it (triggered effect early some aura of parent spell
4059 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4060 if (spellProto
->EffectTriggerSpell
[j
] == i_spellId
)
4061 is_triggered_by_spell
= true;
4063 if (is_triggered_by_spell
)
4066 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
4068 // single allowed spell specific from same caster or from any caster at target
4069 bool is_spellSpecPerTargetPerCaster
= IsSingleFromSpellSpecificPerTargetPerCaster(spellId_spec
,i_spellId_spec
);
4070 bool is_spellSpecPerTarget
= IsSingleFromSpellSpecificPerTarget(spellId_spec
,i_spellId_spec
);
4071 if( is_spellSpecPerTarget
|| is_spellSpecPerTargetPerCaster
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
4073 // cannot remove higher rank
4074 if (sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4075 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4078 // Its a parent aura (create this aura in ApplyModifier)
4079 if ((*i
).second
->IsInUse())
4081 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());
4084 RemoveAurasDueToSpell(i_spellId
);
4086 if( m_Auras
.empty() )
4089 next
= m_Auras
.begin();
4094 // spell with spell specific that allow single ranks for spell from diff caster
4095 // same caster case processed or early or later
4096 bool is_spellPerTarget
= IsSingleFromSpellSpecificSpellRanksPerTarget(spellId_spec
,i_spellId_spec
);
4097 if ( is_spellPerTarget
&& Aur
->GetCasterGUID() != (*i
).second
->GetCasterGUID() && sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4099 // cannot remove higher rank
4100 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4103 // Its a parent aura (create this aura in ApplyModifier)
4104 if ((*i
).second
->IsInUse())
4106 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());
4109 RemoveAurasDueToSpell(i_spellId
);
4111 if( m_Auras
.empty() )
4114 next
= m_Auras
.begin();
4119 // non single (per caster) per target spell specific (possible single spell per target at caster)
4120 if( !is_spellSpecPerTargetPerCaster
&& !is_spellSpecPerTarget
&& sSpellMgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
4122 // Its a parent aura (create this aura in ApplyModifier)
4123 if ((*i
).second
->IsInUse())
4125 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());
4128 RemoveAurasDueToSpell(i_spellId
);
4130 if( m_Auras
.empty() )
4133 next
= m_Auras
.begin();
4138 // Potions stack aura by aura (elixirs/flask already checked)
4139 if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
4141 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
4143 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4144 return false; // cannot remove higher rank
4146 // Its a parent aura (create this aura in ApplyModifier)
4147 if ((*i
).second
->IsInUse())
4149 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());
4160 void Unit::RemoveAura(uint32 spellId
, SpellEffectIndex effindex
, Aura
* except
, AuraRemoveMode mode
)
4162 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4163 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4165 if(iter
->second
!=except
)
4167 RemoveAura(iter
, mode
);
4168 iter
= m_Auras
.lower_bound(spair
);
4175 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
)
4177 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4179 Aura
*aur
= iter
->second
;
4180 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4187 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, SpellEffectIndex effindex
, uint64 casterGUID
)
4189 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4190 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4192 Aura
*aur
= iter
->second
;
4193 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4196 iter
= m_Auras
.lower_bound(spair
);
4203 void Unit::RemoveSingleAuraDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
4205 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(spellId
);
4207 // Custom dispel cases
4208 // Unstable Affliction
4209 if(spellEntry
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x010000000000)))
4211 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
,SPELLFAMILY_WARLOCK
,UI64LIT(0x010000000000),0x00000000,casterGUID
))
4213 // use clean value for initial damage
4214 int32 damage
= dotAura
->GetSpellProto()->CalculateSimpleValue(EFFECT_INDEX_0
);
4217 // Remove spell auras from stack
4218 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4220 // backfire damage and silence
4221 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,casterGUID
);
4226 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x10000000)))
4228 Unit
* caster
= NULL
;
4229 uint32 triggeredSpell
= 0;
4231 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x10000000), 0x00000000, casterGUID
))
4232 caster
= dotAura
->GetCaster();
4234 if (caster
&& !caster
->isDead())
4236 Unit::AuraList
const& auras
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
4237 for (Unit::AuraList::const_iterator i
= auras
.begin(); i
!= auras
.end(); ++i
)
4239 switch((*i
)->GetId())
4241 case 51480: triggeredSpell
=64694; break;// Lava Flows, Rank 1
4242 case 51481: triggeredSpell
=65263; break;// Lava Flows, Rank 2
4243 case 51482: triggeredSpell
=65264; break;// Lava Flows, Rank 3
4250 // Remove spell auras from stack
4251 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4255 caster
->CastSpell(caster
, triggeredSpell
, true);
4258 // Vampiric touch (first dummy aura)
4259 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_PRIEST
&& spellEntry
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
4261 if (Aura
*dot
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000040000000000), 0x00000000, casterGUID
))
4263 if(Unit
* caster
= dot
->GetCaster())
4265 // use clean value for initial damage
4266 int32 bp0
= dot
->GetSpellProto()->CalculateSimpleValue(EFFECT_INDEX_1
);
4269 // Remove spell auras from stack
4270 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4272 CastCustomSpell(this, 64085, &bp0
, NULL
, NULL
, true, NULL
, NULL
, casterGUID
);
4278 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4281 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
4283 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4285 Aura
*aur
= iter
->second
;
4286 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4288 int32 basePoints
= aur
->GetBasePoints();
4289 // construct the new aura for the attacker - will never return NULL, it's just a wrapper for
4290 // some different constructors
4291 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
, this);
4293 // set its duration and maximum duration
4294 // max duration 2 minutes (in msecs)
4295 int32 dur
= aur
->GetAuraDuration();
4296 int32 max_dur
= 2*MINUTE
*IN_MILLISECONDS
;
4297 int32 new_max_dur
= max_dur
> dur
? dur
: max_dur
;
4298 new_aur
->SetAuraMaxDuration( new_max_dur
);
4299 new_aur
->SetAuraDuration( new_max_dur
);
4301 // set periodic to do at least one tick (for case when original aura has been at last tick preparing)
4302 int32 periodic
= aur
->GetModifier()->periodictime
;
4303 new_aur
->GetModifier()->periodictime
= periodic
< new_max_dur
? periodic
: new_max_dur
;
4305 // Unregister _before_ adding to stealer
4306 aur
->UnregisterSingleCastAura();
4308 // strange but intended behaviour: Stolen single target auras won't be treated as single targeted
4309 new_aur
->SetIsSingleTarget(false);
4311 // add the new aura to stealer
4312 stealer
->AddAura(new_aur
);
4314 // Remove aura as dispel
4315 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
4322 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
4324 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4326 if (iter
->second
->GetId() == spellId
)
4327 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
4333 void Unit::RemoveAurasWithDispelType( DispelType type
)
4335 // Create dispel mask by dispel type
4336 uint32 dispelMask
= GetDispellMask(type
);
4337 // Dispel all existing auras vs current dispel type
4338 AuraMap
& auras
= GetAuras();
4339 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
4341 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
4342 if( (1<<spell
->Dispel
) & dispelMask
)
4345 RemoveAurasDueToSpell(spell
->Id
);
4346 itr
= auras
.begin();
4353 void Unit::RemoveSingleAuraFromStack(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4355 if (i
->second
->modStackAmount(-1))
4360 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, SpellEffectIndex effindex
, AuraRemoveMode mode
)
4362 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4363 if(iter
!= m_Auras
.end())
4364 RemoveSingleAuraFromStack(iter
,mode
);
4367 void Unit::RemoveSingleSpellAurasFromStack(uint32 spellId
, AuraRemoveMode mode
)
4369 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4370 RemoveSingleAuraFromStack(spellId
, SpellEffectIndex(i
), mode
);
4373 void Unit::RemoveSingleSpellAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
, AuraRemoveMode mode
)
4375 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4376 RemoveSingleAuraByCasterSpell(spellId
, SpellEffectIndex(i
), casterGUID
, mode
);
4379 void Unit::RemoveSingleAuraByCasterSpell(uint32 spellId
, SpellEffectIndex effindex
, uint64 casterGUID
, AuraRemoveMode mode
)
4381 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4382 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
); ++iter
)
4384 Aura
*aur
= iter
->second
;
4385 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4387 RemoveSingleAuraFromStack(iter
,mode
);
4394 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
, AuraRemoveMode mode
)
4396 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4397 RemoveAura(spellId
,SpellEffectIndex(i
),except
, mode
);
4400 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
4402 for (int k
=0; k
< MAX_EFFECT_INDEX
; ++k
)
4404 spellEffectPair spair
= spellEffectPair(spellId
, SpellEffectIndex(k
));
4405 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4407 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
4410 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
4418 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
4420 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4422 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
4429 void Unit::RemoveNotOwnSingleTargetAuras(uint32 newPhase
)
4431 // single target auras from other casters
4432 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4434 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
4440 Unit
* caster
= iter
->second
->GetCaster();
4441 if(!caster
|| !caster
->InSamePhase(newPhase
))
4451 // single target auras at other targets
4452 AuraList
& scAuras
= GetSingleCastAuras();
4453 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
4456 if (aura
->GetTarget() != this && !aura
->GetTarget()->InSamePhase(newPhase
))
4458 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
4459 aura
->GetTarget()->RemoveAura(aura
);
4460 iter
= scAuras
.begin();
4468 void Unit::RemoveAura(Aura
* aura
, AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4470 AuraMap::iterator i
= m_Auras
.lower_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4471 AuraMap::iterator upperBound
= m_Auras
.upper_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4472 for (; i
!= upperBound
; ++i
)
4474 if (i
->second
== aura
)
4480 DEBUG_LOG("Trying to remove aura id %u effect %u by pointer but aura not found on target", aura
->GetId(), aura
->GetEffIndex());
4483 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4485 Aura
* Aur
= i
->second
;
4486 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
4488 Aur
->UnregisterSingleCastAura();
4490 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
4491 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
4493 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
4497 Aur
->SetRemoveMode(mode
);
4499 // if unit currently update aura list then make safe update iterator shift to next
4500 if (m_AurasUpdateIterator
== i
)
4501 ++m_AurasUpdateIterator
;
4503 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
4504 // remove aura from list before to prevent deleting it before
4507 // now aura removed from from list and can't be deleted by indirect call but can be referenced from callers
4509 // Statue unsummoned at aura remove
4510 Totem
* statue
= NULL
;
4511 if(IsChanneledSpell(AurSpellInfo
))
4512 if(Unit
* caster
= Aur
->GetCaster())
4513 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
4514 statue
= ((Totem
*)caster
);
4516 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
4518 // some auras also need to apply modifier (on caster) on remove
4519 if (mode
!= AURA_REMOVE_BY_DELETE
|| Aur
->GetModifier()->m_auraname
== SPELL_AURA_MOD_POSSESS
)
4520 Aur
->ApplyModifier(false,true);
4522 if (Aur
->_RemoveAura())
4524 // last aura in stack removed
4525 if (mode
!= AURA_REMOVE_BY_DELETE
&& IsSpellLastAuraEffect(Aur
->GetSpellProto(),Aur
->GetEffIndex()))
4526 Aur
->HandleSpellSpecificBoosts(false);
4529 // If aura in use (removed from code that plan access to it data after return)
4530 // store it in aura list with delayed deletion
4532 m_deletedAuras
.push_back(Aur
);
4539 // only way correctly remove all auras from list
4540 if( m_Auras
.empty() )
4543 i
= m_Auras
.begin();
4547 void Unit::RemoveAllAuras(AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4549 while (!m_Auras
.empty())
4551 AuraMap::iterator iter
= m_Auras
.begin();
4552 RemoveAura(iter
,mode
);
4556 void Unit::RemoveArenaAuras(bool onleave
)
4558 // in join, remove positive buffs, on end, remove negative
4559 // used to remove positive visible auras in arenas
4560 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4562 if (!(iter
->second
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_UNK21
) &&
4563 // don't remove stances, shadowform, pally/hunter auras
4564 !iter
->second
->IsPassive() && // don't remove passive auras
4565 (!(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
) ||
4566 !(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNK8
)) &&
4567 // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable)
4568 (iter
->second
->IsPositive() != onleave
)) // remove positive buffs on enter, negative buffs on leave
4575 void Unit::RemoveAllAurasOnDeath()
4577 // used just after dieing to remove all visible auras
4578 // and disable the mods for the passive ones
4579 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4581 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
4582 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
4588 void Unit::DelayAura(uint32 spellId
, SpellEffectIndex effindex
, int32 delaytime
)
4590 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4591 if (iter
!= m_Auras
.end())
4593 if (iter
->second
->GetAuraDuration() < delaytime
)
4594 iter
->second
->SetAuraDuration(0);
4596 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
4597 iter
->second
->SendAuraUpdate(false);
4598 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());
4602 void Unit::_RemoveAllAuraMods()
4604 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4606 (*i
).second
->ApplyModifier(false);
4610 void Unit::_ApplyAllAuraMods()
4612 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4614 (*i
).second
->ApplyModifier(true);
4618 Aura
* Unit::GetAura(uint32 spellId
, SpellEffectIndex effindex
)
4620 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4621 if (iter
!= m_Auras
.end())
4622 return iter
->second
;
4626 Aura
* Unit::GetAura(AuraType type
, uint32 family
, uint64 familyFlag
, uint32 familyFlag2
, uint64 casterGUID
)
4628 AuraList
const& auras
= GetAurasByType(type
);
4629 for(AuraList::const_iterator i
= auras
.begin();i
!= auras
.end(); ++i
)
4631 SpellEntry
const *spell
= (*i
)->GetSpellProto();
4632 if (spell
->SpellFamilyName
== family
&& (spell
->SpellFamilyFlags
& familyFlag
|| spell
->SpellFamilyFlags2
& familyFlag2
))
4634 if (casterGUID
&& (*i
)->GetCasterGUID()!=casterGUID
)
4642 bool Unit::HasAura(uint32 spellId
) const
4644 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4646 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, SpellEffectIndex(i
)));
4647 if (iter
!= m_Auras
.end())
4653 void Unit::AddDynObject(DynamicObject
* dynObj
)
4655 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
4658 void Unit::RemoveDynObject(uint32 spellid
)
4660 if(m_dynObjGUIDs
.empty())
4662 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4664 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4667 i
= m_dynObjGUIDs
.erase(i
);
4669 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
4672 i
= m_dynObjGUIDs
.erase(i
);
4679 void Unit::RemoveAllDynObjects()
4681 while(!m_dynObjGUIDs
.empty())
4683 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*m_dynObjGUIDs
.begin());
4686 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
4690 DynamicObject
* Unit::GetDynObject(uint32 spellId
, SpellEffectIndex effIndex
)
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
&& dynObj
->GetEffIndex() == effIndex
)
4708 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
4710 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4712 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4715 i
= m_dynObjGUIDs
.erase(i
);
4719 if (dynObj
->GetSpellId() == spellId
)
4726 GameObject
* Unit::GetGameObject(uint32 spellId
) const
4728 for (GameObjectList::const_iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); ++i
)
4729 if ((*i
)->GetSpellId() == spellId
)
4735 void Unit::AddGameObject(GameObject
* gameObj
)
4737 ASSERT(gameObj
&& gameObj
->GetOwnerGUID()==0);
4738 m_gameObj
.push_back(gameObj
);
4739 gameObj
->SetOwnerGUID(GetGUID());
4741 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
4743 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
4744 // Need disable spell use for owner
4745 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4746 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4747 ((Player
*)this)->AddSpellAndCategoryCooldowns(createBySpell
,0,NULL
,true);
4751 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
4753 ASSERT(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
4755 gameObj
->SetOwnerGUID(0);
4757 // GO created by some spell
4758 if (uint32 spellid
= gameObj
->GetSpellId())
4760 RemoveAurasDueToSpell(spellid
);
4762 if (GetTypeId()==TYPEID_PLAYER
)
4764 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(spellid
);
4765 // Need activate spell use for owner
4766 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4767 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4768 ((Player
*)this)->SendCooldownEvent(createBySpell
);
4772 m_gameObj
.remove(gameObj
);
4776 gameObj
->SetRespawnTime(0);
4781 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
4783 if(m_gameObj
.empty())
4785 GameObjectList::iterator i
, next
;
4786 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
4789 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
4791 (*i
)->SetOwnerGUID(0);
4794 (*i
)->SetRespawnTime(0);
4798 next
= m_gameObj
.erase(i
);
4805 void Unit::RemoveAllGameObjects()
4807 // remove references to unit
4808 for(GameObjectList::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4810 (*i
)->SetOwnerGUID(0);
4811 (*i
)->SetRespawnTime(0);
4813 i
= m_gameObj
.erase(i
);
4817 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
4819 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+4+1+4+4+1+1+4+4+1)); // we guess size
4820 data
<< log
->target
->GetPackGUID();
4821 data
<< log
->attacker
->GetPackGUID();
4822 data
<< uint32(log
->SpellID
);
4823 data
<< uint32(log
->damage
); // damage amount
4824 data
<< uint32(log
->overkill
); // overkill
4825 data
<< uint8 (log
->schoolMask
); // damage school
4826 data
<< uint32(log
->absorb
); // AbsorbedDamage
4827 data
<< uint32(log
->resist
); // resist
4828 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
4829 data
<< uint8 (log
->unused
); // unused
4830 data
<< uint32(log
->blocked
); // blocked
4831 data
<< uint32(log
->HitInfo
);
4832 data
<< uint8 (0); // flag to use extend data
4833 SendMessageToSet( &data
, true );
4836 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
, uint32 SpellID
, uint32 Damage
, SpellSchoolMask damageSchoolMask
, uint32 AbsorbedDamage
, uint32 Resist
, bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
4838 SpellNonMeleeDamage
log(this, target
, SpellID
, damageSchoolMask
);
4839 log
.damage
= Damage
- AbsorbedDamage
- Resist
- Blocked
;
4840 log
.absorb
= AbsorbedDamage
;
4841 log
.resist
= Resist
;
4842 log
.physicalLog
= PhysicalDamage
;
4843 log
.blocked
= Blocked
;
4844 log
.HitInfo
= SPELL_HIT_TYPE_UNK1
| SPELL_HIT_TYPE_UNK3
| SPELL_HIT_TYPE_UNK6
;
4846 log
.HitInfo
|= SPELL_HIT_TYPE_CRIT
;
4847 SendSpellNonMeleeDamageLog(&log
);
4850 void Unit::SendPeriodicAuraLog(SpellPeriodicAuraLogInfo
*pInfo
)
4852 Aura
*aura
= pInfo
->aura
;
4853 Modifier
*mod
= aura
->GetModifier();
4855 WorldPacket
data(SMSG_PERIODICAURALOG
, 30);
4856 data
<< aura
->GetTarget()->GetPackGUID();
4857 data
.appendPackGUID(aura
->GetCasterGUID());
4858 data
<< uint32(aura
->GetId()); // spellId
4859 data
<< uint32(1); // count
4860 data
<< uint32(mod
->m_auraname
); // auraId
4861 switch(mod
->m_auraname
)
4863 case SPELL_AURA_PERIODIC_DAMAGE
:
4864 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
4865 data
<< uint32(pInfo
->damage
); // damage
4866 data
<< uint32(pInfo
->overDamage
); // overkill?
4867 data
<< uint32(GetSpellSchoolMask(aura
->GetSpellProto()));
4868 data
<< uint32(pInfo
->absorb
); // absorb
4869 data
<< uint32(pInfo
->resist
); // resist
4870 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4872 case SPELL_AURA_PERIODIC_HEAL
:
4873 case SPELL_AURA_OBS_MOD_HEALTH
:
4874 data
<< uint32(pInfo
->damage
); // damage
4875 data
<< uint32(pInfo
->overDamage
); // overheal?
4876 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4878 case SPELL_AURA_OBS_MOD_MANA
:
4879 case SPELL_AURA_PERIODIC_ENERGIZE
:
4880 data
<< uint32(mod
->m_miscvalue
); // power type
4881 data
<< uint32(pInfo
->damage
); // damage
4883 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4884 data
<< uint32(mod
->m_miscvalue
); // power type
4885 data
<< uint32(pInfo
->damage
); // amount
4886 data
<< float(pInfo
->multiplier
); // gain multiplier
4889 sLog
.outError("Unit::SendPeriodicAuraLog: unknown aura %u", uint32(mod
->m_auraname
));
4893 aura
->GetTarget()->SendMessageToSet(&data
, true);
4896 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
4898 // Not much to do if no flags are set.
4900 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
4901 // Now go on with a victim's events'n'auras
4902 // Not much to do if no flags are set or there is no victim
4903 if(pVictim
&& pVictim
->isAlive() && procVictim
)
4904 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4907 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4909 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4910 data
<< uint32(spellID
);
4911 data
<< uint64(GetGUID());
4912 data
<< uint8(0); // can be 0 or 1
4913 data
<< uint32(1); // target count
4914 // for(i = 0; i < target count; ++i)
4915 data
<< uint64(target
->GetGUID()); // target GUID
4916 data
<< uint8(missInfo
);
4918 SendMessageToSet(&data
, true);
4921 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4923 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4926 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, 16 + 45); // we guess size
4927 data
<< uint32(damageInfo
->HitInfo
);
4928 data
<< damageInfo
->attacker
->GetPackGUID();
4929 data
<< damageInfo
->target
->GetPackGUID();
4930 data
<< uint32(damageInfo
->damage
); // Full damage
4931 data
<< uint32(0); // overkill value
4932 data
<< uint8(count
); // Sub damage count
4934 for(uint32 i
= 0; i
< count
; ++i
)
4936 data
<< uint32(damageInfo
->damageSchoolMask
); // School of sub damage
4937 data
<< float(damageInfo
->damage
); // sub damage
4938 data
<< uint32(damageInfo
->damage
); // Sub Damage
4941 if(damageInfo
->HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4943 for(uint32 i
= 0; i
< count
; ++i
)
4944 data
<< uint32(damageInfo
->absorb
); // Absorb
4947 if(damageInfo
->HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4949 for(uint32 i
= 0; i
< count
; ++i
)
4950 data
<< uint32(damageInfo
->resist
); // Resist
4953 data
<< uint8(damageInfo
->TargetState
);
4957 if(damageInfo
->HitInfo
& HITINFO_BLOCK
)
4958 data
<< uint32(damageInfo
->blocked_amount
);
4960 if(damageInfo
->HitInfo
& HITINFO_UNK3
)
4963 if(damageInfo
->HitInfo
& HITINFO_UNK1
)
4974 for(uint8 i
= 0; i
< 5; ++i
)
4982 SendMessageToSet( &data
, true );
4985 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8
/*SwingType*/, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4987 CalcDamageInfo dmgInfo
;
4988 dmgInfo
.HitInfo
= HitInfo
;
4989 dmgInfo
.attacker
= this;
4990 dmgInfo
.target
= target
;
4991 dmgInfo
.damage
= Damage
- AbsorbDamage
- Resist
- BlockedAmount
;
4992 dmgInfo
.damageSchoolMask
= damageSchoolMask
;
4993 dmgInfo
.absorb
= AbsorbDamage
;
4994 dmgInfo
.resist
= Resist
;
4995 dmgInfo
.TargetState
= TargetState
;
4996 dmgInfo
.blocked_amount
= BlockedAmount
;
4997 SendAttackStateUpdate(&dmgInfo
);
5000 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
5002 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
5004 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5005 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5007 uint32 triggered_spell_id
= 0;
5008 Unit
* target
= pVictim
;
5009 int32 basepoints0
= 0;
5011 switch(hasteSpell
->SpellFamilyName
)
5013 case SPELLFAMILY_ROGUE
:
5015 switch(hasteSpell
->Id
)
5021 target
= SelectRandomUnfriendlyTarget(pVictim
);
5024 basepoints0
= damage
;
5025 triggered_spell_id
= 22482;
5033 // processed charge only counting case
5034 if(!triggered_spell_id
)
5037 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5041 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
5046 if(!target
|| target
!=this && !target
->isAlive())
5049 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5053 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5055 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5057 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5058 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5063 bool Unit::HandleSpellCritChanceAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
5065 SpellEntry
const *triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
5067 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5068 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5070 uint32 triggered_spell_id
= 0;
5071 Unit
* target
= pVictim
;
5072 int32 basepoints0
= 0;
5074 switch(triggeredByAuraSpell
->SpellFamilyName
)
5076 case SPELLFAMILY_MAGE
:
5078 switch(triggeredByAuraSpell
->Id
)
5083 Unit
* caster
= triggeredByAura
->GetCaster();
5087 triggered_spell_id
= 54648;
5095 // processed charge only counting case
5096 if(!triggered_spell_id
)
5099 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5103 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",triggeredByAuraSpell
->Id
,triggered_spell_id
);
5108 if(!target
|| target
!=this && !target
->isAlive())
5111 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5115 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5117 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5119 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5120 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5125 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
5127 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
5128 SpellEffectIndex effIndex
= triggeredByAura
->GetEffIndex();
5129 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
5131 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5132 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5134 // some dummy spells have trigger spell in spell data already (from 3.0.3)
5135 uint32 triggered_spell_id
= dummySpell
->EffectApplyAuraName
[effIndex
] == SPELL_AURA_DUMMY
? dummySpell
->EffectTriggerSpell
[effIndex
] : 0;
5136 Unit
* target
= pVictim
;
5137 int32 basepoints
[MAX_EFFECT_INDEX
] = {0, 0, 0};
5139 switch(dummySpell
->SpellFamilyName
)
5141 case SPELLFAMILY_GENERIC
:
5143 switch (dummySpell
->Id
)
5149 // return damage % to attacker but < 50% own total health
5150 basepoints
[0] = triggerAmount
*int32(damage
)/100;
5151 if (basepoints
[0] > (int32
)GetMaxHealth()/2)
5152 basepoints
[0] = (int32
)GetMaxHealth()/2;
5154 triggered_spell_id
= 25997;
5157 // Sweeping Strikes (NPC spells may be)
5161 // prevent chain of triggered spell from same triggered spell
5162 if (procSpell
&& procSpell
->Id
== 26654)
5165 target
= SelectRandomUnfriendlyTarget(pVictim
);
5169 triggered_spell_id
= 26654;
5172 // Twisted Reflection (boss spell)
5174 triggered_spell_id
= 21064;
5179 if (!procSpell
|| procSpell
->Id
== 24659)
5181 // Need remove one 24659 aura
5182 RemoveSingleSpellAurasFromStack(24659);
5185 // Restless Strength
5188 // Need remove one 24662 aura
5189 RemoveSingleSpellAurasFromStack(24662);
5192 // Adaptive Warding (Frostfire Regalia set)
5200 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
5201 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
5203 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
5205 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& UI64LIT(0x10000000)))
5215 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5217 case SPELL_SCHOOL_NORMAL
:
5218 case SPELL_SCHOOL_HOLY
:
5219 return false; // ignored
5220 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
5221 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
5222 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
5223 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
5224 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
5232 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
5238 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5240 case SPELL_SCHOOL_NORMAL
:
5241 return false; // ignore
5242 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
5243 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
5244 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
5245 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
5246 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
5247 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
5255 // Mana Leech (Passive) (Priest Pet Aura)
5259 target
= GetOwner();
5263 triggered_spell_id
= 34650;
5271 if (!roll_chance_i(triggerAmount
))
5274 // Remove any stun effect on target
5275 AuraMap
& Auras
= pVictim
->GetAuras();
5276 for(AuraMap::const_iterator iter
= Auras
.begin(); iter
!= Auras
.end();)
5278 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
5279 if( spell
->Mechanic
== MECHANIC_STUN
||
5280 spell
->EffectMechanic
[iter
->second
->GetEffIndex()] == MECHANIC_STUN
)
5282 pVictim
->RemoveAurasDueToSpell(spell
->Id
);
5283 iter
= Auras
.begin();
5293 // Cast finish spell at last charge
5294 if (triggeredByAura
->GetAuraCharges() > 1)
5298 triggered_spell_id
= 33494;
5301 // Vampiric Aura (boss spell)
5304 basepoints
[0] = 3 * damage
; // 300%
5305 if (basepoints
[0] < 0)
5308 triggered_spell_id
= 31285;
5312 // Aura of Madness (Darkmoon Card: Madness trinket)
5313 //=====================================================
5314 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
5315 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
5316 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
5317 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5318 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
5319 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
5320 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
5321 // 41011 Martyr Complex: +35 stamina (All classes)
5322 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5323 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5326 if(GetTypeId() != TYPEID_PLAYER
)
5329 // Select class defined buff
5332 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5333 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5335 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
5336 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5339 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
5340 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
5342 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
5343 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5346 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
5347 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
5348 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
5349 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
5351 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
5352 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5355 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
5357 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
5358 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5366 if (roll_chance_i(10))
5367 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
5370 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
5371 // cast 45479 Light's Wrath if Exalted by Aldor
5372 // cast 45429 Arcane Bolt if Exalted by Scryers
5375 if(GetTypeId() != TYPEID_PLAYER
)
5378 // Get Aldor reputation rank
5379 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5382 triggered_spell_id
= 45479;
5385 // Get Scryers reputation rank
5386 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5388 // triggered at positive/self casts also, current attack target used then
5389 if(IsFriendlyTo(target
))
5391 target
= getVictim();
5394 uint64 selected_guid
= ((Player
*)this)->GetSelection();
5395 target
= ObjectAccessor::GetUnit(*this,selected_guid
);
5399 if(IsFriendlyTo(target
))
5403 triggered_spell_id
= 45429;
5408 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
5409 // cast 45480 Light's Strength if Exalted by Aldor
5410 // cast 45428 Arcane Strike if Exalted by Scryers
5413 if(GetTypeId() != TYPEID_PLAYER
)
5416 // Get Aldor reputation rank
5417 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5420 triggered_spell_id
= 45480;
5423 // Get Scryers reputation rank
5424 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5426 triggered_spell_id
= 45428;
5431 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
5432 // cast 45431 Arcane Insight if Exalted by Aldor
5433 // cast 45432 Light's Ward if Exalted by Scryers
5436 if(GetTypeId() != TYPEID_PLAYER
)
5439 // Get Aldor reputation rank
5440 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5443 triggered_spell_id
= 45432;
5446 // Get Scryers reputation rank
5447 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5450 triggered_spell_id
= 45431;
5455 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
5456 // cast 45478 Light's Salvation if Exalted by Aldor
5457 // cast 45430 Arcane Surge if Exalted by Scryers
5460 if(GetTypeId() != TYPEID_PLAYER
)
5463 // Get Aldor reputation rank
5464 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5467 triggered_spell_id
= 45478;
5470 // Get Scryers reputation rank
5471 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5473 triggered_spell_id
= 45430;
5479 // Sunwell Exalted Caster Neck (??? neck)
5480 // cast ??? Light's Wrath if Exalted by Aldor
5481 // cast ??? Arcane Bolt if Exalted by Scryers*/
5483 return false; // old unused version
5487 triggered_spell_id
= 48503;
5488 basepoints
[0] = triggerAmount
;
5492 // Vampiric Touch (generic, used by some boss)
5496 triggered_spell_id
= 52724;
5497 basepoints
[0] = damage
/ 2;
5501 // Shadowfiend Death (Gain mana if pet dies with Glyph of Shadowfiend)
5504 Unit
*owner
= GetOwner();
5505 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
5508 // Glyph of Shadowfiend (need cast as self cast for owner, no hidden cooldown)
5509 owner
->CastSpell(owner
,58227,true,castItem
,triggeredByAura
);
5512 // Glyph of Life Tap
5514 triggered_spell_id
= 63321;
5516 // Item - Shadowmourne Legendary
5519 if (!roll_chance_i(triggerAmount
))
5522 Aura
*aur
= GetAura(71905, EFFECT_INDEX_0
);
5523 if (aur
&& uint32(aur
->GetStackAmount() + 1) >= aur
->GetSpellProto()->StackAmount
)
5525 RemoveAurasDueToSpell(71905);
5526 CastSpell(this, 71904, true); // Chaos Bane
5530 triggered_spell_id
= 71905;
5537 case SPELLFAMILY_MAGE
:
5540 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
5542 if (getPowerType() != POWER_MANA
)
5546 basepoints
[0] = (triggerAmount
* GetMaxPower(POWER_MANA
) / 100);
5548 triggered_spell_id
= 29442;
5551 // Master of Elements
5552 if (dummySpell
->SpellIconID
== 1920)
5558 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5559 basepoints
[0] = cost
* triggerAmount
/100;
5560 if (basepoints
[0] <=0)
5564 triggered_spell_id
= 29077;
5569 if (dummySpell
->SpellIconID
== 2120)
5575 switch (dummySpell
->Id
)
5577 case 31571: triggered_spell_id
= 57529; break;
5578 case 31572: triggered_spell_id
= 57531; break;
5580 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u",dummySpell
->Id
);
5587 if (dummySpell
->SpellIconID
== 2999)
5589 if (effIndex
!= EFFECT_INDEX_0
)
5591 Aura
*counter
= GetAura(triggeredByAura
->GetId(), EFFECT_INDEX_1
);
5595 // Count spell criticals in a row in second aura
5596 Modifier
*mod
= counter
->GetModifier();
5597 if (procEx
& PROC_EX_CRITICAL_HIT
)
5600 if (mod
->m_amount
< 100) // not enough
5602 // Crititcal counted -> roll chance
5603 if (roll_chance_i(triggerAmount
))
5604 CastSpell(this, 48108, true, castItem
, triggeredByAura
);
5610 if (dummySpell
->SpellIconID
== 2998)
5615 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5616 basepoints
[0] = cost
* triggerAmount
/100;
5617 if (basepoints
[0] <=0)
5619 triggered_spell_id
= 44450;
5623 // Incanter's Regalia set (add trigger chance to Mana Shield)
5624 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5626 if (GetTypeId() != TYPEID_PLAYER
)
5630 triggered_spell_id
= 37436;
5633 switch(dummySpell
->Id
)
5642 switch (dummySpell
->Id
)
5644 case 11119: basepoints
[0] = int32(0.04f
*damage
); break;
5645 case 11120: basepoints
[0] = int32(0.08f
*damage
); break;
5646 case 12846: basepoints
[0] = int32(0.12f
*damage
); break;
5647 case 12847: basepoints
[0] = int32(0.16f
*damage
); break;
5648 case 12848: basepoints
[0] = int32(0.20f
*damage
); break;
5650 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
5654 triggered_spell_id
= 12654;
5660 //last charge and crit
5661 if (triggeredByAura
->GetAuraCharges() <= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
5662 return true; // charge counting (will removed)
5664 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
5665 return (procEx
& PROC_EX_CRITICAL_HIT
); // charge update only at crit hits, no hidden cooldowns
5667 // Glyph of Ice Block
5670 if (GetTypeId() != TYPEID_PLAYER
)
5673 // not 100% safe with client version switches but for 3.1.3 no spells with cooldown that can have mage player except Frost Nova.
5674 ((Player
*)this)->RemoveSpellCategoryCooldown(35, true);
5677 // Glyph of Polymorph
5680 if (!pVictim
|| !pVictim
->isAlive())
5683 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE
);
5684 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE_PERCENT
);
5687 // Blessing of Ancient Kings
5691 if (!IsPositiveSpell(procSpell
->Id
))
5694 triggered_spell_id
= 64413;
5695 basepoints
[0] = damage
* 15 / 100;
5701 case SPELLFAMILY_WARRIOR
:
5704 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0000000800000000))
5706 // check attack comes not from behind
5707 if (!HasInArc(M_PI_F
, pVictim
))
5710 triggered_spell_id
= 22858;
5714 if (dummySpell
->SpellIconID
== 1697)
5716 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
5717 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
5719 // Need stun or root mechanic
5720 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_STUN_MASK
))
5723 switch (dummySpell
->Id
)
5725 case 29838: triggered_spell_id
=29842; break;
5726 case 29834: triggered_spell_id
=29841; break;
5727 case 42770: triggered_spell_id
=42771; break;
5729 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
5737 if (dummySpell
->SpellIconID
== 3214)
5739 triggered_spell_id
= 59653;
5740 basepoints
[0] = GetShieldBlockValue() * triggerAmount
/ 100;
5745 if (dummySpell
->Id
== 12328)
5747 // prevent chain of triggered spell from same triggered spell
5748 if(procSpell
&& procSpell
->Id
== 26654)
5751 target
= SelectRandomUnfriendlyTarget(pVictim
);
5755 triggered_spell_id
= 26654;
5760 case SPELLFAMILY_WARLOCK
:
5762 // Seed of Corruption
5763 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
5765 Modifier
* mod
= triggeredByAura
->GetModifier();
5766 // if damage is more than need or target die from damage deal finish spell
5767 if( mod
->m_amount
<= (int32
)damage
|| GetHealth() <= damage
)
5769 // remember guid before aura delete
5770 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5772 // Remove aura (before cast for prevent infinite loop handlers)
5773 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5775 // Cast finish spell (triggeredByAura already not exist!)
5776 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
5777 return true; // no hidden cooldown
5781 mod
->m_amount
-=damage
;
5784 // Seed of Corruption (Mobs cast) - no die req
5785 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0) && dummySpell
->SpellIconID
== 1932)
5787 Modifier
* mod
= triggeredByAura
->GetModifier();
5788 // if damage is more than need deal finish spell
5789 if( mod
->m_amount
<= (int32
)damage
)
5791 // remember guid before aura delete
5792 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5794 // Remove aura (before cast for prevent infinite loop handlers)
5795 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5797 // Cast finish spell (triggeredByAura already not exist!)
5798 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
5799 return true; // no hidden cooldown
5802 mod
->m_amount
-=damage
;
5806 if (dummySpell
->SpellIconID
== 3222)
5811 basepoints
[0] = damage
* triggerAmount
/ 100;
5812 triggered_spell_id
= 54181;
5815 switch(dummySpell
->Id
)
5817 // Nightfall & Glyph of Corruption
5823 triggered_spell_id
= 17941;
5832 basepoints
[0] = int32(damage
*triggerAmount
/100);
5834 triggered_spell_id
= 30294;
5837 // Shadowflame (Voidheart Raiment set bonus)
5840 triggered_spell_id
= 37379;
5843 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
5851 basepoints
[0] = damage
* triggerAmount
/100;
5852 triggered_spell_id
= 37382;
5855 // Shadowflame Hellfire (Voidheart Raiment set bonus)
5858 triggered_spell_id
= 37378;
5864 if (triggeredByAura
->GetEffIndex() != EFFECT_INDEX_0
)
5867 // Glyph of Siphon Life
5868 if (Aura
*aur
= GetAura(56216, EFFECT_INDEX_0
))
5869 triggerAmount
+= triggerAmount
* aur
->GetModifier()->m_amount
/ 100;
5871 basepoints
[0] = int32(damage
* triggerAmount
/ 100);
5872 triggered_spell_id
= 63106;
5878 case SPELLFAMILY_PRIEST
:
5881 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
5883 if(!pVictim
|| !pVictim
->isAlive())
5886 // pVictim is caster of aura
5887 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5890 // Energize 0.25% of max. mana
5891 pVictim
->CastSpell(pVictim
,57669,true,castItem
,triggeredByAura
);
5892 return true; // no hidden cooldown
5895 switch(dummySpell
->SpellIconID
)
5897 // Improved Shadowform
5900 if(!roll_chance_i(triggerAmount
))
5903 RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT
);
5904 RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED
);
5910 basepoints
[0] = damage
* triggerAmount
/100;
5911 triggered_spell_id
= 47753;
5920 // avoid double triggering from 2 auras
5921 if (triggeredByAura
->GetEffIndex() != EFFECT_INDEX_1
)
5926 Aura
* healingAura
= pVictim
->GetAura(SPELL_AURA_PERIODIC_HEAL
, SPELLFAMILY_PRIEST
, UI64LIT(0x40), 0, GetGUID());
5930 int32 healingfromticks
= healingAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
);
5932 basepoints
[0] = healingfromticks
* triggerAmount
/ 100;
5933 triggered_spell_id
= 63544;
5936 // Improved Devouring Plague
5942 if (triggeredByAura
->GetEffIndex() != EFFECT_INDEX_1
)
5945 Aura
* leachAura
= pVictim
->GetAura(SPELL_AURA_PERIODIC_LEECH
, SPELLFAMILY_PRIEST
, UI64LIT(0x02000000), NULL
, GetGUID());
5949 int32 damagefromticks
= leachAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
);
5950 basepoints
[0] = damagefromticks
* triggerAmount
/ 100;
5951 triggered_spell_id
= 63675;
5956 switch(dummySpell
->Id
)
5961 // Return if self damage
5962 if (this == pVictim
)
5965 // Heal amount - Self/Team
5966 int32 team
= triggerAmount
*damage
/500;
5967 int32 self
= triggerAmount
*damage
/100 - team
;
5968 CastCustomSpell(this,15290,&team
,&self
,NULL
,true,castItem
,triggeredByAura
);
5969 return true; // no hidden cooldown
5971 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
5974 // Shadow Word: Pain
5975 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5976 triggered_spell_id
= 40441;
5978 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
5979 triggered_spell_id
= 40440;
5986 // Oracle Healing Bonus ("Garments of the Oracle" set)
5990 basepoints
[0] = int32(damage
* 10/100);
5992 triggered_spell_id
= 26170;
5995 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
5998 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
6002 basepoints
[0] = damage
* triggerAmount
/100;
6004 triggered_spell_id
= 39373;
6007 // Greater Heal (Vestments of Faith (Priest Tier 3) - 4 pieces bonus)
6010 triggered_spell_id
= 28810;
6013 // Glyph of Dispel Magic
6016 if(!target
->IsFriendlyTo(this))
6019 basepoints
[0] = int32(target
->GetMaxHealth() * triggerAmount
/ 100);
6020 // triggered_spell_id in spell data
6026 case SPELLFAMILY_DRUID
:
6028 switch(dummySpell
->Id
)
6030 // Leader of the Pack
6033 // dummy m_amount store health percent (!=0 if Improved Leader of the Pack applied)
6034 int32 heal_percent
= triggeredByAura
->GetModifier()->m_amount
;
6038 // check explicitly only to prevent mana cast when halth cast cooldown
6039 if (cooldown
&& ((Player
*)this)->HasSpellCooldown(34299))
6043 triggered_spell_id
= 34299;
6044 basepoints
[0] = GetMaxHealth() * heal_percent
/ 100;
6048 if (triggeredByAura
->GetCasterGUID() == GetGUID())
6050 if (SpellEntry
const* manaCastEntry
= sSpellStore
.LookupEntry(60889))
6052 int32 mana_percent
= manaCastEntry
->CalculateSimpleValue(EFFECT_INDEX_0
) * heal_percent
;
6053 CastCustomSpell(this, manaCastEntry
, &mana_percent
, NULL
, NULL
, true, castItem
, triggeredByAura
);
6058 // Healing Touch (Dreamwalker Raiment set)
6062 basepoints
[0] = int32(procSpell
->manaCost
* 30 / 100);
6064 triggered_spell_id
= 28742;
6067 // Healing Touch Refund (Idol of Longevity trinket)
6071 triggered_spell_id
= 28848;
6074 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
6079 triggered_spell_id
= 37238;
6082 // Druid Tier 6 Trinket
6088 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
6090 triggered_spell_id
= 40445;
6094 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
6096 triggered_spell_id
= 40446;
6099 // Mangle (Bear) and Mangle (Cat)
6100 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000044000000000))
6102 triggered_spell_id
= 40452;
6108 if (!roll_chance_f(chance
))
6117 // Deadly Interrupt Effect
6118 triggered_spell_id
= 32747;
6121 // Glyph of Rejuvenation
6125 if (pVictim
->GetMaxHealth() < 2 * pVictim
->GetHealth())
6127 basepoints
[0] = triggerAmount
* damage
/ 100;
6128 triggered_spell_id
= 54755;
6131 // Item - Druid T10 Restoration 4P Bonus (Rejuvenation)
6134 if (!procSpell
|| GetTypeId() != TYPEID_PLAYER
)
6138 if (procSpell
->EffectRadiusIndex
[EFFECT_INDEX_0
])
6139 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(procSpell
->EffectRadiusIndex
[EFFECT_INDEX_0
]));
6141 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(procSpell
->rangeIndex
));
6143 ((Player
*)this)->ApplySpellMod(procSpell
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
6145 Unit
*second
= pVictim
->SelectRandomFriendlyTarget(pVictim
, radius
);
6150 pVictim
->CastSpell(second
, procSpell
, true, NULL
, triggeredByAura
, GetGUID());
6155 if (dummySpell
->SpellIconID
== 2856)
6159 // Only 0 aura can proc
6160 if (effIndex
!= EFFECT_INDEX_0
)
6163 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6167 if (!roll_chance_i(60))
6169 triggered_spell_id
= 48518;
6174 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
6178 triggered_spell_id
= 48517;
6185 else if (dummySpell
->SpellIconID
== 2860)
6187 triggered_spell_id
= 48504;
6188 basepoints
[0] = triggerAmount
* damage
/ 100;
6193 case SPELLFAMILY_ROGUE
:
6195 switch(dummySpell
->Id
)
6197 // Deadly Throw Interrupt
6200 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
6201 if (this == pVictim
)
6204 triggered_spell_id
= 32747;
6209 if (dummySpell
->SpellIconID
== 2909)
6211 // "refresh your Slice and Dice duration to its 5 combo point maximum"
6212 // lookup Slice and Dice
6213 AuraList
const& sd
= GetAurasByType(SPELL_AURA_MOD_HASTE
);
6214 for(AuraList::const_iterator itr
= sd
.begin(); itr
!= sd
.end(); ++itr
)
6216 SpellEntry
const *spellProto
= (*itr
)->GetSpellProto();
6217 if (spellProto
->SpellFamilyName
== SPELLFAMILY_ROGUE
&&
6218 (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000040000)))
6220 (*itr
)->SetAuraMaxDuration(GetSpellMaxDuration(spellProto
));
6221 (*itr
)->RefreshAura();
6228 if (dummySpell
->SpellIconID
== 2963)
6230 triggered_spell_id
= 44289;
6234 if (dummySpell
->SpellIconID
== 2116)
6240 basepoints
[0] = procSpell
->manaCost
* triggerAmount
/100;
6241 if (basepoints
[0] <= 0)
6245 triggered_spell_id
= 31663;
6250 case SPELLFAMILY_HUNTER
:
6252 // Aspect of the Viper
6253 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x4000000000000))
6255 uint32 maxmana
= GetMaxPower(POWER_MANA
);
6256 basepoints
[0] = int32(maxmana
* GetAttackTime(RANGED_ATTACK
)/1000.0f
/100.0f
);
6259 triggered_spell_id
= 34075;
6262 // Thrill of the Hunt
6263 if (dummySpell
->SpellIconID
== 2236)
6269 int32 mana
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
6270 basepoints
[0] = mana
* 40/100;
6271 if (basepoints
[0] <= 0)
6275 triggered_spell_id
= 34720;
6279 if (dummySpell
->SpellIconID
== 3406)
6281 triggered_spell_id
= 57669;
6286 if ( dummySpell
->SpellIconID
== 3579 )
6288 // Proc only from periodic (from trap activation proc another aura of this spell)
6289 if (!(procFlag
& PROC_FLAG_ON_DO_PERIODIC
) || !roll_chance_i(triggerAmount
))
6291 triggered_spell_id
= 56453;
6295 // Rapid Recuperation
6296 if ( dummySpell
->SpellIconID
== 3560 )
6298 // This effect only from Rapid Killing (mana regen)
6299 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0100000000000000)))
6304 switch(dummySpell
->Id
)
6306 case 53228: // Rank 1
6307 triggered_spell_id
= 56654;
6309 case 53232: // Rank 2
6310 triggered_spell_id
= 58882;
6315 // Glyph of Mend Pet
6316 if(dummySpell
->Id
== 57870)
6318 pVictim
->CastSpell(pVictim
, 57894, true, NULL
, NULL
, GetGUID());
6323 case SPELLFAMILY_PALADIN
:
6325 // Seal of Righteousness - melee proc dummy (addition ${$MWS*(0.022*$AP+0.044*$SPH)} damage)
6326 if ((dummySpell
->SpellFamilyFlags
& UI64LIT(0x000000008000000)) && effIndex
== EFFECT_INDEX_0
)
6328 triggered_spell_id
= 25742;
6329 float ap
= GetTotalAttackPowerValue(BASE_ATTACK
);
6330 int32 holy
= SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_HOLY
);
6333 basepoints
[0] = GetAttackTime(BASE_ATTACK
) * int32(ap
*0.022f
+ 0.044f
* holy
) / 1000;
6336 // Righteous Vengeance
6337 if (dummySpell
->SpellIconID
== 3025)
6340 basepoints
[0] = triggerAmount
*damage
/400;
6341 triggered_spell_id
= 61840;
6345 if (dummySpell
->SpellIconID
== 3030)
6348 basepoints
[0] = triggerAmount
*damage
/400;
6349 triggered_spell_id
= 54203;
6352 switch(dummySpell
->Id
)
6354 // Judgement of Light
6357 basepoints
[0] = int32( pVictim
->GetMaxHealth() * triggeredByAura
->GetModifier()->m_amount
/ 100 );
6358 pVictim
->CastCustomSpell(pVictim
, 20267, &basepoints
[0], NULL
, NULL
, true, NULL
, triggeredByAura
);
6361 // Judgement of Wisdom
6364 if (pVictim
->getPowerType() == POWER_MANA
)
6366 // 2% of maximum base mana
6367 basepoints
[0] = int32(pVictim
->GetCreateMana() * 2 / 100);
6368 pVictim
->CastCustomSpell(pVictim
, 20268, &basepoints
[0], NULL
, NULL
, true, NULL
, triggeredByAura
);
6372 // Heart of the Crusader (Rank 1)
6374 triggered_spell_id
= 21183;
6376 // Heart of the Crusader (Rank 2)
6378 triggered_spell_id
= 54498;
6380 // Heart of the Crusader (Rank 3)
6382 triggered_spell_id
= 54499;
6384 case 20911: // Blessing of Sanctuary
6385 case 25899: // Greater Blessing of Sanctuary
6388 switch (target
->getPowerType())
6391 triggered_spell_id
= 57319;
6398 // Holy Power (Redemption Armor set)
6404 // Set class defined buff
6405 switch (pVictim
->getClass())
6411 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6415 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6419 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
6422 triggered_spell_id
= 28790; // Increases the friendly target's armor
6429 // Spiritual Attunement
6433 // if healed by another unit (pVictim)
6434 if (this == pVictim
)
6438 basepoints
[0] = triggerAmount
*damage
/100;
6440 triggered_spell_id
= 31786;
6443 // Seal of Vengeance (damage calc on apply aura)
6446 if (effIndex
!= EFFECT_INDEX_0
) // effect 1,2 used by seal unleashing code
6449 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6450 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595) )
6451 triggered_spell_id
= 31803; // Holy Vengeance
6453 // Add 5-stack effect from Holy Vengeance
6455 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6456 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6458 if( ((*itr
)->GetId() == 31803) && (*itr
)->GetCasterGUID()==GetGUID())
6460 stacks
= (*itr
)->GetStackAmount();
6465 CastSpell(target
,42463,true,NULL
,triggeredByAura
);
6468 // Judgements of the Wise
6472 // triggered only at casted Judgement spells, not at additional Judgement effects
6473 if(!procSpell
|| procSpell
->Category
!= 1210)
6477 triggered_spell_id
= 31930;
6480 CastSpell(this, 57669, true, NULL
, triggeredByAura
);
6482 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
6490 // Flash of light/Holy light
6491 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x00000000C0000000))
6493 triggered_spell_id
= 40471;
6497 else if (GetSpellSpecific(procSpell
->Id
)==SPELL_JUDGEMENT
)
6499 triggered_spell_id
= 40472;
6505 if (!roll_chance_f(chance
))
6510 // Light's Beacon (heal target area aura)
6513 // not do bonus heal for explicit beacon focus healing
6514 if (GetGUID() == triggeredByAura
->GetCasterGUID())
6518 Unit
* beacon
= triggeredByAura
->GetCaster();
6522 // find caster main aura at beacon
6524 Unit::AuraList
const& baa
= beacon
->GetAurasByType(SPELL_AURA_PERIODIC_TRIGGER_SPELL
);
6525 for(Unit::AuraList::const_iterator i
= baa
.begin(); i
!= baa
.end(); ++i
)
6527 if ((*i
)->GetId() == 53563 && (*i
)->GetCasterGUID() == pVictim
->GetGUID())
6534 // original heal must be form beacon caster
6538 triggered_spell_id
= 53652; // Beacon of Light
6539 basepoints
[0] = triggeredByAura
->GetModifier()->m_amount
*damage
/100;
6541 // cast with original caster set but beacon to beacon for apply caster mods and avoid LoS check
6542 beacon
->CastCustomSpell(beacon
,triggered_spell_id
,&basepoints
[0],NULL
,NULL
,true,castItem
,triggeredByAura
,pVictim
->GetGUID());
6545 // Seal of Corruption (damage calc on apply aura)
6548 if (effIndex
!= EFFECT_INDEX_0
) // effect 1,2 used by seal unleashing code
6551 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6552 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595))
6553 triggered_spell_id
= 53742; // Blood Corruption
6555 // Add 5-stack effect from Blood Corruption
6557 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6558 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6560 if( ((*itr
)->GetId() == 53742) && (*itr
)->GetCasterGUID()==GetGUID())
6562 stacks
= (*itr
)->GetStackAmount();
6567 CastSpell(target
,53739,true,NULL
,triggeredByAura
);
6570 // Glyph of Holy Light
6573 triggered_spell_id
= 54968;
6574 basepoints
[0] = triggerAmount
*damage
/100;
6577 // Glyph of Divinity
6580 // Lookup base amount mana restore
6581 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
6583 if (procSpell
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
6585 int32 mana
= procSpell
->CalculateSimpleValue(SpellEffectIndex(i
));
6586 CastCustomSpell(this, 54986, NULL
, &mana
, NULL
, true, castItem
, triggeredByAura
);
6592 // Sacred Shield (buff)
6595 triggered_spell_id
= 66922;
6596 SpellEntry
const* triggeredEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6597 if (!triggeredEntry
)
6600 basepoints
[0] = int32(damage
/ (GetSpellDuration(triggeredEntry
) / triggeredEntry
->EffectAmplitude
[EFFECT_INDEX_0
]));
6604 // Sacred Shield (talent rank)
6607 // triggered_spell_id in spell data
6614 case SPELLFAMILY_SHAMAN
:
6616 switch(dummySpell
->Id
)
6618 // Totemic Power (The Earthshatterer set)
6624 // Set class defined buff
6625 switch (pVictim
->getClass())
6631 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6635 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6639 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
6642 triggered_spell_id
= 28827; // Increases the friendly target's armor
6649 // Lesser Healing Wave (Totem of Flowing Water Relic)
6653 triggered_spell_id
= 28850;
6656 // Windfury Weapon (Passive) 1-5 Ranks
6659 if(GetTypeId()!=TYPEID_PLAYER
)
6662 if(!castItem
|| !castItem
->IsEquipped())
6665 // custom cooldown processing case
6666 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6669 // Now amount of extra power stored in 1 effect of Enchant spell
6670 // Get it by item enchant id
6672 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
6674 case 283: spellId
= 8232; break; // 1 Rank
6675 case 284: spellId
= 8235; break; // 2 Rank
6676 case 525: spellId
= 10486; break; // 3 Rank
6677 case 1669:spellId
= 16362; break; // 4 Rank
6678 case 2636:spellId
= 25505; break; // 5 Rank
6679 case 3785:spellId
= 58801; break; // 6 Rank
6680 case 3786:spellId
= 58803; break; // 7 Rank
6681 case 3787:spellId
= 58804; break; // 8 Rank
6684 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
6685 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
6690 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
6691 if(!windfurySpellEntry
)
6693 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
6697 int32 extra_attack_power
= CalculateSpellDamage(pVictim
, windfurySpellEntry
, EFFECT_INDEX_1
);
6700 if (castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
6702 // Value gained from additional AP
6703 basepoints
[0] = int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
6704 triggered_spell_id
= 33750;
6709 // Value gained from additional AP
6710 basepoints
[0] = int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
6711 triggered_spell_id
= 25504;
6714 // apply cooldown before cast to prevent processing itself
6716 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6719 for ( uint32 i
= 0; i
<2; ++i
)
6720 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints
[0],NULL
,NULL
,true,castItem
,triggeredByAura
);
6724 // Shaman Tier 6 Trinket
6731 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6733 triggered_spell_id
= 40465; // Lightning Bolt
6736 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080))
6738 triggered_spell_id
= 40465; // Lesser Healing Wave
6741 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
6743 triggered_spell_id
= 40466; // Stormstrike
6749 if (!roll_chance_f(chance
))
6755 // Glyph of Healing Wave
6758 // Not proc from self heals
6761 basepoints
[0] = triggerAmount
* damage
/ 100;
6763 triggered_spell_id
= 55533;
6770 target
= GetOwner();
6773 basepoints
[0] = triggerAmount
* damage
/ 100;
6774 triggered_spell_id
= 58879;
6777 // Glyph of Totem of Wrath
6780 Totem
* totem
= GetTotem(TOTEM_SLOT_FIRE
);
6784 // find totem aura bonus
6785 AuraList
const& spellPower
= totem
->GetAurasByType(SPELL_AURA_NONE
);
6786 for(AuraList::const_iterator i
= spellPower
.begin();i
!= spellPower
.end(); ++i
)
6788 // select proper aura for format aura type in spell proto
6789 if ((*i
)->GetTarget()==totem
&& (*i
)->GetSpellProto()->EffectApplyAuraName
[(*i
)->GetEffIndex()] == SPELL_AURA_MOD_HEALING_DONE
&&
6790 (*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000004000000))
6792 basepoints
[0] = triggerAmount
* (*i
)->GetModifier()->m_amount
/ 100;
6800 basepoints
[1] = basepoints
[0];
6801 triggered_spell_id
= 63283; // Totem of Wrath, caster bonus
6805 // Shaman T8 Elemental 4P Bonus
6808 basepoints
[0] = int32( triggerAmount
* damage
/ 100 );
6809 triggered_spell_id
= 64930; // Electrified
6812 // Shaman T9 Elemental 4P Bonus
6815 basepoints
[0] = int32( triggerAmount
* damage
/ 100 );
6816 triggered_spell_id
= 71824;
6820 // Storm, Earth and Fire
6821 if (dummySpell
->SpellIconID
== 3063)
6823 // Earthbind Totem summon only
6824 if(procSpell
->Id
!= 2484)
6827 if (!roll_chance_i(triggerAmount
))
6830 triggered_spell_id
= 64695;
6833 // Ancestral Awakening
6834 if (dummySpell
->SpellIconID
== 3065)
6836 triggered_spell_id
= 52759;
6837 basepoints
[0] = triggerAmount
* damage
/ 100;
6842 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
6845 basepoints
[0] = triggerAmount
;
6847 // Glyph of Earth Shield
6848 if (Aura
* aur
= GetDummyAura(63279))
6850 int32 aur_mod
= aur
->GetModifier()->m_amount
;
6851 basepoints
[0] = int32(basepoints
[0] * (aur_mod
+ 100.0f
) / 100.0f
);
6854 triggered_spell_id
= 379;
6857 // Improved Water Shield
6858 if (dummySpell
->SpellIconID
== 2287)
6860 // Lesser Healing Wave need aditional 60% roll
6861 if ((procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)) && !roll_chance_i(60))
6863 // Chain Heal needs additional 30% roll
6864 if ((procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000100)) && !roll_chance_i(30))
6866 // lookup water shield
6867 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6868 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6870 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6871 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000002000000000)))
6873 uint32 spell
= (*itr
)->GetSpellProto()->EffectTriggerSpell
[(*itr
)->GetEffIndex()];
6874 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
6880 // Lightning Overload
6881 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
6883 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
6886 // custom cooldown processing case
6887 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6891 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
6892 switch (procSpell
->Id
)
6895 case 403: spellId
= 45284; break; // Rank 1
6896 case 529: spellId
= 45286; break; // Rank 2
6897 case 548: spellId
= 45287; break; // Rank 3
6898 case 915: spellId
= 45288; break; // Rank 4
6899 case 943: spellId
= 45289; break; // Rank 5
6900 case 6041: spellId
= 45290; break; // Rank 6
6901 case 10391: spellId
= 45291; break; // Rank 7
6902 case 10392: spellId
= 45292; break; // Rank 8
6903 case 15207: spellId
= 45293; break; // Rank 9
6904 case 15208: spellId
= 45294; break; // Rank 10
6905 case 25448: spellId
= 45295; break; // Rank 11
6906 case 25449: spellId
= 45296; break; // Rank 12
6907 case 49237: spellId
= 49239; break; // Rank 13
6908 case 49238: spellId
= 49240; break; // Rank 14
6910 case 421: spellId
= 45297; break; // Rank 1
6911 case 930: spellId
= 45298; break; // Rank 2
6912 case 2860: spellId
= 45299; break; // Rank 3
6913 case 10605: spellId
= 45300; break; // Rank 4
6914 case 25439: spellId
= 45301; break; // Rank 5
6915 case 25442: spellId
= 45302; break; // Rank 6
6916 case 49270: spellId
= 49268; break; // Rank 7
6917 case 49271: spellId
= 49269; break; // Rank 8
6919 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
6922 // No thread generated mod
6923 // TODO: exist special flag in spell attributes for this, need found and use!
6924 SpellModifier
*mod
= new SpellModifier(SPELLMOD_THREAT
,SPELLMOD_PCT
,-100,triggeredByAura
);
6926 ((Player
*)this)->AddSpellMod(mod
, true);
6928 // Remove cooldown (Chain Lightning - have Category Recovery time)
6929 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000002))
6930 ((Player
*)this)->RemoveSpellCooldown(spellId
);
6932 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
6934 ((Player
*)this)->AddSpellMod(mod
, false);
6936 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6937 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6942 if(dummySpell
->SpellIconID
== 3059)
6944 // lookup Lightning Shield
6945 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6946 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6948 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6949 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000400)))
6952 switch ((*itr
)->GetId())
6954 case 324: spell
= 26364; break;
6955 case 325: spell
= 26365; break;
6956 case 905: spell
= 26366; break;
6957 case 945: spell
= 26367; break;
6958 case 8134: spell
= 26369; break;
6959 case 10431: spell
= 26370; break;
6960 case 10432: spell
= 26363; break;
6961 case 25469: spell
= 26371; break;
6962 case 25472: spell
= 26372; break;
6963 case 49280: spell
= 49278; break;
6964 case 49281: spell
= 49279; break;
6968 CastSpell(target
, spell
, true, castItem
, triggeredByAura
);
6969 if ((*itr
)->DropAuraCharge())
6970 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6977 if (dummySpell
->SpellIconID
== 3780)
6979 Unit
*caster
= triggeredByAura
->GetCaster();
6981 if (!procSpell
|| !caster
)
6984 float distance
= caster
->GetDistance(pVictim
);
6985 int32 chance
= triggerAmount
;
6987 if (distance
< 15.0f
|| !roll_chance_i(chance
))
6990 // make triggered cast apply after current damage spell processing for prevent remove by it
6991 if(Spell
* spell
= GetCurrentSpell(CURRENT_GENERIC_SPELL
))
6992 spell
->AddTriggeredSpell(63685);
6997 case SPELLFAMILY_DEATHKNIGHT
:
7000 if (dummySpell
->SpellIconID
== 2664)
7002 basepoints
[0] = triggerAmount
;
7003 triggered_spell_id
= 50163;
7007 // Dancing Rune Weapon
7008 if (dummySpell
->Id
== 49028)
7010 // 1 dummy aura for dismiss rune blade
7011 if (effIndex
!= EFFECT_INDEX_2
)
7013 // TODO: wite script for this "fights on its own, doing the same attacks"
7014 // NOTE: Trigger here on every attack and spell cast
7018 if (dummySpell
->Id
== 49005)
7020 // TODO: need more info (cooldowns/PPM)
7021 triggered_spell_id
= 61607;
7025 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000010000))
7027 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
7028 triggered_spell_id
= 50181;
7033 if (dummySpell
->SpellIconID
== 2709)
7035 // only melee auto attack affected and Rune Strike
7036 if (procSpell
&& procSpell
->Id
!= 56815)
7039 basepoints
[0] = triggerAmount
* damage
/ 100;
7040 triggered_spell_id
= 51460;
7043 // Threat of Thassarian
7044 if (dummySpell
->SpellIconID
== 2023)
7047 if (!procSpell
|| !haveOffhandWeapon())
7049 // Chance as basepoints for dummy aura
7050 if (!roll_chance_i(triggerAmount
))
7053 switch (procSpell
->Id
)
7056 case 49020: // Rank 1
7057 triggered_spell_id
= 66198; break;
7058 case 51423: // Rank 2
7059 triggered_spell_id
= 66972; break;
7060 case 51424: // Rank 3
7061 triggered_spell_id
= 66973; break;
7062 case 51425: // Rank 4
7063 triggered_spell_id
= 66974; break;
7065 case 49143: // Rank 1
7066 triggered_spell_id
= 66196; break;
7067 case 51416: // Rank 2
7068 triggered_spell_id
= 66958; break;
7069 case 51417: // Rank 3
7070 triggered_spell_id
= 66959; break;
7071 case 51418: // Rank 4
7072 triggered_spell_id
= 66960; break;
7073 case 51419: // Rank 5
7074 triggered_spell_id
= 66961; break;
7075 case 55268: // Rank 6
7076 triggered_spell_id
= 66962; break;
7078 case 45462: // Rank 1
7079 triggered_spell_id
= 66216; break;
7080 case 49917: // Rank 2
7081 triggered_spell_id
= 66988; break;
7082 case 49918: // Rank 3
7083 triggered_spell_id
= 66989; break;
7084 case 49919: // Rank 4
7085 triggered_spell_id
= 66990; break;
7086 case 49920: // Rank 5
7087 triggered_spell_id
= 66991; break;
7088 case 49921: // Rank 6
7089 triggered_spell_id
= 66992; break;
7091 case 49998: // Rank 1
7092 triggered_spell_id
= 66188; break;
7093 case 49999: // Rank 2
7094 triggered_spell_id
= 66950; break;
7095 case 45463: // Rank 3
7096 triggered_spell_id
= 66951; break;
7097 case 49923: // Rank 4
7098 triggered_spell_id
= 66952; break;
7099 case 49924: // Rank 5
7100 triggered_spell_id
= 66953; break;
7103 triggered_spell_id
= 66217; break;
7105 case 45902: // Rank 1
7106 triggered_spell_id
= 66215; break;
7107 case 49926: // Rank 2
7108 triggered_spell_id
= 66975; break;
7109 case 49927: // Rank 3
7110 triggered_spell_id
= 66976; break;
7111 case 49928: // Rank 4
7112 triggered_spell_id
= 66977; break;
7113 case 49929: // Rank 5
7114 triggered_spell_id
= 66978; break;
7115 case 49930: // Rank 6
7116 triggered_spell_id
= 66979; break;
7122 // Runic Power Back on Snare/Root
7123 if (dummySpell
->Id
== 61257)
7125 // only for spells and hit/crit (trigger start always) and not start from self casted spells
7126 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7128 // Need snare or root mechanic
7129 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_SNARE_MASK
))
7131 triggered_spell_id
= 61258;
7136 if (dummySpell
->SpellIconID
== 1614)
7138 if (!roll_chance_f(GetUnitCriticalChance(BASE_ATTACK
, pVictim
)))
7140 basepoints
[0] = triggerAmount
* damage
/ 100;
7141 triggered_spell_id
= 50526;
7144 // Blood-Caked Blade
7145 if (dummySpell
->SpellIconID
== 138)
7147 // only main hand melee auto attack affected and Rune Strike
7148 if ((procFlag
& PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
) || procSpell
&& procSpell
->Id
!= 56815)
7151 // triggered_spell_id in spell data
7160 // processed charge only counting case
7161 if(!triggered_spell_id
)
7164 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
7168 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
7173 if(!target
|| target
!=this && !target
->isAlive())
7176 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
7179 if (basepoints
[EFFECT_INDEX_0
] || basepoints
[EFFECT_INDEX_1
] || basepoints
[EFFECT_INDEX_2
])
7180 CastCustomSpell(target
, triggered_spell_id
,
7181 basepoints
[EFFECT_INDEX_0
] ? &basepoints
[EFFECT_INDEX_0
] : NULL
,
7182 basepoints
[EFFECT_INDEX_1
] ? &basepoints
[EFFECT_INDEX_1
] : NULL
,
7183 basepoints
[EFFECT_INDEX_2
] ? &basepoints
[EFFECT_INDEX_2
] : NULL
,
7184 true, castItem
, triggeredByAura
);
7186 CastSpell(target
, triggered_spell_id
, true, castItem
, triggeredByAura
);
7188 if (cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7189 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
7194 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
7196 // Get triggered aura spell info
7197 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
7199 // Basepoints of trigger aura
7200 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7202 // Set trigger spell id, target, custom basepoints
7203 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
7204 Unit
* target
= NULL
;
7205 int32 basepoints
[MAX_EFFECT_INDEX
] = {0, 0, 0};
7207 if(triggeredByAura
->GetModifier()->m_auraname
== SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
)
7208 basepoints
[0] = triggerAmount
;
7210 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7211 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7213 // Try handle unknown trigger spells
7214 // Custom requirements (not listed in procEx) Warning! damage dealing after this
7215 // Custom triggered spells
7216 switch (auraSpellInfo
->SpellFamilyName
)
7218 case SPELLFAMILY_GENERIC
:
7219 switch(auraSpellInfo
->Id
)
7221 //case 191: // Elemental Response
7222 // switch (procSpell->School)
7224 // case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192; break;
7225 // case SPELL_SCHOOL_FROST: trigger_spell_id = 34193; break;
7226 // case SPELL_SCHOOL_ARCANE:trigger_spell_id = 34194; break;
7227 // case SPELL_SCHOOL_NATURE:trigger_spell_id = 34195; break;
7228 // case SPELL_SCHOOL_SHADOW:trigger_spell_id = 34196; break;
7229 // case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197; break;
7230 // case SPELL_SCHOOL_NORMAL:trigger_spell_id = 34198; break;
7233 //case 5301: break; // Defensive State (DND)
7234 //case 7137: break: // Shadow Charge (Rank 1)
7235 //case 7377: break: // Take Immune Periodic Damage <Not Working>
7236 //case 13358: break; // Defensive State (DND)
7237 //case 16092: break; // Defensive State (DND)
7238 //case 18943: break; // Double Attack
7239 //case 19194: break; // Double Attack
7240 //case 19817: break; // Double Attack
7241 //case 19818: break; // Double Attack
7242 //case 22835: break; // Drunken Rage
7243 // trigger_spell_id = 14822; break;
7244 case 23780: // Aegis of Preservation (Aegis of Preservation trinket)
7245 trigger_spell_id
= 23781;
7247 //case 24949: break; // Defensive State 2 (DND)
7248 case 27522: // Mana Drain Trigger
7249 case 40336: // Mana Drain Trigger
7250 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
7252 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
7253 if (pVictim
&& pVictim
->isAlive())
7254 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
7256 case 31255: // Deadly Swiftness (Rank 1)
7257 // whenever you deal damage to a target who is below 20% health.
7258 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
7262 trigger_spell_id
= 22588;
7264 //case 33207: break; // Gossip NPC Periodic - Fidget
7265 case 33896: // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
7266 trigger_spell_id
= 33898;
7268 //case 34082: break; // Advantaged State (DND)
7269 //case 34783: break: // Spell Reflection
7270 //case 35205: break: // Vanish
7271 //case 35321: break; // Gushing Wound
7272 //case 36096: break: // Spell Reflection
7273 //case 36207: break: // Steal Weapon
7274 //case 36576: break: // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
7275 //case 37030: break; // Chaotic Temperament
7276 //case 38363: break; // Gushing Wound
7277 //case 39215: break; // Gushing Wound
7278 //case 40250: break; // Improved Duration
7279 //case 40329: break; // Demo Shout Sensor
7280 //case 40364: break; // Entangling Roots Sensor
7281 //case 41054: break; // Copy Weapon
7282 // trigger_spell_id = 41055; break;
7283 //case 41248: break; // Consuming Strikes
7284 // trigger_spell_id = 41249; break;
7285 //case 42730: break: // Woe Strike
7286 //case 43453: break: // Rune Ward
7287 //case 43504: break; // Alterac Valley OnKill Proc Aura
7288 //case 44326: break: // Pure Energy Passive
7289 //case 44526: break; // Hate Monster (Spar) (30 sec)
7290 //case 44527: break; // Hate Monster (Spar Buddy) (30 sec)
7291 //case 44819: break; // Hate Monster (Spar Buddy) (>30% Health)
7292 //case 44820: break; // Hate Monster (Spar) (<30%)
7293 case 45057: // Evasive Maneuvers (Commendation of Kael`thas trinket)
7294 // reduce you below $s1% health
7295 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
7298 //case 45903: break: // Offensive State
7299 //case 46146: break: // [PH] Ahune Spanky Hands
7300 //case 46939: break; // Black Bow of the Betrayer
7301 // trigger_spell_id = 29471; - gain mana
7302 // 27526; - drain mana if possible
7303 case 43820: // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
7304 // Pct value stored in dummy
7305 basepoints
[0] = pVictim
->GetCreateHealth() * auraSpellInfo
->CalculateSimpleValue(EFFECT_INDEX_1
) / 100;
7308 //case 45205: break; // Copy Offhand Weapon
7309 //case 45343: break; // Dark Flame Aura
7310 //case 47300: break; // Dark Flame Aura
7311 //case 48876: break; // Beast's Mark
7312 // trigger_spell_id = 48877; break;
7313 //case 49059: break; // Horde, Hate Monster (Spar Buddy) (>30% Health)
7314 //case 50051: break; // Ethereal Pet Aura
7315 //case 50689: break; // Blood Presence (Rank 1)
7316 //case 50844: break; // Blood Mirror
7317 //case 52856: break; // Charge
7318 //case 54072: break; // Knockback Ball Passive
7319 //case 54476: break; // Blood Presence
7320 //case 54775: break; // Abandon Vehicle on Poly
7321 case 57345: // Darkmoon Card: Greatness
7325 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 60229;stat
= GetStat(STAT_STRENGTH
); }
7327 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 60233;stat
= GetStat(STAT_AGILITY
); }
7329 if (GetStat(STAT_INTELLECT
)> stat
) { trigger_spell_id
= 60234;stat
= GetStat(STAT_INTELLECT
);}
7331 if (GetStat(STAT_SPIRIT
) > stat
) { trigger_spell_id
= 60235; }
7334 //case 55580: break: // Mana Link
7335 //case 57587: break: // Steal Ranged ()
7336 //case 57594: break; // Copy Ranged Weapon
7337 //case 59237: break; // Beast's Mark
7338 // trigger_spell_id = 59233; break;
7339 //case 59288: break; // Infra-Green Shield
7340 //case 59532: break; // Abandon Passengers on Poly
7341 //case 59735: break: // Woe Strike
7342 case 64415: // // Val'anyr Hammer of Ancient Kings - Equip Effect
7345 if (!IsPositiveSpell(procSpell
->Id
))
7349 case 67702: // Death's Choice, Item - Coliseum 25 Normal Melee Trinket
7353 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67708;stat
= GetStat(STAT_STRENGTH
); }
7355 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67703; }
7358 case 67771: // Death's Choice (heroic), Item - Coliseum 25 Heroic Melee Trinket
7362 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67773;stat
= GetStat(STAT_STRENGTH
); }
7364 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67772; }
7369 case SPELLFAMILY_MAGE
:
7370 if (auraSpellInfo
->SpellIconID
== 2127) // Blazing Speed
7372 switch (auraSpellInfo
->Id
)
7374 case 31641: // Rank 1
7375 case 31642: // Rank 2
7376 trigger_spell_id
= 31643;
7379 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
7383 // Persistent Shield (Scarab Brooch trinket)
7384 else if(auraSpellInfo
->Id
== 26467)
7386 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
7387 basepoints
[0] = damage
* 15 / 100;
7389 trigger_spell_id
= 26470;
7392 case SPELLFAMILY_WARRIOR
:
7393 // Deep Wounds (replace triggered spells to directly apply DoT), dot spell have finilyflags
7394 if (auraSpellInfo
->SpellFamilyFlags
== UI64LIT(0x0) && auraSpellInfo
->SpellIconID
== 243)
7397 // DW should benefit of attack power, damage percent mods etc.
7398 // TODO: check if using offhand damage is correct and if it should be divided by 2
7399 if (haveOffhandWeapon() && getAttackTimer(BASE_ATTACK
) > getAttackTimer(OFF_ATTACK
))
7400 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
))/2;
7402 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXDAMAGE
))/2;
7404 switch (auraSpellInfo
->Id
)
7406 case 12834: basepoints
[0] = int32(weaponDamage
* 16 / 100); break;
7407 case 12849: basepoints
[0] = int32(weaponDamage
* 32 / 100); break;
7408 case 12867: basepoints
[0] = int32(weaponDamage
* 48 / 100); break;
7411 sLog
.outError("Unit::HandleProcTriggerSpell: DW unknown spell rank %u",auraSpellInfo
->Id
);
7415 // 1 tick/sec * 6 sec = 6 ticks
7418 trigger_spell_id
= 12721;
7421 if (auraSpellInfo
->Id
== 50421) // Scent of Blood
7422 trigger_spell_id
= 50422;
7424 case SPELLFAMILY_WARLOCK
:
7427 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
7429 // search for "Improved Drain Soul" dummy aura
7430 Unit::AuraList
const& mDummyAura
= GetAurasByType(SPELL_AURA_DUMMY
);
7431 for(Unit::AuraList::const_iterator i
= mDummyAura
.begin(); i
!= mDummyAura
.end(); ++i
)
7433 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
7435 // basepoints of trigger spell stored in dummyeffect of spellProto
7436 int32 basepoints
= GetMaxPower(POWER_MANA
) * (*i
)->GetSpellProto()->CalculateSimpleValue(EFFECT_INDEX_2
) / 100;
7437 CastCustomSpell(this, 18371, &basepoints
, NULL
, NULL
, true, castItem
, triggeredByAura
);
7441 // Not remove charge (aura removed on death in any cases)
7442 // Need for correct work Drain Soul SPELL_AURA_CHANNEL_DEATH_ITEM aura
7445 // Nether Protection
7446 else if (auraSpellInfo
->SpellIconID
== 1985)
7450 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7452 case SPELL_SCHOOL_NORMAL
:
7453 return false; // ignore
7454 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 54370; break;
7455 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 54371; break;
7456 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 54375; break;
7457 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 54372; break;
7458 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 54374; break;
7459 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
7465 else if (auraSpellInfo
->Id
== 28845)
7467 // When your health drops below 20% ....
7468 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
7472 else if (auraSpellInfo
->Id
== 63156 || auraSpellInfo
->Id
== 63158)
7474 // Looking for dummy effect
7475 Aura
*aur
= GetAura(auraSpellInfo
->Id
, EFFECT_INDEX_1
);
7479 // If target's health is not below equal certain value (35%) not proc
7480 if (int32(pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth()) > aur
->GetModifier()->m_amount
)
7485 case SPELLFAMILY_PRIEST
:
7487 // Greater Heal Refund (Avatar Raiment set)
7488 if (auraSpellInfo
->Id
==37594)
7490 // Not give if target already have full health
7491 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
7493 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
7494 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
7496 trigger_spell_id
= 37595;
7499 else if (auraSpellInfo
->SpellIconID
== 1875)
7501 switch (auraSpellInfo
->Id
)
7503 case 27811: trigger_spell_id
= 27813; break;
7504 case 27815: trigger_spell_id
= 27817; break;
7505 case 27816: trigger_spell_id
= 27818; break;
7507 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
7510 basepoints
[0] = damage
* triggerAmount
/ 100 / 3;
7515 case SPELLFAMILY_DRUID
:
7517 // Druid Forms Trinket
7518 if (auraSpellInfo
->Id
==37336)
7522 case FORM_NONE
: trigger_spell_id
= 37344;break;
7523 case FORM_CAT
: trigger_spell_id
= 37341;break;
7525 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
7526 case FORM_TREE
: trigger_spell_id
= 37342;break;
7527 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
7532 // Druid T9 Feral Relic (Lacerate, Swipe, Mangle, and Shred)
7533 else if (auraSpellInfo
->Id
==67353)
7537 case FORM_CAT
: trigger_spell_id
= 67355; break;
7539 case FORM_DIREBEAR
: trigger_spell_id
= 67354; break;
7546 case SPELLFAMILY_HUNTER
:
7548 if (auraSpellInfo
->SpellIconID
== 3247 && auraSpellInfo
->SpellVisual
[0] == 0)
7550 basepoints
[0] = damage
* triggerAmount
/ 100 / 8;
7551 trigger_spell_id
= 63468;
7554 // Rapid Recuperation
7555 else if (auraSpellInfo
->Id
== 53228 || auraSpellInfo
->Id
== 53232)
7557 // This effect only from Rapid Fire (ability cast)
7558 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000020)))
7562 case SPELLFAMILY_PALADIN
:
7566 if (auraSpellInfo->SpellIconID == 2137)
7568 switch (auraSpellInfo->Id)
7570 case 31828: // Rank 1
7571 case 31829: // Rank 2
7572 case 31830: // Rank 3
7575 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
7581 if (auraSpellInfo
->Id
==37705)
7583 trigger_spell_id
= 37706;
7587 if (auraSpellInfo
->Id
==60510)
7589 trigger_spell_id
= 60515;
7593 else if (auraSpellInfo
->SpellIconID
==241)
7597 // procspell is triggered spell but we need mana cost of original casted spell
7598 uint32 originalSpellId
= procSpell
->Id
;
7600 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0001000000000000))
7602 switch(procSpell
->Id
)
7604 case 25914: originalSpellId
= 20473; break;
7605 case 25913: originalSpellId
= 20929; break;
7606 case 25903: originalSpellId
= 20930; break;
7607 case 27175: originalSpellId
= 27174; break;
7608 case 33074: originalSpellId
= 33072; break;
7609 case 48820: originalSpellId
= 48824; break;
7610 case 48821: originalSpellId
= 48825; break;
7612 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
7616 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
7619 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
7622 // percent stored in effect 1 (class scripts) base points
7623 int32 cost
= originalSpell
->manaCost
+ originalSpell
->ManaCostPercentage
* GetCreateMana() / 100;
7624 basepoints
[0] = cost
*auraSpellInfo
->CalculateSimpleValue(EFFECT_INDEX_1
)/100;
7625 trigger_spell_id
= 20272;
7628 // Lightning Capacitor
7629 else if (auraSpellInfo
->Id
==37657)
7631 if(!pVictim
|| !pVictim
->isAlive())
7634 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
7636 Aura
* dummy
= GetDummyAura(37658);
7637 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7638 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7641 RemoveAurasDueToSpell(37658);
7642 trigger_spell_id
= 37661;
7645 // Bonus Healing (Crystal Spire of Karabor mace)
7646 else if (auraSpellInfo
->Id
== 40971)
7648 // If your target is below $s1% health
7649 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
7652 // Thunder Capacitor
7653 else if (auraSpellInfo
->Id
== 54841)
7655 if(!pVictim
|| !pVictim
->isAlive())
7658 CastSpell(this, 54842, true, NULL
, triggeredByAura
);
7661 Aura
* dummy
= GetDummyAura(54842);
7662 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7663 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7666 RemoveAurasDueToSpell(54842);
7667 trigger_spell_id
= 54843;
7672 case SPELLFAMILY_SHAMAN
:
7674 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc
7675 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000400))
7677 switch(auraSpellInfo
->Id
)
7680 trigger_spell_id
= 26364; break;
7682 trigger_spell_id
= 26365; break;
7684 trigger_spell_id
= 26366; break;
7686 trigger_spell_id
= 26367; break;
7687 case 8134: // Rank 5
7688 trigger_spell_id
= 26369; break;
7689 case 10431: // Rank 6
7690 trigger_spell_id
= 26370; break;
7691 case 10432: // Rank 7
7692 trigger_spell_id
= 26363; break;
7693 case 25469: // Rank 8
7694 trigger_spell_id
= 26371; break;
7695 case 25472: // Rank 9
7696 trigger_spell_id
= 26372; break;
7697 case 49280: // Rank 10
7698 trigger_spell_id
= 49278; break;
7699 case 49281: // Rank 11
7700 trigger_spell_id
= 49279; break;
7702 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
7706 // Lightning Shield (The Ten Storms set)
7707 else if (auraSpellInfo
->Id
== 23551)
7709 trigger_spell_id
= 23552;
7712 // Damage from Lightning Shield (The Ten Storms set)
7713 else if (auraSpellInfo
->Id
== 23552)
7714 trigger_spell_id
= 27635;
7715 // Mana Surge (The Earthfury set)
7716 else if (auraSpellInfo
->Id
== 23572)
7720 basepoints
[0] = procSpell
->manaCost
* 35 / 100;
7721 trigger_spell_id
= 23571;
7724 // Nature's Guardian
7725 else if (auraSpellInfo
->SpellIconID
== 2013)
7727 // Check health condition - should drop to less 30% (damage deal after this!)
7728 if (!(10*(int32(GetHealth() - damage
)) < int32(3 * GetMaxHealth())))
7731 if(pVictim
&& pVictim
->isAlive())
7732 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
7734 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
7735 trigger_spell_id
= 31616;
7740 case SPELLFAMILY_DEATHKNIGHT
:
7743 if (auraSpellInfo
->SpellIconID
== 1930)
7747 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7749 case SPELL_SCHOOL_NORMAL
:
7750 return false; // ignore
7751 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 50490; break;
7752 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 50362; break;
7753 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 50488; break;
7754 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 50485; break;
7755 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 50489; break;
7756 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 50486; break;
7762 else if (auraSpellInfo
->SpellIconID
== 85)
7764 if (GetTypeId() != TYPEID_PLAYER
|| getClass() != CLASS_DEATH_KNIGHT
||
7765 !((Player
*)this)->IsBaseRuneSlotsOnCooldown(RUNE_BLOOD
))
7768 // Improved Blood Presence
7769 else if (auraSpellInfo
->Id
== 63611)
7771 if (GetTypeId() != TYPEID_PLAYER
|| !((Player
*)this)->isHonorOrXPTarget(pVictim
) || !damage
)
7773 basepoints
[0] = triggerAmount
* damage
/ 100;
7774 trigger_spell_id
= 50475;
7782 // All ok. Check current trigger spell
7783 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
7786 // Not cast unknown spell
7787 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
7791 // not allow proc extra attack spell at extra attack
7792 if (m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
))
7795 // Custom basepoints/target for exist spell
7796 // dummy basepoints or other customs
7797 switch(trigger_spell_id
)
7799 // Cast positive spell on enemy target
7800 case 7099: // Curse of Mending
7801 case 39647: // Curse of Mending
7802 case 29494: // Temptation
7803 case 20233: // Improved Lay on Hands (cast on target)
7808 // Combo points add triggers (need add combopoint only for main target, and after possible combopoints reset)
7809 case 15250: // Rogue Setup
7811 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
7813 break; // continue normal case
7815 // Finish movies that add combo
7816 case 14189: // Seal Fate (Netherblade set)
7817 case 14157: // Ruthlessness
7819 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
7822 // Bloodthirst (($m/100)% of max health)
7825 basepoints
[0] = int32(GetMaxHealth() * triggerAmount
/ 100);
7828 // Shamanistic Rage triggered spell
7831 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7834 // Enlightenment (trigger only from mana cost spells)
7837 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
7844 // As the spell is proced from pet's attack - find owner
7845 Unit
* owner
= GetOwner();
7846 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
7849 // This spell doesn't stack, but refreshes duration. So we receive current bonuses to minus them later.
7851 if (Aura
* aur
= owner
->GetAura(48090, EFFECT_INDEX_0
))
7852 curBonus
= aur
->GetModifier()->m_amount
;
7853 int32 spellDamage
= owner
->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_MAGIC
) - curBonus
;
7854 if(spellDamage
<= 0)
7857 // percent stored in owner talent dummy
7858 AuraList
const& dummyAuras
= owner
->GetAurasByType(SPELL_AURA_DUMMY
);
7859 for (AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
7861 if ((*i
)->GetSpellProto()->SpellIconID
== 3220)
7863 basepoints
[0] = basepoints
[1] = int32(spellDamage
* (*i
)->GetModifier()->m_amount
/ 100);
7872 // Remove cooldown on Shield Slam
7873 if (GetTypeId() == TYPEID_PLAYER
)
7874 ((Player
*)this)->RemoveSpellCategoryCooldown(1209, true);
7880 // have rank dependent proc chance, ignore too often cases
7881 // PPM = 2.5 * (rank of talent),
7882 uint32 rank
= sSpellMgr
.GetSpellRank(auraSpellInfo
->Id
);
7883 // 5 rank -> 100% 4 rank -> 80% and etc from full rate
7884 if(!roll_chance_i(20*rank
))
7893 // For trigger from Blizzard need exist Improved Blizzard
7894 if (procSpell
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)))
7897 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7898 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7900 int32 script
= (*i
)->GetModifier()->m_miscvalue
;
7901 if(script
==836 || script
==988 || script
==989)
7915 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7918 // Need stun, fear or silence mechanic
7919 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_SILENCE_AND_STUN_AND_FEAR_MASK
))
7923 // Burning Determination
7928 // Need Interrupt or Silenced mechanic
7929 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_INTERRUPT_AND_SILENCE_MASK
))
7936 // Proc only from trap activation (from periodic proc another aura of this spell)
7937 if (!(procFlags
& PROC_FLAG_ON_TRAP_ACTIVATION
) || !roll_chance_i(triggerAmount
))
7941 // Freezing Fog (Rime triggered)
7944 // Howling Blast cooldown reset
7945 if (GetTypeId() == TYPEID_PLAYER
)
7946 ((Player
*)this)->RemoveSpellCategoryCooldown(1248, true);
7949 // Druid - Savage Defense
7952 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7957 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
7960 // try detect target manually if not set
7962 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
7965 if (!target
|| target
!=this && !target
->isAlive())
7968 if (basepoints
[EFFECT_INDEX_0
] || basepoints
[EFFECT_INDEX_1
] || basepoints
[EFFECT_INDEX_2
])
7969 CastCustomSpell(target
,trigger_spell_id
,
7970 basepoints
[EFFECT_INDEX_0
] ? &basepoints
[EFFECT_INDEX_0
] : NULL
,
7971 basepoints
[EFFECT_INDEX_1
] ? &basepoints
[EFFECT_INDEX_1
] : NULL
,
7972 basepoints
[EFFECT_INDEX_2
] ? &basepoints
[EFFECT_INDEX_2
] : NULL
,
7973 true, castItem
, triggeredByAura
);
7975 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
7977 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7978 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
7983 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
7985 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
7987 if(!pVictim
|| !pVictim
->isAlive())
7990 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7991 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7993 // Basepoints of trigger aura
7994 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7996 uint32 triggered_spell_id
= 0;
8000 case 836: // Improved Blizzard (Rank 1)
8002 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
8004 triggered_spell_id
= 12484;
8007 case 988: // Improved Blizzard (Rank 2)
8009 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
8011 triggered_spell_id
= 12485;
8014 case 989: // Improved Blizzard (Rank 3)
8016 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
8018 triggered_spell_id
= 12486;
8021 case 4086: // Improved Mend Pet (Rank 1)
8022 case 4087: // Improved Mend Pet (Rank 2)
8024 if(!roll_chance_i(triggerAmount
))
8027 triggered_spell_id
= 24406;
8030 case 4533: // Dreamwalker Raiment 2 pieces bonus
8033 if (!roll_chance_i(50))
8036 switch (pVictim
->getPowerType())
8038 case POWER_MANA
: triggered_spell_id
= 28722; break;
8039 case POWER_RAGE
: triggered_spell_id
= 28723; break;
8040 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
8046 case 4537: // Dreamwalker Raiment 6 pieces bonus
8047 triggered_spell_id
= 28750; // Blessing of the Claw
8049 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
8050 triggered_spell_id
= 37445; // Mana Surge
8052 case 6953: // Warbringer
8053 RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK
,0,true);
8055 case 7010: // Revitalize (rank 1)
8056 case 7011: // Revitalize (rank 2)
8057 case 7012: // Revitalize (rank 3)
8059 if(!roll_chance_i(triggerAmount
))
8062 switch( pVictim
->getPowerType() )
8064 case POWER_MANA
: triggered_spell_id
= 48542; break;
8065 case POWER_RAGE
: triggered_spell_id
= 48541; break;
8066 case POWER_ENERGY
: triggered_spell_id
= 48540; break;
8067 case POWER_RUNIC_POWER
: triggered_spell_id
= 48543; break;
8068 default: return false;
8075 if(!triggered_spell_id
)
8078 // standard non-dummy case
8079 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
8083 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
8087 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
8090 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
8092 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
8093 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
8098 void Unit::setPowerType(Powers new_powertype
)
8100 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
8102 if(GetTypeId() == TYPEID_PLAYER
)
8104 if(((Player
*)this)->GetGroup())
8105 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
8107 else if(((Creature
*)this)->isPet())
8109 Pet
*pet
= ((Pet
*)this);
8110 if(pet
->isControlled())
8112 Unit
*owner
= GetOwner();
8113 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
8114 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
8118 switch(new_powertype
)
8124 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
8125 SetPower( POWER_RAGE
,0);
8128 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
8129 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
8132 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
8134 case POWER_HAPPINESS
:
8135 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
8136 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
8141 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
8143 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
8146 static uint64 guid
= 0; // prevent repeating spam same faction problem
8148 if(GetGUID() != guid
)
8150 if(GetTypeId() == TYPEID_PLAYER
)
8151 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
8153 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
8160 bool Unit::IsHostileTo(Unit
const* unit
) const
8162 // always non-hostile to self
8166 // always non-hostile to GM in GM mode
8167 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
8170 // always hostile to enemy
8171 if(getVictim()==unit
|| unit
->getVictim()==this)
8174 // test pet/charm masters instead pers/charmeds
8175 Unit
const* testerOwner
= GetCharmerOrOwner();
8176 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
8178 // always hostile to owner's enemy
8179 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
8182 // always hostile to enemy owner
8183 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
8186 // always hostile to owner of owner's enemy
8187 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
8190 Unit
const* tester
= testerOwner
? testerOwner
: this;
8191 Unit
const* target
= targetOwner
? targetOwner
: unit
;
8193 // always non-hostile to target with common owner, or to owner/pet
8197 // special cases (Duel, etc)
8198 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
8200 Player
const* pTester
= (Player
const*)tester
;
8201 Player
const* pTarget
= (Player
const*)target
;
8204 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
8208 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
8212 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
8216 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
8220 // Green/Blue (can't attack)
8221 if(pTester
->GetTeam()==pTarget
->GetTeam())
8224 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
8225 return pTester
->IsPvP() && pTarget
->IsPvP();
8228 // faction base cases
8229 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8230 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8231 if(!tester_faction
|| !target_faction
)
8234 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8237 // PvC forced reaction and reputation case
8238 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8241 if(target_faction
->faction
)
8243 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8244 return *force
<= REP_HOSTILE
;
8246 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
8247 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8248 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8249 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8252 // CvP forced reaction and reputation case
8253 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8256 if(tester_faction
->faction
)
8258 if(ReputationRank
const* force
= ((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8259 return *force
<= REP_HOSTILE
;
8261 // apply reputation state
8262 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
8263 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
8264 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) <= REP_HOSTILE
;
8268 // common faction based case (CvC,PvC,CvP)
8269 return tester_faction
->IsHostileTo(*target_faction
);
8272 bool Unit::IsFriendlyTo(Unit
const* unit
) const
8274 // always friendly to self
8278 // always friendly to GM in GM mode
8279 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
8282 // always non-friendly to enemy
8283 if(getVictim()==unit
|| unit
->getVictim()==this)
8286 // test pet/charm masters instead pers/charmeds
8287 Unit
const* testerOwner
= GetCharmerOrOwner();
8288 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
8290 // always non-friendly to owner's enemy
8291 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
8294 // always non-friendly to enemy owner
8295 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
8298 // always non-friendly to owner of owner's enemy
8299 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
8302 Unit
const* tester
= testerOwner
? testerOwner
: this;
8303 Unit
const* target
= targetOwner
? targetOwner
: unit
;
8305 // always friendly to target with common owner, or to owner/pet
8309 // special cases (Duel)
8310 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
8312 Player
const* pTester
= (Player
const*)tester
;
8313 Player
const* pTarget
= (Player
const*)target
;
8316 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
8320 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
8324 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
8328 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
8332 // Green/Blue (non-attackable)
8333 if(pTester
->GetTeam()==pTarget
->GetTeam())
8336 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
8337 return !pTarget
->IsPvP();
8340 // faction base cases
8341 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8342 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8343 if(!tester_faction
|| !target_faction
)
8346 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8349 // PvC forced reaction and reputation case
8350 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8353 if(target_faction
->faction
)
8355 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8356 return *force
>= REP_FRIENDLY
;
8358 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
8359 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8360 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8361 return !(factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8364 // CvP forced reaction and reputation case
8365 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8368 if(tester_faction
->faction
)
8370 if(ReputationRank
const* force
=((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8371 return *force
>= REP_FRIENDLY
;
8373 // apply reputation state
8374 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
8375 if(raw_tester_faction
->reputationListID
>=0 )
8376 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) >= REP_FRIENDLY
;
8380 // common faction based case (CvC,PvC,CvP)
8381 return tester_faction
->IsFriendlyTo(*target_faction
);
8384 bool Unit::IsHostileToPlayers() const
8386 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8387 if(!my_faction
|| !my_faction
->faction
)
8390 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8391 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8394 return my_faction
->IsHostileToPlayers();
8397 bool Unit::IsNeutralToAll() const
8399 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8400 if(!my_faction
|| !my_faction
->faction
)
8403 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8404 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8407 return my_faction
->IsNeutralToAll();
8410 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
8412 if(!victim
|| victim
== this)
8415 // dead units can neither attack nor be attacked
8416 if(!isAlive() || !victim
->IsInWorld() || !victim
->isAlive())
8419 // player cannot attack in mount state
8420 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
8423 // nobody can attack GM in GM-mode
8424 if(victim
->GetTypeId()==TYPEID_PLAYER
)
8426 if(((Player
*)victim
)->isGameMaster())
8431 if(((Creature
*)victim
)->IsInEvadeMode())
8435 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
8436 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
8437 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
8439 // in fighting already
8442 if (m_attacking
== victim
)
8444 // switch to melee attack from ranged/magic
8445 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
8447 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8448 SendMeleeAttackStart(victim
);
8454 // remove old target data
8460 // set position before any AI calls/assistance
8461 if(GetTypeId()==TYPEID_UNIT
)
8462 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
8466 SetTargetGUID(victim
->GetGUID());
8469 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8471 m_attacking
= victim
;
8472 m_attacking
->_addAttacker(this);
8474 if (GetTypeId() == TYPEID_UNIT
)
8476 ((Creature
*)this)->SendAIReaction(AI_REACTION_HOSTILE
);
8477 ((Creature
*)this)->CallAssistance();
8480 // delay offhand weapon attack to next attack time
8481 if(haveOffhandWeapon())
8482 resetAttackTimer(OFF_ATTACK
);
8485 SendMeleeAttackStart(victim
);
8490 bool Unit::AttackStop(bool targetSwitch
/*=false*/)
8495 Unit
* victim
= m_attacking
;
8497 m_attacking
->_removeAttacker(this);
8503 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
8505 InterruptSpell(CURRENT_MELEE_SPELL
);
8507 // reset only at real combat stop
8508 if(!targetSwitch
&& GetTypeId()==TYPEID_UNIT
)
8510 ((Creature
*)this)->SetNoCallAssistance(false);
8512 if (((Creature
*)this)->HasSearchedAssistance())
8514 ((Creature
*)this)->SetNoSearchAssistance(false);
8515 UpdateSpeed(MOVE_RUN
, false);
8519 SendMeleeAttackStop(victim
);
8524 void Unit::CombatStop(bool includingCast
)
8526 if (includingCast
&& IsNonMeleeSpellCasted(false))
8527 InterruptNonMeleeSpells(false);
8530 RemoveAllAttackers();
8531 if( GetTypeId()==TYPEID_PLAYER
)
8532 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
8536 struct CombatStopWithPetsHelper
8538 explicit CombatStopWithPetsHelper(bool _includingCast
) : includingCast(_includingCast
) {}
8539 void operator()(Unit
* unit
) const { unit
->CombatStop(includingCast
); }
8543 void Unit::CombatStopWithPets(bool includingCast
)
8545 CombatStop(includingCast
);
8546 CallForAllControlledUnits(CombatStopWithPetsHelper(includingCast
),false,true,true);
8549 struct IsAttackingPlayerHelper
8551 explicit IsAttackingPlayerHelper() {}
8552 bool operator()(Unit
* unit
) const { return unit
->isAttackingPlayer(); }
8555 bool Unit::isAttackingPlayer() const
8557 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
8560 return CheckAllControlledUnits(IsAttackingPlayerHelper(),true,true,true);
8563 void Unit::RemoveAllAttackers()
8565 while (!m_attackers
.empty())
8567 AttackerSet::iterator iter
= m_attackers
.begin();
8568 if(!(*iter
)->AttackStop())
8570 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
8571 m_attackers
.erase(iter
);
8576 bool Unit::HasAuraStateForCaster(AuraState flag
, uint64 caster
) const
8578 if(!HasAuraState(flag
))
8581 // single per-caster aura state
8582 if(flag
== AURA_STATE_CONFLAGRATE
)
8584 Unit::AuraList
const& dotList
= GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
8585 for(Unit::AuraList::const_iterator i
= dotList
.begin(); i
!= dotList
.end(); ++i
)
8587 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
8588 (*i
)->GetCasterGUID() == caster
&&
8590 (((*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000004)) ||
8592 ((*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x00000002)))
8604 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
8608 if (!HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)))
8610 SetFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8611 if(GetTypeId() == TYPEID_PLAYER
)
8613 const PlayerSpellMap
& sp_list
= ((Player
*)this)->GetSpellMap();
8614 for (PlayerSpellMap::const_iterator itr
= sp_list
.begin(); itr
!= sp_list
.end(); ++itr
)
8616 if(itr
->second
.state
== PLAYERSPELL_REMOVED
) continue;
8617 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
8618 if (!spellInfo
|| !IsPassiveSpell(itr
->first
)) continue;
8619 if (spellInfo
->CasterAuraState
== flag
)
8620 CastSpell(this, itr
->first
, true, NULL
);
8627 if (HasFlag(UNIT_FIELD_AURASTATE
,1<<(flag
-1)))
8629 RemoveFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8631 if (flag
!= AURA_STATE_ENRAGE
) // enrage aura state triggering continues auras
8633 Unit::AuraMap
& tAuras
= GetAuras();
8634 for (Unit::AuraMap::iterator itr
= tAuras
.begin(); itr
!= tAuras
.end();)
8636 SpellEntry
const* spellProto
= (*itr
).second
->GetSpellProto();
8637 if (spellProto
->CasterAuraState
== flag
)
8647 Unit
*Unit::GetOwner() const
8649 if(uint64 ownerid
= GetOwnerGUID())
8650 return ObjectAccessor::GetUnit(*this, ownerid
);
8654 Unit
*Unit::GetCharmer() const
8656 if(uint64 charmerid
= GetCharmerGUID())
8657 return ObjectAccessor::GetUnit(*this, charmerid
);
8661 bool Unit::IsCharmerOrOwnerPlayerOrPlayerItself() const
8663 if (GetTypeId()==TYPEID_PLAYER
)
8666 return IS_PLAYER_GUID(GetCharmerOrOwnerGUID());
8669 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
8671 uint64 guid
= GetCharmerOrOwnerGUID();
8672 if(IS_PLAYER_GUID(guid
))
8673 return ObjectAccessor::FindPlayer(guid
);
8675 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
8678 Pet
* Unit::GetPet() const
8680 if(uint64 pet_guid
= GetPetGUID())
8682 if(Pet
* pet
= GetMap()->GetPet(pet_guid
))
8685 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
8686 const_cast<Unit
*>(this)->SetPet(0);
8692 Unit
* Unit::GetCharm() const
8694 if (uint64 charm_guid
= GetCharmGUID())
8696 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
8699 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
8700 const_cast<Unit
*>(this)->SetCharm(NULL
);
8706 void Unit::Uncharm()
8708 if (Unit
* charm
= GetCharm())
8710 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM
);
8711 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS
);
8715 float Unit::GetCombatDistance( const Unit
* target
) const
8717 float radius
= target
->GetFloatValue(UNIT_FIELD_COMBATREACH
) + GetFloatValue(UNIT_FIELD_COMBATREACH
);
8718 float dx
= GetPositionX() - target
->GetPositionX();
8719 float dy
= GetPositionY() - target
->GetPositionY();
8720 float dz
= GetPositionZ() - target
->GetPositionZ();
8721 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - radius
;
8722 return ( dist
> 0 ? dist
: 0);
8725 void Unit::SetPet(Pet
* pet
)
8727 SetPetGUID(pet
? pet
->GetGUID() : 0);
8729 if(pet
&& GetTypeId() == TYPEID_PLAYER
)
8730 ((Player
*)this)->SendPetGUIDs();
8733 void Unit::SetCharm(Unit
* pet
)
8735 SetCharmGUID(pet
? pet
->GetGUID() : 0);
8738 void Unit::AddGuardian( Pet
* pet
)
8740 m_guardianPets
.insert(pet
->GetGUID());
8743 void Unit::RemoveGuardian( Pet
* pet
)
8745 m_guardianPets
.erase(pet
->GetGUID());
8748 void Unit::RemoveGuardians()
8750 while(!m_guardianPets
.empty())
8752 uint64 guid
= *m_guardianPets
.begin();
8753 if(Pet
* pet
= GetMap()->GetPet(guid
))
8754 pet
->Remove(PET_SAVE_AS_DELETED
);
8756 m_guardianPets
.erase(guid
);
8760 Pet
* Unit::FindGuardianWithEntry(uint32 entry
)
8762 // pet guid middle part is entry (and creature also)
8763 // and in guardian list must be guardians with same entry _always_
8764 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
8765 if(Pet
* pet
= GetMap()->GetPet(*itr
))
8766 if (pet
->GetEntry() == entry
)
8772 Unit
* Unit::_GetTotem(TotemSlot slot
) const
8774 return GetTotem(slot
);
8777 Totem
* Unit::GetTotem(TotemSlot slot
) const
8779 if(slot
>= MAX_TOTEM_SLOT
|| !IsInWorld())
8782 Creature
*totem
= GetMap()->GetCreature(m_TotemSlot
[slot
]);
8783 return totem
&& totem
->isTotem() ? (Totem
*)totem
: NULL
;
8786 bool Unit::IsAllTotemSlotsUsed() const
8788 for (int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8789 if (!m_TotemSlot
[i
])
8794 void Unit::_AddTotem(TotemSlot slot
, Totem
* totem
)
8796 m_TotemSlot
[slot
] = totem
->GetGUID();
8799 void Unit::_RemoveTotem(Totem
* totem
)
8801 for(int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8803 if (m_TotemSlot
[i
] == totem
->GetGUID())
8813 void Unit::UnsummonAllTotems()
8815 for (int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8816 if (Totem
* totem
= GetTotem(TotemSlot(i
)))
8820 int32
Unit::DealHeal(Unit
*pVictim
, uint32 addhealth
, SpellEntry
const *spellProto
, bool critical
)
8822 int32 gain
= pVictim
->ModifyHealth(int32(addhealth
));
8826 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8829 if (unit
->GetTypeId()==TYPEID_PLAYER
)
8831 // overheal = addhealth - gain
8832 unit
->SendHealSpellLog(pVictim
, spellProto
->Id
, addhealth
, addhealth
- gain
, critical
);
8834 if (BattleGround
*bg
= ((Player
*)unit
)->GetBattleGround())
8835 bg
->UpdatePlayerScore((Player
*)unit
, SCORE_HEALING_DONE
, gain
);
8837 // use the actual gain, as the overheal shall not be counted, skip gain 0 (it ignored anyway in to criteria)
8839 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE
, gain
, 0, pVictim
);
8841 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED
, addhealth
);
8844 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
8846 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED
, gain
);
8847 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED
, addhealth
);
8853 Unit
* Unit::SelectMagnetTarget(Unit
*victim
, SpellEntry
const *spellInfo
)
8859 if(spellInfo
&& (spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
|| spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
))
8861 Unit::AuraList
const& magnetAuras
= victim
->GetAurasByType(SPELL_AURA_SPELL_MAGNET
);
8862 for(Unit::AuraList::const_iterator itr
= magnetAuras
.begin(); itr
!= magnetAuras
.end(); ++itr
)
8863 if(Unit
* magnet
= (*itr
)->GetCaster())
8864 if(magnet
->IsWithinLOSInMap(this) && magnet
->isAlive())
8867 // Melee && ranged case
8870 AuraList
const& hitTriggerAuras
= victim
->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER
);
8871 for(AuraList::const_iterator i
= hitTriggerAuras
.begin(); i
!= hitTriggerAuras
.end(); ++i
)
8872 if(Unit
* magnet
= (*i
)->GetCaster())
8873 if(magnet
->isAlive() && magnet
->IsWithinLOSInMap(this))
8874 if(roll_chance_i((*i
)->GetModifier()->m_amount
))
8881 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, uint32 OverHeal
, bool critical
)
8884 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
8885 data
<< pVictim
->GetPackGUID();
8886 data
<< GetPackGUID();
8887 data
<< uint32(SpellID
);
8888 data
<< uint32(Damage
);
8889 data
<< uint32(OverHeal
);
8890 data
<< uint8(critical
? 1 : 0);
8891 data
<< uint8(0); // unused in client?
8892 SendMessageToSet(&data
, true);
8895 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8897 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
8898 data
<< pVictim
->GetPackGUID();
8899 data
<< GetPackGUID();
8900 data
<< uint32(SpellID
);
8901 data
<< uint32(powertype
);
8902 data
<< uint32(Damage
);
8903 SendMessageToSet(&data
, true);
8906 void Unit::EnergizeBySpell(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8908 SendEnergizeSpellLog(pVictim
, SpellID
, Damage
, powertype
);
8909 // needs to be called after sending spell log
8910 pVictim
->ModifyPower(powertype
, Damage
);
8913 int32
Unit::SpellBonusWithCoeffs(SpellEntry
const *spellProto
, int32 total
, int32 benefit
, int32 ap_benefit
, DamageEffectType damagetype
, bool donePart
, float defCoeffMod
)
8915 // Distribute Damage over multiple effects, reduce by AoE
8918 // Not apply this to creature casted spells
8919 if (GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
8921 // Check for table values
8922 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
8924 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
8926 // apply ap bonus at done part calculation only (it flat total mod so common with taken)
8927 if (donePart
&& bonus
->ap_bonus
)
8928 total
+= int32(bonus
->ap_bonus
* (GetTotalAttackPowerValue(BASE_ATTACK
) + ap_benefit
));
8930 // Default calculation
8932 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
) * defCoeffMod
;
8936 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
8938 // Spellmod SpellDamage
8939 if(Player
* modOwner
= GetSpellModOwner())
8942 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
, coeff
);
8946 total
+= int32(benefit
* coeff
* LvlPenalty
);
8953 * Calculates caster part of spell damage bonuses,
8954 * also includes different bonuses dependent from target auras
8956 uint32
Unit::SpellDamageBonusDone(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
8958 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
8961 // For totems get damage bonus from owner (statue isn't totem in fact)
8962 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8964 if(Unit
* owner
= GetOwner())
8965 return owner
->SpellDamageBonusDone(pVictim
, spellProto
, pdamage
, damagetype
);
8968 float DoneTotalMod
= 1.0f
;
8969 int32 DoneTotal
= 0;
8972 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
8973 DoneTotalMod
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
8975 if (!(spellProto
->AttributesEx6
& SPELL_ATTR_EX6_NO_DMG_PERCENT_MODS
))
8977 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
8978 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
8980 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
8981 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
8982 // -1 == any item class (not wand then)
8983 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
8984 // 0 == any inventory type (not wand then)
8986 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8991 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8992 // Add flat bonus from spell damage versus
8993 DoneTotal
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
8994 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
8995 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
8996 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8997 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8999 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
9000 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
9002 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
9003 DoneTotalMod
+= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9006 // done scripted mod (take it from owner)
9007 Unit
*owner
= GetOwner();
9008 if (!owner
) owner
= this;
9009 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9010 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9012 if (!(*i
)->isAffectedOnSpell(spellProto
))
9014 switch((*i
)->GetModifier()->m_miscvalue
)
9016 case 4920: // Molten Fury
9018 case 6917: // Death's Embrace
9022 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9023 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
9030 // effect 1 m_amount
9031 int32 maxPercent
= (*i
)->GetModifier()->m_amount
;
9032 // effect 0 m_amount
9033 int32 stepPercent
= CalculateSpellDamage(this, (*i
)->GetSpellProto(), EFFECT_INDEX_0
);
9034 // count affliction effects and calc additional damage in percentage
9035 int32 modPercent
= 0;
9036 AuraMap
const& victimAuras
= pVictim
->GetAuras();
9037 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
9039 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
9040 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_WARLOCK
|| !(m_spell
->SpellFamilyFlags
& UI64LIT(0x0004071B8044C402)))
9042 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
9043 if (modPercent
>= maxPercent
)
9045 modPercent
= maxPercent
;
9049 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
9052 case 6916: // Death's Embrace
9055 if (HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
))
9056 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
9058 case 5481: // Starfire Bonus
9060 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000200002)))
9061 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9064 case 4418: // Increased Shock Damage
9065 case 4554: // Increased Lightning Damage
9066 case 4555: // Improved Moonfire
9067 case 5142: // Increased Lightning Damage
9068 case 5147: // Improved Consecration / Libram of Resurgence
9069 case 5148: // Idol of the Shooting Star
9070 case 6008: // Increased Lightning Damage
9071 case 8627: // Totem of Hex
9073 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
9081 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
9083 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9084 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
9086 else // Tundra Stalker
9088 // Frost Fever (target debuff)
9089 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
9090 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9095 case 7293: // Rage of Rivendare
9097 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
9098 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9104 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000000000008000), 0, GetGUID()))
9105 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9115 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
9116 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9122 // Custom scripted damage
9123 switch(spellProto
->SpellFamilyName
)
9125 case SPELLFAMILY_MAGE
:
9128 if (spellProto
->SpellIconID
== 186)
9130 if (pVictim
->isFrozen())
9132 float multiplier
= 3.0f
;
9134 // if target have higher level
9135 if (pVictim
->getLevel() > getLevel())
9136 // Glyph of Ice Lance
9137 if (Aura
* glyph
= GetDummyAura(56377))
9138 multiplier
= glyph
->GetModifier()->m_amount
;
9140 DoneTotalMod
*= multiplier
;
9143 // Torment the weak affected (Arcane Barrage, Arcane Blast, Frostfire Bolt, Arcane Missiles, Fireball)
9144 if ((spellProto
->SpellFamilyFlags
& UI64LIT(0x0000900020200021)) &&
9145 (pVictim
->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED
) || pVictim
->HasAuraType(SPELL_AURA_HASTE_ALL
)))
9147 //Search for Torment the weak dummy aura
9148 Unit::AuraList
const& ttw
= GetAurasByType(SPELL_AURA_DUMMY
);
9149 for(Unit::AuraList::const_iterator i
= ttw
.begin(); i
!= ttw
.end(); ++i
)
9151 if ((*i
)->GetSpellProto()->SpellIconID
== 3263)
9153 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9160 case SPELLFAMILY_WARLOCK
:
9162 case SPELLFAMILY_PRIEST
:
9165 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x00000080))
9168 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x00100000), NULL
))
9169 if (Aura
*aur
= GetAura(55692, EFFECT_INDEX_0
))
9170 DoneTotalMod
*= (aur
->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9174 case SPELLFAMILY_DRUID
:
9176 // Improved Insect Swarm (Wrath part)
9177 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
9179 // if Insect Swarm on target
9180 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x000000000200000), 0, GetGUID()))
9182 Unit::AuraList
const& improvedSwarm
= GetAurasByType(SPELL_AURA_DUMMY
);
9183 for(Unit::AuraList::const_iterator iter
= improvedSwarm
.begin(); iter
!= improvedSwarm
.end(); ++iter
)
9185 if ((*iter
)->GetSpellProto()->SpellIconID
== 1771)
9187 DoneTotalMod
*= ((*iter
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9195 case SPELLFAMILY_DEATHKNIGHT
:
9197 // Icy Touch and Howling Blast
9198 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000200000002))
9202 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
9203 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
9205 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
9214 // search for Glacier Rot dummy aura
9215 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9216 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
9218 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
9220 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9231 // Done fixed damage bonus auras
9232 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonusDone(GetSpellSchoolMask(spellProto
));
9234 // Pets just add their bonus damage to their spell damage
9235 // note that their spell damage is just gain of their own auras
9236 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9237 DoneAdvertisedBenefit
+= ((Pet
*)this)->GetBonusDamage();
9239 // apply ap bonus and benefit affected by spell power implicit coeffs and spell level penalties
9240 DoneTotal
= SpellBonusWithCoeffs(spellProto
, DoneTotal
, DoneAdvertisedBenefit
, 0, damagetype
, true);
9242 float tmpDamage
= (int32(pdamage
) + DoneTotal
* int32(stack
)) * DoneTotalMod
;
9243 // apply spellmod to Done damage (flat and pct)
9244 if(Player
* modOwner
= GetSpellModOwner())
9245 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
9247 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9251 * Calculates target part of spell damage bonuses,
9252 * will be called on each tick for periodic damage over time auras
9254 uint32
Unit::SpellDamageBonusTaken(Unit
*pCaster
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
9256 if(!spellProto
|| !pCaster
|| damagetype
==DIRECT_DAMAGE
)
9259 // Taken total percent damage auras
9260 float TakenTotalMod
= 1.0f
;
9261 int32 TakenTotal
= 0;
9264 AuraList
const& mModDamagePercentTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
9265 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
9267 if ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
))
9268 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9271 // .. taken pct: dummy auras
9272 if (GetTypeId() == TYPEID_PLAYER
)
9275 if (Aura
*dummy
= GetDummyAura(45182))
9277 float mod
= -((Player
*)this)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
9278 if (mod
< float(dummy
->GetModifier()->m_amount
))
9279 mod
= float(dummy
->GetModifier()->m_amount
);
9280 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
9284 // From caster spells
9285 AuraList
const& mOwnerTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_FROM_CASTER
);
9286 for(AuraList::const_iterator i
= mOwnerTaken
.begin(); i
!= mOwnerTaken
.end(); ++i
)
9288 if ((*i
)->GetCasterGUID() == pCaster
->GetGUID() && (*i
)->isAffectedOnSpell(spellProto
))
9289 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9292 // Mod damage from spell mechanic
9293 TakenTotalMod
*= GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,GetAllSpellMechanicMask(spellProto
));
9295 // Mod damage taken from AoE spells
9296 if(IsAreaOfEffectSpell(spellProto
))
9298 AuraList
const& avoidAuras
= GetAurasByType(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
9299 for(AuraList::const_iterator itr
= avoidAuras
.begin(); itr
!= avoidAuras
.end(); ++itr
)
9300 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9303 // Taken fixed damage bonus auras
9304 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusTaken(GetSpellSchoolMask(spellProto
));
9306 // apply benefit affected by spell power implicit coeffs and spell level penalties
9307 TakenTotal
= SpellBonusWithCoeffs(spellProto
, TakenTotal
, TakenAdvertisedBenefit
, 0, damagetype
, false);
9309 float tmpDamage
= (int32(pdamage
) + TakenTotal
* int32(stack
)) * TakenTotalMod
;
9311 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9314 int32
Unit::SpellBaseDamageBonusDone(SpellSchoolMask schoolMask
)
9316 int32 DoneAdvertisedBenefit
= 0;
9319 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9320 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
9322 if (((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
9323 (*i
)->GetSpellProto()->EquippedItemClass
== -1 && // -1 == any item class (not wand then)
9324 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0) // 0 == any inventory type (not wand then)
9325 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9328 if (GetTypeId() == TYPEID_PLAYER
)
9331 DoneAdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9333 // Damage bonus from stats
9334 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
9335 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
9337 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9339 // stat used stored in miscValueB for this aura
9340 Stats usedStat
= Stats((*i
)->GetMiscBValue());
9341 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9344 // ... and attack power
9345 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
9346 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
9348 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9349 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9353 return DoneAdvertisedBenefit
;
9356 int32
Unit::SpellBaseDamageBonusTaken(SpellSchoolMask schoolMask
)
9358 int32 TakenAdvertisedBenefit
= 0;
9361 AuraList
const& mDamageTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
9362 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9364 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9365 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9368 return TakenAdvertisedBenefit
;
9371 bool Unit::IsSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
9373 // not critting spell
9374 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
9377 float crit_chance
= 0.0f
;
9378 switch(spellProto
->DmgClass
)
9380 case SPELL_DAMAGE_CLASS_NONE
:
9382 case SPELL_DAMAGE_CLASS_MAGIC
:
9384 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
9386 // For other schools
9387 else if (GetTypeId() == TYPEID_PLAYER
)
9388 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
9391 crit_chance
= float(m_baseSpellCritChance
);
9392 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9397 if (!IsPositiveSpell(spellProto
->Id
))
9399 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
9400 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
9401 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
9402 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
9403 // Modify by player victim resilience
9404 crit_chance
-= pVictim
->GetSpellCritChanceReduction();
9407 // scripted (increase crit chance ... against ... target by x%)
9408 // scripted (Increases the critical effect chance of your .... by x% on targets ...)
9409 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9410 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9412 if (!((*i
)->isAffectedOnSpell(spellProto
)))
9414 switch((*i
)->GetModifier()->m_miscvalue
)
9416 case 849: if (pVictim
->isFrozen()) crit_chance
+= 17.0f
; break; //Shatter Rank 1
9417 case 910: if (pVictim
->isFrozen()) crit_chance
+= 34.0f
; break; //Shatter Rank 2
9418 case 911: if (pVictim
->isFrozen()) crit_chance
+= 50.0f
; break; //Shatter Rank 3
9419 case 7917: // Glyph of Shadowburn
9420 if (pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9421 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9423 case 7997: // Renewed Hope
9425 if (pVictim
->HasAura(6788))
9426 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9432 // Custom crit by class
9433 switch(spellProto
->SpellFamilyName
)
9435 case SPELLFAMILY_PRIEST
:
9437 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000800))
9439 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth()/2)
9441 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9442 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9444 // Improved Flash Heal
9445 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_PRIEST
&&
9446 (*i
)->GetSpellProto()->SpellIconID
== 2542)
9448 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9454 case SPELLFAMILY_DRUID
:
9455 // Improved Insect Swarm (Starfire part)
9456 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
9458 // search for Moonfire on target
9459 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x000000000000002), 0, GetGUID()))
9461 Unit::AuraList
const& improvedSwarm
= GetAurasByType(SPELL_AURA_DUMMY
);
9462 for(Unit::AuraList::const_iterator iter
= improvedSwarm
.begin(); iter
!= improvedSwarm
.end(); ++iter
)
9464 if ((*iter
)->GetSpellProto()->SpellIconID
== 1771)
9466 crit_chance
+= (*iter
)->GetModifier()->m_amount
;
9473 case SPELLFAMILY_PALADIN
:
9475 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000040000000))
9477 Aura
*aura
= pVictim
->GetDummyAura(58597);
9478 if (aura
&& aura
->GetCasterGUID() == GetGUID())
9479 crit_chance
+=aura
->GetModifier()->m_amount
;
9482 else if (spellProto
->Category
== 19)
9484 if (pVictim
->GetCreatureTypeMask() & CREATURE_TYPEMASK_DEMON_OR_UNDEAD
)
9488 case SPELLFAMILY_SHAMAN
:
9490 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000100000000000))
9493 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000000010000000), 0, GetGUID()))
9501 case SPELL_DAMAGE_CLASS_MELEE
:
9502 case SPELL_DAMAGE_CLASS_RANGED
:
9505 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
9507 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9514 // only players use intelligence for critical chance computations
9515 if(Player
* modOwner
= GetSpellModOwner())
9516 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
9518 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
9519 if (roll_chance_f(crit_chance
))
9524 uint32
Unit::SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9526 // Calculate critical bonus
9528 switch(spellProto
->DmgClass
)
9530 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9531 case SPELL_DAMAGE_CLASS_RANGED
:
9532 crit_bonus
= damage
;
9535 crit_bonus
= damage
/ 2; // for spells is 50%
9539 // adds additional damage to crit_bonus (from talents)
9540 if(Player
* modOwner
= GetSpellModOwner())
9541 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
9544 return damage
+= crit_bonus
;
9546 int32 critPctDamageMod
= 0;
9547 if(spellProto
->DmgClass
>= SPELL_DAMAGE_CLASS_MELEE
)
9549 if(GetWeaponAttackType(spellProto
) == RANGED_ATTACK
)
9550 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
9552 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
9555 critPctDamageMod
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_DAMAGE
,GetSpellSchoolMask(spellProto
));
9557 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, GetSpellSchoolMask(spellProto
));
9559 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9560 critPctDamageMod
+= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
);
9562 if(critPctDamageMod
!=0)
9563 crit_bonus
= int32(crit_bonus
* float((100.0f
+ critPctDamageMod
)/100.0f
));
9566 damage
+= crit_bonus
;
9571 uint32
Unit::SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9573 // Calculate critical bonus
9575 switch(spellProto
->DmgClass
)
9577 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9578 case SPELL_DAMAGE_CLASS_RANGED
:
9579 // TODO: write here full calculation for melee/ranged spells
9580 crit_bonus
= damage
;
9583 crit_bonus
= damage
/ 2; // for spells is 50%
9589 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9590 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
9594 damage
+= crit_bonus
;
9596 damage
= int32(damage
* GetTotalAuraMultiplier(SPELL_AURA_MOD_CRITICAL_HEALING_AMOUNT
));
9602 * Calculates caster part of healing spell bonuses,
9603 * also includes different bonuses dependent from target auras
9605 uint32
Unit::SpellHealingBonusDone(Unit
*pVictim
, SpellEntry
const *spellProto
, int32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9607 // For totems get healing bonus from owner (statue isn't totem in fact)
9608 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
9609 if(Unit
* owner
= GetOwner())
9610 return owner
->SpellHealingBonusDone(pVictim
, spellProto
, healamount
, damagetype
, stack
);
9612 // No heal amount for this class spells
9613 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9614 return healamount
< 0 ? 0 : healamount
;
9617 // Done total percent damage auras
9618 float DoneTotalMod
= 1.0f
;
9619 int32 DoneTotal
= 0;
9621 // Healing done percent
9622 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
9623 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
9624 DoneTotalMod
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
9626 // done scripted mod (take it from owner)
9627 Unit
*owner
= GetOwner();
9628 if (!owner
) owner
= this;
9629 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9630 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9632 if (!(*i
)->isAffectedOnSpell(spellProto
))
9634 switch((*i
)->GetModifier()->m_miscvalue
)
9636 case 4415: // Increased Rejuvenation Healing
9638 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
9639 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
9641 case 7997: // Renewed Hope
9643 if (pVictim
->HasAura(6788))
9644 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9646 case 21: // Test of Faith
9649 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
9650 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9652 case 7798: // Glyph of Regrowth
9654 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_HEAL
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000000040)))
9655 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9658 case 8477: // Nourish Heal Boost
9660 int32 stepPercent
= (*i
)->GetModifier()->m_amount
;
9662 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())
9671 DoneTotalMod
*= (stepPercent
* ownHotCount
+ 100.0f
) / 100.0f
;
9674 case 7871: // Glyph of Lesser Healing Wave
9676 if (pVictim
->GetAura(SPELL_AURA_DUMMY
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000040000000000), 0, GetGUID()))
9677 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9685 // Nourish 20% of heal increase if target is affected by Druids HOTs
9686 if (spellProto
->SpellFamilyName
== SPELLFAMILY_DRUID
&& (spellProto
->SpellFamilyFlags
& UI64LIT(0x0200000000000000)))
9688 int ownHotCount
= 0; // counted HoT types amount, not stacks
9689 Unit::AuraList
const& RejorRegr
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_HEAL
);
9690 for(Unit::AuraList::const_iterator i
= RejorRegr
.begin(); i
!= RejorRegr
.end(); ++i
)
9691 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_DRUID
&&
9692 (*i
)->GetCasterGUID() == GetGUID())
9697 DoneTotalMod
*= 1.2f
; // base bonus at HoTs
9699 if (Aura
* glyph
= GetAura(62971, EFFECT_INDEX_0
))// Glyph of Nourish
9700 DoneTotalMod
*= (glyph
->GetModifier()->m_amount
* ownHotCount
+ 100.0f
) / 100.0f
;
9704 // Done fixed damage bonus auras
9705 int32 DoneAdvertisedBenefit
= SpellBaseHealingBonusDone(GetSpellSchoolMask(spellProto
));
9707 // apply ap bonus and benefit affected by spell power implicit coeffs and spell level penalties
9708 DoneTotal
= SpellBonusWithCoeffs(spellProto
, DoneTotal
, DoneAdvertisedBenefit
, 0, damagetype
, true, 1.88f
);
9710 // use float as more appropriate for negative values and percent applying
9711 float heal
= (healamount
+ DoneTotal
* int32(stack
))*DoneTotalMod
;
9712 // apply spellmod to Done amount
9713 if(Player
* modOwner
= GetSpellModOwner())
9714 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
9716 return heal
< 0 ? 0 : uint32(heal
);
9720 * Calculates target part of healing spell bonuses,
9721 * will be called on each tick for periodic damage over time auras
9723 uint32
Unit::SpellHealingBonusTaken(Unit
*pCaster
, SpellEntry
const *spellProto
, int32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9725 float TakenTotalMod
= 1.0f
;
9727 // Healing taken percent
9728 float minval
= float(GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
));
9730 TakenTotalMod
*= (100.0f
+ minval
) / 100.0f
;
9732 float maxval
= float(GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
));
9734 TakenTotalMod
*= (100.0f
+ maxval
) / 100.0f
;
9736 // No heal amount for this class spells
9737 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9739 healamount
= int32(healamount
* TakenTotalMod
);
9740 return healamount
< 0 ? 0 : healamount
;
9744 // Done total percent damage auras
9745 int32 TakenTotal
= 0;
9747 // Taken fixed damage bonus auras
9748 int32 TakenAdvertisedBenefit
= SpellBaseHealingBonusTaken(GetSpellSchoolMask(spellProto
));
9750 // apply benefit affected by spell power implicit coeffs and spell level penalties
9751 TakenTotal
= SpellBonusWithCoeffs(spellProto
, TakenTotal
, TakenAdvertisedBenefit
, 0, damagetype
, false, 1.88f
);
9753 AuraList
const& mHealingGet
= GetAurasByType(SPELL_AURA_MOD_HEALING_RECEIVED
);
9754 for(AuraList::const_iterator i
= mHealingGet
.begin(); i
!= mHealingGet
.end(); ++i
)
9755 if ((*i
)->isAffectedOnSpell(spellProto
))
9756 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9758 // use float as more appropriate for negative values and percent applying
9759 float heal
= (healamount
+ TakenTotal
* int32(stack
)) * TakenTotalMod
;
9761 return heal
< 0 ? 0 : uint32(heal
);
9764 int32
Unit::SpellBaseHealingBonusDone(SpellSchoolMask schoolMask
)
9766 int32 AdvertisedBenefit
= 0;
9768 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
9769 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
9770 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9771 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9773 // Healing bonus of spirit, intellect and strength
9774 if (GetTypeId() == TYPEID_PLAYER
)
9777 AdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9779 // Healing bonus from stats
9780 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
9781 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
9783 // stat used dependent from misc value (stat index)
9784 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
9785 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9788 // ... and attack power
9789 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
9790 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
9791 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9792 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9794 return AdvertisedBenefit
;
9797 int32
Unit::SpellBaseHealingBonusTaken(SpellSchoolMask schoolMask
)
9799 int32 AdvertisedBenefit
= 0;
9800 AuraList
const& mDamageTaken
= GetAurasByType(SPELL_AURA_MOD_HEALING
);
9801 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9802 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9803 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9805 return AdvertisedBenefit
;
9808 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
)
9810 //If m_immuneToSchool type contain this school type, IMMUNE damage.
9811 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9812 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9813 if (itr
->type
& shoolMask
)
9816 //If m_immuneToDamage type contain magic, IMMUNE damage.
9817 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
9818 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
9819 if (itr
->type
& shoolMask
)
9825 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
)
9830 //TODO add spellEffect immunity checks!, player with flag in bg is imune to imunity buffs from other friendly players!
9831 //SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_EFFECT];
9833 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
9834 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
9835 if (itr
->type
== spellInfo
->Dispel
)
9838 if (!(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
) && // unaffected by school immunity
9839 !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)) // can remove immune (by dispell or immune it)
9841 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9842 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9843 if (!(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
9844 (itr
->type
& GetSpellSchoolMask(spellInfo
)))
9848 if(uint32 mechanic
= spellInfo
->Mechanic
)
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)))
9864 bool Unit::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, SpellEffectIndex index
) const
9866 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
9867 uint32 effect
= spellInfo
->Effect
[index
];
9868 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
9869 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
9870 if (itr
->type
== effect
)
9873 if(uint32 mechanic
= spellInfo
->EffectMechanic
[index
])
9875 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9876 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9877 if (itr
->type
== mechanic
)
9880 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9881 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9882 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9886 if(uint32 aura
= spellInfo
->EffectApplyAuraName
[index
])
9888 SpellImmuneList
const& list
= m_spellImmune
[IMMUNITY_STATE
];
9889 for(SpellImmuneList::const_iterator itr
= list
.begin(); itr
!= list
.end(); ++itr
)
9890 if (itr
->type
== aura
)
9893 // Check for immune to application of harmful magical effects
9894 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL
);
9895 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9896 if (spellInfo
->Dispel
== DISPEL_MAGIC
&& // Magic debuff
9897 ((*iter
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellInfo
)) && // Check school
9898 !IsPositiveEffect(spellInfo
->Id
, index
)) // Harmful
9905 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
9910 uint32 family
= spellInfo
->SpellFamilyName
;
9911 uint64 flags
= spellInfo
->SpellFamilyFlags
;
9913 if ((family
== 5 && flags
== 256) || //Searing Pain
9914 (family
== 6 && flags
== 8192) || //Mind Blast
9915 (family
== 11 && flags
== 1048576)) //Earth Shock
9922 * Calculates caster part of melee damage bonuses,
9923 * also includes different bonuses dependent from target auras
9925 uint32
Unit::MeleeDamageBonusDone(Unit
*pVictim
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
9933 // differentiate for weapon damage based spells
9934 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
9935 Item
* pWeapon
= GetTypeId() == TYPEID_PLAYER
? ((Player
*)this)->GetWeaponForAttack(attType
,true,false) : NULL
;
9936 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9937 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
9938 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
9940 // Shred also have bonus as MECHANIC_BLEED damages
9941 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
9942 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
9945 // FLAT damage bonus auras
9946 // =======================
9950 // ..done flat, already included in wepon damage based spells
9951 if (!isWeaponDamageBasedSpell
)
9953 AuraList
const& mModDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9954 for(AuraList::const_iterator i
= mModDamageDone
.begin(); i
!= mModDamageDone
.end(); ++i
)
9956 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9957 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9958 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9959 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
9961 DoneFlat
+= (*i
)->GetModifier()->m_amount
;
9965 // Pets just add their bonus damage to their melee damage
9966 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9967 DoneFlat
+= ((Pet
*)this)->GetBonusDamage();
9970 // ..done flat (by creature type mask)
9971 DoneFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
, creatureTypeMask
);
9973 // ..done flat (base at attack power for marked target and base at attack power for creature type)
9974 if (attType
== RANGED_ATTACK
)
9976 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
9977 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9981 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
9982 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9985 // PERCENT damage auras
9986 // ====================
9987 float DonePercent
= 1.0f
;
9989 // ..done pct, already included in weapon damage based spells
9990 if(!isWeaponDamageBasedSpell
)
9992 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
9993 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
9995 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9996 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9997 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9998 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
10000 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
10004 if (attType
== OFF_ATTACK
)
10005 DonePercent
*= GetModifierValue(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_PCT
); // no school check required
10008 // ..done pct (by creature type mask)
10009 DonePercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
, creatureTypeMask
);
10011 // special dummys/class sripts and other effects
10012 // =============================================
10013 Unit
*owner
= GetOwner();
10017 // ..done (class scripts)
10020 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
10021 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
10023 if (!(*i
)->isAffectedOnSpell(spellProto
))
10026 switch((*i
)->GetModifier()->m_miscvalue
)
10029 // Merciless Combat
10032 // Merciless Combat
10033 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
10035 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
10036 DonePercent
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
10038 else // Tundra Stalker
10040 // Frost Fever (target debuff)
10041 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
10042 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10047 case 7293: // Rage of Rivendare
10049 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
10050 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10053 // Marked for Death
10060 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
10061 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10068 // .. done (class scripts)
10069 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
10070 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
10072 switch((*i
)->GetMiscValue())
10077 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
10079 Aura
* eff0
= GetAura((*i
)->GetId(), EFFECT_INDEX_0
);
10080 if (!eff0
|| (*i
)->GetEffIndex() != EFFECT_INDEX_1
)
10082 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
10086 // effect 0 have expected value but in negative state
10087 DonePercent
*= (-eff0
->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
10094 if (spellProto
&& spellProto
->SpellFamilyName
== SPELLFAMILY_DEATHKNIGHT
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000400000000))
10097 bool found
= false;
10098 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
10099 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
10101 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
10110 // search for Glacier Rot dummy aura
10111 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
10112 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
10114 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
10116 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
10124 // final calculation
10125 // =================
10127 float DoneTotal
= 0.0f
;
10129 // scaling of non weapon based spells
10130 if (!isWeaponDamageBasedSpell
)
10132 // apply ap bonus and benefit affected by spell power implicit coeffs and spell level penalties
10133 DoneTotal
= SpellBonusWithCoeffs(spellProto
, DoneTotal
, DoneFlat
, APbonus
, damagetype
, true);
10135 // weapon damage based spells
10136 else if( APbonus
|| DoneFlat
)
10138 bool normalized
= spellProto
? IsSpellHaveEffect(spellProto
, SPELL_EFFECT_NORMALIZED_WEAPON_DMG
) : false;
10139 DoneTotal
+= int32(APbonus
/ 14.0f
* GetAPMultiplier(attType
,normalized
));
10141 // for weapon damage based spells we still have to apply damage done percent mods
10142 // (that are already included into pdamage) to not-yet included DoneFlat
10143 // e.g. from doneVersusCreature, apBonusVs...
10148 case BASE_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_MAINHAND
; break;
10149 case OFF_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_OFFHAND
; break;
10150 case RANGED_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_RANGED
; break;
10153 DoneTotal
+= DoneFlat
;
10155 DoneTotal
*= GetModifierValue(unitMod
, TOTAL_PCT
);
10158 float tmpDamage
= float(int32(pdamage
) + DoneTotal
* int32(stack
)) * DonePercent
;
10160 // apply spellmod to Done damage
10163 if(Player
* modOwner
= GetSpellModOwner())
10164 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
10167 // bonus result can be negative
10168 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
10172 * Calculates target part of melee damage bonuses,
10173 * will be called on each tick for periodic damage over time auras
10175 uint32
Unit::MeleeDamageBonusTaken(Unit
*pCaster
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
10183 // differentiate for weapon damage based spells
10184 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
10185 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
10186 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
10188 // Shred also have bonus as MECHANIC_BLEED damages
10189 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
10190 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
10193 // FLAT damage bonus auras
10194 // =======================
10195 int32 TakenFlat
= 0;
10197 // ..taken flat (base at attack power for marked target and base at attack power for creature type)
10198 if (attType
== RANGED_ATTACK
)
10199 TakenFlat
+= GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
10201 TakenFlat
+= GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
10203 // ..taken flat (by school mask)
10204 TakenFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_TAKEN
, schoolMask
);
10206 // PERCENT damage auras
10207 // ====================
10208 float TakenPercent
= 1.0f
;
10210 // ..taken pct (by school mask)
10211 TakenPercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
, schoolMask
);
10213 // ..taken pct (by mechanic mask)
10214 TakenPercent
*= GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,mechanicMask
);
10216 // ..taken pct (melee/ranged)
10217 if(attType
== RANGED_ATTACK
)
10218 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
10220 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
10222 // ..taken pct (aoe avoidance)
10223 if(spellProto
&& IsAreaOfEffectSpell(spellProto
))
10224 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
10227 // special dummys/class scripts and other effects
10228 // =============================================
10230 // .. taken (dummy auras)
10231 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
10232 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
10234 switch((*i
)->GetSpellProto()->SpellIconID
)
10238 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
10240 if(GetTypeId() != TYPEID_PLAYER
)
10243 float mod
= ((Player
*)this)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
10244 if (mod
< float((*i
)->GetModifier()->m_amount
))
10245 mod
= float((*i
)->GetModifier()->m_amount
);
10247 TakenPercent
*= (mod
+ 100.0f
) / 100.0f
;
10253 // final calculation
10254 // =================
10256 // scaling of non weapon based spells
10257 if (!isWeaponDamageBasedSpell
)
10259 // apply benefit affected by spell power implicit coeffs and spell level penalties
10260 TakenFlat
= SpellBonusWithCoeffs(spellProto
, 0, TakenFlat
, 0, damagetype
, false);
10263 float tmpDamage
= float(int32(pdamage
) + TakenFlat
* int32(stack
)) * TakenPercent
;
10265 // bonus result can be negative
10266 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
10269 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
10273 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
10275 next
= itr
; ++next
;
10276 if(itr
->type
== type
)
10278 m_spellImmune
[op
].erase(itr
);
10279 next
= m_spellImmune
[op
].begin();
10282 SpellImmune Immune
;
10283 Immune
.spellId
= spellId
;
10284 Immune
.type
= type
;
10285 m_spellImmune
[op
].push_back(Immune
);
10289 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
10291 if(itr
->spellId
== spellId
)
10293 m_spellImmune
[op
].erase(itr
);
10301 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
10303 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
10305 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
10306 RemoveAurasWithDispelType(type
);
10309 float Unit::GetWeaponProcChance() const
10311 // normalized proc chance for weapon attack speed
10312 // (odd formula...)
10313 if (isAttackReady(BASE_ATTACK
))
10314 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
10315 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
10316 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
10321 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
10323 // proc per minute chance calculation
10326 return WeaponSpeed
* PPM
/ 600.0f
; // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
10329 void Unit::Mount(uint32 mount
, uint32 spellId
)
10334 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
10336 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
10338 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
10340 if (GetTypeId() == TYPEID_PLAYER
)
10342 // Called by Taxi system / GM command
10344 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10345 // Called by mount aura
10346 else if (SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellId
))
10348 // Flying case (Unsummon any pet)
10349 if (IsSpellHaveAura(spellInfo
, SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED
))
10350 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10351 // Normal case (Unsummon only permanent pet)
10352 else if (Pet
* pet
= GetPet())
10354 if (pet
->IsPermanentPetFor((Player
*)this) && !((Player
*)this)->InArena())
10355 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10357 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,true);
10363 void Unit::Unmount()
10368 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
10370 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
10371 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
10373 // only resummon old pet if the player is already added to a map
10374 // this prevents adding a pet to a not created map which would otherwise cause a crash
10375 // (it could probably happen when logging in after a previous crash)
10376 if(GetTypeId() == TYPEID_PLAYER
)
10378 if(Pet
* pet
= GetPet())
10379 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,false);
10381 ((Player
*)this)->ResummonPetTemporaryUnSummonedIfAny();
10385 void Unit::SetInCombatWith(Unit
* enemy
)
10387 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
10388 if (eOwner
->IsPvP())
10390 SetInCombatState(true,enemy
);
10395 if (eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
10397 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
10398 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
10400 SetInCombatState(true,enemy
);
10405 SetInCombatState(false,enemy
);
10408 void Unit::SetInCombatState(bool PvP
, Unit
* enemy
)
10410 // only alive units can be in combat
10415 m_CombatTimer
= 5000;
10417 bool creatureNotInCombat
= GetTypeId()==TYPEID_UNIT
&& !HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10419 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10421 if (isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10422 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10424 if (creatureNotInCombat
)
10426 // should probably be removed for the attacked (+ it's party/group) only, not global
10427 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10429 if (((Creature
*)this)->AI())
10430 ((Creature
*)this)->AI()->EnterCombat(enemy
);
10434 void Unit::ClearInCombat()
10437 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10439 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10440 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10442 // Player's state will be cleared in Player::UpdateContestedPvP
10443 if (GetTypeId() != TYPEID_PLAYER
)
10445 Creature
* creature
= (Creature
*)this;
10446 if (creature
->GetCreatureInfo() && creature
->GetCreatureInfo()->unit_flags
& UNIT_FLAG_OOC_NOT_ATTACKABLE
)
10447 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10449 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
10452 ((Player
*)this)->UpdatePotionCooldown();
10455 bool Unit::isTargetableForAttack(bool inverseAlive
/*=false*/) const
10457 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
10460 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
10463 // to be removed if unit by any reason enter combat
10464 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
))
10467 // inversealive is needed for some spells which need to be casted at dead targets (aoe)
10468 if (isAlive() == inverseAlive
)
10471 return IsInWorld() && !hasUnitState(UNIT_STAT_DIED
) && !isInFlight();
10474 int32
Unit::ModifyHealth(int32 dVal
)
10481 int32 curHealth
= (int32
)GetHealth();
10483 int32 val
= dVal
+ curHealth
;
10490 int32 maxHealth
= (int32
)GetMaxHealth();
10492 if(val
< maxHealth
)
10495 gain
= val
- curHealth
;
10497 else if(curHealth
!= maxHealth
)
10499 SetHealth(maxHealth
);
10500 gain
= maxHealth
- curHealth
;
10506 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
10513 int32 curPower
= (int32
)GetPower(power
);
10515 int32 val
= dVal
+ curPower
;
10522 int32 maxPower
= (int32
)GetMaxPower(power
);
10526 SetPower(power
,val
);
10527 gain
= val
- curPower
;
10529 else if(curPower
!= maxPower
)
10531 SetPower(power
,maxPower
);
10532 gain
= maxPower
- curPower
;
10538 bool Unit::isVisibleForOrDetect(Unit
const* u
, WorldObject
const* viewPoint
, bool detect
, bool inVisibleList
, bool is3dDistance
) const
10540 if(!u
|| !IsInMap(u
))
10543 // Always can see self
10547 // player visible for other player if not logout and at same transport
10548 // including case when player is out of world
10549 bool at_same_transport
=
10550 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
10551 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
10552 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
10553 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
10556 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
10559 // forbidden to seen (at GM respawn command)
10560 if(m_Visibility
==VISIBILITY_RESPAWN
)
10563 Map
& _map
= *u
->GetMap();
10564 // Grid dead/alive checks
10565 if (u
->GetTypeId()==TYPEID_PLAYER
)
10567 // non visible at grid for any stealth state
10568 if(!IsVisibleInGridForPlayer((Player
*)u
))
10571 // if player is dead then he can't detect anyone in any cases
10577 // all dead creatures/players not visible for any creatures
10578 if(!u
->isAlive() || !isAlive())
10582 // always seen by far sight caster
10583 if (u
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)u
)->GetFarSight()==GetGUID())
10586 // different visible distance checks
10587 if (u
->isInFlight()) // what see player in flight
10589 // use object grey distance for all (only see objects any way)
10590 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10593 else if(!isAlive()) // distance for show body
10595 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10598 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
10600 if(u
->GetTypeId()==TYPEID_PLAYER
)
10602 // Players far than max visible distance for player or not in our map are not visible too
10603 if (!at_same_transport
&& !IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10608 // Units far than max visible distance for creature or not in our map are not visible too
10609 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10613 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
10615 // Pet/charmed far than max visible distance for player or not in our map are not visible too
10616 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10619 else // distance for show creature
10621 // Units far than max visible distance for creature or not in our map are not visible too
10622 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10626 // always seen by owner
10627 if (GetCharmerOrOwnerGUID()==u
->GetGUID())
10630 // isInvisibleForAlive() those units can only be seen by dead or if other
10631 // unit is also invisible for alive.. if an isinvisibleforalive unit dies we
10632 // should be able to see it too
10633 if (u
->isAlive() && isAlive() && isInvisibleForAlive() != u
->isInvisibleForAlive())
10634 if (u
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)u
)->isGameMaster())
10637 // Visible units, always are visible for all units, except for units under invisibility and phases
10638 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0 && InSamePhase(u
))
10641 // GMs see any players, not higher GMs and all units in any phase
10642 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
10644 if(GetTypeId() == TYPEID_PLAYER
)
10645 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
10650 // non faction visibility non-breakable for non-GMs
10651 if (m_Visibility
== VISIBILITY_OFF
)
10654 // phased visibility (both must phased in same way)
10655 if(!InSamePhase(u
))
10658 // raw invisibility
10659 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
10661 // detectable invisibility case
10663 // Invisible units, always are visible for units under same invisibility type
10664 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
10665 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
10666 u
->canDetectInvisibilityOf(this) ||
10667 // Units that can detect invisibility always are visible for units that can be detected
10668 canDetectInvisibilityOf(u
) ))
10673 // special cases for always overwrite invisibility/stealth
10674 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
10676 // non-hostile case
10677 if (!u
->IsHostileTo(this))
10679 // 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)
10680 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
10682 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
10685 // else apply same rules as for hostile case (detecting check for stealth)
10691 // Hunter mark functionality
10692 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
10693 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
10694 if((*iter
)->GetCasterGUID()==u
->GetGUID())
10697 // else apply detecting check for stealth
10700 // none other cases for detect invisibility, so invisible
10704 // else apply stealth detecting check
10707 // unit got in stealth in this moment and must ignore old detected state
10708 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
10711 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
10712 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
10715 // NOW ONLY STEALTH CASE
10717 //if in non-detect mode then invisible for unit
10718 //mobs always detect players (detect == true)... return 'false' for those mobs which have (detect == false)
10719 //players detect players only in Player::HandleStealthedUnitsDetection()
10721 return (u
->GetTypeId() == TYPEID_PLAYER
) ? ((Player
*)u
)->HaveAtClient(this) : false;
10725 // If is attacked then stealth is lost, some creature can use stealth too
10726 if( !getAttackers().empty() )
10729 // If there is collision rogue is seen regardless of level difference
10730 if (IsWithinDist(u
,0.24f
))
10733 //If a mob or player is stunned he will not be able to detect stealth
10734 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
10738 float visibleDistance
= (u
->GetTypeId() == TYPEID_PLAYER
) ? MAX_PLAYER_STEALTH_DETECT_RANGE
: ((Creature
const*)u
)->GetAttackDistance(this);
10740 //Always invisible from back (when stealth detection is on), also filter max distance cases
10741 bool isInFront
= viewPoint
->isInFrontInMap(this, visibleDistance
);
10745 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
10746 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
10748 //Calculation if target is in front
10750 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
10751 visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
10753 //Visible distance is modified by
10754 //-Level Diff (every level diff = 1.0f in visible distance)
10755 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
10757 //This allows to check talent tree and will add addition stealth dependent on used points)
10758 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
10762 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
10763 //based on wowwiki every 5 mod we have 1 more level diff in calculation
10764 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_DETECT
)) - stealthMod
)/5.0f
;
10765 visibleDistance
= visibleDistance
> MAX_PLAYER_STEALTH_DETECT_RANGE
? MAX_PLAYER_STEALTH_DETECT_RANGE
: visibleDistance
;
10767 // recheck new distance
10768 if(visibleDistance
<= 0 || !IsWithinDist(viewPoint
,visibleDistance
))
10772 // Now check is target visible with LoS
10774 viewPoint
->GetPosition(ox
,oy
,oz
);
10775 return IsWithinLOS(ox
,oy
,oz
);
10778 void Unit::SetVisibility(UnitVisibility x
)
10786 if(GetTypeId()==TYPEID_PLAYER
)
10787 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10789 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10793 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
10795 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
10797 for(uint32 i
= 0; i
< 10; ++i
)
10799 if(((1 << i
) & mask
)==0)
10802 // find invisibility level
10803 int32 invLevel
= 0;
10804 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
10805 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
10806 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
10807 invLevel
= (*itr
)->GetModifier()->m_amount
;
10809 // find invisibility detect level
10810 int32 detectLevel
= 0;
10811 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
10812 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
10813 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
10814 detectLevel
= (*itr
)->GetModifier()->m_amount
;
10816 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
10818 detectLevel
= ((Player
*)this)->GetDrunkValue();
10821 if(invLevel
<= detectLevel
)
10829 struct UpdateWalkModeHelper
10831 explicit UpdateWalkModeHelper(Unit
* _source
) : source(_source
) {}
10832 void operator()(Unit
* unit
) const { unit
->UpdateWalkMode(source
, true); }
10836 void Unit::UpdateWalkMode(Unit
* source
, bool self
)
10838 if (GetTypeId() == TYPEID_PLAYER
)
10839 ((Player
*)this)->CallForAllControlledUnits(UpdateWalkModeHelper(source
), false, true, true, true);
10842 bool on
= source
->GetTypeId() == TYPEID_PLAYER
10843 ? ((Player
*)source
)->HasMovementFlag(MOVEFLAG_WALK_MODE
)
10844 : ((Creature
*)source
)->HasSplineFlag(SPLINEFLAG_WALKMODE
);
10848 if (((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10849 ((Creature
*)this)->AddSplineFlag(SPLINEFLAG_WALKMODE
);
10853 if (((Creature
*)this)->isPet())
10854 ((Creature
*)this)->RemoveSplineFlag(SPLINEFLAG_WALKMODE
);
10858 CallForAllControlledUnits(UpdateWalkModeHelper(source
), false, true, true);
10861 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
, float ratio
)
10863 // not in combat pet have same speed as owner
10869 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10871 if(Unit
* owner
= GetOwner())
10873 SetSpeedRate(mtype
, owner
->GetSpeedRate(mtype
), forced
);
10880 int32 main_speed_mod
= 0;
10881 float stack_bonus
= 1.0f
;
10882 float non_stack_bonus
= 1.0f
;
10890 if (IsMounted()) // Use on mount auras
10892 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
10893 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
10894 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
10898 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
10899 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
10900 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
10904 case MOVE_RUN_BACK
:
10908 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
10911 case MOVE_SWIM_BACK
:
10915 if (IsMounted()) // Use on mount auras
10917 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED
);
10918 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED_STACKING
);
10919 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED_NOT_STACKING
))/100.0f
;
10921 else // Use not mount (shapeshift for example) auras (should stack)
10923 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED
);
10924 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_STACKING
);
10925 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACKING
))/100.0f
;
10929 case MOVE_FLIGHT_BACK
:
10932 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
10936 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
10937 // now we ready for speed calculation
10938 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
10946 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
10947 // TODO: possible affect only on MOVE_RUN
10948 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
10950 // Use speed from aura
10951 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
10952 if (speed
> max_speed
)
10961 // for creature case, we check explicit if mob searched for assistance
10962 if (GetTypeId() == TYPEID_UNIT
)
10964 if (((Creature
*)this)->HasSearchedAssistance())
10965 speed
*= 0.66f
; // best guessed value, so this will be 33% reduction. Based off initial speed, mob can then "run", "walk fast" or "walk".
10968 // Apply strongest slow aura mod to speed
10969 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
10972 speed
*=(100.0f
+ slow
)/100.0f
;
10973 float min_speed
= (float)GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MINIMUM_SPEED
) / 100.0f
;
10974 if (speed
< min_speed
)
10977 SetSpeedRate(mtype
, speed
* ratio
, forced
);
10980 float Unit::GetSpeed( UnitMoveType mtype
) const
10982 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
10985 struct SetSpeedRateHelper
10987 explicit SetSpeedRateHelper(UnitMoveType _mtype
, bool _forced
) : mtype(_mtype
), forced(_forced
) {}
10988 void operator()(Unit
* unit
) const { unit
->UpdateSpeed(mtype
,forced
); }
10989 UnitMoveType mtype
;
10993 void Unit::SetSpeedRate(UnitMoveType mtype
, float rate
, bool forced
)
10998 // Update speed only on change
10999 if (m_speed_rate
[mtype
] == rate
)
11002 m_speed_rate
[mtype
] = rate
;
11004 propagateSpeedChange();
11012 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11015 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11017 case MOVE_RUN_BACK
:
11018 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11021 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11023 case MOVE_SWIM_BACK
:
11024 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11026 case MOVE_TURN_RATE
:
11027 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+2+4+4+4+4+4+4+4);
11030 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11032 case MOVE_FLIGHT_BACK
:
11033 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11035 case MOVE_PITCH_RATE
:
11036 data
.Initialize(MSG_MOVE_SET_PITCH_RATE
, 8+4+2+4+4+4+4+4+4+4);
11039 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
11043 data
<< GetPackGUID();
11044 data
<< uint32(0); // movement flags
11045 data
<< uint16(0); // unk flags
11046 data
<< uint32(getMSTime());
11047 data
<< float(GetPositionX());
11048 data
<< float(GetPositionY());
11049 data
<< float(GetPositionZ());
11050 data
<< float(GetOrientation());
11051 data
<< uint32(0); // fall time
11052 data
<< float(GetSpeed(mtype
));
11053 SendMessageToSet( &data
, true );
11057 if(GetTypeId() == TYPEID_PLAYER
)
11059 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
11060 // and do it only for real sent packets and use run for run/mounted as client expected
11061 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
11067 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
11070 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
11072 case MOVE_RUN_BACK
:
11073 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
11076 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
11078 case MOVE_SWIM_BACK
:
11079 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
11081 case MOVE_TURN_RATE
:
11082 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
11085 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
11087 case MOVE_FLIGHT_BACK
:
11088 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
11090 case MOVE_PITCH_RATE
:
11091 data
.Initialize(SMSG_FORCE_PITCH_RATE_CHANGE
, 16);
11094 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
11097 data
<< GetPackGUID();
11098 data
<< (uint32
)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
11099 if (mtype
== MOVE_RUN
)
11100 data
<< uint8(0); // new 2.1.0
11101 data
<< float(GetSpeed(mtype
));
11102 SendMessageToSet( &data
, true );
11105 if (GetTypeId() == TYPEID_PLAYER
) // need include minpet
11106 ((Player
*)this)->CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true,true);
11108 CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true);
11111 void Unit::SetHover(bool on
)
11114 CastSpell(this, 11010, true);
11116 RemoveAurasDueToSpell(11010);
11119 void Unit::setDeathState(DeathState s
)
11121 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
11124 DeleteThreatList();
11125 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
11127 if(IsNonMeleeSpellCasted(false))
11128 InterruptNonMeleeSpells(false);
11131 if (s
== JUST_DIED
)
11133 RemoveAllAurasOnDeath();
11135 UnsummonAllTotems();
11137 // after removing a Fearaura (in RemoveAllAurasOnDeath)
11138 // Unit::SetFeared is called and makes that creatures attack player again
11141 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
11142 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
11143 // remove aurastates allowing special moves
11144 ClearAllReactives();
11145 ClearDiminishings();
11147 else if(s
== JUST_ALIVED
)
11149 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
11152 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
11154 //_ApplyAllAuraMods();
11159 /*########################################
11161 ######## AGGRO SYSTEM ########
11163 ########################################*/
11164 bool Unit::CanHaveThreatList() const
11166 // only creatures can have threat list
11167 if( GetTypeId() != TYPEID_UNIT
)
11170 // only alive units can have threat list
11174 // totems can not have threat list
11175 if( ((Creature
*)this)->isTotem() )
11178 // vehicles can not have threat list
11179 if( ((Creature
*)this)->isVehicle() )
11182 // pets can not have a threat list, unless they are controlled by a creature
11183 if( ((Creature
*)this)->isPet() && IS_PLAYER_GUID(((Pet
*)this)->GetOwnerGUID()) )
11189 //======================================================================
11191 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
11193 if (!HasAuraType(SPELL_AURA_MOD_THREAT
))
11196 if (schoolMask
== SPELL_SCHOOL_MASK_NONE
)
11199 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
11201 return threat
* m_threatModifier
[school
];
11204 //======================================================================
11206 void Unit::AddThreat(Unit
* pVictim
, float threat
/*= 0.0f*/, bool crit
/*= false*/, SpellSchoolMask schoolMask
/*= SPELL_SCHOOL_MASK_NONE*/, SpellEntry
const *threatSpell
/*= NULL*/)
11208 // Only mobs can manage threat lists
11209 if(CanHaveThreatList())
11210 m_ThreatManager
.addThreat(pVictim
, threat
, crit
, schoolMask
, threatSpell
);
11213 //======================================================================
11215 void Unit::DeleteThreatList()
11217 if(CanHaveThreatList() && !m_ThreatManager
.isThreatListEmpty())
11219 m_ThreatManager
.clearReferences();
11222 //======================================================================
11224 void Unit::TauntApply(Unit
* taunter
)
11226 ASSERT(GetTypeId()== TYPEID_UNIT
);
11228 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
11231 if(!CanHaveThreatList())
11234 Unit
*target
= getVictim();
11235 if(target
&& target
== taunter
)
11238 SetInFront(taunter
);
11239 if (((Creature
*)this)->AI())
11240 ((Creature
*)this)->AI()->AttackStart(taunter
);
11242 m_ThreatManager
.tauntApply(taunter
);
11245 //======================================================================
11247 void Unit::TauntFadeOut(Unit
*taunter
)
11249 ASSERT(GetTypeId()== TYPEID_UNIT
);
11251 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
11254 if(!CanHaveThreatList())
11257 Unit
*target
= getVictim();
11258 if(!target
|| target
!= taunter
)
11261 if(m_ThreatManager
.isThreatListEmpty())
11263 if(((Creature
*)this)->AI())
11264 ((Creature
*)this)->AI()->EnterEvadeMode();
11268 m_ThreatManager
.tauntFadeOut(taunter
);
11269 target
= m_ThreatManager
.getHostileTarget();
11271 if (target
&& target
!= taunter
)
11273 SetInFront(target
);
11274 if (((Creature
*)this)->AI())
11275 ((Creature
*)this)->AI()->AttackStart(target
);
11279 //======================================================================
11281 bool Unit::SelectHostileTarget()
11283 //function provides main threat functionality
11284 //next-victim-selection algorithm and evade mode are called
11285 //threat list sorting etc.
11287 ASSERT(GetTypeId()== TYPEID_UNIT
);
11289 if (!this->isAlive())
11291 //This function only useful once AI has been initialized
11292 if (!((Creature
*)this)->AI())
11295 Unit
* target
= NULL
;
11297 // First checking if we have some taunt on us
11298 const AuraList
& tauntAuras
= GetAurasByType(SPELL_AURA_MOD_TAUNT
);
11299 if ( !tauntAuras
.empty() )
11303 // The last taunt aura caster is alive an we are happy to attack him
11304 if ( (caster
= tauntAuras
.back()->GetCaster()) && caster
->isAlive() )
11306 else if (tauntAuras
.size() > 1)
11308 // We do not have last taunt aura caster but we have more taunt auras,
11309 // so find first available target
11311 // Auras are pushed_back, last caster will be on the end
11312 AuraList::const_iterator aura
= --tauntAuras
.end();
11316 if ( (caster
= (*aura
)->GetCaster()) &&
11317 caster
->IsInMap(this) && caster
->isTargetableForAttack() && caster
->isInAccessablePlaceFor((Creature
*)this) )
11322 }while (aura
!= tauntAuras
.begin());
11326 if ( !target
&& !m_ThreatManager
.isThreatListEmpty() )
11327 // No taunt aura or taunt aura caster is dead standart target selection
11328 target
= m_ThreatManager
.getHostileTarget();
11332 if (!hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_DIED
))
11334 SetInFront(target
);
11335 ((Creature
*)this)->AI()->AttackStart(target
);
11340 // no target but something prevent go to evade mode
11341 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
11344 // last case when creature don't must go to evade mode:
11345 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
11346 // for example at owner command to pet attack some far away creature
11347 // Note: creature not have targeted movement generator but have attacker in this case
11348 if (GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE
)
11350 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
11352 if ((*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this))
11357 // enter in evade mode in other case
11358 ((Creature
*)this)->AI()->EnterEvadeMode();
11363 //======================================================================
11364 //======================================================================
11365 //======================================================================
11367 int32
Unit::CalculateSpellDamage(Unit
const* target
, SpellEntry
const* spellProto
, SpellEffectIndex effect_index
, int32
const* effBasePoints
)
11369 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
11371 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
11373 int32 level
= int32(getLevel());
11374 if (level
> (int32
)spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
11375 level
= (int32
)spellProto
->maxLevel
;
11376 else if (level
< (int32
)spellProto
->baseLevel
)
11377 level
= (int32
)spellProto
->baseLevel
;
11378 level
-= (int32
)spellProto
->spellLevel
;
11380 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
11381 int32 basePoints
= effBasePoints
? *effBasePoints
- 1 : spellProto
->EffectBasePoints
[effect_index
];
11382 basePoints
+= int32(level
* basePointsPerLevel
);
11383 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
]);
11384 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
11386 switch(randomPoints
)
11388 case 0: // not used
11389 case 1: basePoints
+= 1; break; // range 1..1
11391 // range can have positive (1..rand) and negative (rand..1) values, so order its for irand
11392 int32 randvalue
= (randomPoints
>= 1)
11393 ? irand(1, randomPoints
)
11394 : irand(randomPoints
, 1);
11396 basePoints
+= randvalue
;
11400 int32 value
= basePoints
;
11403 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
11404 value
+= (int32
)(comboDamage
* comboPoints
);
11406 if(Player
* modOwner
= GetSpellModOwner())
11408 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_ALL_EFFECTS
, value
);
11409 switch(effect_index
)
11412 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT1
, value
);
11415 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT2
, value
);
11418 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT3
, value
);
11423 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
11424 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
11425 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
&&
11426 (spellProto
->Effect
[effect_index
] != SPELL_EFFECT_APPLY_AURA
|| spellProto
->EffectApplyAuraName
[effect_index
] != SPELL_AURA_MOD_DECREASE_SPEED
))
11427 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
11432 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, SpellEffectIndex effect_index
, Unit
const* target
)
11434 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
11436 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
11438 int32 minduration
= GetSpellDuration(spellProto
);
11439 int32 maxduration
= GetSpellMaxDuration(spellProto
);
11443 if( minduration
!= -1 && minduration
!= maxduration
)
11444 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
11446 duration
= minduration
;
11450 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
11451 // Find total mod value (negative bonus)
11452 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
11453 // Modify from SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL aura for negatve effects (stack always ?)
11454 if (!IsPositiveEffect(spellProto
->Id
, effect_index
))
11455 durationMod_always
+=target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
, spellProto
->Dispel
);
11456 // Find max mod (negative bonus)
11457 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
11459 if (!IsPositiveSpell(spellProto
->Id
))
11460 durationMod_always
+= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS
, spellProto
->DmgClass
);
11462 int32 durationMod
= 0;
11463 // Select strongest negative mod
11464 if (durationMod_always
> durationMod_not_stack
)
11465 durationMod
= durationMod_not_stack
;
11467 durationMod
= durationMod_always
;
11469 if (durationMod
!= 0)
11470 duration
= int32(int64(duration
) * (100+durationMod
) /100);
11472 if (duration
< 0) duration
= 0;
11478 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
11480 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11482 if(i
->DRGroup
!= group
)
11486 return DIMINISHING_LEVEL_1
;
11489 return DIMINISHING_LEVEL_1
;
11491 // If last spell was casted more than 15 seconds ago - reset the count.
11492 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
11494 i
->hitCount
= DIMINISHING_LEVEL_1
;
11495 return DIMINISHING_LEVEL_1
;
11497 // or else increase the count.
11500 return DiminishingLevels(i
->hitCount
);
11503 return DIMINISHING_LEVEL_1
;
11506 void Unit::IncrDiminishing(DiminishingGroup group
)
11508 // Checking for existing in the table
11509 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11511 if(i
->DRGroup
!= group
)
11513 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
11517 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
11520 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
, int32 limitduration
)
11522 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
11525 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
11526 if(limitduration
> 0 && duration
> limitduration
)
11528 // test pet/charm masters instead pets/charmeds
11529 Unit
const* targetOwner
= GetCharmerOrOwner();
11530 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
11532 Unit
const* target
= targetOwner
? targetOwner
: this;
11533 Unit
const* source
= casterOwner
? casterOwner
: caster
;
11535 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
11536 duration
= limitduration
;
11541 // Some diminishings applies to mobs too (for example, Stun)
11542 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
11544 DiminishingLevels diminish
= Level
;
11547 case DIMINISHING_LEVEL_1
: break;
11548 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
11549 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
11550 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
11555 duration
= int32(duration
* mod
);
11558 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
11560 // Checking for existing in the table
11561 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11563 if(i
->DRGroup
!= group
)
11571 // Remember time after last aura from group removed
11573 i
->hitTime
= getMSTime();
11579 Unit
* Unit::GetUnit(WorldObject
const& object
, uint64 guid
)
11581 return ObjectAccessor::GetUnit(object
,guid
);
11584 bool Unit::isVisibleForInState( Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const
11586 return isVisibleForOrDetect(u
, viewPoint
, false, inVisibleList
, false);
11589 /// returns true if creature can't be seen by alive units
11590 bool Unit::isInvisibleForAlive() const
11592 if (m_AuraFlags
& UNIT_AURAFLAG_ALIVE_INVISIBLE
)
11594 // TODO: maybe spiritservices also have just an aura
11595 return isSpiritService();
11598 uint32
Unit::GetCreatureType() const
11600 if(GetTypeId() == TYPEID_PLAYER
)
11602 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(m_form
);
11603 if(ssEntry
&& ssEntry
->creatureType
> 0)
11604 return ssEntry
->creatureType
;
11606 return CREATURE_TYPE_HUMANOID
;
11609 return ((Creature
*)this)->GetCreatureInfo()->type
;
11612 /*#######################################
11614 ######## STAT SYSTEM ########
11616 #######################################*/
11618 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
11620 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11622 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
11628 switch(modifierType
)
11632 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
11636 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
11639 val
= (100.0f
+ amount
) / 100.0f
;
11640 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
11647 if(!CanModifyStats())
11652 case UNIT_MOD_STAT_STRENGTH
:
11653 case UNIT_MOD_STAT_AGILITY
:
11654 case UNIT_MOD_STAT_STAMINA
:
11655 case UNIT_MOD_STAT_INTELLECT
:
11656 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
11658 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
11659 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
11661 case UNIT_MOD_MANA
:
11662 case UNIT_MOD_RAGE
:
11663 case UNIT_MOD_FOCUS
:
11664 case UNIT_MOD_ENERGY
:
11665 case UNIT_MOD_HAPPINESS
:
11666 case UNIT_MOD_RUNE
:
11667 case UNIT_MOD_RUNIC_POWER
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
11669 case UNIT_MOD_RESISTANCE_HOLY
:
11670 case UNIT_MOD_RESISTANCE_FIRE
:
11671 case UNIT_MOD_RESISTANCE_NATURE
:
11672 case UNIT_MOD_RESISTANCE_FROST
:
11673 case UNIT_MOD_RESISTANCE_SHADOW
:
11674 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
11676 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
11677 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
11679 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
11680 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
11681 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
11690 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
11692 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11694 sLog
.outError("trial to access non existed modifier value from UnitMods!");
11698 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
11701 return m_auraModifiersGroup
[unitMod
][modifierType
];
11704 float Unit::GetTotalStatValue(Stats stat
) const
11706 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
11708 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11711 // value = ((base_value * base_pct) + total_value) * total_pct
11712 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
11713 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11714 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11715 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11720 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
11722 if(unitMod
>= UNIT_MOD_END
)
11724 sLog
.outError("trial to access non existed UnitMods in GetTotalAuraModValue()!");
11728 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11731 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
11732 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11733 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11734 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11739 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
11741 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
11745 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
11746 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
11747 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
11748 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
11749 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
11750 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
11759 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
11761 Stats stat
= STAT_STRENGTH
;
11765 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
11766 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
11767 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
11768 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
11769 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
11778 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
11782 case UNIT_MOD_MANA
: return POWER_MANA
;
11783 case UNIT_MOD_RAGE
: return POWER_RAGE
;
11784 case UNIT_MOD_FOCUS
: return POWER_FOCUS
;
11785 case UNIT_MOD_ENERGY
: return POWER_ENERGY
;
11786 case UNIT_MOD_HAPPINESS
: return POWER_HAPPINESS
;
11787 case UNIT_MOD_RUNE
: return POWER_RUNE
;
11788 case UNIT_MOD_RUNIC_POWER
:return POWER_RUNIC_POWER
;
11789 default: return POWER_MANA
;
11795 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
11797 if (attType
== RANGED_ATTACK
)
11799 int32 ap
= GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER_MODS
);
11802 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER
));
11806 int32 ap
= GetInt32Value(UNIT_FIELD_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_ATTACK_POWER_MODS
);
11809 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER
));
11813 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
11815 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
11818 return m_weaponDamage
[attType
][type
];
11821 void Unit::SetLevel(uint32 lvl
)
11823 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
11826 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
11827 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
11830 void Unit::SetHealth(uint32 val
)
11832 uint32 maxHealth
= GetMaxHealth();
11833 if(maxHealth
< val
)
11836 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
11839 if(GetTypeId() == TYPEID_PLAYER
)
11841 if(((Player
*)this)->GetGroup())
11842 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
11844 else if(((Creature
*)this)->isPet())
11846 Pet
*pet
= ((Pet
*)this);
11847 if(pet
->isControlled())
11849 Unit
*owner
= GetOwner();
11850 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11851 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
11856 void Unit::SetMaxHealth(uint32 val
)
11858 uint32 health
= GetHealth();
11859 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
11862 if(GetTypeId() == TYPEID_PLAYER
)
11864 if(((Player
*)this)->GetGroup())
11865 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
11867 else if(((Creature
*)this)->isPet())
11869 Pet
*pet
= ((Pet
*)this);
11870 if(pet
->isControlled())
11872 Unit
*owner
= GetOwner();
11873 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11874 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP
);
11882 void Unit::SetHealthPercent(float percent
)
11884 uint32 newHealth
= GetMaxHealth() * percent
/100.0f
;
11885 SetHealth(newHealth
);
11888 void Unit::SetPower(Powers power
, uint32 val
)
11890 if(GetPower(power
) == val
)
11893 uint32 maxPower
= GetMaxPower(power
);
11897 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
11899 WorldPacket
data(SMSG_POWER_UPDATE
);
11900 data
<< GetPackGUID();
11901 data
<< uint8(power
);
11902 data
<< uint32(val
);
11903 SendMessageToSet(&data
, GetTypeId() == TYPEID_PLAYER
? true : false);
11906 if(GetTypeId() == TYPEID_PLAYER
)
11908 if(((Player
*)this)->GetGroup())
11909 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11911 else if(((Creature
*)this)->isPet())
11913 Pet
*pet
= ((Pet
*)this);
11914 if(pet
->isControlled())
11916 Unit
*owner
= GetOwner();
11917 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11918 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11921 // Update the pet's character sheet with happiness damage bonus
11922 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
11924 pet
->UpdateDamagePhysical(BASE_ATTACK
);
11929 void Unit::SetMaxPower(Powers power
, uint32 val
)
11931 uint32 cur_power
= GetPower(power
);
11932 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
11935 if(GetTypeId() == TYPEID_PLAYER
)
11937 if(((Player
*)this)->GetGroup())
11938 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_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_MAX_POWER
);
11951 if(val
< cur_power
)
11952 SetPower(power
, val
);
11955 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
11957 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
11960 if(GetTypeId() == TYPEID_PLAYER
)
11962 if(((Player
*)this)->GetGroup())
11963 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11965 else if(((Creature
*)this)->isPet())
11967 Pet
*pet
= ((Pet
*)this);
11968 if(pet
->isControlled())
11970 Unit
*owner
= GetOwner();
11971 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11972 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11977 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
11979 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
11982 if(GetTypeId() == TYPEID_PLAYER
)
11984 if(((Player
*)this)->GetGroup())
11985 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
11987 else if(((Creature
*)this)->isPet())
11989 Pet
*pet
= ((Pet
*)this);
11990 if(pet
->isControlled())
11992 Unit
*owner
= GetOwner();
11993 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11994 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
11999 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
12001 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
12003 tAuraProcTriggerDamage
.push_back(aura
);
12005 tAuraProcTriggerDamage
.remove(aura
);
12008 uint32
Unit::GetCreatePowers( Powers power
) const
12010 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
12013 case POWER_HEALTH
: return 0;
12014 case POWER_MANA
: return GetCreateMana();
12015 case POWER_RAGE
: return 1000;
12016 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
12017 case POWER_ENERGY
: return 100;
12018 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
12019 case POWER_RUNIC_POWER
: return 1000;
12020 case POWER_RUNE
: return 0;
12026 void Unit::AddToWorld()
12028 Object::AddToWorld();
12031 void Unit::RemoveFromWorld()
12037 RemoveNotOwnSingleTargetAuras();
12039 RemoveAllGameObjects();
12040 RemoveAllDynObjects();
12041 CleanupDeletedAuras();
12044 Object::RemoveFromWorld();
12047 void Unit::CleanupsBeforeDelete()
12049 if(m_uint32Values
) // only for fully created object
12051 InterruptNonMeleeSpells(true);
12052 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
12054 ClearComboPointHolders();
12055 DeleteThreatList();
12056 if (GetTypeId()==TYPEID_PLAYER
)
12057 getHostileRefManager().setOnlineOfflineState(false);
12059 getHostileRefManager().deleteReferences();
12060 RemoveAllAuras(AURA_REMOVE_BY_DELETE
);
12061 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
12063 WorldObject::CleanupsBeforeDelete();
12066 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
12069 m_charmInfo
= new CharmInfo(charm
);
12070 return m_charmInfo
;
12073 CharmInfo::CharmInfo(Unit
* unit
)
12074 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
12076 for(int i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
12077 m_charmspells
[i
].SetActionAndType(0,ACT_DISABLED
);
12080 void CharmInfo::InitPetActionBar()
12082 // the first 3 SpellOrActions are attack, follow and stay
12083 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_START
- ACTION_BAR_INDEX_START
; ++i
)
12084 SetActionBar(ACTION_BAR_INDEX_START
+ i
,COMMAND_ATTACK
- i
,ACT_COMMAND
);
12086 // middle 4 SpellOrActions are spells/special attacks/abilities
12087 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_END
-ACTION_BAR_INDEX_PET_SPELL_START
; ++i
)
12088 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_START
+ i
,0,ACT_DISABLED
);
12090 // last 3 SpellOrActions are reactions
12091 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_END
- ACTION_BAR_INDEX_PET_SPELL_END
; ++i
)
12092 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_END
+ i
,COMMAND_ATTACK
- i
,ACT_REACTION
);
12095 void CharmInfo::InitEmptyActionBar()
12097 SetActionBar(ACTION_BAR_INDEX_START
,COMMAND_ATTACK
,ACT_COMMAND
);
12098 for(uint32 x
= ACTION_BAR_INDEX_START
+1; x
< ACTION_BAR_INDEX_END
; ++x
)
12099 SetActionBar(x
,0,ACT_PASSIVE
);
12102 void CharmInfo::InitPossessCreateSpells()
12104 InitEmptyActionBar(); //charm action bar
12106 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //possessed players don't have spells, keep the action bar empty
12109 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12111 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
12112 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
12114 AddSpellToActionBar(((Creature
*)m_unit
)->m_spells
[x
], ACT_PASSIVE
);
12118 void CharmInfo::InitCharmCreateSpells()
12120 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
12122 InitEmptyActionBar();
12126 InitPetActionBar();
12128 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12130 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
12134 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
12138 if (IsPassiveSpell(spellId
))
12140 m_unit
->CastSpell(m_unit
, spellId
, true);
12141 m_charmspells
[x
].SetActionAndType(spellId
,ACT_PASSIVE
);
12145 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
12147 ActiveStates newstate
;
12148 bool onlyselfcast
= true;
12149 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
12151 if(!spellInfo
) onlyselfcast
= false;
12152 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
12154 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
12155 onlyselfcast
= false;
12158 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
12159 newstate
= ACT_DISABLED
;
12161 newstate
= ACT_PASSIVE
;
12163 AddSpellToActionBar(spellId
, newstate
);
12168 bool CharmInfo::AddSpellToActionBar(uint32 spell_id
, ActiveStates newstate
)
12170 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
12172 // new spell rank can be already listed
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 PetActionBar
[i
].SetAction(spell_id
);
12185 // or use empty slot in other case
12186 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12188 if (!PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
12190 SetActionBar(i
,spell_id
,newstate
== ACT_DECIDE
? ACT_DISABLED
: newstate
);
12197 bool CharmInfo::RemoveSpellFromActionBar(uint32 spell_id
)
12199 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
12201 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12203 if (uint32 action
= PetActionBar
[i
].GetAction())
12205 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
12207 SetActionBar(i
,0,ACT_DISABLED
);
12216 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
12218 if(IsPassiveSpell(spellid
))
12221 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12222 if(spellid
== m_charmspells
[x
].GetAction())
12223 m_charmspells
[x
].SetType(apply
? ACT_ENABLED
: ACT_DISABLED
);
12226 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
12228 m_petnumber
= petnumber
;
12230 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
12232 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
12235 void CharmInfo::LoadPetActionBar(const std::string
& data
)
12237 InitPetActionBar();
12239 Tokens tokens
= StrSplit(data
, " ");
12241 if (tokens
.size() != (ACTION_BAR_INDEX_END
-ACTION_BAR_INDEX_START
)*2)
12242 return; // non critical, will reset to default
12245 Tokens::iterator iter
;
12246 for(iter
= tokens
.begin(), index
= ACTION_BAR_INDEX_START
; index
< ACTION_BAR_INDEX_END
; ++iter
, ++index
)
12248 // use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
12249 uint8 type
= (uint8
)atol((*iter
).c_str());
12251 uint32 action
= atol((*iter
).c_str());
12253 PetActionBar
[index
].SetActionAndType(action
,ActiveStates(type
));
12255 // check correctness
12256 if(PetActionBar
[index
].IsActionBarForSpell() && !sSpellStore
.LookupEntry(PetActionBar
[index
].GetAction()))
12257 SetActionBar(index
,0,ACT_DISABLED
);
12261 void CharmInfo::BuildActionBar( WorldPacket
* data
)
12263 for(uint32 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12264 *data
<< uint32(PetActionBar
[i
].packedData
);
12267 void CharmInfo::SetSpellAutocast( uint32 spell_id
, bool state
)
12269 for(int i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12271 if(spell_id
== PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
12273 PetActionBar
[i
].SetType(state
? ACT_ENABLED
: ACT_DISABLED
);
12279 bool Unit::isFrozen() const
12281 return HasAuraState(AURA_STATE_FROZEN
);
12284 struct ProcTriggeredData
12286 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
12287 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
12288 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
12290 SpellProcEventEntry
const *spellProcEvent
;
12291 Aura
* triggeredByAura
;
12292 Unit::spellEffectPair triggeredByAura_SpellPair
;
12295 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
12296 typedef std::list
< uint32
> RemoveSpellList
;
12298 // List of auras that CAN be trigger but may not exist in spell_proc_event
12299 // in most case need for drop charges
12300 // in some types of aura need do additional check
12301 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
12302 bool InitTriggerAuraData()
12304 for (int i
=0;i
<TOTAL_AURAS
;++i
)
12306 isTriggerAura
[i
]=false;
12307 isNonTriggerAura
[i
] = false;
12309 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
12310 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
12311 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
12312 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
12313 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
12314 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
12315 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
12316 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
12317 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
12318 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
12319 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
12320 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
12321 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
] = true;
12322 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
12323 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
12324 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
12325 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
12326 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
12327 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
12328 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
12329 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
12330 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
12331 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
12332 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
12333 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
12334 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
12335 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
12336 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
] = true;
12337 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_FROM_CASTER
] = true;
12338 isTriggerAura
[SPELL_AURA_MOD_SPELL_CRIT_CHANCE
] = true;
12339 isTriggerAura
[SPELL_AURA_MAELSTROM_WEAPON
] = true;
12341 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
12342 isNonTriggerAura
[SPELL_AURA_REDUCE_PUSHBACK
]=true;
12347 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
12349 uint32 procEx
= PROC_EX_NONE
;
12350 // Check victim state
12351 if (missCondition
!=SPELL_MISS_NONE
)
12352 switch (missCondition
)
12354 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
12355 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
12356 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
12357 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
12358 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
12359 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
12360 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
12361 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
12362 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
12363 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
12364 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
12371 if (damageInfo
->blocked
)
12372 procEx
|=PROC_EX_BLOCK
;
12374 if (damageInfo
->absorb
)
12375 procEx
|=PROC_EX_ABSORB
;
12377 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
12378 procEx
|=PROC_EX_CRITICAL_HIT
;
12380 procEx
|=PROC_EX_NORMAL_HIT
;
12385 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
12387 // For melee/ranged based attack need update skills and set some Aura states
12388 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
12390 // Update skills here for players
12391 if (GetTypeId() == TYPEID_PLAYER
)
12393 // On melee based hit/miss/resist need update skill (for victim and attacker)
12394 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
12396 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
12397 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, isVictim
);
12399 // Update defence if player is victim and parry/dodge/block
12400 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
12401 ((Player
*)this)->UpdateDefense();
12403 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
12404 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
12409 // if victim and dodge attack
12410 if (procExtra
&PROC_EX_DODGE
)
12412 //Update AURA_STATE on dodge
12413 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
12415 ModifyAuraState(AURA_STATE_DEFENSE
, true);
12416 StartReactiveTimer( REACTIVE_DEFENSE
);
12419 // if victim and parry attack
12420 if (procExtra
& PROC_EX_PARRY
)
12422 // For Hunters only Counterattack (skip Mongoose bite)
12423 if (getClass() == CLASS_HUNTER
)
12425 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
12426 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
12430 ModifyAuraState(AURA_STATE_DEFENSE
, true);
12431 StartReactiveTimer( REACTIVE_DEFENSE
);
12434 // if and victim block attack
12435 if (procExtra
& PROC_EX_BLOCK
)
12437 ModifyAuraState(AURA_STATE_DEFENSE
,true);
12438 StartReactiveTimer( REACTIVE_DEFENSE
);
12441 else //For attacker
12443 // Overpower on victim dodge
12444 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
12446 ((Player
*)this)->AddComboPoints(pTarget
, 1);
12447 StartReactiveTimer( REACTIVE_OVERPOWER
);
12453 RemoveSpellList removedSpells
;
12454 ProcTriggeredList procTriggered
;
12455 // Fill procTriggered list
12456 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
12458 // skip deleted auras (possible at recursive triggered call
12459 if(itr
->second
->IsDeleted())
12462 SpellProcEventEntry
const* spellProcEvent
= NULL
;
12463 if(!IsTriggeredAtSpellProcEvent(pTarget
, itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
12466 itr
->second
->SetInUse(true); // prevent aura deletion
12467 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
12471 if (procTriggered
.empty())
12474 // Handle effects proceed this time
12475 for(ProcTriggeredList::const_iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
12477 // Some auras can be deleted in function called in this loop (except first, ofc)
12478 Aura
*triggeredByAura
= i
->triggeredByAura
;
12479 if(triggeredByAura
->IsDeleted())
12482 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
12483 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
12484 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
12485 bool useCharges
= triggeredByAura
->GetAuraCharges() > 0;
12486 // For players set spell cooldown if need
12487 uint32 cooldown
= 0;
12488 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
12489 cooldown
= spellProcEvent
->cooldown
;
12491 switch(auraModifier
->m_auraname
)
12493 case SPELL_AURA_PROC_TRIGGER_SPELL
:
12495 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());
12496 // Don`t drop charge or add cooldown for not started trigger
12497 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12499 triggeredByAura
->SetInUse(false);
12504 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
12506 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());
12507 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, SpellSchoolMask(spellInfo
->SchoolMask
));
12508 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
12509 damageInfo
.target
->CalculateAbsorbResistBlock(this, &damageInfo
, spellInfo
);
12510 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
12511 SendSpellNonMeleeDamageLog(&damageInfo
);
12512 DealSpellDamage(&damageInfo
, true);
12515 case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
:
12516 case SPELL_AURA_MANA_SHIELD
:
12517 case SPELL_AURA_OBS_MOD_MANA
:
12518 case SPELL_AURA_ADD_PCT_MODIFIER
:
12519 case SPELL_AURA_DUMMY
:
12521 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());
12522 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12524 triggeredByAura
->SetInUse(false);
12529 case SPELL_AURA_MOD_HASTE
:
12531 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());
12532 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12534 triggeredByAura
->SetInUse(false);
12539 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
12541 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());
12542 if (!HandleOverrideClassScriptAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, cooldown
))
12544 triggeredByAura
->SetInUse(false);
12549 case SPELL_AURA_PRAYER_OF_MENDING
:
12551 DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST
, "ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
12552 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
12554 HandleMendingAuraProc(triggeredByAura
);
12557 case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
:
12559 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());
12561 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12563 triggeredByAura
->SetInUse(false);
12568 case SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
:
12569 // Skip melee hits or instant cast spells
12570 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
12572 triggeredByAura
->SetInUse(false);
12576 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
12577 // Skip Melee hits and spells ws wrong school
12578 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
12580 triggeredByAura
->SetInUse(false);
12584 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
12585 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
12586 // Skip melee hits and spells ws wrong school or zero cost
12587 if (procSpell
== NULL
||
12588 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
12589 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
12591 triggeredByAura
->SetInUse(false);
12595 case SPELL_AURA_MECHANIC_IMMUNITY
:
12596 // Compare mechanic
12597 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12599 triggeredByAura
->SetInUse(false);
12603 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
12604 // Compare mechanic
12605 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12607 triggeredByAura
->SetInUse(false);
12611 case SPELL_AURA_MOD_DAMAGE_FROM_CASTER
:
12613 if (triggeredByAura
->GetCasterGUID() != pTarget
->GetGUID())
12615 triggeredByAura
->SetInUse(false);
12619 case SPELL_AURA_MOD_SPELL_CRIT_CHANCE
:
12622 triggeredByAura
->SetInUse(false);
12625 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());
12626 if (!HandleSpellCritChanceAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12628 triggeredByAura
->SetInUse(false);
12632 case SPELL_AURA_MAELSTROM_WEAPON
:
12633 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());
12635 // remove all stack;
12636 RemoveSpellsCausingAura(SPELL_AURA_MAELSTROM_WEAPON
);
12637 triggeredByAura
->SetInUse(false); // this safe, aura locked
12638 continue; // avoid re-remove attempts
12640 // nothing do, just charges counter
12644 // Remove charge (aura can be removed by triggers)
12645 if(useCharges
&& !triggeredByAura
->IsDeleted())
12647 // If last charge dropped add spell to remove list
12648 if(triggeredByAura
->DropAuraCharge())
12649 removedSpells
.push_back(triggeredByAura
->GetId());
12652 triggeredByAura
->SetInUse(false);
12654 if (!removedSpells
.empty())
12656 // Sort spells and remove dublicates
12657 removedSpells
.sort();
12658 removedSpells
.unique();
12659 // Remove auras from removedAuras
12660 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();++i
)
12661 RemoveSingleSpellAurasFromStack(*i
);
12665 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
12667 return SPELL_SCHOOL_MASK_NORMAL
;
12670 Player
* Unit::GetSpellModOwner()
12672 if(GetTypeId()==TYPEID_PLAYER
)
12673 return (Player
*)this;
12674 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
12676 Unit
* owner
= GetOwner();
12677 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
12678 return (Player
*)owner
;
12683 ///----------Pet responses methods-----------------
12684 void Unit::SendPetCastFail(uint32 spellid
, SpellCastResult msg
)
12686 if(msg
== SPELL_CAST_OK
)
12689 Unit
*owner
= GetCharmerOrOwner();
12690 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12693 WorldPacket
data(SMSG_PET_CAST_FAILED
, 1 + 4 + 1);
12694 data
<< uint8(0); // cast count?
12695 data
<< uint32(spellid
);
12696 data
<< uint8(msg
);
12697 // uint32 for some reason
12698 // uint32 for some reason
12699 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12702 void Unit::SendPetActionFeedback (uint8 msg
)
12704 Unit
* owner
= GetOwner();
12705 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12708 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
12709 data
<< uint8(msg
);
12710 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12713 void Unit::SendPetTalk (uint32 pettalk
)
12715 Unit
* owner
= GetOwner();
12716 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12719 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8 + 4);
12720 data
<< uint64(GetGUID());
12721 data
<< uint32(pettalk
);
12722 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12725 void Unit::SendPetAIReaction(uint64 guid
)
12727 Unit
* owner
= GetOwner();
12728 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12731 WorldPacket
data(SMSG_AI_REACTION
, 8 + 4);
12732 data
<< uint64(guid
);
12733 data
<< uint32(AI_REACTION_HOSTILE
);
12734 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12737 ///----------End of Pet responses methods----------
12739 void Unit::StopMoving()
12741 clearUnitState(UNIT_STAT_MOVING
);
12743 // send explicit stop packet
12744 // player expected for correct work SPLINEFLAG_WALKMODE
12745 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_NORMAL
, GetTypeId() == TYPEID_PLAYER
? SPLINEFLAG_WALKMODE
: SPLINEFLAG_NONE
, 0);
12747 // update position and orientation for near players
12749 BuildHeartBeatMsg(&data
);
12750 SendMessageToSet(&data
, false);
12753 void Unit::SetFeared(bool apply
, uint64
const& casterGUID
, uint32 spellID
, uint32 time
)
12757 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
12760 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12762 GetMotionMaster()->MovementExpired(false);
12763 CastStop(GetGUID() == casterGUID
? spellID
: 0);
12765 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
12767 GetMotionMaster()->MoveFleeing(caster
, time
); // caster==NULL processed in MoveFleeing
12771 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12773 GetMotionMaster()->MovementExpired(false);
12775 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
12777 // restore appropriate movement generator
12779 GetMotionMaster()->MoveChase(getVictim());
12781 GetMotionMaster()->Initialize();
12783 // attack caster if can
12784 Unit
* caster
= Unit::GetUnit(*this, casterGUID
);
12785 if(caster
&& ((Creature
*)this)->AI())
12786 ((Creature
*)this)->AI()->AttackedBy(caster
);
12790 if (GetTypeId() == TYPEID_PLAYER
)
12791 ((Player
*)this)->SetClientControl(this, !apply
);
12794 void Unit::SetConfused(bool apply
, uint64
const& casterGUID
, uint32 spellID
)
12798 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12800 CastStop(GetGUID()==casterGUID
? spellID
: 0);
12802 GetMotionMaster()->MoveConfused();
12806 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12808 GetMotionMaster()->MovementExpired(false);
12810 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12812 // restore appropriate movement generator
12814 GetMotionMaster()->MoveChase(getVictim());
12816 GetMotionMaster()->Initialize();
12820 if(GetTypeId() == TYPEID_PLAYER
)
12821 ((Player
*)this)->SetClientControl(this, !apply
);
12824 void Unit::SetFeignDeath(bool apply
, uint64
const& casterGUID
, uint32
/*spellID*/)
12829 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12832 SendMessageToSet(&data,true);
12835 if(GetTypeId() != TYPEID_PLAYER
)
12838 ((Player
*)this)->m_movementInfo
.SetMovementFlags(MOVEFLAG_NONE
);
12840 // blizz like 2.0.x
12841 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12842 // blizz like 2.0.x
12843 SetFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12844 // blizz like 2.0.x
12845 SetFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12847 addUnitState(UNIT_STAT_DIED
);
12849 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION
);
12851 // prevent interrupt message
12852 if (casterGUID
== GetGUID())
12853 FinishSpell(CURRENT_GENERIC_SPELL
,false);
12854 InterruptNonMeleeSpells(true);
12855 getHostileRefManager().deleteReferences();
12860 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12863 SendMessageToSet(&data,true);
12865 // blizz like 2.0.x
12866 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12867 // blizz like 2.0.x
12868 RemoveFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12869 // blizz like 2.0.x
12870 RemoveFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12872 clearUnitState(UNIT_STAT_DIED
);
12874 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12876 // restore appropriate movement generator
12878 GetMotionMaster()->MoveChase(getVictim());
12880 GetMotionMaster()->Initialize();
12886 bool Unit::IsSitState() const
12888 uint8 s
= getStandState();
12890 s
== UNIT_STAND_STATE_SIT_CHAIR
|| s
== UNIT_STAND_STATE_SIT_LOW_CHAIR
||
12891 s
== UNIT_STAND_STATE_SIT_MEDIUM_CHAIR
|| s
== UNIT_STAND_STATE_SIT_HIGH_CHAIR
||
12892 s
== UNIT_STAND_STATE_SIT
;
12895 bool Unit::IsStandState() const
12897 uint8 s
= getStandState();
12898 return !IsSitState() && s
!= UNIT_STAND_STATE_SLEEP
&& s
!= UNIT_STAND_STATE_KNEEL
;
12901 void Unit::SetStandState(uint8 state
)
12903 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
12905 if (IsStandState())
12906 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
12908 if(GetTypeId()==TYPEID_PLAYER
)
12910 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
12911 data
<< (uint8
)state
;
12912 ((Player
*)this)->GetSession()->SendPacket(&data
);
12916 bool Unit::IsPolymorphed() const
12918 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
12921 void Unit::SetDisplayId(uint32 modelId
)
12923 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
12925 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
12927 Pet
*pet
= ((Pet
*)this);
12928 if(!pet
->isControlled())
12930 Unit
*owner
= GetOwner();
12931 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12932 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
12936 void Unit::ClearComboPointHolders()
12938 while(!m_ComboPointHolders
.empty())
12940 uint32 lowguid
= *m_ComboPointHolders
.begin();
12942 Player
* plr
= sObjectMgr
.GetPlayer(ObjectGuid(HIGHGUID_PLAYER
, lowguid
));
12943 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
12944 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
12946 m_ComboPointHolders
.erase(lowguid
); // or remove manually
12950 void Unit::ClearAllReactives()
12952 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
12953 m_reactiveTimer
[i
] = 0;
12955 if (HasAuraState( AURA_STATE_DEFENSE
))
12956 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12957 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
12958 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12959 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12960 ((Player
*)this)->ClearComboPoints();
12963 void Unit::UpdateReactives( uint32 p_time
)
12965 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
12967 ReactiveType reactive
= ReactiveType(i
);
12969 if(!m_reactiveTimer
[reactive
])
12972 if ( m_reactiveTimer
[reactive
] <= p_time
)
12974 m_reactiveTimer
[reactive
] = 0;
12976 switch ( reactive
)
12978 case REACTIVE_DEFENSE
:
12979 if (HasAuraState(AURA_STATE_DEFENSE
))
12980 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12982 case REACTIVE_HUNTER_PARRY
:
12983 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
12984 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12986 case REACTIVE_OVERPOWER
:
12987 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12988 ((Player
*)this)->ClearComboPoints();
12996 m_reactiveTimer
[reactive
] -= p_time
;
13001 Unit
* Unit::SelectRandomUnfriendlyTarget(Unit
* except
/*= NULL*/, float radius
/*= ATTACK_DISTANCE*/) const
13003 std::list
<Unit
*> targets
;
13005 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, radius
);
13006 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
13007 Cell::VisitAllObjects(this, searcher
, radius
);
13009 // remove current target
13011 targets
.remove(except
);
13013 // remove not LoS targets
13014 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
13016 if(!IsWithinLOSInMap(*tIter
))
13018 std::list
<Unit
*>::iterator tIter2
= tIter
;
13020 targets
.erase(tIter2
);
13026 // no appropriate targets
13027 if(targets
.empty())
13031 uint32 rIdx
= urand(0,targets
.size()-1);
13032 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
13033 for(uint32 i
= 0; i
< rIdx
; ++i
)
13039 Unit
* Unit::SelectRandomFriendlyTarget(Unit
* except
/*= NULL*/, float radius
/*= ATTACK_DISTANCE*/) const
13041 std::list
<Unit
*> targets
;
13043 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(this, radius
);
13044 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
13046 Cell::VisitAllObjects(this, searcher
, radius
);
13047 // remove current target
13049 targets
.remove(except
);
13051 // remove not LoS targets
13052 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
13054 if(!IsWithinLOSInMap(*tIter
))
13056 std::list
<Unit
*>::iterator tIter2
= tIter
;
13058 targets
.erase(tIter2
);
13064 // no appropriate targets
13065 if(targets
.empty())
13069 uint32 rIdx
= urand(0,targets
.size()-1);
13070 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
13071 for(uint32 i
= 0; i
< rIdx
; ++i
)
13077 bool Unit::hasNegativeAuraWithInterruptFlag(uint32 flag
)
13079 for (AuraMap::const_iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); ++iter
)
13081 if (!iter
->second
->IsPositive() && iter
->second
->GetSpellProto()->AuraInterruptFlags
& flag
)
13087 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
13091 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
13092 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
13096 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
13097 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
13101 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
13104 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
13106 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
13109 void Unit::UpdateAuraForGroup(uint8 slot
)
13111 if(GetTypeId() == TYPEID_PLAYER
)
13113 Player
* player
= (Player
*)this;
13114 if(player
->GetGroup())
13116 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
13117 player
->SetAuraUpdateMask(slot
);
13120 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
13122 Pet
*pet
= ((Pet
*)this);
13123 if(pet
->isControlled())
13125 Unit
*owner
= GetOwner();
13126 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
13128 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
13129 pet
->SetAuraUpdateMask(slot
);
13135 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
13137 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
13138 return float(GetAttackTime(attType
))/1000.0f
;
13140 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
, true, false);
13142 return 2.4f
; // fist attack
13144 switch (Weapon
->GetProto()->InventoryType
)
13146 case INVTYPE_2HWEAPON
:
13148 case INVTYPE_RANGED
:
13149 case INVTYPE_RANGEDRIGHT
:
13150 case INVTYPE_THROWN
:
13152 case INVTYPE_WEAPON
:
13153 case INVTYPE_WEAPONMAINHAND
:
13154 case INVTYPE_WEAPONOFFHAND
:
13156 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7f
: 2.4f
;
13160 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
13162 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
13163 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
13164 if ((*itr
)->GetId() == spell_id
)
13170 void Unit::SetContestedPvP(Player
*attackedPlayer
)
13172 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
13174 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
13177 player
->SetContestedPvPTimer(30000);
13178 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
13180 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
13181 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
13182 // call MoveInLineOfSight for nearby contested guards
13183 SetVisibility(GetVisibility());
13185 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
13187 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
13188 // call MoveInLineOfSight for nearby contested guards
13189 SetVisibility(GetVisibility());
13193 void Unit::AddPetAura(PetAura
const* petSpell
)
13195 m_petAuras
.insert(petSpell
);
13196 if(Pet
* pet
= GetPet())
13197 pet
->CastPetAura(petSpell
);
13200 void Unit::RemovePetAura(PetAura
const* petSpell
)
13202 m_petAuras
.erase(petSpell
);
13203 if(Pet
* pet
= GetPet())
13204 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
13207 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
13209 Pet
* pet
= new Pet(HUNTER_PET
);
13211 if(!pet
->CreateBaseAtCreature(creatureTarget
))
13217 pet
->SetOwnerGUID(GetGUID());
13218 pet
->SetCreatorGUID(GetGUID());
13219 pet
->setFaction(getFaction());
13220 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
13222 if(GetTypeId()==TYPEID_PLAYER
)
13223 pet
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
13229 pet
->SetFFAPvP(true);
13231 uint32 level
= (creatureTarget
->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget
->getLevel();
13233 if(!pet
->InitStatsForLevel(level
))
13235 sLog
.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
13240 pet
->GetCharmInfo()->SetPetNumber(sObjectMgr
.GeneratePetNumber(), true);
13241 // this enables pet details window (Shift+P)
13242 pet
->AIM_Initialize();
13243 pet
->InitPetCreateSpells();
13244 pet
->InitLevelupSpellsForLevel();
13245 pet
->InitTalentForLevel();
13246 pet
->SetHealth(pet
->GetMaxHealth());
13251 bool Unit::IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
13253 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
13255 // Get proc Event Entry
13256 spellProcEvent
= sSpellMgr
.GetSpellProcEvent(spellProto
->Id
);
13258 // Aura info stored here
13259 Modifier
*mod
= aura
->GetModifier();
13261 if (isNonTriggerAura
[mod
->m_auraname
])
13263 // If not trigger by default and spellProcEvent==NULL - skip
13264 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
13267 // Get EventProcFlag
13268 uint32 EventProcFlag
;
13269 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
13270 EventProcFlag
= spellProcEvent
->procFlags
;
13272 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
13273 // Continue if no trigger exist
13274 if (!EventProcFlag
)
13277 // Check spellProcEvent data requirements
13278 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
13281 // In most cases req get honor or XP from kill
13282 if (EventProcFlag
& PROC_FLAG_KILL
&& GetTypeId() == TYPEID_PLAYER
)
13284 bool allow
= ((Player
*)this)->isHonorOrXPTarget(pVictim
);
13285 // Shadow Word: Death - can trigger from every kill
13286 if (aura
->GetId() == 32409)
13291 // Aura added by spell can`t trogger from self (prevent drop charges/do triggers)
13292 // But except periodic triggers (can triggered from self)
13293 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
& PROC_FLAG_ON_TAKE_PERIODIC
))
13296 // Check if current equipment allows aura to proc
13297 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
13299 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
13302 if(attType
== BASE_ATTACK
)
13303 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
13304 else if (attType
== OFF_ATTACK
)
13305 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
13307 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
13309 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
13312 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
13314 // Check if player is wearing shield
13315 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
13316 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
13320 // Get chance from spell
13321 float chance
= (float)spellProto
->procChance
;
13322 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
13323 if(spellProcEvent
&& spellProcEvent
->customChance
)
13324 chance
= spellProcEvent
->customChance
;
13325 // If PPM exist calculate chance from PPM
13326 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
13328 uint32 WeaponSpeed
= GetAttackTime(attType
);
13329 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
13331 // Apply chance modifer aura
13332 if(Player
* modOwner
= GetSpellModOwner())
13334 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
13335 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_FREQUENCY_OF_SUCCESS
,chance
);
13338 return roll_chance_f(chance
);
13341 bool Unit::HandleMendingAuraProc( Aura
* triggeredByAura
)
13343 // aura can be deleted at casts
13344 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
13345 SpellEffectIndex effIdx
= triggeredByAura
->GetEffIndex();
13346 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
13347 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
13350 int32 jumps
= triggeredByAura
->GetAuraCharges()-1;
13352 // current aura expire
13353 triggeredByAura
->SetAuraCharges(1); // will removed at next charges decrease
13355 // next target selection
13356 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
13359 if (spellProto
->EffectRadiusIndex
[effIdx
])
13360 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
13362 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
13364 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
13366 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
13368 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
13370 // aura will applied from caster, but spell casted from current aura holder
13371 SpellModifier
*mod
= new SpellModifier(SPELLMOD_CHARGES
,SPELLMOD_FLAT
,jumps
-5,spellProto
->Id
,spellProto
->SpellFamilyFlags
,spellProto
->SpellFamilyFlags2
);
13373 // remove before apply next (locked against deleted)
13374 triggeredByAura
->SetInUse(true);
13375 RemoveAurasByCasterSpell(spellProto
->Id
,caster
->GetGUID());
13377 caster
->AddSpellMod(mod
, true);
13378 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
13379 caster
->AddSpellMod(mod
, false);
13380 triggeredByAura
->SetInUse(false);
13386 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
13390 void Unit::RemoveAurasAtMechanicImmunity(uint32 mechMask
, uint32 exceptSpellId
, bool non_positive
/*= false*/)
13392 Unit::AuraMap
& auras
= GetAuras();
13393 for(Unit::AuraMap::iterator iter
= auras
.begin(); iter
!= auras
.end();)
13395 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
13396 if (spell
->Id
== exceptSpellId
)
13398 else if (non_positive
&& iter
->second
->IsPositive())
13400 else if (spell
->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
)
13402 else if (GetSpellMechanicMask(spell
, iter
->second
->GetEffIndex()) & mechMask
)
13404 RemoveAurasDueToSpell(spell
->Id
);
13408 iter
= auras
.begin();
13415 void Unit::SetPhaseMask(uint32 newPhaseMask
, bool update
)
13417 if(newPhaseMask
==GetPhaseMask())
13421 RemoveNotOwnSingleTargetAuras(newPhaseMask
); // we can lost access to caster or target
13423 WorldObject::SetPhaseMask(newPhaseMask
,update
);
13426 if(Pet
* pet
= GetPet())
13427 pet
->SetPhaseMask(newPhaseMask
,true);
13430 void Unit::NearTeleportTo( float x
, float y
, float z
, float orientation
, bool casting
/*= false*/ )
13432 if(GetTypeId() == TYPEID_PLAYER
)
13433 ((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));
13436 Creature
* c
= (Creature
*)this;
13437 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13438 if (!c
->GetMotionMaster()->empty())
13439 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13440 movgen
->Interrupt(*c
);
13442 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, orientation
);
13445 BuildHeartBeatMsg(&data
);
13446 SendMessageToSet(&data
, false);
13447 // finished relocation, movegen can different from top before creature relocation,
13448 // but apply Reset expected to be safe in any case
13449 if (!c
->GetMotionMaster()->empty())
13450 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13455 void Unit::MonsterMove(float x
, float y
, float z
, uint32 transitTime
)
13457 SplineFlags flags
= GetTypeId() == TYPEID_PLAYER
? SPLINEFLAG_WALKMODE
: ((Creature
*)this)->GetSplineFlags();
13458 SendMonsterMove(x
, y
, z
, SPLINETYPE_NORMAL
, flags
, transitTime
);
13460 if (GetTypeId() != TYPEID_PLAYER
)
13462 Creature
* c
= (Creature
*)this;
13463 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13464 if (!c
->GetMotionMaster()->empty())
13465 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13466 movgen
->Interrupt(*c
);
13468 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, 0.0f
);
13470 // finished relocation, movegen can different from top before creature relocation,
13471 // but apply Reset expected to be safe in any case
13472 if (!c
->GetMotionMaster()->empty())
13473 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13478 void Unit::MonsterMoveWithSpeed(float x
, float y
, float z
, uint32 transitTime
)
13480 SendMonsterMoveWithSpeed(x
, y
, z
, transitTime
);
13482 if (GetTypeId() != TYPEID_PLAYER
)
13484 Creature
* c
= (Creature
*)this;
13485 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13486 if (!c
->GetMotionMaster()->empty())
13487 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13488 movgen
->Interrupt(*c
);
13490 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, 0.0f
);
13492 // finished relocation, movegen can different from top before creature relocation,
13493 // but apply Reset expected to be safe in any case
13494 if (!c
->GetMotionMaster()->empty())
13495 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13500 struct SetPvPHelper
13502 explicit SetPvPHelper(bool _state
) : state(_state
) {}
13503 void operator()(Unit
* unit
) const { unit
->SetPvP(state
); }
13507 void Unit::SetPvP( bool state
)
13510 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13512 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13514 CallForAllControlledUnits(SetPvPHelper(state
),true,true,true);
13517 struct SetFFAPvPHelper
13519 explicit SetFFAPvPHelper(bool _state
) : state(_state
) {}
13520 void operator()(Unit
* unit
) const { unit
->SetFFAPvP(state
); }
13524 void Unit::SetFFAPvP( bool state
)
13527 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13529 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13531 CallForAllControlledUnits(SetFFAPvPHelper(state
),true,true,true);
13534 void Unit::KnockBackFrom(Unit
* target
, float horizontalSpeed
, float verticalSpeed
)
13536 float angle
= this == target
? GetOrientation() + M_PI_F
: target
->GetAngle(this);
13537 float vsin
= sin(angle
);
13538 float vcos
= cos(angle
);
13540 // Effect propertly implemented only for players
13541 if(GetTypeId()==TYPEID_PLAYER
)
13543 WorldPacket
data(SMSG_MOVE_KNOCK_BACK
, 8+4+4+4+4+4);
13544 data
<< GetPackGUID();
13545 data
<< uint32(0); // Sequence
13546 data
<< float(vcos
); // x direction
13547 data
<< float(vsin
); // y direction
13548 data
<< float(horizontalSpeed
); // Horizontal speed
13549 data
<< float(-verticalSpeed
); // Z Movement speed (vertical)
13550 ((Player
*)this)->GetSession()->SendPacket(&data
);
13554 float dis
= horizontalSpeed
;
13557 GetPosition(ox
, oy
, oz
);
13559 float fx
= ox
+ dis
* vcos
;
13560 float fy
= oy
+ dis
* vsin
;
13563 float fx2
, fy2
, fz2
; // getObjectHitPos overwrite last args in any result case
13564 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), ox
,oy
,oz
+0.5f
, fx
,fy
,oz
+0.5f
,fx2
,fy2
,fz2
, -0.5f
))
13571 UpdateGroundPositionZ(fx
, fy
, fz
);
13573 //FIXME: this mostly hack, must exist some packet for proper creature move at client side
13574 // with CreatureRelocation at server side
13575 NearTeleportTo(fx
, fy
, fz
, GetOrientation(), this == target
);
13579 float Unit::GetCombatRatingReduction(CombatRating cr
) const
13581 if (GetTypeId() == TYPEID_PLAYER
)
13582 return ((Player
const*)this)->GetRatingBonusValue(cr
);
13583 else if (((Creature
const*)this)->isPet())
13585 // Player's pet have 0.4 resilience from owner
13586 if (Unit
* owner
= GetOwner())
13587 if(owner
->GetTypeId() == TYPEID_PLAYER
)
13588 return ((Player
*)owner
)->GetRatingBonusValue(cr
) * 0.4f
;
13594 uint32
Unit::GetCombatRatingDamageReduction(CombatRating cr
, float rate
, float cap
, uint32 damage
) const
13596 float percent
= GetCombatRatingReduction(cr
) * rate
;
13599 return uint32 (percent
* damage
/ 100.0f
);
13602 void Unit::SendThreatUpdate()
13604 ThreatList
const& tlist
= getThreatManager().getThreatList();
13605 if (uint32 count
= tlist
.size())
13607 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "WORLD: Send SMSG_THREAT_UPDATE Message");
13608 WorldPacket
data(SMSG_THREAT_UPDATE
, 8 + count
* 8);
13609 data
<< GetPackGUID();
13610 data
<< uint32(count
);
13611 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13613 data
.appendPackGUID((*itr
)->getUnitGuid());
13614 data
<< uint32((*itr
)->getThreat());
13616 SendMessageToSet(&data
, false);
13620 void Unit::SendHighestThreatUpdate(HostileReference
* pHostilReference
)
13622 ThreatList
const& tlist
= getThreatManager().getThreatList();
13623 if (uint32 count
= tlist
.size())
13625 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message");
13626 WorldPacket
data(SMSG_HIGHEST_THREAT_UPDATE
, 8 + 8 + count
* 8);
13627 data
<< GetPackGUID();
13628 data
.appendPackGUID(pHostilReference
->getUnitGuid());
13629 data
<< uint32(count
);
13630 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13632 data
.appendPackGUID((*itr
)->getUnitGuid());
13633 data
<< uint32((*itr
)->getThreat());
13635 SendMessageToSet(&data
, false);
13639 void Unit::SendThreatClear()
13641 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "WORLD: Send SMSG_THREAT_CLEAR Message");
13642 WorldPacket
data(SMSG_THREAT_CLEAR
, 8);
13643 data
<< GetPackGUID();
13644 SendMessageToSet(&data
, false);
13647 void Unit::SendThreatRemove(HostileReference
* pHostileReference
)
13649 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT
, "WORLD: Send SMSG_THREAT_REMOVE Message");
13650 WorldPacket
data(SMSG_THREAT_REMOVE
, 8 + 8);
13651 data
<< GetPackGUID();
13652 data
.appendPackGUID(pHostileReference
->getUnitGuid());
13653 SendMessageToSet(&data
, false);
13656 struct StopAttackFactionHelper
13658 explicit StopAttackFactionHelper(uint32 _faction_id
) : faction_id(_faction_id
) {}
13659 void operator()(Unit
* unit
) const { unit
->StopAttackFaction(faction_id
); }
13663 void Unit::StopAttackFaction(uint32 faction_id
)
13665 if (Unit
* victim
= getVictim())
13667 if (victim
->getFactionTemplateEntry()->faction
==faction_id
)
13670 if (IsNonMeleeSpellCasted(false))
13671 InterruptNonMeleeSpells(false);
13673 // melee and ranged forced attack cancel
13674 if (GetTypeId() == TYPEID_PLAYER
)
13675 ((Player
*)this)->SendAttackSwingCancelAttack();
13679 AttackerSet
const& attackers
= getAttackers();
13680 for(AttackerSet::const_iterator itr
= attackers
.begin(); itr
!= attackers
.end();)
13682 if ((*itr
)->getFactionTemplateEntry()->faction
==faction_id
)
13684 (*itr
)->AttackStop();
13685 itr
= attackers
.begin();
13691 getHostileRefManager().deleteReferencesForFaction(faction_id
);
13693 CallForAllControlledUnits(StopAttackFactionHelper(faction_id
),false,true,true);
13696 void Unit::CleanupDeletedAuras()
13698 // really delete auras "deleted" while processing its ApplyModify code
13699 for(AuraList::const_iterator itr
= m_deletedAuras
.begin(); itr
!= m_deletedAuras
.end(); ++itr
)
13701 m_deletedAuras
.clear();
13704 bool Unit::CheckAndIncreaseCastCounter()
13706 uint32 maxCasts
= sWorld
.getConfig(CONFIG_UINT32_MAX_SPELL_CASTS_IN_CHAIN
);
13708 if (maxCasts
&& m_castCounter
>= maxCasts
)