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 CreatureInfo
const* cInfo
= ((Creature
*)pVictim
)->GetCreatureInfo();
570 if(cInfo
&& cInfo
->lootid
)
571 pVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
573 // some critters required for quests (need normal entry instead possible heroic in any cases)
574 if(GetTypeId() == TYPEID_PLAYER
)
575 if(CreatureInfo
const* normalInfo
= ObjectMgr::GetCreatureTemplate(pVictim
->GetEntry()))
576 ((Player
*)this)->KilledMonster(normalInfo
,pVictim
->GetObjectGuid());
581 DEBUG_LOG("DealDamageStart");
583 uint32 health
= pVictim
->GetHealth();
584 DETAIL_LOG("deal dmg:%d to health:%d ",damage
,health
);
586 // duel ends when player has 1 or less hp
587 bool duel_hasEnded
= false;
588 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->duel
&& damage
>= (health
-1))
590 // prevent kill only if killed in duel and killed by opponent or opponent controlled creature
591 if(((Player
*)pVictim
)->duel
->opponent
==this || ((Player
*)pVictim
)->duel
->opponent
->GetGUID() == GetOwnerGUID())
594 duel_hasEnded
= true;
597 if(pVictim
!= this && damagetype
!= DOT
)
599 SetInCombatWith(pVictim
);
600 pVictim
->SetInCombatWith(this);
602 if(Player
* attackedPlayer
= pVictim
->GetCharmerOrOwnerPlayerOrPlayerItself())
603 SetContestedPvP(attackedPlayer
);
606 // Rage from Damage made (only from direct weapon damage)
607 if( cleanDamage
&& damagetype
==DIRECT_DAMAGE
&& this != pVictim
&& GetTypeId() == TYPEID_PLAYER
&& (getPowerType() == POWER_RAGE
))
609 uint32 weaponSpeedHitFactor
;
611 switch(cleanDamage
->attackType
)
615 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
616 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 7);
618 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
620 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
626 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
627 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
629 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 1.75f
);
631 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
640 if (GetTypeId() == TYPEID_PLAYER
&& this != pVictim
)
642 Player
*killer
= ((Player
*)this);
644 // in bg, count dmg if victim is also a player
645 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
647 if (BattleGround
*bg
= killer
->GetBattleGround())
649 // FIXME: kept by compatibility. don't know in BG if the restriction apply.
650 bg
->UpdatePlayerScore(killer
, SCORE_DAMAGE_DONE
, damage
);
654 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DAMAGE_DONE
, damage
, 0, pVictim
);
655 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_DEALT
, damage
);
658 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
659 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_RECEIVED
, damage
);
661 if (pVictim
->GetTypeId() == TYPEID_UNIT
&& !((Creature
*)pVictim
)->isPet() && !((Creature
*)pVictim
)->hasLootRecipient())
662 ((Creature
*)pVictim
)->SetLootRecipient(this);
664 if (health
<= damage
)
666 DEBUG_LOG("DealDamage: victim just died");
668 // find player: owner of controlled `this` or `this` itself maybe
669 Player
*player
= GetCharmerOrOwnerPlayerOrPlayerItself();
671 // find owner of pVictim, used for creature cases, AI calls
672 Unit
* pOwner
= pVictim
->GetCharmerOrOwner();
674 if(pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->GetLootRecipient())
675 player
= ((Creature
*)pVictim
)->GetLootRecipient();
677 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
679 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, health
);
681 player
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_SPECIAL_PVP_KILL
,1,0,pVictim
);
684 // Reward player, his pets, and group/raid members
685 // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop)
686 if(player
&& player
!=pVictim
)
688 player
->RewardPlayerAndGroupAtKill(pVictim
);
689 player
->ProcDamageAndSpell(pVictim
, PROC_FLAG_KILL
, PROC_FLAG_KILLED
, PROC_EX_NONE
, 0);
691 WorldPacket
data(SMSG_PARTYKILLLOG
, (8+8)); //send event PARTY_KILL
692 data
<< uint64(player
->GetGUID()); //player with killing blow
693 data
<< uint64(pVictim
->GetGUID()); //victim
694 if (Group
*group
= player
->GetGroup())
695 group
->BroadcastPacket(&data
, group
->GetMemberGroup(player
->GetGUID()));
697 player
->SendDirectMessage(&data
);
700 DEBUG_LOG("DealDamageAttackStop");
703 pVictim
->CombatStop();
704 pVictim
->getHostileRefManager().deleteReferences();
706 bool damageFromSpiritOfRedemtionTalent
= spellProto
&& spellProto
->Id
== 27795;
708 // if talent known but not triggered (check priest class for speedup check)
709 Aura
* spiritOfRedemtionTalentReady
= NULL
;
710 if( !damageFromSpiritOfRedemtionTalent
&& // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION
711 pVictim
->GetTypeId()==TYPEID_PLAYER
&& pVictim
->getClass()==CLASS_PRIEST
)
713 AuraList
const& vDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
714 for(AuraList::const_iterator itr
= vDummyAuras
.begin(); itr
!= vDummyAuras
.end(); ++itr
)
716 if((*itr
)->GetSpellProto()->SpellIconID
==1654)
718 spiritOfRedemtionTalentReady
= *itr
;
724 DEBUG_LOG("SET JUST_DIED");
725 if(!spiritOfRedemtionTalentReady
)
726 pVictim
->setDeathState(JUST_DIED
);
728 DEBUG_LOG("DealDamageHealth1");
730 if(spiritOfRedemtionTalentReady
)
732 // save value before aura remove
733 uint32 ressSpellId
= pVictim
->GetUInt32Value(PLAYER_SELF_RES_SPELL
);
735 ressSpellId
= ((Player
*)pVictim
)->GetResurrectionSpellId();
737 //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers)
738 pVictim
->RemoveAllAurasOnDeath();
740 // restore for use at real death
741 pVictim
->SetUInt32Value(PLAYER_SELF_RES_SPELL
,ressSpellId
);
743 // FORM_SPIRITOFREDEMPTION and related auras
744 pVictim
->CastSpell(pVictim
,27827,true,NULL
,spiritOfRedemtionTalentReady
);
747 pVictim
->SetHealth(0);
749 // remember victim PvP death for corpse type and corpse reclaim delay
750 // at original death (not at SpiritOfRedemtionTalent timeout)
751 if( pVictim
->GetTypeId()==TYPEID_PLAYER
&& !damageFromSpiritOfRedemtionTalent
)
752 ((Player
*)pVictim
)->SetPvPDeath(player
!=NULL
);
754 // Call KilledUnit for creatures
755 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->AI())
756 ((Creature
*)this)->AI()->KilledUnit(pVictim
);
759 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
761 if (GetTypeId() == TYPEID_UNIT
)
762 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE
, GetEntry());
763 else if(GetTypeId() == TYPEID_PLAYER
&& pVictim
!= this)
764 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER
, 1, ((Player
*)this)->GetTeam());
767 // 10% durability loss on death
768 // clean InHateListOf
769 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
771 // only if not player and not controlled by player pet. And not at BG
772 if (durabilityLoss
&& !player
&& !((Player
*)pVictim
)->InBattleGround())
774 DEBUG_LOG("We are dead, loosing 10 percents durability");
775 ((Player
*)pVictim
)->DurabilityLossAll(0.10f
,false);
776 // durability lost message
777 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
778 ((Player
*)pVictim
)->GetSession()->SendPacket(&data
);
781 else // creature died
783 DEBUG_LOG("DealDamageNotPlayer");
784 Creature
*cVictim
= (Creature
*)pVictim
;
786 if(!cVictim
->isPet())
788 cVictim
->DeleteThreatList();
789 // only lootable if it has loot or can drop gold
790 if(cVictim
->GetCreatureInfo()->lootid
|| cVictim
->GetCreatureInfo()->maxgold
> 0)
791 cVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
793 cVictim
->lootForBody
= true; // needed for skinning
795 // Call creature just died function
797 cVictim
->AI()->JustDied(this);
799 if (cVictim
->isTemporarySummon())
801 TemporarySummon
* pSummon
= (TemporarySummon
*)cVictim
;
802 if (pSummon
->GetSummonerGuid().IsCreature())
803 if(Creature
* pSummoner
= cVictim
->GetMap()->GetCreature(pSummon
->GetSummonerGuid()))
805 pSummoner
->AI()->SummonedCreatureJustDied(cVictim
);
807 else if (pOwner
&& pOwner
->GetTypeId() == TYPEID_UNIT
)
809 if (((Creature
*)pOwner
)->AI())
810 ((Creature
*)pOwner
)->AI()->SummonedCreatureJustDied(cVictim
);
813 // Dungeon specific stuff, only applies to players killing creatures
814 if(cVictim
->GetInstanceId())
816 Map
*m
= cVictim
->GetMap();
817 Player
*creditedPlayer
= GetCharmerOrOwnerPlayerOrPlayerItself();
818 // TODO: do instance binding anyway if the charmer/owner is offline
820 if(m
->IsDungeon() && creditedPlayer
)
822 if (m
->IsRaidOrHeroicDungeon())
824 if(cVictim
->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
825 ((InstanceMap
*)m
)->PermBindAllPlayers(creditedPlayer
);
829 // the reset time is set but not added to the scheduler
830 // until the players leave the instance
831 time_t resettime
= cVictim
->GetRespawnTimeEx() + 2 * HOUR
;
832 if(InstanceSave
*save
= sInstanceSaveMgr
.GetInstanceSave(cVictim
->GetInstanceId()))
833 if(save
->GetResetTime() < resettime
) save
->SetResetTime(resettime
);
839 // last damage from non duel opponent or opponent controlled creature
842 ASSERT(pVictim
->GetTypeId()==TYPEID_PLAYER
);
843 Player
*he
= (Player
*)pVictim
;
847 he
->duel
->opponent
->CombatStopWithPets(true);
848 he
->CombatStopWithPets(true);
850 he
->DuelComplete(DUEL_INTERUPTED
);
853 // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill)
854 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->InBattleGround())
856 Player
*killed
= ((Player
*)pVictim
);
857 if(BattleGround
*bg
= killed
->GetBattleGround())
859 bg
->HandleKillPlayer(killed
, player
);
861 else if(pVictim
->GetTypeId() == TYPEID_UNIT
)
864 if (BattleGround
*bg
= player
->GetBattleGround())
865 bg
->HandleKillUnit((Creature
*)pVictim
, player
);
868 else // if (health <= damage)
870 DEBUG_LOG("DealDamageAlive");
872 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
873 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, damage
);
875 pVictim
->ModifyHealth(- (int32
)damage
);
877 if(damagetype
!= DOT
)
881 // if not have main target then attack state with target (including AI call)
882 //start melee attacks only after melee hit
883 Attack(pVictim
,(damagetype
== DIRECT_DAMAGE
));
886 // if damage pVictim call AI reaction
887 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
888 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
891 // polymorphed, hex and other negative transformed cases
892 uint32 morphSpell
= pVictim
->getTransForm();
893 if (morphSpell
&& !IsPositiveSpell(morphSpell
))
895 if (SpellEntry
const* morphEntry
= sSpellStore
.LookupEntry(morphSpell
))
897 if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_CONFUSE
))
898 pVictim
->RemoveAurasDueToSpell(morphSpell
);
899 else if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_PACIFY_SILENCE
))
900 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_PACIFY_SILENCE
, damage
);
904 if(damagetype
== DIRECT_DAMAGE
|| damagetype
== SPELL_DIRECT_DAMAGE
)
906 if (!spellProto
|| !(spellProto
->AuraInterruptFlags
&AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
))
907 pVictim
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
);
909 if (pVictim
->GetTypeId() != TYPEID_PLAYER
)
911 if(spellProto
&& IsDamageToThreatSpell(spellProto
))
912 pVictim
->AddThreat(this, float(damage
*2), (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
914 pVictim
->AddThreat(this, float(damage
), (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
916 else // victim is a player
918 // Rage from damage received
919 if(this != pVictim
&& pVictim
->getPowerType() == POWER_RAGE
)
921 uint32 rage_damage
= damage
+ (cleanDamage
? cleanDamage
->damage
: 0);
922 ((Player
*)pVictim
)->RewardRage(rage_damage
, 0, false);
925 // random durability for items (HIT TAKEN)
926 if (roll_chance_f(sWorld
.getConfig(CONFIG_FLOAT_RATE_DURABILITY_LOSS_DAMAGE
)))
928 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
929 ((Player
*)pVictim
)->DurabilityPointLossForEquipSlot(slot
);
933 if(GetTypeId()==TYPEID_PLAYER
)
935 // random durability for items (HIT DONE)
936 if (roll_chance_f(sWorld
.getConfig(CONFIG_FLOAT_RATE_DURABILITY_LOSS_DAMAGE
)))
938 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
939 ((Player
*)this)->DurabilityPointLossForEquipSlot(slot
);
943 // TODO: Store auras by interrupt flag to speed this up.
944 AuraMap
& vAuras
= pVictim
->GetAuras();
945 for (AuraMap::const_iterator i
= vAuras
.begin(), next
; i
!= vAuras
.end(); i
= next
)
947 const SpellEntry
*se
= i
->second
->GetSpellProto();
949 if (spellProto
&& spellProto
->Id
== se
->Id
) // Not drop auras added by self
951 if( se
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_DAMAGE
)
954 if (se
->procFlags
& (1<<3))
956 if (!roll_chance_i(se
->procChance
))
961 pVictim
->RemoveAurasDueToSpell(i
->second
->GetId());
962 // FIXME: this may cause the auras with proc chance to be rerolled several times
963 next
= vAuras
.begin();
968 if (damagetype
!= NODAMAGE
&& damage
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
970 if( damagetype
!= DOT
)
972 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
974 // skip channeled spell (processed differently below)
975 if (i
== CURRENT_CHANNELED_SPELL
)
978 if(Spell
* spell
= pVictim
->GetCurrentSpell(CurrentSpellTypes(i
)))
980 if(spell
->getState() == SPELL_STATE_PREPARING
)
982 if(spell
->m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_ABORT_ON_DMG
)
983 pVictim
->InterruptSpell(CurrentSpellTypes(i
));
991 if(Spell
* spell
= pVictim
->m_currentSpells
[CURRENT_CHANNELED_SPELL
])
993 if (spell
->getState() == SPELL_STATE_CASTING
)
995 uint32 channelInterruptFlags
= spell
->m_spellInfo
->ChannelInterruptFlags
;
996 if( channelInterruptFlags
& CHANNEL_FLAG_DELAY
)
998 if(pVictim
!=this) //don't shorten the duration of channeling if you damage yourself
999 spell
->DelayedChannel();
1001 else if( (channelInterruptFlags
& (CHANNEL_FLAG_DAMAGE
| CHANNEL_FLAG_DAMAGE2
)) )
1003 DETAIL_LOG("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
1004 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
1007 else if (spell
->getState() == SPELL_STATE_DELAYED
)
1008 // break channeled spell in delayed state on damage
1010 DETAIL_LOG("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
1011 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
1016 // last damage from duel opponent
1019 ASSERT(pVictim
->GetTypeId()==TYPEID_PLAYER
);
1020 Player
*he
= (Player
*)pVictim
;
1026 he
->duel
->opponent
->CombatStopWithPets(true);
1027 he
->CombatStopWithPets(true);
1029 he
->CastSpell(he
, 7267, true); // beg
1030 he
->DuelComplete(DUEL_WON
);
1034 DEBUG_LOG("DealDamageEnd returned %d damage", damage
);
1039 void Unit::CastStop(uint32 except_spellid
)
1041 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
1042 if (m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
!=except_spellid
)
1043 InterruptSpell(CurrentSpellTypes(i
),false);
1046 void Unit::CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1048 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1052 sLog
.outError("CastSpell: unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1056 CastSpell(Victim
, spellInfo
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1059 void Unit::CastSpell(Unit
* Victim
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1063 sLog
.outError("CastSpell: unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1068 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1070 if(originalCaster
.IsEmpty() && triggeredByAura
)
1071 originalCaster
= triggeredByAura
->GetCasterGUID();
1073 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1075 SpellCastTargets targets
;
1076 targets
.setUnitTarget( Victim
);
1077 spell
->m_CastItem
= castItem
;
1078 spell
->prepare(&targets
, triggeredByAura
);
1081 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1083 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1087 sLog
.outError("CastCustomSpell: unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1091 CastCustomSpell(Victim
, spellInfo
, bp0
, bp1
, bp2
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1094 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
)
1098 sLog
.outError("CastCustomSpell: unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1103 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1105 if(originalCaster
.IsEmpty() && triggeredByAura
)
1106 originalCaster
= triggeredByAura
->GetCasterGUID();
1108 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1111 spell
->m_currentBasePoints
[EFFECT_INDEX_0
] = *bp0
;
1114 spell
->m_currentBasePoints
[EFFECT_INDEX_1
] = *bp1
;
1117 spell
->m_currentBasePoints
[EFFECT_INDEX_2
] = *bp2
;
1119 SpellCastTargets targets
;
1120 targets
.setUnitTarget( Victim
);
1121 spell
->m_CastItem
= castItem
;
1122 spell
->prepare(&targets
, triggeredByAura
);
1125 // used for scripting
1126 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1128 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1132 sLog
.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1136 CastSpell(x
, y
, z
, spellInfo
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1139 // used for scripting
1140 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1144 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1149 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1151 if(originalCaster
.IsEmpty() && triggeredByAura
)
1152 originalCaster
= triggeredByAura
->GetCasterGUID();
1154 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1156 SpellCastTargets targets
;
1157 targets
.setDestination(x
, y
, z
);
1158 spell
->m_CastItem
= castItem
;
1159 spell
->prepare(&targets
, triggeredByAura
);
1162 // Obsolete func need remove, here only for comotability vs another patches
1163 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
)
1165 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
1166 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, spellInfo
->SchoolMask
);
1167 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
1168 damageInfo
.target
->CalculateAbsorbResistBlock(this, &damageInfo
, spellInfo
);
1169 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
1170 SendSpellNonMeleeDamageLog(&damageInfo
);
1171 DealSpellDamage(&damageInfo
, true);
1172 return damageInfo
.damage
;
1175 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
1177 SpellSchoolMask damageSchoolMask
= SpellSchoolMask(damageInfo
->schoolMask
);
1178 Unit
*pVictim
= damageInfo
->target
;
1183 if(!this || !pVictim
)
1185 if(!this->isAlive() || !pVictim
->isAlive())
1188 // Check spell crit chance
1189 bool crit
= IsSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
1191 // damage bonus (per damage class)
1192 switch (spellInfo
->DmgClass
)
1194 // Melee and Ranged Spells
1195 case SPELL_DAMAGE_CLASS_RANGED
:
1196 case SPELL_DAMAGE_CLASS_MELEE
:
1198 //Calculate damage bonus
1199 damage
= MeleeDamageBonusDone(pVictim
, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1200 damage
= pVictim
->MeleeDamageBonusTaken(this, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1202 // if crit add critical bonus
1205 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1206 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1207 // Resilience - reduce crit damage
1208 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1209 if (attackType
!= RANGED_ATTACK
)
1210 damage
-= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1212 damage
-= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1217 case SPELL_DAMAGE_CLASS_NONE
:
1218 case SPELL_DAMAGE_CLASS_MAGIC
:
1220 // Calculate damage bonus
1221 damage
= SpellDamageBonusDone(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1222 damage
= pVictim
->SpellDamageBonusTaken(this, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1224 // If crit add critical bonus
1227 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1228 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1229 // Resilience - reduce crit damage
1230 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1231 damage
-= pVictim
->GetSpellCritDamageReduction(redunction_affected_damage
);
1237 // only from players
1238 if (GetTypeId() == TYPEID_PLAYER
)
1240 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1241 damage
-= pVictim
->GetSpellDamageReduction(redunction_affected_damage
);
1244 // damage mitigation
1247 // physical damage => armor
1248 if (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
1250 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1251 damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(pVictim
, armor_affected_damage
);
1256 damageInfo
->damage
= damage
;
1259 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1264 Unit
*pVictim
= damageInfo
->target
;
1266 if(!this || !pVictim
)
1269 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1272 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1273 if (spellProto
== NULL
)
1275 DEBUG_LOG("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1279 //You don't lose health from damage taken from another player while in a sanctuary
1280 //You still see it in the combat log though
1281 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1283 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1284 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1288 // Call default DealDamage (send critical in hit info for threat calculation)
1289 CleanDamage
cleanDamage(0, BASE_ATTACK
, damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
? MELEE_HIT_CRIT
: MELEE_HIT_NORMAL
);
1290 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->schoolMask
), spellProto
, durabilityLoss
);
1293 //TODO for melee need create structure as in
1294 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1296 damageInfo
->attacker
= this;
1297 damageInfo
->target
= pVictim
;
1298 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1299 damageInfo
->attackType
= attackType
;
1300 damageInfo
->damage
= 0;
1301 damageInfo
->cleanDamage
= 0;
1302 damageInfo
->absorb
= 0;
1303 damageInfo
->resist
= 0;
1304 damageInfo
->blocked_amount
= 0;
1306 damageInfo
->TargetState
= 0;
1307 damageInfo
->HitInfo
= 0;
1308 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1309 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1310 damageInfo
->procEx
= PROC_EX_NONE
;
1311 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1313 if(!this || !pVictim
)
1315 if(!this->isAlive() || !pVictim
->isAlive())
1318 // Select HitInfo/procAttacker/procVictim flag based on attack type
1322 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
;
1323 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1324 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1327 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1328 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1329 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1332 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1333 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1334 damageInfo
->HitInfo
= 0x08;// test
1340 // Physical Immune check
1341 if (damageInfo
->target
->IsImmunedToDamage(damageInfo
->damageSchoolMask
))
1343 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1344 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1346 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1347 damageInfo
->damage
= 0;
1348 damageInfo
->cleanDamage
= 0;
1351 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1352 // Add melee damage bonus
1353 damage
= MeleeDamageBonusDone(damageInfo
->target
, damage
, damageInfo
->attackType
);
1354 damage
= damageInfo
->target
->MeleeDamageBonusTaken(this, damage
, damageInfo
->attackType
);
1355 // Calculate armor reduction
1357 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageInfo
->damageSchoolMask
);
1358 damageInfo
->damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(damageInfo
->target
, armor_affected_damage
);
1359 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1361 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1363 // Disable parry or dodge for ranged attack
1364 if (damageInfo
->attackType
== RANGED_ATTACK
)
1366 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1367 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1370 switch(damageInfo
->hitOutCome
)
1372 case MELEE_HIT_EVADE
:
1374 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1375 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1377 damageInfo
->procEx
|=PROC_EX_EVADE
;
1378 damageInfo
->damage
= 0;
1379 damageInfo
->cleanDamage
= 0;
1382 case MELEE_HIT_MISS
:
1384 damageInfo
->HitInfo
|= HITINFO_MISS
;
1385 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1387 damageInfo
->procEx
|=PROC_EX_MISS
;
1388 damageInfo
->damage
= 0;
1389 damageInfo
->cleanDamage
= 0;
1392 case MELEE_HIT_NORMAL
:
1393 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1394 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1396 case MELEE_HIT_CRIT
:
1398 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1399 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1401 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1403 damageInfo
->damage
+= damageInfo
->damage
;
1405 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1406 if(damageInfo
->attackType
== RANGED_ATTACK
)
1407 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1409 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1411 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, SPELL_SCHOOL_MASK_NORMAL
);
1413 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1415 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1416 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1418 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1420 // Resilience - reduce crit damage
1421 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1422 uint32 resilienceReduction
;
1423 if (attackType
!= RANGED_ATTACK
)
1424 resilienceReduction
= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1426 resilienceReduction
= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1428 damageInfo
->damage
-= resilienceReduction
;
1429 damageInfo
->cleanDamage
+= resilienceReduction
;
1432 case MELEE_HIT_PARRY
:
1433 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1434 damageInfo
->procEx
|= PROC_EX_PARRY
;
1435 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1436 damageInfo
->damage
= 0;
1439 case MELEE_HIT_DODGE
:
1440 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1441 damageInfo
->procEx
|=PROC_EX_DODGE
;
1442 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1443 damageInfo
->damage
= 0;
1445 case MELEE_HIT_BLOCK
:
1447 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1448 damageInfo
->HitInfo
|= HITINFO_BLOCK
;
1449 damageInfo
->procEx
|= PROC_EX_BLOCK
;
1450 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1452 // Target has a chance to double the blocked amount if it has SPELL_AURA_MOD_BLOCK_CRIT_CHANCE
1453 if (roll_chance_i(pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_CRIT_CHANCE
)))
1454 damageInfo
->blocked_amount
*= 2;
1456 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1458 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1459 damageInfo
->blocked_amount
= damageInfo
->damage
;
1460 damageInfo
->procEx
|= PROC_EX_FULL_BLOCK
;
1463 damageInfo
->procEx
|= PROC_EX_NORMAL_HIT
; // Partial blocks can still cause attacker procs
1465 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1466 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1469 case MELEE_HIT_GLANCING
:
1471 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1472 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1473 damageInfo
->procEx
|= PROC_EX_NORMAL_HIT
;
1474 float reducePercent
= 1.0f
; //damage factor
1475 // calculate base values and mods
1476 float baseLowEnd
= 1.3f
;
1477 float baseHighEnd
= 1.2f
;
1478 switch(getClass()) // lowering base values for casters
1486 baseHighEnd
-= 0.3f
;
1490 float maxLowEnd
= 0.6f
;
1491 switch(getClass()) // upper for melee classes
1495 maxLowEnd
= 0.91f
; //If the attacker is a melee class then instead the lower value of 0.91
1499 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1500 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1501 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1503 // apply max/min bounds
1504 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1506 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1509 if ( highEnd
< 0.2f
) //high end limits
1511 if ( highEnd
> 0.99f
)
1514 if(lowEnd
> highEnd
) // prevent negative range size
1517 reducePercent
= lowEnd
+ rand_norm_f() * ( highEnd
- lowEnd
);
1519 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1520 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1523 case MELEE_HIT_CRUSHING
:
1525 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1526 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1527 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1528 // 150% normal damage
1529 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1537 // only from players
1538 if (GetTypeId() == TYPEID_PLAYER
)
1540 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1541 uint32 resilienceReduction
;
1542 if (attackType
!= RANGED_ATTACK
)
1543 resilienceReduction
= pVictim
->GetMeleeDamageReduction(redunction_affected_damage
);
1545 resilienceReduction
= pVictim
->GetRangedDamageReduction(redunction_affected_damage
);
1546 damageInfo
->damage
-= resilienceReduction
;
1547 damageInfo
->cleanDamage
+= resilienceReduction
;
1550 // Calculate absorb resist
1551 if(int32(damageInfo
->damage
) > 0)
1553 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1555 // Calculate absorb & resists
1556 uint32 absorb_affected_damage
= CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1557 damageInfo
->target
->CalculateAbsorbAndResist(this, damageInfo
->damageSchoolMask
, DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, true);
1558 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1559 if (damageInfo
->absorb
)
1561 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1562 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1564 if (damageInfo
->resist
)
1565 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1568 else // Umpossible get negative result but....
1569 damageInfo
->damage
= 0;
1572 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1574 if (damageInfo
==0) return;
1575 Unit
*pVictim
= damageInfo
->target
;
1577 if(!this || !pVictim
)
1580 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1583 //You don't lose health from damage taken from another player while in a sanctuary
1584 //You still see it in the combat log though
1585 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1587 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1588 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1592 // Hmmmm dont like this emotes client must by self do all animations
1593 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1594 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1595 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1596 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1598 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1600 // Get attack timers
1601 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1602 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1603 // Reduce attack time
1604 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1606 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20f
;
1607 float percent60
= 3.0f
* percent20
;
1608 if(offtime
> percent20
&& offtime
<= percent60
)
1610 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1612 else if(offtime
> percent60
)
1614 offtime
-= 2.0f
* percent20
;
1615 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1620 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20f
;
1621 float percent60
= 3.0f
* percent20
;
1622 if(basetime
> percent20
&& basetime
<= percent60
)
1624 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1626 else if(basetime
> percent60
)
1628 basetime
-= 2.0f
* percent20
;
1629 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1634 // Call default DealDamage
1635 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1636 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, damageInfo
->damageSchoolMask
, NULL
, durabilityLoss
);
1638 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1639 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1640 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI_F
, this) )
1642 // -probability is between 0% and 40%
1644 float Probability
= 20.0f
;
1646 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1647 if( pVictim
->getLevel() < 30 )
1648 Probability
= 0.65f
*pVictim
->getLevel()+0.5f
;
1650 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1651 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1653 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1655 if(Probability
> 40.0f
)
1656 Probability
= 40.0f
;
1658 if(roll_chance_f(Probability
))
1659 CastSpell(pVictim
, 1604, true);
1663 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1665 // on weapon hit casts
1666 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1667 ((Player
*)this)->CastItemCombatSpell(pVictim
, damageInfo
->attackType
);
1669 // victim's damage shield
1670 std::set
<Aura
*> alreadyDone
;
1671 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1672 for(AuraList::const_iterator i
= vDamageShields
.begin(); i
!= vDamageShields
.end();)
1674 if (alreadyDone
.find(*i
) == alreadyDone
.end())
1676 alreadyDone
.insert(*i
);
1677 uint32 damage
=(*i
)->GetModifier()->m_amount
;
1678 SpellEntry
const *i_spellProto
= (*i
)->GetSpellProto();
1679 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
1682 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1683 //damage-=absorb + resist;
1685 pVictim
->DealDamageMods(this,damage
,NULL
);
1687 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4+4+4));
1688 data
<< uint64(pVictim
->GetGUID());
1689 data
<< uint64(GetGUID());
1690 data
<< uint32(i_spellProto
->Id
);
1691 data
<< uint32(damage
); // Damage
1692 data
<< uint32(0); // Overkill
1693 data
<< uint32(i_spellProto
->SchoolMask
);
1694 pVictim
->SendMessageToSet(&data
, true );
1696 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(i_spellProto
), i_spellProto
, true);
1698 i
= vDamageShields
.begin();
1707 void Unit::HandleEmoteCommand(uint32 anim_id
)
1709 WorldPacket
data( SMSG_EMOTE
, 4 + 8 );
1710 data
<< uint32(anim_id
);
1711 data
<< uint64(GetGUID());
1712 SendMessageToSet(&data
, true);
1715 void Unit::HandleEmoteState(uint32 anim_id
)
1717 SetUInt32Value(UNIT_NPC_EMOTESTATE
, anim_id
);
1720 void Unit::HandleEmote(uint32 anim_id
)
1723 HandleEmoteState(0);
1724 else if (EmotesEntry
const* emoteEntry
= sEmotesStore
.LookupEntry(anim_id
))
1726 if (emoteEntry
->EmoteType
) // 1,2 states, 0 command
1727 HandleEmoteState(anim_id
);
1729 HandleEmoteCommand(anim_id
);
1733 uint32
Unit::CalcNotIgnoreAbsorbDamage( uint32 damage
, SpellSchoolMask damageSchoolMask
, SpellEntry
const* spellInfo
/*= NULL*/)
1735 float absorb_affected_rate
= 1.0f
;
1736 Unit::AuraList
const& ignoreAbsorbSchool
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_SCHOOL
);
1737 for(Unit::AuraList::const_iterator i
= ignoreAbsorbSchool
.begin(); i
!= ignoreAbsorbSchool
.end(); ++i
)
1738 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1739 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1743 Unit::AuraList
const& ignoreAbsorbForSpell
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL
);
1744 for(Unit::AuraList::const_iterator citr
= ignoreAbsorbForSpell
.begin(); citr
!= ignoreAbsorbForSpell
.end(); ++citr
)
1745 if ((*citr
)->isAffectedOnSpell(spellInfo
))
1746 absorb_affected_rate
*= (100.0f
- (*citr
)->GetModifier()->m_amount
)/100.0f
;
1749 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1752 uint32
Unit::CalcNotIgnoreDamageRedunction( uint32 damage
, SpellSchoolMask damageSchoolMask
)
1754 float absorb_affected_rate
= 1.0f
;
1755 Unit::AuraList
const& ignoreAbsorb
= GetAurasByType(SPELL_AURA_MOD_IGNORE_DAMAGE_REDUCTION_SCHOOL
);
1756 for(Unit::AuraList::const_iterator i
= ignoreAbsorb
.begin(); i
!= ignoreAbsorb
.end(); ++i
)
1757 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1758 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1760 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1763 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
1765 uint32 newdamage
= 0;
1766 float armor
= (float)pVictim
->GetArmor();
1768 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
1769 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
1771 // Apply Player CR_ARMOR_PENETRATION rating and percent talents
1772 if (GetTypeId()==TYPEID_PLAYER
)
1773 armor
*= 1.0f
- ((Player
*)this)->GetArmorPenetrationPct() / 100.0f
;
1778 float levelModifier
= (float)getLevel();
1779 if (levelModifier
> 59)
1780 levelModifier
= levelModifier
+ (4.5f
* (levelModifier
-59));
1782 float tmpvalue
= 0.1f
* armor
/ (8.5f
* levelModifier
+ 40);
1783 tmpvalue
= tmpvalue
/(1.0f
+ tmpvalue
);
1785 if (tmpvalue
< 0.0f
)
1787 if (tmpvalue
> 0.75f
)
1790 newdamage
= uint32(damage
- (damage
* tmpvalue
));
1792 return (newdamage
> 1) ? newdamage
: 1;
1795 void Unit::CalculateAbsorbAndResist(Unit
*pCaster
, SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
, bool canReflect
)
1797 if(!pCaster
|| !isAlive() || !damage
)
1800 // Magic damage, check for resists
1801 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
1803 // Get base victim resistance for school
1804 float tmpvalue2
= (float)GetResistance(GetFirstSchoolInMask(schoolMask
));
1805 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
1806 tmpvalue2
+= (float)pCaster
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
1808 tmpvalue2
*= (float)(0.15f
/ getLevel());
1809 if (tmpvalue2
< 0.0f
)
1811 if (tmpvalue2
> 0.75f
)
1813 uint32 ran
= urand(0, 100);
1814 float faq
[4] = {24.0f
,6.0f
,4.0f
,6.0f
};
1817 for (uint8 i
= 0; i
< 4; ++i
)
1819 Binom
+= 2400 *( powf(tmpvalue2
, float(i
)) * powf( (1-tmpvalue2
), float(4-i
)))/faq
[i
];
1825 if (damagetype
== DOT
&& m
== 4)
1826 *resist
+= uint32(damage
- 1);
1828 *resist
+= uint32(damage
* m
/ 4);
1829 if(*resist
> damage
)
1835 int32 RemainingDamage
= damage
- *resist
;
1837 // Get unit state (need for some absorb check)
1838 uint32 unitflag
= GetUInt32Value(UNIT_FIELD_FLAGS
);
1839 // Reflect damage spells (not cast any damage spell in aura lookup)
1840 uint32 reflectSpell
= 0;
1841 int32 reflectDamage
= 0;
1842 Aura
* reflectTriggeredBy
= NULL
; // expected as not expired at reflect as in current cases
1843 // Death Prevention Aura
1844 SpellEntry
const* preventDeathSpell
= NULL
;
1845 int32 preventDeathAmount
= 0;
1847 // full absorb cases (by chance)
1848 AuraList
const& vAbsorb
= GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1849 for(AuraList::const_iterator i
= vAbsorb
.begin(); i
!= vAbsorb
.end() && RemainingDamage
> 0; ++i
)
1851 // only work with proper school mask damage
1852 Modifier
* i_mod
= (*i
)->GetModifier();
1853 if (!(i_mod
->m_miscvalue
& schoolMask
))
1856 SpellEntry
const* i_spellProto
= (*i
)->GetSpellProto();
1857 // Fire Ward or Frost Ward
1858 if(i_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& i_spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000108))
1861 Unit::AuraList
const& auras
= GetAurasByType(SPELL_AURA_ADD_PCT_MODIFIER
);
1862 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
1864 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
1865 // Frost Warding (chance full absorb)
1866 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& itr_spellProto
->SpellIconID
== 501)
1868 // chance stored in next dummy effect
1869 chance
= itr_spellProto
->CalculateSimpleValue(EFFECT_INDEX_1
);
1873 if(roll_chance_i(chance
))
1875 int32 amount
= RemainingDamage
;
1876 RemainingDamage
= 0;
1878 // Frost Warding (mana regen)
1879 CastCustomSpell(this, 57776, &amount
, NULL
, NULL
, true, NULL
, *i
);
1885 // Need remove expired auras after
1886 bool existExpired
= false;
1888 // Incanter's Absorption, for converting to spell power
1889 int32 incanterAbsorption
= 0;
1891 // absorb without mana cost
1892 AuraList
const& vSchoolAbsorb
= GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1893 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; ++i
)
1895 Modifier
* mod
= (*i
)->GetModifier();
1896 if (!(mod
->m_miscvalue
& schoolMask
))
1899 SpellEntry
const* spellProto
= (*i
)->GetSpellProto();
1901 // Max Amount can be absorbed by this aura
1902 int32 currentAbsorb
= mod
->m_amount
;
1904 // Found empty aura (impossible but..)
1905 if (currentAbsorb
<=0)
1907 existExpired
= true;
1910 // Handle custom absorb auras
1911 // TODO: try find better way
1912 switch(spellProto
->SpellFamilyName
)
1914 case SPELLFAMILY_GENERIC
:
1917 if (spellProto
->SpellIconID
== 3066)
1919 //reduces all damage taken while stun, fear or silence
1920 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1921 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1925 if (spellProto
->SpellIconID
== 2115)
1927 // while affected by Stun and Fear
1928 if (unitflag
&(UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
))
1929 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1933 if (spellProto
->SpellIconID
== 3006)
1935 // You have a chance equal to your Parry chance
1936 if (damagetype
== DIRECT_DAMAGE
&& // Only for direct damage
1937 roll_chance_f(GetUnitParryChance())) // Roll chance
1938 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1941 // Reflective Shield (Lady Malande boss)
1942 if (spellProto
->Id
== 41475 && canReflect
)
1944 if(RemainingDamage
< currentAbsorb
)
1945 reflectDamage
= RemainingDamage
/ 2;
1947 reflectDamage
= currentAbsorb
/ 2;
1948 reflectSpell
= 33619;
1949 reflectTriggeredBy
= *i
;
1952 if (spellProto
->Id
== 39228 || // Argussian Compass
1953 spellProto
->Id
== 60218) // Essence of Gossamer
1955 // Max absorb stored in 1 dummy effect
1956 int32 max_absorb
= spellProto
->CalculateSimpleValue(EFFECT_INDEX_1
);
1957 if (max_absorb
< currentAbsorb
)
1958 currentAbsorb
= max_absorb
;
1963 case SPELLFAMILY_DRUID
:
1966 if (spellProto
->SpellIconID
== 2253)
1968 //reduces all damage taken while Stunned and in Cat Form
1969 if (m_form
== FORM_CAT
&& (unitflag
& UNIT_FLAG_STUNNED
))
1970 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1975 case SPELLFAMILY_ROGUE
:
1977 // Cheat Death (make less prio with Guardian Spirit case)
1978 if (!preventDeathSpell
&& spellProto
->SpellIconID
== 2109 &&
1979 GetTypeId()==TYPEID_PLAYER
&& // Only players
1980 !((Player
*)this)->HasSpellCooldown(31231) &&
1981 // Only if no cooldown
1982 roll_chance_i((*i
)->GetModifier()->m_amount
))
1985 preventDeathSpell
= (*i
)->GetSpellProto();
1990 case SPELLFAMILY_PRIEST
:
1993 if (spellProto
->SpellIconID
== 2873)
1995 preventDeathSpell
= (*i
)->GetSpellProto();
1996 preventDeathAmount
= (*i
)->GetModifier()->m_amount
;
1999 // Reflective Shield
2000 if (spellProto
->SpellFamilyFlags
== 0x1 && canReflect
)
2002 if (pCaster
== this)
2004 Unit
* caster
= (*i
)->GetCaster();
2007 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
2008 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
2010 switch((*k
)->GetModifier()->m_miscvalue
)
2012 case 5065: // Rank 1
2013 case 5064: // Rank 2
2015 if(RemainingDamage
>= currentAbsorb
)
2016 reflectDamage
= (*k
)->GetModifier()->m_amount
* currentAbsorb
/100;
2018 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
2019 reflectSpell
= 33619;
2020 reflectTriggeredBy
= *i
;
2029 case SPELLFAMILY_SHAMAN
:
2032 if (spellProto
->SpellIconID
== 3066)
2034 //reduces all damage taken while stun, fear or silence
2035 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
2036 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2041 case SPELLFAMILY_DEATHKNIGHT
:
2044 if (spellProto
->SpellIconID
== 1958)
2046 // TODO: absorb only while transform
2049 // Anti-Magic Shell (on self)
2050 if (spellProto
->Id
== 48707)
2052 // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power.
2053 // This, if I'm not mistaken, shows that we get back ~2% of the absorbed damage as runic power.
2054 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
2055 int32 regen
= absorbed
* 2 / 10;
2056 CastCustomSpell(this, 49088, ®en
, NULL
, NULL
, true, NULL
, *i
);
2057 RemainingDamage
-= absorbed
;
2060 // Anti-Magic Shell (on single party/raid member)
2061 if (spellProto
->Id
== 50462)
2063 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2067 if (spellProto
->Id
== 50461)
2069 Unit
* caster
= (*i
)->GetCaster();
2072 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
2073 int32 canabsorb
= caster
->GetHealth();
2074 if (canabsorb
< absorbed
)
2075 absorbed
= canabsorb
;
2077 RemainingDamage
-= absorbed
;
2079 uint32 ab_damage
= absorbed
;
2080 pCaster
->DealDamageMods(caster
,ab_damage
,NULL
);
2081 pCaster
->DealDamage(caster
, ab_damage
, NULL
, damagetype
, schoolMask
, 0, false);
2090 // currentAbsorb - damage can be absorbed by shield
2091 // If need absorb less damage
2092 if (RemainingDamage
< currentAbsorb
)
2093 currentAbsorb
= RemainingDamage
;
2095 RemainingDamage
-= currentAbsorb
;
2097 // Fire Ward or Frost Ward or Ice Barrier (or Mana Shield)
2098 // for Incanter's Absorption converting to spell power
2099 if (spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& spellProto
->SpellFamilyFlags2
& 0x000008)
2100 incanterAbsorption
+= currentAbsorb
;
2102 // Reduce shield amount
2103 mod
->m_amount
-=currentAbsorb
;
2104 if((*i
)->DropAuraCharge())
2106 // Need remove it later
2107 if (mod
->m_amount
<=0)
2108 existExpired
= true;
2111 // Remove all expired absorb auras
2114 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end();)
2116 if ((*i
)->GetModifier()->m_amount
<=0)
2118 RemoveAurasDueToSpell((*i
)->GetId());
2119 i
= vSchoolAbsorb
.begin();
2126 // Cast back reflect damage spell
2127 if (canReflect
&& reflectSpell
)
2128 CastCustomSpell(pCaster
, reflectSpell
, &reflectDamage
, NULL
, NULL
, true, NULL
, reflectTriggeredBy
);
2130 // absorb by mana cost
2131 AuraList
const& vManaShield
= GetAurasByType(SPELL_AURA_MANA_SHIELD
);
2132 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
2136 // check damage school mask
2137 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2140 int32 currentAbsorb
;
2141 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2142 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2144 currentAbsorb
= RemainingDamage
;
2146 if (float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()])
2148 if(Player
*modOwner
= GetSpellModOwner())
2149 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
2151 int32 maxAbsorb
= int32(GetPower(POWER_MANA
) / manaMultiplier
);
2152 if (currentAbsorb
> maxAbsorb
)
2153 currentAbsorb
= maxAbsorb
;
2155 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
2156 ApplyPowerMod(POWER_MANA
, manaReduction
, false);
2159 // Mana Shield (or Fire Ward or Frost Ward or Ice Barrier)
2160 // for Incanter's Absorption converting to spell power
2161 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_MAGE
&& (*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x000008)
2162 incanterAbsorption
+= currentAbsorb
;
2164 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
2165 if((*i
)->GetModifier()->m_amount
<= 0)
2167 RemoveAurasDueToSpell((*i
)->GetId());
2168 next
= vManaShield
.begin();
2171 RemainingDamage
-= currentAbsorb
;
2174 // effects dependent from full absorb amount
2175 // Incanter's Absorption, if have affective absorbing
2176 if (incanterAbsorption
)
2178 Unit::AuraList
const& auras
= GetAurasByType(SPELL_AURA_DUMMY
);
2179 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
2181 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
2183 // Incanter's Absorption
2184 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_GENERIC
&&
2185 itr_spellProto
->SpellIconID
== 2941)
2188 int32 amount
= int32(incanterAbsorption
* (*itr
)->GetModifier()->m_amount
/ 100);
2190 // apply normalized part of already accumulated amount in aura
2191 if (Aura
* spdAura
= GetAura(44413, EFFECT_INDEX_0
))
2192 amount
+= spdAura
->GetModifier()->m_amount
* spdAura
->GetAuraDuration() / spdAura
->GetAuraMaxDuration();
2194 // Incanter's Absorption (triggered absorb based spell power, will replace existed if any)
2195 CastCustomSpell(this, 44413, &amount
, NULL
, NULL
, true);
2201 // only split damage if not damaging yourself
2204 AuraList
const& vSplitDamageFlat
= GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
2205 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
2209 // check damage school mask
2210 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2213 // Damage can be splitted only if aura has an alive caster
2214 Unit
*caster
= (*i
)->GetCaster();
2215 if(!caster
|| caster
== this || !caster
->IsInWorld() || !caster
->isAlive())
2218 int32 currentAbsorb
;
2219 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2220 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2222 currentAbsorb
= RemainingDamage
;
2224 RemainingDamage
-= currentAbsorb
;
2227 uint32 splitted
= currentAbsorb
;
2228 uint32 splitted_absorb
= 0;
2229 pCaster
->DealDamageMods(caster
,splitted
,&splitted_absorb
);
2231 pCaster
->SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, splitted_absorb
, 0, false, 0, false);
2233 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2234 pCaster
->DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2237 AuraList
const& vSplitDamagePct
= GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
2238 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
2242 // check damage school mask
2243 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2246 // Damage can be splitted only if aura has an alive caster
2247 Unit
*caster
= (*i
)->GetCaster();
2248 if(!caster
|| caster
== this || !caster
->IsInWorld() || !caster
->isAlive())
2251 uint32 splitted
= uint32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
2253 RemainingDamage
-= int32(splitted
);
2255 uint32 split_absorb
= 0;
2256 pCaster
->DealDamageMods(caster
,splitted
,&split_absorb
);
2258 pCaster
->SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, split_absorb
, 0, false, 0, false);
2260 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2261 pCaster
->DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2265 // Apply death prevention spells effects
2266 if (preventDeathSpell
&& RemainingDamage
>= (int32
)GetHealth())
2268 switch(preventDeathSpell
->SpellFamilyName
)
2271 case SPELLFAMILY_ROGUE
:
2274 if (preventDeathSpell
->SpellIconID
== 2109)
2276 CastSpell(this,31231,true);
2277 ((Player
*)this)->AddSpellCooldown(31231,0,time(NULL
)+60);
2278 // with health > 10% lost health until health==10%, in other case no losses
2279 uint32 health10
= GetMaxHealth()/10;
2280 RemainingDamage
= GetHealth() > health10
? GetHealth() - health10
: 0;
2285 case SPELLFAMILY_PRIEST
:
2288 if (preventDeathSpell
->SpellIconID
== 2873)
2290 int32 healAmount
= GetMaxHealth() * preventDeathAmount
/ 100;
2291 CastCustomSpell(this, 48153, &healAmount
, NULL
, NULL
, true);
2292 RemoveAurasDueToSpell(preventDeathSpell
->Id
);
2293 RemainingDamage
= 0;
2300 *absorb
= damage
- RemainingDamage
- *resist
;
2303 void Unit::CalculateAbsorbResistBlock(Unit
*pCaster
, SpellNonMeleeDamage
*damageInfo
, SpellEntry
const* spellProto
, WeaponAttackType attType
)
2305 bool blocked
= false;
2306 // Get blocked status
2307 switch (spellProto
->DmgClass
)
2309 // Melee and Ranged Spells
2310 case SPELL_DAMAGE_CLASS_RANGED
:
2311 case SPELL_DAMAGE_CLASS_MELEE
:
2312 blocked
= IsSpellBlocked(pCaster
, spellProto
, attType
);
2320 damageInfo
->blocked
= GetShieldBlockValue();
2321 if (damageInfo
->damage
< (int32
)damageInfo
->blocked
)
2322 damageInfo
->blocked
= damageInfo
->damage
;
2323 damageInfo
->damage
-=damageInfo
->blocked
;
2326 uint32 absorb_affected_damage
= pCaster
->CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,GetSpellSchoolMask(spellProto
),spellProto
);
2327 CalculateAbsorbAndResist(pCaster
, GetSpellSchoolMask(spellProto
), SPELL_DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, !(spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
));
2328 damageInfo
->damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
2331 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
2333 if(hasUnitState(UNIT_STAT_CAN_NOT_REACT
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
2336 if (!pVictim
->isAlive())
2339 if(IsNonMeleeSpellCasted(false))
2343 if (attType
== BASE_ATTACK
)
2344 hitInfo
= HITINFO_NORMALSWING2
;
2345 else if (attType
== OFF_ATTACK
)
2346 hitInfo
= HITINFO_LEFTSWING
;
2348 return; // ignore ranged case
2350 uint32 extraAttacks
= m_extraAttacks
;
2352 // melee attack spell casted at main hand attack only
2353 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
2355 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
2357 // not recent extra attack only at any non extra attack (melee spell case)
2358 if(!extra
&& extraAttacks
)
2360 while(m_extraAttacks
)
2362 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2363 if(m_extraAttacks
> 0)
2370 // attack can be redirected to another target
2371 pVictim
= SelectMagnetTarget(pVictim
);
2373 CalcDamageInfo damageInfo
;
2374 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
2375 // Send log damage message to client
2376 DealDamageMods(pVictim
,damageInfo
.damage
,&damageInfo
.absorb
);
2377 SendAttackStateUpdate(&damageInfo
);
2378 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
2379 DealMeleeDamage(&damageInfo
,true);
2381 if (GetTypeId() == TYPEID_PLAYER
)
2382 DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2383 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2385 DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2386 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2388 // if damage pVictim call AI reaction
2389 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
2390 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
2392 // extra attack only at any non extra attack (normal case)
2393 if(!extra
&& extraAttacks
)
2395 while(m_extraAttacks
)
2397 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2398 if(m_extraAttacks
> 0)
2404 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
2406 // This is only wrapper
2408 // Miss chance based on melee
2409 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
2411 // Critical hit chance
2412 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
2414 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
2415 float dodge_chance
= pVictim
->GetUnitDodgeChance();
2416 float block_chance
= pVictim
->GetUnitBlockChance();
2417 float parry_chance
= pVictim
->GetUnitParryChance();
2419 // Useful if want to specify crit & miss chances for melee, else it could be removed
2420 DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance
,crit_chance
,dodge_chance
,parry_chance
,block_chance
);
2422 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100));
2425 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const
2427 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2428 return MELEE_HIT_EVADE
;
2430 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
2431 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
2433 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
2434 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
2436 // bonus from skills is 0.04%
2437 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
2438 int32 sum
= 0, tmp
= 0;
2439 int32 roll
= urand (0, 10000);
2441 DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
2442 DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
2443 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
2447 if (tmp
> 0 && roll
< (sum
+= tmp
))
2449 DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS");
2450 return MELEE_HIT_MISS
;
2453 // always crit against a sitting target (except 0 crit chance)
2454 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
2456 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)");
2457 return MELEE_HIT_CRIT
;
2462 // only players can't dodge if attacker is behind
2463 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI_F
,this))
2465 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
2469 // Reduce dodge chance by attacker expertise rating
2470 if (GetTypeId() == TYPEID_PLAYER
)
2471 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2473 dodge_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2475 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2476 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2479 if ( (tmp
> 0) // check if unit _can_ dodge
2480 && ((tmp
-= skillBonus
) > 0)
2481 && roll
< (sum
+= tmp
))
2483 DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
2484 return MELEE_HIT_DODGE
;
2488 // parry & block chances
2490 // check if attack comes from behind, nobody can parry or block if attacker is behind
2491 if (!pVictim
->HasInArc(M_PI_F
,this))
2493 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind.");
2497 // Reduce parry chance by attacker expertise rating
2498 if (GetTypeId() == TYPEID_PLAYER
)
2499 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2501 parry_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2503 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
2505 int32 tmp2
= int32(parry_chance
);
2506 if ( (tmp2
> 0) // check if unit _can_ parry
2507 && ((tmp2
-= skillBonus
) > 0)
2508 && (roll
< (sum
+= tmp2
)))
2510 DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp2
, sum
);
2511 return MELEE_HIT_PARRY
;
2515 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
2518 if ( (tmp
> 0) // check if unit _can_ block
2519 && ((tmp
-= skillBonus
) > 0)
2520 && (roll
< (sum
+= tmp
)))
2522 DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
2523 return MELEE_HIT_BLOCK
;
2531 if (tmp
> 0 && roll
< (sum
+= tmp
))
2533 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
2534 return MELEE_HIT_CRIT
;
2537 // 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)
2538 if( attType
!= RANGED_ATTACK
&&
2539 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
2540 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
2541 getLevel() < pVictim
->getLevelForTarget(this) )
2543 // cap possible value (with bonuses > max skill)
2544 int32 skill
= attackerWeaponSkill
;
2545 int32 maxskill
= attackerMaxSkillValueForLevel
;
2546 skill
= (skill
> maxskill
) ? maxskill
: skill
;
2548 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
2549 tmp
= tmp
> 4000 ? 4000 : tmp
;
2550 if (roll
< (sum
+= tmp
))
2552 DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
2553 return MELEE_HIT_GLANCING
;
2557 // mobs can score crushing blows if they're 4 or more levels above victim
2558 if (getLevelForTarget(pVictim
) >= pVictim
->getLevelForTarget(this) + 4 &&
2559 // can be from by creature (if can) or from controlled player that considered as creature
2560 (GetTypeId()!=TYPEID_PLAYER
&& !((Creature
*)this)->isPet() &&
2561 !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) ||
2562 GetTypeId()==TYPEID_PLAYER
&& GetCharmerOrOwnerGUID()))
2564 // when their weapon skill is 15 or more above victim's defense skill
2565 tmp
= victimDefenseSkill
;
2566 int32 tmpmax
= victimMaxSkillValueForLevel
;
2567 // having defense above your maximum (from items, talents etc.) has no effect
2568 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
2569 // tmp = mob's level * 5 - player's current defense skill
2570 tmp
= attackerMaxSkillValueForLevel
- tmp
;
2573 // add 2% chance per lacking skill point, min. is 15%
2574 tmp
= tmp
* 200 - 1500;
2575 if (roll
< (sum
+= tmp
))
2577 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
2578 return MELEE_HIT_CRUSHING
;
2583 DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL");
2584 return MELEE_HIT_NORMAL
;
2587 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
2589 float min_damage
, max_damage
;
2591 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
2592 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
2598 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
2599 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
2602 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
2603 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
2606 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
2607 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
2609 // Just for good manner
2617 if (min_damage
> max_damage
)
2619 std::swap(min_damage
,max_damage
);
2622 if(max_damage
== 0.0f
)
2625 return urand((uint32
)min_damage
, (uint32
)max_damage
);
2628 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
2630 if(spellProto
->spellLevel
<= 0)
2633 float LvlPenalty
= 0.0f
;
2635 if(spellProto
->spellLevel
< 20)
2636 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
2637 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
2638 if(LvlFactor
> 1.0f
)
2641 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
2644 void Unit::SendMeleeAttackStart(Unit
* pVictim
)
2646 WorldPacket
data( SMSG_ATTACKSTART
, 8 + 8 );
2647 data
<< uint64(GetGUID());
2648 data
<< uint64(pVictim
->GetGUID());
2650 SendMessageToSet(&data
, true);
2651 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
2654 void Unit::SendMeleeAttackStop(Unit
* victim
)
2659 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
2660 data
<< GetPackGUID();
2661 data
<< victim
->GetPackGUID(); // can be 0x00...
2662 data
<< uint32(0); // can be 0x1
2663 SendMessageToSet(&data
, true);
2664 DETAIL_LOG("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER
? "player" : "creature"), GetGUIDLow(), (victim
->GetTypeId()==TYPEID_PLAYER
? "player" : "creature"),victim
->GetGUIDLow());
2666 /*if(victim->GetTypeId() == TYPEID_UNIT)
2667 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
2670 bool Unit::IsSpellBlocked(Unit
*pCaster
, SpellEntry
const * /*spellProto*/, WeaponAttackType attackType
)
2672 if (HasInArc(M_PI_F
,pCaster
))
2674 /* Currently not exist spells with ignore block
2675 // Ignore combat result aura (parry/dodge check on prepare)
2676 AuraList const& ignore = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2677 for(AuraList::const_iterator i = ignore.begin(); i != ignore.end(); ++i)
2679 if (!(*i)->isAffectedOnSpell(spellProto))
2681 if ((*i)->GetModifier()->m_miscvalue == )
2686 // Check creatures flags_extra for disable block
2687 if(GetTypeId()==TYPEID_UNIT
&&
2688 ((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
)
2691 float blockChance
= GetUnitBlockChance();
2692 blockChance
+= (int32(pCaster
->GetWeaponSkillValue(attackType
)) - int32(GetMaxSkillValueForLevel()))*0.04f
;
2693 if (roll_chance_f(blockChance
))
2699 // Melee based spells can be miss, parry or dodge on this step
2700 // Crit or block - determined on damage calculation phase! (and can be both in some time)
2701 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
2703 // Calculate hit chance (more correct for chance mod)
2706 // PvP - PvE melee chances
2707 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2708 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
2710 HitChance
= 95 - leveldif
;
2712 HitChance
= 93 - (leveldif
- 2) * lchance
;
2714 // Hit chance depends from victim auras
2715 if(attType
== RANGED_ATTACK
)
2716 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2718 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2720 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2721 if(Player
*modOwner
= GetSpellModOwner())
2722 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
2725 float miss_chance
= 100.0f
- HitChance
;
2727 // Bonuses from attacker aura and ratings
2728 if (attType
== RANGED_ATTACK
)
2729 miss_chance
-= m_modRangedHitChance
;
2731 miss_chance
-= m_modMeleeHitChance
;
2733 // bonus from skills is 0.04%
2734 miss_chance
-= skillDiff
* 0.04f
;
2736 // Limit miss chance from 0 to 60%
2737 if (miss_chance
< 0.0f
)
2739 if (miss_chance
> 60.0f
)
2744 // Melee based spells hit result calculations
2745 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2747 WeaponAttackType attType
= BASE_ATTACK
;
2749 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
2750 attType
= RANGED_ATTACK
;
2752 // bonus from skills is 0.04% per skill Diff
2753 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
2754 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
2755 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
2757 uint32 roll
= urand (0, 10000);
2759 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
2761 uint32 tmp
= missChance
;
2763 return SPELL_MISS_MISS
;
2765 // Chance resist mechanic (select max value from every mechanic spell effect)
2766 int32 resist_mech
= 0;
2767 // Get effects mechanic and chance
2768 for(int eff
= 0; eff
< MAX_EFFECT_INDEX
; ++eff
)
2770 int32 effect_mech
= GetEffectMechanic(spell
, SpellEffectIndex(eff
));
2773 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2774 if (resist_mech
< temp
*100)
2775 resist_mech
= temp
*100;
2781 return SPELL_MISS_RESIST
;
2783 bool canDodge
= true;
2784 bool canParry
= true;
2786 // Same spells cannot be parry/dodge
2787 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
2788 return SPELL_MISS_NONE
;
2790 // Ranged attack cannot be parry/dodge only deflect
2791 if (attType
== RANGED_ATTACK
)
2794 if (pVictim
->HasInArc(M_PI_F
,this))
2796 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2797 tmp
+=deflect_chance
;
2799 return SPELL_MISS_DEFLECT
;
2801 return SPELL_MISS_NONE
;
2804 // Check for attack from behind
2805 if (!pVictim
->HasInArc(M_PI_F
,this))
2807 // Can`t dodge from behind in PvP (but its possible in PvE)
2808 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
2813 // Check creatures flags_extra for disable parry
2814 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
2816 uint32 flagEx
= ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
;
2817 if( flagEx
& CREATURE_FLAG_EXTRA_NO_PARRY
)
2820 // Ignore combat result aura
2821 AuraList
const& ignore
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
2822 for(AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
2824 if (!(*i
)->isAffectedOnSpell(spell
))
2826 switch((*i
)->GetModifier()->m_miscvalue
)
2828 case MELEE_HIT_DODGE
: canDodge
= false; break;
2829 case MELEE_HIT_BLOCK
: break; // Block check in hit step
2830 case MELEE_HIT_PARRY
: canParry
= false; break;
2832 DEBUG_LOG("Spell %u SPELL_AURA_IGNORE_COMBAT_RESULT have unhandled state %d", (*i
)->GetId(), (*i
)->GetModifier()->m_miscvalue
);
2840 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
2841 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2842 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
)*100;
2843 // Reduce dodge chance by attacker expertise rating
2844 if (GetTypeId() == TYPEID_PLAYER
)
2845 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2847 dodgeChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2848 if (dodgeChance
< 0)
2853 return SPELL_MISS_DODGE
;
2859 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
2860 // Reduce parry chance by attacker expertise rating
2861 if (GetTypeId() == TYPEID_PLAYER
)
2862 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2864 parryChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2865 if (parryChance
< 0)
2870 return SPELL_MISS_PARRY
;
2873 return SPELL_MISS_NONE
;
2876 // TODO need use unit spell resistances in calculations
2877 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2879 // Can`t miss on dead target (on skinning for example)
2880 if (!pVictim
->isAlive())
2881 return SPELL_MISS_NONE
;
2883 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
2884 // PvP - PvE spell misschances per leveldif > 2
2885 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
2886 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2888 // Base hit chance from attacker and victim levels
2891 modHitChance
= 96 - leveldif
;
2893 modHitChance
= 94 - (leveldif
- 2) * lchance
;
2895 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2896 if(Player
*modOwner
= GetSpellModOwner())
2897 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
2898 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
2899 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
2900 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
2901 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
2902 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
2903 if (IsAreaOfEffectSpell(spell
))
2904 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
2905 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
2906 if (IsDispelSpell(spell
))
2907 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
2908 // Chance resist mechanic (select max value from every mechanic spell effect)
2909 int32 resist_mech
= 0;
2910 // Get effects mechanic and chance
2911 for(int eff
= 0; eff
< MAX_EFFECT_INDEX
; ++eff
)
2913 int32 effect_mech
= GetEffectMechanic(spell
, SpellEffectIndex(eff
));
2916 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2917 if (resist_mech
< temp
)
2922 modHitChance
-=resist_mech
;
2924 // Chance resist debuff
2925 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
2927 int32 HitChance
= modHitChance
* 100;
2928 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
2929 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
2931 // Decrease hit chance from victim rating bonus
2932 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2933 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
2935 if (HitChance
< 100) HitChance
= 100;
2936 if (HitChance
> 10000) HitChance
= 10000;
2938 int32 tmp
= 10000 - HitChance
;
2940 int32 rand
= irand(0,10000);
2943 return SPELL_MISS_MISS
;
2945 // cast by caster in front of victim
2946 if (pVictim
->HasInArc(M_PI_F
,this))
2948 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2949 tmp
+=deflect_chance
;
2951 return SPELL_MISS_DEFLECT
;
2954 return SPELL_MISS_NONE
;
2957 // Calculate spell hit result can be:
2958 // Every spell can: Evade/Immune/Reflect/Sucesful hit
2959 // For melee based spells:
2965 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
2967 // Return evade for units in evade mode
2968 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2969 return SPELL_MISS_EVADE
;
2972 if (pVictim
->IsImmunedToSpell(spell
))
2973 return SPELL_MISS_IMMUNE
;
2975 // All positive spells can`t miss
2976 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
2977 if (IsPositiveSpell(spell
->Id
))
2978 return SPELL_MISS_NONE
;
2981 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
)))
2982 return SPELL_MISS_IMMUNE
;
2984 // Try victim reflect spell
2987 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
2988 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
2989 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
2990 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
2991 reflectchance
+= (*i
)->GetModifier()->m_amount
;
2992 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
2994 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
2995 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
2996 return SPELL_MISS_REFLECT
;
3000 switch (spell
->DmgClass
)
3002 case SPELL_DAMAGE_CLASS_NONE
:
3003 return SPELL_MISS_NONE
;
3004 case SPELL_DAMAGE_CLASS_MAGIC
:
3005 return MagicSpellHitResult(pVictim
, spell
);
3006 case SPELL_DAMAGE_CLASS_MELEE
:
3007 case SPELL_DAMAGE_CLASS_RANGED
:
3008 return MeleeSpellHitResult(pVictim
, spell
);
3010 return SPELL_MISS_NONE
;
3013 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
3018 // Base misschance 5%
3019 float misschance
= 5.0f
;
3021 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
3022 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
3024 bool isNormal
= false;
3025 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
3027 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
3033 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
3039 // PvP : PvE melee misschances per leveldif > 2
3040 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
3042 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
3046 // Hit chance from attacker based on ratings and auras
3047 float m_modHitChance
;
3048 if (attType
== RANGED_ATTACK
)
3049 m_modHitChance
= m_modRangedHitChance
;
3051 m_modHitChance
= m_modMeleeHitChance
;
3054 misschance
+= (leveldif
- m_modHitChance
);
3056 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
3058 // Hit chance for victim based on ratings
3059 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
3061 if (attType
== RANGED_ATTACK
)
3062 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
3064 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
3067 // Modify miss chance by victim auras
3068 if(attType
== RANGED_ATTACK
)
3069 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
3071 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
3073 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
3074 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
3075 misschance
-= skillBonus
* 0.04f
;
3077 // Limit miss chance from 0 to 60%
3078 if ( misschance
< 0.0f
)
3080 if ( misschance
> 60.0f
)
3086 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
3088 if(GetTypeId() == TYPEID_PLAYER
)
3090 // in PvP use full skill instead current skill value
3091 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3092 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
3093 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
3094 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
3098 return GetUnitMeleeSkill(target
);
3101 float Unit::GetUnitDodgeChance() const
3103 if(hasUnitState(UNIT_STAT_STUNNED
))
3105 if( GetTypeId() == TYPEID_PLAYER
)
3106 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
3109 if(((Creature
const*)this)->isTotem())
3114 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
3115 return dodge
> 0.0f
? dodge
: 0.0f
;
3120 float Unit::GetUnitParryChance() const
3122 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3125 float chance
= 0.0f
;
3127 if(GetTypeId() == TYPEID_PLAYER
)
3129 Player
const* player
= (Player
const*)this;
3130 if(player
->CanParry() )
3132 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true,true);
3134 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true,true);
3137 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
3140 else if(GetTypeId() == TYPEID_UNIT
)
3142 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
3145 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
3149 return chance
> 0.0f
? chance
: 0.0f
;
3152 float Unit::GetUnitBlockChance() const
3154 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3157 if(GetTypeId() == TYPEID_PLAYER
)
3159 Player
const* player
= (Player
const*)this;
3160 if(player
->CanBlock() )
3162 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
3163 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
3164 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
3166 // is player but has no block ability or no not broken shield equipped
3171 if(((Creature
const*)this)->isTotem())
3176 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
3177 return block
> 0.0f
? block
: 0.0f
;
3182 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
3186 if(GetTypeId() == TYPEID_PLAYER
)
3191 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
3194 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
3197 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
3199 // Just for good manner
3208 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
3212 if(attackType
== RANGED_ATTACK
)
3213 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
3215 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
3217 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
3219 // reduce crit chance from Rating for players
3220 if (attackType
!= RANGED_ATTACK
)
3221 crit
-= pVictim
->GetMeleeCritChanceReduction();
3223 crit
-= pVictim
->GetRangedCritChanceReduction();
3225 // Apply crit chance from defence skill
3226 crit
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
3233 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
3236 if(GetTypeId() == TYPEID_PLAYER
)
3238 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true,true);
3240 // feral or unarmed skill only for base attack
3241 if(attType
!= BASE_ATTACK
&& !item
)
3245 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
3247 // weapon skill or (unarmed for base attack)
3248 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
3250 // in PvP use full skill instead current skill value
3251 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3252 ? ((Player
*)this)->GetMaxSkillValue(skill
)
3253 : ((Player
*)this)->GetSkillValue(skill
);
3254 // Modify value from ratings
3255 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
3258 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
3259 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
3260 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
3264 value
= GetUnitMeleeSkill(target
);
3268 void Unit::_UpdateSpells( uint32 time
)
3270 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
3271 _UpdateAutoRepeatSpell();
3273 // remove finished spells from current pointers
3274 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3276 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
3278 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
3279 m_currentSpells
[i
] = NULL
; // remove pointer
3284 // m_AurasUpdateIterator can be updated in inderect called code at aura remove to skip next planned to update but removed auras
3285 for (m_AurasUpdateIterator
= m_Auras
.begin(); m_AurasUpdateIterator
!= m_Auras
.end();)
3287 Aura
* i_aura
= m_AurasUpdateIterator
->second
;
3288 ++m_AurasUpdateIterator
; // need shift to next for allow update if need into aura update
3289 i_aura
->UpdateAura(time
);
3292 // remove expired auras
3293 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
3297 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
3306 if(!m_gameObj
.empty())
3308 GameObjectList::iterator ite1
, dnext1
;
3309 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
3312 //(*i)->Update( difftime );
3313 if( !(*ite1
)->isSpawned() )
3315 (*ite1
)->SetOwnerGUID(0);
3316 (*ite1
)->SetRespawnTime(0);
3318 dnext1
= m_gameObj
.erase(ite1
);
3326 void Unit::_UpdateAutoRepeatSpell()
3328 bool isAutoShot
= m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
== SPELL_ID_AUTOSHOT
;
3331 if (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving())
3333 // cancel wand shoot
3335 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3336 // auto shot just waits
3340 // check spell casts
3341 if (IsNonMeleeSpellCasted(false, false, true))
3343 // cancel wand shoot
3346 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3349 // auto shot is delayed by everythihng, except ranged(!) CURRENT_GENERIC_SPELL's -> recheck that
3350 else if (!(m_currentSpells
[CURRENT_GENERIC_SPELL
] && m_currentSpells
[CURRENT_GENERIC_SPELL
]->IsRangedSpell()))
3355 if (isAttackReady(RANGED_ATTACK
))
3357 // Check if able to cast
3358 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CheckCast(true) != SPELL_CAST_OK
)
3360 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3365 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
3366 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
3368 // all went good, reset attack
3369 resetAttackTimer(RANGED_ATTACK
);
3373 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
3375 ASSERT(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
3377 CurrentSpellTypes CSpellType
= pSpell
->GetCurrentContainer();
3379 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
3381 // break same type spell if it is not delayed
3382 InterruptSpell(CSpellType
,false);
3384 // special breakage effects:
3387 case CURRENT_GENERIC_SPELL
:
3389 // generic spells always break channeled not delayed spells
3390 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3392 // autorepeat breaking
3393 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3395 // break autorepeat if not Auto Shot
3396 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3397 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3401 case CURRENT_CHANNELED_SPELL
:
3403 // channel spells always break generic non-delayed and any channeled spells
3404 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3405 InterruptSpell(CURRENT_CHANNELED_SPELL
);
3407 // it also does break autorepeat if not Auto Shot
3408 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
3409 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3410 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3413 case CURRENT_AUTOREPEAT_SPELL
:
3415 // only Auto Shoot does not break anything
3416 if (pSpell
->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3418 // generic autorepeats break generic non-delayed and channeled non-delayed spells
3419 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3420 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3421 // special action: first cast delay
3422 if ( getAttackTimer(RANGED_ATTACK
) < 500 )
3423 setAttackTimer(RANGED_ATTACK
,500);
3429 // other spell types don't break anything now
3433 // current spell (if it is still here) may be safely deleted now
3434 if (m_currentSpells
[CSpellType
])
3435 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
3437 // set new current spell
3438 m_currentSpells
[CSpellType
] = pSpell
;
3439 pSpell
->SetReferencedFromCurrent(true);
3441 pSpell
->m_selfContainer
= &(m_currentSpells
[pSpell
->GetCurrentContainer()]);
3444 void Unit::InterruptSpell(CurrentSpellTypes spellType
, bool withDelayed
, bool sendAutoRepeatCancelToClient
)
3446 ASSERT(spellType
< CURRENT_MAX_SPELL
);
3448 if (m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
3450 // send autorepeat cancel message for autorepeat spells
3451 if (spellType
== CURRENT_AUTOREPEAT_SPELL
&& sendAutoRepeatCancelToClient
)
3453 if(GetTypeId() == TYPEID_PLAYER
)
3454 ((Player
*)this)->SendAutoRepeatCancel(this);
3457 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
3458 m_currentSpells
[spellType
]->cancel();
3460 // cancel can interrupt spell already (caster cancel ->target aura remove -> caster iterrupt)
3461 if (m_currentSpells
[spellType
])
3463 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
3464 m_currentSpells
[spellType
] = NULL
;
3469 void Unit::FinishSpell(CurrentSpellTypes spellType
, bool ok
/*= true*/)
3471 Spell
* spell
= m_currentSpells
[spellType
];
3475 if (spellType
== CURRENT_CHANNELED_SPELL
)
3476 spell
->SendChannelUpdate(0);
3482 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
3484 // We don't do loop here to explicitly show that melee spell is excluded.
3485 // Maybe later some special spells will be excluded too.
3487 // generic spells are casted when they are not finished and not delayed
3488 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
3489 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3490 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3493 // channeled spells may be delayed, but they are still considered casted
3494 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
3495 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
3498 // autorepeat spells may be finished or delayed, but they are still considered casted
3499 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3505 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
3507 // generic spells are interrupted if they are not finished or delayed
3508 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
3509 InterruptSpell(CURRENT_GENERIC_SPELL
,withDelayed
);
3511 // autorepeat spells are interrupted if they are not finished or delayed
3512 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
3513 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
,withDelayed
);
3515 // channeled spells are interrupted if they are not finished, even if they are delayed
3516 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
3517 InterruptSpell(CURRENT_CHANNELED_SPELL
,true);
3520 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
3522 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3523 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
3524 return m_currentSpells
[i
];
3528 void Unit::SetInFront(Unit
const* target
)
3530 SetOrientation(GetAngle(target
));
3533 void Unit::SetFacingTo(float ori
)
3535 // update orientation at server
3536 SetOrientation(ori
);
3540 BuildHeartBeatMsg(&data
);
3541 SendMessageToSet(&data
, false);
3544 // Consider move this to Creature:: since only creature appear to be able to use this
3545 void Unit::SetFacingToObject(WorldObject
* pObject
)
3547 if (GetTypeId() != TYPEID_UNIT
)
3550 // never face when already moving
3554 // TODO: figure out under what conditions creature will move towards object instead of facing it where it currently is.
3556 SetOrientation(GetAngle(pObject
));
3557 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_FACINGTARGET
, ((Creature
*)this)->GetSplineFlags(), 0, NULL
, pObject
->GetGUID());
3560 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
3563 return c
->canSwim();
3565 return c
->canWalk() || c
->canFly();
3568 bool Unit::IsInWater() const
3570 return GetBaseMap()->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
3573 bool Unit::IsUnderWater() const
3575 return GetBaseMap()->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3578 void Unit::DeMorph()
3580 SetDisplayId(GetNativeDisplayId());
3583 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3587 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3588 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3589 modifier
+= (*i
)->GetModifier()->m_amount
;
3594 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3596 float multiplier
= 1.0f
;
3598 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3599 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3600 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3605 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3609 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3610 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3611 if ((*i
)->GetModifier()->m_amount
> modifier
)
3612 modifier
= (*i
)->GetModifier()->m_amount
;
3617 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
3621 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3622 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3623 if ((*i
)->GetModifier()->m_amount
< modifier
)
3624 modifier
= (*i
)->GetModifier()->m_amount
;
3629 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3636 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3637 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3639 Modifier
* mod
= (*i
)->GetModifier();
3640 if (mod
->m_miscvalue
& misc_mask
)
3641 modifier
+= mod
->m_amount
;
3646 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3651 float multiplier
= 1.0f
;
3653 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3654 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3656 Modifier
* mod
= (*i
)->GetModifier();
3657 if (mod
->m_miscvalue
& misc_mask
)
3658 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3663 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3670 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3671 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3673 Modifier
* mod
= (*i
)->GetModifier();
3674 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
> modifier
)
3675 modifier
= mod
->m_amount
;
3681 int32
Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
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
&& mod
->m_amount
< modifier
)
3693 modifier
= mod
->m_amount
;
3699 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3703 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3704 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3706 Modifier
* mod
= (*i
)->GetModifier();
3707 if (mod
->m_miscvalue
== misc_value
)
3708 modifier
+= mod
->m_amount
;
3713 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
3715 float multiplier
= 1.0f
;
3717 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3718 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3720 Modifier
* mod
= (*i
)->GetModifier();
3721 if (mod
->m_miscvalue
== misc_value
)
3722 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3727 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3731 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3732 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3734 Modifier
* mod
= (*i
)->GetModifier();
3735 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
3736 modifier
= mod
->m_amount
;
3742 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3746 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3747 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3749 Modifier
* mod
= (*i
)->GetModifier();
3750 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
< modifier
)
3751 modifier
= mod
->m_amount
;
3757 float Unit::GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype
, uint32 mask
) const
3762 float multiplier
= 1.0f
;
3764 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3765 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3767 Modifier
* mod
= (*i
)->GetModifier();
3768 if (mask
& (1 << (mod
->m_miscvalue
-1)))
3769 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3774 bool Unit::AddAura(Aura
*Aur
)
3776 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
3778 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
3779 if( !isAlive() && !IsDeathPersistentSpell(aurSpellInfo
) &&
3780 !IsDeathOnlySpell(aurSpellInfo
) &&
3781 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
3787 if(Aur
->GetTarget() != this)
3789 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
3790 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
3791 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
3796 // m_auraname can be modified to SPELL_AURA_NONE for area auras, this expected for this value
3797 AuraType aurName
= Aur
->GetModifier()->m_auraname
;
3799 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
3800 AuraMap::iterator i
= m_Auras
.find( spair
);
3802 // take out same spell
3803 if (i
!= m_Auras
.end())
3805 // passive and persistent auras can stack with themselves any number of times
3806 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
3808 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
3810 Aura
* aur2
= i2
->second
;
3811 if(aur2
->GetCasterGUID()==Aur
->GetCasterGUID())
3813 // Aura can stack on self -> Stack it;
3814 if(aurSpellInfo
->StackAmount
)
3816 // can be created with >1 stack by some spell mods
3817 aur2
->modStackAmount(Aur
->GetStackAmount());
3822 // Check for coexisting Weapon-proced Auras
3823 if (Aur
->isWeaponBuffCoexistableWith(aur2
))
3826 // Carry over removed Aura's remaining damage if Aura still has ticks remaining
3827 if (aur2
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_STACK_DOT_MODIFIER
&& aurName
== SPELL_AURA_PERIODIC_DAMAGE
&& aur2
->GetAuraDuration() > 0)
3829 int32 remainingTicks
= aur2
->GetAuraMaxTicks() - aur2
->GetAuraTicks();
3830 int32 remainingDamage
= aur2
->GetModifier()->m_amount
* remainingTicks
;
3832 Aur
->GetModifier()->m_amount
+= int32(remainingDamage
/ Aur
->GetAuraMaxTicks());
3834 // can be only single (this check done at _each_ aura add
3835 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3841 // m_auraname can be modified to SPELL_AURA_NONE for area auras, use original
3842 AuraType aurNameReal
= AuraType(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()]);
3847 case SPELL_AURA_DUMMY
: // allow stack
3848 case SPELL_AURA_PERIODIC_DAMAGE
:
3849 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
3850 case SPELL_AURA_PERIODIC_LEECH
:
3851 case SPELL_AURA_PERIODIC_HEAL
:
3852 case SPELL_AURA_OBS_MOD_HEALTH
:
3853 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3854 case SPELL_AURA_OBS_MOD_MANA
:
3855 case SPELL_AURA_POWER_BURN_MANA
:
3857 case SPELL_AURA_PERIODIC_ENERGIZE
: // all or self or clear non-stackable
3858 default: // not allow
3859 // can be only single (this check done at _each_ aura add
3860 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3871 // passive auras not stacable with other ranks
3872 if (!IsPassiveSpellStackableWithRanks(aurSpellInfo
))
3874 if (!RemoveNoStackAurasDueToAura(Aur
))
3877 return false; // couldn't remove conflicting aura with higher rank
3881 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
3882 if (Aur
->IsSingleTarget() && Aur
->GetTarget())
3884 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
3887 Unit
* caster
= Aur
->GetCaster();
3888 if(!caster
) // caster deleted and not required adding scAura
3891 bool restart
= false;
3892 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3893 for(AuraList::const_iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
3895 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
3896 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
3898 if ((*itr
)->IsInUse())
3900 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());
3903 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
3912 scAuras
.push_back(Aur
);
3918 // add aura, register in lists and arrays
3920 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
3921 if (aurName
< TOTAL_AURAS
)
3923 m_modAuras
[aurName
].push_back(Aur
);
3926 Aur
->ApplyModifier(true,true);
3927 DEBUG_LOG("Aura %u now is in use", aurName
);
3929 // if aura deleted before boosts apply ignore
3930 // this can be possible it it removed indirectly by triggered spell effect at ApplyModifier
3931 if (Aur
->IsDeleted())
3934 if(IsSpellLastAuraEffect(aurSpellInfo
,Aur
->GetEffIndex()))
3935 Aur
->HandleSpellSpecificBoosts(true);
3940 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
3942 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3945 AuraMap::const_iterator i
,next
;
3946 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3950 uint32 i_spellId
= (*i
).second
->GetId();
3951 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
3953 if(sSpellMgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
3955 RemoveAurasDueToSpell(i_spellId
);
3957 if( m_Auras
.empty() )
3960 next
= m_Auras
.begin();
3966 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
3971 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
3975 uint32 spellId
= Aur
->GetId();
3976 SpellEffectIndex effIndex
= Aur
->GetEffIndex();
3978 // passive spell special case (only non stackable with ranks)
3979 if(IsPassiveSpell(spellId
))
3981 if(IsPassiveSpellStackableWithRanks(spellProto
))
3985 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
3987 AuraMap::iterator i
,next
;
3988 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3992 if (!(*i
).second
) continue;
3994 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
3999 uint32 i_spellId
= i_spellProto
->Id
;
4001 // early checks that spellId is passive non stackable spell
4002 if(IsPassiveSpell(i_spellId
))
4004 // passive non-stackable spells not stackable only for same caster
4005 if(Aur
->GetCasterGUID()!=i
->second
->GetCasterGUID())
4008 // passive non-stackable spells not stackable only with another rank of same spell
4009 if (!sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4013 SpellEffectIndex i_effIndex
= (*i
).second
->GetEffIndex();
4015 if(i_spellId
== spellId
) continue;
4017 bool is_triggered_by_spell
= false;
4018 // prevent triggering aura of removing aura that triggered it
4019 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4020 if (i_spellProto
->EffectTriggerSpell
[j
] == spellId
)
4021 is_triggered_by_spell
= true;
4023 // prevent triggered aura of removing aura that triggering it (triggered effect early some aura of parent spell
4024 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4025 if (spellProto
->EffectTriggerSpell
[j
] == i_spellId
)
4026 is_triggered_by_spell
= true;
4028 if (is_triggered_by_spell
)
4031 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
4033 // single allowed spell specific from same caster or from any caster at target
4034 bool is_spellSpecPerTargetPerCaster
= IsSingleFromSpellSpecificPerTargetPerCaster(spellId_spec
,i_spellId_spec
);
4035 bool is_spellSpecPerTarget
= IsSingleFromSpellSpecificPerTarget(spellId_spec
,i_spellId_spec
);
4036 if( is_spellSpecPerTarget
|| is_spellSpecPerTargetPerCaster
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
4038 // cannot remove higher rank
4039 if (sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4040 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4043 // Its a parent aura (create this aura in ApplyModifier)
4044 if ((*i
).second
->IsInUse())
4046 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());
4049 RemoveAurasDueToSpell(i_spellId
);
4051 if( m_Auras
.empty() )
4054 next
= m_Auras
.begin();
4059 // spell with spell specific that allow single ranks for spell from diff caster
4060 // same caster case processed or early or later
4061 bool is_spellPerTarget
= IsSingleFromSpellSpecificSpellRanksPerTarget(spellId_spec
,i_spellId_spec
);
4062 if ( is_spellPerTarget
&& Aur
->GetCasterGUID() != (*i
).second
->GetCasterGUID() && sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4064 // cannot remove higher rank
4065 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4068 // Its a parent aura (create this aura in ApplyModifier)
4069 if ((*i
).second
->IsInUse())
4071 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());
4074 RemoveAurasDueToSpell(i_spellId
);
4076 if( m_Auras
.empty() )
4079 next
= m_Auras
.begin();
4084 // non single (per caster) per target spell specific (possible single spell per target at caster)
4085 if( !is_spellSpecPerTargetPerCaster
&& !is_spellSpecPerTarget
&& sSpellMgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
4087 // Its a parent aura (create this aura in ApplyModifier)
4088 if ((*i
).second
->IsInUse())
4090 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());
4093 RemoveAurasDueToSpell(i_spellId
);
4095 if( m_Auras
.empty() )
4098 next
= m_Auras
.begin();
4103 // Potions stack aura by aura (elixirs/flask already checked)
4104 if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
4106 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
4108 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4109 return false; // cannot remove higher rank
4111 // Its a parent aura (create this aura in ApplyModifier)
4112 if ((*i
).second
->IsInUse())
4114 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());
4125 void Unit::RemoveAura(uint32 spellId
, SpellEffectIndex effindex
, Aura
* except
)
4127 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4128 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4130 if(iter
->second
!=except
)
4133 iter
= m_Auras
.lower_bound(spair
);
4140 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
)
4142 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4144 Aura
*aur
= iter
->second
;
4145 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4152 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, SpellEffectIndex effindex
, uint64 casterGUID
)
4154 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4155 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4157 Aura
*aur
= iter
->second
;
4158 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4161 iter
= m_Auras
.lower_bound(spair
);
4168 void Unit::RemoveSingleAuraDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
4170 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(spellId
);
4172 // Custom dispel cases
4173 // Unstable Affliction
4174 if(spellEntry
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x010000000000)))
4176 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
,SPELLFAMILY_WARLOCK
,UI64LIT(0x010000000000),0x00000000,casterGUID
))
4178 // use clean value for initial damage
4179 int32 damage
= dotAura
->GetSpellProto()->CalculateSimpleValue(EFFECT_INDEX_0
);
4182 // Remove spell auras from stack
4183 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4185 // backfire damage and silence
4186 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,casterGUID
);
4191 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x10000000)))
4193 Unit
* caster
= NULL
;
4194 uint32 triggeredSpell
= 0;
4196 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x10000000), 0x00000000, casterGUID
))
4197 caster
= dotAura
->GetCaster();
4199 if (caster
&& !caster
->isDead())
4201 Unit::AuraList
const& auras
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
4202 for (Unit::AuraList::const_iterator i
= auras
.begin(); i
!= auras
.end(); ++i
)
4204 switch((*i
)->GetId())
4206 case 51480: triggeredSpell
=64694; break;// Lava Flows, Rank 1
4207 case 51481: triggeredSpell
=65263; break;// Lava Flows, Rank 2
4208 case 51482: triggeredSpell
=65264; break;// Lava Flows, Rank 3
4215 // Remove spell auras from stack
4216 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4220 caster
->CastSpell(caster
, triggeredSpell
, true);
4223 // Vampiric touch (first dummy aura)
4224 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_PRIEST
&& spellEntry
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
4226 if (Aura
*dot
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000040000000000), 0x00000000, casterGUID
))
4228 if(Unit
* caster
= dot
->GetCaster())
4230 // use clean value for initial damage
4231 int32 bp0
= dot
->GetSpellProto()->CalculateSimpleValue(EFFECT_INDEX_1
);
4234 // Remove spell auras from stack
4235 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4237 CastCustomSpell(this, 64085, &bp0
, NULL
, NULL
, true, NULL
, NULL
, casterGUID
);
4243 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4246 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
4248 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4250 Aura
*aur
= iter
->second
;
4251 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4253 int32 basePoints
= aur
->GetBasePoints();
4254 // construct the new aura for the attacker - will never return NULL, it's just a wrapper for
4255 // some different constructors
4256 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
, this);
4258 // set its duration and maximum duration
4259 // max duration 2 minutes (in msecs)
4260 int32 dur
= aur
->GetAuraDuration();
4261 int32 max_dur
= 2*MINUTE
*IN_MILLISECONDS
;
4262 int32 new_max_dur
= max_dur
> dur
? dur
: max_dur
;
4263 new_aur
->SetAuraMaxDuration( new_max_dur
);
4264 new_aur
->SetAuraDuration( new_max_dur
);
4266 // set periodic to do at least one tick (for case when original aura has been at last tick preparing)
4267 int32 periodic
= aur
->GetModifier()->periodictime
;
4268 new_aur
->GetModifier()->periodictime
= periodic
< new_max_dur
? periodic
: new_max_dur
;
4270 // Unregister _before_ adding to stealer
4271 aur
->UnregisterSingleCastAura();
4273 // strange but intended behaviour: Stolen single target auras won't be treated as single targeted
4274 new_aur
->SetIsSingleTarget(false);
4276 // add the new aura to stealer
4277 stealer
->AddAura(new_aur
);
4279 // Remove aura as dispel
4280 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
4287 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
4289 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4291 if (iter
->second
->GetId() == spellId
)
4292 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
4298 void Unit::RemoveAurasWithDispelType( DispelType type
)
4300 // Create dispel mask by dispel type
4301 uint32 dispelMask
= GetDispellMask(type
);
4302 // Dispel all existing auras vs current dispel type
4303 AuraMap
& auras
= GetAuras();
4304 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
4306 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
4307 if( (1<<spell
->Dispel
) & dispelMask
)
4310 RemoveAurasDueToSpell(spell
->Id
);
4311 itr
= auras
.begin();
4318 void Unit::RemoveSingleAuraFromStack(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4320 if (i
->second
->modStackAmount(-1))
4325 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, SpellEffectIndex effindex
, AuraRemoveMode mode
)
4327 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4328 if(iter
!= m_Auras
.end())
4329 RemoveSingleAuraFromStack(iter
,mode
);
4332 void Unit::RemoveSingleSpellAurasFromStack(uint32 spellId
, AuraRemoveMode mode
)
4334 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4335 RemoveSingleAuraFromStack(spellId
, SpellEffectIndex(i
), mode
);
4338 void Unit::RemoveSingleSpellAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
, AuraRemoveMode mode
)
4340 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4341 RemoveSingleAuraByCasterSpell(spellId
, SpellEffectIndex(i
), casterGUID
, mode
);
4344 void Unit::RemoveSingleAuraByCasterSpell(uint32 spellId
, SpellEffectIndex effindex
, uint64 casterGUID
, AuraRemoveMode mode
)
4346 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4347 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
); ++iter
)
4349 Aura
*aur
= iter
->second
;
4350 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4352 RemoveSingleAuraFromStack(iter
,mode
);
4359 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
)
4361 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4362 RemoveAura(spellId
,SpellEffectIndex(i
),except
);
4365 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
4367 for (int k
=0; k
< MAX_EFFECT_INDEX
; ++k
)
4369 spellEffectPair spair
= spellEffectPair(spellId
, SpellEffectIndex(k
));
4370 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4372 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
4375 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
4383 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
4385 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4387 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
4394 void Unit::RemoveNotOwnSingleTargetAuras(uint32 newPhase
)
4396 // single target auras from other casters
4397 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4399 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
4405 Unit
* caster
= iter
->second
->GetCaster();
4406 if(!caster
|| !caster
->InSamePhase(newPhase
))
4416 // single target auras at other targets
4417 AuraList
& scAuras
= GetSingleCastAuras();
4418 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
4421 if (aura
->GetTarget() != this && !aura
->GetTarget()->InSamePhase(newPhase
))
4423 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
4424 aura
->GetTarget()->RemoveAura(aura
);
4425 iter
= scAuras
.begin();
4433 void Unit::RemoveAura(Aura
* aura
, AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4435 AuraMap::iterator i
= m_Auras
.lower_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4436 AuraMap::iterator upperBound
= m_Auras
.upper_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4437 for (; i
!= upperBound
; ++i
)
4439 if (i
->second
== aura
)
4445 DEBUG_LOG("Trying to remove aura id %u effect %u by pointer but aura not found on target", aura
->GetId(), aura
->GetEffIndex());
4448 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4450 Aura
* Aur
= i
->second
;
4451 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
4453 Aur
->UnregisterSingleCastAura();
4455 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
4456 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
4458 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
4462 Aur
->SetRemoveMode(mode
);
4464 // if unit currently update aura list then make safe update iterator shift to next
4465 if (m_AurasUpdateIterator
== i
)
4466 ++m_AurasUpdateIterator
;
4468 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
4469 // remove aura from list before to prevent deleting it before
4472 // now aura removed from from list and can't be deleted by indirect call but can be referenced from callers
4474 // Statue unsummoned at aura remove
4475 Totem
* statue
= NULL
;
4476 if(IsChanneledSpell(AurSpellInfo
))
4477 if(Unit
* caster
= Aur
->GetCaster())
4478 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
4479 statue
= ((Totem
*)caster
);
4481 DEBUG_LOG("Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
4483 // some auras also need to apply modifier (on caster) on remove
4484 if (mode
!= AURA_REMOVE_BY_DELETE
|| Aur
->GetModifier()->m_auraname
== SPELL_AURA_MOD_POSSESS
)
4485 Aur
->ApplyModifier(false,true);
4487 if (Aur
->_RemoveAura())
4489 // last aura in stack removed
4490 if (mode
!= AURA_REMOVE_BY_DELETE
&& IsSpellLastAuraEffect(Aur
->GetSpellProto(),Aur
->GetEffIndex()))
4491 Aur
->HandleSpellSpecificBoosts(false);
4494 // If aura in use (removed from code that plan access to it data after return)
4495 // store it in aura list with delayed deletion
4497 m_deletedAuras
.push_back(Aur
);
4504 // only way correctly remove all auras from list
4505 if( m_Auras
.empty() )
4508 i
= m_Auras
.begin();
4512 void Unit::RemoveAllAuras(AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4514 while (!m_Auras
.empty())
4516 AuraMap::iterator iter
= m_Auras
.begin();
4517 RemoveAura(iter
,mode
);
4521 void Unit::RemoveArenaAuras(bool onleave
)
4523 // in join, remove positive buffs, on end, remove negative
4524 // used to remove positive visible auras in arenas
4525 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4527 if (!(iter
->second
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_UNK21
) &&
4528 // don't remove stances, shadowform, pally/hunter auras
4529 !iter
->second
->IsPassive() && // don't remove passive auras
4530 (!(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
) ||
4531 !(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNK8
)) &&
4532 // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable)
4533 (iter
->second
->IsPositive() != onleave
)) // remove positive buffs on enter, negative buffs on leave
4540 void Unit::RemoveAllAurasOnDeath()
4542 // used just after dieing to remove all visible auras
4543 // and disable the mods for the passive ones
4544 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4546 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
4547 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
4553 void Unit::DelayAura(uint32 spellId
, SpellEffectIndex effindex
, int32 delaytime
)
4555 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4556 if (iter
!= m_Auras
.end())
4558 if (iter
->second
->GetAuraDuration() < delaytime
)
4559 iter
->second
->SetAuraDuration(0);
4561 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
4562 iter
->second
->SendAuraUpdate(false);
4563 DEBUG_LOG("Aura %u partially interrupted on unit %u, new duration: %u ms",iter
->second
->GetModifier()->m_auraname
, GetGUIDLow(), iter
->second
->GetAuraDuration());
4567 void Unit::_RemoveAllAuraMods()
4569 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4571 (*i
).second
->ApplyModifier(false);
4575 void Unit::_ApplyAllAuraMods()
4577 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4579 (*i
).second
->ApplyModifier(true);
4583 Aura
* Unit::GetAura(uint32 spellId
, SpellEffectIndex effindex
)
4585 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4586 if (iter
!= m_Auras
.end())
4587 return iter
->second
;
4591 Aura
* Unit::GetAura(AuraType type
, uint32 family
, uint64 familyFlag
, uint32 familyFlag2
, uint64 casterGUID
)
4593 AuraList
const& auras
= GetAurasByType(type
);
4594 for(AuraList::const_iterator i
= auras
.begin();i
!= auras
.end(); ++i
)
4596 SpellEntry
const *spell
= (*i
)->GetSpellProto();
4597 if (spell
->SpellFamilyName
== family
&& (spell
->SpellFamilyFlags
& familyFlag
|| spell
->SpellFamilyFlags2
& familyFlag2
))
4599 if (casterGUID
&& (*i
)->GetCasterGUID()!=casterGUID
)
4607 bool Unit::HasAura(uint32 spellId
) const
4609 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4611 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, SpellEffectIndex(i
)));
4612 if (iter
!= m_Auras
.end())
4618 void Unit::AddDynObject(DynamicObject
* dynObj
)
4620 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
4623 void Unit::RemoveDynObject(uint32 spellid
)
4625 if(m_dynObjGUIDs
.empty())
4627 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4629 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4632 i
= m_dynObjGUIDs
.erase(i
);
4634 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
4637 i
= m_dynObjGUIDs
.erase(i
);
4644 void Unit::RemoveAllDynObjects()
4646 while(!m_dynObjGUIDs
.empty())
4648 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*m_dynObjGUIDs
.begin());
4651 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
4655 DynamicObject
* Unit::GetDynObject(uint32 spellId
, SpellEffectIndex effIndex
)
4657 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4659 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4662 i
= m_dynObjGUIDs
.erase(i
);
4666 if (dynObj
->GetSpellId() == spellId
&& dynObj
->GetEffIndex() == effIndex
)
4673 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
4675 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4677 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4680 i
= m_dynObjGUIDs
.erase(i
);
4684 if (dynObj
->GetSpellId() == spellId
)
4691 GameObject
* Unit::GetGameObject(uint32 spellId
) const
4693 for (GameObjectList::const_iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); ++i
)
4694 if ((*i
)->GetSpellId() == spellId
)
4700 void Unit::AddGameObject(GameObject
* gameObj
)
4702 ASSERT(gameObj
&& gameObj
->GetOwnerGUID()==0);
4703 m_gameObj
.push_back(gameObj
);
4704 gameObj
->SetOwnerGUID(GetGUID());
4706 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
4708 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
4709 // Need disable spell use for owner
4710 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4711 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4712 ((Player
*)this)->AddSpellAndCategoryCooldowns(createBySpell
,0,NULL
,true);
4716 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
4718 ASSERT(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
4720 gameObj
->SetOwnerGUID(0);
4722 // GO created by some spell
4723 if (uint32 spellid
= gameObj
->GetSpellId())
4725 RemoveAurasDueToSpell(spellid
);
4727 if (GetTypeId()==TYPEID_PLAYER
)
4729 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(spellid
);
4730 // Need activate spell use for owner
4731 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4732 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4733 ((Player
*)this)->SendCooldownEvent(createBySpell
);
4737 m_gameObj
.remove(gameObj
);
4741 gameObj
->SetRespawnTime(0);
4746 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
4748 if(m_gameObj
.empty())
4750 GameObjectList::iterator i
, next
;
4751 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
4754 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
4756 (*i
)->SetOwnerGUID(0);
4759 (*i
)->SetRespawnTime(0);
4763 next
= m_gameObj
.erase(i
);
4770 void Unit::RemoveAllGameObjects()
4772 // remove references to unit
4773 for(GameObjectList::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4775 (*i
)->SetOwnerGUID(0);
4776 (*i
)->SetRespawnTime(0);
4778 i
= m_gameObj
.erase(i
);
4782 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
4784 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+4+1+4+4+1+1+4+4+1)); // we guess size
4785 data
<< log
->target
->GetPackGUID();
4786 data
<< log
->attacker
->GetPackGUID();
4787 data
<< uint32(log
->SpellID
);
4788 data
<< uint32(log
->damage
); // damage amount
4789 data
<< uint32(log
->overkill
); // overkill
4790 data
<< uint8 (log
->schoolMask
); // damage school
4791 data
<< uint32(log
->absorb
); // AbsorbedDamage
4792 data
<< uint32(log
->resist
); // resist
4793 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
4794 data
<< uint8 (log
->unused
); // unused
4795 data
<< uint32(log
->blocked
); // blocked
4796 data
<< uint32(log
->HitInfo
);
4797 data
<< uint8 (0); // flag to use extend data
4798 SendMessageToSet( &data
, true );
4801 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
, uint32 SpellID
, uint32 Damage
, SpellSchoolMask damageSchoolMask
, uint32 AbsorbedDamage
, uint32 Resist
, bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
4803 SpellNonMeleeDamage
log(this, target
, SpellID
, damageSchoolMask
);
4804 log
.damage
= Damage
- AbsorbedDamage
- Resist
- Blocked
;
4805 log
.absorb
= AbsorbedDamage
;
4806 log
.resist
= Resist
;
4807 log
.physicalLog
= PhysicalDamage
;
4808 log
.blocked
= Blocked
;
4809 log
.HitInfo
= SPELL_HIT_TYPE_UNK1
| SPELL_HIT_TYPE_UNK3
| SPELL_HIT_TYPE_UNK6
;
4811 log
.HitInfo
|= SPELL_HIT_TYPE_CRIT
;
4812 SendSpellNonMeleeDamageLog(&log
);
4815 void Unit::SendPeriodicAuraLog(SpellPeriodicAuraLogInfo
*pInfo
)
4817 Aura
*aura
= pInfo
->aura
;
4818 Modifier
*mod
= aura
->GetModifier();
4820 WorldPacket
data(SMSG_PERIODICAURALOG
, 30);
4821 data
<< aura
->GetTarget()->GetPackGUID();
4822 data
.appendPackGUID(aura
->GetCasterGUID());
4823 data
<< uint32(aura
->GetId()); // spellId
4824 data
<< uint32(1); // count
4825 data
<< uint32(mod
->m_auraname
); // auraId
4826 switch(mod
->m_auraname
)
4828 case SPELL_AURA_PERIODIC_DAMAGE
:
4829 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
4830 data
<< uint32(pInfo
->damage
); // damage
4831 data
<< uint32(pInfo
->overDamage
); // overkill?
4832 data
<< uint32(GetSpellSchoolMask(aura
->GetSpellProto()));
4833 data
<< uint32(pInfo
->absorb
); // absorb
4834 data
<< uint32(pInfo
->resist
); // resist
4835 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4837 case SPELL_AURA_PERIODIC_HEAL
:
4838 case SPELL_AURA_OBS_MOD_HEALTH
:
4839 data
<< uint32(pInfo
->damage
); // damage
4840 data
<< uint32(pInfo
->overDamage
); // overheal?
4841 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4843 case SPELL_AURA_OBS_MOD_MANA
:
4844 case SPELL_AURA_PERIODIC_ENERGIZE
:
4845 data
<< uint32(mod
->m_miscvalue
); // power type
4846 data
<< uint32(pInfo
->damage
); // damage
4848 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4849 data
<< uint32(mod
->m_miscvalue
); // power type
4850 data
<< uint32(pInfo
->damage
); // amount
4851 data
<< float(pInfo
->multiplier
); // gain multiplier
4854 sLog
.outError("Unit::SendPeriodicAuraLog: unknown aura %u", uint32(mod
->m_auraname
));
4858 aura
->GetTarget()->SendMessageToSet(&data
, true);
4861 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
4863 // Not much to do if no flags are set.
4865 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
4866 // Now go on with a victim's events'n'auras
4867 // Not much to do if no flags are set or there is no victim
4868 if(pVictim
&& pVictim
->isAlive() && procVictim
)
4869 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4872 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4874 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4875 data
<< uint32(spellID
);
4876 data
<< uint64(GetGUID());
4877 data
<< uint8(0); // can be 0 or 1
4878 data
<< uint32(1); // target count
4879 // for(i = 0; i < target count; ++i)
4880 data
<< uint64(target
->GetGUID()); // target GUID
4881 data
<< uint8(missInfo
);
4883 SendMessageToSet(&data
, true);
4886 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4888 DEBUG_LOG("WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4891 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, 16 + 45); // we guess size
4892 data
<< uint32(damageInfo
->HitInfo
);
4893 data
<< damageInfo
->attacker
->GetPackGUID();
4894 data
<< damageInfo
->target
->GetPackGUID();
4895 data
<< uint32(damageInfo
->damage
); // Full damage
4896 data
<< uint32(0); // overkill value
4897 data
<< uint8(count
); // Sub damage count
4899 for(uint32 i
= 0; i
< count
; ++i
)
4901 data
<< uint32(damageInfo
->damageSchoolMask
); // School of sub damage
4902 data
<< float(damageInfo
->damage
); // sub damage
4903 data
<< uint32(damageInfo
->damage
); // Sub Damage
4906 if(damageInfo
->HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4908 for(uint32 i
= 0; i
< count
; ++i
)
4909 data
<< uint32(damageInfo
->absorb
); // Absorb
4912 if(damageInfo
->HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4914 for(uint32 i
= 0; i
< count
; ++i
)
4915 data
<< uint32(damageInfo
->resist
); // Resist
4918 data
<< uint8(damageInfo
->TargetState
);
4922 if(damageInfo
->HitInfo
& HITINFO_BLOCK
)
4923 data
<< uint32(damageInfo
->blocked_amount
);
4925 if(damageInfo
->HitInfo
& HITINFO_UNK3
)
4928 if(damageInfo
->HitInfo
& HITINFO_UNK1
)
4939 for(uint8 i
= 0; i
< 5; ++i
)
4947 SendMessageToSet( &data
, true );
4950 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8
/*SwingType*/, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4952 CalcDamageInfo dmgInfo
;
4953 dmgInfo
.HitInfo
= HitInfo
;
4954 dmgInfo
.attacker
= this;
4955 dmgInfo
.target
= target
;
4956 dmgInfo
.damage
= Damage
- AbsorbDamage
- Resist
- BlockedAmount
;
4957 dmgInfo
.damageSchoolMask
= damageSchoolMask
;
4958 dmgInfo
.absorb
= AbsorbDamage
;
4959 dmgInfo
.resist
= Resist
;
4960 dmgInfo
.TargetState
= TargetState
;
4961 dmgInfo
.blocked_amount
= BlockedAmount
;
4962 SendAttackStateUpdate(&dmgInfo
);
4965 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4967 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
4969 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4970 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4972 uint32 triggered_spell_id
= 0;
4973 Unit
* target
= pVictim
;
4974 int32 basepoints0
= 0;
4976 switch(hasteSpell
->SpellFamilyName
)
4978 case SPELLFAMILY_ROGUE
:
4980 switch(hasteSpell
->Id
)
4986 target
= SelectRandomUnfriendlyTarget(pVictim
);
4989 basepoints0
= damage
;
4990 triggered_spell_id
= 22482;
4998 // processed charge only counting case
4999 if(!triggered_spell_id
)
5002 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5006 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
5011 if(!target
|| target
!=this && !target
->isAlive())
5014 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5018 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5020 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5022 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5023 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5028 bool Unit::HandleSpellCritChanceAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
5030 SpellEntry
const *triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
5032 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5033 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5035 uint32 triggered_spell_id
= 0;
5036 Unit
* target
= pVictim
;
5037 int32 basepoints0
= 0;
5039 switch(triggeredByAuraSpell
->SpellFamilyName
)
5041 case SPELLFAMILY_MAGE
:
5043 switch(triggeredByAuraSpell
->Id
)
5048 Unit
* caster
= triggeredByAura
->GetCaster();
5052 triggered_spell_id
= 54648;
5060 // processed charge only counting case
5061 if(!triggered_spell_id
)
5064 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5068 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",triggeredByAuraSpell
->Id
,triggered_spell_id
);
5073 if(!target
|| target
!=this && !target
->isAlive())
5076 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5080 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5082 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5084 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5085 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5090 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
5092 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
5093 SpellEffectIndex effIndex
= triggeredByAura
->GetEffIndex();
5094 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
5096 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5097 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5099 uint32 triggered_spell_id
= 0;
5100 Unit
* target
= pVictim
;
5101 int32 basepoints
[MAX_EFFECT_INDEX
] = {0, 0, 0};
5103 switch(dummySpell
->SpellFamilyName
)
5105 case SPELLFAMILY_GENERIC
:
5107 switch (dummySpell
->Id
)
5113 // return damage % to attacker but < 50% own total health
5114 basepoints
[0] = triggerAmount
*int32(damage
)/100;
5115 if (basepoints
[0] > (int32
)GetMaxHealth()/2)
5116 basepoints
[0] = (int32
)GetMaxHealth()/2;
5118 triggered_spell_id
= 25997;
5121 // Sweeping Strikes (NPC spells may be)
5125 // prevent chain of triggered spell from same triggered spell
5126 if (procSpell
&& procSpell
->Id
== 26654)
5129 target
= SelectRandomUnfriendlyTarget(pVictim
);
5133 triggered_spell_id
= 26654;
5136 // Twisted Reflection (boss spell)
5138 triggered_spell_id
= 21064;
5143 if (!procSpell
|| procSpell
->Id
== 24659)
5145 // Need remove one 24659 aura
5146 RemoveSingleSpellAurasFromStack(24659);
5149 // Restless Strength
5152 // Need remove one 24662 aura
5153 RemoveSingleSpellAurasFromStack(24662);
5156 // Adaptive Warding (Frostfire Regalia set)
5164 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
5165 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
5167 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
5169 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& UI64LIT(0x10000000)))
5179 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5181 case SPELL_SCHOOL_NORMAL
:
5182 case SPELL_SCHOOL_HOLY
:
5183 return false; // ignored
5184 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
5185 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
5186 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
5187 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
5188 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
5196 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
5202 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5204 case SPELL_SCHOOL_NORMAL
:
5205 return false; // ignore
5206 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
5207 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
5208 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
5209 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
5210 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
5211 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
5219 // Mana Leech (Passive) (Priest Pet Aura)
5223 target
= GetOwner();
5227 triggered_spell_id
= 34650;
5235 if (!roll_chance_i(triggerAmount
))
5238 // Remove any stun effect on target
5239 AuraMap
& Auras
= pVictim
->GetAuras();
5240 for(AuraMap::const_iterator iter
= Auras
.begin(); iter
!= Auras
.end();)
5242 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
5243 if( spell
->Mechanic
== MECHANIC_STUN
||
5244 spell
->EffectMechanic
[iter
->second
->GetEffIndex()] == MECHANIC_STUN
)
5246 pVictim
->RemoveAurasDueToSpell(spell
->Id
);
5247 iter
= Auras
.begin();
5257 // Cast finish spell at last charge
5258 if (triggeredByAura
->GetAuraCharges() > 1)
5262 triggered_spell_id
= 33494;
5265 // Vampiric Aura (boss spell)
5268 basepoints
[0] = 3 * damage
; // 300%
5269 if (basepoints
[0] < 0)
5272 triggered_spell_id
= 31285;
5276 // Aura of Madness (Darkmoon Card: Madness trinket)
5277 //=====================================================
5278 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
5279 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
5280 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
5281 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5282 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
5283 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
5284 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
5285 // 41011 Martyr Complex: +35 stamina (All classes)
5286 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5287 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5290 if(GetTypeId() != TYPEID_PLAYER
)
5293 // Select class defined buff
5296 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5297 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5299 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
5300 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5303 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
5304 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
5306 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
5307 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5310 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
5311 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
5312 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
5313 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
5315 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
5316 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5319 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
5321 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
5322 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5330 if (roll_chance_i(10))
5331 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
5334 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
5335 // cast 45479 Light's Wrath if Exalted by Aldor
5336 // cast 45429 Arcane Bolt if Exalted by Scryers
5339 if(GetTypeId() != TYPEID_PLAYER
)
5342 // Get Aldor reputation rank
5343 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5346 triggered_spell_id
= 45479;
5349 // Get Scryers reputation rank
5350 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5352 // triggered at positive/self casts also, current attack target used then
5353 if(IsFriendlyTo(target
))
5355 target
= getVictim();
5358 uint64 selected_guid
= ((Player
*)this)->GetSelection();
5359 target
= ObjectAccessor::GetUnit(*this,selected_guid
);
5363 if(IsFriendlyTo(target
))
5367 triggered_spell_id
= 45429;
5372 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
5373 // cast 45480 Light's Strength if Exalted by Aldor
5374 // cast 45428 Arcane Strike if Exalted by Scryers
5377 if(GetTypeId() != TYPEID_PLAYER
)
5380 // Get Aldor reputation rank
5381 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5384 triggered_spell_id
= 45480;
5387 // Get Scryers reputation rank
5388 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5390 triggered_spell_id
= 45428;
5395 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
5396 // cast 45431 Arcane Insight if Exalted by Aldor
5397 // cast 45432 Light's Ward if Exalted by Scryers
5400 if(GetTypeId() != TYPEID_PLAYER
)
5403 // Get Aldor reputation rank
5404 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5407 triggered_spell_id
= 45432;
5410 // Get Scryers reputation rank
5411 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5414 triggered_spell_id
= 45431;
5419 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
5420 // cast 45478 Light's Salvation if Exalted by Aldor
5421 // cast 45430 Arcane Surge if Exalted by Scryers
5424 if(GetTypeId() != TYPEID_PLAYER
)
5427 // Get Aldor reputation rank
5428 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5431 triggered_spell_id
= 45478;
5434 // Get Scryers reputation rank
5435 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5437 triggered_spell_id
= 45430;
5443 // Sunwell Exalted Caster Neck (??? neck)
5444 // cast ??? Light's Wrath if Exalted by Aldor
5445 // cast ??? Arcane Bolt if Exalted by Scryers*/
5447 return false; // old unused version
5451 triggered_spell_id
= 48503;
5452 basepoints
[0] = triggerAmount
;
5456 // Vampiric Touch (generic, used by some boss)
5460 triggered_spell_id
= 52724;
5461 basepoints
[0] = damage
/ 2;
5465 // Shadowfiend Death (Gain mana if pet dies with Glyph of Shadowfiend)
5468 Unit
*owner
= GetOwner();
5469 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
5472 // Glyph of Shadowfiend (need cast as self cast for owner, no hidden cooldown)
5473 owner
->CastSpell(owner
,58227,true,castItem
,triggeredByAura
);
5476 // Glyph of Life Tap
5478 triggered_spell_id
= 63321;
5480 // Item - Shadowmourne Legendary
5483 if (!roll_chance_i(triggerAmount
))
5486 Aura
*aur
= GetAura(71905, EFFECT_INDEX_0
);
5487 if (aur
&& uint32(aur
->GetStackAmount() + 1) >= aur
->GetSpellProto()->StackAmount
)
5489 RemoveAurasDueToSpell(71905);
5490 CastSpell(this, 71904, true); // Chaos Bane
5494 triggered_spell_id
= 71905;
5501 case SPELLFAMILY_MAGE
:
5504 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
5506 if (getPowerType() != POWER_MANA
)
5510 basepoints
[0] = (triggerAmount
* GetMaxPower(POWER_MANA
) / 100);
5512 triggered_spell_id
= 29442;
5515 // Master of Elements
5516 if (dummySpell
->SpellIconID
== 1920)
5522 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5523 basepoints
[0] = cost
* triggerAmount
/100;
5524 if (basepoints
[0] <=0)
5528 triggered_spell_id
= 29077;
5533 if (dummySpell
->SpellIconID
== 2120)
5539 switch (dummySpell
->Id
)
5541 case 31571: triggered_spell_id
= 57529; break;
5542 case 31572: triggered_spell_id
= 57531; break;
5544 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u",dummySpell
->Id
);
5551 if (dummySpell
->SpellIconID
== 2999)
5553 if (effIndex
!= EFFECT_INDEX_0
)
5555 Aura
*counter
= GetAura(triggeredByAura
->GetId(), EFFECT_INDEX_1
);
5559 // Count spell criticals in a row in second aura
5560 Modifier
*mod
= counter
->GetModifier();
5561 if (procEx
& PROC_EX_CRITICAL_HIT
)
5564 if (mod
->m_amount
< 100) // not enough
5566 // Crititcal counted -> roll chance
5567 if (roll_chance_i(triggerAmount
))
5568 CastSpell(this, 48108, true, castItem
, triggeredByAura
);
5574 if (dummySpell
->SpellIconID
== 2998)
5579 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5580 basepoints
[0] = cost
* triggerAmount
/100;
5581 if (basepoints
[0] <=0)
5583 triggered_spell_id
= 44450;
5587 // Incanter's Regalia set (add trigger chance to Mana Shield)
5588 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5590 if (GetTypeId() != TYPEID_PLAYER
)
5594 triggered_spell_id
= 37436;
5597 switch(dummySpell
->Id
)
5606 switch (dummySpell
->Id
)
5608 case 11119: basepoints
[0] = int32(0.04f
*damage
); break;
5609 case 11120: basepoints
[0] = int32(0.08f
*damage
); break;
5610 case 12846: basepoints
[0] = int32(0.12f
*damage
); break;
5611 case 12847: basepoints
[0] = int32(0.16f
*damage
); break;
5612 case 12848: basepoints
[0] = int32(0.20f
*damage
); break;
5614 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
5618 triggered_spell_id
= 12654;
5624 //last charge and crit
5625 if (triggeredByAura
->GetAuraCharges() <= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
5626 return true; // charge counting (will removed)
5628 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
5629 return (procEx
& PROC_EX_CRITICAL_HIT
); // charge update only at crit hits, no hidden cooldowns
5631 // Glyph of Ice Block
5634 if (GetTypeId() != TYPEID_PLAYER
)
5637 // not 100% safe with client version switches but for 3.1.3 no spells with cooldown that can have mage player except Frost Nova.
5638 ((Player
*)this)->RemoveSpellCategoryCooldown(35, true);
5641 // Glyph of Polymorph
5644 if (!pVictim
|| !pVictim
->isAlive())
5647 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE
);
5648 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE_PERCENT
);
5651 // Blessing of Ancient Kings
5655 if (!IsPositiveSpell(procSpell
->Id
))
5658 triggered_spell_id
= 64413;
5659 basepoints
[0] = damage
* 15 / 100;
5665 case SPELLFAMILY_WARRIOR
:
5668 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0000000800000000))
5670 // check attack comes not from behind
5671 if (!HasInArc(M_PI_F
, pVictim
))
5674 triggered_spell_id
= 22858;
5678 if (dummySpell
->SpellIconID
== 1697)
5680 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
5681 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
5683 // Need stun or root mechanic
5684 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_STUN_MASK
))
5687 switch (dummySpell
->Id
)
5689 case 29838: triggered_spell_id
=29842; break;
5690 case 29834: triggered_spell_id
=29841; break;
5691 case 42770: triggered_spell_id
=42771; break;
5693 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
5701 if (dummySpell
->SpellIconID
== 3214)
5703 triggered_spell_id
= 59653;
5704 basepoints
[0] = GetShieldBlockValue() * triggerAmount
/ 100;
5709 if (dummySpell
->Id
== 12328)
5711 // prevent chain of triggered spell from same triggered spell
5712 if(procSpell
&& procSpell
->Id
== 26654)
5715 target
= SelectRandomUnfriendlyTarget(pVictim
);
5719 triggered_spell_id
= 26654;
5724 case SPELLFAMILY_WARLOCK
:
5726 // Seed of Corruption
5727 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
5729 Modifier
* mod
= triggeredByAura
->GetModifier();
5730 // if damage is more than need or target die from damage deal finish spell
5731 if( mod
->m_amount
<= (int32
)damage
|| GetHealth() <= damage
)
5733 // remember guid before aura delete
5734 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5736 // Remove aura (before cast for prevent infinite loop handlers)
5737 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5739 // Cast finish spell (triggeredByAura already not exist!)
5740 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
5741 return true; // no hidden cooldown
5745 mod
->m_amount
-=damage
;
5748 // Seed of Corruption (Mobs cast) - no die req
5749 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0) && dummySpell
->SpellIconID
== 1932)
5751 Modifier
* mod
= triggeredByAura
->GetModifier();
5752 // if damage is more than need deal finish spell
5753 if( mod
->m_amount
<= (int32
)damage
)
5755 // remember guid before aura delete
5756 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5758 // Remove aura (before cast for prevent infinite loop handlers)
5759 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5761 // Cast finish spell (triggeredByAura already not exist!)
5762 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
5763 return true; // no hidden cooldown
5766 mod
->m_amount
-=damage
;
5770 if (dummySpell
->SpellIconID
== 3222)
5775 basepoints
[0] = damage
* triggerAmount
/ 100;
5776 triggered_spell_id
= 54181;
5779 switch(dummySpell
->Id
)
5781 // Nightfall & Glyph of Corruption
5787 triggered_spell_id
= 17941;
5796 basepoints
[0] = int32(damage
*triggerAmount
/100);
5798 triggered_spell_id
= 30294;
5801 // Shadowflame (Voidheart Raiment set bonus)
5804 triggered_spell_id
= 37379;
5807 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
5815 basepoints
[0] = damage
* triggerAmount
/100;
5816 triggered_spell_id
= 37382;
5819 // Shadowflame Hellfire (Voidheart Raiment set bonus)
5822 triggered_spell_id
= 37378;
5828 if (triggeredByAura
->GetEffIndex() != EFFECT_INDEX_0
)
5831 // Glyph of Siphon Life
5832 if (Aura
*aur
= GetAura(56216, EFFECT_INDEX_0
))
5833 triggerAmount
+= triggerAmount
* aur
->GetModifier()->m_amount
/ 100;
5835 basepoints
[0] = int32(damage
* triggerAmount
/ 100);
5836 triggered_spell_id
= 63106;
5842 case SPELLFAMILY_PRIEST
:
5845 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
5847 if(!pVictim
|| !pVictim
->isAlive())
5850 // pVictim is caster of aura
5851 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5854 // Energize 0.25% of max. mana
5855 pVictim
->CastSpell(pVictim
,57669,true,castItem
,triggeredByAura
);
5856 return true; // no hidden cooldown
5859 switch(dummySpell
->SpellIconID
)
5861 // Improved Shadowform
5864 if(!roll_chance_i(triggerAmount
))
5867 RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT
);
5868 RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED
);
5874 basepoints
[0] = damage
* triggerAmount
/100;
5875 triggered_spell_id
= 47753;
5884 Aura
* healingAura
= pVictim
->GetAura(procSpell
->Id
, EFFECT_INDEX_0
);
5888 int32 healingfromticks
= healingAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
);
5890 basepoints
[0] = healingfromticks
* triggerAmount
/ 100;
5891 triggered_spell_id
= 63544;
5894 // Improved Devouring Plague
5900 if (triggeredByAura
->GetEffIndex() != EFFECT_INDEX_1
)
5903 Aura
* leachAura
= pVictim
->GetAura(SPELL_AURA_PERIODIC_LEECH
, SPELLFAMILY_PRIEST
, UI64LIT(0x02000000), NULL
, GetGUID());
5907 int32 damagefromticks
= leachAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
);
5908 basepoints
[0] = damagefromticks
* triggerAmount
/ 100;
5909 triggered_spell_id
= 63675;
5914 switch(dummySpell
->Id
)
5919 // Return if self damage
5920 if (this == pVictim
)
5923 // Heal amount - Self/Team
5924 int32 team
= triggerAmount
*damage
/500;
5925 int32 self
= triggerAmount
*damage
/100 - team
;
5926 CastCustomSpell(this,15290,&team
,&self
,NULL
,true,castItem
,triggeredByAura
);
5927 return true; // no hidden cooldown
5929 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
5932 // Shadow Word: Pain
5933 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5934 triggered_spell_id
= 40441;
5936 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
5937 triggered_spell_id
= 40440;
5944 // Oracle Healing Bonus ("Garments of the Oracle" set)
5948 basepoints
[0] = int32(damage
* 10/100);
5950 triggered_spell_id
= 26170;
5953 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
5956 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
5960 basepoints
[0] = damage
* triggerAmount
/100;
5962 triggered_spell_id
= 39373;
5965 // Greater Heal (Vestments of Faith (Priest Tier 3) - 4 pieces bonus)
5968 triggered_spell_id
= 28810;
5971 // Glyph of Dispel Magic
5974 if(!target
->IsFriendlyTo(this))
5977 basepoints
[0] = int32(target
->GetMaxHealth() * triggerAmount
/ 100);
5978 triggered_spell_id
= 56131;
5984 case SPELLFAMILY_DRUID
:
5986 switch(dummySpell
->Id
)
5988 // Leader of the Pack
5991 // dummy m_amount store health percent (!=0 if Improved Leader of the Pack applied)
5992 int32 heal_percent
= triggeredByAura
->GetModifier()->m_amount
;
5996 // check explicitly only to prevent mana cast when halth cast cooldown
5997 if (cooldown
&& ((Player
*)this)->HasSpellCooldown(34299))
6001 triggered_spell_id
= 34299;
6002 basepoints
[0] = GetMaxHealth() * heal_percent
/ 100;
6006 if (triggeredByAura
->GetCasterGUID() == GetGUID())
6008 if (SpellEntry
const* manaCastEntry
= sSpellStore
.LookupEntry(60889))
6010 int32 mana_percent
= manaCastEntry
->CalculateSimpleValue(EFFECT_INDEX_0
) * heal_percent
;
6011 CastCustomSpell(this, manaCastEntry
, &mana_percent
, NULL
, NULL
, true, castItem
, triggeredByAura
);
6016 // Healing Touch (Dreamwalker Raiment set)
6020 basepoints
[0] = int32(procSpell
->manaCost
* 30 / 100);
6022 triggered_spell_id
= 28742;
6025 // Healing Touch Refund (Idol of Longevity trinket)
6029 triggered_spell_id
= 28848;
6032 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
6037 triggered_spell_id
= 37238;
6040 // Druid Tier 6 Trinket
6046 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
6048 triggered_spell_id
= 40445;
6052 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
6054 triggered_spell_id
= 40446;
6057 // Mangle (Bear) and Mangle (Cat)
6058 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000044000000000))
6060 triggered_spell_id
= 40452;
6066 if (!roll_chance_f(chance
))
6075 // Deadly Interrupt Effect
6076 triggered_spell_id
= 32747;
6079 // Glyph of Rejuvenation
6083 if (pVictim
->GetMaxHealth() < 2 * pVictim
->GetHealth())
6085 basepoints
[0] = triggerAmount
* damage
/ 100;
6086 triggered_spell_id
= 54755;
6089 // Item - Druid T10 Restoration 4P Bonus (Rejuvenation)
6092 if (!procSpell
|| GetTypeId() != TYPEID_PLAYER
)
6096 if (procSpell
->EffectRadiusIndex
[EFFECT_INDEX_0
])
6097 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(procSpell
->EffectRadiusIndex
[EFFECT_INDEX_0
]));
6099 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(procSpell
->rangeIndex
));
6101 ((Player
*)this)->ApplySpellMod(procSpell
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
6103 Unit
*second
= pVictim
->SelectRandomFriendlyTarget(pVictim
, radius
);
6108 pVictim
->CastSpell(second
, procSpell
, true, NULL
, triggeredByAura
, GetGUID());
6113 if (dummySpell
->SpellIconID
== 2856)
6117 // Only 0 aura can proc
6118 if (effIndex
!= EFFECT_INDEX_0
)
6121 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6125 if (!roll_chance_i(60))
6127 triggered_spell_id
= 48518;
6132 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
6136 triggered_spell_id
= 48517;
6143 else if (dummySpell
->SpellIconID
== 2860)
6145 triggered_spell_id
= 48504;
6146 basepoints
[0] = triggerAmount
* damage
/ 100;
6151 case SPELLFAMILY_ROGUE
:
6153 switch(dummySpell
->Id
)
6155 // Deadly Throw Interrupt
6158 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
6159 if (this == pVictim
)
6162 triggered_spell_id
= 32747;
6167 if (dummySpell
->SpellIconID
== 2909)
6169 // "refresh your Slice and Dice duration to its 5 combo point maximum"
6170 // lookup Slice and Dice
6171 AuraList
const& sd
= GetAurasByType(SPELL_AURA_MOD_HASTE
);
6172 for(AuraList::const_iterator itr
= sd
.begin(); itr
!= sd
.end(); ++itr
)
6174 SpellEntry
const *spellProto
= (*itr
)->GetSpellProto();
6175 if (spellProto
->SpellFamilyName
== SPELLFAMILY_ROGUE
&&
6176 (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000040000)))
6178 (*itr
)->SetAuraMaxDuration(GetSpellMaxDuration(spellProto
));
6179 (*itr
)->RefreshAura();
6186 if (dummySpell
->SpellIconID
== 2963)
6188 triggered_spell_id
= 44289;
6192 if (dummySpell
->SpellIconID
== 2116)
6198 basepoints
[0] = procSpell
->manaCost
* triggerAmount
/100;
6199 if (basepoints
[0] <= 0)
6203 triggered_spell_id
= 31663;
6208 case SPELLFAMILY_HUNTER
:
6210 // Aspect of the Viper
6211 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x4000000000000))
6213 uint32 maxmana
= GetMaxPower(POWER_MANA
);
6214 basepoints
[0] = int32(maxmana
* GetAttackTime(RANGED_ATTACK
)/1000.0f
/100.0f
);
6217 triggered_spell_id
= 34075;
6220 // Thrill of the Hunt
6221 if (dummySpell
->SpellIconID
== 2236)
6227 int32 mana
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
6228 basepoints
[0] = mana
* 40/100;
6229 if (basepoints
[0] <= 0)
6233 triggered_spell_id
= 34720;
6237 if (dummySpell
->SpellIconID
== 3406)
6239 triggered_spell_id
= 57669;
6244 if ( dummySpell
->SpellIconID
== 3579 )
6246 // Proc only from periodic (from trap activation proc another aura of this spell)
6247 if (!(procFlag
& PROC_FLAG_ON_DO_PERIODIC
) || !roll_chance_i(triggerAmount
))
6249 triggered_spell_id
= 56453;
6253 // Rapid Recuperation
6254 if ( dummySpell
->SpellIconID
== 3560 )
6256 // This effect only from Rapid Killing (mana regen)
6257 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0100000000000000)))
6262 switch(dummySpell
->Id
)
6264 case 53228: // Rank 1
6265 triggered_spell_id
= 56654;
6267 case 53232: // Rank 2
6268 triggered_spell_id
= 58882;
6273 // Glyph of Mend Pet
6274 if(dummySpell
->Id
== 57870)
6276 pVictim
->CastSpell(pVictim
, 57894, true, NULL
, NULL
, GetGUID());
6281 case SPELLFAMILY_PALADIN
:
6283 // Seal of Righteousness - melee proc dummy (addition ${$MWS*(0.022*$AP+0.044*$SPH)} damage)
6284 if ((dummySpell
->SpellFamilyFlags
& UI64LIT(0x000000008000000)) && effIndex
== EFFECT_INDEX_0
)
6286 triggered_spell_id
= 25742;
6287 float ap
= GetTotalAttackPowerValue(BASE_ATTACK
);
6288 int32 holy
= SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_HOLY
);
6291 basepoints
[0] = GetAttackTime(BASE_ATTACK
) * int32(ap
*0.022f
+ 0.044f
* holy
) / 1000;
6294 // Righteous Vengeance
6295 if (dummySpell
->SpellIconID
== 3025)
6298 basepoints
[0] = triggerAmount
*damage
/400;
6299 triggered_spell_id
= 61840;
6303 if (dummySpell
->SpellIconID
== 3030)
6306 basepoints
[0] = triggerAmount
*damage
/400;
6307 triggered_spell_id
= 54203;
6310 switch(dummySpell
->Id
)
6312 // Judgement of Light
6315 basepoints
[0] = int32( pVictim
->GetMaxHealth() * triggeredByAura
->GetModifier()->m_amount
/ 100 );
6316 pVictim
->CastCustomSpell(pVictim
, 20267, &basepoints
[0], NULL
, NULL
, true, NULL
, triggeredByAura
);
6319 // Judgement of Wisdom
6322 if (pVictim
->getPowerType() == POWER_MANA
)
6324 // 2% of maximum base mana
6325 basepoints
[0] = int32(pVictim
->GetCreateMana() * 2 / 100);
6326 pVictim
->CastCustomSpell(pVictim
, 20268, &basepoints
[0], NULL
, NULL
, true, NULL
, triggeredByAura
);
6330 // Heart of the Crusader (Rank 1)
6332 triggered_spell_id
= 21183;
6334 // Heart of the Crusader (Rank 2)
6336 triggered_spell_id
= 54498;
6338 // Heart of the Crusader (Rank 3)
6340 triggered_spell_id
= 54499;
6342 case 20911: // Blessing of Sanctuary
6343 case 25899: // Greater Blessing of Sanctuary
6346 switch (target
->getPowerType())
6349 triggered_spell_id
= 57319;
6356 // Holy Power (Redemption Armor set)
6362 // Set class defined buff
6363 switch (pVictim
->getClass())
6369 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6373 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6377 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
6380 triggered_spell_id
= 28790; // Increases the friendly target's armor
6387 // Spiritual Attunement
6391 // if healed by another unit (pVictim)
6392 if (this == pVictim
)
6396 basepoints
[0] = triggerAmount
*damage
/100;
6398 triggered_spell_id
= 31786;
6401 // Seal of Vengeance (damage calc on apply aura)
6404 if (effIndex
!= EFFECT_INDEX_0
) // effect 1,2 used by seal unleashing code
6407 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6408 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595) )
6409 triggered_spell_id
= 31803; // Holy Vengeance
6411 // Add 5-stack effect from Holy Vengeance
6413 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6414 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6416 if( ((*itr
)->GetId() == 31803) && (*itr
)->GetCasterGUID()==GetGUID())
6418 stacks
= (*itr
)->GetStackAmount();
6423 CastSpell(target
,42463,true,NULL
,triggeredByAura
);
6426 // Judgements of the Wise
6430 // triggered only at casted Judgement spells, not at additional Judgement effects
6431 if(!procSpell
|| procSpell
->Category
!= 1210)
6435 triggered_spell_id
= 31930;
6438 CastSpell(this, 57669, true, NULL
, triggeredByAura
);
6440 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
6448 // Flash of light/Holy light
6449 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x00000000C0000000))
6451 triggered_spell_id
= 40471;
6455 else if (GetSpellSpecific(procSpell
->Id
)==SPELL_JUDGEMENT
)
6457 triggered_spell_id
= 40472;
6463 if (!roll_chance_f(chance
))
6468 // Light's Beacon (heal target area aura)
6471 // not do bonus heal for explicit beacon focus healing
6472 if (GetGUID() == triggeredByAura
->GetCasterGUID())
6476 Unit
* beacon
= triggeredByAura
->GetCaster();
6480 // find caster main aura at beacon
6482 Unit::AuraList
const& baa
= beacon
->GetAurasByType(SPELL_AURA_PERIODIC_TRIGGER_SPELL
);
6483 for(Unit::AuraList::const_iterator i
= baa
.begin(); i
!= baa
.end(); ++i
)
6485 if ((*i
)->GetId() == 53563 && (*i
)->GetCasterGUID() == pVictim
->GetGUID())
6492 // original heal must be form beacon caster
6496 triggered_spell_id
= 53652; // Beacon of Light
6497 basepoints
[0] = triggeredByAura
->GetModifier()->m_amount
*damage
/100;
6499 // cast with original caster set but beacon to beacon for apply caster mods and avoid LoS check
6500 beacon
->CastCustomSpell(beacon
,triggered_spell_id
,&basepoints
[0],NULL
,NULL
,true,castItem
,triggeredByAura
,pVictim
->GetGUID());
6503 // Seal of Corruption (damage calc on apply aura)
6506 if (effIndex
!= EFFECT_INDEX_0
) // effect 1,2 used by seal unleashing code
6509 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6510 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595))
6511 triggered_spell_id
= 53742; // Blood Corruption
6513 // Add 5-stack effect from Blood Corruption
6515 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6516 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6518 if( ((*itr
)->GetId() == 53742) && (*itr
)->GetCasterGUID()==GetGUID())
6520 stacks
= (*itr
)->GetStackAmount();
6525 CastSpell(target
,53739,true,NULL
,triggeredByAura
);
6528 // Glyph of Holy Light
6531 triggered_spell_id
= 54968;
6532 basepoints
[0] = triggerAmount
*damage
/100;
6535 // Glyph of Divinity
6538 // Lookup base amount mana restore
6539 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
6541 if (procSpell
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
6543 int32 mana
= procSpell
->CalculateSimpleValue(SpellEffectIndex(i
));
6544 CastCustomSpell(this, 54986, NULL
, &mana
, NULL
, true, castItem
, triggeredByAura
);
6550 // Sacred Shield (buff)
6553 triggered_spell_id
= 66922;
6554 SpellEntry
const* triggeredEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6555 if (!triggeredEntry
)
6558 basepoints
[0] = int32(damage
/ (GetSpellDuration(triggeredEntry
) / triggeredEntry
->EffectAmplitude
[EFFECT_INDEX_0
]));
6562 // Sacred Shield (talent rank)
6565 triggered_spell_id
= 58597;
6572 case SPELLFAMILY_SHAMAN
:
6574 switch(dummySpell
->Id
)
6576 // Totemic Power (The Earthshatterer set)
6582 // Set class defined buff
6583 switch (pVictim
->getClass())
6589 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6593 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6597 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
6600 triggered_spell_id
= 28827; // Increases the friendly target's armor
6607 // Lesser Healing Wave (Totem of Flowing Water Relic)
6611 triggered_spell_id
= 28850;
6614 // Windfury Weapon (Passive) 1-5 Ranks
6617 if(GetTypeId()!=TYPEID_PLAYER
)
6620 if(!castItem
|| !castItem
->IsEquipped())
6623 // custom cooldown processing case
6624 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6627 // Now amount of extra power stored in 1 effect of Enchant spell
6628 // Get it by item enchant id
6630 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
6632 case 283: spellId
= 8232; break; // 1 Rank
6633 case 284: spellId
= 8235; break; // 2 Rank
6634 case 525: spellId
= 10486; break; // 3 Rank
6635 case 1669:spellId
= 16362; break; // 4 Rank
6636 case 2636:spellId
= 25505; break; // 5 Rank
6637 case 3785:spellId
= 58801; break; // 6 Rank
6638 case 3786:spellId
= 58803; break; // 7 Rank
6639 case 3787:spellId
= 58804; break; // 8 Rank
6642 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
6643 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
6648 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
6649 if(!windfurySpellEntry
)
6651 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
6655 int32 extra_attack_power
= CalculateSpellDamage(pVictim
, windfurySpellEntry
, EFFECT_INDEX_1
);
6658 if (castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
6660 // Value gained from additional AP
6661 basepoints
[0] = int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
6662 triggered_spell_id
= 33750;
6667 // Value gained from additional AP
6668 basepoints
[0] = int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
6669 triggered_spell_id
= 25504;
6672 // apply cooldown before cast to prevent processing itself
6674 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6677 for ( uint32 i
= 0; i
<2; ++i
)
6678 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints
[0],NULL
,NULL
,true,castItem
,triggeredByAura
);
6682 // Shaman Tier 6 Trinket
6689 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6691 triggered_spell_id
= 40465; // Lightning Bolt
6694 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080))
6696 triggered_spell_id
= 40465; // Lesser Healing Wave
6699 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
6701 triggered_spell_id
= 40466; // Stormstrike
6707 if (!roll_chance_f(chance
))
6713 // Glyph of Healing Wave
6716 // Not proc from self heals
6719 basepoints
[0] = triggerAmount
* damage
/ 100;
6721 triggered_spell_id
= 55533;
6728 target
= GetOwner();
6731 basepoints
[0] = triggerAmount
* damage
/ 100;
6732 triggered_spell_id
= 58879;
6735 // Glyph of Totem of Wrath
6738 Totem
* totem
= GetTotem(TOTEM_SLOT_FIRE
);
6742 // find totem aura bonus
6743 AuraList
const& spellPower
= totem
->GetAurasByType(SPELL_AURA_NONE
);
6744 for(AuraList::const_iterator i
= spellPower
.begin();i
!= spellPower
.end(); ++i
)
6746 // select proper aura for format aura type in spell proto
6747 if ((*i
)->GetTarget()==totem
&& (*i
)->GetSpellProto()->EffectApplyAuraName
[(*i
)->GetEffIndex()] == SPELL_AURA_MOD_HEALING_DONE
&&
6748 (*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000004000000))
6750 basepoints
[0] = triggerAmount
* (*i
)->GetModifier()->m_amount
/ 100;
6758 basepoints
[1] = basepoints
[0];
6759 triggered_spell_id
= 63283; // Totem of Wrath, caster bonus
6763 // Shaman T8 Elemental 4P Bonus
6766 basepoints
[0] = int32( triggerAmount
* damage
/ 100 );
6767 triggered_spell_id
= 64930; // Electrified
6770 // Shaman T9 Elemental 4P Bonus
6773 basepoints
[0] = int32( triggerAmount
* damage
/ 100 );
6774 triggered_spell_id
= 71824;
6778 // Storm, Earth and Fire
6779 if (dummySpell
->SpellIconID
== 3063)
6781 // Earthbind Totem summon only
6782 if(procSpell
->Id
!= 2484)
6785 if (!roll_chance_i(triggerAmount
))
6788 triggered_spell_id
= 64695;
6791 // Ancestral Awakening
6792 if (dummySpell
->SpellIconID
== 3065)
6794 triggered_spell_id
= 52759;
6795 basepoints
[0] = triggerAmount
* damage
/ 100;
6800 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
6803 basepoints
[0] = triggerAmount
;
6805 // Glyph of Earth Shield
6806 if (Aura
* aur
= GetDummyAura(63279))
6808 int32 aur_mod
= aur
->GetModifier()->m_amount
;
6809 basepoints
[0] = int32(basepoints
[0] * (aur_mod
+ 100.0f
) / 100.0f
);
6812 triggered_spell_id
= 379;
6815 // Improved Water Shield
6816 if (dummySpell
->SpellIconID
== 2287)
6818 // Lesser Healing Wave need aditional 60% roll
6819 if ((procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)) && !roll_chance_i(60))
6821 // lookup water shield
6822 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6823 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6825 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6826 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000002000000000)))
6828 uint32 spell
= (*itr
)->GetSpellProto()->EffectTriggerSpell
[(*itr
)->GetEffIndex()];
6829 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
6830 if ((*itr
)->DropAuraCharge())
6831 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6838 // Lightning Overload
6839 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
6841 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
6844 // custom cooldown processing case
6845 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6849 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
6850 switch (procSpell
->Id
)
6853 case 403: spellId
= 45284; break; // Rank 1
6854 case 529: spellId
= 45286; break; // Rank 2
6855 case 548: spellId
= 45287; break; // Rank 3
6856 case 915: spellId
= 45288; break; // Rank 4
6857 case 943: spellId
= 45289; break; // Rank 5
6858 case 6041: spellId
= 45290; break; // Rank 6
6859 case 10391: spellId
= 45291; break; // Rank 7
6860 case 10392: spellId
= 45292; break; // Rank 8
6861 case 15207: spellId
= 45293; break; // Rank 9
6862 case 15208: spellId
= 45294; break; // Rank 10
6863 case 25448: spellId
= 45295; break; // Rank 11
6864 case 25449: spellId
= 45296; break; // Rank 12
6865 case 49237: spellId
= 49239; break; // Rank 13
6866 case 49238: spellId
= 49240; break; // Rank 14
6868 case 421: spellId
= 45297; break; // Rank 1
6869 case 930: spellId
= 45298; break; // Rank 2
6870 case 2860: spellId
= 45299; break; // Rank 3
6871 case 10605: spellId
= 45300; break; // Rank 4
6872 case 25439: spellId
= 45301; break; // Rank 5
6873 case 25442: spellId
= 45302; break; // Rank 6
6874 case 49270: spellId
= 49268; break; // Rank 7
6875 case 49271: spellId
= 49269; break; // Rank 8
6877 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
6880 // No thread generated mod
6881 // TODO: exist special flag in spell attributes for this, need found and use!
6882 SpellModifier
*mod
= new SpellModifier(SPELLMOD_THREAT
,SPELLMOD_PCT
,-100,triggeredByAura
);
6884 ((Player
*)this)->AddSpellMod(mod
, true);
6886 // Remove cooldown (Chain Lightning - have Category Recovery time)
6887 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000002))
6888 ((Player
*)this)->RemoveSpellCooldown(spellId
);
6890 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
6892 ((Player
*)this)->AddSpellMod(mod
, false);
6894 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6895 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6900 if(dummySpell
->SpellIconID
== 3059)
6902 // lookup Lightning Shield
6903 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6904 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6906 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6907 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000400)))
6910 switch ((*itr
)->GetId())
6912 case 324: spell
= 26364; break;
6913 case 325: spell
= 26365; break;
6914 case 905: spell
= 26366; break;
6915 case 945: spell
= 26367; break;
6916 case 8134: spell
= 26369; break;
6917 case 10431: spell
= 26370; break;
6918 case 10432: spell
= 26363; break;
6919 case 25469: spell
= 26371; break;
6920 case 25472: spell
= 26372; break;
6921 case 49280: spell
= 49278; break;
6922 case 49281: spell
= 49279; break;
6926 CastSpell(target
, spell
, true, castItem
, triggeredByAura
);
6927 if ((*itr
)->DropAuraCharge())
6928 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6935 if (dummySpell
->SpellIconID
== 3780)
6937 Unit
*caster
= triggeredByAura
->GetCaster();
6939 if (!procSpell
|| !caster
)
6942 float distance
= caster
->GetDistance(pVictim
);
6943 int32 chance
= triggerAmount
;
6945 if (distance
< 15.0f
|| !roll_chance_i(chance
))
6948 // make triggered cast apply after current damage spell processing for prevent remove by it
6949 if(Spell
* spell
= GetCurrentSpell(CURRENT_GENERIC_SPELL
))
6950 spell
->AddTriggeredSpell(63685);
6955 case SPELLFAMILY_DEATHKNIGHT
:
6958 if (dummySpell
->SpellIconID
== 2664)
6960 basepoints
[0] = triggerAmount
;
6961 triggered_spell_id
= 50163;
6965 // Dancing Rune Weapon
6966 if (dummySpell
->Id
== 49028)
6968 // 1 dummy aura for dismiss rune blade
6969 if (effIndex
!= EFFECT_INDEX_2
)
6971 // TODO: wite script for this "fights on its own, doing the same attacks"
6972 // NOTE: Trigger here on every attack and spell cast
6976 if (dummySpell
->Id
== 49005)
6978 // TODO: need more info (cooldowns/PPM)
6979 triggered_spell_id
= 61607;
6983 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000010000))
6985 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
6986 triggered_spell_id
= 50181;
6991 if (dummySpell
->SpellIconID
== 2709)
6993 basepoints
[0] = triggerAmount
* damage
/ 100;
6994 triggered_spell_id
= 51460;
6997 // Threat of Thassarian
6998 if (dummySpell
->SpellIconID
== 2023)
7001 if (!procSpell
|| !haveOffhandWeapon())
7003 // Chance as basepoints for dummy aura
7004 if (!roll_chance_i(triggerAmount
))
7007 switch (procSpell
->Id
)
7010 case 49020: // Rank 1
7011 triggered_spell_id
= 66198; break;
7012 case 51423: // Rank 2
7013 triggered_spell_id
= 66972; break;
7014 case 51424: // Rank 3
7015 triggered_spell_id
= 66973; break;
7016 case 51425: // Rank 4
7017 triggered_spell_id
= 66974; break;
7019 case 49143: // Rank 1
7020 triggered_spell_id
= 66196; break;
7021 case 51416: // Rank 2
7022 triggered_spell_id
= 66958; break;
7023 case 51417: // Rank 3
7024 triggered_spell_id
= 66959; break;
7025 case 51418: // Rank 4
7026 triggered_spell_id
= 66960; break;
7027 case 51419: // Rank 5
7028 triggered_spell_id
= 66961; break;
7029 case 55268: // Rank 6
7030 triggered_spell_id
= 66962; break;
7032 case 45462: // Rank 1
7033 triggered_spell_id
= 66216; break;
7034 case 49917: // Rank 2
7035 triggered_spell_id
= 66988; break;
7036 case 49918: // Rank 3
7037 triggered_spell_id
= 66989; break;
7038 case 49919: // Rank 4
7039 triggered_spell_id
= 66990; break;
7040 case 49920: // Rank 5
7041 triggered_spell_id
= 66991; break;
7042 case 49921: // Rank 6
7043 triggered_spell_id
= 66992; break;
7045 case 49998: // Rank 1
7046 triggered_spell_id
= 66188; break;
7047 case 49999: // Rank 2
7048 triggered_spell_id
= 66950; break;
7049 case 45463: // Rank 3
7050 triggered_spell_id
= 66951; break;
7051 case 49923: // Rank 4
7052 triggered_spell_id
= 66952; break;
7053 case 49924: // Rank 5
7054 triggered_spell_id
= 66953; break;
7057 triggered_spell_id
= 66217; break;
7059 case 45902: // Rank 1
7060 triggered_spell_id
= 66215; break;
7061 case 49926: // Rank 2
7062 triggered_spell_id
= 66975; break;
7063 case 49927: // Rank 3
7064 triggered_spell_id
= 66976; break;
7065 case 49928: // Rank 4
7066 triggered_spell_id
= 66977; break;
7067 case 49929: // Rank 5
7068 triggered_spell_id
= 66978; break;
7069 case 49930: // Rank 6
7070 triggered_spell_id
= 66979; break;
7076 // Runic Power Back on Snare/Root
7077 if (dummySpell
->Id
== 61257)
7079 // only for spells and hit/crit (trigger start always) and not start from self casted spells
7080 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7082 // Need snare or root mechanic
7083 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_SNARE_MASK
))
7085 triggered_spell_id
= 61258;
7090 if (dummySpell
->SpellIconID
== 1614)
7092 if (!roll_chance_f(GetUnitCriticalChance(BASE_ATTACK
, pVictim
)))
7094 basepoints
[0] = triggerAmount
* damage
/ 100;
7095 triggered_spell_id
= 50526;
7098 // Blood-Caked Blade
7099 if (dummySpell
->SpellIconID
== 138)
7101 triggered_spell_id
= dummySpell
->EffectTriggerSpell
[effIndex
];
7110 // processed charge only counting case
7111 if(!triggered_spell_id
)
7114 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
7118 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
7123 if(!target
|| target
!=this && !target
->isAlive())
7126 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
7129 if (basepoints
[EFFECT_INDEX_0
] || basepoints
[EFFECT_INDEX_1
] || basepoints
[EFFECT_INDEX_2
])
7130 CastCustomSpell(target
, triggered_spell_id
,
7131 basepoints
[EFFECT_INDEX_0
] ? &basepoints
[EFFECT_INDEX_0
] : NULL
,
7132 basepoints
[EFFECT_INDEX_1
] ? &basepoints
[EFFECT_INDEX_1
] : NULL
,
7133 basepoints
[EFFECT_INDEX_2
] ? &basepoints
[EFFECT_INDEX_2
] : NULL
,
7134 true, castItem
, triggeredByAura
);
7136 CastSpell(target
, triggered_spell_id
, true, castItem
, triggeredByAura
);
7138 if (cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7139 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
7144 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
7146 // Get triggered aura spell info
7147 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
7149 // Basepoints of trigger aura
7150 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7152 // Set trigger spell id, target, custom basepoints
7153 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
7154 Unit
* target
= NULL
;
7155 int32 basepoints
[MAX_EFFECT_INDEX
] = {0, 0, 0};
7157 if(triggeredByAura
->GetModifier()->m_auraname
== SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
)
7158 basepoints
[0] = triggerAmount
;
7160 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7161 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7163 // Try handle unknown trigger spells
7164 // Custom requirements (not listed in procEx) Warning! damage dealing after this
7165 // Custom triggered spells
7166 switch (auraSpellInfo
->SpellFamilyName
)
7168 case SPELLFAMILY_GENERIC
:
7169 switch(auraSpellInfo
->Id
)
7171 //case 191: // Elemental Response
7172 // switch (procSpell->School)
7174 // case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192; break;
7175 // case SPELL_SCHOOL_FROST: trigger_spell_id = 34193; break;
7176 // case SPELL_SCHOOL_ARCANE:trigger_spell_id = 34194; break;
7177 // case SPELL_SCHOOL_NATURE:trigger_spell_id = 34195; break;
7178 // case SPELL_SCHOOL_SHADOW:trigger_spell_id = 34196; break;
7179 // case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197; break;
7180 // case SPELL_SCHOOL_NORMAL:trigger_spell_id = 34198; break;
7183 //case 5301: break; // Defensive State (DND)
7184 //case 7137: break: // Shadow Charge (Rank 1)
7185 //case 7377: break: // Take Immune Periodic Damage <Not Working>
7186 //case 13358: break; // Defensive State (DND)
7187 //case 16092: break; // Defensive State (DND)
7188 //case 18943: break; // Double Attack
7189 //case 19194: break; // Double Attack
7190 //case 19817: break; // Double Attack
7191 //case 19818: break; // Double Attack
7192 //case 22835: break; // Drunken Rage
7193 // trigger_spell_id = 14822; break;
7194 case 23780: // Aegis of Preservation (Aegis of Preservation trinket)
7195 trigger_spell_id
= 23781;
7197 //case 24949: break; // Defensive State 2 (DND)
7198 case 27522: // Mana Drain Trigger
7199 case 40336: // Mana Drain Trigger
7200 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
7202 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
7203 if (pVictim
&& pVictim
->isAlive())
7204 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
7206 case 31255: // Deadly Swiftness (Rank 1)
7207 // whenever you deal damage to a target who is below 20% health.
7208 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
7212 trigger_spell_id
= 22588;
7214 //case 33207: break; // Gossip NPC Periodic - Fidget
7215 case 33896: // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
7216 trigger_spell_id
= 33898;
7218 //case 34082: break; // Advantaged State (DND)
7219 //case 34783: break: // Spell Reflection
7220 //case 35205: break: // Vanish
7221 //case 35321: break; // Gushing Wound
7222 //case 36096: break: // Spell Reflection
7223 //case 36207: break: // Steal Weapon
7224 //case 36576: break: // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
7225 //case 37030: break; // Chaotic Temperament
7226 //case 38363: break; // Gushing Wound
7227 //case 39215: break; // Gushing Wound
7228 //case 40250: break; // Improved Duration
7229 //case 40329: break; // Demo Shout Sensor
7230 //case 40364: break; // Entangling Roots Sensor
7231 //case 41054: break; // Copy Weapon
7232 // trigger_spell_id = 41055; break;
7233 //case 41248: break; // Consuming Strikes
7234 // trigger_spell_id = 41249; break;
7235 //case 42730: break: // Woe Strike
7236 //case 43453: break: // Rune Ward
7237 //case 43504: break; // Alterac Valley OnKill Proc Aura
7238 //case 44326: break: // Pure Energy Passive
7239 //case 44526: break; // Hate Monster (Spar) (30 sec)
7240 //case 44527: break; // Hate Monster (Spar Buddy) (30 sec)
7241 //case 44819: break; // Hate Monster (Spar Buddy) (>30% Health)
7242 //case 44820: break; // Hate Monster (Spar) (<30%)
7243 case 45057: // Evasive Maneuvers (Commendation of Kael`thas trinket)
7244 // reduce you below $s1% health
7245 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
7248 //case 45903: break: // Offensive State
7249 //case 46146: break: // [PH] Ahune Spanky Hands
7250 //case 46939: break; // Black Bow of the Betrayer
7251 // trigger_spell_id = 29471; - gain mana
7252 // 27526; - drain mana if possible
7253 case 43820: // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
7254 // Pct value stored in dummy
7255 basepoints
[0] = pVictim
->GetCreateHealth() * auraSpellInfo
->CalculateSimpleValue(EFFECT_INDEX_1
) / 100;
7258 //case 45205: break; // Copy Offhand Weapon
7259 //case 45343: break; // Dark Flame Aura
7260 //case 47300: break; // Dark Flame Aura
7261 //case 48876: break; // Beast's Mark
7262 // trigger_spell_id = 48877; break;
7263 //case 49059: break; // Horde, Hate Monster (Spar Buddy) (>30% Health)
7264 //case 50051: break; // Ethereal Pet Aura
7265 //case 50689: break; // Blood Presence (Rank 1)
7266 //case 50844: break; // Blood Mirror
7267 //case 52856: break; // Charge
7268 //case 54072: break; // Knockback Ball Passive
7269 //case 54476: break; // Blood Presence
7270 //case 54775: break; // Abandon Vehicle on Poly
7271 case 57345: // Darkmoon Card: Greatness
7275 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 60229;stat
= GetStat(STAT_STRENGTH
); }
7277 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 60233;stat
= GetStat(STAT_AGILITY
); }
7279 if (GetStat(STAT_INTELLECT
)> stat
) { trigger_spell_id
= 60234;stat
= GetStat(STAT_INTELLECT
);}
7281 if (GetStat(STAT_SPIRIT
) > stat
) { trigger_spell_id
= 60235; }
7284 //case 55580: break: // Mana Link
7285 //case 57587: break: // Steal Ranged ()
7286 //case 57594: break; // Copy Ranged Weapon
7287 //case 59237: break; // Beast's Mark
7288 // trigger_spell_id = 59233; break;
7289 //case 59288: break; // Infra-Green Shield
7290 //case 59532: break; // Abandon Passengers on Poly
7291 //case 59735: break: // Woe Strike
7292 case 64415: // // Val'anyr Hammer of Ancient Kings - Equip Effect
7295 if (!IsPositiveSpell(procSpell
->Id
))
7299 case 67702: // Death's Choice, Item - Coliseum 25 Normal Melee Trinket
7303 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67708;stat
= GetStat(STAT_STRENGTH
); }
7305 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67703; }
7308 case 67771: // Death's Choice (heroic), Item - Coliseum 25 Heroic Melee Trinket
7312 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67773;stat
= GetStat(STAT_STRENGTH
); }
7314 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67772; }
7319 case SPELLFAMILY_MAGE
:
7320 if (auraSpellInfo
->SpellIconID
== 2127) // Blazing Speed
7322 switch (auraSpellInfo
->Id
)
7324 case 31641: // Rank 1
7325 case 31642: // Rank 2
7326 trigger_spell_id
= 31643;
7329 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
7333 // Persistent Shield (Scarab Brooch trinket)
7334 else if(auraSpellInfo
->Id
== 26467)
7336 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
7337 basepoints
[0] = damage
* 15 / 100;
7339 trigger_spell_id
= 26470;
7342 case SPELLFAMILY_WARRIOR
:
7343 // Deep Wounds (replace triggered spells to directly apply DoT), dot spell have finilyflags
7344 if (auraSpellInfo
->SpellFamilyFlags
== UI64LIT(0x0) && auraSpellInfo
->SpellIconID
== 243)
7347 // DW should benefit of attack power, damage percent mods etc.
7348 // TODO: check if using offhand damage is correct and if it should be divided by 2
7349 if (haveOffhandWeapon() && getAttackTimer(BASE_ATTACK
) > getAttackTimer(OFF_ATTACK
))
7350 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
))/2;
7352 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXDAMAGE
))/2;
7354 switch (auraSpellInfo
->Id
)
7356 case 12834: basepoints
[0] = int32(weaponDamage
* 16 / 100); break;
7357 case 12849: basepoints
[0] = int32(weaponDamage
* 32 / 100); break;
7358 case 12867: basepoints
[0] = int32(weaponDamage
* 48 / 100); break;
7361 sLog
.outError("Unit::HandleProcTriggerSpell: DW unknown spell rank %u",auraSpellInfo
->Id
);
7365 // 1 tick/sec * 6 sec = 6 ticks
7368 trigger_spell_id
= 12721;
7371 if (auraSpellInfo
->Id
== 50421) // Scent of Blood
7372 trigger_spell_id
= 50422;
7374 case SPELLFAMILY_WARLOCK
:
7377 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
7379 Unit::AuraList
const& mAddFlatModifier
= GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER
);
7380 for(Unit::AuraList::const_iterator i
= mAddFlatModifier
.begin(); i
!= mAddFlatModifier
.end(); ++i
)
7382 if ((*i
)->GetModifier()->m_miscvalue
== SPELLMOD_CHANCE_OF_SUCCESS
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
7385 CastCustomSpell(this, 18371, &basepoints
[0], NULL
, NULL
, true, castItem
, triggeredByAura
);
7389 // Not remove charge (aura removed on death in any cases)
7390 // Need for correct work Drain Soul SPELL_AURA_CHANNEL_DEATH_ITEM aura
7393 // Nether Protection
7394 else if (auraSpellInfo
->SpellIconID
== 1985)
7398 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7400 case SPELL_SCHOOL_NORMAL
:
7401 return false; // ignore
7402 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 54370; break;
7403 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 54371; break;
7404 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 54375; break;
7405 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 54372; break;
7406 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 54374; break;
7407 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
7413 else if (auraSpellInfo
->Id
== 28845)
7415 // When your health drops below 20% ....
7416 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
7420 else if (auraSpellInfo
->Id
== 63156 || auraSpellInfo
->Id
== 63158)
7422 // Looking for dummy effect
7423 Aura
*aur
= GetAura(auraSpellInfo
->Id
, EFFECT_INDEX_1
);
7427 // If target's health is not below equal certain value (35%) not proc
7428 if (int32(pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth()) > aur
->GetModifier()->m_amount
)
7433 case SPELLFAMILY_PRIEST
:
7435 // Greater Heal Refund (Avatar Raiment set)
7436 if (auraSpellInfo
->Id
==37594)
7438 // Not give if target already have full health
7439 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
7441 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
7442 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
7444 trigger_spell_id
= 37595;
7447 else if (auraSpellInfo
->SpellIconID
== 1875)
7449 switch (auraSpellInfo
->Id
)
7451 case 27811: trigger_spell_id
= 27813; break;
7452 case 27815: trigger_spell_id
= 27817; break;
7453 case 27816: trigger_spell_id
= 27818; break;
7455 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
7458 basepoints
[0] = damage
* triggerAmount
/ 100 / 3;
7463 case SPELLFAMILY_DRUID
:
7465 // Druid Forms Trinket
7466 if (auraSpellInfo
->Id
==37336)
7470 case FORM_NONE
: trigger_spell_id
= 37344;break;
7471 case FORM_CAT
: trigger_spell_id
= 37341;break;
7473 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
7474 case FORM_TREE
: trigger_spell_id
= 37342;break;
7475 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
7480 // Druid T9 Feral Relic (Lacerate, Swipe, Mangle, and Shred)
7481 else if (auraSpellInfo
->Id
==67353)
7485 case FORM_CAT
: trigger_spell_id
= 67355; break;
7487 case FORM_DIREBEAR
: trigger_spell_id
= 67354; break;
7494 case SPELLFAMILY_HUNTER
:
7496 if (auraSpellInfo
->SpellIconID
== 3247 && auraSpellInfo
->SpellVisual
[0] == 0)
7498 basepoints
[0] = damage
* triggerAmount
/ 100 / 8;
7499 trigger_spell_id
= 63468;
7502 // Rapid Recuperation
7503 else if (auraSpellInfo
->Id
== 53228 || auraSpellInfo
->Id
== 53232)
7505 // This effect only from Rapid Fire (ability cast)
7506 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000020)))
7510 case SPELLFAMILY_PALADIN
:
7514 if (auraSpellInfo->SpellIconID == 2137)
7516 switch (auraSpellInfo->Id)
7518 case 31828: // Rank 1
7519 case 31829: // Rank 2
7520 case 31830: // Rank 3
7523 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
7529 if (auraSpellInfo
->Id
==37705)
7531 trigger_spell_id
= 37706;
7535 if (auraSpellInfo
->Id
==60510)
7537 trigger_spell_id
= 60515;
7541 else if (auraSpellInfo
->SpellIconID
==241)
7545 // procspell is triggered spell but we need mana cost of original casted spell
7546 uint32 originalSpellId
= procSpell
->Id
;
7548 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0001000000000000))
7550 switch(procSpell
->Id
)
7552 case 25914: originalSpellId
= 20473; break;
7553 case 25913: originalSpellId
= 20929; break;
7554 case 25903: originalSpellId
= 20930; break;
7555 case 27175: originalSpellId
= 27174; break;
7556 case 33074: originalSpellId
= 33072; break;
7557 case 48820: originalSpellId
= 48824; break;
7558 case 48821: originalSpellId
= 48825; break;
7560 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
7564 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
7567 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
7570 // percent stored in effect 1 (class scripts) base points
7571 int32 cost
= originalSpell
->manaCost
+ originalSpell
->ManaCostPercentage
* GetCreateMana() / 100;
7572 basepoints
[0] = cost
*auraSpellInfo
->CalculateSimpleValue(EFFECT_INDEX_1
)/100;
7573 trigger_spell_id
= 20272;
7576 // Lightning Capacitor
7577 else if (auraSpellInfo
->Id
==37657)
7579 if(!pVictim
|| !pVictim
->isAlive())
7582 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
7584 Aura
* dummy
= GetDummyAura(37658);
7585 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7586 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7589 RemoveAurasDueToSpell(37658);
7590 trigger_spell_id
= 37661;
7593 // Bonus Healing (Crystal Spire of Karabor mace)
7594 else if (auraSpellInfo
->Id
== 40971)
7596 // If your target is below $s1% health
7597 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
7600 // Thunder Capacitor
7601 else if (auraSpellInfo
->Id
== 54841)
7603 if(!pVictim
|| !pVictim
->isAlive())
7606 CastSpell(this, 54842, true, NULL
, triggeredByAura
);
7609 Aura
* dummy
= GetDummyAura(54842);
7610 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7611 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7614 RemoveAurasDueToSpell(54842);
7615 trigger_spell_id
= 54843;
7620 case SPELLFAMILY_SHAMAN
:
7622 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc
7623 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000400))
7625 switch(auraSpellInfo
->Id
)
7628 trigger_spell_id
= 26364; break;
7630 trigger_spell_id
= 26365; break;
7632 trigger_spell_id
= 26366; break;
7634 trigger_spell_id
= 26367; break;
7635 case 8134: // Rank 5
7636 trigger_spell_id
= 26369; break;
7637 case 10431: // Rank 6
7638 trigger_spell_id
= 26370; break;
7639 case 10432: // Rank 7
7640 trigger_spell_id
= 26363; break;
7641 case 25469: // Rank 8
7642 trigger_spell_id
= 26371; break;
7643 case 25472: // Rank 9
7644 trigger_spell_id
= 26372; break;
7645 case 49280: // Rank 10
7646 trigger_spell_id
= 49278; break;
7647 case 49281: // Rank 11
7648 trigger_spell_id
= 49279; break;
7650 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
7654 // Lightning Shield (The Ten Storms set)
7655 else if (auraSpellInfo
->Id
== 23551)
7657 trigger_spell_id
= 23552;
7660 // Damage from Lightning Shield (The Ten Storms set)
7661 else if (auraSpellInfo
->Id
== 23552)
7662 trigger_spell_id
= 27635;
7663 // Mana Surge (The Earthfury set)
7664 else if (auraSpellInfo
->Id
== 23572)
7668 basepoints
[0] = procSpell
->manaCost
* 35 / 100;
7669 trigger_spell_id
= 23571;
7672 // Nature's Guardian
7673 else if (auraSpellInfo
->SpellIconID
== 2013)
7675 // Check health condition - should drop to less 30% (damage deal after this!)
7676 if (!(10*(int32(GetHealth() - damage
)) < int32(3 * GetMaxHealth())))
7679 if(pVictim
&& pVictim
->isAlive())
7680 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
7682 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
7683 trigger_spell_id
= 31616;
7688 case SPELLFAMILY_DEATHKNIGHT
:
7691 if (auraSpellInfo
->SpellIconID
== 1930)
7695 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7697 case SPELL_SCHOOL_NORMAL
:
7698 return false; // ignore
7699 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 50490; break;
7700 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 50362; break;
7701 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 50488; break;
7702 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 50485; break;
7703 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 50489; break;
7704 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 50486; break;
7710 else if (auraSpellInfo
->SpellIconID
== 85)
7712 if (GetTypeId() != TYPEID_PLAYER
|| getClass() != CLASS_DEATH_KNIGHT
||
7713 !((Player
*)this)->IsBaseRuneSlotsOnCooldown(RUNE_BLOOD
))
7716 // Improved Blood Presence
7717 else if (auraSpellInfo
->Id
== 63611)
7719 if (GetTypeId() != TYPEID_PLAYER
|| !((Player
*)this)->isHonorOrXPTarget(pVictim
) || !damage
)
7721 basepoints
[0] = triggerAmount
* damage
/ 100;
7722 trigger_spell_id
= 50475;
7730 // All ok. Check current trigger spell
7731 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
7734 // Not cast unknown spell
7735 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
7739 // not allow proc extra attack spell at extra attack
7740 if (m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
))
7743 // Custom basepoints/target for exist spell
7744 // dummy basepoints or other customs
7745 switch(trigger_spell_id
)
7747 // Cast positive spell on enemy target
7748 case 7099: // Curse of Mending
7749 case 39647: // Curse of Mending
7750 case 29494: // Temptation
7751 case 20233: // Improved Lay on Hands (cast on target)
7756 // Combo points add triggers (need add combopoint only for main target, and after possible combopoints reset)
7757 case 15250: // Rogue Setup
7759 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
7761 break; // continue normal case
7763 // Finish movies that add combo
7764 case 14189: // Seal Fate (Netherblade set)
7765 case 14157: // Ruthlessness
7767 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
7770 // Bloodthirst (($m/100)% of max health)
7773 basepoints
[0] = int32(GetMaxHealth() * triggerAmount
/ 100);
7776 // Shamanistic Rage triggered spell
7779 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7782 // Enlightenment (trigger only from mana cost spells)
7785 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
7792 // As the spell is proced from pet's attack - find owner
7793 Unit
* owner
= GetOwner();
7794 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
7797 // This spell doesn't stack, but refreshes duration. So we receive current bonuses to minus them later.
7799 if (Aura
* aur
= owner
->GetAura(48090, EFFECT_INDEX_0
))
7800 curBonus
= aur
->GetModifier()->m_amount
;
7801 int32 spellDamage
= owner
->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_MAGIC
) - curBonus
;
7802 if(spellDamage
<= 0)
7805 // percent stored in owner talent dummy
7806 AuraList
const& dummyAuras
= owner
->GetAurasByType(SPELL_AURA_DUMMY
);
7807 for (AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
7809 if ((*i
)->GetSpellProto()->SpellIconID
== 3220)
7811 basepoints
[0] = basepoints
[1] = int32(spellDamage
* (*i
)->GetModifier()->m_amount
/ 100);
7820 // Remove cooldown on Shield Slam
7821 if (GetTypeId() == TYPEID_PLAYER
)
7822 ((Player
*)this)->RemoveSpellCategoryCooldown(1209, true);
7828 // have rank dependent proc chance, ignore too often cases
7829 // PPM = 2.5 * (rank of talent),
7830 uint32 rank
= sSpellMgr
.GetSpellRank(auraSpellInfo
->Id
);
7831 // 5 rank -> 100% 4 rank -> 80% and etc from full rate
7832 if(!roll_chance_i(20*rank
))
7841 // For trigger from Blizzard need exist Improved Blizzard
7842 if (procSpell
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)))
7845 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7846 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7848 int32 script
= (*i
)->GetModifier()->m_miscvalue
;
7849 if(script
==836 || script
==988 || script
==989)
7863 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7866 // Need stun, fear or silence mechanic
7867 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_SILENCE_AND_STUN_AND_FEAR_MASK
))
7871 // Burning Determination
7876 // Need Interrupt or Silenced mechanic
7877 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_INTERRUPT_AND_SILENCE_MASK
))
7884 // Proc only from trap activation (from periodic proc another aura of this spell)
7885 if (!(procFlags
& PROC_FLAG_ON_TRAP_ACTIVATION
) || !roll_chance_i(triggerAmount
))
7889 // Freezing Fog (Rime triggered)
7892 // Howling Blast cooldown reset
7893 if (GetTypeId() == TYPEID_PLAYER
)
7894 ((Player
*)this)->RemoveSpellCategoryCooldown(1248, true);
7897 // Druid - Savage Defense
7900 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7905 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
7908 // try detect target manually if not set
7910 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
7913 if (!target
|| target
!=this && !target
->isAlive())
7916 if (basepoints
[EFFECT_INDEX_0
] || basepoints
[EFFECT_INDEX_1
] || basepoints
[EFFECT_INDEX_2
])
7917 CastCustomSpell(target
,trigger_spell_id
,
7918 basepoints
[EFFECT_INDEX_0
] ? &basepoints
[EFFECT_INDEX_0
] : NULL
,
7919 basepoints
[EFFECT_INDEX_1
] ? &basepoints
[EFFECT_INDEX_1
] : NULL
,
7920 basepoints
[EFFECT_INDEX_2
] ? &basepoints
[EFFECT_INDEX_2
] : NULL
,
7921 true, castItem
, triggeredByAura
);
7923 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
7925 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7926 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
7931 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
7933 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
7935 if(!pVictim
|| !pVictim
->isAlive())
7938 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7939 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7941 // Basepoints of trigger aura
7942 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7944 uint32 triggered_spell_id
= 0;
7948 case 836: // Improved Blizzard (Rank 1)
7950 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7952 triggered_spell_id
= 12484;
7955 case 988: // Improved Blizzard (Rank 2)
7957 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7959 triggered_spell_id
= 12485;
7962 case 989: // Improved Blizzard (Rank 3)
7964 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7966 triggered_spell_id
= 12486;
7969 case 4086: // Improved Mend Pet (Rank 1)
7970 case 4087: // Improved Mend Pet (Rank 2)
7972 if(!roll_chance_i(triggerAmount
))
7975 triggered_spell_id
= 24406;
7978 case 4533: // Dreamwalker Raiment 2 pieces bonus
7981 if (!roll_chance_i(50))
7984 switch (pVictim
->getPowerType())
7986 case POWER_MANA
: triggered_spell_id
= 28722; break;
7987 case POWER_RAGE
: triggered_spell_id
= 28723; break;
7988 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
7994 case 4537: // Dreamwalker Raiment 6 pieces bonus
7995 triggered_spell_id
= 28750; // Blessing of the Claw
7997 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
7998 triggered_spell_id
= 37445; // Mana Surge
8000 case 6953: // Warbringer
8001 RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK
,0,true);
8003 case 7010: // Revitalize (rank 1)
8004 case 7011: // Revitalize (rank 2)
8005 case 7012: // Revitalize (rank 3)
8007 if(!roll_chance_i(triggerAmount
))
8010 switch( pVictim
->getPowerType() )
8012 case POWER_MANA
: triggered_spell_id
= 48542; break;
8013 case POWER_RAGE
: triggered_spell_id
= 48541; break;
8014 case POWER_ENERGY
: triggered_spell_id
= 48540; break;
8015 case POWER_RUNIC_POWER
: triggered_spell_id
= 48543; break;
8016 default: return false;
8023 if(!triggered_spell_id
)
8026 // standard non-dummy case
8027 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
8031 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
8035 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
8038 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
8040 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
8041 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
8046 void Unit::setPowerType(Powers new_powertype
)
8048 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
8050 if(GetTypeId() == TYPEID_PLAYER
)
8052 if(((Player
*)this)->GetGroup())
8053 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
8055 else if(((Creature
*)this)->isPet())
8057 Pet
*pet
= ((Pet
*)this);
8058 if(pet
->isControlled())
8060 Unit
*owner
= GetOwner();
8061 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
8062 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
8066 switch(new_powertype
)
8072 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
8073 SetPower( POWER_RAGE
,0);
8076 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
8077 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
8080 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
8082 case POWER_HAPPINESS
:
8083 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
8084 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
8089 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
8091 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
8094 static uint64 guid
= 0; // prevent repeating spam same faction problem
8096 if(GetGUID() != guid
)
8098 if(GetTypeId() == TYPEID_PLAYER
)
8099 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
8101 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
8108 bool Unit::IsHostileTo(Unit
const* unit
) const
8110 // always non-hostile to self
8114 // always non-hostile to GM in GM mode
8115 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
8118 // always hostile to enemy
8119 if(getVictim()==unit
|| unit
->getVictim()==this)
8122 // test pet/charm masters instead pers/charmeds
8123 Unit
const* testerOwner
= GetCharmerOrOwner();
8124 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
8126 // always hostile to owner's enemy
8127 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
8130 // always hostile to enemy owner
8131 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
8134 // always hostile to owner of owner's enemy
8135 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
8138 Unit
const* tester
= testerOwner
? testerOwner
: this;
8139 Unit
const* target
= targetOwner
? targetOwner
: unit
;
8141 // always non-hostile to target with common owner, or to owner/pet
8145 // special cases (Duel, etc)
8146 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
8148 Player
const* pTester
= (Player
const*)tester
;
8149 Player
const* pTarget
= (Player
const*)target
;
8152 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
8156 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
8160 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
8164 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
8168 // Green/Blue (can't attack)
8169 if(pTester
->GetTeam()==pTarget
->GetTeam())
8172 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
8173 return pTester
->IsPvP() && pTarget
->IsPvP();
8176 // faction base cases
8177 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8178 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8179 if(!tester_faction
|| !target_faction
)
8182 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8185 // PvC forced reaction and reputation case
8186 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8189 if(target_faction
->faction
)
8191 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8192 return *force
<= REP_HOSTILE
;
8194 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
8195 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8196 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8197 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8200 // CvP forced reaction and reputation case
8201 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8204 if(tester_faction
->faction
)
8206 if(ReputationRank
const* force
= ((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8207 return *force
<= REP_HOSTILE
;
8209 // apply reputation state
8210 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
8211 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
8212 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) <= REP_HOSTILE
;
8216 // common faction based case (CvC,PvC,CvP)
8217 return tester_faction
->IsHostileTo(*target_faction
);
8220 bool Unit::IsFriendlyTo(Unit
const* unit
) const
8222 // always friendly to self
8226 // always friendly to GM in GM mode
8227 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
8230 // always non-friendly to enemy
8231 if(getVictim()==unit
|| unit
->getVictim()==this)
8234 // test pet/charm masters instead pers/charmeds
8235 Unit
const* testerOwner
= GetCharmerOrOwner();
8236 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
8238 // always non-friendly to owner's enemy
8239 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
8242 // always non-friendly to enemy owner
8243 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
8246 // always non-friendly to owner of owner's enemy
8247 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
8250 Unit
const* tester
= testerOwner
? testerOwner
: this;
8251 Unit
const* target
= targetOwner
? targetOwner
: unit
;
8253 // always friendly to target with common owner, or to owner/pet
8257 // special cases (Duel)
8258 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
8260 Player
const* pTester
= (Player
const*)tester
;
8261 Player
const* pTarget
= (Player
const*)target
;
8264 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
8268 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
8272 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
8276 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
8280 // Green/Blue (non-attackable)
8281 if(pTester
->GetTeam()==pTarget
->GetTeam())
8284 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
8285 return !pTarget
->IsPvP();
8288 // faction base cases
8289 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8290 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8291 if(!tester_faction
|| !target_faction
)
8294 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8297 // PvC forced reaction and reputation case
8298 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8301 if(target_faction
->faction
)
8303 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8304 return *force
>= REP_FRIENDLY
;
8306 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
8307 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8308 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8309 return !(factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8312 // CvP forced reaction and reputation case
8313 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8316 if(tester_faction
->faction
)
8318 if(ReputationRank
const* force
=((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8319 return *force
>= REP_FRIENDLY
;
8321 // apply reputation state
8322 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
8323 if(raw_tester_faction
->reputationListID
>=0 )
8324 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) >= REP_FRIENDLY
;
8328 // common faction based case (CvC,PvC,CvP)
8329 return tester_faction
->IsFriendlyTo(*target_faction
);
8332 bool Unit::IsHostileToPlayers() const
8334 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8335 if(!my_faction
|| !my_faction
->faction
)
8338 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8339 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8342 return my_faction
->IsHostileToPlayers();
8345 bool Unit::IsNeutralToAll() const
8347 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8348 if(!my_faction
|| !my_faction
->faction
)
8351 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8352 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8355 return my_faction
->IsNeutralToAll();
8358 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
8360 if(!victim
|| victim
== this)
8363 // dead units can neither attack nor be attacked
8364 if(!isAlive() || !victim
->IsInWorld() || !victim
->isAlive())
8367 // player cannot attack in mount state
8368 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
8371 // nobody can attack GM in GM-mode
8372 if(victim
->GetTypeId()==TYPEID_PLAYER
)
8374 if(((Player
*)victim
)->isGameMaster())
8379 if(((Creature
*)victim
)->IsInEvadeMode())
8383 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
8384 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
8385 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
8387 // in fighting already
8390 if (m_attacking
== victim
)
8392 // switch to melee attack from ranged/magic
8393 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
8395 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8396 SendMeleeAttackStart(victim
);
8402 // remove old target data
8408 // set position before any AI calls/assistance
8409 if(GetTypeId()==TYPEID_UNIT
)
8410 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
8414 SetTargetGUID(victim
->GetGUID());
8417 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8419 m_attacking
= victim
;
8420 m_attacking
->_addAttacker(this);
8422 if (GetTypeId() == TYPEID_UNIT
)
8424 ((Creature
*)this)->SendAIReaction(AI_REACTION_HOSTILE
);
8425 ((Creature
*)this)->CallAssistance();
8428 // delay offhand weapon attack to next attack time
8429 if(haveOffhandWeapon())
8430 resetAttackTimer(OFF_ATTACK
);
8433 SendMeleeAttackStart(victim
);
8438 bool Unit::AttackStop(bool targetSwitch
/*=false*/)
8443 Unit
* victim
= m_attacking
;
8445 m_attacking
->_removeAttacker(this);
8451 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
8453 InterruptSpell(CURRENT_MELEE_SPELL
);
8455 // reset only at real combat stop
8456 if(!targetSwitch
&& GetTypeId()==TYPEID_UNIT
)
8458 ((Creature
*)this)->SetNoCallAssistance(false);
8460 if (((Creature
*)this)->HasSearchedAssistance())
8462 ((Creature
*)this)->SetNoSearchAssistance(false);
8463 UpdateSpeed(MOVE_RUN
, false);
8467 SendMeleeAttackStop(victim
);
8472 void Unit::CombatStop(bool includingCast
)
8474 if (includingCast
&& IsNonMeleeSpellCasted(false))
8475 InterruptNonMeleeSpells(false);
8478 RemoveAllAttackers();
8479 if( GetTypeId()==TYPEID_PLAYER
)
8480 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
8484 struct CombatStopWithPetsHelper
8486 explicit CombatStopWithPetsHelper(bool _includingCast
) : includingCast(_includingCast
) {}
8487 void operator()(Unit
* unit
) const { unit
->CombatStop(includingCast
); }
8491 void Unit::CombatStopWithPets(bool includingCast
)
8493 CombatStop(includingCast
);
8494 CallForAllControlledUnits(CombatStopWithPetsHelper(includingCast
),false,true,true);
8497 struct IsAttackingPlayerHelper
8499 explicit IsAttackingPlayerHelper() {}
8500 bool operator()(Unit
* unit
) const { return unit
->isAttackingPlayer(); }
8503 bool Unit::isAttackingPlayer() const
8505 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
8508 return CheckAllControlledUnits(IsAttackingPlayerHelper(),true,true,true);
8511 void Unit::RemoveAllAttackers()
8513 while (!m_attackers
.empty())
8515 AttackerSet::iterator iter
= m_attackers
.begin();
8516 if(!(*iter
)->AttackStop())
8518 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
8519 m_attackers
.erase(iter
);
8524 bool Unit::HasAuraStateForCaster(AuraState flag
, uint64 caster
) const
8526 if(!HasAuraState(flag
))
8529 // single per-caster aura state
8530 if(flag
== AURA_STATE_CONFLAGRATE
)
8532 Unit::AuraList
const& dotList
= GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
8533 for(Unit::AuraList::const_iterator i
= dotList
.begin(); i
!= dotList
.end(); ++i
)
8535 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
8536 (*i
)->GetCasterGUID() == caster
&&
8538 (((*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000004)) ||
8540 ((*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x00000002)))
8552 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
8556 if (!HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)))
8558 SetFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8559 if(GetTypeId() == TYPEID_PLAYER
)
8561 const PlayerSpellMap
& sp_list
= ((Player
*)this)->GetSpellMap();
8562 for (PlayerSpellMap::const_iterator itr
= sp_list
.begin(); itr
!= sp_list
.end(); ++itr
)
8564 if(itr
->second
.state
== PLAYERSPELL_REMOVED
) continue;
8565 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
8566 if (!spellInfo
|| !IsPassiveSpell(itr
->first
)) continue;
8567 if (spellInfo
->CasterAuraState
== flag
)
8568 CastSpell(this, itr
->first
, true, NULL
);
8575 if (HasFlag(UNIT_FIELD_AURASTATE
,1<<(flag
-1)))
8577 RemoveFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8579 if (flag
!= AURA_STATE_ENRAGE
) // enrage aura state triggering continues auras
8581 Unit::AuraMap
& tAuras
= GetAuras();
8582 for (Unit::AuraMap::iterator itr
= tAuras
.begin(); itr
!= tAuras
.end();)
8584 SpellEntry
const* spellProto
= (*itr
).second
->GetSpellProto();
8585 if (spellProto
->CasterAuraState
== flag
)
8595 Unit
*Unit::GetOwner() const
8597 if(uint64 ownerid
= GetOwnerGUID())
8598 return ObjectAccessor::GetUnit(*this, ownerid
);
8602 Unit
*Unit::GetCharmer() const
8604 if(uint64 charmerid
= GetCharmerGUID())
8605 return ObjectAccessor::GetUnit(*this, charmerid
);
8609 bool Unit::IsCharmerOrOwnerPlayerOrPlayerItself() const
8611 if (GetTypeId()==TYPEID_PLAYER
)
8614 return IS_PLAYER_GUID(GetCharmerOrOwnerGUID());
8617 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
8619 uint64 guid
= GetCharmerOrOwnerGUID();
8620 if(IS_PLAYER_GUID(guid
))
8621 return ObjectAccessor::FindPlayer(guid
);
8623 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
8626 Pet
* Unit::GetPet() const
8628 if(uint64 pet_guid
= GetPetGUID())
8630 if(Pet
* pet
= GetMap()->GetPet(pet_guid
))
8633 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
8634 const_cast<Unit
*>(this)->SetPet(0);
8640 Unit
* Unit::GetCharm() const
8642 if (uint64 charm_guid
= GetCharmGUID())
8644 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
8647 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
8648 const_cast<Unit
*>(this)->SetCharm(NULL
);
8654 void Unit::Uncharm()
8656 if (Unit
* charm
= GetCharm())
8658 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM
);
8659 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS
);
8663 float Unit::GetCombatDistance( const Unit
* target
) const
8665 float radius
= target
->GetFloatValue(UNIT_FIELD_COMBATREACH
) + GetFloatValue(UNIT_FIELD_COMBATREACH
);
8666 float dx
= GetPositionX() - target
->GetPositionX();
8667 float dy
= GetPositionY() - target
->GetPositionY();
8668 float dz
= GetPositionZ() - target
->GetPositionZ();
8669 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - radius
;
8670 return ( dist
> 0 ? dist
: 0);
8673 void Unit::SetPet(Pet
* pet
)
8675 SetPetGUID(pet
? pet
->GetGUID() : 0);
8677 if(pet
&& GetTypeId() == TYPEID_PLAYER
)
8678 ((Player
*)this)->SendPetGUIDs();
8681 void Unit::SetCharm(Unit
* pet
)
8683 SetCharmGUID(pet
? pet
->GetGUID() : 0);
8686 void Unit::AddGuardian( Pet
* pet
)
8688 m_guardianPets
.insert(pet
->GetGUID());
8691 void Unit::RemoveGuardian( Pet
* pet
)
8693 m_guardianPets
.erase(pet
->GetGUID());
8696 void Unit::RemoveGuardians()
8698 while(!m_guardianPets
.empty())
8700 uint64 guid
= *m_guardianPets
.begin();
8701 if(Pet
* pet
= GetMap()->GetPet(guid
))
8702 pet
->Remove(PET_SAVE_AS_DELETED
);
8704 m_guardianPets
.erase(guid
);
8708 Pet
* Unit::FindGuardianWithEntry(uint32 entry
)
8710 // pet guid middle part is entry (and creature also)
8711 // and in guardian list must be guardians with same entry _always_
8712 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
8713 if(Pet
* pet
= GetMap()->GetPet(*itr
))
8714 if (pet
->GetEntry() == entry
)
8720 Unit
* Unit::_GetTotem(TotemSlot slot
) const
8722 return GetTotem(slot
);
8725 Totem
* Unit::GetTotem(TotemSlot slot
) const
8727 if(slot
>= MAX_TOTEM_SLOT
|| !IsInWorld())
8730 Creature
*totem
= GetMap()->GetCreature(m_TotemSlot
[slot
]);
8731 return totem
&& totem
->isTotem() ? (Totem
*)totem
: NULL
;
8734 bool Unit::IsAllTotemSlotsUsed() const
8736 for (int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8737 if (!m_TotemSlot
[i
])
8742 void Unit::_AddTotem(TotemSlot slot
, Totem
* totem
)
8744 m_TotemSlot
[slot
] = totem
->GetGUID();
8747 void Unit::_RemoveTotem(Totem
* totem
)
8749 for(int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8751 if (m_TotemSlot
[i
] == totem
->GetGUID())
8761 void Unit::UnsummonAllTotems()
8763 for (int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8764 if (Totem
* totem
= GetTotem(TotemSlot(i
)))
8768 int32
Unit::DealHeal(Unit
*pVictim
, uint32 addhealth
, SpellEntry
const *spellProto
, bool critical
)
8770 int32 gain
= pVictim
->ModifyHealth(int32(addhealth
));
8774 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8777 if (unit
->GetTypeId()==TYPEID_PLAYER
)
8779 // overheal = addhealth - gain
8780 unit
->SendHealSpellLog(pVictim
, spellProto
->Id
, addhealth
, addhealth
- gain
, critical
);
8782 if (BattleGround
*bg
= ((Player
*)unit
)->GetBattleGround())
8783 bg
->UpdatePlayerScore((Player
*)unit
, SCORE_HEALING_DONE
, gain
);
8785 // use the actual gain, as the overheal shall not be counted, skip gain 0 (it ignored anyway in to criteria)
8787 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE
, gain
, 0, pVictim
);
8789 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED
, addhealth
);
8792 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
8794 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED
, gain
);
8795 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED
, addhealth
);
8801 Unit
* Unit::SelectMagnetTarget(Unit
*victim
, SpellEntry
const *spellInfo
)
8807 if(spellInfo
&& (spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
|| spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
))
8809 Unit::AuraList
const& magnetAuras
= victim
->GetAurasByType(SPELL_AURA_SPELL_MAGNET
);
8810 for(Unit::AuraList::const_iterator itr
= magnetAuras
.begin(); itr
!= magnetAuras
.end(); ++itr
)
8811 if(Unit
* magnet
= (*itr
)->GetCaster())
8812 if(magnet
->IsWithinLOSInMap(this) && magnet
->isAlive())
8815 // Melee && ranged case
8818 AuraList
const& hitTriggerAuras
= victim
->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER
);
8819 for(AuraList::const_iterator i
= hitTriggerAuras
.begin(); i
!= hitTriggerAuras
.end(); ++i
)
8820 if(Unit
* magnet
= (*i
)->GetCaster())
8821 if(magnet
->isAlive() && magnet
->IsWithinLOSInMap(this))
8822 if(roll_chance_i((*i
)->GetModifier()->m_amount
))
8829 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, uint32 OverHeal
, bool critical
)
8832 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
8833 data
<< pVictim
->GetPackGUID();
8834 data
<< GetPackGUID();
8835 data
<< uint32(SpellID
);
8836 data
<< uint32(Damage
);
8837 data
<< uint32(OverHeal
);
8838 data
<< uint8(critical
? 1 : 0);
8839 data
<< uint8(0); // unused in client?
8840 SendMessageToSet(&data
, true);
8843 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8845 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
8846 data
<< pVictim
->GetPackGUID();
8847 data
<< GetPackGUID();
8848 data
<< uint32(SpellID
);
8849 data
<< uint32(powertype
);
8850 data
<< uint32(Damage
);
8851 SendMessageToSet(&data
, true);
8854 void Unit::EnergizeBySpell(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8856 SendEnergizeSpellLog(pVictim
, SpellID
, Damage
, powertype
);
8857 // needs to be called after sending spell log
8858 pVictim
->ModifyPower(powertype
, Damage
);
8862 * Calculates caster part of spell damage bonuses,
8863 * also includes different bonuses dependent from target auras
8865 uint32
Unit::SpellDamageBonusDone(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
8867 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
8870 // For totems get damage bonus from owner (statue isn't totem in fact)
8871 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8873 if(Unit
* owner
= GetOwner())
8874 return owner
->SpellDamageBonusDone(pVictim
, spellProto
, pdamage
, damagetype
);
8877 float DoneTotalMod
= 1.0f
;
8878 int32 DoneTotal
= 0;
8881 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
8882 DoneTotalMod
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
8884 if (!(spellProto
->AttributesEx6
& SPELL_ATTR_EX6_NO_DMG_PERCENT_MODS
))
8886 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
8887 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
8889 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
8890 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
8891 // -1 == any item class (not wand then)
8892 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
8893 // 0 == any inventory type (not wand then)
8895 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8900 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8901 // Add flat bonus from spell damage versus
8902 DoneTotal
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
8903 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
8904 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
8905 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8906 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8908 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
8909 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
8911 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8912 DoneTotalMod
+= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8915 // done scripted mod (take it from owner)
8916 Unit
*owner
= GetOwner();
8917 if (!owner
) owner
= this;
8918 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8919 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
8921 if (!(*i
)->isAffectedOnSpell(spellProto
))
8923 switch((*i
)->GetModifier()->m_miscvalue
)
8925 case 4920: // Molten Fury
8927 case 6917: // Death's Embrace
8931 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8932 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8939 // effect 1 m_amount
8940 int32 maxPercent
= (*i
)->GetModifier()->m_amount
;
8941 // effect 0 m_amount
8942 int32 stepPercent
= CalculateSpellDamage(this, (*i
)->GetSpellProto(), EFFECT_INDEX_0
);
8943 // count affliction effects and calc additional damage in percentage
8944 int32 modPercent
= 0;
8945 AuraMap
const& victimAuras
= pVictim
->GetAuras();
8946 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
8948 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
8949 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_WARLOCK
|| !(m_spell
->SpellFamilyFlags
& UI64LIT(0x0004071B8044C402)))
8951 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
8952 if (modPercent
>= maxPercent
)
8954 modPercent
= maxPercent
;
8958 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
8961 case 6916: // Death's Embrace
8964 if (HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
))
8965 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8967 case 5481: // Starfire Bonus
8969 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000200002)))
8970 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8973 case 4418: // Increased Shock Damage
8974 case 4554: // Increased Lightning Damage
8975 case 4555: // Improved Moonfire
8976 case 5142: // Increased Lightning Damage
8977 case 5147: // Improved Consecration / Libram of Resurgence
8978 case 5148: // Idol of the Shooting Star
8979 case 6008: // Increased Lightning Damage
8980 case 8627: // Totem of Hex
8982 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
8990 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
8992 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8993 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8995 else // Tundra Stalker
8997 // Frost Fever (target debuff)
8998 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
8999 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9004 case 7293: // Rage of Rivendare
9006 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
9007 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9013 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000000000008000), 0, GetGUID()))
9014 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9024 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
9025 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9031 // Custom scripted damage
9032 switch(spellProto
->SpellFamilyName
)
9034 case SPELLFAMILY_MAGE
:
9037 if (spellProto
->SpellIconID
== 186)
9039 if (pVictim
->isFrozen())
9041 float multiplier
= 3.0f
;
9043 // if target have higher level
9044 if (pVictim
->getLevel() > getLevel())
9045 // Glyph of Ice Lance
9046 if (Aura
* glyph
= GetDummyAura(56377))
9047 multiplier
= glyph
->GetModifier()->m_amount
;
9049 DoneTotalMod
*= multiplier
;
9052 // Torment the weak affected (Arcane Barrage, Arcane Blast, Frostfire Bolt, Arcane Missiles, Fireball)
9053 if ((spellProto
->SpellFamilyFlags
& UI64LIT(0x0000900020200021)) &&
9054 (pVictim
->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED
) || pVictim
->HasAuraType(SPELL_AURA_HASTE_ALL
)))
9056 //Search for Torment the weak dummy aura
9057 Unit::AuraList
const& ttw
= GetAurasByType(SPELL_AURA_DUMMY
);
9058 for(Unit::AuraList::const_iterator i
= ttw
.begin(); i
!= ttw
.end(); ++i
)
9060 if ((*i
)->GetSpellProto()->SpellIconID
== 3263)
9062 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9069 case SPELLFAMILY_WARLOCK
:
9072 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
9074 if (pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth() <= 25)
9079 case SPELLFAMILY_PRIEST
:
9082 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x00000080))
9085 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x00100000), NULL
))
9086 if (Aura
*aur
= GetAura(55692, EFFECT_INDEX_0
))
9087 DoneTotalMod
*= (aur
->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9091 case SPELLFAMILY_DRUID
:
9093 // Improved Insect Swarm (Wrath part)
9094 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
9096 // if Insect Swarm on target
9097 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x000000000200000), 0, GetGUID()))
9099 Unit::AuraList
const& improvedSwarm
= GetAurasByType(SPELL_AURA_DUMMY
);
9100 for(Unit::AuraList::const_iterator iter
= improvedSwarm
.begin(); iter
!= improvedSwarm
.end(); ++iter
)
9102 if ((*iter
)->GetSpellProto()->SpellIconID
== 1771)
9104 DoneTotalMod
*= ((*iter
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9112 case SPELLFAMILY_DEATHKNIGHT
:
9114 // Icy Touch and Howling Blast
9115 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000200000002))
9119 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
9120 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
9122 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
9131 // search for Glacier Rot dummy aura
9132 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9133 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
9135 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
9137 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9148 // Done fixed damage bonus auras
9149 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonusDone(GetSpellSchoolMask(spellProto
));
9151 // Pets just add their bonus damage to their spell damage
9152 // note that their spell damage is just gain of their own auras
9153 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9154 DoneAdvertisedBenefit
+= ((Pet
*)this)->GetBonusDamage();
9156 if (DoneAdvertisedBenefit
)
9158 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9160 // Spellmod SpellDamage
9161 float SpellModSpellDamage
= 100.0f
;
9162 if(Player
* modOwner
= GetSpellModOwner())
9163 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
9164 SpellModSpellDamage
/= 100.0f
;
9166 // Distribute Damage over multiple effects, reduce by AoE
9169 // Not apply this to creature casted spells
9170 if (GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
9172 // Check for table values
9173 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9175 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
9177 if (bonus
->ap_bonus
)
9178 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
));
9180 // Default calculation
9182 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
);
9184 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* LvlPenalty
* SpellModSpellDamage
);
9187 float tmpDamage
= (int32(pdamage
) + DoneTotal
* int32(stack
)) * DoneTotalMod
;
9188 // apply spellmod to Done damage (flat and pct)
9189 if(Player
* modOwner
= GetSpellModOwner())
9190 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
9192 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9196 * Calculates target part of spell damage bonuses,
9197 * will be called on each tick for periodic damage over time auras
9199 uint32
Unit::SpellDamageBonusTaken(Unit
*pCaster
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
9201 if(!spellProto
|| !pCaster
|| damagetype
==DIRECT_DAMAGE
)
9204 // Taken total percent damage auras
9205 float TakenTotalMod
= 1.0f
;
9206 int32 TakenTotal
= 0;
9209 AuraList
const& mModDamagePercentTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
9210 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
9212 if ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
))
9213 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9216 // .. taken pct: dummy auras
9217 if (GetTypeId() == TYPEID_PLAYER
)
9220 if (Aura
*dummy
= GetDummyAura(45182))
9222 float mod
= -((Player
*)this)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
9223 if (mod
< float(dummy
->GetModifier()->m_amount
))
9224 mod
= float(dummy
->GetModifier()->m_amount
);
9225 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
9229 // From caster spells
9230 AuraList
const& mOwnerTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_FROM_CASTER
);
9231 for(AuraList::const_iterator i
= mOwnerTaken
.begin(); i
!= mOwnerTaken
.end(); ++i
)
9233 if ((*i
)->GetCasterGUID() == pCaster
->GetGUID() && (*i
)->isAffectedOnSpell(spellProto
))
9234 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9237 // Mod damage from spell mechanic
9238 TakenTotalMod
*= GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,GetAllSpellMechanicMask(spellProto
));
9240 // Mod damage taken from AoE spells
9241 if(IsAreaOfEffectSpell(spellProto
))
9243 AuraList
const& avoidAuras
= GetAurasByType(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
9244 for(AuraList::const_iterator itr
= avoidAuras
.begin(); itr
!= avoidAuras
.end(); ++itr
)
9245 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9248 // Taken fixed damage bonus auras
9249 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusTaken(GetSpellSchoolMask(spellProto
));
9251 if (TakenAdvertisedBenefit
)
9253 float LvlPenalty
= pCaster
->CalculateLevelPenalty(spellProto
);
9255 // Distribute Damage over multiple effects, reduce by AoE
9258 // Not apply this to creature casted spells
9259 if (pCaster
->GetTypeId()==TYPEID_UNIT
&& !((Creature
*)pCaster
)->isPet())
9261 // Check for table values
9262 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9263 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
9264 // Default calculation
9266 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
);
9268 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
* LvlPenalty
);
9271 float tmpDamage
= (int32(pdamage
) + TakenTotal
* int32(stack
)) * TakenTotalMod
;
9273 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9276 int32
Unit::SpellBaseDamageBonusDone(SpellSchoolMask schoolMask
)
9278 int32 DoneAdvertisedBenefit
= 0;
9281 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9282 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
9284 if (((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
9285 (*i
)->GetSpellProto()->EquippedItemClass
== -1 && // -1 == any item class (not wand then)
9286 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0) // 0 == any inventory type (not wand then)
9287 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9290 if (GetTypeId() == TYPEID_PLAYER
)
9293 DoneAdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9295 // Damage bonus from stats
9296 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
9297 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
9299 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9301 // stat used stored in miscValueB for this aura
9302 Stats usedStat
= Stats((*i
)->GetMiscBValue());
9303 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9306 // ... and attack power
9307 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
9308 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
9310 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9311 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9315 return DoneAdvertisedBenefit
;
9318 int32
Unit::SpellBaseDamageBonusTaken(SpellSchoolMask schoolMask
)
9320 int32 TakenAdvertisedBenefit
= 0;
9323 AuraList
const& mDamageTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
9324 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9326 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9327 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9330 return TakenAdvertisedBenefit
;
9333 bool Unit::IsSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
9335 // not critting spell
9336 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
9339 float crit_chance
= 0.0f
;
9340 switch(spellProto
->DmgClass
)
9342 case SPELL_DAMAGE_CLASS_NONE
:
9344 case SPELL_DAMAGE_CLASS_MAGIC
:
9346 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
9348 // For other schools
9349 else if (GetTypeId() == TYPEID_PLAYER
)
9350 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
9353 crit_chance
= float(m_baseSpellCritChance
);
9354 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9359 if (!IsPositiveSpell(spellProto
->Id
))
9361 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
9362 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
9363 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
9364 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
9365 // Modify by player victim resilience
9366 crit_chance
-= pVictim
->GetSpellCritChanceReduction();
9369 // scripted (increase crit chance ... against ... target by x%)
9370 // scripted (Increases the critical effect chance of your .... by x% on targets ...)
9371 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9372 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9374 if (!((*i
)->isAffectedOnSpell(spellProto
)))
9376 switch((*i
)->GetModifier()->m_miscvalue
)
9378 case 849: if (pVictim
->isFrozen()) crit_chance
+= 17.0f
; break; //Shatter Rank 1
9379 case 910: if (pVictim
->isFrozen()) crit_chance
+= 34.0f
; break; //Shatter Rank 2
9380 case 911: if (pVictim
->isFrozen()) crit_chance
+= 50.0f
; break; //Shatter Rank 3
9381 case 7917: // Glyph of Shadowburn
9382 if (pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9383 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9385 case 7997: // Renewed Hope
9387 if (pVictim
->HasAura(6788))
9388 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9394 // Custom crit by class
9395 switch(spellProto
->SpellFamilyName
)
9397 case SPELLFAMILY_PRIEST
:
9399 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000800))
9401 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth()/2)
9403 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9404 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9406 // Improved Flash Heal
9407 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_PRIEST
&&
9408 (*i
)->GetSpellProto()->SpellIconID
== 2542)
9410 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9416 case SPELLFAMILY_DRUID
:
9417 // Improved Insect Swarm (Starfire part)
9418 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
9420 // search for Moonfire on target
9421 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x000000000000002), 0, GetGUID()))
9423 Unit::AuraList
const& improvedSwarm
= GetAurasByType(SPELL_AURA_DUMMY
);
9424 for(Unit::AuraList::const_iterator iter
= improvedSwarm
.begin(); iter
!= improvedSwarm
.end(); ++iter
)
9426 if ((*iter
)->GetSpellProto()->SpellIconID
== 1771)
9428 crit_chance
+= (*iter
)->GetModifier()->m_amount
;
9435 case SPELLFAMILY_PALADIN
:
9437 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000040000000))
9439 Aura
*aura
= pVictim
->GetDummyAura(58597);
9440 if (aura
&& aura
->GetCasterGUID() == GetGUID())
9441 crit_chance
+=aura
->GetModifier()->m_amount
;
9444 else if (spellProto
->Category
== 19)
9446 if (pVictim
->GetCreatureTypeMask() & CREATURE_TYPEMASK_DEMON_OR_UNDEAD
)
9450 case SPELLFAMILY_SHAMAN
:
9452 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000100000000000))
9455 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000000010000000), 0, GetGUID()))
9463 case SPELL_DAMAGE_CLASS_MELEE
:
9464 case SPELL_DAMAGE_CLASS_RANGED
:
9467 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
9469 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9476 // only players use intelligence for critical chance computations
9477 if(Player
* modOwner
= GetSpellModOwner())
9478 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
9480 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
9481 if (roll_chance_f(crit_chance
))
9486 uint32
Unit::SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9488 // Calculate critical bonus
9490 switch(spellProto
->DmgClass
)
9492 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9493 case SPELL_DAMAGE_CLASS_RANGED
:
9494 crit_bonus
= damage
;
9497 crit_bonus
= damage
/ 2; // for spells is 50%
9501 // adds additional damage to crit_bonus (from talents)
9502 if(Player
* modOwner
= GetSpellModOwner())
9503 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
9506 return damage
+= crit_bonus
;
9508 int32 critPctDamageMod
= 0;
9509 if(spellProto
->DmgClass
>= SPELL_DAMAGE_CLASS_MELEE
)
9511 if(GetWeaponAttackType(spellProto
) == RANGED_ATTACK
)
9512 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
9514 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
9517 critPctDamageMod
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_DAMAGE
,GetSpellSchoolMask(spellProto
));
9519 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, GetSpellSchoolMask(spellProto
));
9521 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9522 critPctDamageMod
+= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
);
9524 if(critPctDamageMod
!=0)
9525 crit_bonus
= int32(crit_bonus
* float((100.0f
+ critPctDamageMod
)/100.0f
));
9528 damage
+= crit_bonus
;
9533 uint32
Unit::SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9535 // Calculate critical bonus
9537 switch(spellProto
->DmgClass
)
9539 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9540 case SPELL_DAMAGE_CLASS_RANGED
:
9541 // TODO: write here full calculation for melee/ranged spells
9542 crit_bonus
= damage
;
9545 crit_bonus
= damage
/ 2; // for spells is 50%
9551 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9552 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
9556 damage
+= crit_bonus
;
9558 damage
= int32(damage
* GetTotalAuraMultiplier(SPELL_AURA_MOD_CRITICAL_HEALING_AMOUNT
));
9564 * Calculates caster part of healing spell bonuses,
9565 * also includes different bonuses dependent from target auras
9567 uint32
Unit::SpellHealingBonusDone(Unit
*pVictim
, SpellEntry
const *spellProto
, int32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9569 // For totems get healing bonus from owner (statue isn't totem in fact)
9570 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
9571 if(Unit
* owner
= GetOwner())
9572 return owner
->SpellHealingBonusDone(pVictim
, spellProto
, healamount
, damagetype
, stack
);
9574 // No heal amount for this class spells
9575 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9576 return healamount
< 0 ? 0 : healamount
;
9579 // Done total percent damage auras
9580 float DoneTotalMod
= 1.0f
;
9581 int32 DoneTotal
= 0;
9583 // Healing done percent
9584 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
9585 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
9586 DoneTotalMod
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
9588 // done scripted mod (take it from owner)
9589 Unit
*owner
= GetOwner();
9590 if (!owner
) owner
= this;
9591 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9592 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9594 if (!(*i
)->isAffectedOnSpell(spellProto
))
9596 switch((*i
)->GetModifier()->m_miscvalue
)
9598 case 4415: // Increased Rejuvenation Healing
9600 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
9601 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
9603 case 7997: // Renewed Hope
9605 if (pVictim
->HasAura(6788))
9606 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9608 case 21: // Test of Faith
9611 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
9612 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9614 case 7798: // Glyph of Regrowth
9616 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_HEAL
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000000040)))
9617 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9620 case 8477: // Nourish Heal Boost
9622 int32 stepPercent
= (*i
)->GetModifier()->m_amount
;
9624 int ownHotCount
= 0; // counted HoT types amount, not stacks
9626 Unit::AuraList
const& RejorRegr
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_HEAL
);
9627 for(Unit::AuraList::const_iterator i
= RejorRegr
.begin(); i
!= RejorRegr
.end(); ++i
)
9628 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_DRUID
&&
9629 (*i
)->GetCasterGUID() == GetGUID())
9633 DoneTotalMod
*= (stepPercent
* ownHotCount
+ 100.0f
) / 100.0f
;
9636 case 7871: // Glyph of Lesser Healing Wave
9638 if (pVictim
->GetAura(SPELL_AURA_DUMMY
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000040000000000), 0, GetGUID()))
9639 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9647 // Nourish 20% of heal increase if target is affected by Druids HOTs
9648 if (spellProto
->SpellFamilyName
== SPELLFAMILY_DRUID
&& (spellProto
->SpellFamilyFlags
& UI64LIT(0x0200000000000000)))
9650 int ownHotCount
= 0; // counted HoT types amount, not stacks
9651 Unit::AuraList
const& RejorRegr
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_HEAL
);
9652 for(Unit::AuraList::const_iterator i
= RejorRegr
.begin(); i
!= RejorRegr
.end(); ++i
)
9653 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_DRUID
&&
9654 (*i
)->GetCasterGUID() == GetGUID())
9659 DoneTotalMod
*= 1.2f
; // base bonus at HoTs
9661 if (Aura
* glyph
= GetAura(62971, EFFECT_INDEX_0
))// Glyph of Nourish
9662 DoneTotalMod
*= (glyph
->GetModifier()->m_amount
* ownHotCount
+ 100.0f
) / 100.0f
;
9666 // Done fixed damage bonus auras
9667 int32 DoneAdvertisedBenefit
= SpellBaseHealingBonusDone(GetSpellSchoolMask(spellProto
));
9669 if (DoneAdvertisedBenefit
)
9671 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9673 // Spellmod SpellDamage
9674 float SpellModSpellDamage
= 100.0f
;
9675 if(Player
* modOwner
= GetSpellModOwner())
9676 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_SPELL_BONUS_DAMAGE
, SpellModSpellDamage
);
9677 SpellModSpellDamage
/= 100.0f
;
9679 // Distribute Damage over multiple effects, reduce by AoE
9682 // Not apply this to creature casted spells
9683 if (GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
9685 // Check for table values
9686 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9688 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
9690 if (bonus
->ap_bonus
)
9691 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
));
9693 // Default calculation
9695 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
) * 1.88f
;
9697 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* LvlPenalty
* SpellModSpellDamage
);
9700 // use float as more appropriate for negative values and percent applying
9701 float heal
= (healamount
+ DoneTotal
* int32(stack
))*DoneTotalMod
;
9702 // apply spellmod to Done amount
9703 if(Player
* modOwner
= GetSpellModOwner())
9704 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
9706 return heal
< 0 ? 0 : uint32(heal
);
9710 * Calculates target part of healing spell bonuses,
9711 * will be called on each tick for periodic damage over time auras
9713 uint32
Unit::SpellHealingBonusTaken(Unit
*pCaster
, SpellEntry
const *spellProto
, int32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9715 float TakenTotalMod
= 1.0f
;
9717 // Healing taken percent
9718 float minval
= float(GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
));
9720 TakenTotalMod
*= (100.0f
+ minval
) / 100.0f
;
9722 float maxval
= float(GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
));
9724 TakenTotalMod
*= (100.0f
+ maxval
) / 100.0f
;
9726 // No heal amount for this class spells
9727 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9729 healamount
= int32(healamount
* TakenTotalMod
);
9730 return healamount
< 0 ? 0 : healamount
;
9734 // Done total percent damage auras
9735 int32 TakenTotal
= 0;
9737 // Taken fixed damage bonus auras
9738 int32 TakenAdvertisedBenefit
= SpellBaseHealingBonusTaken(GetSpellSchoolMask(spellProto
));
9740 if (TakenAdvertisedBenefit
)
9742 float LvlPenalty
= pCaster
->CalculateLevelPenalty(spellProto
);
9744 // Distribute Damage over multiple effects, reduce by AoE
9747 // Not apply this to creature casted spells
9748 if (GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
9750 // Check for table values
9751 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9752 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
9753 // Default calculation
9755 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
) * 1.88f
;
9757 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
* LvlPenalty
);
9760 AuraList
const& mHealingGet
= GetAurasByType(SPELL_AURA_MOD_HEALING_RECEIVED
);
9761 for(AuraList::const_iterator i
= mHealingGet
.begin(); i
!= mHealingGet
.end(); ++i
)
9762 if ((*i
)->isAffectedOnSpell(spellProto
))
9763 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9765 // use float as more appropriate for negative values and percent applying
9766 float heal
= (healamount
+ TakenTotal
* int32(stack
)) * TakenTotalMod
;
9768 return heal
< 0 ? 0 : uint32(heal
);
9771 int32
Unit::SpellBaseHealingBonusDone(SpellSchoolMask schoolMask
)
9773 int32 AdvertisedBenefit
= 0;
9775 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
9776 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
9777 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9778 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9780 // Healing bonus of spirit, intellect and strength
9781 if (GetTypeId() == TYPEID_PLAYER
)
9784 AdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9786 // Healing bonus from stats
9787 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
9788 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
9790 // stat used dependent from misc value (stat index)
9791 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
9792 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9795 // ... and attack power
9796 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
9797 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
9798 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9799 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9801 return AdvertisedBenefit
;
9804 int32
Unit::SpellBaseHealingBonusTaken(SpellSchoolMask schoolMask
)
9806 int32 AdvertisedBenefit
= 0;
9807 AuraList
const& mDamageTaken
= GetAurasByType(SPELL_AURA_MOD_HEALING
);
9808 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9809 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9810 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9812 return AdvertisedBenefit
;
9815 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
)
9817 //If m_immuneToSchool type contain this school type, IMMUNE damage.
9818 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9819 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9820 if (itr
->type
& shoolMask
)
9823 //If m_immuneToDamage type contain magic, IMMUNE damage.
9824 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
9825 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
9826 if (itr
->type
& shoolMask
)
9832 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
)
9837 //TODO add spellEffect immunity checks!, player with flag in bg is imune to imunity buffs from other friendly players!
9838 //SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_EFFECT];
9840 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
9841 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
9842 if (itr
->type
== spellInfo
->Dispel
)
9845 if (!(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
) && // unaffected by school immunity
9846 !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)) // can remove immune (by dispell or immune it)
9848 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9849 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9850 if (!(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
9851 (itr
->type
& GetSpellSchoolMask(spellInfo
)))
9855 if(uint32 mechanic
= spellInfo
->Mechanic
)
9857 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9858 for(SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9859 if (itr
->type
== mechanic
)
9862 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9863 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9864 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9871 bool Unit::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, SpellEffectIndex index
) const
9873 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
9874 uint32 effect
= spellInfo
->Effect
[index
];
9875 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
9876 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
9877 if (itr
->type
== effect
)
9880 if(uint32 mechanic
= spellInfo
->EffectMechanic
[index
])
9882 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9883 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9884 if (itr
->type
== mechanic
)
9887 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9888 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9889 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9893 if(uint32 aura
= spellInfo
->EffectApplyAuraName
[index
])
9895 SpellImmuneList
const& list
= m_spellImmune
[IMMUNITY_STATE
];
9896 for(SpellImmuneList::const_iterator itr
= list
.begin(); itr
!= list
.end(); ++itr
)
9897 if (itr
->type
== aura
)
9900 // Check for immune to application of harmful magical effects
9901 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL
);
9902 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9903 if (spellInfo
->Dispel
== DISPEL_MAGIC
&& // Magic debuff
9904 ((*iter
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellInfo
)) && // Check school
9905 !IsPositiveEffect(spellInfo
->Id
, index
)) // Harmful
9912 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
9917 uint32 family
= spellInfo
->SpellFamilyName
;
9918 uint64 flags
= spellInfo
->SpellFamilyFlags
;
9920 if ((family
== 5 && flags
== 256) || //Searing Pain
9921 (family
== 6 && flags
== 8192) || //Mind Blast
9922 (family
== 11 && flags
== 1048576)) //Earth Shock
9929 * Calculates caster part of melee damage bonuses,
9930 * also includes different bonuses dependent from target auras
9932 uint32
Unit::MeleeDamageBonusDone(Unit
*pVictim
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
9940 // differentiate for weapon damage based spells
9941 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
9942 Item
* pWeapon
= GetTypeId() == TYPEID_PLAYER
? ((Player
*)this)->GetWeaponForAttack(attType
,true,false) : NULL
;
9943 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9944 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
9945 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
9947 // Shred also have bonus as MECHANIC_BLEED damages
9948 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
9949 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
9952 // FLAT damage bonus auras
9953 // =======================
9957 // ..done flat, already included in wepon damage based spells
9958 if (!isWeaponDamageBasedSpell
)
9960 AuraList
const& mModDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9961 for(AuraList::const_iterator i
= mModDamageDone
.begin(); i
!= mModDamageDone
.end(); ++i
)
9963 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9964 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9965 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9966 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
9968 DoneFlat
+= (*i
)->GetModifier()->m_amount
;
9972 // Pets just add their bonus damage to their melee damage
9973 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9974 DoneFlat
+= ((Pet
*)this)->GetBonusDamage();
9977 // ..done flat (by creature type mask)
9978 DoneFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
, creatureTypeMask
);
9980 // ..done flat (base at attack power for marked target and base at attack power for creature type)
9981 if (attType
== RANGED_ATTACK
)
9983 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
9984 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9988 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
9989 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9992 // PERCENT damage auras
9993 // ====================
9994 float DonePercent
= 1.0f
;
9996 // ..done pct, already included in weapon damage based spells
9997 if(!isWeaponDamageBasedSpell
)
9999 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
10000 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
10002 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
10003 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
10004 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
10005 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
10007 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
10011 if (attType
== OFF_ATTACK
)
10012 DonePercent
*= GetModifierValue(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_PCT
); // no school check required
10015 // ..done pct (by creature type mask)
10016 DonePercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
, creatureTypeMask
);
10018 // special dummys/class sripts and other effects
10019 // =============================================
10020 Unit
*owner
= GetOwner();
10024 // ..done (class scripts)
10027 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
10028 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
10030 if (!(*i
)->isAffectedOnSpell(spellProto
))
10033 switch((*i
)->GetModifier()->m_miscvalue
)
10036 // Merciless Combat
10039 // Merciless Combat
10040 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
10042 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
10043 DonePercent
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
10045 else // Tundra Stalker
10047 // Frost Fever (target debuff)
10048 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
10049 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10054 case 7293: // Rage of Rivendare
10056 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
10057 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10060 // Marked for Death
10067 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
10068 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10075 // .. done (class scripts)
10076 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
10077 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
10079 switch((*i
)->GetMiscValue())
10084 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
10086 Aura
* eff0
= GetAura((*i
)->GetId(), EFFECT_INDEX_0
);
10087 if (!eff0
|| (*i
)->GetEffIndex() != EFFECT_INDEX_1
)
10089 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
10093 // effect 0 have expected value but in negative state
10094 DonePercent
*= (-eff0
->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
10101 if (spellProto
&& spellProto
->SpellFamilyName
== SPELLFAMILY_DEATHKNIGHT
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000400000000))
10104 bool found
= false;
10105 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
10106 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
10108 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
10117 // search for Glacier Rot dummy aura
10118 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
10119 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
10121 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
10123 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
10131 // final calculation
10132 // =================
10134 float DoneTotal
= 0.0f
;
10136 // scaling of non weapon based spells
10137 if (!isWeaponDamageBasedSpell
)
10139 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
10141 // Distribute Damage over multiple effects, reduce by AoE
10142 float coeff
= 0.0f
;
10144 // Not apply this to creature casted spells
10145 if (GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
10147 // Check for table values
10148 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
10150 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
10152 if (bonus
->ap_bonus
)
10153 DoneTotal
+= bonus
->ap_bonus
* (GetTotalAttackPowerValue(BASE_ATTACK
) + APbonus
);
10155 // Default calculation
10157 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
);
10159 DoneTotal
+= DoneFlat
* coeff
* LvlPenalty
;
10161 // weapon damage based spells
10162 else if( APbonus
|| DoneFlat
)
10164 bool normalized
= spellProto
? IsSpellHaveEffect(spellProto
, SPELL_EFFECT_NORMALIZED_WEAPON_DMG
) : false;
10165 DoneTotal
+= int32(APbonus
/ 14.0f
* GetAPMultiplier(attType
,normalized
));
10167 // for weapon damage based spells we still have to apply damage done percent mods
10168 // (that are already included into pdamage) to not-yet included DoneFlat
10169 // e.g. from doneVersusCreature, apBonusVs...
10174 case BASE_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_MAINHAND
; break;
10175 case OFF_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_OFFHAND
; break;
10176 case RANGED_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_RANGED
; break;
10179 DoneTotal
+= DoneFlat
;
10181 DoneTotal
*= GetModifierValue(unitMod
, TOTAL_PCT
);
10184 float tmpDamage
= float(int32(pdamage
) + DoneTotal
* int32(stack
)) * DonePercent
;
10186 // apply spellmod to Done damage
10189 if(Player
* modOwner
= GetSpellModOwner())
10190 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
10193 // bonus result can be negative
10194 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
10198 * Calculates target part of melee damage bonuses,
10199 * will be called on each tick for periodic damage over time auras
10201 uint32
Unit::MeleeDamageBonusTaken(Unit
*pCaster
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
10209 // differentiate for weapon damage based spells
10210 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
10211 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
10212 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
10214 // Shred also have bonus as MECHANIC_BLEED damages
10215 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
10216 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
10219 // FLAT damage bonus auras
10220 // =======================
10221 int32 TakenFlat
= 0;
10223 // ..taken flat (base at attack power for marked target and base at attack power for creature type)
10224 if (attType
== RANGED_ATTACK
)
10225 TakenFlat
+= GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
10227 TakenFlat
+= GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
10229 // ..taken flat (by school mask)
10230 TakenFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_TAKEN
, schoolMask
);
10232 // PERCENT damage auras
10233 // ====================
10234 float TakenPercent
= 1.0f
;
10236 // ..taken pct (by school mask)
10237 TakenPercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
, schoolMask
);
10239 // ..taken pct (by mechanic mask)
10240 TakenPercent
*= GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,mechanicMask
);
10242 // ..taken pct (melee/ranged)
10243 if(attType
== RANGED_ATTACK
)
10244 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
10246 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
10248 // ..taken pct (aoe avoidance)
10249 if(spellProto
&& IsAreaOfEffectSpell(spellProto
))
10250 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
10253 // special dummys/class scripts and other effects
10254 // =============================================
10256 // .. taken (dummy auras)
10257 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
10258 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
10260 switch((*i
)->GetSpellProto()->SpellIconID
)
10264 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
10266 if(GetTypeId() != TYPEID_PLAYER
)
10269 float mod
= ((Player
*)this)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
10270 if (mod
< float((*i
)->GetModifier()->m_amount
))
10271 mod
= float((*i
)->GetModifier()->m_amount
);
10273 TakenPercent
*= (mod
+ 100.0f
) / 100.0f
;
10279 // final calculation
10280 // =================
10282 // scaling of non weapon based spells
10283 if (!isWeaponDamageBasedSpell
)
10288 float LvlPenalty
= pCaster
->CalculateLevelPenalty(spellProto
);
10290 // Distribute Damage over multiple effects, reduce by AoE
10293 // Not apply this to creature casted spells
10294 if (pCaster
->GetTypeId()==TYPEID_UNIT
&& !((Creature
*)pCaster
)->isPet())
10296 // Check for table values
10297 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
10298 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
10299 // Default calculation
10300 else if (TakenFlat
)
10301 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
);
10303 TakenFlat
*= coeff
* LvlPenalty
;
10307 float tmpDamage
= float(int32(pdamage
) + TakenFlat
* int32(stack
)) * TakenPercent
;
10309 // bonus result can be negative
10310 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
10313 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
10317 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
10319 next
= itr
; ++next
;
10320 if(itr
->type
== type
)
10322 m_spellImmune
[op
].erase(itr
);
10323 next
= m_spellImmune
[op
].begin();
10326 SpellImmune Immune
;
10327 Immune
.spellId
= spellId
;
10328 Immune
.type
= type
;
10329 m_spellImmune
[op
].push_back(Immune
);
10333 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
10335 if(itr
->spellId
== spellId
)
10337 m_spellImmune
[op
].erase(itr
);
10345 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
10347 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
10349 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
10350 RemoveAurasWithDispelType(type
);
10353 float Unit::GetWeaponProcChance() const
10355 // normalized proc chance for weapon attack speed
10356 // (odd formula...)
10357 if (isAttackReady(BASE_ATTACK
))
10358 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
10359 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
10360 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
10365 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
10367 // proc per minute chance calculation
10370 return WeaponSpeed
* PPM
/ 600.0f
; // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
10373 void Unit::Mount(uint32 mount
, uint32 spellId
)
10378 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
10380 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
10382 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
10384 if (GetTypeId() == TYPEID_PLAYER
)
10386 // Called by Taxi system / GM command
10388 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10389 // Called by mount aura
10390 else if (SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellId
))
10392 // Flying case (Unsummon any pet)
10393 if (IsSpellHaveAura(spellInfo
, SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED
))
10394 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10395 // Normal case (Unsummon only permanent pet)
10396 else if (Pet
* pet
= GetPet())
10398 if (pet
->IsPermanentPetFor((Player
*)this) && !((Player
*)this)->InArena())
10399 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10401 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,true);
10407 void Unit::Unmount()
10412 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
10414 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
10415 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
10417 // only resummon old pet if the player is already added to a map
10418 // this prevents adding a pet to a not created map which would otherwise cause a crash
10419 // (it could probably happen when logging in after a previous crash)
10420 if(GetTypeId() == TYPEID_PLAYER
)
10422 if(Pet
* pet
= GetPet())
10423 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,false);
10425 ((Player
*)this)->ResummonPetTemporaryUnSummonedIfAny();
10429 void Unit::SetInCombatWith(Unit
* enemy
)
10431 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
10432 if (eOwner
->IsPvP())
10434 SetInCombatState(true,enemy
);
10439 if (eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
10441 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
10442 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
10444 SetInCombatState(true,enemy
);
10449 SetInCombatState(false,enemy
);
10452 void Unit::SetInCombatState(bool PvP
, Unit
* enemy
)
10454 // only alive units can be in combat
10459 m_CombatTimer
= 5000;
10461 bool creatureNotInCombat
= GetTypeId()==TYPEID_UNIT
&& !HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10463 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10465 if (isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10466 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10468 if (creatureNotInCombat
)
10470 // should probably be removed for the attacked (+ it's party/group) only, not global
10471 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10473 if (((Creature
*)this)->AI())
10474 ((Creature
*)this)->AI()->EnterCombat(enemy
);
10478 void Unit::ClearInCombat()
10481 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10483 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10484 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10486 // Player's state will be cleared in Player::UpdateContestedPvP
10487 if (GetTypeId() != TYPEID_PLAYER
)
10489 Creature
* creature
= (Creature
*)this;
10490 if (creature
->GetCreatureInfo() && creature
->GetCreatureInfo()->unit_flags
& UNIT_FLAG_OOC_NOT_ATTACKABLE
)
10491 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10493 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
10496 ((Player
*)this)->UpdatePotionCooldown();
10499 bool Unit::isTargetableForAttack(bool inverseAlive
/*=false*/) const
10501 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
10504 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
10507 // to be removed if unit by any reason enter combat
10508 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
))
10511 // inversealive is needed for some spells which need to be casted at dead targets (aoe)
10512 if (isAlive() == inverseAlive
)
10515 return IsInWorld() && !hasUnitState(UNIT_STAT_DIED
) && !isInFlight();
10518 int32
Unit::ModifyHealth(int32 dVal
)
10525 int32 curHealth
= (int32
)GetHealth();
10527 int32 val
= dVal
+ curHealth
;
10534 int32 maxHealth
= (int32
)GetMaxHealth();
10536 if(val
< maxHealth
)
10539 gain
= val
- curHealth
;
10541 else if(curHealth
!= maxHealth
)
10543 SetHealth(maxHealth
);
10544 gain
= maxHealth
- curHealth
;
10550 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
10557 int32 curPower
= (int32
)GetPower(power
);
10559 int32 val
= dVal
+ curPower
;
10566 int32 maxPower
= (int32
)GetMaxPower(power
);
10570 SetPower(power
,val
);
10571 gain
= val
- curPower
;
10573 else if(curPower
!= maxPower
)
10575 SetPower(power
,maxPower
);
10576 gain
= maxPower
- curPower
;
10582 bool Unit::isVisibleForOrDetect(Unit
const* u
, WorldObject
const* viewPoint
, bool detect
, bool inVisibleList
, bool is3dDistance
) const
10584 if(!u
|| !IsInMap(u
))
10587 // Always can see self
10591 // player visible for other player if not logout and at same transport
10592 // including case when player is out of world
10593 bool at_same_transport
=
10594 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
10595 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
10596 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
10597 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
10600 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
10603 // forbidden to seen (at GM respawn command)
10604 if(m_Visibility
==VISIBILITY_RESPAWN
)
10607 Map
& _map
= *u
->GetMap();
10608 // Grid dead/alive checks
10609 if (u
->GetTypeId()==TYPEID_PLAYER
)
10611 // non visible at grid for any stealth state
10612 if(!IsVisibleInGridForPlayer((Player
*)u
))
10615 // if player is dead then he can't detect anyone in any cases
10621 // all dead creatures/players not visible for any creatures
10622 if(!u
->isAlive() || !isAlive())
10626 // always seen by far sight caster
10627 if (u
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)u
)->GetFarSight()==GetGUID())
10630 // different visible distance checks
10631 if (u
->isInFlight()) // what see player in flight
10633 // use object grey distance for all (only see objects any way)
10634 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10637 else if(!isAlive()) // distance for show body
10639 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10642 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
10644 if(u
->GetTypeId()==TYPEID_PLAYER
)
10646 // Players far than max visible distance for player or not in our map are not visible too
10647 if (!at_same_transport
&& !IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10652 // Units far than max visible distance for creature or not in our map are not visible too
10653 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10657 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
10659 // Pet/charmed far than max visible distance for player or not in our map are not visible too
10660 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10663 else // distance for show creature
10665 // Units far than max visible distance for creature or not in our map are not visible too
10666 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10670 // always seen by owner
10671 if (GetCharmerOrOwnerGUID()==u
->GetGUID())
10674 // isInvisibleForAlive() those units can only be seen by dead or if other
10675 // unit is also invisible for alive.. if an isinvisibleforalive unit dies we
10676 // should be able to see it too
10677 if (u
->isAlive() && isAlive() && isInvisibleForAlive() != u
->isInvisibleForAlive())
10678 if (u
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)u
)->isGameMaster())
10681 // Visible units, always are visible for all units, except for units under invisibility and phases
10682 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0 && InSamePhase(u
))
10685 // GMs see any players, not higher GMs and all units in any phase
10686 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
10688 if(GetTypeId() == TYPEID_PLAYER
)
10689 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
10694 // non faction visibility non-breakable for non-GMs
10695 if (m_Visibility
== VISIBILITY_OFF
)
10698 // phased visibility (both must phased in same way)
10699 if(!InSamePhase(u
))
10702 // raw invisibility
10703 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
10705 // detectable invisibility case
10707 // Invisible units, always are visible for units under same invisibility type
10708 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
10709 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
10710 u
->canDetectInvisibilityOf(this) ||
10711 // Units that can detect invisibility always are visible for units that can be detected
10712 canDetectInvisibilityOf(u
) ))
10717 // special cases for always overwrite invisibility/stealth
10718 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
10720 // non-hostile case
10721 if (!u
->IsHostileTo(this))
10723 // 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)
10724 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
10726 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
10729 // else apply same rules as for hostile case (detecting check for stealth)
10735 // Hunter mark functionality
10736 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
10737 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
10738 if((*iter
)->GetCasterGUID()==u
->GetGUID())
10741 // else apply detecting check for stealth
10744 // none other cases for detect invisibility, so invisible
10748 // else apply stealth detecting check
10751 // unit got in stealth in this moment and must ignore old detected state
10752 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
10755 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
10756 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
10759 // NOW ONLY STEALTH CASE
10761 //if in non-detect mode then invisible for unit
10762 //mobs always detect players (detect == true)... return 'false' for those mobs which have (detect == false)
10763 //players detect players only in Player::HandleStealthedUnitsDetection()
10765 return (u
->GetTypeId() == TYPEID_PLAYER
) ? ((Player
*)u
)->HaveAtClient(this) : false;
10769 // If is attacked then stealth is lost, some creature can use stealth too
10770 if( !getAttackers().empty() )
10773 // If there is collision rogue is seen regardless of level difference
10774 if (IsWithinDist(u
,0.24f
))
10777 //If a mob or player is stunned he will not be able to detect stealth
10778 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
10782 float visibleDistance
= (u
->GetTypeId() == TYPEID_PLAYER
) ? MAX_PLAYER_STEALTH_DETECT_RANGE
: ((Creature
const*)u
)->GetAttackDistance(this);
10784 //Always invisible from back (when stealth detection is on), also filter max distance cases
10785 bool isInFront
= viewPoint
->isInFrontInMap(this, visibleDistance
);
10789 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
10790 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
10792 //Calculation if target is in front
10794 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
10795 visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
10797 //Visible distance is modified by
10798 //-Level Diff (every level diff = 1.0f in visible distance)
10799 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
10801 //This allows to check talent tree and will add addition stealth dependent on used points)
10802 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
10806 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
10807 //based on wowwiki every 5 mod we have 1 more level diff in calculation
10808 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_DETECT
)) - stealthMod
)/5.0f
;
10809 visibleDistance
= visibleDistance
> MAX_PLAYER_STEALTH_DETECT_RANGE
? MAX_PLAYER_STEALTH_DETECT_RANGE
: visibleDistance
;
10811 // recheck new distance
10812 if(visibleDistance
<= 0 || !IsWithinDist(viewPoint
,visibleDistance
))
10816 // Now check is target visible with LoS
10818 viewPoint
->GetPosition(ox
,oy
,oz
);
10819 return IsWithinLOS(ox
,oy
,oz
);
10822 void Unit::SetVisibility(UnitVisibility x
)
10830 if(GetTypeId()==TYPEID_PLAYER
)
10831 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10833 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10837 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
10839 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
10841 for(uint32 i
= 0; i
< 10; ++i
)
10843 if(((1 << i
) & mask
)==0)
10846 // find invisibility level
10847 int32 invLevel
= 0;
10848 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
10849 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
10850 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
10851 invLevel
= (*itr
)->GetModifier()->m_amount
;
10853 // find invisibility detect level
10854 int32 detectLevel
= 0;
10855 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
10856 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
10857 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
10858 detectLevel
= (*itr
)->GetModifier()->m_amount
;
10860 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
10862 detectLevel
= ((Player
*)this)->GetDrunkValue();
10865 if(invLevel
<= detectLevel
)
10873 struct UpdateWalkModeHelper
10875 explicit UpdateWalkModeHelper(Unit
* _source
) : source(_source
) {}
10876 void operator()(Unit
* unit
) const { unit
->UpdateWalkMode(source
, true); }
10880 void Unit::UpdateWalkMode(Unit
* source
, bool self
)
10882 if (GetTypeId() == TYPEID_PLAYER
)
10883 ((Player
*)this)->CallForAllControlledUnits(UpdateWalkModeHelper(source
), false, true, true, true);
10886 bool on
= source
->GetTypeId() == TYPEID_PLAYER
10887 ? ((Player
*)source
)->HasMovementFlag(MOVEFLAG_WALK_MODE
)
10888 : ((Creature
*)source
)->HasSplineFlag(SPLINEFLAG_WALKMODE
);
10892 if (((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10893 ((Creature
*)this)->AddSplineFlag(SPLINEFLAG_WALKMODE
);
10897 if (((Creature
*)this)->isPet())
10898 ((Creature
*)this)->RemoveSplineFlag(SPLINEFLAG_WALKMODE
);
10902 CallForAllControlledUnits(UpdateWalkModeHelper(source
), false, true, true);
10905 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
, float ratio
)
10907 // not in combat pet have same speed as owner
10913 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10915 if(Unit
* owner
= GetOwner())
10917 SetSpeedRate(mtype
, owner
->GetSpeedRate(mtype
), forced
);
10924 int32 main_speed_mod
= 0;
10925 float stack_bonus
= 1.0f
;
10926 float non_stack_bonus
= 1.0f
;
10934 if (IsMounted()) // Use on mount auras
10936 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
10937 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
10938 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
10942 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
10943 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
10944 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
10948 case MOVE_RUN_BACK
:
10952 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
10955 case MOVE_SWIM_BACK
:
10959 if (IsMounted()) // Use on mount auras
10961 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED
);
10962 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED_STACKING
);
10963 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED_NOT_STACKING
))/100.0f
;
10965 else // Use not mount (shapeshift for example) auras (should stack)
10967 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED
);
10968 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_STACKING
);
10969 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACKING
))/100.0f
;
10973 case MOVE_FLIGHT_BACK
:
10976 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
10980 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
10981 // now we ready for speed calculation
10982 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
10990 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
10991 // TODO: possible affect only on MOVE_RUN
10992 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
10994 // Use speed from aura
10995 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
10996 if (speed
> max_speed
)
11005 // for creature case, we check explicit if mob searched for assistance
11006 if (GetTypeId() == TYPEID_UNIT
)
11008 if (((Creature
*)this)->HasSearchedAssistance())
11009 speed
*= 0.66f
; // best guessed value, so this will be 33% reduction. Based off initial speed, mob can then "run", "walk fast" or "walk".
11012 // Apply strongest slow aura mod to speed
11013 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
11016 speed
*=(100.0f
+ slow
)/100.0f
;
11017 float min_speed
= (float)GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MINIMUM_SPEED
) / 100.0f
;
11018 if (speed
< min_speed
)
11021 SetSpeedRate(mtype
, speed
* ratio
, forced
);
11024 float Unit::GetSpeed( UnitMoveType mtype
) const
11026 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
11029 struct SetSpeedRateHelper
11031 explicit SetSpeedRateHelper(UnitMoveType _mtype
, bool _forced
) : mtype(_mtype
), forced(_forced
) {}
11032 void operator()(Unit
* unit
) const { unit
->UpdateSpeed(mtype
,forced
); }
11033 UnitMoveType mtype
;
11037 void Unit::SetSpeedRate(UnitMoveType mtype
, float rate
, bool forced
)
11042 // Update speed only on change
11043 if (m_speed_rate
[mtype
] == rate
)
11046 m_speed_rate
[mtype
] = rate
;
11048 propagateSpeedChange();
11056 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11059 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11061 case MOVE_RUN_BACK
:
11062 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11065 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11067 case MOVE_SWIM_BACK
:
11068 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11070 case MOVE_TURN_RATE
:
11071 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+2+4+4+4+4+4+4+4);
11074 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11076 case MOVE_FLIGHT_BACK
:
11077 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11079 case MOVE_PITCH_RATE
:
11080 data
.Initialize(MSG_MOVE_SET_PITCH_RATE
, 8+4+2+4+4+4+4+4+4+4);
11083 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
11087 data
<< GetPackGUID();
11088 data
<< uint32(0); // movement flags
11089 data
<< uint16(0); // unk flags
11090 data
<< uint32(getMSTime());
11091 data
<< float(GetPositionX());
11092 data
<< float(GetPositionY());
11093 data
<< float(GetPositionZ());
11094 data
<< float(GetOrientation());
11095 data
<< uint32(0); // fall time
11096 data
<< float(GetSpeed(mtype
));
11097 SendMessageToSet( &data
, true );
11101 if(GetTypeId() == TYPEID_PLAYER
)
11103 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
11104 // and do it only for real sent packets and use run for run/mounted as client expected
11105 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
11111 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
11114 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
11116 case MOVE_RUN_BACK
:
11117 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
11120 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
11122 case MOVE_SWIM_BACK
:
11123 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
11125 case MOVE_TURN_RATE
:
11126 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
11129 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
11131 case MOVE_FLIGHT_BACK
:
11132 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
11134 case MOVE_PITCH_RATE
:
11135 data
.Initialize(SMSG_FORCE_PITCH_RATE_CHANGE
, 16);
11138 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
11141 data
<< GetPackGUID();
11142 data
<< (uint32
)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
11143 if (mtype
== MOVE_RUN
)
11144 data
<< uint8(0); // new 2.1.0
11145 data
<< float(GetSpeed(mtype
));
11146 SendMessageToSet( &data
, true );
11149 if (GetTypeId() == TYPEID_PLAYER
) // need include minpet
11150 ((Player
*)this)->CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true,true);
11152 CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true);
11155 void Unit::SetHover(bool on
)
11158 CastSpell(this, 11010, true);
11160 RemoveAurasDueToSpell(11010);
11163 void Unit::setDeathState(DeathState s
)
11165 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
11168 DeleteThreatList();
11169 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
11171 if(IsNonMeleeSpellCasted(false))
11172 InterruptNonMeleeSpells(false);
11175 if (s
== JUST_DIED
)
11177 RemoveAllAurasOnDeath();
11179 UnsummonAllTotems();
11181 // after removing a Fearaura (in RemoveAllAurasOnDeath)
11182 // Unit::SetFeared is called and makes that creatures attack player again
11185 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
11186 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
11187 // remove aurastates allowing special moves
11188 ClearAllReactives();
11189 ClearDiminishings();
11191 else if(s
== JUST_ALIVED
)
11193 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
11196 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
11198 //_ApplyAllAuraMods();
11203 /*########################################
11205 ######## AGGRO SYSTEM ########
11207 ########################################*/
11208 bool Unit::CanHaveThreatList() const
11210 // only creatures can have threat list
11211 if( GetTypeId() != TYPEID_UNIT
)
11214 // only alive units can have threat list
11218 // totems can not have threat list
11219 if( ((Creature
*)this)->isTotem() )
11222 // vehicles can not have threat list
11223 if( ((Creature
*)this)->isVehicle() )
11226 // pets can not have a threat list, unless they are controlled by a creature
11227 if( ((Creature
*)this)->isPet() && IS_PLAYER_GUID(((Pet
*)this)->GetOwnerGUID()) )
11233 //======================================================================
11235 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
11237 if (!HasAuraType(SPELL_AURA_MOD_THREAT
))
11240 if (schoolMask
== SPELL_SCHOOL_MASK_NONE
)
11243 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
11245 return threat
* m_threatModifier
[school
];
11248 //======================================================================
11250 void Unit::AddThreat(Unit
* pVictim
, float threat
/*= 0.0f*/, bool crit
/*= false*/, SpellSchoolMask schoolMask
/*= SPELL_SCHOOL_MASK_NONE*/, SpellEntry
const *threatSpell
/*= NULL*/)
11252 // Only mobs can manage threat lists
11253 if(CanHaveThreatList())
11254 m_ThreatManager
.addThreat(pVictim
, threat
, crit
, schoolMask
, threatSpell
);
11257 //======================================================================
11259 void Unit::DeleteThreatList()
11261 if(CanHaveThreatList() && !m_ThreatManager
.isThreatListEmpty())
11263 m_ThreatManager
.clearReferences();
11266 //======================================================================
11268 void Unit::TauntApply(Unit
* taunter
)
11270 ASSERT(GetTypeId()== TYPEID_UNIT
);
11272 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
11275 if(!CanHaveThreatList())
11278 Unit
*target
= getVictim();
11279 if(target
&& target
== taunter
)
11282 SetInFront(taunter
);
11283 if (((Creature
*)this)->AI())
11284 ((Creature
*)this)->AI()->AttackStart(taunter
);
11286 m_ThreatManager
.tauntApply(taunter
);
11289 //======================================================================
11291 void Unit::TauntFadeOut(Unit
*taunter
)
11293 ASSERT(GetTypeId()== TYPEID_UNIT
);
11295 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
11298 if(!CanHaveThreatList())
11301 Unit
*target
= getVictim();
11302 if(!target
|| target
!= taunter
)
11305 if(m_ThreatManager
.isThreatListEmpty())
11307 if(((Creature
*)this)->AI())
11308 ((Creature
*)this)->AI()->EnterEvadeMode();
11312 m_ThreatManager
.tauntFadeOut(taunter
);
11313 target
= m_ThreatManager
.getHostileTarget();
11315 if (target
&& target
!= taunter
)
11317 SetInFront(target
);
11318 if (((Creature
*)this)->AI())
11319 ((Creature
*)this)->AI()->AttackStart(target
);
11323 //======================================================================
11325 bool Unit::SelectHostileTarget()
11327 //function provides main threat functionality
11328 //next-victim-selection algorithm and evade mode are called
11329 //threat list sorting etc.
11331 ASSERT(GetTypeId()== TYPEID_UNIT
);
11333 if (!this->isAlive())
11335 //This function only useful once AI has been initialized
11336 if (!((Creature
*)this)->AI())
11339 Unit
* target
= NULL
;
11341 // First checking if we have some taunt on us
11342 const AuraList
& tauntAuras
= GetAurasByType(SPELL_AURA_MOD_TAUNT
);
11343 if ( !tauntAuras
.empty() )
11347 // The last taunt aura caster is alive an we are happy to attack him
11348 if ( (caster
= tauntAuras
.back()->GetCaster()) && caster
->isAlive() )
11350 else if (tauntAuras
.size() > 1)
11352 // We do not have last taunt aura caster but we have more taunt auras,
11353 // so find first available target
11355 // Auras are pushed_back, last caster will be on the end
11356 AuraList::const_iterator aura
= --tauntAuras
.end();
11360 if ( (caster
= (*aura
)->GetCaster()) &&
11361 caster
->IsInMap(this) && caster
->isTargetableForAttack() && caster
->isInAccessablePlaceFor((Creature
*)this) )
11366 }while (aura
!= tauntAuras
.begin());
11370 if ( !target
&& !m_ThreatManager
.isThreatListEmpty() )
11371 // No taunt aura or taunt aura caster is dead standart target selection
11372 target
= m_ThreatManager
.getHostileTarget();
11376 if (!hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_DIED
))
11378 SetInFront(target
);
11379 ((Creature
*)this)->AI()->AttackStart(target
);
11384 // no target but something prevent go to evade mode
11385 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
11388 // last case when creature don't must go to evade mode:
11389 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
11390 // for example at owner command to pet attack some far away creature
11391 // Note: creature not have targeted movement generator but have attacker in this case
11392 if (GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE
)
11394 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
11396 if ((*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this))
11401 // enter in evade mode in other case
11402 ((Creature
*)this)->AI()->EnterEvadeMode();
11407 //======================================================================
11408 //======================================================================
11409 //======================================================================
11411 int32
Unit::CalculateSpellDamage(Unit
const* target
, SpellEntry
const* spellProto
, SpellEffectIndex effect_index
, int32
const* effBasePoints
)
11413 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
11415 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
11417 int32 level
= int32(getLevel());
11418 if (level
> (int32
)spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
11419 level
= (int32
)spellProto
->maxLevel
;
11420 else if (level
< (int32
)spellProto
->baseLevel
)
11421 level
= (int32
)spellProto
->baseLevel
;
11422 level
-= (int32
)spellProto
->spellLevel
;
11424 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
11425 int32 basePoints
= effBasePoints
? *effBasePoints
- 1 : spellProto
->EffectBasePoints
[effect_index
];
11426 basePoints
+= int32(level
* basePointsPerLevel
);
11427 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
]);
11428 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
11430 switch(randomPoints
)
11432 case 0: // not used
11433 case 1: basePoints
+= 1; break; // range 1..1
11435 // range can have positive (1..rand) and negative (rand..1) values, so order its for irand
11436 int32 randvalue
= (randomPoints
>= 1)
11437 ? irand(1, randomPoints
)
11438 : irand(randomPoints
, 1);
11440 basePoints
+= randvalue
;
11444 int32 value
= basePoints
;
11447 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
11448 value
+= (int32
)(comboDamage
* comboPoints
);
11450 if(Player
* modOwner
= GetSpellModOwner())
11452 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_ALL_EFFECTS
, value
);
11453 switch(effect_index
)
11456 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT1
, value
);
11459 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT2
, value
);
11462 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT3
, value
);
11467 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
11468 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
11469 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
&&
11470 (spellProto
->Effect
[effect_index
] != SPELL_EFFECT_APPLY_AURA
|| spellProto
->EffectApplyAuraName
[effect_index
] != SPELL_AURA_MOD_DECREASE_SPEED
))
11471 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
11476 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, SpellEffectIndex effect_index
, Unit
const* target
)
11478 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
11480 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
11482 int32 minduration
= GetSpellDuration(spellProto
);
11483 int32 maxduration
= GetSpellMaxDuration(spellProto
);
11487 if( minduration
!= -1 && minduration
!= maxduration
)
11488 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
11490 duration
= minduration
;
11494 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
11495 // Find total mod value (negative bonus)
11496 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
11497 // Modify from SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL aura for negatve effects (stack always ?)
11498 if (!IsPositiveEffect(spellProto
->Id
, effect_index
))
11499 durationMod_always
+=target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
, spellProto
->Dispel
);
11500 // Find max mod (negative bonus)
11501 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
11503 if (!IsPositiveSpell(spellProto
->Id
))
11504 durationMod_always
+= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS
, spellProto
->DmgClass
);
11506 int32 durationMod
= 0;
11507 // Select strongest negative mod
11508 if (durationMod_always
> durationMod_not_stack
)
11509 durationMod
= durationMod_not_stack
;
11511 durationMod
= durationMod_always
;
11513 if (durationMod
!= 0)
11514 duration
= int32(int64(duration
) * (100+durationMod
) /100);
11516 if (duration
< 0) duration
= 0;
11522 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
11524 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11526 if(i
->DRGroup
!= group
)
11530 return DIMINISHING_LEVEL_1
;
11533 return DIMINISHING_LEVEL_1
;
11535 // If last spell was casted more than 15 seconds ago - reset the count.
11536 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
11538 i
->hitCount
= DIMINISHING_LEVEL_1
;
11539 return DIMINISHING_LEVEL_1
;
11541 // or else increase the count.
11544 return DiminishingLevels(i
->hitCount
);
11547 return DIMINISHING_LEVEL_1
;
11550 void Unit::IncrDiminishing(DiminishingGroup group
)
11552 // Checking for existing in the table
11553 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11555 if(i
->DRGroup
!= group
)
11557 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
11561 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
11564 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
, int32 limitduration
)
11566 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
11569 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
11570 if(limitduration
> 0 && duration
> limitduration
)
11572 // test pet/charm masters instead pets/charmeds
11573 Unit
const* targetOwner
= GetCharmerOrOwner();
11574 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
11576 Unit
const* target
= targetOwner
? targetOwner
: this;
11577 Unit
const* source
= casterOwner
? casterOwner
: caster
;
11579 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
11580 duration
= limitduration
;
11585 // Some diminishings applies to mobs too (for example, Stun)
11586 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
11588 DiminishingLevels diminish
= Level
;
11591 case DIMINISHING_LEVEL_1
: break;
11592 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
11593 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
11594 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
11599 duration
= int32(duration
* mod
);
11602 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
11604 // Checking for existing in the table
11605 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11607 if(i
->DRGroup
!= group
)
11615 // Remember time after last aura from group removed
11617 i
->hitTime
= getMSTime();
11623 Unit
* Unit::GetUnit(WorldObject
const& object
, uint64 guid
)
11625 return ObjectAccessor::GetUnit(object
,guid
);
11628 bool Unit::isVisibleForInState( Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const
11630 return isVisibleForOrDetect(u
, viewPoint
, false, inVisibleList
, false);
11633 /// returns true if creature can't be seen by alive units
11634 bool Unit::isInvisibleForAlive() const
11636 if (m_AuraFlags
& UNIT_AURAFLAG_ALIVE_INVISIBLE
)
11638 // TODO: maybe spiritservices also have just an aura
11639 return isSpiritService();
11642 uint32
Unit::GetCreatureType() const
11644 if(GetTypeId() == TYPEID_PLAYER
)
11646 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(m_form
);
11647 if(ssEntry
&& ssEntry
->creatureType
> 0)
11648 return ssEntry
->creatureType
;
11650 return CREATURE_TYPE_HUMANOID
;
11653 return ((Creature
*)this)->GetCreatureInfo()->type
;
11656 /*#######################################
11658 ######## STAT SYSTEM ########
11660 #######################################*/
11662 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
11664 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11666 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
11672 switch(modifierType
)
11676 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
11680 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
11683 val
= (100.0f
+ amount
) / 100.0f
;
11684 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
11691 if(!CanModifyStats())
11696 case UNIT_MOD_STAT_STRENGTH
:
11697 case UNIT_MOD_STAT_AGILITY
:
11698 case UNIT_MOD_STAT_STAMINA
:
11699 case UNIT_MOD_STAT_INTELLECT
:
11700 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
11702 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
11703 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
11705 case UNIT_MOD_MANA
:
11706 case UNIT_MOD_RAGE
:
11707 case UNIT_MOD_FOCUS
:
11708 case UNIT_MOD_ENERGY
:
11709 case UNIT_MOD_HAPPINESS
:
11710 case UNIT_MOD_RUNE
:
11711 case UNIT_MOD_RUNIC_POWER
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
11713 case UNIT_MOD_RESISTANCE_HOLY
:
11714 case UNIT_MOD_RESISTANCE_FIRE
:
11715 case UNIT_MOD_RESISTANCE_NATURE
:
11716 case UNIT_MOD_RESISTANCE_FROST
:
11717 case UNIT_MOD_RESISTANCE_SHADOW
:
11718 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
11720 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
11721 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
11723 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
11724 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
11725 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
11734 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
11736 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11738 sLog
.outError("trial to access non existed modifier value from UnitMods!");
11742 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
11745 return m_auraModifiersGroup
[unitMod
][modifierType
];
11748 float Unit::GetTotalStatValue(Stats stat
) const
11750 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
11752 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11755 // value = ((base_value * base_pct) + total_value) * total_pct
11756 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
11757 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11758 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11759 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11764 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
11766 if(unitMod
>= UNIT_MOD_END
)
11768 sLog
.outError("trial to access non existed UnitMods in GetTotalAuraModValue()!");
11772 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11775 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
11776 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11777 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11778 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11783 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
11785 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
11789 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
11790 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
11791 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
11792 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
11793 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
11794 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
11803 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
11805 Stats stat
= STAT_STRENGTH
;
11809 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
11810 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
11811 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
11812 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
11813 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
11822 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
11826 case UNIT_MOD_MANA
: return POWER_MANA
;
11827 case UNIT_MOD_RAGE
: return POWER_RAGE
;
11828 case UNIT_MOD_FOCUS
: return POWER_FOCUS
;
11829 case UNIT_MOD_ENERGY
: return POWER_ENERGY
;
11830 case UNIT_MOD_HAPPINESS
: return POWER_HAPPINESS
;
11831 case UNIT_MOD_RUNE
: return POWER_RUNE
;
11832 case UNIT_MOD_RUNIC_POWER
:return POWER_RUNIC_POWER
;
11833 default: return POWER_MANA
;
11839 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
11841 if (attType
== RANGED_ATTACK
)
11843 int32 ap
= GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER_MODS
);
11846 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER
));
11850 int32 ap
= GetInt32Value(UNIT_FIELD_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_ATTACK_POWER_MODS
);
11853 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER
));
11857 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
11859 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
11862 return m_weaponDamage
[attType
][type
];
11865 void Unit::SetLevel(uint32 lvl
)
11867 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
11870 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
11871 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
11874 void Unit::SetHealth(uint32 val
)
11876 uint32 maxHealth
= GetMaxHealth();
11877 if(maxHealth
< val
)
11880 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
11883 if(GetTypeId() == TYPEID_PLAYER
)
11885 if(((Player
*)this)->GetGroup())
11886 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
11888 else if(((Creature
*)this)->isPet())
11890 Pet
*pet
= ((Pet
*)this);
11891 if(pet
->isControlled())
11893 Unit
*owner
= GetOwner();
11894 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11895 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
11900 void Unit::SetMaxHealth(uint32 val
)
11902 uint32 health
= GetHealth();
11903 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
11906 if(GetTypeId() == TYPEID_PLAYER
)
11908 if(((Player
*)this)->GetGroup())
11909 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
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_MAX_HP
);
11926 void Unit::SetHealthPercent(float percent
)
11928 uint32 newHealth
= GetMaxHealth() * percent
/100.0f
;
11929 SetHealth(newHealth
);
11932 void Unit::SetPower(Powers power
, uint32 val
)
11934 if(GetPower(power
) == val
)
11937 uint32 maxPower
= GetMaxPower(power
);
11941 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
11943 WorldPacket
data(SMSG_POWER_UPDATE
);
11944 data
<< GetPackGUID();
11945 data
<< uint8(power
);
11946 data
<< uint32(val
);
11947 SendMessageToSet(&data
, GetTypeId() == TYPEID_PLAYER
? true : false);
11950 if(GetTypeId() == TYPEID_PLAYER
)
11952 if(((Player
*)this)->GetGroup())
11953 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11955 else if(((Creature
*)this)->isPet())
11957 Pet
*pet
= ((Pet
*)this);
11958 if(pet
->isControlled())
11960 Unit
*owner
= GetOwner();
11961 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11962 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11965 // Update the pet's character sheet with happiness damage bonus
11966 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
11968 pet
->UpdateDamagePhysical(BASE_ATTACK
);
11973 void Unit::SetMaxPower(Powers power
, uint32 val
)
11975 uint32 cur_power
= GetPower(power
);
11976 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
11979 if(GetTypeId() == TYPEID_PLAYER
)
11981 if(((Player
*)this)->GetGroup())
11982 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
11984 else if(((Creature
*)this)->isPet())
11986 Pet
*pet
= ((Pet
*)this);
11987 if(pet
->isControlled())
11989 Unit
*owner
= GetOwner();
11990 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11991 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
11995 if(val
< cur_power
)
11996 SetPower(power
, val
);
11999 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
12001 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
12004 if(GetTypeId() == TYPEID_PLAYER
)
12006 if(((Player
*)this)->GetGroup())
12007 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
12009 else if(((Creature
*)this)->isPet())
12011 Pet
*pet
= ((Pet
*)this);
12012 if(pet
->isControlled())
12014 Unit
*owner
= GetOwner();
12015 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12016 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
12021 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
12023 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
12026 if(GetTypeId() == TYPEID_PLAYER
)
12028 if(((Player
*)this)->GetGroup())
12029 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
12031 else if(((Creature
*)this)->isPet())
12033 Pet
*pet
= ((Pet
*)this);
12034 if(pet
->isControlled())
12036 Unit
*owner
= GetOwner();
12037 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12038 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
12043 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
12045 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
12047 tAuraProcTriggerDamage
.push_back(aura
);
12049 tAuraProcTriggerDamage
.remove(aura
);
12052 uint32
Unit::GetCreatePowers( Powers power
) const
12054 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
12057 case POWER_HEALTH
: return 0;
12058 case POWER_MANA
: return GetCreateMana();
12059 case POWER_RAGE
: return 1000;
12060 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
12061 case POWER_ENERGY
: return 100;
12062 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
12063 case POWER_RUNIC_POWER
: return 1000;
12064 case POWER_RUNE
: return 0;
12070 void Unit::AddToWorld()
12072 Object::AddToWorld();
12075 void Unit::RemoveFromWorld()
12081 RemoveNotOwnSingleTargetAuras();
12083 RemoveAllGameObjects();
12084 RemoveAllDynObjects();
12085 CleanupDeletedAuras();
12088 Object::RemoveFromWorld();
12091 void Unit::CleanupsBeforeDelete()
12093 if(m_uint32Values
) // only for fully created object
12095 InterruptNonMeleeSpells(true);
12096 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
12098 ClearComboPointHolders();
12099 DeleteThreatList();
12100 getHostileRefManager().setOnlineOfflineState(false);
12101 RemoveAllAuras(AURA_REMOVE_BY_DELETE
);
12102 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
12104 WorldObject::CleanupsBeforeDelete();
12107 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
12110 m_charmInfo
= new CharmInfo(charm
);
12111 return m_charmInfo
;
12114 CharmInfo::CharmInfo(Unit
* unit
)
12115 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
12117 for(int i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
12118 m_charmspells
[i
].SetActionAndType(0,ACT_DISABLED
);
12121 void CharmInfo::InitPetActionBar()
12123 // the first 3 SpellOrActions are attack, follow and stay
12124 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_START
- ACTION_BAR_INDEX_START
; ++i
)
12125 SetActionBar(ACTION_BAR_INDEX_START
+ i
,COMMAND_ATTACK
- i
,ACT_COMMAND
);
12127 // middle 4 SpellOrActions are spells/special attacks/abilities
12128 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_END
-ACTION_BAR_INDEX_PET_SPELL_START
; ++i
)
12129 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_START
+ i
,0,ACT_DISABLED
);
12131 // last 3 SpellOrActions are reactions
12132 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_END
- ACTION_BAR_INDEX_PET_SPELL_END
; ++i
)
12133 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_END
+ i
,COMMAND_ATTACK
- i
,ACT_REACTION
);
12136 void CharmInfo::InitEmptyActionBar()
12138 SetActionBar(ACTION_BAR_INDEX_START
,COMMAND_ATTACK
,ACT_COMMAND
);
12139 for(uint32 x
= ACTION_BAR_INDEX_START
+1; x
< ACTION_BAR_INDEX_END
; ++x
)
12140 SetActionBar(x
,0,ACT_PASSIVE
);
12143 void CharmInfo::InitPossessCreateSpells()
12145 InitEmptyActionBar(); //charm action bar
12147 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //possessed players don't have spells, keep the action bar empty
12150 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12152 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
12153 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
12155 AddSpellToActionBar(((Creature
*)m_unit
)->m_spells
[x
], ACT_PASSIVE
);
12159 void CharmInfo::InitCharmCreateSpells()
12161 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
12163 InitEmptyActionBar();
12167 InitPetActionBar();
12169 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12171 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
12175 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
12179 if (IsPassiveSpell(spellId
))
12181 m_unit
->CastSpell(m_unit
, spellId
, true);
12182 m_charmspells
[x
].SetActionAndType(spellId
,ACT_PASSIVE
);
12186 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
12188 ActiveStates newstate
;
12189 bool onlyselfcast
= true;
12190 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
12192 if(!spellInfo
) onlyselfcast
= false;
12193 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
12195 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
12196 onlyselfcast
= false;
12199 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
12200 newstate
= ACT_DISABLED
;
12202 newstate
= ACT_PASSIVE
;
12204 AddSpellToActionBar(spellId
, newstate
);
12209 bool CharmInfo::AddSpellToActionBar(uint32 spell_id
, ActiveStates newstate
)
12211 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
12213 // new spell rank can be already listed
12214 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12216 if (uint32 action
= PetActionBar
[i
].GetAction())
12218 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
12220 PetActionBar
[i
].SetAction(spell_id
);
12226 // or use empty slot in other case
12227 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12229 if (!PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
12231 SetActionBar(i
,spell_id
,newstate
== ACT_DECIDE
? ACT_DISABLED
: newstate
);
12238 bool CharmInfo::RemoveSpellFromActionBar(uint32 spell_id
)
12240 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
12242 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12244 if (uint32 action
= PetActionBar
[i
].GetAction())
12246 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
12248 SetActionBar(i
,0,ACT_DISABLED
);
12257 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
12259 if(IsPassiveSpell(spellid
))
12262 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12263 if(spellid
== m_charmspells
[x
].GetAction())
12264 m_charmspells
[x
].SetType(apply
? ACT_ENABLED
: ACT_DISABLED
);
12267 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
12269 m_petnumber
= petnumber
;
12271 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
12273 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
12276 void CharmInfo::LoadPetActionBar(const std::string
& data
)
12278 InitPetActionBar();
12280 Tokens tokens
= StrSplit(data
, " ");
12282 if (tokens
.size() != (ACTION_BAR_INDEX_END
-ACTION_BAR_INDEX_START
)*2)
12283 return; // non critical, will reset to default
12286 Tokens::iterator iter
;
12287 for(iter
= tokens
.begin(), index
= ACTION_BAR_INDEX_START
; index
< ACTION_BAR_INDEX_END
; ++iter
, ++index
)
12289 // use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
12290 uint8 type
= (uint8
)atol((*iter
).c_str());
12292 uint32 action
= atol((*iter
).c_str());
12294 PetActionBar
[index
].SetActionAndType(action
,ActiveStates(type
));
12296 // check correctness
12297 if(PetActionBar
[index
].IsActionBarForSpell() && !sSpellStore
.LookupEntry(PetActionBar
[index
].GetAction()))
12298 SetActionBar(index
,0,ACT_DISABLED
);
12302 void CharmInfo::BuildActionBar( WorldPacket
* data
)
12304 for(uint32 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12305 *data
<< uint32(PetActionBar
[i
].packedData
);
12308 void CharmInfo::SetSpellAutocast( uint32 spell_id
, bool state
)
12310 for(int i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12312 if(spell_id
== PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
12314 PetActionBar
[i
].SetType(state
? ACT_ENABLED
: ACT_DISABLED
);
12320 bool Unit::isFrozen() const
12322 return HasAuraState(AURA_STATE_FROZEN
);
12325 struct ProcTriggeredData
12327 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
12328 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
12329 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
12331 SpellProcEventEntry
const *spellProcEvent
;
12332 Aura
* triggeredByAura
;
12333 Unit::spellEffectPair triggeredByAura_SpellPair
;
12336 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
12337 typedef std::list
< uint32
> RemoveSpellList
;
12339 // List of auras that CAN be trigger but may not exist in spell_proc_event
12340 // in most case need for drop charges
12341 // in some types of aura need do additional check
12342 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
12343 bool InitTriggerAuraData()
12345 for (int i
=0;i
<TOTAL_AURAS
;++i
)
12347 isTriggerAura
[i
]=false;
12348 isNonTriggerAura
[i
] = false;
12350 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
12351 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
12352 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
12353 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
12354 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
12355 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
12356 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
12357 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
12358 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
12359 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
12360 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
12361 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
12362 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
] = true;
12363 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
12364 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
12365 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
12366 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
12367 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
12368 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
12369 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
12370 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
12371 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
12372 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
12373 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
12374 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
12375 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
12376 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
12377 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
] = true;
12378 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_FROM_CASTER
] = true;
12379 isTriggerAura
[SPELL_AURA_MOD_SPELL_CRIT_CHANCE
] = true;
12380 isTriggerAura
[SPELL_AURA_MAELSTROM_WEAPON
] = true;
12382 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
12383 isNonTriggerAura
[SPELL_AURA_REDUCE_PUSHBACK
]=true;
12388 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
12390 uint32 procEx
= PROC_EX_NONE
;
12391 // Check victim state
12392 if (missCondition
!=SPELL_MISS_NONE
)
12393 switch (missCondition
)
12395 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
12396 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
12397 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
12398 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
12399 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
12400 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
12401 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
12402 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
12403 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
12404 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
12405 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
12412 if (damageInfo
->blocked
)
12413 procEx
|=PROC_EX_BLOCK
;
12415 if (damageInfo
->absorb
)
12416 procEx
|=PROC_EX_ABSORB
;
12418 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
12419 procEx
|=PROC_EX_CRITICAL_HIT
;
12421 procEx
|=PROC_EX_NORMAL_HIT
;
12426 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
12428 // For melee/ranged based attack need update skills and set some Aura states
12429 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
12431 // Update skills here for players
12432 if (GetTypeId() == TYPEID_PLAYER
)
12434 // On melee based hit/miss/resist need update skill (for victim and attacker)
12435 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
12437 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
12438 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, isVictim
);
12440 // Update defence if player is victim and parry/dodge/block
12441 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
12442 ((Player
*)this)->UpdateDefense();
12444 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
12445 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
12450 // if victim and dodge attack
12451 if (procExtra
&PROC_EX_DODGE
)
12453 //Update AURA_STATE on dodge
12454 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
12456 ModifyAuraState(AURA_STATE_DEFENSE
, true);
12457 StartReactiveTimer( REACTIVE_DEFENSE
);
12460 // if victim and parry attack
12461 if (procExtra
& PROC_EX_PARRY
)
12463 // For Hunters only Counterattack (skip Mongoose bite)
12464 if (getClass() == CLASS_HUNTER
)
12466 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
12467 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
12471 ModifyAuraState(AURA_STATE_DEFENSE
, true);
12472 StartReactiveTimer( REACTIVE_DEFENSE
);
12475 // if and victim block attack
12476 if (procExtra
& PROC_EX_BLOCK
)
12478 ModifyAuraState(AURA_STATE_DEFENSE
,true);
12479 StartReactiveTimer( REACTIVE_DEFENSE
);
12482 else //For attacker
12484 // Overpower on victim dodge
12485 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
12487 ((Player
*)this)->AddComboPoints(pTarget
, 1);
12488 StartReactiveTimer( REACTIVE_OVERPOWER
);
12494 RemoveSpellList removedSpells
;
12495 ProcTriggeredList procTriggered
;
12496 // Fill procTriggered list
12497 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
12499 // skip deleted auras (possible at recursive triggered call
12500 if(itr
->second
->IsDeleted())
12503 SpellProcEventEntry
const* spellProcEvent
= NULL
;
12504 if(!IsTriggeredAtSpellProcEvent(pTarget
, itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
12507 itr
->second
->SetInUse(true); // prevent aura deletion
12508 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
12512 if (procTriggered
.empty())
12515 // Handle effects proceed this time
12516 for(ProcTriggeredList::const_iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
12518 // Some auras can be deleted in function called in this loop (except first, ofc)
12519 Aura
*triggeredByAura
= i
->triggeredByAura
;
12520 if(triggeredByAura
->IsDeleted())
12523 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
12524 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
12525 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
12526 bool useCharges
= triggeredByAura
->GetAuraCharges() > 0;
12527 // For players set spell cooldown if need
12528 uint32 cooldown
= 0;
12529 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
12530 cooldown
= spellProcEvent
->cooldown
;
12532 switch(auraModifier
->m_auraname
)
12534 case SPELL_AURA_PROC_TRIGGER_SPELL
:
12536 DEBUG_LOG("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12537 // Don`t drop charge or add cooldown for not started trigger
12538 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12540 triggeredByAura
->SetInUse(false);
12545 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
12547 DEBUG_LOG("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());
12548 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, spellInfo
->SchoolMask
);
12549 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
12550 damageInfo
.target
->CalculateAbsorbResistBlock(this, &damageInfo
, spellInfo
);
12551 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
12552 SendSpellNonMeleeDamageLog(&damageInfo
);
12553 DealSpellDamage(&damageInfo
, true);
12556 case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
:
12557 case SPELL_AURA_MANA_SHIELD
:
12558 case SPELL_AURA_OBS_MOD_MANA
:
12559 case SPELL_AURA_ADD_PCT_MODIFIER
:
12560 case SPELL_AURA_DUMMY
:
12562 DEBUG_LOG("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12563 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12565 triggeredByAura
->SetInUse(false);
12570 case SPELL_AURA_MOD_HASTE
:
12572 DEBUG_LOG("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12573 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12575 triggeredByAura
->SetInUse(false);
12580 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
12582 DEBUG_LOG("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12583 if (!HandleOverrideClassScriptAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, cooldown
))
12585 triggeredByAura
->SetInUse(false);
12590 case SPELL_AURA_PRAYER_OF_MENDING
:
12592 DEBUG_LOG("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
12593 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
12595 HandleMendingAuraProc(triggeredByAura
);
12598 case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
:
12600 DEBUG_LOG("ProcDamageAndSpell: casting spell %u (triggered with value by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12602 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12604 triggeredByAura
->SetInUse(false);
12609 case SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
:
12610 // Skip melee hits or instant cast spells
12611 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
12613 triggeredByAura
->SetInUse(false);
12617 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
12618 // Skip Melee hits and spells ws wrong school
12619 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
12621 triggeredByAura
->SetInUse(false);
12625 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
12626 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
12627 // Skip melee hits and spells ws wrong school or zero cost
12628 if (procSpell
== NULL
||
12629 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
12630 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
12632 triggeredByAura
->SetInUse(false);
12636 case SPELL_AURA_MECHANIC_IMMUNITY
:
12637 // Compare mechanic
12638 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12640 triggeredByAura
->SetInUse(false);
12644 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
12645 // Compare mechanic
12646 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12648 triggeredByAura
->SetInUse(false);
12652 case SPELL_AURA_MOD_DAMAGE_FROM_CASTER
:
12654 if (triggeredByAura
->GetCasterGUID() != pTarget
->GetGUID())
12656 triggeredByAura
->SetInUse(false);
12660 case SPELL_AURA_MOD_SPELL_CRIT_CHANCE
:
12663 triggeredByAura
->SetInUse(false);
12666 DEBUG_LOG("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());
12667 if (!HandleSpellCritChanceAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12669 triggeredByAura
->SetInUse(false);
12673 case SPELL_AURA_MAELSTROM_WEAPON
:
12674 DEBUG_LOG("ProcDamageAndSpell: casting spell id %u (triggered by %s maelstrom aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12676 // remove all stack;
12677 RemoveSpellsCausingAura(SPELL_AURA_MAELSTROM_WEAPON
);
12678 triggeredByAura
->SetInUse(false); // this safe, aura locked
12679 continue; // avoid re-remove attempts
12681 // nothing do, just charges counter
12685 // Remove charge (aura can be removed by triggers)
12686 if(useCharges
&& !triggeredByAura
->IsDeleted())
12688 // If last charge dropped add spell to remove list
12689 if(triggeredByAura
->DropAuraCharge())
12690 removedSpells
.push_back(triggeredByAura
->GetId());
12693 triggeredByAura
->SetInUse(false);
12695 if (!removedSpells
.empty())
12697 // Sort spells and remove dublicates
12698 removedSpells
.sort();
12699 removedSpells
.unique();
12700 // Remove auras from removedAuras
12701 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();++i
)
12702 RemoveSingleSpellAurasFromStack(*i
);
12706 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
12708 return SPELL_SCHOOL_MASK_NORMAL
;
12711 Player
* Unit::GetSpellModOwner()
12713 if(GetTypeId()==TYPEID_PLAYER
)
12714 return (Player
*)this;
12715 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
12717 Unit
* owner
= GetOwner();
12718 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
12719 return (Player
*)owner
;
12724 ///----------Pet responses methods-----------------
12725 void Unit::SendPetCastFail(uint32 spellid
, SpellCastResult msg
)
12727 if(msg
== SPELL_CAST_OK
)
12730 Unit
*owner
= GetCharmerOrOwner();
12731 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12734 WorldPacket
data(SMSG_PET_CAST_FAILED
, 1 + 4 + 1);
12735 data
<< uint8(0); // cast count?
12736 data
<< uint32(spellid
);
12737 data
<< uint8(msg
);
12738 // uint32 for some reason
12739 // uint32 for some reason
12740 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12743 void Unit::SendPetActionFeedback (uint8 msg
)
12745 Unit
* owner
= GetOwner();
12746 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12749 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
12750 data
<< uint8(msg
);
12751 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12754 void Unit::SendPetTalk (uint32 pettalk
)
12756 Unit
* owner
= GetOwner();
12757 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12760 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8 + 4);
12761 data
<< uint64(GetGUID());
12762 data
<< uint32(pettalk
);
12763 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12766 void Unit::SendPetAIReaction(uint64 guid
)
12768 Unit
* owner
= GetOwner();
12769 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12772 WorldPacket
data(SMSG_AI_REACTION
, 8 + 4);
12773 data
<< uint64(guid
);
12774 data
<< uint32(AI_REACTION_HOSTILE
);
12775 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12778 ///----------End of Pet responses methods----------
12780 void Unit::StopMoving()
12782 clearUnitState(UNIT_STAT_MOVING
);
12784 // send explicit stop packet
12785 // player expected for correct work SPLINEFLAG_WALKMODE
12786 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_NORMAL
, GetTypeId() == TYPEID_PLAYER
? SPLINEFLAG_WALKMODE
: SPLINEFLAG_NONE
, 0);
12788 // update position and orientation for near players
12790 BuildHeartBeatMsg(&data
);
12791 SendMessageToSet(&data
, false);
12794 void Unit::SetFeared(bool apply
, uint64
const& casterGUID
, uint32 spellID
, uint32 time
)
12798 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
12801 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12803 GetMotionMaster()->MovementExpired(false);
12804 CastStop(GetGUID() == casterGUID
? spellID
: 0);
12806 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
12808 GetMotionMaster()->MoveFleeing(caster
, time
); // caster==NULL processed in MoveFleeing
12812 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12814 GetMotionMaster()->MovementExpired(false);
12816 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
12818 // restore appropriate movement generator
12820 GetMotionMaster()->MoveChase(getVictim());
12822 GetMotionMaster()->Initialize();
12824 // attack caster if can
12825 Unit
* caster
= Unit::GetUnit(*this, casterGUID
);
12826 if(caster
&& ((Creature
*)this)->AI())
12827 ((Creature
*)this)->AI()->AttackedBy(caster
);
12831 if (GetTypeId() == TYPEID_PLAYER
)
12832 ((Player
*)this)->SetClientControl(this, !apply
);
12835 void Unit::SetConfused(bool apply
, uint64
const& casterGUID
, uint32 spellID
)
12839 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12841 CastStop(GetGUID()==casterGUID
? spellID
: 0);
12843 GetMotionMaster()->MoveConfused();
12847 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12849 GetMotionMaster()->MovementExpired(false);
12851 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12853 // restore appropriate movement generator
12855 GetMotionMaster()->MoveChase(getVictim());
12857 GetMotionMaster()->Initialize();
12861 if(GetTypeId() == TYPEID_PLAYER
)
12862 ((Player
*)this)->SetClientControl(this, !apply
);
12865 void Unit::SetFeignDeath(bool apply
, uint64
const& casterGUID
, uint32
/*spellID*/)
12870 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12873 SendMessageToSet(&data,true);
12876 if(GetTypeId() != TYPEID_PLAYER
)
12879 ((Player
*)this)->m_movementInfo
.SetMovementFlags(MOVEFLAG_NONE
);
12881 // blizz like 2.0.x
12882 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12883 // blizz like 2.0.x
12884 SetFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12885 // blizz like 2.0.x
12886 SetFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12888 addUnitState(UNIT_STAT_DIED
);
12890 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION
);
12892 // prevent interrupt message
12893 if (casterGUID
== GetGUID())
12894 FinishSpell(CURRENT_GENERIC_SPELL
,false);
12895 InterruptNonMeleeSpells(true);
12896 getHostileRefManager().deleteReferences();
12901 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12904 SendMessageToSet(&data,true);
12906 // blizz like 2.0.x
12907 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12908 // blizz like 2.0.x
12909 RemoveFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12910 // blizz like 2.0.x
12911 RemoveFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12913 clearUnitState(UNIT_STAT_DIED
);
12915 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12917 // restore appropriate movement generator
12919 GetMotionMaster()->MoveChase(getVictim());
12921 GetMotionMaster()->Initialize();
12927 bool Unit::IsSitState() const
12929 uint8 s
= getStandState();
12931 s
== UNIT_STAND_STATE_SIT_CHAIR
|| s
== UNIT_STAND_STATE_SIT_LOW_CHAIR
||
12932 s
== UNIT_STAND_STATE_SIT_MEDIUM_CHAIR
|| s
== UNIT_STAND_STATE_SIT_HIGH_CHAIR
||
12933 s
== UNIT_STAND_STATE_SIT
;
12936 bool Unit::IsStandState() const
12938 uint8 s
= getStandState();
12939 return !IsSitState() && s
!= UNIT_STAND_STATE_SLEEP
&& s
!= UNIT_STAND_STATE_KNEEL
;
12942 void Unit::SetStandState(uint8 state
)
12944 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
12946 if (IsStandState())
12947 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
12949 if(GetTypeId()==TYPEID_PLAYER
)
12951 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
12952 data
<< (uint8
)state
;
12953 ((Player
*)this)->GetSession()->SendPacket(&data
);
12957 bool Unit::IsPolymorphed() const
12959 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
12962 void Unit::SetDisplayId(uint32 modelId
)
12964 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
12966 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
12968 Pet
*pet
= ((Pet
*)this);
12969 if(!pet
->isControlled())
12971 Unit
*owner
= GetOwner();
12972 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12973 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
12977 void Unit::ClearComboPointHolders()
12979 while(!m_ComboPointHolders
.empty())
12981 uint32 lowguid
= *m_ComboPointHolders
.begin();
12983 Player
* plr
= sObjectMgr
.GetPlayer(ObjectGuid(HIGHGUID_PLAYER
, lowguid
));
12984 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
12985 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
12987 m_ComboPointHolders
.erase(lowguid
); // or remove manually
12991 void Unit::ClearAllReactives()
12993 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
12994 m_reactiveTimer
[i
] = 0;
12996 if (HasAuraState( AURA_STATE_DEFENSE
))
12997 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12998 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
12999 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
13000 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
13001 ((Player
*)this)->ClearComboPoints();
13004 void Unit::UpdateReactives( uint32 p_time
)
13006 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
13008 ReactiveType reactive
= ReactiveType(i
);
13010 if(!m_reactiveTimer
[reactive
])
13013 if ( m_reactiveTimer
[reactive
] <= p_time
)
13015 m_reactiveTimer
[reactive
] = 0;
13017 switch ( reactive
)
13019 case REACTIVE_DEFENSE
:
13020 if (HasAuraState(AURA_STATE_DEFENSE
))
13021 ModifyAuraState(AURA_STATE_DEFENSE
, false);
13023 case REACTIVE_HUNTER_PARRY
:
13024 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
13025 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
13027 case REACTIVE_OVERPOWER
:
13028 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
13029 ((Player
*)this)->ClearComboPoints();
13037 m_reactiveTimer
[reactive
] -= p_time
;
13042 Unit
* Unit::SelectRandomUnfriendlyTarget(Unit
* except
/*= NULL*/, float radius
/*= ATTACK_DISTANCE*/) const
13044 std::list
<Unit
*> targets
;
13046 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, radius
);
13047 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
13048 Cell::VisitAllObjects(this, searcher
, radius
);
13050 // remove current target
13052 targets
.remove(except
);
13054 // remove not LoS targets
13055 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
13057 if(!IsWithinLOSInMap(*tIter
))
13059 std::list
<Unit
*>::iterator tIter2
= tIter
;
13061 targets
.erase(tIter2
);
13067 // no appropriate targets
13068 if(targets
.empty())
13072 uint32 rIdx
= urand(0,targets
.size()-1);
13073 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
13074 for(uint32 i
= 0; i
< rIdx
; ++i
)
13080 Unit
* Unit::SelectRandomFriendlyTarget(Unit
* except
/*= NULL*/, float radius
/*= ATTACK_DISTANCE*/) const
13082 std::list
<Unit
*> targets
;
13084 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(this, radius
);
13085 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
13087 Cell::VisitAllObjects(this, searcher
, radius
);
13088 // remove current target
13090 targets
.remove(except
);
13092 // remove not LoS targets
13093 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
13095 if(!IsWithinLOSInMap(*tIter
))
13097 std::list
<Unit
*>::iterator tIter2
= tIter
;
13099 targets
.erase(tIter2
);
13105 // no appropriate targets
13106 if(targets
.empty())
13110 uint32 rIdx
= urand(0,targets
.size()-1);
13111 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
13112 for(uint32 i
= 0; i
< rIdx
; ++i
)
13118 bool Unit::hasNegativeAuraWithInterruptFlag(uint32 flag
)
13120 for (AuraMap::const_iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); ++iter
)
13122 if (!iter
->second
->IsPositive() && iter
->second
->GetSpellProto()->AuraInterruptFlags
& flag
)
13128 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
13132 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
13133 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
13137 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
13138 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
13142 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
13145 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
13147 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
13150 void Unit::UpdateAuraForGroup(uint8 slot
)
13152 if(GetTypeId() == TYPEID_PLAYER
)
13154 Player
* player
= (Player
*)this;
13155 if(player
->GetGroup())
13157 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
13158 player
->SetAuraUpdateMask(slot
);
13161 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
13163 Pet
*pet
= ((Pet
*)this);
13164 if(pet
->isControlled())
13166 Unit
*owner
= GetOwner();
13167 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
13169 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
13170 pet
->SetAuraUpdateMask(slot
);
13176 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
13178 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
13179 return float(GetAttackTime(attType
))/1000.0f
;
13181 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
, true, false);
13183 return 2.4f
; // fist attack
13185 switch (Weapon
->GetProto()->InventoryType
)
13187 case INVTYPE_2HWEAPON
:
13189 case INVTYPE_RANGED
:
13190 case INVTYPE_RANGEDRIGHT
:
13191 case INVTYPE_THROWN
:
13193 case INVTYPE_WEAPON
:
13194 case INVTYPE_WEAPONMAINHAND
:
13195 case INVTYPE_WEAPONOFFHAND
:
13197 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7f
: 2.4f
;
13201 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
13203 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
13204 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
13205 if ((*itr
)->GetId() == spell_id
)
13211 void Unit::SetContestedPvP(Player
*attackedPlayer
)
13213 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
13215 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
13218 player
->SetContestedPvPTimer(30000);
13219 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
13221 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
13222 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
13223 // call MoveInLineOfSight for nearby contested guards
13224 SetVisibility(GetVisibility());
13226 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
13228 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
13229 // call MoveInLineOfSight for nearby contested guards
13230 SetVisibility(GetVisibility());
13234 void Unit::AddPetAura(PetAura
const* petSpell
)
13236 m_petAuras
.insert(petSpell
);
13237 if(Pet
* pet
= GetPet())
13238 pet
->CastPetAura(petSpell
);
13241 void Unit::RemovePetAura(PetAura
const* petSpell
)
13243 m_petAuras
.erase(petSpell
);
13244 if(Pet
* pet
= GetPet())
13245 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
13248 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
13250 Pet
* pet
= new Pet(HUNTER_PET
);
13252 if(!pet
->CreateBaseAtCreature(creatureTarget
))
13258 pet
->SetOwnerGUID(GetGUID());
13259 pet
->SetCreatorGUID(GetGUID());
13260 pet
->setFaction(getFaction());
13261 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
13263 if(GetTypeId()==TYPEID_PLAYER
)
13264 pet
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
13270 pet
->SetFFAPvP(true);
13272 uint32 level
= (creatureTarget
->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget
->getLevel();
13274 if(!pet
->InitStatsForLevel(level
))
13276 sLog
.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
13281 pet
->GetCharmInfo()->SetPetNumber(sObjectMgr
.GeneratePetNumber(), true);
13282 // this enables pet details window (Shift+P)
13283 pet
->AIM_Initialize();
13284 pet
->InitPetCreateSpells();
13285 pet
->InitLevelupSpellsForLevel();
13286 pet
->InitTalentForLevel();
13287 pet
->SetHealth(pet
->GetMaxHealth());
13292 bool Unit::IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
13294 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
13296 // Get proc Event Entry
13297 spellProcEvent
= sSpellMgr
.GetSpellProcEvent(spellProto
->Id
);
13299 // Aura info stored here
13300 Modifier
*mod
= aura
->GetModifier();
13302 if (isNonTriggerAura
[mod
->m_auraname
])
13304 // If not trigger by default and spellProcEvent==NULL - skip
13305 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
13308 // Get EventProcFlag
13309 uint32 EventProcFlag
;
13310 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
13311 EventProcFlag
= spellProcEvent
->procFlags
;
13313 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
13314 // Continue if no trigger exist
13315 if (!EventProcFlag
)
13318 // Check spellProcEvent data requirements
13319 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
13322 // In most cases req get honor or XP from kill
13323 if (EventProcFlag
& PROC_FLAG_KILL
&& GetTypeId() == TYPEID_PLAYER
)
13325 bool allow
= ((Player
*)this)->isHonorOrXPTarget(pVictim
);
13326 // Shadow Word: Death - can trigger from every kill
13327 if (aura
->GetId() == 32409)
13332 // Aura added by spell can`t trogger from self (prevent drop charges/do triggers)
13333 // But except periodic triggers (can triggered from self)
13334 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
& PROC_FLAG_ON_TAKE_PERIODIC
))
13337 // Check if current equipment allows aura to proc
13338 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
13340 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
13343 if(attType
== BASE_ATTACK
)
13344 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
13345 else if (attType
== OFF_ATTACK
)
13346 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
13348 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
13350 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
13353 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
13355 // Check if player is wearing shield
13356 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
13357 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
13361 // Get chance from spell
13362 float chance
= (float)spellProto
->procChance
;
13363 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
13364 if(spellProcEvent
&& spellProcEvent
->customChance
)
13365 chance
= spellProcEvent
->customChance
;
13366 // If PPM exist calculate chance from PPM
13367 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
13369 uint32 WeaponSpeed
= GetAttackTime(attType
);
13370 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
13372 // Apply chance modifer aura
13373 if(Player
* modOwner
= GetSpellModOwner())
13375 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
13376 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_FREQUENCY_OF_SUCCESS
,chance
);
13379 return roll_chance_f(chance
);
13382 bool Unit::HandleMendingAuraProc( Aura
* triggeredByAura
)
13384 // aura can be deleted at casts
13385 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
13386 SpellEffectIndex effIdx
= triggeredByAura
->GetEffIndex();
13387 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
13388 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
13391 int32 jumps
= triggeredByAura
->GetAuraCharges()-1;
13393 // current aura expire
13394 triggeredByAura
->SetAuraCharges(1); // will removed at next charges decrease
13396 // next target selection
13397 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
13400 if (spellProto
->EffectRadiusIndex
[effIdx
])
13401 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
13403 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
13405 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
13407 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
13409 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
13411 // aura will applied from caster, but spell casted from current aura holder
13412 SpellModifier
*mod
= new SpellModifier(SPELLMOD_CHARGES
,SPELLMOD_FLAT
,jumps
-5,spellProto
->Id
,spellProto
->SpellFamilyFlags
,spellProto
->SpellFamilyFlags2
);
13414 // remove before apply next (locked against deleted)
13415 triggeredByAura
->SetInUse(true);
13416 RemoveAurasByCasterSpell(spellProto
->Id
,caster
->GetGUID());
13418 caster
->AddSpellMod(mod
, true);
13419 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
13420 caster
->AddSpellMod(mod
, false);
13421 triggeredByAura
->SetInUse(false);
13427 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
13431 void Unit::RemoveAurasAtMechanicImmunity(uint32 mechMask
, uint32 exceptSpellId
, bool non_positive
/*= false*/)
13433 Unit::AuraMap
& auras
= GetAuras();
13434 for(Unit::AuraMap::iterator iter
= auras
.begin(); iter
!= auras
.end();)
13436 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
13437 if (spell
->Id
== exceptSpellId
)
13439 else if (non_positive
&& iter
->second
->IsPositive())
13441 else if (spell
->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
)
13443 else if (GetSpellMechanicMask(spell
, iter
->second
->GetEffIndex()) & mechMask
)
13445 RemoveAurasDueToSpell(spell
->Id
);
13449 iter
= auras
.begin();
13456 void Unit::SetPhaseMask(uint32 newPhaseMask
, bool update
)
13458 if(newPhaseMask
==GetPhaseMask())
13462 RemoveNotOwnSingleTargetAuras(newPhaseMask
); // we can lost access to caster or target
13464 WorldObject::SetPhaseMask(newPhaseMask
,update
);
13467 if(Pet
* pet
= GetPet())
13468 pet
->SetPhaseMask(newPhaseMask
,true);
13471 void Unit::NearTeleportTo( float x
, float y
, float z
, float orientation
, bool casting
/*= false*/ )
13473 if(GetTypeId() == TYPEID_PLAYER
)
13474 ((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));
13477 Creature
* c
= (Creature
*)this;
13478 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13479 if (!c
->GetMotionMaster()->empty())
13480 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13481 movgen
->Interrupt(*c
);
13483 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, orientation
);
13486 BuildHeartBeatMsg(&data
);
13487 SendMessageToSet(&data
, false);
13488 // finished relocation, movegen can different from top before creature relocation,
13489 // but apply Reset expected to be safe in any case
13490 if (!c
->GetMotionMaster()->empty())
13491 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13496 void Unit::MonsterMove(float x
, float y
, float z
, uint32 transitTime
)
13498 SplineFlags flags
= GetTypeId() == TYPEID_PLAYER
? SPLINEFLAG_WALKMODE
: ((Creature
*)this)->GetSplineFlags();
13499 SendMonsterMove(x
, y
, z
, SPLINETYPE_NORMAL
, flags
, transitTime
);
13501 if (GetTypeId() != TYPEID_PLAYER
)
13503 Creature
* c
= (Creature
*)this;
13504 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13505 if (!c
->GetMotionMaster()->empty())
13506 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13507 movgen
->Interrupt(*c
);
13509 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, 0.0f
);
13511 // finished relocation, movegen can different from top before creature relocation,
13512 // but apply Reset expected to be safe in any case
13513 if (!c
->GetMotionMaster()->empty())
13514 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13519 void Unit::MonsterMoveWithSpeed(float x
, float y
, float z
, uint32 transitTime
)
13521 SendMonsterMoveWithSpeed(x
, y
, z
, transitTime
);
13523 if (GetTypeId() != TYPEID_PLAYER
)
13525 Creature
* c
= (Creature
*)this;
13526 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13527 if (!c
->GetMotionMaster()->empty())
13528 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13529 movgen
->Interrupt(*c
);
13531 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, 0.0f
);
13533 // finished relocation, movegen can different from top before creature relocation,
13534 // but apply Reset expected to be safe in any case
13535 if (!c
->GetMotionMaster()->empty())
13536 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13541 struct SetPvPHelper
13543 explicit SetPvPHelper(bool _state
) : state(_state
) {}
13544 void operator()(Unit
* unit
) const { unit
->SetPvP(state
); }
13548 void Unit::SetPvP( bool state
)
13551 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13553 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13555 CallForAllControlledUnits(SetPvPHelper(state
),true,true,true);
13558 struct SetFFAPvPHelper
13560 explicit SetFFAPvPHelper(bool _state
) : state(_state
) {}
13561 void operator()(Unit
* unit
) const { unit
->SetFFAPvP(state
); }
13565 void Unit::SetFFAPvP( bool state
)
13568 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13570 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13572 CallForAllControlledUnits(SetFFAPvPHelper(state
),true,true,true);
13575 void Unit::KnockBackFrom(Unit
* target
, float horizontalSpeed
, float verticalSpeed
)
13577 float angle
= this == target
? GetOrientation() + M_PI_F
: target
->GetAngle(this);
13578 float vsin
= sin(angle
);
13579 float vcos
= cos(angle
);
13581 // Effect propertly implemented only for players
13582 if(GetTypeId()==TYPEID_PLAYER
)
13584 WorldPacket
data(SMSG_MOVE_KNOCK_BACK
, 8+4+4+4+4+4);
13585 data
<< GetPackGUID();
13586 data
<< uint32(0); // Sequence
13587 data
<< float(vcos
); // x direction
13588 data
<< float(vsin
); // y direction
13589 data
<< float(horizontalSpeed
); // Horizontal speed
13590 data
<< float(-verticalSpeed
); // Z Movement speed (vertical)
13591 ((Player
*)this)->GetSession()->SendPacket(&data
);
13595 float dis
= horizontalSpeed
;
13598 GetPosition(ox
, oy
, oz
);
13600 float fx
= ox
+ dis
* vcos
;
13601 float fy
= oy
+ dis
* vsin
;
13604 float fx2
, fy2
, fz2
; // getObjectHitPos overwrite last args in any result case
13605 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), ox
,oy
,oz
+0.5f
, fx
,fy
,oz
+0.5f
,fx2
,fy2
,fz2
, -0.5f
))
13612 UpdateGroundPositionZ(fx
, fy
, fz
);
13614 //FIXME: this mostly hack, must exist some packet for proper creature move at client side
13615 // with CreatureRelocation at server side
13616 NearTeleportTo(fx
, fy
, fz
, GetOrientation(), this == target
);
13620 float Unit::GetCombatRatingReduction(CombatRating cr
) const
13622 if (GetTypeId() == TYPEID_PLAYER
)
13623 return ((Player
const*)this)->GetRatingBonusValue(cr
);
13624 else if (((Creature
const*)this)->isPet())
13626 // Player's pet have 0.4 resilience from owner
13627 if (Unit
* owner
= GetOwner())
13628 if(owner
->GetTypeId() == TYPEID_PLAYER
)
13629 return ((Player
*)owner
)->GetRatingBonusValue(cr
) * 0.4f
;
13635 uint32
Unit::GetCombatRatingDamageReduction(CombatRating cr
, float rate
, float cap
, uint32 damage
) const
13637 float percent
= GetCombatRatingReduction(cr
) * rate
;
13640 return uint32 (percent
* damage
/ 100.0f
);
13643 void Unit::SendThreatUpdate()
13645 ThreatList
const& tlist
= getThreatManager().getThreatList();
13646 if (uint32 count
= tlist
.size())
13648 DEBUG_LOG( "WORLD: Send SMSG_THREAT_UPDATE Message" );
13649 WorldPacket
data(SMSG_THREAT_UPDATE
, 8 + count
* 8);
13650 data
<< GetPackGUID();
13651 data
<< uint32(count
);
13652 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13654 data
.appendPackGUID((*itr
)->getUnitGuid());
13655 data
<< uint32((*itr
)->getThreat());
13657 SendMessageToSet(&data
, false);
13661 void Unit::SendHighestThreatUpdate(HostileReference
* pHostilReference
)
13663 ThreatList
const& tlist
= getThreatManager().getThreatList();
13664 if (uint32 count
= tlist
.size())
13666 DEBUG_LOG( "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message" );
13667 WorldPacket
data(SMSG_HIGHEST_THREAT_UPDATE
, 8 + 8 + count
* 8);
13668 data
<< GetPackGUID();
13669 data
.appendPackGUID(pHostilReference
->getUnitGuid());
13670 data
<< uint32(count
);
13671 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13673 data
.appendPackGUID((*itr
)->getUnitGuid());
13674 data
<< uint32((*itr
)->getThreat());
13676 SendMessageToSet(&data
, false);
13680 void Unit::SendThreatClear()
13682 DEBUG_LOG( "WORLD: Send SMSG_THREAT_CLEAR Message" );
13683 WorldPacket
data(SMSG_THREAT_CLEAR
, 8);
13684 data
<< GetPackGUID();
13685 SendMessageToSet(&data
, false);
13688 void Unit::SendThreatRemove(HostileReference
* pHostileReference
)
13690 DEBUG_LOG( "WORLD: Send SMSG_THREAT_REMOVE Message" );
13691 WorldPacket
data(SMSG_THREAT_REMOVE
, 8 + 8);
13692 data
<< GetPackGUID();
13693 data
.appendPackGUID(pHostileReference
->getUnitGuid());
13694 SendMessageToSet(&data
, false);
13697 struct StopAttackFactionHelper
13699 explicit StopAttackFactionHelper(uint32 _faction_id
) : faction_id(_faction_id
) {}
13700 void operator()(Unit
* unit
) const { unit
->StopAttackFaction(faction_id
); }
13704 void Unit::StopAttackFaction(uint32 faction_id
)
13706 if (Unit
* victim
= getVictim())
13708 if (victim
->getFactionTemplateEntry()->faction
==faction_id
)
13711 if (IsNonMeleeSpellCasted(false))
13712 InterruptNonMeleeSpells(false);
13714 // melee and ranged forced attack cancel
13715 if (GetTypeId() == TYPEID_PLAYER
)
13716 ((Player
*)this)->SendAttackSwingCancelAttack();
13720 AttackerSet
const& attackers
= getAttackers();
13721 for(AttackerSet::const_iterator itr
= attackers
.begin(); itr
!= attackers
.end();)
13723 if ((*itr
)->getFactionTemplateEntry()->faction
==faction_id
)
13725 (*itr
)->AttackStop();
13726 itr
= attackers
.begin();
13732 getHostileRefManager().deleteReferencesForFaction(faction_id
);
13734 CallForAllControlledUnits(StopAttackFactionHelper(faction_id
),false,true,true);
13737 void Unit::CleanupDeletedAuras()
13739 // really delete auras "deleted" while processing its ApplyModify code
13740 for(AuraList::const_iterator itr
= m_deletedAuras
.begin(); itr
!= m_deletedAuras
.end(); ++itr
)
13742 m_deletedAuras
.clear();
13745 bool Unit::CheckAndIncreaseCastCounter()
13747 uint32 maxCasts
= sWorld
.getConfig(CONFIG_UINT32_MAX_SPELL_CASTS_IN_CHAIN
);
13749 if (maxCasts
&& m_castCounter
>= maxCasts
)