2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "WorldPacket.h"
23 #include "WorldSession.h"
25 #include "ObjectMgr.h"
26 #include "ObjectDefines.h"
34 #include "SpellAuras.h"
35 #include "MapManager.h"
36 #include "ObjectAccessor.h"
37 #include "CreatureAI.h"
38 #include "TemporarySummon.h"
43 #include "BattleGround.h"
44 #include "InstanceSaveMgr.h"
45 #include "GridNotifiersImpl.h"
48 #include "Traveller.h"
49 #include "VMapFactory.h"
53 float baseMoveSpeed
[MAX_MOVE_TYPE
] =
57 1.25f
, // MOVE_RUN_BACK
58 4.722222f
, // MOVE_SWIM
59 4.5f
, // MOVE_SWIM_BACK
60 3.141594f
, // MOVE_TURN_RATE
62 4.5f
, // MOVE_FLIGHT_BACK
63 3.14f
// MOVE_PITCH_RATE
66 // Used for prepare can/can`t trigger aura
67 static bool InitTriggerAuraData();
68 // Define can trigger auras
69 static bool isTriggerAura
[TOTAL_AURAS
];
70 // Define can`t trigger auras (need for disable second trigger)
71 static bool isNonTriggerAura
[TOTAL_AURAS
];
73 static bool procPrepared
= InitTriggerAuraData();
75 MovementInfo::MovementInfo(WorldPacket
&data
)
78 moveFlags
= MOVEFLAG_NONE
;
79 moveFlags2
= MOVEFLAG2_NONE
;
87 j_velocity
= j_sinAngle
= j_cosAngle
= j_xyspeed
= 0.0f
;
94 void MovementInfo::Read(ByteBuffer
&data
)
104 if(HasMovementFlag(MOVEFLAG_ONTRANSPORT
))
106 if(!data
.readPackGUID(t_guid
))
116 if(moveFlags2
& MOVEFLAG2_UNK1
)
120 if((HasMovementFlag(MovementFlags(MOVEFLAG_SWIMMING
| MOVEFLAG_FLYING
))) || (moveFlags2
& MOVEFLAG2_ALLOW_PITCHING
))
127 if(HasMovementFlag(MOVEFLAG_JUMPING
))
135 if(HasMovementFlag(MOVEFLAG_SPLINE
))
141 void MovementInfo::Write(ByteBuffer
&data
)
151 if(HasMovementFlag(MOVEFLAG_ONTRANSPORT
))
153 data
.appendPackGUID(t_guid
);
162 if(moveFlags2
& MOVEFLAG2_UNK1
)
166 if((HasMovementFlag(MovementFlags(MOVEFLAG_SWIMMING
| MOVEFLAG_FLYING
))) || (moveFlags2
& MOVEFLAG2_ALLOW_PITCHING
))
173 if(HasMovementFlag(MOVEFLAG_JUMPING
))
181 if(HasMovementFlag(MOVEFLAG_SPLINE
))
188 : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostileRefManager(this)
190 m_objectType
|= TYPEMASK_UNIT
;
191 m_objectTypeId
= TYPEID_UNIT
;
193 m_updateFlag
= (UPDATEFLAG_HIGHGUID
| UPDATEFLAG_LIVING
| UPDATEFLAG_HAS_POSITION
);
195 m_attackTimer
[BASE_ATTACK
] = 0;
196 m_attackTimer
[OFF_ATTACK
] = 0;
197 m_attackTimer
[RANGED_ATTACK
] = 0;
198 m_modAttackSpeedPct
[BASE_ATTACK
] = 1.0f
;
199 m_modAttackSpeedPct
[OFF_ATTACK
] = 1.0f
;
200 m_modAttackSpeedPct
[RANGED_ATTACK
] = 1.0f
;
206 m_deathState
= ALIVE
;
208 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
209 m_currentSpells
[i
] = NULL
;
213 for(int i
= 0; i
< MAX_TOTEM
; ++i
)
216 m_ObjectSlot
[0] = m_ObjectSlot
[1] = m_ObjectSlot
[2] = m_ObjectSlot
[3] = 0;
218 //m_AurasCheck = 2000;
219 //m_removeAuraTimer = 4;
220 m_AurasUpdateIterator
= m_Auras
.end();
223 m_Visibility
= VISIBILITY_ON
;
225 m_detectInvisibilityMask
= 0;
226 m_invisibilityMask
= 0;
228 m_ShapeShiftFormSpellId
= 0;
229 m_canModifyStats
= false;
231 for (int i
= 0; i
< MAX_SPELL_IMMUNITY
; ++i
)
232 m_spellImmune
[i
].clear();
233 for (int i
= 0; i
< UNIT_MOD_END
; ++i
)
235 m_auraModifiersGroup
[i
][BASE_VALUE
] = 0.0f
;
236 m_auraModifiersGroup
[i
][BASE_PCT
] = 1.0f
;
237 m_auraModifiersGroup
[i
][TOTAL_VALUE
] = 0.0f
;
238 m_auraModifiersGroup
[i
][TOTAL_PCT
] = 1.0f
;
240 // implement 50% base damage from offhand
241 m_auraModifiersGroup
[UNIT_MOD_DAMAGE_OFFHAND
][TOTAL_PCT
] = 0.5f
;
243 for (int i
= 0; i
< MAX_ATTACK
; ++i
)
245 m_weaponDamage
[i
][MINDAMAGE
] = BASE_MINDAMAGE
;
246 m_weaponDamage
[i
][MAXDAMAGE
] = BASE_MAXDAMAGE
;
248 for (int i
= 0; i
< MAX_STATS
; ++i
)
249 m_createStats
[i
] = 0.0f
;
252 m_modMeleeHitChance
= 0.0f
;
253 m_modRangedHitChance
= 0.0f
;
254 m_modSpellHitChance
= 0.0f
;
255 m_baseSpellCritChance
= 5;
258 m_lastManaUseTimer
= 0;
260 //m_victimThreat = 0.0f;
261 for (int i
= 0; i
< MAX_SPELL_SCHOOL
; ++i
)
262 m_threatModifier
[i
] = 1.0f
;
264 for (int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
265 m_speed_rate
[i
] = 1.0f
;
269 // remove aurastates allowing special moves
270 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
271 m_reactiveTimer
[i
] = 0;
276 // set current spells as deletable
277 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
279 if (m_currentSpells
[i
])
281 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
282 m_currentSpells
[i
] = NULL
;
289 // those should be already removed at "RemoveFromWorld()" call
290 assert(m_gameObj
.size() == 0);
291 assert(m_dynObjGUIDs
.size() == 0);
292 assert(m_deletedAuras
.size() == 0);
295 void Unit::Update( uint32 p_time
)
300 /*if(p_time > m_AurasCheck)
305 m_AurasCheck -= p_time;*/
307 // WARNING! Order of execution here is important, do not change.
308 // Spells must be processed with event system BEFORE they go to _UpdateSpells.
309 // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
310 m_Events
.Update( p_time
);
311 _UpdateSpells( p_time
);
313 CleanupDeletedAuras();
315 if (m_lastManaUseTimer
)
317 if (p_time
>= m_lastManaUseTimer
)
318 m_lastManaUseTimer
= 0;
320 m_lastManaUseTimer
-= p_time
;
323 if (CanHaveThreatList())
324 getThreatManager().UpdateForClient(p_time
);
326 // update combat timer only for players and pets
327 if (isInCombat() && (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet() || ((Creature
*)this)->isCharmed()))
329 // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away
330 // targets without stopping half way there and running off.
331 // These flags are reset after target dies or another command is given.
332 if (m_HostileRefManager
.isEmpty())
334 // m_CombatTimer set at aura start and it will be freeze until aura removing
335 if (m_CombatTimer
<= p_time
)
338 m_CombatTimer
-= p_time
;
342 if (uint32 base_att
= getAttackTimer(BASE_ATTACK
))
344 setAttackTimer(BASE_ATTACK
, (p_time
>= base_att
? 0 : base_att
- p_time
) );
347 // update abilities available only for fraction of time
348 UpdateReactives( p_time
);
350 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, GetHealth() < GetMaxHealth()*0.20f
);
351 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, GetHealth() < GetMaxHealth()*0.35f
);
352 ModifyAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT
, GetHealth() > GetMaxHealth()*0.75f
);
354 i_motionMaster
.UpdateMotion(p_time
);
357 bool Unit::haveOffhandWeapon() const
359 if(GetTypeId() == TYPEID_PLAYER
)
360 return ((Player
*)this)->GetWeaponForAttack(OFF_ATTACK
,true,true);
365 void Unit::SendMonsterMove(float NewPosX
, float NewPosY
, float NewPosZ
, uint8 type
, MonsterMovementFlags flags
, uint32 Time
, Player
* player
)
367 float moveTime
= Time
;
369 WorldPacket
data( SMSG_MONSTER_MOVE
, (41 + GetPackGUID().size()) );
370 data
.append(GetPackGUID());
371 data
<< uint8(0); // new in 3.1
372 data
<< GetPositionX() << GetPositionY() << GetPositionZ();
373 data
<< uint32(getMSTime());
375 data
<< uint8(type
); // unknown
378 case 0: // normal packet
380 case 1: // stop packet (raw pos?)
381 SendMessageToSet( &data
, true );
383 case 2: // facing spot, not used currently
388 case 3: // not used currently
389 data
<< uint64(0); // probably target guid (facing target?)
391 case 4: // not used currently
392 data
<< float(0); // facing angle
396 data
<< uint32(flags
);
398 if(flags
& MONSTER_MOVE_WALK
)
401 data
<< uint32(moveTime
); // Time in between points
402 data
<< uint32(1); // 1 single waypoint
403 data
<< NewPosX
<< NewPosY
<< NewPosZ
; // the single waypoint Point B
406 player
->GetSession()->SendPacket(&data
);
408 SendMessageToSet( &data
, true );
411 void Unit::SendMonsterMoveByPath(Path
const& path
, uint32 start
, uint32 end
, MonsterMovementFlags flags
)
413 uint32 traveltime
= uint32(path
.GetTotalLength(start
, end
) * 32);
415 uint32 pathSize
= end
- start
;
417 WorldPacket
data( SMSG_MONSTER_MOVE
, (GetPackGUID().size()+1+4+4+4+4+1+4+4+4+pathSize
*4*3) );
418 data
.append(GetPackGUID());
420 data
<< GetPositionX();
421 data
<< GetPositionY();
422 data
<< GetPositionZ();
423 data
<< uint32(getMSTime());
425 data
<< uint32(flags
);
426 data
<< uint32(traveltime
);
427 data
<< uint32(pathSize
);
428 data
.append((char*)path
.GetNodes(start
), pathSize
* 4 * 3);
429 SendMessageToSet(&data
, true);
432 void Unit::BuildHeartBeatMsg(WorldPacket
*data
) const
434 MovementFlags move_flags
= GetTypeId()==TYPEID_PLAYER
435 ? ((Player
const*)this)->m_movementInfo
.GetMovementFlags()
438 data
->Initialize(MSG_MOVE_HEARTBEAT
, 32);
439 data
->append(GetPackGUID());
440 *data
<< uint32(move_flags
); // movement flags
441 *data
<< uint16(0); // 2.3.0
442 *data
<< uint32(getMSTime()); // time
443 *data
<< float(GetPositionX());
444 *data
<< float(GetPositionY());
445 *data
<< float(GetPositionZ());
446 *data
<< float(GetOrientation());
450 void Unit::resetAttackTimer(WeaponAttackType type
)
452 m_attackTimer
[type
] = uint32(GetAttackTime(type
) * m_modAttackSpeedPct
[type
]);
455 bool Unit::canReachWithAttack(Unit
*pVictim
) const
458 float reach
= GetFloatValue(UNIT_FIELD_COMBATREACH
);
461 return IsWithinDistInMap(pVictim
, reach
);
464 void Unit::RemoveSpellsCausingAura(AuraType auraType
)
466 if (auraType
>= TOTAL_AURAS
) return;
467 AuraList::const_iterator iter
, next
;
468 for (iter
= m_modAuras
[auraType
].begin(); iter
!= m_modAuras
[auraType
].end(); iter
= next
)
475 RemoveAurasDueToSpell((*iter
)->GetId());
476 if (!m_modAuras
[auraType
].empty())
477 next
= m_modAuras
[auraType
].begin();
484 bool Unit::HasAuraType(AuraType auraType
) const
486 return (!m_modAuras
[auraType
].empty());
489 /* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */
490 void Unit::RemoveSpellbyDamageTaken(AuraType auraType
, uint32 damage
)
492 if(!HasAuraType(auraType
))
495 // The chance to dispel an aura depends on the damage taken with respect to the casters level.
496 uint32 max_dmg
= getLevel() > 8 ? 25 * getLevel() - 150 : 50;
497 float chance
= float(damage
) / max_dmg
* 100.0f
;
498 if (roll_chance_f(chance
))
499 RemoveSpellsCausingAura(auraType
);
502 void Unit::DealDamageMods(Unit
*pVictim
, uint32
&damage
, uint32
* absorb
)
504 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
512 //You don't lose health from damage taken from another player while in a sanctuary
513 //You still see it in the combat log though
514 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
516 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
517 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) //sanctuary
525 uint32 originalDamage
= damage
;
527 //Script Event damage Deal
528 if( GetTypeId()== TYPEID_UNIT
&& ((Creature
*)this)->AI())
529 ((Creature
*)this)->AI()->DamageDeal(pVictim
, damage
);
530 //Script Event damage taken
531 if( pVictim
->GetTypeId()== TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI() )
532 ((Creature
*)pVictim
)->AI()->DamageTaken(this, damage
);
534 if(absorb
&& originalDamage
> damage
)
535 absorb
+= (originalDamage
- damage
);
538 uint32
Unit::DealDamage(Unit
*pVictim
, uint32 damage
, CleanDamage
const* cleanDamage
, DamageEffectType damagetype
, SpellSchoolMask damageSchoolMask
, SpellEntry
const *spellProto
, bool durabilityLoss
)
540 // remove affects from victim (including from 0 damage and DoTs)
542 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
544 // remove affects from attacker at any non-DoT damage (including 0 damage)
545 if( damagetype
!= DOT
)
547 RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
548 RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
551 RemoveSpellsCausingAura(SPELL_AURA_MOD_INVISIBILITY
);
553 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->IsStandState() && !pVictim
->hasUnitState(UNIT_STAT_STUNNED
))
554 pVictim
->SetStandState(UNIT_STAND_STATE_STAND
);
559 // Rage from physical damage received .
560 if(cleanDamage
&& cleanDamage
->damage
&& (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
) && pVictim
->GetTypeId() == TYPEID_PLAYER
&& (pVictim
->getPowerType() == POWER_RAGE
))
561 ((Player
*)pVictim
)->RewardRage(cleanDamage
->damage
, 0, false);
565 if (!spellProto
|| !IsSpellHaveAura(spellProto
,SPELL_AURA_MOD_FEAR
))
566 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_FEAR
, damage
);
567 // root type spells do not dispel the root effect
568 if (!spellProto
|| !(spellProto
->Mechanic
== MECHANIC_ROOT
|| IsSpellHaveAura(spellProto
,SPELL_AURA_MOD_ROOT
)))
569 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_ROOT
, damage
);
571 // no xp,health if type 8 /critters/
572 if(pVictim
->GetTypeId() != TYPEID_PLAYER
&& pVictim
->GetCreatureType() == CREATURE_TYPE_CRITTER
)
574 pVictim
->setDeathState(JUST_DIED
);
575 pVictim
->SetHealth(0);
577 // allow loot only if has loot_id in creature_template
578 CreatureInfo
const* cInfo
= ((Creature
*)pVictim
)->GetCreatureInfo();
579 if(cInfo
&& cInfo
->lootid
)
580 pVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
582 // some critters required for quests (need normal entry instead possible heroic in any cases)
583 if(GetTypeId() == TYPEID_PLAYER
)
584 if(CreatureInfo
const* normalInfo
= ObjectMgr::GetCreatureTemplate(pVictim
->GetEntry()))
585 ((Player
*)this)->KilledMonster(normalInfo
,pVictim
->GetGUID());
590 DEBUG_LOG("DealDamageStart");
592 uint32 health
= pVictim
->GetHealth();
593 sLog
.outDetail("deal dmg:%d to health:%d ",damage
,health
);
595 // duel ends when player has 1 or less hp
596 bool duel_hasEnded
= false;
597 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->duel
&& damage
>= (health
-1))
599 // prevent kill only if killed in duel and killed by opponent or opponent controlled creature
600 if(((Player
*)pVictim
)->duel
->opponent
==this || ((Player
*)pVictim
)->duel
->opponent
->GetGUID() == GetOwnerGUID())
603 duel_hasEnded
= true;
606 if(pVictim
!= this && damagetype
!= DOT
)
608 SetInCombatWith(pVictim
);
609 pVictim
->SetInCombatWith(this);
611 if(Player
* attackedPlayer
= pVictim
->GetCharmerOrOwnerPlayerOrPlayerItself())
612 SetContestedPvP(attackedPlayer
);
615 // Rage from Damage made (only from direct weapon damage)
616 if( cleanDamage
&& damagetype
==DIRECT_DAMAGE
&& this != pVictim
&& GetTypeId() == TYPEID_PLAYER
&& (getPowerType() == POWER_RAGE
))
618 uint32 weaponSpeedHitFactor
;
620 switch(cleanDamage
->attackType
)
624 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
625 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 7);
627 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
629 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
635 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
636 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
638 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 1.75f
);
640 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
649 if (GetTypeId() == TYPEID_PLAYER
&& this != pVictim
)
651 Player
*killer
= ((Player
*)this);
653 // in bg, count dmg if victim is also a player
654 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
656 if (BattleGround
*bg
= killer
->GetBattleGround())
658 // FIXME: kept by compatibility. don't know in BG if the restriction apply.
659 bg
->UpdatePlayerScore(killer
, SCORE_DAMAGE_DONE
, damage
);
663 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DAMAGE_DONE
, damage
, 0, pVictim
);
664 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_DEALT
, damage
);
667 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
668 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_RECEIVED
, damage
);
670 if (pVictim
->GetTypeId() == TYPEID_UNIT
&& !((Creature
*)pVictim
)->isPet() && !((Creature
*)pVictim
)->hasLootRecipient())
671 ((Creature
*)pVictim
)->SetLootRecipient(this);
673 if (health
<= damage
)
675 DEBUG_LOG("DealDamage: victim just died");
677 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
678 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, health
);
680 // find player: owner of controlled `this` or `this` itself maybe
681 Player
*player
= GetCharmerOrOwnerPlayerOrPlayerItself();
683 if(pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->GetLootRecipient())
684 player
= ((Creature
*)pVictim
)->GetLootRecipient();
685 // Reward player, his pets, and group/raid members
686 // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop)
687 if(player
&& player
!=pVictim
)
689 player
->RewardPlayerAndGroupAtKill(pVictim
);
690 player
->ProcDamageAndSpell(pVictim
, PROC_FLAG_KILL
, PROC_FLAG_KILLED
, PROC_EX_NONE
, 0);
692 WorldPacket
data(SMSG_PARTYKILLLOG
, (8+8)); //send event PARTY_KILL
693 data
<< uint64(player
->GetGUID()); //player with killing blow
694 data
<< uint64(pVictim
->GetGUID()); //victim
695 if (Group
*group
= player
->GetGroup())
696 group
->BroadcastPacket(&data
, group
->GetMemberGroup(player
->GetGUID()));
698 player
->SendDirectMessage(&data
);
701 DEBUG_LOG("DealDamageAttackStop");
704 pVictim
->CombatStop();
705 pVictim
->getHostileRefManager().deleteReferences();
707 bool damageFromSpiritOfRedemtionTalent
= spellProto
&& spellProto
->Id
== 27795;
709 // if talent known but not triggered (check priest class for speedup check)
710 Aura
* spiritOfRedemtionTalentReady
= NULL
;
711 if( !damageFromSpiritOfRedemtionTalent
&& // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION
712 pVictim
->GetTypeId()==TYPEID_PLAYER
&& pVictim
->getClass()==CLASS_PRIEST
)
714 AuraList
const& vDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
715 for(AuraList::const_iterator itr
= vDummyAuras
.begin(); itr
!= vDummyAuras
.end(); ++itr
)
717 if((*itr
)->GetSpellProto()->SpellIconID
==1654)
719 spiritOfRedemtionTalentReady
= *itr
;
725 DEBUG_LOG("SET JUST_DIED");
726 if(!spiritOfRedemtionTalentReady
)
727 pVictim
->setDeathState(JUST_DIED
);
729 DEBUG_LOG("DealDamageHealth1");
731 if(spiritOfRedemtionTalentReady
)
733 // save value before aura remove
734 uint32 ressSpellId
= pVictim
->GetUInt32Value(PLAYER_SELF_RES_SPELL
);
736 ressSpellId
= ((Player
*)pVictim
)->GetResurrectionSpellId();
738 //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers)
739 pVictim
->RemoveAllAurasOnDeath();
741 // restore for use at real death
742 pVictim
->SetUInt32Value(PLAYER_SELF_RES_SPELL
,ressSpellId
);
744 // FORM_SPIRITOFREDEMPTION and related auras
745 pVictim
->CastSpell(pVictim
,27827,true,NULL
,spiritOfRedemtionTalentReady
);
748 pVictim
->SetHealth(0);
750 // remember victim PvP death for corpse type and corpse reclaim delay
751 // at original death (not at SpiritOfRedemtionTalent timeout)
752 if( pVictim
->GetTypeId()==TYPEID_PLAYER
&& !damageFromSpiritOfRedemtionTalent
)
753 ((Player
*)pVictim
)->SetPvPDeath(player
!=NULL
);
755 // Call KilledUnit for creatures
756 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->AI())
757 ((Creature
*)this)->AI()->KilledUnit(pVictim
);
760 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
762 if (GetTypeId() == TYPEID_UNIT
)
763 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE
, GetEntry());
764 else if(GetTypeId() == TYPEID_PLAYER
&& pVictim
!= this)
765 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER
, 1, ((Player
*)this)->GetTeam());
768 // 10% durability loss on death
769 // clean InHateListOf
770 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
772 // only if not player and not controlled by player pet. And not at BG
773 if (durabilityLoss
&& !player
&& !((Player
*)pVictim
)->InBattleGround())
775 DEBUG_LOG("We are dead, loosing 10 percents durability");
776 ((Player
*)pVictim
)->DurabilityLossAll(0.10f
,false);
777 // durability lost message
778 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
779 ((Player
*)pVictim
)->GetSession()->SendPacket(&data
);
782 else // creature died
784 DEBUG_LOG("DealDamageNotPlayer");
785 Creature
*cVictim
= (Creature
*)pVictim
;
787 if(!cVictim
->isPet())
789 cVictim
->DeleteThreatList();
790 // only lootable if it has loot or can drop gold
791 if(cVictim
->GetCreatureInfo()->lootid
|| cVictim
->GetCreatureInfo()->maxgold
> 0)
792 cVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
794 cVictim
->lootForBody
= true; // needed for skinning
796 // Call creature just died function
798 cVictim
->AI()->JustDied(this);
800 if (cVictim
->isTemporarySummon())
802 TemporarySummon
* pSummon
= (TemporarySummon
*)cVictim
;
803 if (IS_CREATURE_GUID(pSummon
->GetSummonerGUID()))
804 if(Creature
* pSummoner
= cVictim
->GetMap()->GetCreature(pSummon
->GetSummonerGUID()))
806 pSummoner
->AI()->SummonedCreatureJustDied(cVictim
);
810 // Dungeon specific stuff, only applies to players killing creatures
811 if(cVictim
->GetInstanceId())
813 Map
*m
= cVictim
->GetMap();
814 Player
*creditedPlayer
= GetCharmerOrOwnerPlayerOrPlayerItself();
815 // TODO: do instance binding anyway if the charmer/owner is offline
817 if(m
->IsDungeon() && creditedPlayer
)
819 if (m
->IsRaidOrHeroicDungeon())
821 if(cVictim
->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
822 ((InstanceMap
*)m
)->PermBindAllPlayers(creditedPlayer
);
826 // the reset time is set but not added to the scheduler
827 // until the players leave the instance
828 time_t resettime
= cVictim
->GetRespawnTimeEx() + 2 * HOUR
;
829 if(InstanceSave
*save
= sInstanceSaveMgr
.GetInstanceSave(cVictim
->GetInstanceId()))
830 if(save
->GetResetTime() < resettime
) save
->SetResetTime(resettime
);
836 // last damage from non duel opponent or opponent controlled creature
839 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
840 Player
*he
= (Player
*)pVictim
;
844 he
->duel
->opponent
->CombatStopWithPets(true);
845 he
->CombatStopWithPets(true);
847 he
->DuelComplete(DUEL_INTERUPTED
);
850 // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill)
851 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->InBattleGround())
853 Player
*killed
= ((Player
*)pVictim
);
854 if(BattleGround
*bg
= killed
->GetBattleGround())
856 bg
->HandleKillPlayer(killed
, player
);
858 else if(pVictim
->GetTypeId() == TYPEID_UNIT
)
861 if (BattleGround
*bg
= player
->GetBattleGround())
862 bg
->HandleKillUnit((Creature
*)pVictim
, player
);
865 else // if (health <= damage)
867 DEBUG_LOG("DealDamageAlive");
869 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
870 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, damage
);
872 pVictim
->ModifyHealth(- (int32
)damage
);
874 if(damagetype
!= DOT
)
878 // if not have main target then attack state with target (including AI call)
879 //start melee attacks only after melee hit
880 Attack(pVictim
,(damagetype
== DIRECT_DAMAGE
));
883 // if damage pVictim call AI reaction
884 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
885 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
888 // polymorphed, hex and other negative transformed cases
889 uint32 morphSpell
= pVictim
->getTransForm();
890 if (morphSpell
&& !IsPositiveSpell(morphSpell
))
892 if (SpellEntry
const* morphEntry
= sSpellStore
.LookupEntry(morphSpell
))
894 if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_CONFUSE
))
895 pVictim
->RemoveAurasDueToSpell(morphSpell
);
896 else if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_PACIFY_SILENCE
))
897 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_PACIFY_SILENCE
, damage
);
901 if(damagetype
== DIRECT_DAMAGE
|| damagetype
== SPELL_DIRECT_DAMAGE
)
903 if (!spellProto
|| !(spellProto
->AuraInterruptFlags
&AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
))
904 pVictim
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
);
906 if (pVictim
->GetTypeId() != TYPEID_PLAYER
)
908 if(spellProto
&& IsDamageToThreatSpell(spellProto
))
909 pVictim
->AddThreat(this, damage
*2, (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
911 pVictim
->AddThreat(this, damage
, (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
913 else // victim is a player
915 // Rage from damage received
916 if(this != pVictim
&& pVictim
->getPowerType() == POWER_RAGE
)
918 uint32 rage_damage
= damage
+ (cleanDamage
? cleanDamage
->damage
: 0);
919 ((Player
*)pVictim
)->RewardRage(rage_damage
, 0, false);
922 // random durability for items (HIT TAKEN)
923 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
925 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
926 ((Player
*)pVictim
)->DurabilityPointLossForEquipSlot(slot
);
930 if(GetTypeId()==TYPEID_PLAYER
)
932 // random durability for items (HIT DONE)
933 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
935 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
936 ((Player
*)this)->DurabilityPointLossForEquipSlot(slot
);
940 // TODO: Store auras by interrupt flag to speed this up.
941 AuraMap
& vAuras
= pVictim
->GetAuras();
942 for (AuraMap::const_iterator i
= vAuras
.begin(), next
; i
!= vAuras
.end(); i
= next
)
944 const SpellEntry
*se
= i
->second
->GetSpellProto();
946 if (spellProto
&& spellProto
->Id
== se
->Id
) // Not drop auras added by self
948 if( se
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_DAMAGE
)
951 if (se
->procFlags
& (1<<3))
953 if (!roll_chance_i(se
->procChance
))
958 pVictim
->RemoveAurasDueToSpell(i
->second
->GetId());
959 // FIXME: this may cause the auras with proc chance to be rerolled several times
960 next
= vAuras
.begin();
965 if (damagetype
!= NODAMAGE
&& damage
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
967 if( damagetype
!= DOT
)
969 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
971 // skip channeled spell (processed differently below)
972 if (i
== CURRENT_CHANNELED_SPELL
)
975 if(Spell
* spell
= pVictim
->GetCurrentSpell(CurrentSpellTypes(i
)))
977 if(spell
->getState() == SPELL_STATE_PREPARING
)
979 if(spell
->m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_ABORT_ON_DMG
)
980 pVictim
->InterruptSpell(CurrentSpellTypes(i
));
988 if(Spell
* spell
= pVictim
->m_currentSpells
[CURRENT_CHANNELED_SPELL
])
990 if (spell
->getState() == SPELL_STATE_CASTING
)
992 uint32 channelInterruptFlags
= spell
->m_spellInfo
->ChannelInterruptFlags
;
993 if( channelInterruptFlags
& CHANNEL_FLAG_DELAY
)
995 if(pVictim
!=this) //don't shorten the duration of channeling if you damage yourself
996 spell
->DelayedChannel();
998 else if( (channelInterruptFlags
& (CHANNEL_FLAG_DAMAGE
| CHANNEL_FLAG_DAMAGE2
)) )
1000 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
1001 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
1004 else if (spell
->getState() == SPELL_STATE_DELAYED
)
1005 // break channeled spell in delayed state on damage
1007 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
1008 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
1013 // last damage from duel opponent
1016 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
1017 Player
*he
= (Player
*)pVictim
;
1023 he
->duel
->opponent
->CombatStopWithPets(true);
1024 he
->CombatStopWithPets(true);
1026 he
->CastSpell(he
, 7267, true); // beg
1027 he
->DuelComplete(DUEL_WON
);
1031 DEBUG_LOG("DealDamageEnd returned %d damage", damage
);
1036 void Unit::CastStop(uint32 except_spellid
)
1038 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
1039 if (m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
!=except_spellid
)
1040 InterruptSpell(CurrentSpellTypes(i
),false);
1043 void Unit::CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1045 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1049 sLog
.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId
,(GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
1053 CastSpell(Victim
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
1056 void Unit::CastSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1060 sLog
.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
1065 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1067 if(!originalCaster
&& triggeredByAura
)
1068 originalCaster
= triggeredByAura
->GetCasterGUID();
1070 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1072 SpellCastTargets targets
;
1073 targets
.setUnitTarget( Victim
);
1074 spell
->m_CastItem
= castItem
;
1075 spell
->prepare(&targets
, triggeredByAura
);
1078 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1080 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1084 sLog
.outError("CastCustomSpell: unknown spell id %i", spellId
);
1088 CastCustomSpell(Victim
,spellInfo
,bp0
,bp1
,bp2
,triggered
,castItem
,triggeredByAura
, originalCaster
);
1091 void Unit::CastCustomSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1095 sLog
.outError("CastCustomSpell: unknown spell");
1100 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1102 if(!originalCaster
&& triggeredByAura
)
1103 originalCaster
= triggeredByAura
->GetCasterGUID();
1105 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1108 spell
->m_currentBasePoints
[0] = *bp0
-int32(spellInfo
->EffectBaseDice
[0]);
1111 spell
->m_currentBasePoints
[1] = *bp1
-int32(spellInfo
->EffectBaseDice
[1]);
1114 spell
->m_currentBasePoints
[2] = *bp2
-int32(spellInfo
->EffectBaseDice
[2]);
1116 SpellCastTargets targets
;
1117 targets
.setUnitTarget( Victim
);
1118 spell
->m_CastItem
= castItem
;
1119 spell
->prepare(&targets
, triggeredByAura
);
1122 // used for scripting
1123 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1125 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1129 sLog
.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s %u)", spellId
,(GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
1133 CastSpell(x
, y
, z
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
1136 // used for scripting
1137 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1141 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
1146 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1148 if(!originalCaster
&& triggeredByAura
)
1149 originalCaster
= triggeredByAura
->GetCasterGUID();
1151 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1153 SpellCastTargets targets
;
1154 targets
.setDestination(x
, y
, z
);
1155 spell
->m_CastItem
= castItem
;
1156 spell
->prepare(&targets
, triggeredByAura
);
1159 // Obsolete func need remove, here only for comotability vs another patches
1160 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
)
1162 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
1163 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, spellInfo
->SchoolMask
);
1164 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
1165 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
1166 SendSpellNonMeleeDamageLog(&damageInfo
);
1167 DealSpellDamage(&damageInfo
, true);
1168 return damageInfo
.damage
;
1171 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
1173 SpellSchoolMask damageSchoolMask
= SpellSchoolMask(damageInfo
->schoolMask
);
1174 Unit
*pVictim
= damageInfo
->target
;
1179 if(!this || !pVictim
)
1181 if(!this->isAlive() || !pVictim
->isAlive())
1184 uint32 crTypeMask
= pVictim
->GetCreatureTypeMask();
1185 // Check spell crit chance
1186 bool crit
= isSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
1187 bool blocked
= false;
1189 // damage bonus (per damage class)
1190 switch (spellInfo
->DmgClass
)
1192 // Melee and Ranged Spells
1193 case SPELL_DAMAGE_CLASS_RANGED
:
1194 case SPELL_DAMAGE_CLASS_MELEE
:
1196 //Calculate damage bonus
1197 damage
= MeleeDamageBonus(pVictim
, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1198 // Get blocked status
1199 blocked
= isSpellBlocked(pVictim
, spellInfo
, attackType
);
1201 // if crit add critical bonus
1204 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1205 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1206 // Resilience - reduce crit damage
1207 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1208 if (attackType
!= RANGED_ATTACK
)
1209 damage
-= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1211 damage
-= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1216 case SPELL_DAMAGE_CLASS_NONE
:
1217 case SPELL_DAMAGE_CLASS_MAGIC
:
1219 // Calculate damage bonus
1220 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1221 // If crit add critical bonus
1224 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1225 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1226 // Resilience - reduce crit damage
1227 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1228 damage
-= pVictim
->GetSpellCritDamageReduction(redunction_affected_damage
);
1234 // only from players
1235 if (GetTypeId() == TYPEID_PLAYER
)
1237 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1238 damage
-= pVictim
->GetSpellDamageReduction(redunction_affected_damage
);
1241 // damage mitigation
1244 // physical damage => armor
1245 if (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
1247 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1248 damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(pVictim
, armor_affected_damage
);
1251 // block (only for damage class ranged and -melee, also non-physical damage possible)
1254 damageInfo
->blocked
= uint32(pVictim
->GetShieldBlockValue());
1255 if (damage
< damageInfo
->blocked
)
1256 damageInfo
->blocked
= damage
;
1257 damage
-=damageInfo
->blocked
;
1260 uint32 absorb_affected_damage
= CalcNotIgnoreAbsorbDamage(damage
,damageSchoolMask
,spellInfo
);
1261 CalcAbsorbResist(pVictim
, damageSchoolMask
, SPELL_DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, !(spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
));
1262 damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
1266 damageInfo
->damage
= damage
;
1269 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1274 Unit
*pVictim
= damageInfo
->target
;
1276 if(!this || !pVictim
)
1279 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1282 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1283 if (spellProto
== NULL
)
1285 sLog
.outDebug("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1289 //You don't lose health from damage taken from another player while in a sanctuary
1290 //You still see it in the combat log though
1291 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1293 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1294 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1298 // Call default DealDamage (send critical in hit info for threat calculation)
1299 CleanDamage
cleanDamage(damageInfo
->cleanDamage
, BASE_ATTACK
, damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
? MELEE_HIT_CRIT
: MELEE_HIT_NORMAL
);
1300 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->schoolMask
), spellProto
, durabilityLoss
);
1303 //TODO for melee need create structure as in
1304 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1306 damageInfo
->attacker
= this;
1307 damageInfo
->target
= pVictim
;
1308 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1309 damageInfo
->attackType
= attackType
;
1310 damageInfo
->damage
= 0;
1311 damageInfo
->cleanDamage
= 0;
1312 damageInfo
->absorb
= 0;
1313 damageInfo
->resist
= 0;
1314 damageInfo
->blocked_amount
= 0;
1316 damageInfo
->TargetState
= 0;
1317 damageInfo
->HitInfo
= 0;
1318 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1319 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1320 damageInfo
->procEx
= PROC_EX_NONE
;
1321 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1323 if(!this || !pVictim
)
1325 if(!this->isAlive() || !pVictim
->isAlive())
1328 // Select HitInfo/procAttacker/procVictim flag based on attack type
1332 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
;
1333 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1334 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1337 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1338 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1339 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1342 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1343 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1344 damageInfo
->HitInfo
= 0x08;// test
1350 // Physical Immune check
1351 if (damageInfo
->target
->IsImmunedToDamage(damageInfo
->damageSchoolMask
))
1353 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1354 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1356 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1357 damageInfo
->damage
= 0;
1358 damageInfo
->cleanDamage
= 0;
1361 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1362 // Add melee damage bonus
1363 damage
= MeleeDamageBonus(damageInfo
->target
, damage
, damageInfo
->attackType
);
1364 // Calculate armor reduction
1366 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageInfo
->damageSchoolMask
);
1367 damageInfo
->damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(damageInfo
->target
, armor_affected_damage
);
1368 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1370 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1372 // Disable parry or dodge for ranged attack
1373 if (damageInfo
->attackType
== RANGED_ATTACK
)
1375 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1376 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1379 switch(damageInfo
->hitOutCome
)
1381 case MELEE_HIT_EVADE
:
1383 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1384 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1386 damageInfo
->procEx
|=PROC_EX_EVADE
;
1387 damageInfo
->damage
= 0;
1388 damageInfo
->cleanDamage
= 0;
1391 case MELEE_HIT_MISS
:
1393 damageInfo
->HitInfo
|= HITINFO_MISS
;
1394 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1396 damageInfo
->procEx
|=PROC_EX_MISS
;
1397 damageInfo
->damage
= 0;
1398 damageInfo
->cleanDamage
= 0;
1401 case MELEE_HIT_NORMAL
:
1402 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1403 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1405 case MELEE_HIT_CRIT
:
1407 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1408 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1410 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1412 damageInfo
->damage
+= damageInfo
->damage
;
1414 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1415 if(damageInfo
->attackType
== RANGED_ATTACK
)
1416 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1418 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1420 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, SPELL_SCHOOL_MASK_NORMAL
);
1422 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1424 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1425 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1427 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1429 // Resilience - reduce crit damage
1430 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1431 uint32 resilienceReduction
;
1432 if (attackType
!= RANGED_ATTACK
)
1433 resilienceReduction
= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1435 resilienceReduction
= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1437 damageInfo
->damage
-= resilienceReduction
;
1438 damageInfo
->cleanDamage
+= resilienceReduction
;
1441 case MELEE_HIT_PARRY
:
1442 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1443 damageInfo
->procEx
|= PROC_EX_PARRY
;
1444 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1445 damageInfo
->damage
= 0;
1448 case MELEE_HIT_DODGE
:
1449 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1450 damageInfo
->procEx
|=PROC_EX_DODGE
;
1451 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1452 damageInfo
->damage
= 0;
1454 case MELEE_HIT_BLOCK
:
1456 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1457 damageInfo
->HitInfo
|= HITINFO_BLOCK
;
1458 damageInfo
->procEx
|= PROC_EX_BLOCK
;
1459 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1460 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1462 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1463 damageInfo
->blocked_amount
= damageInfo
->damage
;
1464 damageInfo
->procEx
|= PROC_EX_FULL_BLOCK
;
1466 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1467 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1470 case MELEE_HIT_GLANCING
:
1472 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1473 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1474 damageInfo
->procEx
|= PROC_EX_NORMAL_HIT
;
1475 float reducePercent
= 1.0f
; //damage factor
1476 // calculate base values and mods
1477 float baseLowEnd
= 1.3f
;
1478 float baseHighEnd
= 1.2f
;
1479 switch(getClass()) // lowering base values for casters
1487 baseHighEnd
-= 0.3f
;
1491 float maxLowEnd
= 0.6f
;
1492 switch(getClass()) // upper for melee classes
1496 maxLowEnd
= 0.91f
; //If the attacker is a melee class then instead the lower value of 0.91
1500 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1501 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1502 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1504 // apply max/min bounds
1505 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1507 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1510 if ( highEnd
< 0.2f
) //high end limits
1512 if ( highEnd
> 0.99f
)
1515 if(lowEnd
> highEnd
) // prevent negative range size
1518 reducePercent
= lowEnd
+ rand_norm() * ( highEnd
- lowEnd
);
1520 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1521 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1524 case MELEE_HIT_CRUSHING
:
1526 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1527 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1528 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1529 // 150% normal damage
1530 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1538 // only from players
1539 if (GetTypeId() == TYPEID_PLAYER
)
1541 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageInfo
->damageSchoolMask
);
1542 if (attackType
!= RANGED_ATTACK
)
1543 damage
-= pVictim
->GetMeleeDamageReduction(redunction_affected_damage
);
1545 damage
-= pVictim
->GetRangedDamageReduction(redunction_affected_damage
);
1548 // Calculate absorb resist
1549 if(int32(damageInfo
->damage
) > 0)
1551 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1553 // Calculate absorb & resists
1554 uint32 absorb_affected_damage
= CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1555 CalcAbsorbResist(damageInfo
->target
, damageInfo
->damageSchoolMask
, DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, true);
1556 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1557 if (damageInfo
->absorb
)
1559 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1560 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1562 if (damageInfo
->resist
)
1563 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1566 else // Umpossible get negative result but....
1567 damageInfo
->damage
= 0;
1570 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1572 if (damageInfo
==0) return;
1573 Unit
*pVictim
= damageInfo
->target
;
1575 if(!this || !pVictim
)
1578 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1581 //You don't lose health from damage taken from another player while in a sanctuary
1582 //You still see it in the combat log though
1583 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1585 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1586 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1590 // Hmmmm dont like this emotes client must by self do all animations
1591 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1592 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1593 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1594 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1596 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1598 // Get attack timers
1599 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1600 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1601 // Reduce attack time
1602 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1604 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20f
;
1605 float percent60
= 3.0f
* percent20
;
1606 if(offtime
> percent20
&& offtime
<= percent60
)
1608 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1610 else if(offtime
> percent60
)
1612 offtime
-= 2.0f
* percent20
;
1613 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1618 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20;
1619 float percent60
= 3.0f
* percent20
;
1620 if(basetime
> percent20
&& basetime
<= percent60
)
1622 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1624 else if(basetime
> percent60
)
1626 basetime
-= 2.0f
* percent20
;
1627 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1632 // Call default DealDamage
1633 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1634 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, damageInfo
->damageSchoolMask
, NULL
, durabilityLoss
);
1636 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1637 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1638 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI
, this) )
1640 // -probability is between 0% and 40%
1642 float Probability
= 20.0f
;
1644 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1645 if( pVictim
->getLevel() < 30 )
1646 Probability
= 0.65f
*pVictim
->getLevel()+0.5f
;
1648 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1649 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1651 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1653 if(Probability
> 40.0f
)
1654 Probability
= 40.0f
;
1656 if(roll_chance_f(Probability
))
1657 CastSpell(pVictim
, 1604, true);
1661 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1663 // on weapon hit casts
1664 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1665 ((Player
*)this)->CastItemCombatSpell(pVictim
, damageInfo
->attackType
);
1667 // victim's damage shield
1668 std::set
<Aura
*> alreadyDone
;
1669 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1670 for(AuraList::const_iterator i
= vDamageShields
.begin(); i
!= vDamageShields
.end();)
1672 if (alreadyDone
.find(*i
) == alreadyDone
.end())
1674 alreadyDone
.insert(*i
);
1675 uint32 damage
=(*i
)->GetModifier()->m_amount
;
1676 SpellEntry
const *i_spellProto
= (*i
)->GetSpellProto();
1677 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
1680 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1681 //damage-=absorb + resist;
1683 pVictim
->DealDamageMods(this,damage
,NULL
);
1685 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4+4+4));
1686 data
<< uint64(pVictim
->GetGUID());
1687 data
<< uint64(GetGUID());
1688 data
<< uint32(i_spellProto
->Id
);
1689 data
<< uint32(damage
); // Damage
1690 data
<< uint32(0); // Overkill
1691 data
<< uint32(i_spellProto
->SchoolMask
);
1692 pVictim
->SendMessageToSet(&data
, true );
1694 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(i_spellProto
), i_spellProto
, true);
1696 i
= vDamageShields
.begin();
1705 void Unit::HandleEmoteCommand(uint32 anim_id
)
1707 WorldPacket
data( SMSG_EMOTE
, 4 + 8 );
1708 data
<< uint32(anim_id
);
1709 data
<< uint64(GetGUID());
1710 SendMessageToSet(&data
, true);
1713 uint32
Unit::CalcNotIgnoreAbsorbDamage( uint32 damage
, SpellSchoolMask damageSchoolMask
, SpellEntry
const* spellInfo
/*= NULL*/)
1715 float absorb_affected_rate
= 1.0f
;
1716 Unit::AuraList
const& ignoreAbsorbSchool
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_SCHOOL
);
1717 for(Unit::AuraList::const_iterator i
= ignoreAbsorbSchool
.begin(); i
!= ignoreAbsorbSchool
.end(); ++i
)
1718 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1719 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1723 Unit::AuraList
const& ignoreAbsorbForSpell
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL
);
1724 for(Unit::AuraList::const_iterator citr
= ignoreAbsorbForSpell
.begin(); citr
!= ignoreAbsorbForSpell
.end(); ++citr
)
1725 if ((*citr
)->isAffectedOnSpell(spellInfo
))
1726 absorb_affected_rate
*= (100.0f
- (*citr
)->GetModifier()->m_amount
)/100.0f
;
1729 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1732 uint32
Unit::CalcNotIgnoreDamageRedunction( uint32 damage
, SpellSchoolMask damageSchoolMask
)
1734 float absorb_affected_rate
= 1.0f
;
1735 Unit::AuraList
const& ignoreAbsorb
= GetAurasByType(SPELL_AURA_MOD_IGNORE_DAMAGE_REDUCTION_SCHOOL
);
1736 for(Unit::AuraList::const_iterator i
= ignoreAbsorb
.begin(); i
!= ignoreAbsorb
.end(); ++i
)
1737 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1738 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1740 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1743 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
1745 uint32 newdamage
= 0;
1746 float armor
= pVictim
->GetArmor();
1748 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
1749 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
1751 // Apply Player CR_ARMOR_PENETRATION rating and percent talents
1752 if (GetTypeId()==TYPEID_PLAYER
)
1753 armor
*= 1.0f
- ((Player
*)this)->GetArmorPenetrationPct() / 100.0f
;
1758 float levelModifier
= getLevel();
1759 if (levelModifier
> 59)
1760 levelModifier
= levelModifier
+ (4.5f
* (levelModifier
-59));
1762 float tmpvalue
= 0.1f
* armor
/ (8.5f
* levelModifier
+ 40);
1763 tmpvalue
= tmpvalue
/(1.0f
+ tmpvalue
);
1765 if (tmpvalue
< 0.0f
)
1767 if (tmpvalue
> 0.75f
)
1770 newdamage
= uint32(damage
- (damage
* tmpvalue
));
1772 return (newdamage
> 1) ? newdamage
: 1;
1775 void Unit::CalcAbsorbResist(Unit
*pVictim
,SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
, bool canReflect
)
1777 if(!pVictim
|| !pVictim
->isAlive() || !damage
)
1780 // Magic damage, check for resists
1781 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
1783 // Get base victim resistance for school
1784 float tmpvalue2
= (float)pVictim
->GetResistance(GetFirstSchoolInMask(schoolMask
));
1785 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
1786 tmpvalue2
+= (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
1788 tmpvalue2
*= (float)(0.15f
/ getLevel());
1789 if (tmpvalue2
< 0.0f
)
1791 if (tmpvalue2
> 0.75f
)
1793 uint32 ran
= urand(0, 100);
1794 uint32 faq
[4] = {24,6,4,6};
1797 for (uint8 i
= 0; i
< 4; ++i
)
1799 Binom
+= 2400 *( powf(tmpvalue2
, i
) * powf( (1-tmpvalue2
), (4-i
)))/faq
[i
];
1805 if (damagetype
== DOT
&& m
== 4)
1806 *resist
+= uint32(damage
- 1);
1808 *resist
+= uint32(damage
* m
/ 4);
1809 if(*resist
> damage
)
1815 int32 RemainingDamage
= damage
- *resist
;
1817 // Get unit state (need for some absorb check)
1818 uint32 unitflag
= pVictim
->GetUInt32Value(UNIT_FIELD_FLAGS
);
1819 // Reflect damage spells (not cast any damage spell in aura lookup)
1820 uint32 reflectSpell
= 0;
1821 int32 reflectDamage
= 0;
1822 Aura
* reflectTriggeredBy
= NULL
; // expected as not expired at reflect as in current cases
1823 // Death Prevention Aura
1824 SpellEntry
const* preventDeathSpell
= NULL
;
1825 int32 preventDeathAmount
= 0;
1827 // full absorb cases (by chance)
1828 AuraList
const& vAbsorb
= pVictim
->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1829 for(AuraList::const_iterator i
= vAbsorb
.begin(); i
!= vAbsorb
.end() && RemainingDamage
> 0; ++i
)
1831 // only work with proper school mask damage
1832 Modifier
* i_mod
= (*i
)->GetModifier();
1833 if (!(i_mod
->m_miscvalue
& schoolMask
))
1836 SpellEntry
const* i_spellProto
= (*i
)->GetSpellProto();
1837 // Fire Ward or Frost Ward
1838 if(i_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& i_spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000108))
1841 Unit::AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_ADD_PCT_MODIFIER
);
1842 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
1844 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
1845 // Frost Warding (chance full absorb)
1846 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& itr_spellProto
->SpellIconID
== 501)
1848 // chance stored in next dummy effect
1849 chance
= itr_spellProto
->CalculateSimpleValue(1);
1853 if(roll_chance_i(chance
))
1855 int32 amount
= RemainingDamage
;
1856 RemainingDamage
= 0;
1857 // Frost Warding (mana regen)
1858 pVictim
->CastCustomSpell(pVictim
, 57776, &amount
, NULL
, NULL
, true, NULL
, *i
);
1864 // Need remove expired auras after
1865 bool existExpired
= false;
1867 // absorb without mana cost
1868 AuraList
const& vSchoolAbsorb
= pVictim
->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1869 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; ++i
)
1871 Modifier
* mod
= (*i
)->GetModifier();
1872 if (!(mod
->m_miscvalue
& schoolMask
))
1875 SpellEntry
const* spellProto
= (*i
)->GetSpellProto();
1877 // Max Amount can be absorbed by this aura
1878 int32 currentAbsorb
= mod
->m_amount
;
1880 // Found empty aura (impossible but..)
1881 if (currentAbsorb
<=0)
1883 existExpired
= true;
1886 // Handle custom absorb auras
1887 // TODO: try find better way
1888 switch(spellProto
->SpellFamilyName
)
1890 case SPELLFAMILY_GENERIC
:
1893 if (spellProto
->SpellIconID
== 3066)
1895 //reduces all damage taken while stun, fear or silence
1896 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1897 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1901 if (spellProto
->SpellIconID
== 2115)
1903 // while affected by Stun and Fear
1904 if (unitflag
&(UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
))
1905 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1909 if (spellProto
->SpellIconID
== 3006)
1911 // You have a chance equal to your Parry chance
1912 if (damagetype
== DIRECT_DAMAGE
&& // Only for direct damage
1913 roll_chance_f(pVictim
->GetUnitParryChance())) // Roll chance
1914 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1917 // Reflective Shield (Lady Malande boss)
1918 if (spellProto
->Id
== 41475 && canReflect
)
1920 if(RemainingDamage
< currentAbsorb
)
1921 reflectDamage
= RemainingDamage
/ 2;
1923 reflectDamage
= currentAbsorb
/ 2;
1924 reflectSpell
= 33619;
1925 reflectTriggeredBy
= *i
;
1928 if (spellProto
->Id
== 39228 || // Argussian Compass
1929 spellProto
->Id
== 60218) // Essence of Gossamer
1931 // Max absorb stored in 1 dummy effect
1932 if (spellProto
->EffectBasePoints
[1] < currentAbsorb
)
1933 currentAbsorb
= spellProto
->EffectBasePoints
[1];
1938 case SPELLFAMILY_DRUID
:
1941 if (spellProto
->SpellIconID
== 2253)
1943 //reduces all damage taken while Stunned
1944 if (unitflag
& UNIT_FLAG_STUNNED
)
1945 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1950 case SPELLFAMILY_ROGUE
:
1952 // Cheat Death (make less prio with Guardian Spirit case)
1953 if (!preventDeathSpell
&& spellProto
->SpellIconID
== 2109 &&
1954 pVictim
->GetTypeId()==TYPEID_PLAYER
&& // Only players
1955 !((Player
*)pVictim
)->HasSpellCooldown(31231) &&
1956 // Only if no cooldown
1957 roll_chance_i((*i
)->GetModifier()->m_amount
))
1960 preventDeathSpell
= (*i
)->GetSpellProto();
1965 case SPELLFAMILY_PRIEST
:
1968 if (spellProto
->SpellIconID
== 2873)
1970 preventDeathSpell
= (*i
)->GetSpellProto();
1971 preventDeathAmount
= (*i
)->GetModifier()->m_amount
;
1974 // Power Word: Shield
1975 if (spellProto
->SpellFamilyFlags
& UI64LIT(00000001) && spellProto
->Mechanic
== MECHANIC_SHIELD
)
1977 // Glyph of Power Word: Shield
1978 if (Aura
*glyph
= pVictim
->GetAura(55672,0))
1980 int32 heal
= int32(glyph
->GetModifier()->m_amount
*
1981 (RemainingDamage
>= currentAbsorb
? currentAbsorb
: RemainingDamage
) / 100);
1982 pVictim
->CastCustomSpell(pVictim
, 56160, &heal
, NULL
, NULL
, true, 0, *i
);
1985 // Reflective Shield
1986 if (spellProto
->SpellFamilyFlags
== 0x1 && canReflect
)
1988 if (pVictim
== this)
1990 Unit
* caster
= (*i
)->GetCaster();
1993 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
1994 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
1996 switch((*k
)->GetModifier()->m_miscvalue
)
1998 case 5065: // Rank 1
1999 case 5064: // Rank 2
2001 if(RemainingDamage
>= currentAbsorb
)
2002 reflectDamage
= (*k
)->GetModifier()->m_amount
* currentAbsorb
/100;
2004 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
2005 reflectSpell
= 33619;
2006 reflectTriggeredBy
= *i
;
2015 case SPELLFAMILY_SHAMAN
:
2018 if (spellProto
->SpellIconID
== 3066)
2020 //reduces all damage taken while stun, fear or silence
2021 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
2022 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2027 case SPELLFAMILY_DEATHKNIGHT
:
2030 if (spellProto
->SpellIconID
== 1958)
2032 // TODO: absorb only while transform
2035 // Anti-Magic Shell (on self)
2036 if (spellProto
->Id
== 48707)
2038 // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power.
2039 // This, if I'm not mistaken, shows that we get back ~2% of the absorbed damage as runic power.
2040 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
2041 int32 regen
= absorbed
* 2 / 10;
2042 pVictim
->CastCustomSpell(pVictim
, 49088, ®en
, NULL
, NULL
, true, NULL
, *i
);
2043 RemainingDamage
-= absorbed
;
2046 // Anti-Magic Shell (on single party/raid member)
2047 if (spellProto
->Id
== 50462)
2049 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2053 if (spellProto
->Id
== 50461)
2055 Unit
* caster
= (*i
)->GetCaster();
2058 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
2059 int32 canabsorb
= caster
->GetHealth();
2060 if (canabsorb
< absorbed
)
2061 absorbed
= canabsorb
;
2063 RemainingDamage
-= absorbed
;
2065 uint32 ab_damage
= absorbed
;
2066 DealDamageMods(caster
,ab_damage
,NULL
);
2067 DealDamage(caster
, ab_damage
, NULL
, damagetype
, schoolMask
, 0, false);
2076 // currentAbsorb - damage can be absorbed by shield
2077 // If need absorb less damage
2078 if (RemainingDamage
< currentAbsorb
)
2079 currentAbsorb
= RemainingDamage
;
2081 RemainingDamage
-= currentAbsorb
;
2083 // Reduce shield amount
2084 mod
->m_amount
-=currentAbsorb
;
2085 if((*i
)->DropAuraCharge())
2087 // Need remove it later
2088 if (mod
->m_amount
<=0)
2089 existExpired
= true;
2092 // Remove all expired absorb auras
2095 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end();)
2097 if ((*i
)->GetModifier()->m_amount
<=0)
2099 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
2100 i
= vSchoolAbsorb
.begin();
2107 // Cast back reflect damage spell
2108 if (canReflect
&& reflectSpell
)
2109 pVictim
->CastCustomSpell(this, reflectSpell
, &reflectDamage
, NULL
, NULL
, true, NULL
, reflectTriggeredBy
);
2111 // absorb by mana cost
2112 AuraList
const& vManaShield
= pVictim
->GetAurasByType(SPELL_AURA_MANA_SHIELD
);
2113 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
2117 // check damage school mask
2118 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2121 int32 currentAbsorb
;
2122 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2123 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2125 currentAbsorb
= RemainingDamage
;
2127 if (float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()])
2129 if(Player
*modOwner
= pVictim
->GetSpellModOwner())
2130 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
2132 int32 maxAbsorb
= int32(pVictim
->GetPower(POWER_MANA
) / manaMultiplier
);
2133 if (currentAbsorb
> maxAbsorb
)
2134 currentAbsorb
= maxAbsorb
;
2136 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
2137 pVictim
->ApplyPowerMod(POWER_MANA
, manaReduction
, false);
2140 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
2141 if((*i
)->GetModifier()->m_amount
<= 0)
2143 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
2144 next
= vManaShield
.begin();
2147 RemainingDamage
-= currentAbsorb
;
2150 // effects dependent from full absorb amount
2151 if (int32 full_absorb
= damage
- RemainingDamage
- *resist
)
2153 Unit::AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
2154 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
2156 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
2158 // Incanter's Absorption
2159 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_GENERIC
&&
2160 itr_spellProto
->SpellIconID
== 2941)
2163 int32 amount
= int32(full_absorb
* (*itr
)->GetModifier()->m_amount
/ 100);
2165 // apply normalized part of already accumulated amount in aura
2166 if (Aura
* spdAura
= pVictim
->GetAura(44413,0))
2167 amount
+= spdAura
->GetModifier()->m_amount
* spdAura
->GetAuraDuration() / spdAura
->GetAuraMaxDuration();
2169 // limit 5 health percents
2170 int32 health_5percent
= pVictim
->GetMaxHealth()*5/100;
2171 if(amount
> health_5percent
)
2172 amount
= health_5percent
;
2174 // Incanter's Absorption (triggered absorb based spell power, will replace existed if any)
2175 pVictim
->CastCustomSpell(pVictim
, 44413, &amount
, NULL
, NULL
, true);
2181 // only split damage if not damaging yourself
2184 AuraList
const& vSplitDamageFlat
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
2185 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
2189 // check damage school mask
2190 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2193 // Damage can be splitted only if aura has an alive caster
2194 Unit
*caster
= (*i
)->GetCaster();
2195 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
2198 int32 currentAbsorb
;
2199 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2200 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2202 currentAbsorb
= RemainingDamage
;
2204 RemainingDamage
-= currentAbsorb
;
2207 uint32 splitted
= currentAbsorb
;
2208 uint32 splitted_absorb
= 0;
2209 DealDamageMods(caster
,splitted
,&splitted_absorb
);
2211 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, splitted_absorb
, 0, false, 0, false);
2213 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2214 DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2217 AuraList
const& vSplitDamagePct
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
2218 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
2222 // check damage school mask
2223 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2226 // Damage can be splitted only if aura has an alive caster
2227 Unit
*caster
= (*i
)->GetCaster();
2228 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
2231 uint32 splitted
= uint32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
2233 RemainingDamage
-= int32(splitted
);
2235 uint32 split_absorb
= 0;
2236 DealDamageMods(caster
,splitted
,&split_absorb
);
2238 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, split_absorb
, 0, false, 0, false);
2240 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2241 DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2245 // Apply death prevention spells effects
2246 if (preventDeathSpell
&& RemainingDamage
>= pVictim
->GetHealth())
2248 switch(preventDeathSpell
->SpellFamilyName
)
2251 case SPELLFAMILY_ROGUE
:
2254 if (preventDeathSpell
->SpellIconID
== 2109)
2256 pVictim
->CastSpell(pVictim
,31231,true);
2257 ((Player
*)pVictim
)->AddSpellCooldown(31231,0,time(NULL
)+60);
2258 // with health > 10% lost health until health==10%, in other case no losses
2259 uint32 health10
= pVictim
->GetMaxHealth()/10;
2260 RemainingDamage
= pVictim
->GetHealth() > health10
? pVictim
->GetHealth() - health10
: 0;
2265 case SPELLFAMILY_PRIEST
:
2268 if (preventDeathSpell
->SpellIconID
== 2873)
2270 int32 healAmount
= pVictim
->GetMaxHealth() * preventDeathAmount
/ 100;
2271 pVictim
->CastCustomSpell(pVictim
, 48153, &healAmount
, NULL
, NULL
, true);
2272 pVictim
->RemoveAurasDueToSpell(preventDeathSpell
->Id
);
2273 RemainingDamage
= 0;
2280 *absorb
= damage
- RemainingDamage
- *resist
;
2283 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
2285 if(hasUnitState(UNIT_STAT_CAN_NOT_REACT
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
2288 if (!pVictim
->isAlive())
2291 if(IsNonMeleeSpellCasted(false))
2295 if (attType
== BASE_ATTACK
)
2296 hitInfo
= HITINFO_NORMALSWING2
;
2297 else if (attType
== OFF_ATTACK
)
2298 hitInfo
= HITINFO_LEFTSWING
;
2300 return; // ignore ranged case
2302 uint32 extraAttacks
= m_extraAttacks
;
2304 // melee attack spell casted at main hand attack only
2305 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
2307 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
2309 // not recent extra attack only at any non extra attack (melee spell case)
2310 if(!extra
&& extraAttacks
)
2312 while(m_extraAttacks
)
2314 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2315 if(m_extraAttacks
> 0)
2322 // attack can be redirected to another target
2323 pVictim
= SelectMagnetTarget(pVictim
);
2325 CalcDamageInfo damageInfo
;
2326 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
2327 // Send log damage message to client
2328 DealDamageMods(pVictim
,damageInfo
.damage
,&damageInfo
.absorb
);
2329 SendAttackStateUpdate(&damageInfo
);
2330 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
2331 DealMeleeDamage(&damageInfo
,true);
2333 if (GetTypeId() == TYPEID_PLAYER
)
2334 DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2335 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2337 DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2338 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2340 // if damage pVictim call AI reaction
2341 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
2342 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
2344 // extra attack only at any non extra attack (normal case)
2345 if(!extra
&& extraAttacks
)
2347 while(m_extraAttacks
)
2349 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2350 if(m_extraAttacks
> 0)
2356 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
2358 // This is only wrapper
2360 // Miss chance based on melee
2361 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
2363 // Critical hit chance
2364 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
2366 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
2367 float dodge_chance
= pVictim
->GetUnitDodgeChance();
2368 float block_chance
= pVictim
->GetUnitBlockChance();
2369 float parry_chance
= pVictim
->GetUnitParryChance();
2371 // Useful if want to specify crit & miss chances for melee, else it could be removed
2372 DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance
,crit_chance
,dodge_chance
,parry_chance
,block_chance
);
2374 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100));
2377 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const
2379 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2380 return MELEE_HIT_EVADE
;
2382 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
2383 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
2385 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
2386 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
2388 // bonus from skills is 0.04%
2389 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
2390 int32 sum
= 0, tmp
= 0;
2391 int32 roll
= urand (0, 10000);
2393 DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
2394 DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
2395 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
2399 if (tmp
> 0 && roll
< (sum
+= tmp
))
2401 DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS");
2402 return MELEE_HIT_MISS
;
2405 // always crit against a sitting target (except 0 crit chance)
2406 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
2408 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)");
2409 return MELEE_HIT_CRIT
;
2414 // only players can't dodge if attacker is behind
2415 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI
,this))
2417 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
2421 // Reduce dodge chance by attacker expertise rating
2422 if (GetTypeId() == TYPEID_PLAYER
)
2423 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2425 dodge_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2427 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2428 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2431 if ( (tmp
> 0) // check if unit _can_ dodge
2432 && ((tmp
-= skillBonus
) > 0)
2433 && roll
< (sum
+= tmp
))
2435 DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
2436 return MELEE_HIT_DODGE
;
2440 // parry & block chances
2442 // check if attack comes from behind, nobody can parry or block if attacker is behind
2443 if (!pVictim
->HasInArc(M_PI
,this))
2445 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind.");
2449 // Reduce parry chance by attacker expertise rating
2450 if (GetTypeId() == TYPEID_PLAYER
)
2451 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2453 parry_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2455 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
2457 int32 tmp2
= int32(parry_chance
);
2458 if ( (tmp2
> 0) // check if unit _can_ parry
2459 && ((tmp2
-= skillBonus
) > 0)
2460 && (roll
< (sum
+= tmp2
)))
2462 DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp2
, sum
);
2463 return MELEE_HIT_PARRY
;
2467 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
2470 if ( (tmp
> 0) // check if unit _can_ block
2471 && ((tmp
-= skillBonus
) > 0)
2472 && (roll
< (sum
+= tmp
)))
2474 DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
2475 return MELEE_HIT_BLOCK
;
2483 if (tmp
> 0 && roll
< (sum
+= tmp
))
2485 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
2486 return MELEE_HIT_CRIT
;
2489 // 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)
2490 if( attType
!= RANGED_ATTACK
&&
2491 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
2492 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
2493 getLevel() < pVictim
->getLevelForTarget(this) )
2495 // cap possible value (with bonuses > max skill)
2496 int32 skill
= attackerWeaponSkill
;
2497 int32 maxskill
= attackerMaxSkillValueForLevel
;
2498 skill
= (skill
> maxskill
) ? maxskill
: skill
;
2500 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
2501 tmp
= tmp
> 4000 ? 4000 : tmp
;
2502 if (roll
< (sum
+= tmp
))
2504 DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
2505 return MELEE_HIT_GLANCING
;
2509 // mobs can score crushing blows if they're 4 or more levels above victim
2510 if (getLevelForTarget(pVictim
) >= pVictim
->getLevelForTarget(this) + 4 &&
2511 // can be from by creature (if can) or from controlled player that considered as creature
2512 (GetTypeId()!=TYPEID_PLAYER
&& !((Creature
*)this)->isPet() &&
2513 !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) ||
2514 GetTypeId()==TYPEID_PLAYER
&& GetCharmerOrOwnerGUID()))
2516 // when their weapon skill is 15 or more above victim's defense skill
2517 tmp
= victimDefenseSkill
;
2518 int32 tmpmax
= victimMaxSkillValueForLevel
;
2519 // having defense above your maximum (from items, talents etc.) has no effect
2520 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
2521 // tmp = mob's level * 5 - player's current defense skill
2522 tmp
= attackerMaxSkillValueForLevel
- tmp
;
2525 // add 2% chance per lacking skill point, min. is 15%
2526 tmp
= tmp
* 200 - 1500;
2527 if (roll
< (sum
+= tmp
))
2529 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
2530 return MELEE_HIT_CRUSHING
;
2535 DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL");
2536 return MELEE_HIT_NORMAL
;
2539 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
2541 float min_damage
, max_damage
;
2543 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
2544 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
2550 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
2551 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
2554 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
2555 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
2558 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
2559 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
2561 // Just for good manner
2569 if (min_damage
> max_damage
)
2571 std::swap(min_damage
,max_damage
);
2574 if(max_damage
== 0.0f
)
2577 return urand((uint32
)min_damage
, (uint32
)max_damage
);
2580 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
2582 if(spellProto
->spellLevel
<= 0)
2585 float LvlPenalty
= 0.0f
;
2587 if(spellProto
->spellLevel
< 20)
2588 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
2589 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
2590 if(LvlFactor
> 1.0f
)
2593 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
2596 void Unit::SendMeleeAttackStart(Unit
* pVictim
)
2598 WorldPacket
data( SMSG_ATTACKSTART
, 8 + 8 );
2599 data
<< uint64(GetGUID());
2600 data
<< uint64(pVictim
->GetGUID());
2602 SendMessageToSet(&data
, true);
2603 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
2606 void Unit::SendMeleeAttackStop(Unit
* victim
)
2611 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
2612 data
.append(GetPackGUID());
2613 data
.append(victim
->GetPackGUID()); // can be 0x00...
2614 data
<< uint32(0); // can be 0x1
2615 SendMessageToSet(&data
, true);
2616 sLog
.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER
? "player" : "creature"), GetGUIDLow(), (victim
->GetTypeId()==TYPEID_PLAYER
? "player" : "creature"),victim
->GetGUIDLow());
2618 /*if(victim->GetTypeId() == TYPEID_UNIT)
2619 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
2622 bool Unit::isSpellBlocked(Unit
*pVictim
, SpellEntry
const * /*spellProto*/, WeaponAttackType attackType
)
2624 if (pVictim
->HasInArc(M_PI
,this))
2626 /* Currently not exist spells with ignore block
2627 // Ignore combat result aura (parry/dodge check on prepare)
2628 AuraList const& ignore = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2629 for(AuraList::const_iterator i = ignore.begin(); i != ignore.end(); ++i)
2631 if (!(*i)->isAffectedOnSpell(spellProto))
2633 if ((*i)->GetModifier()->m_miscvalue == )
2638 // Check creatures flags_extra for disable block
2639 if(pVictim
->GetTypeId()==TYPEID_UNIT
&&
2640 ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
)
2643 float blockChance
= pVictim
->GetUnitBlockChance();
2644 blockChance
+= (int32(GetWeaponSkillValue(attackType
)) - int32(pVictim
->GetMaxSkillValueForLevel()))*0.04f
;
2645 if (roll_chance_f(blockChance
))
2651 // Melee based spells can be miss, parry or dodge on this step
2652 // Crit or block - determined on damage calculation phase! (and can be both in some time)
2653 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
2655 // Calculate hit chance (more correct for chance mod)
2658 // PvP - PvE melee chances
2659 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2660 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
2662 HitChance
= 95 - leveldif
;
2664 HitChance
= 93 - (leveldif
- 2) * lchance
;
2666 // Hit chance depends from victim auras
2667 if(attType
== RANGED_ATTACK
)
2668 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2670 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2672 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2673 if(Player
*modOwner
= GetSpellModOwner())
2674 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
2677 float miss_chance
= 100.0f
- HitChance
;
2679 // Bonuses from attacker aura and ratings
2680 if (attType
== RANGED_ATTACK
)
2681 miss_chance
-= m_modRangedHitChance
;
2683 miss_chance
-= m_modMeleeHitChance
;
2685 // bonus from skills is 0.04%
2686 miss_chance
-= skillDiff
* 0.04f
;
2688 // Limit miss chance from 0 to 60%
2689 if (miss_chance
< 0.0f
)
2691 if (miss_chance
> 60.0f
)
2696 // Melee based spells hit result calculations
2697 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2699 WeaponAttackType attType
= BASE_ATTACK
;
2701 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
2702 attType
= RANGED_ATTACK
;
2704 // bonus from skills is 0.04% per skill Diff
2705 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
2706 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
2707 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
2709 uint32 roll
= urand (0, 10000);
2711 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
2713 uint32 tmp
= missChance
;
2715 return SPELL_MISS_MISS
;
2717 // Chance resist mechanic (select max value from every mechanic spell effect)
2718 int32 resist_mech
= 0;
2719 // Get effects mechanic and chance
2720 for(int eff
= 0; eff
< 3; ++eff
)
2722 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2725 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2726 if (resist_mech
< temp
*100)
2727 resist_mech
= temp
*100;
2733 return SPELL_MISS_RESIST
;
2735 bool canDodge
= true;
2736 bool canParry
= true;
2738 // Same spells cannot be parry/dodge
2739 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
2740 return SPELL_MISS_NONE
;
2742 // Ranged attack cannot be parry/dodge only deflect
2743 if (attType
== RANGED_ATTACK
)
2746 if (pVictim
->HasInArc(M_PI
,this))
2748 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2749 tmp
+=deflect_chance
;
2751 return SPELL_MISS_DEFLECT
;
2753 return SPELL_MISS_NONE
;
2756 // Check for attack from behind
2757 if (!pVictim
->HasInArc(M_PI
,this))
2759 // Can`t dodge from behind in PvP (but its possible in PvE)
2760 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
2765 // Check creatures flags_extra for disable parry
2766 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
2768 uint32 flagEx
= ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
;
2769 if( flagEx
& CREATURE_FLAG_EXTRA_NO_PARRY
)
2772 // Ignore combat result aura
2773 AuraList
const& ignore
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
2774 for(AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
2776 if (!(*i
)->isAffectedOnSpell(spell
))
2778 switch((*i
)->GetModifier()->m_miscvalue
)
2780 case MELEE_HIT_DODGE
: canDodge
= false; break;
2781 case MELEE_HIT_BLOCK
: break; // Block check in hit step
2782 case MELEE_HIT_PARRY
: canParry
= false; break;
2784 DEBUG_LOG("Spell %u SPELL_AURA_IGNORE_COMBAT_RESULT have unhandled state %d", (*i
)->GetId(), (*i
)->GetModifier()->m_miscvalue
);
2792 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
2793 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2794 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
)*100;
2795 // Reduce dodge chance by attacker expertise rating
2796 if (GetTypeId() == TYPEID_PLAYER
)
2797 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2799 dodgeChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2800 if (dodgeChance
< 0)
2805 return SPELL_MISS_DODGE
;
2811 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
2812 // Reduce parry chance by attacker expertise rating
2813 if (GetTypeId() == TYPEID_PLAYER
)
2814 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2816 parryChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2817 if (parryChance
< 0)
2822 return SPELL_MISS_PARRY
;
2825 return SPELL_MISS_NONE
;
2828 // TODO need use unit spell resistances in calculations
2829 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2831 // Can`t miss on dead target (on skinning for example)
2832 if (!pVictim
->isAlive())
2833 return SPELL_MISS_NONE
;
2835 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
2836 // PvP - PvE spell misschances per leveldif > 2
2837 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
2838 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2840 // Base hit chance from attacker and victim levels
2843 modHitChance
= 96 - leveldif
;
2845 modHitChance
= 94 - (leveldif
- 2) * lchance
;
2847 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2848 if(Player
*modOwner
= GetSpellModOwner())
2849 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
2850 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
2851 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
2852 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
2853 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
2854 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
2855 if (IsAreaOfEffectSpell(spell
))
2856 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
2857 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
2858 if (IsDispelSpell(spell
))
2859 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
2860 // Chance resist mechanic (select max value from every mechanic spell effect)
2861 int32 resist_mech
= 0;
2862 // Get effects mechanic and chance
2863 for(int eff
= 0; eff
< 3; ++eff
)
2865 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2868 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2869 if (resist_mech
< temp
)
2874 modHitChance
-=resist_mech
;
2876 // Chance resist debuff
2877 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
2879 int32 HitChance
= modHitChance
* 100;
2880 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
2881 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
2883 // Decrease hit chance from victim rating bonus
2884 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2885 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
2887 if (HitChance
< 100) HitChance
= 100;
2888 if (HitChance
> 10000) HitChance
= 10000;
2890 int32 tmp
= 10000 - HitChance
;
2892 uint32 rand
= urand(0,10000);
2895 return SPELL_MISS_MISS
;
2897 // cast by caster in front of victim
2898 if (pVictim
->HasInArc(M_PI
,this))
2900 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2901 tmp
+=deflect_chance
;
2903 return SPELL_MISS_DEFLECT
;
2906 return SPELL_MISS_NONE
;
2909 // Calculate spell hit result can be:
2910 // Every spell can: Evade/Immune/Reflect/Sucesful hit
2911 // For melee based spells:
2917 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
2919 // Return evade for units in evade mode
2920 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2921 return SPELL_MISS_EVADE
;
2924 if (pVictim
->IsImmunedToSpell(spell
))
2925 return SPELL_MISS_IMMUNE
;
2927 // All positive spells can`t miss
2928 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
2929 if (IsPositiveSpell(spell
->Id
))
2930 return SPELL_MISS_NONE
;
2933 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
)))
2934 return SPELL_MISS_IMMUNE
;
2936 // Try victim reflect spell
2939 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
2940 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
2941 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
2942 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
2943 reflectchance
+= (*i
)->GetModifier()->m_amount
;
2944 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
2946 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
2947 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
2948 return SPELL_MISS_REFLECT
;
2952 switch (spell
->DmgClass
)
2954 case SPELL_DAMAGE_CLASS_RANGED
:
2955 case SPELL_DAMAGE_CLASS_MELEE
:
2956 return MeleeSpellHitResult(pVictim
, spell
);
2957 case SPELL_DAMAGE_CLASS_NONE
:
2958 case SPELL_DAMAGE_CLASS_MAGIC
:
2959 return MagicSpellHitResult(pVictim
, spell
);
2961 return SPELL_MISS_NONE
;
2964 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
2969 // Base misschance 5%
2970 float misschance
= 5.0f
;
2972 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
2973 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
2975 bool isNormal
= false;
2976 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
2978 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
2984 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
2990 // PvP : PvE melee misschances per leveldif > 2
2991 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2993 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2997 // Hit chance from attacker based on ratings and auras
2998 float m_modHitChance
;
2999 if (attType
== RANGED_ATTACK
)
3000 m_modHitChance
= m_modRangedHitChance
;
3002 m_modHitChance
= m_modMeleeHitChance
;
3005 misschance
+= (leveldif
- m_modHitChance
);
3007 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
3009 // Hit chance for victim based on ratings
3010 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
3012 if (attType
== RANGED_ATTACK
)
3013 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
3015 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
3018 // Modify miss chance by victim auras
3019 if(attType
== RANGED_ATTACK
)
3020 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
3022 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
3024 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
3025 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
3026 misschance
-= skillBonus
* 0.04f
;
3028 // Limit miss chance from 0 to 60%
3029 if ( misschance
< 0.0f
)
3031 if ( misschance
> 60.0f
)
3037 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
3039 if(GetTypeId() == TYPEID_PLAYER
)
3041 // in PvP use full skill instead current skill value
3042 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3043 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
3044 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
3045 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
3049 return GetUnitMeleeSkill(target
);
3052 float Unit::GetUnitDodgeChance() const
3054 if(hasUnitState(UNIT_STAT_STUNNED
))
3056 if( GetTypeId() == TYPEID_PLAYER
)
3057 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
3060 if(((Creature
const*)this)->isTotem())
3065 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
3066 return dodge
> 0.0f
? dodge
: 0.0f
;
3071 float Unit::GetUnitParryChance() const
3073 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3076 float chance
= 0.0f
;
3078 if(GetTypeId() == TYPEID_PLAYER
)
3080 Player
const* player
= (Player
const*)this;
3081 if(player
->CanParry() )
3083 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true,true);
3085 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true,true);
3088 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
3091 else if(GetTypeId() == TYPEID_UNIT
)
3093 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
3096 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
3100 return chance
> 0.0f
? chance
: 0.0f
;
3103 float Unit::GetUnitBlockChance() const
3105 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3108 if(GetTypeId() == TYPEID_PLAYER
)
3110 Player
const* player
= (Player
const*)this;
3111 if(player
->CanBlock() )
3113 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
3114 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
3115 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
3117 // is player but has no block ability or no not broken shield equipped
3122 if(((Creature
const*)this)->isTotem())
3127 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
3128 return block
> 0.0f
? block
: 0.0f
;
3133 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
3137 if(GetTypeId() == TYPEID_PLAYER
)
3142 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
3145 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
3148 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
3150 // Just for good manner
3159 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
3163 if(attackType
== RANGED_ATTACK
)
3164 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
3166 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
3168 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
3170 // reduce crit chance from Rating for players
3171 if (attackType
!= RANGED_ATTACK
)
3172 crit
-= pVictim
->GetMeleeCritChanceReduction();
3174 crit
-= pVictim
->GetRangedCritChanceReduction();
3176 // Apply crit chance from defence skill
3177 crit
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
3184 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
3187 if(GetTypeId() == TYPEID_PLAYER
)
3189 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true,true);
3191 // feral or unarmed skill only for base attack
3192 if(attType
!= BASE_ATTACK
&& !item
)
3196 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
3198 // weapon skill or (unarmed for base attack)
3199 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
3201 // in PvP use full skill instead current skill value
3202 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3203 ? ((Player
*)this)->GetMaxSkillValue(skill
)
3204 : ((Player
*)this)->GetSkillValue(skill
);
3205 // Modify value from ratings
3206 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
3209 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
3210 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
3211 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
3215 value
= GetUnitMeleeSkill(target
);
3219 void Unit::_UpdateSpells( uint32 time
)
3221 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
3222 _UpdateAutoRepeatSpell();
3224 // remove finished spells from current pointers
3225 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3227 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
3229 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
3230 m_currentSpells
[i
] = NULL
; // remove pointer
3235 // m_AurasUpdateIterator can be updated in inderect called code at aura remove to skip next planned to update but removed auras
3236 for (m_AurasUpdateIterator
= m_Auras
.begin(); m_AurasUpdateIterator
!= m_Auras
.end();)
3238 Aura
* i_aura
= m_AurasUpdateIterator
->second
;
3239 ++m_AurasUpdateIterator
; // need shift to next for allow update if need into aura update
3240 i_aura
->UpdateAura(time
);
3243 // remove expired auras
3244 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
3248 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
3257 if(!m_gameObj
.empty())
3259 GameObjectList::iterator ite1
, dnext1
;
3260 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
3263 //(*i)->Update( difftime );
3264 if( !(*ite1
)->isSpawned() )
3266 (*ite1
)->SetOwnerGUID(0);
3267 (*ite1
)->SetRespawnTime(0);
3269 dnext1
= m_gameObj
.erase(ite1
);
3277 void Unit::_UpdateAutoRepeatSpell()
3279 //check "realtime" interrupts
3280 if ( (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) )
3282 // cancel wand shoot
3283 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3284 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3285 m_AutoRepeatFirstCast
= true;
3290 if ( m_AutoRepeatFirstCast
&& getAttackTimer(RANGED_ATTACK
) < 500 )
3291 setAttackTimer(RANGED_ATTACK
,500);
3292 m_AutoRepeatFirstCast
= false;
3295 if (isAttackReady(RANGED_ATTACK
))
3297 // Check if able to cast
3298 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CheckCast(true) != SPELL_CAST_OK
)
3300 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3305 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
3306 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
3308 // all went good, reset attack
3309 resetAttackTimer(RANGED_ATTACK
);
3313 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
3315 assert(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
3317 CurrentSpellTypes CSpellType
= pSpell
->GetCurrentContainer();
3319 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
3321 // break same type spell if it is not delayed
3322 InterruptSpell(CSpellType
,false);
3324 // special breakage effects:
3327 case CURRENT_GENERIC_SPELL
:
3329 // generic spells always break channeled not delayed spells
3330 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3332 // autorepeat breaking
3333 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3335 // break autorepeat if not Auto Shot
3336 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3337 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3338 m_AutoRepeatFirstCast
= true;
3342 case CURRENT_CHANNELED_SPELL
:
3344 // channel spells always break generic non-delayed and any channeled spells
3345 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3346 InterruptSpell(CURRENT_CHANNELED_SPELL
);
3348 // it also does break autorepeat if not Auto Shot
3349 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
3350 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3351 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3354 case CURRENT_AUTOREPEAT_SPELL
:
3356 // only Auto Shoot does not break anything
3357 if (pSpell
->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3359 // generic autorepeats break generic non-delayed and channeled non-delayed spells
3360 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3361 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3363 // special action: set first cast flag
3364 m_AutoRepeatFirstCast
= true;
3369 // other spell types don't break anything now
3373 // current spell (if it is still here) may be safely deleted now
3374 if (m_currentSpells
[CSpellType
])
3375 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
3377 // set new current spell
3378 m_currentSpells
[CSpellType
] = pSpell
;
3379 pSpell
->SetReferencedFromCurrent(true);
3381 pSpell
->m_selfContainer
= &(m_currentSpells
[pSpell
->GetCurrentContainer()]);
3384 void Unit::InterruptSpell(CurrentSpellTypes spellType
, bool withDelayed
)
3386 assert(spellType
< CURRENT_MAX_SPELL
);
3388 if (m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
3390 // send autorepeat cancel message for autorepeat spells
3391 if (spellType
== CURRENT_AUTOREPEAT_SPELL
)
3393 if(GetTypeId() == TYPEID_PLAYER
)
3394 ((Player
*)this)->SendAutoRepeatCancel(this);
3397 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
3398 m_currentSpells
[spellType
]->cancel();
3400 // cancel can interrupt spell already (caster cancel ->target aura remove -> caster iterrupt)
3401 if (m_currentSpells
[spellType
])
3403 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
3404 m_currentSpells
[spellType
] = NULL
;
3409 void Unit::FinishSpell(CurrentSpellTypes spellType
, bool ok
/*= true*/)
3411 Spell
* spell
= m_currentSpells
[spellType
];
3415 if (spellType
== CURRENT_CHANNELED_SPELL
)
3416 spell
->SendChannelUpdate(0);
3422 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
3424 // We don't do loop here to explicitly show that melee spell is excluded.
3425 // Maybe later some special spells will be excluded too.
3427 // generic spells are casted when they are not finished and not delayed
3428 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
3429 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3430 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3433 // channeled spells may be delayed, but they are still considered casted
3434 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
3435 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
3438 // autorepeat spells may be finished or delayed, but they are still considered casted
3439 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3445 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
3447 // generic spells are interrupted if they are not finished or delayed
3448 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
3449 InterruptSpell(CURRENT_GENERIC_SPELL
,withDelayed
);
3451 // autorepeat spells are interrupted if they are not finished or delayed
3452 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
3453 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
,withDelayed
);
3455 // channeled spells are interrupted if they are not finished, even if they are delayed
3456 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
3457 InterruptSpell(CURRENT_CHANNELED_SPELL
,true);
3460 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
3462 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3463 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
3464 return m_currentSpells
[i
];
3468 void Unit::SetInFront(Unit
const* target
)
3470 SetOrientation(GetAngle(target
));
3473 void Unit::SetFacingTo(float ori
)
3475 // update orientation at server
3476 SetOrientation(ori
);
3480 BuildHeartBeatMsg(&data
);
3481 SendMessageToSet(&data
, false);
3484 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
3487 return c
->canSwim();
3489 return c
->canWalk() || c
->canFly();
3492 bool Unit::IsInWater() const
3494 return GetBaseMap()->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
3497 bool Unit::IsUnderWater() const
3499 return GetBaseMap()->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3502 void Unit::DeMorph()
3504 SetDisplayId(GetNativeDisplayId());
3507 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3511 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3512 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3513 modifier
+= (*i
)->GetModifier()->m_amount
;
3518 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3520 float multiplier
= 1.0f
;
3522 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3523 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3524 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3529 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3533 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3534 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3535 if ((*i
)->GetModifier()->m_amount
> modifier
)
3536 modifier
= (*i
)->GetModifier()->m_amount
;
3541 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
3545 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3546 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3547 if ((*i
)->GetModifier()->m_amount
< modifier
)
3548 modifier
= (*i
)->GetModifier()->m_amount
;
3553 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3560 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3561 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3563 Modifier
* mod
= (*i
)->GetModifier();
3564 if (mod
->m_miscvalue
& misc_mask
)
3565 modifier
+= mod
->m_amount
;
3570 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3575 float multiplier
= 1.0f
;
3577 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3578 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3580 Modifier
* mod
= (*i
)->GetModifier();
3581 if (mod
->m_miscvalue
& misc_mask
)
3582 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3587 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3594 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3595 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3597 Modifier
* mod
= (*i
)->GetModifier();
3598 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
> modifier
)
3599 modifier
= mod
->m_amount
;
3605 int32
Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3612 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3613 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3615 Modifier
* mod
= (*i
)->GetModifier();
3616 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
< modifier
)
3617 modifier
= mod
->m_amount
;
3623 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3627 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3628 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3630 Modifier
* mod
= (*i
)->GetModifier();
3631 if (mod
->m_miscvalue
== misc_value
)
3632 modifier
+= mod
->m_amount
;
3637 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
3639 float multiplier
= 1.0f
;
3641 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3642 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3644 Modifier
* mod
= (*i
)->GetModifier();
3645 if (mod
->m_miscvalue
== misc_value
)
3646 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3651 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3655 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3656 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3658 Modifier
* mod
= (*i
)->GetModifier();
3659 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
3660 modifier
= mod
->m_amount
;
3666 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) 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_value
&& mod
->m_amount
< modifier
)
3675 modifier
= mod
->m_amount
;
3681 float Unit::GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype
, uint32 mask
) const
3686 float multiplier
= 1.0f
;
3688 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3689 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3691 Modifier
* mod
= (*i
)->GetModifier();
3692 if (mask
& (1 << (mod
->m_miscvalue
-1)))
3693 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3698 bool Unit::AddAura(Aura
*Aur
)
3700 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
3702 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
3703 if( !isAlive() && !IsDeathPersistentSpell(aurSpellInfo
) &&
3704 !IsDeathOnlySpell(aurSpellInfo
) &&
3705 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
3711 if(Aur
->GetTarget() != this)
3713 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
3714 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
3715 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
3720 // m_auraname can be modified to SPELL_AURA_NONE for area auras, this expected for this value
3721 AuraType aurName
= Aur
->GetModifier()->m_auraname
;
3723 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
3724 AuraMap::iterator i
= m_Auras
.find( spair
);
3726 // take out same spell
3727 if (i
!= m_Auras
.end())
3729 // passive and persistent auras can stack with themselves any number of times
3730 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
3732 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
3734 Aura
* aur2
= i2
->second
;
3735 if(aur2
->GetCasterGUID()==Aur
->GetCasterGUID())
3737 // Aura can stack on self -> Stack it;
3738 if(aurSpellInfo
->StackAmount
)
3740 // can be created with >1 stack by some spell mods
3741 aur2
->modStackAmount(Aur
->GetStackAmount());
3745 // Carry over removed Aura's remaining damage if Aura still has ticks remaining
3746 else if (aur2
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_STACK_DOT_MODIFIER
&& aurName
== SPELL_AURA_PERIODIC_DAMAGE
&& aur2
->GetAuraDuration() > 0)
3748 int32 remainingTicks
= aur2
->GetAuraMaxTicks() - aur2
->GetAuraTicks();
3749 int32 remainingDamage
= aur2
->GetModifier()->m_amount
* remainingTicks
;
3751 Aur
->GetModifier()->m_amount
+= int32(remainingDamage
/ Aur
->GetAuraMaxTicks());
3753 // can be only single (this check done at _each_ aura add
3754 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3760 // m_auraname can be modified to SPELL_AURA_NONE for area auras, use original
3761 AuraType aurNameReal
= AuraType(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()]);
3766 case SPELL_AURA_DUMMY
: // allow stack
3767 case SPELL_AURA_PERIODIC_DAMAGE
:
3768 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
3769 case SPELL_AURA_PERIODIC_LEECH
:
3770 case SPELL_AURA_PERIODIC_HEAL
:
3771 case SPELL_AURA_OBS_MOD_HEALTH
:
3772 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3773 case SPELL_AURA_OBS_MOD_MANA
:
3774 case SPELL_AURA_POWER_BURN_MANA
:
3776 case SPELL_AURA_PERIODIC_ENERGIZE
: // all or self or clear non-stackable
3777 default: // not allow
3778 // can be only single (this check done at _each_ aura add
3779 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3790 // passive auras not stacable with other ranks
3791 if (!IsPassiveSpellStackableWithRanks(aurSpellInfo
))
3793 if (!RemoveNoStackAurasDueToAura(Aur
))
3796 return false; // couldn't remove conflicting aura with higher rank
3800 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
3801 if (Aur
->IsSingleTarget() && Aur
->GetTarget())
3803 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
3806 Unit
* caster
= Aur
->GetCaster();
3807 if(!caster
) // caster deleted and not required adding scAura
3810 bool restart
= false;
3811 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3812 for(AuraList::const_iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
3814 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
3815 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
3817 if ((*itr
)->IsInUse())
3819 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());
3822 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
3831 scAuras
.push_back(Aur
);
3837 // add aura, register in lists and arrays
3839 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
3840 if (aurName
< TOTAL_AURAS
)
3842 m_modAuras
[aurName
].push_back(Aur
);
3845 Aur
->ApplyModifier(true,true);
3846 sLog
.outDebug("Aura %u now is in use", aurName
);
3848 // if aura deleted before boosts apply ignore
3849 // this can be possible it it removed indirectly by triggered spell effect at ApplyModifier
3850 if (Aur
->IsDeleted())
3853 if(IsSpellLastAuraEffect(aurSpellInfo
,Aur
->GetEffIndex()))
3854 Aur
->HandleSpellSpecificBoosts(true);
3859 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
3861 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3864 AuraMap::const_iterator i
,next
;
3865 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3869 uint32 i_spellId
= (*i
).second
->GetId();
3870 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
3872 if(sSpellMgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
3874 RemoveAurasDueToSpell(i_spellId
);
3876 if( m_Auras
.empty() )
3879 next
= m_Auras
.begin();
3885 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
3890 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
3894 uint32 spellId
= Aur
->GetId();
3895 uint32 effIndex
= Aur
->GetEffIndex();
3897 // passive spell special case (only non stackable with ranks)
3898 if(IsPassiveSpell(spellId
))
3900 if(IsPassiveSpellStackableWithRanks(spellProto
))
3904 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
3906 AuraMap::iterator i
,next
;
3907 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3911 if (!(*i
).second
) continue;
3913 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
3918 uint32 i_spellId
= i_spellProto
->Id
;
3920 // early checks that spellId is passive non stackable spell
3921 if(IsPassiveSpell(i_spellId
))
3923 // passive non-stackable spells not stackable only for same caster
3924 if(Aur
->GetCasterGUID()!=i
->second
->GetCasterGUID())
3927 // passive non-stackable spells not stackable only with another rank of same spell
3928 if (!sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3932 uint32 i_effIndex
= (*i
).second
->GetEffIndex();
3934 if(i_spellId
== spellId
) continue;
3936 bool is_triggered_by_spell
= false;
3937 // prevent triggering aura of removing aura that triggered it
3938 for(int j
= 0; j
< 3; ++j
)
3939 if (i_spellProto
->EffectTriggerSpell
[j
] == spellId
)
3940 is_triggered_by_spell
= true;
3942 // prevent triggered aura of removing aura that triggering it (triggered effect early some aura of parent spell
3943 for(int j
= 0; j
< 3; ++j
)
3944 if (spellProto
->EffectTriggerSpell
[j
] == i_spellId
)
3945 is_triggered_by_spell
= true;
3947 if (is_triggered_by_spell
)
3950 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
3952 // single allowed spell specific from same caster or from any caster at target
3953 bool is_spellSpecPerTargetPerCaster
= IsSingleFromSpellSpecificPerTargetPerCaster(spellId_spec
,i_spellId_spec
);
3954 bool is_spellSpecPerTarget
= IsSingleFromSpellSpecificPerTarget(spellId_spec
,i_spellId_spec
);
3955 if( is_spellSpecPerTarget
|| is_spellSpecPerTargetPerCaster
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
3957 // cannot remove higher rank
3958 if (sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3959 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3962 // Its a parent aura (create this aura in ApplyModifier)
3963 if ((*i
).second
->IsInUse())
3965 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());
3968 RemoveAurasDueToSpell(i_spellId
);
3970 if( m_Auras
.empty() )
3973 next
= m_Auras
.begin();
3978 // spell with spell specific that allow single ranks for spell from diff caster
3979 // same caster case processed or early or later
3980 bool is_spellPerTarget
= IsSingleFromSpellSpecificSpellRanksPerTarget(spellId_spec
,i_spellId_spec
);
3981 if ( is_spellPerTarget
&& Aur
->GetCasterGUID() != (*i
).second
->GetCasterGUID() && sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3983 // cannot remove higher rank
3984 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3987 // Its a parent aura (create this aura in ApplyModifier)
3988 if ((*i
).second
->IsInUse())
3990 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());
3993 RemoveAurasDueToSpell(i_spellId
);
3995 if( m_Auras
.empty() )
3998 next
= m_Auras
.begin();
4003 // non single (per caster) per target spell specific (possible single spell per target at caster)
4004 if( !is_spellSpecPerTargetPerCaster
&& !is_spellSpecPerTarget
&& sSpellMgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
4006 // Its a parent aura (create this aura in ApplyModifier)
4007 if ((*i
).second
->IsInUse())
4009 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());
4012 RemoveAurasDueToSpell(i_spellId
);
4014 if( m_Auras
.empty() )
4017 next
= m_Auras
.begin();
4022 // Potions stack aura by aura (elixirs/flask already checked)
4023 if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
4025 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
4027 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4028 return false; // cannot remove higher rank
4030 // Its a parent aura (create this aura in ApplyModifier)
4031 if ((*i
).second
->IsInUse())
4033 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());
4044 void Unit::RemoveAura(uint32 spellId
, uint32 effindex
, Aura
* except
)
4046 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4047 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4049 if(iter
->second
!=except
)
4052 iter
= m_Auras
.lower_bound(spair
);
4059 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
)
4061 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4063 Aura
*aur
= iter
->second
;
4064 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4071 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint32 effindex
, uint64 casterGUID
)
4073 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4074 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4076 Aura
*aur
= iter
->second
;
4077 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4080 iter
= m_Auras
.lower_bound(spair
);
4087 void Unit::RemoveSingleAuraDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
4089 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(spellId
);
4091 // Custom dispel cases
4092 // Unstable Affliction
4093 if(spellEntry
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x010000000000)))
4095 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
,SPELLFAMILY_WARLOCK
,UI64LIT(0x010000000000),0x00000000,casterGUID
))
4097 int32 damage
= dotAura
->GetModifier()->m_amount
*9;
4099 // Remove spell auras from stack
4100 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4102 // backfire damage and silence
4103 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,casterGUID
);
4108 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x10000000)))
4110 Unit
* caster
= NULL
;
4111 uint32 triggeredSpell
= 0;
4113 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x10000000), 0x00000000, casterGUID
))
4114 caster
= dotAura
->GetCaster();
4116 if (caster
&& !caster
->isDead())
4118 Unit::AuraList
const& auras
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
4119 for (Unit::AuraList::const_iterator i
= auras
.begin(); i
!= auras
.end(); ++i
)
4121 switch((*i
)->GetId())
4123 case 51480: triggeredSpell
=64694; break;// Lava Flows, Rank 1
4124 case 51481: triggeredSpell
=65263; break;// Lava Flows, Rank 2
4125 case 51482: triggeredSpell
=65264; break;// Lava Flows, Rank 3
4132 // Remove spell auras from stack
4133 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4137 caster
->CastSpell(caster
, triggeredSpell
, true);
4140 // Vampiric touch (first dummy aura)
4141 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_PRIEST
&& spellEntry
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
4143 if (Aura
*dot
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000040000000000), 0x00000000, casterGUID
))
4145 if(Unit
* caster
= dot
->GetCaster())
4147 int32 bp0
= dot
->GetModifier()->m_amount
;
4148 bp0
= 8 * caster
->SpellDamageBonus(this, spellEntry
, bp0
, DOT
, 1);
4150 // Remove spell auras from stack
4151 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4153 CastCustomSpell(this, 64085, &bp0
, NULL
, NULL
, true, NULL
, NULL
, casterGUID
);
4159 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4162 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
4164 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4166 Aura
*aur
= iter
->second
;
4167 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4169 int32 basePoints
= aur
->GetBasePoints();
4170 // construct the new aura for the attacker - will never return NULL, it's just a wrapper for
4171 // some different constructors
4172 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
, this);
4174 // set its duration and maximum duration
4175 // max duration 2 minutes (in msecs)
4176 int32 dur
= aur
->GetAuraDuration();
4177 int32 max_dur
= 2*MINUTE
*IN_MILISECONDS
;
4178 int32 new_max_dur
= max_dur
> dur
? dur
: max_dur
;
4179 new_aur
->SetAuraMaxDuration( new_max_dur
);
4180 new_aur
->SetAuraDuration( new_max_dur
);
4182 // set periodic to do at least one tick (for case when original aura has been at last tick preparing)
4183 int32 periodic
= aur
->GetModifier()->periodictime
;
4184 new_aur
->GetModifier()->periodictime
= periodic
< new_max_dur
? periodic
: new_max_dur
;
4186 // Unregister _before_ adding to stealer
4187 aur
->UnregisterSingleCastAura();
4189 // strange but intended behaviour: Stolen single target auras won't be treated as single targeted
4190 new_aur
->SetIsSingleTarget(false);
4192 // add the new aura to stealer
4193 stealer
->AddAura(new_aur
);
4195 // Remove aura as dispel
4196 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
4203 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
4205 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4207 if (iter
->second
->GetId() == spellId
)
4208 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
4214 void Unit::RemoveAurasWithDispelType( DispelType type
)
4216 // Create dispel mask by dispel type
4217 uint32 dispelMask
= GetDispellMask(type
);
4218 // Dispel all existing auras vs current dispel type
4219 AuraMap
& auras
= GetAuras();
4220 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
4222 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
4223 if( (1<<spell
->Dispel
) & dispelMask
)
4226 RemoveAurasDueToSpell(spell
->Id
);
4227 itr
= auras
.begin();
4234 void Unit::RemoveSingleAuraFromStack(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4236 if (i
->second
->modStackAmount(-1))
4241 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, uint32 effindex
, AuraRemoveMode mode
)
4243 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4244 if(iter
!= m_Auras
.end())
4245 RemoveSingleAuraFromStack(iter
,mode
);
4248 void Unit::RemoveSingleSpellAurasFromStack(uint32 spellId
, AuraRemoveMode mode
)
4250 for (int i
=0; i
<3; ++i
)
4251 RemoveSingleAuraFromStack(spellId
, i
, mode
);
4254 void Unit::RemoveSingleSpellAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
, AuraRemoveMode mode
)
4256 for (int i
=0; i
<3; ++i
)
4257 RemoveSingleAuraByCasterSpell(spellId
, i
, casterGUID
, mode
);
4260 void Unit::RemoveSingleAuraByCasterSpell(uint32 spellId
, uint32 effindex
, uint64 casterGUID
, AuraRemoveMode mode
)
4262 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4263 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
); ++iter
)
4265 Aura
*aur
= iter
->second
;
4266 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4268 RemoveSingleAuraFromStack(iter
,mode
);
4275 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
)
4277 for (int i
= 0; i
< 3; ++i
)
4278 RemoveAura(spellId
,i
,except
);
4281 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
4283 for (int k
=0; k
< 3; ++k
)
4285 spellEffectPair spair
= spellEffectPair(spellId
, k
);
4286 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4288 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
4291 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
4299 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
4301 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4303 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
4310 void Unit::RemoveNotOwnSingleTargetAuras(uint32 newPhase
)
4312 // single target auras from other casters
4313 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4315 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
4321 Unit
* caster
= iter
->second
->GetCaster();
4322 if(!caster
|| !caster
->InSamePhase(newPhase
))
4332 // single target auras at other targets
4333 AuraList
& scAuras
= GetSingleCastAuras();
4334 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
4337 if (aura
->GetTarget() != this && !aura
->GetTarget()->InSamePhase(newPhase
))
4339 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
4340 aura
->GetTarget()->RemoveAura(aura
);
4341 iter
= scAuras
.begin();
4349 void Unit::RemoveAura(Aura
* aura
, AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4351 AuraMap::iterator i
= m_Auras
.lower_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4352 AuraMap::iterator upperBound
= m_Auras
.upper_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4353 for (; i
!= upperBound
; ++i
)
4355 if (i
->second
== aura
)
4361 sLog
.outDebug("Trying to remove aura id %u effect %u by pointer but aura not found on target", aura
->GetId(), aura
->GetEffIndex());
4364 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4366 Aura
* Aur
= i
->second
;
4367 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
4369 Aur
->UnregisterSingleCastAura();
4371 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
4372 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
4374 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
4378 Aur
->SetRemoveMode(mode
);
4380 // if unit currently update aura list then make safe update iterator shift to next
4381 if (m_AurasUpdateIterator
== i
)
4382 ++m_AurasUpdateIterator
;
4384 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
4385 // remove aura from list before to prevent deleting it before
4388 // now aura removed from from list and can't be deleted by indirect call but can be referenced from callers
4390 // Statue unsummoned at aura remove
4391 Totem
* statue
= NULL
;
4392 if(IsChanneledSpell(AurSpellInfo
))
4393 if(Unit
* caster
= Aur
->GetCaster())
4394 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
4395 statue
= ((Totem
*)caster
);
4397 sLog
.outDebug("Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
4398 if (mode
!= AURA_REMOVE_BY_DELETE
) // not unapply if target will deleted
4399 Aur
->ApplyModifier(false,true);
4401 if (Aur
->_RemoveAura())
4403 // last aura in stack removed
4404 if (mode
!= AURA_REMOVE_BY_DELETE
&& IsSpellLastAuraEffect(Aur
->GetSpellProto(),Aur
->GetEffIndex()))
4405 Aur
->HandleSpellSpecificBoosts(false);
4408 // If aura in use (removed from code that plan access to it data after return)
4409 // store it in aura list with delayed deletion
4411 m_deletedAuras
.push_back(Aur
);
4418 // only way correctly remove all auras from list
4419 if( m_Auras
.empty() )
4422 i
= m_Auras
.begin();
4426 void Unit::RemoveAllAuras(AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4428 while (!m_Auras
.empty())
4430 AuraMap::iterator iter
= m_Auras
.begin();
4431 RemoveAura(iter
,mode
);
4435 void Unit::RemoveArenaAuras(bool onleave
)
4437 // in join, remove positive buffs, on end, remove negative
4438 // used to remove positive visible auras in arenas
4439 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4441 if (!(iter
->second
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_UNK21
) &&
4442 // don't remove stances, shadowform, pally/hunter auras
4443 !iter
->second
->IsPassive() && // don't remove passive auras
4444 (!(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
) ||
4445 !(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNK8
)) &&
4446 // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable)
4447 (iter
->second
->IsPositive() != onleave
)) // remove positive buffs on enter, negative buffs on leave
4454 void Unit::RemoveAllAurasOnDeath()
4456 // used just after dieing to remove all visible auras
4457 // and disable the mods for the passive ones
4458 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4460 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
4461 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
4467 void Unit::DelayAura(uint32 spellId
, uint32 effindex
, int32 delaytime
)
4469 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4470 if (iter
!= m_Auras
.end())
4472 if (iter
->second
->GetAuraDuration() < delaytime
)
4473 iter
->second
->SetAuraDuration(0);
4475 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
4476 iter
->second
->SendAuraUpdate(false);
4477 sLog
.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter
->second
->GetModifier()->m_auraname
, GetGUIDLow(), iter
->second
->GetAuraDuration());
4481 void Unit::_RemoveAllAuraMods()
4483 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4485 (*i
).second
->ApplyModifier(false);
4489 void Unit::_ApplyAllAuraMods()
4491 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4493 (*i
).second
->ApplyModifier(true);
4497 Aura
* Unit::GetAura(uint32 spellId
, uint32 effindex
)
4499 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4500 if (iter
!= m_Auras
.end())
4501 return iter
->second
;
4505 Aura
* Unit::GetAura(AuraType type
, uint32 family
, uint64 familyFlag
, uint32 familyFlag2
, uint64 casterGUID
)
4507 AuraList
const& auras
= GetAurasByType(type
);
4508 for(AuraList::const_iterator i
= auras
.begin();i
!= auras
.end(); ++i
)
4510 SpellEntry
const *spell
= (*i
)->GetSpellProto();
4511 if (spell
->SpellFamilyName
== family
&& (spell
->SpellFamilyFlags
& familyFlag
|| spell
->SpellFamilyFlags2
& familyFlag2
))
4513 if (casterGUID
&& (*i
)->GetCasterGUID()!=casterGUID
)
4521 bool Unit::HasAura(uint32 spellId
) const
4523 for (int i
= 0; i
< 3 ; ++i
)
4525 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, i
));
4526 if (iter
!= m_Auras
.end())
4532 void Unit::AddDynObject(DynamicObject
* dynObj
)
4534 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
4537 void Unit::RemoveDynObject(uint32 spellid
)
4539 if(m_dynObjGUIDs
.empty())
4541 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4543 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4546 i
= m_dynObjGUIDs
.erase(i
);
4548 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
4551 i
= m_dynObjGUIDs
.erase(i
);
4558 void Unit::RemoveAllDynObjects()
4560 while(!m_dynObjGUIDs
.empty())
4562 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*m_dynObjGUIDs
.begin());
4565 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
4569 DynamicObject
* Unit::GetDynObject(uint32 spellId
, uint32 effIndex
)
4571 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4573 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4576 i
= m_dynObjGUIDs
.erase(i
);
4580 if (dynObj
->GetSpellId() == spellId
&& dynObj
->GetEffIndex() == effIndex
)
4587 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
4589 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4591 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4594 i
= m_dynObjGUIDs
.erase(i
);
4598 if (dynObj
->GetSpellId() == spellId
)
4605 GameObject
* Unit::GetGameObject(uint32 spellId
) const
4607 for (GameObjectList::const_iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); ++i
)
4608 if ((*i
)->GetSpellId() == spellId
)
4614 void Unit::AddGameObject(GameObject
* gameObj
)
4616 assert(gameObj
&& gameObj
->GetOwnerGUID()==0);
4617 m_gameObj
.push_back(gameObj
);
4618 gameObj
->SetOwnerGUID(GetGUID());
4620 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
4622 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
4623 // Need disable spell use for owner
4624 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4625 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4626 ((Player
*)this)->AddSpellAndCategoryCooldowns(createBySpell
,0,NULL
,true);
4630 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
4632 assert(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
4634 gameObj
->SetOwnerGUID(0);
4636 // GO created by some spell
4637 if (uint32 spellid
= gameObj
->GetSpellId())
4639 RemoveAurasDueToSpell(spellid
);
4641 if (GetTypeId()==TYPEID_PLAYER
)
4643 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(spellid
);
4644 // Need activate spell use for owner
4645 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4646 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4647 ((Player
*)this)->SendCooldownEvent(createBySpell
);
4651 m_gameObj
.remove(gameObj
);
4655 gameObj
->SetRespawnTime(0);
4660 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
4662 if(m_gameObj
.empty())
4664 GameObjectList::iterator i
, next
;
4665 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
4668 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
4670 (*i
)->SetOwnerGUID(0);
4673 (*i
)->SetRespawnTime(0);
4677 next
= m_gameObj
.erase(i
);
4684 void Unit::RemoveAllGameObjects()
4686 // remove references to unit
4687 for(GameObjectList::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4689 (*i
)->SetOwnerGUID(0);
4690 (*i
)->SetRespawnTime(0);
4692 i
= m_gameObj
.erase(i
);
4696 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
4698 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+4+1+4+4+1+1+4+4+1)); // we guess size
4699 data
.append(log
->target
->GetPackGUID());
4700 data
.append(log
->attacker
->GetPackGUID());
4701 data
<< uint32(log
->SpellID
);
4702 data
<< uint32(log
->damage
); // damage amount
4703 data
<< uint32(log
->overkill
); // overkill
4704 data
<< uint8 (log
->schoolMask
); // damage school
4705 data
<< uint32(log
->absorb
); // AbsorbedDamage
4706 data
<< uint32(log
->resist
); // resist
4707 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
4708 data
<< uint8 (log
->unused
); // unused
4709 data
<< uint32(log
->blocked
); // blocked
4710 data
<< uint32(log
->HitInfo
);
4711 data
<< uint8 (0); // flag to use extend data
4712 SendMessageToSet( &data
, true );
4715 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
, uint32 SpellID
, uint32 Damage
, SpellSchoolMask damageSchoolMask
, uint32 AbsorbedDamage
, uint32 Resist
, bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
4717 SpellNonMeleeDamage
log(this, target
, SpellID
, damageSchoolMask
);
4718 log
.damage
= Damage
- AbsorbedDamage
- Resist
- Blocked
;
4719 log
.absorb
= AbsorbedDamage
;
4720 log
.resist
= Resist
;
4721 log
.physicalLog
= PhysicalDamage
;
4722 log
.blocked
= Blocked
;
4723 log
.HitInfo
= SPELL_HIT_TYPE_UNK1
| SPELL_HIT_TYPE_UNK3
| SPELL_HIT_TYPE_UNK6
;
4725 log
.HitInfo
|= SPELL_HIT_TYPE_CRIT
;
4726 SendSpellNonMeleeDamageLog(&log
);
4729 void Unit::SendPeriodicAuraLog(SpellPeriodicAuraLogInfo
*pInfo
)
4731 Aura
*aura
= pInfo
->aura
;
4732 Modifier
*mod
= aura
->GetModifier();
4734 WorldPacket
data(SMSG_PERIODICAURALOG
, 30);
4735 data
.append(aura
->GetTarget()->GetPackGUID());
4736 data
.appendPackGUID(aura
->GetCasterGUID());
4737 data
<< uint32(aura
->GetId()); // spellId
4738 data
<< uint32(1); // count
4739 data
<< uint32(mod
->m_auraname
); // auraId
4740 switch(mod
->m_auraname
)
4742 case SPELL_AURA_PERIODIC_DAMAGE
:
4743 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
4744 data
<< uint32(pInfo
->damage
); // damage
4745 data
<< uint32(pInfo
->overDamage
); // overkill?
4746 data
<< uint32(GetSpellSchoolMask(aura
->GetSpellProto()));
4747 data
<< uint32(pInfo
->absorb
); // absorb
4748 data
<< uint32(pInfo
->resist
); // resist
4749 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4751 case SPELL_AURA_PERIODIC_HEAL
:
4752 case SPELL_AURA_OBS_MOD_HEALTH
:
4753 data
<< uint32(pInfo
->damage
); // damage
4754 data
<< uint32(pInfo
->overDamage
); // overheal?
4755 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4757 case SPELL_AURA_OBS_MOD_MANA
:
4758 case SPELL_AURA_PERIODIC_ENERGIZE
:
4759 data
<< uint32(mod
->m_miscvalue
); // power type
4760 data
<< uint32(pInfo
->damage
); // damage
4762 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4763 data
<< uint32(mod
->m_miscvalue
); // power type
4764 data
<< uint32(pInfo
->damage
); // amount
4765 data
<< float(pInfo
->multiplier
); // gain multiplier
4768 sLog
.outError("Unit::SendPeriodicAuraLog: unknown aura %u", uint32(mod
->m_auraname
));
4772 aura
->GetTarget()->SendMessageToSet(&data
, true);
4775 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
4777 // Not much to do if no flags are set.
4779 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
4780 // Now go on with a victim's events'n'auras
4781 // Not much to do if no flags are set or there is no victim
4782 if(pVictim
&& pVictim
->isAlive() && procVictim
)
4783 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4786 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4788 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4789 data
<< uint32(spellID
);
4790 data
<< uint64(GetGUID());
4791 data
<< uint8(0); // can be 0 or 1
4792 data
<< uint32(1); // target count
4793 // for(i = 0; i < target count; ++i)
4794 data
<< uint64(target
->GetGUID()); // target GUID
4795 data
<< uint8(missInfo
);
4797 SendMessageToSet(&data
, true);
4800 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4802 sLog
.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4805 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, 16 + 45); // we guess size
4806 data
<< uint32(damageInfo
->HitInfo
);
4807 data
.append(damageInfo
->attacker
->GetPackGUID());
4808 data
.append(damageInfo
->target
->GetPackGUID());
4809 data
<< uint32(damageInfo
->damage
); // Full damage
4810 data
<< uint32(0); // overkill value
4811 data
<< uint8(count
); // Sub damage count
4813 for(int i
= 0; i
< count
; ++i
)
4815 data
<< uint32(damageInfo
->damageSchoolMask
); // School of sub damage
4816 data
<< float(damageInfo
->damage
); // sub damage
4817 data
<< uint32(damageInfo
->damage
); // Sub Damage
4820 if(damageInfo
->HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4822 for(int i
= 0; i
< count
; ++i
)
4823 data
<< uint32(damageInfo
->absorb
); // Absorb
4826 if(damageInfo
->HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4828 for(int i
= 0; i
< count
; ++i
)
4829 data
<< uint32(damageInfo
->resist
); // Resist
4832 data
<< uint8(damageInfo
->TargetState
);
4836 if(damageInfo
->HitInfo
& HITINFO_BLOCK
)
4837 data
<< uint32(damageInfo
->blocked_amount
);
4839 if(damageInfo
->HitInfo
& HITINFO_UNK3
)
4842 if(damageInfo
->HitInfo
& HITINFO_UNK1
)
4853 for(uint8 i
= 0; i
< 5; ++i
)
4861 SendMessageToSet( &data
, true );
4864 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8 SwingType
, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4866 CalcDamageInfo dmgInfo
;
4867 dmgInfo
.HitInfo
= HitInfo
;
4868 dmgInfo
.attacker
= this;
4869 dmgInfo
.target
= target
;
4870 dmgInfo
.damage
= Damage
- AbsorbDamage
- Resist
- BlockedAmount
;
4871 dmgInfo
.damageSchoolMask
= damageSchoolMask
;
4872 dmgInfo
.absorb
= AbsorbDamage
;
4873 dmgInfo
.resist
= Resist
;
4874 dmgInfo
.TargetState
= TargetState
;
4875 dmgInfo
.blocked_amount
= BlockedAmount
;
4876 SendAttackStateUpdate(&dmgInfo
);
4879 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4881 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
4883 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4884 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4886 uint32 triggered_spell_id
= 0;
4887 Unit
* target
= pVictim
;
4888 int32 basepoints0
= 0;
4890 switch(hasteSpell
->SpellFamilyName
)
4892 case SPELLFAMILY_ROGUE
:
4894 switch(hasteSpell
->Id
)
4900 target
= SelectNearbyTarget(pVictim
);
4903 basepoints0
= damage
;
4904 triggered_spell_id
= 22482;
4912 // processed charge only counting case
4913 if(!triggered_spell_id
)
4916 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
4920 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
4925 if(!target
|| target
!=this && !target
->isAlive())
4928 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
4932 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4934 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
4936 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
4937 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
4942 bool Unit::HandleSpellCritChanceAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4944 SpellEntry
const *triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
4946 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4947 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4949 uint32 triggered_spell_id
= 0;
4950 Unit
* target
= pVictim
;
4951 int32 basepoints0
= 0;
4953 switch(triggeredByAuraSpell
->SpellFamilyName
)
4955 case SPELLFAMILY_MAGE
:
4957 switch(triggeredByAuraSpell
->Id
)
4962 Unit
* caster
= triggeredByAura
->GetCaster();
4966 triggered_spell_id
= 54648;
4974 // processed charge only counting case
4975 if(!triggered_spell_id
)
4978 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
4982 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",triggeredByAuraSpell
->Id
,triggered_spell_id
);
4987 if(!target
|| target
!=this && !target
->isAlive())
4990 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
4994 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4996 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
4998 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
4999 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5004 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
5006 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
5007 uint32 effIndex
= triggeredByAura
->GetEffIndex();
5008 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
5010 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5011 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5013 uint32 triggered_spell_id
= 0;
5014 Unit
* target
= pVictim
;
5015 int32 basepoints0
= 0;
5017 switch(dummySpell
->SpellFamilyName
)
5019 case SPELLFAMILY_GENERIC
:
5021 switch (dummySpell
->Id
)
5027 // return damage % to attacker but < 50% own total health
5028 basepoints0
= triggerAmount
*int32(damage
)/100;
5029 if(basepoints0
> GetMaxHealth()/2)
5030 basepoints0
= GetMaxHealth()/2;
5032 triggered_spell_id
= 25997;
5035 // Sweeping Strikes (NPC spells may be)
5039 // prevent chain of triggered spell from same triggered spell
5040 if(procSpell
&& procSpell
->Id
== 26654)
5043 target
= SelectNearbyTarget(pVictim
);
5047 triggered_spell_id
= 26654;
5050 // Twisted Reflection (boss spell)
5052 triggered_spell_id
= 21064;
5057 if (!procSpell
|| procSpell
->Id
== 24659)
5059 // Need remove one 24659 aura
5060 RemoveSingleSpellAurasFromStack(24659);
5063 // Restless Strength
5066 // Need remove one 24662 aura
5067 RemoveSingleSpellAurasFromStack(24662);
5070 // Adaptive Warding (Frostfire Regalia set)
5078 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
5079 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
5081 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
5083 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& UI64LIT(0x10000000)))
5093 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5095 case SPELL_SCHOOL_NORMAL
:
5096 case SPELL_SCHOOL_HOLY
:
5097 return false; // ignored
5098 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
5099 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
5100 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
5101 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
5102 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
5110 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
5116 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5118 case SPELL_SCHOOL_NORMAL
:
5119 return false; // ignore
5120 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
5121 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
5122 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
5123 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
5124 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
5125 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
5133 // Mana Leech (Passive) (Priest Pet Aura)
5137 target
= GetOwner();
5141 triggered_spell_id
= 34650;
5149 if (!roll_chance_i(triggerAmount
))
5152 // Remove any stun effect on target
5153 AuraMap
& Auras
= pVictim
->GetAuras();
5154 for(AuraMap::const_iterator iter
= Auras
.begin(); iter
!= Auras
.end();)
5156 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
5157 if( spell
->Mechanic
== MECHANIC_STUN
||
5158 spell
->EffectMechanic
[iter
->second
->GetEffIndex()] == MECHANIC_STUN
)
5160 pVictim
->RemoveAurasDueToSpell(spell
->Id
);
5161 iter
= Auras
.begin();
5171 // Cast finish spell at last charge
5172 if (triggeredByAura
->GetAuraCharges() > 1)
5176 triggered_spell_id
= 33494;
5179 // Vampiric Aura (boss spell)
5182 basepoints0
= 3 * damage
; // 300%
5183 if (basepoints0
< 0)
5186 triggered_spell_id
= 31285;
5190 // Aura of Madness (Darkmoon Card: Madness trinket)
5191 //=====================================================
5192 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
5193 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
5194 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
5195 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5196 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
5197 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
5198 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
5199 // 41011 Martyr Complex: +35 stamina (All classes)
5200 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5201 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5204 if(GetTypeId() != TYPEID_PLAYER
)
5207 // Select class defined buff
5210 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5211 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5213 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
5214 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5217 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
5218 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
5220 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
5221 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5224 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
5225 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
5226 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
5227 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
5229 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
5230 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5233 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
5235 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
5236 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5244 if (roll_chance_i(10))
5245 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
5248 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
5249 // cast 45479 Light's Wrath if Exalted by Aldor
5250 // cast 45429 Arcane Bolt if Exalted by Scryers
5253 if(GetTypeId() != TYPEID_PLAYER
)
5256 // Get Aldor reputation rank
5257 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5260 triggered_spell_id
= 45479;
5263 // Get Scryers reputation rank
5264 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5266 // triggered at positive/self casts also, current attack target used then
5267 if(IsFriendlyTo(target
))
5269 target
= getVictim();
5272 uint64 selected_guid
= ((Player
*)this)->GetSelection();
5273 target
= ObjectAccessor::GetUnit(*this,selected_guid
);
5277 if(IsFriendlyTo(target
))
5281 triggered_spell_id
= 45429;
5286 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
5287 // cast 45480 Light's Strength if Exalted by Aldor
5288 // cast 45428 Arcane Strike if Exalted by Scryers
5291 if(GetTypeId() != TYPEID_PLAYER
)
5294 // Get Aldor reputation rank
5295 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5298 triggered_spell_id
= 45480;
5301 // Get Scryers reputation rank
5302 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5304 triggered_spell_id
= 45428;
5309 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
5310 // cast 45431 Arcane Insight if Exalted by Aldor
5311 // cast 45432 Light's Ward if Exalted by Scryers
5314 if(GetTypeId() != TYPEID_PLAYER
)
5317 // Get Aldor reputation rank
5318 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5321 triggered_spell_id
= 45432;
5324 // Get Scryers reputation rank
5325 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5328 triggered_spell_id
= 45431;
5333 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
5334 // cast 45478 Light's Salvation if Exalted by Aldor
5335 // cast 45430 Arcane Surge if Exalted by Scryers
5338 if(GetTypeId() != TYPEID_PLAYER
)
5341 // Get Aldor reputation rank
5342 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5345 triggered_spell_id
= 45478;
5348 // Get Scryers reputation rank
5349 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5351 triggered_spell_id
= 45430;
5357 // Sunwell Exalted Caster Neck (??? neck)
5358 // cast ??? Light's Wrath if Exalted by Aldor
5359 // cast ??? Arcane Bolt if Exalted by Scryers*/
5361 return false; // old unused version
5365 triggered_spell_id
= 48503;
5366 basepoints0
= triggerAmount
;
5370 // Vampiric Touch (generic, used by some boss)
5374 triggered_spell_id
= 52724;
5375 basepoints0
= damage
/ 2;
5379 // Shadowfiend Death (Gain mana if pet dies with Glyph of Shadowfiend)
5382 Unit
*owner
= GetOwner();
5383 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
5386 // Glyph of Shadowfiend (need cast as self cast for owner, no hidden cooldown)
5387 owner
->CastSpell(owner
,58227,true,castItem
,triggeredByAura
);
5390 // Glyph of Life Tap
5392 triggered_spell_id
= 63321;
5394 // Item - Shadowmourne Legendary
5397 if (!roll_chance_i(triggerAmount
))
5400 Aura
*aur
= GetAura(71905, 0);
5401 if (aur
&& aur
->GetStackAmount() + 1 >= aur
->GetSpellProto()->StackAmount
)
5403 RemoveAurasDueToSpell(71905);
5404 CastSpell(this, 71904, true); // Chaos Bane
5408 triggered_spell_id
= 71905;
5415 case SPELLFAMILY_MAGE
:
5418 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
5420 if (getPowerType() != POWER_MANA
)
5424 basepoints0
= (triggerAmount
* GetMaxPower(POWER_MANA
) / 100);
5426 triggered_spell_id
= 29442;
5429 // Master of Elements
5430 if (dummySpell
->SpellIconID
== 1920)
5436 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5437 basepoints0
= cost
* triggerAmount
/100;
5438 if( basepoints0
<=0 )
5442 triggered_spell_id
= 29077;
5447 if (dummySpell
->SpellIconID
== 2120)
5453 switch (dummySpell
->Id
)
5455 case 31571: triggered_spell_id
= 57529; break;
5456 case 31572: triggered_spell_id
= 57531; break;
5458 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u",dummySpell
->Id
);
5465 if (dummySpell
->SpellIconID
== 2999)
5469 Aura
*counter
= GetAura(triggeredByAura
->GetId(), 1);
5473 // Count spell criticals in a row in second aura
5474 Modifier
*mod
= counter
->GetModifier();
5475 if (procEx
& PROC_EX_CRITICAL_HIT
)
5478 if (mod
->m_amount
< 100) // not enough
5480 // Crititcal counted -> roll chance
5481 if (roll_chance_i(triggerAmount
))
5482 CastSpell(this, 48108, true, castItem
, triggeredByAura
);
5488 if (dummySpell
->SpellIconID
== 2998)
5493 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5494 basepoints0
= cost
* triggerAmount
/100;
5495 if( basepoints0
<=0 )
5497 triggered_spell_id
= 44450;
5501 // Incanter's Regalia set (add trigger chance to Mana Shield)
5502 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5504 if(GetTypeId() != TYPEID_PLAYER
)
5508 triggered_spell_id
= 37436;
5511 switch(dummySpell
->Id
)
5520 switch (dummySpell
->Id
)
5522 case 11119: basepoints0
= int32(0.04f
*damage
); break;
5523 case 11120: basepoints0
= int32(0.08f
*damage
); break;
5524 case 12846: basepoints0
= int32(0.12f
*damage
); break;
5525 case 12847: basepoints0
= int32(0.16f
*damage
); break;
5526 case 12848: basepoints0
= int32(0.20f
*damage
); break;
5528 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
5532 triggered_spell_id
= 12654;
5538 //last charge and crit
5539 if (triggeredByAura
->GetAuraCharges() <= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
5540 return true; // charge counting (will removed)
5542 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
5543 return (procEx
& PROC_EX_CRITICAL_HIT
); // charge update only at crit hits, no hidden cooldowns
5545 // Glyph of Ice Block
5548 if (GetTypeId() != TYPEID_PLAYER
)
5551 // not 100% safe with client version switches but for 3.1.3 no spells with cooldown that can have mage player except Frost Nova.
5552 ((Player
*)this)->RemoveSpellCategoryCooldown(35, true);
5555 // Glyph of Polymorph
5558 if (!pVictim
|| !pVictim
->isAlive())
5561 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE
);
5562 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE_PERCENT
);
5568 case SPELLFAMILY_WARRIOR
:
5571 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0000000800000000))
5573 // check attack comes not from behind
5574 if (!HasInArc(M_PI
, pVictim
))
5577 triggered_spell_id
= 22858;
5581 if (dummySpell
->SpellIconID
== 1697)
5583 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
5584 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
5586 // Need stun or root mechanic
5587 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_STUN_MASK
))
5590 switch (dummySpell
->Id
)
5592 case 29838: triggered_spell_id
=29842; break;
5593 case 29834: triggered_spell_id
=29841; break;
5594 case 42770: triggered_spell_id
=42771; break;
5596 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
5604 if (dummySpell
->SpellIconID
== 3214)
5606 triggered_spell_id
= 59653;
5607 basepoints0
= GetShieldBlockValue() * triggerAmount
/ 100;
5612 if (dummySpell
->Id
== 12328)
5614 // prevent chain of triggered spell from same triggered spell
5615 if(procSpell
&& procSpell
->Id
== 26654)
5618 target
= SelectNearbyTarget(pVictim
);
5622 triggered_spell_id
= 26654;
5627 case SPELLFAMILY_WARLOCK
:
5629 // Seed of Corruption
5630 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
5632 Modifier
* mod
= triggeredByAura
->GetModifier();
5633 // if damage is more than need or target die from damage deal finish spell
5634 if( mod
->m_amount
<= damage
|| GetHealth() <= damage
)
5636 // remember guid before aura delete
5637 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5639 // Remove aura (before cast for prevent infinite loop handlers)
5640 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5642 // Cast finish spell (triggeredByAura already not exist!)
5643 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
5644 return true; // no hidden cooldown
5648 mod
->m_amount
-=damage
;
5651 // Seed of Corruption (Mobs cast) - no die req
5652 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0) && dummySpell
->SpellIconID
== 1932)
5654 Modifier
* mod
= triggeredByAura
->GetModifier();
5655 // if damage is more than need deal finish spell
5656 if( mod
->m_amount
<= damage
)
5658 // remember guid before aura delete
5659 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5661 // Remove aura (before cast for prevent infinite loop handlers)
5662 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5664 // Cast finish spell (triggeredByAura already not exist!)
5665 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
5666 return true; // no hidden cooldown
5669 mod
->m_amount
-=damage
;
5673 if (dummySpell
->SpellIconID
== 3222)
5678 basepoints0
= damage
* triggerAmount
/ 100;
5679 triggered_spell_id
= 54181;
5682 switch(dummySpell
->Id
)
5684 // Nightfall & Glyph of Corruption
5690 triggered_spell_id
= 17941;
5699 basepoints0
= int32(damage
*triggerAmount
/100);
5701 triggered_spell_id
= 30294;
5704 // Shadowflame (Voidheart Raiment set bonus)
5707 triggered_spell_id
= 37379;
5710 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
5718 basepoints0
= damage
* triggerAmount
/100;
5719 triggered_spell_id
= 37382;
5722 // Shadowflame Hellfire (Voidheart Raiment set bonus)
5725 triggered_spell_id
= 37378;
5731 basepoints0
= int32(damage
* triggerAmount
/ 100);
5732 triggered_spell_id
= 63106;
5738 case SPELLFAMILY_PRIEST
:
5741 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
5743 if(!pVictim
|| !pVictim
->isAlive())
5746 // pVictim is caster of aura
5747 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5750 // Energize 0.25% of max. mana
5751 pVictim
->CastSpell(pVictim
,57669,true,castItem
,triggeredByAura
);
5752 return true; // no hidden cooldown
5755 switch(dummySpell
->SpellIconID
)
5757 // Improved Shadowform
5760 if(!roll_chance_i(triggerAmount
))
5763 RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT
);
5764 RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED
);
5770 basepoints0
= damage
* triggerAmount
/100;
5771 triggered_spell_id
= 47753;
5780 Aura
* healingAura
= pVictim
->GetAura(procSpell
->Id
,0);
5784 int32 healingfromticks
= SpellHealingBonus(pVictim
, procSpell
, (healingAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
)), DOT
);
5785 basepoints0
= healingfromticks
* triggerAmount
/ 100;
5786 triggered_spell_id
= 63544;
5789 // Improved Devouring Plague
5795 Aura
* leachAura
= pVictim
->GetAura(procSpell
->Id
,0);
5799 int32 damagefromticks
= SpellDamageBonus(pVictim
, procSpell
, (leachAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
)), DOT
);
5800 basepoints0
= damagefromticks
* triggerAmount
/ 100;
5801 triggered_spell_id
= 63675;
5806 switch(dummySpell
->Id
)
5811 // Return if self damage
5812 if (this == pVictim
)
5815 // Heal amount - Self/Team
5816 int32 team
= triggerAmount
*damage
/500;
5817 int32 self
= triggerAmount
*damage
/100 - team
;
5818 CastCustomSpell(this,15290,&team
,&self
,NULL
,true,castItem
,triggeredByAura
);
5819 return true; // no hidden cooldown
5821 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
5824 // Shadow Word: Pain
5825 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5826 triggered_spell_id
= 40441;
5828 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
5829 triggered_spell_id
= 40440;
5836 // Oracle Healing Bonus ("Garments of the Oracle" set)
5840 basepoints0
= int32(damage
* 10/100);
5842 triggered_spell_id
= 26170;
5845 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
5848 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
5852 basepoints0
= damage
* triggerAmount
/100;
5854 triggered_spell_id
= 39373;
5857 // Greater Heal (Vestments of Faith (Priest Tier 3) - 4 pieces bonus)
5860 triggered_spell_id
= 28810;
5863 // Glyph of Dispel Magic
5866 if(!target
->IsFriendlyTo(this))
5869 basepoints0
= int32(target
->GetMaxHealth() * triggerAmount
/ 100);
5870 triggered_spell_id
= 56131;
5876 case SPELLFAMILY_DRUID
:
5878 switch(dummySpell
->Id
)
5880 // Leader of the Pack
5883 // dummy m_amount store health percent (!=0 if Improved Leader of the Pack applied)
5884 int32 heal_percent
= triggeredByAura
->GetModifier()->m_amount
;
5888 // check explicitly only to prevent mana cast when halth cast cooldown
5889 if (cooldown
&& ((Player
*)this)->HasSpellCooldown(34299))
5893 triggered_spell_id
= 34299;
5894 basepoints0
= GetMaxHealth() * heal_percent
/ 100;
5898 if (triggeredByAura
->GetCasterGUID() == GetGUID())
5900 if (SpellEntry
const* manaCastEntry
= sSpellStore
.LookupEntry(60889))
5902 int32 mana_percent
= manaCastEntry
->CalculateSimpleValue(0) * heal_percent
;
5903 CastCustomSpell(this, manaCastEntry
, &mana_percent
, NULL
, NULL
, true, castItem
, triggeredByAura
);
5908 // Healing Touch (Dreamwalker Raiment set)
5912 basepoints0
= int32(procSpell
->manaCost
* 30 / 100);
5914 triggered_spell_id
= 28742;
5917 // Healing Touch Refund (Idol of Longevity trinket)
5921 triggered_spell_id
= 28848;
5924 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
5929 triggered_spell_id
= 37238;
5932 // Druid Tier 6 Trinket
5938 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
5940 triggered_spell_id
= 40445;
5944 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
5946 triggered_spell_id
= 40446;
5949 // Mangle (Bear) and Mangle (Cat)
5950 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000044000000000))
5952 triggered_spell_id
= 40452;
5958 if (!roll_chance_f(chance
))
5967 // Deadly Interrupt Effect
5968 triggered_spell_id
= 32747;
5971 // Glyph of Rejuvenation
5975 if (pVictim
->GetMaxHealth() < 2 * pVictim
->GetHealth())
5977 basepoints0
= triggerAmount
* damage
/ 100;
5978 triggered_spell_id
= 54755;
5983 if (dummySpell
->SpellIconID
== 2856)
5987 // Only 0 aura can proc
5991 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
5995 if (!roll_chance_i(60))
5997 triggered_spell_id
= 48518;
6002 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
6006 triggered_spell_id
= 48517;
6013 else if (dummySpell
->SpellIconID
== 2860)
6015 triggered_spell_id
= 48504;
6016 basepoints0
= triggerAmount
* damage
/ 100;
6021 case SPELLFAMILY_ROGUE
:
6023 switch(dummySpell
->Id
)
6025 // Deadly Throw Interrupt
6028 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
6029 if (this == pVictim
)
6032 triggered_spell_id
= 32747;
6037 if (dummySpell
->SpellIconID
== 2909)
6039 // "refresh your Slice and Dice duration to its 5 combo point maximum"
6040 // lookup Slice and Dice
6041 AuraList
const& sd
= GetAurasByType(SPELL_AURA_MOD_HASTE
);
6042 for(AuraList::const_iterator itr
= sd
.begin(); itr
!= sd
.end(); ++itr
)
6044 SpellEntry
const *spellProto
= (*itr
)->GetSpellProto();
6045 if (spellProto
->SpellFamilyName
== SPELLFAMILY_ROGUE
&&
6046 (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000040000)))
6048 (*itr
)->SetAuraMaxDuration(GetSpellMaxDuration(spellProto
));
6049 (*itr
)->RefreshAura();
6056 if (dummySpell
->SpellIconID
== 2963)
6058 triggered_spell_id
= 44289;
6062 if (dummySpell
->SpellIconID
== 2116)
6068 basepoints0
= procSpell
->manaCost
* triggerAmount
/100;
6069 if (basepoints0
<= 0)
6073 triggered_spell_id
= 31663;
6078 case SPELLFAMILY_HUNTER
:
6080 // Aspect of the Viper
6081 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x4000000000000))
6083 uint32 maxmana
= GetMaxPower(POWER_MANA
);
6084 basepoints0
= int32(maxmana
* GetAttackTime(RANGED_ATTACK
)/1000.0f
/100.0f
);
6087 triggered_spell_id
= 34075;
6090 // Thrill of the Hunt
6091 if (dummySpell
->SpellIconID
== 2236)
6097 int32 mana
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
6098 basepoints0
= mana
* 40/100;
6099 if(basepoints0
<= 0)
6103 triggered_spell_id
= 34720;
6107 if ( dummySpell
->SpellIconID
== 3406 )
6109 triggered_spell_id
= 57669;
6114 if ( dummySpell
->SpellIconID
== 3579 )
6116 // Proc only from periodic (from trap activation proc another aura of this spell)
6117 if (!(procFlag
& PROC_FLAG_ON_DO_PERIODIC
) || !roll_chance_i(triggerAmount
))
6119 triggered_spell_id
= 56453;
6123 // Rapid Recuperation
6124 if ( dummySpell
->SpellIconID
== 3560 )
6126 // This effect only from Rapid Killing (mana regen)
6127 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0100000000000000)))
6132 switch(dummySpell
->Id
)
6134 case 53228: // Rank 1
6135 triggered_spell_id
= 56654;
6137 case 53232: // Rank 2
6138 triggered_spell_id
= 58882;
6143 // Glyph of Mend Pet
6144 if(dummySpell
->Id
== 57870)
6146 pVictim
->CastSpell(pVictim
, 57894, true, NULL
, NULL
, GetGUID());
6151 case SPELLFAMILY_PALADIN
:
6153 // Seal of Righteousness - melee proc dummy (addition ${$MWS*(0.022*$AP+0.044*$SPH)} damage)
6154 if ((dummySpell
->SpellFamilyFlags
& UI64LIT(0x000000008000000)) && effIndex
==0)
6156 triggered_spell_id
= 25742;
6157 float ap
= GetTotalAttackPowerValue(BASE_ATTACK
);
6158 int32 holy
= SpellBaseDamageBonus(SPELL_SCHOOL_MASK_HOLY
) +
6159 SpellBaseDamageBonusForVictim(SPELL_SCHOOL_MASK_HOLY
, pVictim
);
6160 basepoints0
= GetAttackTime(BASE_ATTACK
) * int32(ap
*0.022f
+ 0.044f
* holy
) / 1000;
6163 // Righteous Vengeance
6164 if (dummySpell
->SpellIconID
== 3025)
6167 basepoints0
= triggerAmount
*damage
/400;
6168 triggered_spell_id
= 61840;
6172 if (dummySpell
->SpellIconID
== 3030)
6175 basepoints0
= triggerAmount
*damage
/400;
6176 triggered_spell_id
= 54203;
6179 switch(dummySpell
->Id
)
6181 // Judgement of Light
6184 basepoints0
= int32( pVictim
->GetMaxHealth() * triggeredByAura
->GetModifier()->m_amount
/ 100 );
6185 pVictim
->CastCustomSpell(pVictim
, 20267, &basepoints0
, NULL
, NULL
, true, NULL
, triggeredByAura
);
6188 // Judgement of Wisdom
6191 if (pVictim
->getPowerType() == POWER_MANA
)
6193 // 2% of maximum base mana
6194 basepoints0
= int32(pVictim
->GetCreateMana() * 2 / 100);
6195 pVictim
->CastCustomSpell(pVictim
, 20268, &basepoints0
, NULL
, NULL
, true, NULL
, triggeredByAura
);
6199 // Heart of the Crusader (Rank 1)
6201 triggered_spell_id
= 21183;
6203 // Heart of the Crusader (Rank 2)
6205 triggered_spell_id
= 54498;
6207 // Heart of the Crusader (Rank 3)
6209 triggered_spell_id
= 54499;
6211 case 20911: // Blessing of Sanctuary
6212 case 25899: // Greater Blessing of Sanctuary
6215 switch (target
->getPowerType())
6218 triggered_spell_id
= 57319;
6225 // Holy Power (Redemption Armor set)
6231 // Set class defined buff
6232 switch (pVictim
->getClass())
6238 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6242 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6246 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
6249 triggered_spell_id
= 28790; // Increases the friendly target's armor
6256 // Spiritual Attunement
6260 // if healed by another unit (pVictim)
6265 basepoints0
= triggerAmount
*damage
/100;
6267 triggered_spell_id
= 31786;
6270 // Seal of Vengeance (damage calc on apply aura)
6273 if(effIndex
!= 0) // effect 1,2 used by seal unleashing code
6276 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6277 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595) )
6278 triggered_spell_id
= 31803; // Holy Vengeance
6280 // Add 5-stack effect from Holy Vengeance
6282 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6283 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6285 if( ((*itr
)->GetId() == 31803) && (*itr
)->GetCasterGUID()==GetGUID())
6287 stacks
= (*itr
)->GetStackAmount();
6292 CastSpell(target
,42463,true,NULL
,triggeredByAura
);
6295 // Judgements of the Wise
6299 // triggered only at casted Judgement spells, not at additional Judgement effects
6300 if(!procSpell
|| procSpell
->Category
!= 1210)
6304 triggered_spell_id
= 31930;
6307 CastSpell(this, 57669, true, NULL
, triggeredByAura
);
6309 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
6317 // Flash of light/Holy light
6318 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x00000000C0000000))
6320 triggered_spell_id
= 40471;
6324 else if (GetSpellSpecific(procSpell
->Id
)==SPELL_JUDGEMENT
)
6326 triggered_spell_id
= 40472;
6332 if (!roll_chance_f(chance
))
6337 // Light's Beacon (heal target area aura)
6340 // not do bonus heal for explicit beacon focus healing
6341 if (GetGUID() == triggeredByAura
->GetCasterGUID())
6345 Unit
* beacon
= triggeredByAura
->GetCaster();
6349 // find caster main aura at beacon
6351 Unit::AuraList
const& baa
= beacon
->GetAurasByType(SPELL_AURA_PERIODIC_TRIGGER_SPELL
);
6352 for(Unit::AuraList::const_iterator i
= baa
.begin(); i
!= baa
.end(); ++i
)
6354 if ((*i
)->GetId() == 53563 && (*i
)->GetCasterGUID() == pVictim
->GetGUID())
6361 // original heal must be form beacon caster
6365 triggered_spell_id
= 53652; // Beacon of Light
6366 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*damage
/100;
6368 // cast with original caster set but beacon to beacon for apply caster mods and avoid LoS check
6369 beacon
->CastCustomSpell(beacon
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
,pVictim
->GetGUID());
6372 // Seal of Corruption (damage calc on apply aura)
6375 if(effIndex
!= 0) // effect 1,2 used by seal unleashing code
6378 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6379 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595))
6380 triggered_spell_id
= 53742; // Blood Corruption
6382 // Add 5-stack effect from Blood Corruption
6384 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6385 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6387 if( ((*itr
)->GetId() == 53742) && (*itr
)->GetCasterGUID()==GetGUID())
6389 stacks
= (*itr
)->GetStackAmount();
6394 CastSpell(target
,53739,true,NULL
,triggeredByAura
);
6397 // Glyph of Flash of Light
6400 triggered_spell_id
= 54957;
6401 basepoints0
= triggerAmount
*damage
/100;
6404 // Glyph of Holy Light
6407 triggered_spell_id
= 54968;
6408 basepoints0
= triggerAmount
*damage
/100;
6411 // Glyph of Divinity
6414 // Lookup base amount mana restore
6415 for (int i
=0; i
<3;++i
)
6416 if (procSpell
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
6418 int32 mana
= procSpell
->EffectBasePoints
[i
];
6419 CastCustomSpell(this, 54986, NULL
, &mana
, NULL
, true, castItem
, triggeredByAura
);
6424 // Sacred Shield (buff)
6427 triggered_spell_id
= 66922;
6428 SpellEntry
const* triggeredEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6429 if (!triggeredEntry
)
6432 basepoints0
= int32(damage
/ (GetSpellDuration(triggeredEntry
) / triggeredEntry
->EffectAmplitude
[0]));
6436 // Sacred Shield (talent rank)
6439 triggered_spell_id
= 58597;
6446 case SPELLFAMILY_SHAMAN
:
6448 switch(dummySpell
->Id
)
6450 // Totemic Power (The Earthshatterer set)
6456 // Set class defined buff
6457 switch (pVictim
->getClass())
6463 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6467 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6471 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
6474 triggered_spell_id
= 28827; // Increases the friendly target's armor
6481 // Lesser Healing Wave (Totem of Flowing Water Relic)
6485 triggered_spell_id
= 28850;
6488 // Windfury Weapon (Passive) 1-5 Ranks
6491 if(GetTypeId()!=TYPEID_PLAYER
)
6494 if(!castItem
|| !castItem
->IsEquipped())
6497 // custom cooldown processing case
6498 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6501 // Now amount of extra power stored in 1 effect of Enchant spell
6502 // Get it by item enchant id
6504 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
6506 case 283: spellId
= 8232; break; // 1 Rank
6507 case 284: spellId
= 8235; break; // 2 Rank
6508 case 525: spellId
= 10486; break; // 3 Rank
6509 case 1669:spellId
= 16362; break; // 4 Rank
6510 case 2636:spellId
= 25505; break; // 5 Rank
6511 case 3785:spellId
= 58801; break; // 6 Rank
6512 case 3786:spellId
= 58803; break; // 7 Rank
6513 case 3787:spellId
= 58804; break; // 8 Rank
6516 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
6517 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
6522 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
6523 if(!windfurySpellEntry
)
6525 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
6529 int32 extra_attack_power
= CalculateSpellDamage(windfurySpellEntry
, 1, windfurySpellEntry
->EffectBasePoints
[1], pVictim
);
6532 if ( castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
6534 // Value gained from additional AP
6535 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
6536 triggered_spell_id
= 33750;
6541 // Value gained from additional AP
6542 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
6543 triggered_spell_id
= 25504;
6546 // apply cooldown before cast to prevent processing itself
6548 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6551 for ( uint32 i
= 0; i
<2; ++i
)
6552 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6556 // Shaman Tier 6 Trinket
6563 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6565 triggered_spell_id
= 40465; // Lightning Bolt
6568 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080))
6570 triggered_spell_id
= 40465; // Lesser Healing Wave
6573 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
6575 triggered_spell_id
= 40466; // Stormstrike
6581 if (!roll_chance_f(chance
))
6587 // Glyph of Healing Wave
6590 // Not proc from self heals
6593 basepoints0
= triggerAmount
* damage
/ 100;
6595 triggered_spell_id
= 55533;
6602 target
= GetOwner();
6605 basepoints0
= triggerAmount
* damage
/ 100;
6606 triggered_spell_id
= 58879;
6609 // Shaman T8 Elemental 4P Bonus
6612 basepoints0
= int32( triggerAmount
* damage
/ 100 );
6613 triggered_spell_id
= 64930; // Electrified
6617 // Storm, Earth and Fire
6618 if (dummySpell
->SpellIconID
== 3063)
6620 // Earthbind Totem summon only
6621 if(procSpell
->Id
!= 2484)
6624 float chance
= triggerAmount
;
6625 if (!roll_chance_f(chance
))
6628 triggered_spell_id
= 64695;
6631 // Ancestral Awakening
6632 if (dummySpell
->SpellIconID
== 3065)
6634 triggered_spell_id
= 52759;
6635 basepoints0
= triggerAmount
* damage
/ 100;
6640 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
6643 basepoints0
= triggerAmount
;
6645 // Glyph of Earth Shield
6646 if (Aura
* aur
= GetDummyAura(63279))
6648 int32 aur_mod
= aur
->GetModifier()->m_amount
;
6649 basepoints0
= int32(basepoints0
* (aur_mod
+ 100.0f
) / 100.0f
);
6652 triggered_spell_id
= 379;
6655 // Improved Water Shield
6656 if (dummySpell
->SpellIconID
== 2287)
6658 // Lesser Healing Wave need aditional 60% roll
6659 if ((procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)) && !roll_chance_i(60))
6661 // lookup water shield
6662 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6663 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6665 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6666 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000002000000000)))
6668 uint32 spell
= (*itr
)->GetSpellProto()->EffectTriggerSpell
[(*itr
)->GetEffIndex()];
6669 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
6670 if ((*itr
)->DropAuraCharge())
6671 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6678 // Lightning Overload
6679 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
6681 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
6684 // custom cooldown processing case
6685 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6689 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
6690 switch (procSpell
->Id
)
6693 case 403: spellId
= 45284; break; // Rank 1
6694 case 529: spellId
= 45286; break; // Rank 2
6695 case 548: spellId
= 45287; break; // Rank 3
6696 case 915: spellId
= 45288; break; // Rank 4
6697 case 943: spellId
= 45289; break; // Rank 5
6698 case 6041: spellId
= 45290; break; // Rank 6
6699 case 10391: spellId
= 45291; break; // Rank 7
6700 case 10392: spellId
= 45292; break; // Rank 8
6701 case 15207: spellId
= 45293; break; // Rank 9
6702 case 15208: spellId
= 45294; break; // Rank 10
6703 case 25448: spellId
= 45295; break; // Rank 11
6704 case 25449: spellId
= 45296; break; // Rank 12
6705 case 49237: spellId
= 49239; break; // Rank 13
6706 case 49238: spellId
= 49240; break; // Rank 14
6708 case 421: spellId
= 45297; break; // Rank 1
6709 case 930: spellId
= 45298; break; // Rank 2
6710 case 2860: spellId
= 45299; break; // Rank 3
6711 case 10605: spellId
= 45300; break; // Rank 4
6712 case 25439: spellId
= 45301; break; // Rank 5
6713 case 25442: spellId
= 45302; break; // Rank 6
6714 case 49270: spellId
= 49268; break; // Rank 7
6715 case 49271: spellId
= 49269; break; // Rank 8
6717 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
6720 // No thread generated mod
6721 // TODO: exist special flag in spell attributes for this, need found and use!
6722 SpellModifier
*mod
= new SpellModifier(SPELLMOD_THREAT
,SPELLMOD_PCT
,-100,triggeredByAura
);
6724 ((Player
*)this)->AddSpellMod(mod
, true);
6726 // Remove cooldown (Chain Lightning - have Category Recovery time)
6727 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000002))
6728 ((Player
*)this)->RemoveSpellCooldown(spellId
);
6730 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
6732 ((Player
*)this)->AddSpellMod(mod
, false);
6734 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6735 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6740 if(dummySpell
->SpellIconID
== 3059)
6742 // lookup Lightning Shield
6743 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6744 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6746 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6747 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000400)))
6750 switch ((*itr
)->GetId())
6752 case 324: spell
= 26364; break;
6753 case 325: spell
= 26365; break;
6754 case 905: spell
= 26366; break;
6755 case 945: spell
= 26367; break;
6756 case 8134: spell
= 26369; break;
6757 case 10431: spell
= 26370; break;
6758 case 10432: spell
= 26363; break;
6759 case 25469: spell
= 26371; break;
6760 case 25472: spell
= 26372; break;
6761 case 49280: spell
= 49278; break;
6762 case 49281: spell
= 49279; break;
6766 CastSpell(target
, spell
, true, castItem
, triggeredByAura
);
6767 if ((*itr
)->DropAuraCharge())
6768 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6775 if (dummySpell
->SpellIconID
== 3780)
6777 Unit
*caster
= triggeredByAura
->GetCaster();
6779 if (!procSpell
|| !caster
)
6782 float distance
= caster
->GetDistance(pVictim
);
6783 int32 chance
= triggerAmount
;
6785 if (distance
< 15.0f
|| !roll_chance_i(chance
))
6788 // make triggered cast apply after current damage spell processing for prevent remove by it
6789 if(Spell
* spell
= GetCurrentSpell(CURRENT_GENERIC_SPELL
))
6790 spell
->AddTriggeredSpell(63685);
6795 case SPELLFAMILY_DEATHKNIGHT
:
6798 if (dummySpell
->SpellIconID
== 2636)
6800 if (GetTypeId() != TYPEID_PLAYER
|| !((Player
*)this)->isHonorOrXPTarget(pVictim
))
6802 basepoints0
= triggerAmount
* damage
/ 100;
6803 triggered_spell_id
= 53168;
6807 if (dummySpell
->SpellIconID
== 2664)
6809 basepoints0
= triggerAmount
;
6810 triggered_spell_id
= 50163;
6814 // Dancing Rune Weapon
6815 if (dummySpell
->Id
== 49028)
6817 // 1 dummy aura for dismiss rune blade
6820 // TODO: wite script for this "fights on its own, doing the same attacks"
6821 // NOTE: Trigger here on every attack and spell cast
6825 if (dummySpell
->Id
== 49005)
6827 // TODO: need more info (cooldowns/PPM)
6828 triggered_spell_id
= 61607;
6832 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000010000))
6834 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
6835 triggered_spell_id
= 50181;
6840 if (dummySpell
->SpellIconID
== 2709)
6842 basepoints0
= triggerAmount
* damage
/ 100;
6843 triggered_spell_id
= 51460;
6846 // Threat of Thassarian
6847 if (dummySpell
->SpellIconID
== 2023)
6850 if (!procSpell
|| !haveOffhandWeapon())
6852 // Chance as basepoints for dummy aura
6853 if (!roll_chance_i(triggerAmount
))
6856 switch (procSpell
->Id
)
6859 case 49020: // Rank 1
6860 triggered_spell_id
= 66198; break;
6861 case 51423: // Rank 2
6862 triggered_spell_id
= 66972; break;
6863 case 51424: // Rank 3
6864 triggered_spell_id
= 66973; break;
6865 case 51425: // Rank 4
6866 triggered_spell_id
= 66974; break;
6868 case 49143: // Rank 1
6869 triggered_spell_id
= 66196; break;
6870 case 51416: // Rank 2
6871 triggered_spell_id
= 66958; break;
6872 case 51417: // Rank 3
6873 triggered_spell_id
= 66959; break;
6874 case 51418: // Rank 4
6875 triggered_spell_id
= 66960; break;
6876 case 51419: // Rank 5
6877 triggered_spell_id
= 66961; break;
6878 case 51420: // Rank 6
6879 triggered_spell_id
= 66962; break;
6881 case 45462: // Rank 1
6882 triggered_spell_id
= 66216; break;
6883 case 49917: // Rank 2
6884 triggered_spell_id
= 66988; break;
6885 case 49918: // Rank 3
6886 triggered_spell_id
= 66989; break;
6887 case 49919: // Rank 4
6888 triggered_spell_id
= 66990; break;
6889 case 49920: // Rank 5
6890 triggered_spell_id
= 66991; break;
6891 case 49921: // Rank 6
6892 triggered_spell_id
= 66992; break;
6894 case 49998: // Rank 1
6895 triggered_spell_id
= 66188; break;
6896 case 49999: // Rank 2
6897 triggered_spell_id
= 66950; break;
6898 case 45463: // Rank 3
6899 triggered_spell_id
= 66951; break;
6900 case 49923: // Rank 4
6901 triggered_spell_id
= 66952; break;
6902 case 49924: // Rank 5
6903 triggered_spell_id
= 66953; break;
6906 triggered_spell_id
= 66217; break;
6908 case 45902: // Rank 1
6909 triggered_spell_id
= 66215; break;
6910 case 49926: // Rank 2
6911 triggered_spell_id
= 66975; break;
6912 case 49927: // Rank 3
6913 triggered_spell_id
= 66976; break;
6914 case 49928: // Rank 4
6915 triggered_spell_id
= 66977; break;
6916 case 49929: // Rank 5
6917 triggered_spell_id
= 66978; break;
6918 case 49930: // Rank 6
6919 triggered_spell_id
= 66979; break;
6925 // Runic Power Back on Snare/Root
6926 if (dummySpell
->Id
== 61257)
6928 // only for spells and hit/crit (trigger start always) and not start from self casted spells
6929 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
6931 // Need snare or root mechanic
6932 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_SNARE_MASK
))
6934 triggered_spell_id
= 61258;
6939 if (dummySpell
->SpellIconID
== 1614)
6941 if (!roll_chance_f(GetUnitCriticalChance(BASE_ATTACK
, pVictim
)))
6943 basepoints0
= triggerAmount
* damage
/ 100;
6944 triggered_spell_id
= 50526;
6947 // Blood-Caked Blade
6948 if (dummySpell
->SpellIconID
== 138)
6950 triggered_spell_id
= dummySpell
->EffectTriggerSpell
[effIndex
];
6959 // processed charge only counting case
6960 if(!triggered_spell_id
)
6963 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6967 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
6972 if(!target
|| target
!=this && !target
->isAlive())
6975 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
6979 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6981 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
6983 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6984 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
6989 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
6991 // Get triggered aura spell info
6992 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
6994 // Basepoints of trigger aura
6995 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
6997 // Set trigger spell id, target, custom basepoints
6998 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
6999 Unit
* target
= NULL
;
7000 int32 basepoints
[3] = {0, 0, 0};
7002 if(triggeredByAura
->GetModifier()->m_auraname
== SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
)
7003 basepoints
[0] = triggerAmount
;
7005 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7006 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7008 // Try handle unknown trigger spells
7009 // Custom requirements (not listed in procEx) Warning! damage dealing after this
7010 // Custom triggered spells
7011 switch (auraSpellInfo
->SpellFamilyName
)
7013 case SPELLFAMILY_GENERIC
:
7014 switch(auraSpellInfo
->Id
)
7016 //case 191: // Elemental Response
7017 // switch (procSpell->School)
7019 // case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192; break;
7020 // case SPELL_SCHOOL_FROST: trigger_spell_id = 34193; break;
7021 // case SPELL_SCHOOL_ARCANE:trigger_spell_id = 34194; break;
7022 // case SPELL_SCHOOL_NATURE:trigger_spell_id = 34195; break;
7023 // case SPELL_SCHOOL_SHADOW:trigger_spell_id = 34196; break;
7024 // case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197; break;
7025 // case SPELL_SCHOOL_NORMAL:trigger_spell_id = 34198; break;
7028 //case 5301: break; // Defensive State (DND)
7029 //case 7137: break: // Shadow Charge (Rank 1)
7030 //case 7377: break: // Take Immune Periodic Damage <Not Working>
7031 //case 13358: break; // Defensive State (DND)
7032 //case 16092: break; // Defensive State (DND)
7033 //case 18943: break; // Double Attack
7034 //case 19194: break; // Double Attack
7035 //case 19817: break; // Double Attack
7036 //case 19818: break; // Double Attack
7037 //case 22835: break; // Drunken Rage
7038 // trigger_spell_id = 14822; break;
7039 case 23780: // Aegis of Preservation (Aegis of Preservation trinket)
7040 trigger_spell_id
= 23781;
7042 //case 24949: break; // Defensive State 2 (DND)
7043 case 27522: // Mana Drain Trigger
7044 case 40336: // Mana Drain Trigger
7045 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
7047 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
7048 if (pVictim
&& pVictim
->isAlive())
7049 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
7051 case 31255: // Deadly Swiftness (Rank 1)
7052 // whenever you deal damage to a target who is below 20% health.
7053 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
7057 trigger_spell_id
= 22588;
7059 //case 33207: break; // Gossip NPC Periodic - Fidget
7060 case 33896: // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
7061 trigger_spell_id
= 33898;
7063 //case 34082: break; // Advantaged State (DND)
7064 //case 34783: break: // Spell Reflection
7065 //case 35205: break: // Vanish
7066 //case 35321: break; // Gushing Wound
7067 //case 36096: break: // Spell Reflection
7068 //case 36207: break: // Steal Weapon
7069 //case 36576: break: // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
7070 //case 37030: break; // Chaotic Temperament
7071 //case 38363: break; // Gushing Wound
7072 //case 39215: break; // Gushing Wound
7073 //case 40250: break; // Improved Duration
7074 //case 40329: break; // Demo Shout Sensor
7075 //case 40364: break; // Entangling Roots Sensor
7076 //case 41054: break; // Copy Weapon
7077 // trigger_spell_id = 41055; break;
7078 //case 41248: break; // Consuming Strikes
7079 // trigger_spell_id = 41249; break;
7080 //case 42730: break: // Woe Strike
7081 //case 43453: break: // Rune Ward
7082 //case 43504: break; // Alterac Valley OnKill Proc Aura
7083 //case 44326: break: // Pure Energy Passive
7084 //case 44526: break; // Hate Monster (Spar) (30 sec)
7085 //case 44527: break; // Hate Monster (Spar Buddy) (30 sec)
7086 //case 44819: break; // Hate Monster (Spar Buddy) (>30% Health)
7087 //case 44820: break; // Hate Monster (Spar) (<30%)
7088 case 45057: // Evasive Maneuvers (Commendation of Kael`thas trinket)
7089 // reduce you below $s1% health
7090 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
7093 //case 45903: break: // Offensive State
7094 //case 46146: break: // [PH] Ahune Spanky Hands
7095 //case 46939: break; // Black Bow of the Betrayer
7096 // trigger_spell_id = 29471; - gain mana
7097 // 27526; - drain mana if possible
7098 case 43820: // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
7099 // Pct value stored in dummy
7100 basepoints
[0] = pVictim
->GetCreateHealth() * auraSpellInfo
->EffectBasePoints
[1] / 100;
7103 //case 45205: break; // Copy Offhand Weapon
7104 //case 45343: break; // Dark Flame Aura
7105 //case 47300: break; // Dark Flame Aura
7106 //case 48876: break; // Beast's Mark
7107 // trigger_spell_id = 48877; break;
7108 //case 49059: break; // Horde, Hate Monster (Spar Buddy) (>30% Health)
7109 //case 50051: break; // Ethereal Pet Aura
7110 //case 50689: break; // Blood Presence (Rank 1)
7111 //case 50844: break; // Blood Mirror
7112 //case 52856: break; // Charge
7113 //case 54072: break; // Knockback Ball Passive
7114 //case 54476: break; // Blood Presence
7115 //case 54775: break; // Abandon Vehicle on Poly
7116 case 57345: // Darkmoon Card: Greatness
7120 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 60229;stat
= GetStat(STAT_STRENGTH
); }
7122 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 60233;stat
= GetStat(STAT_AGILITY
); }
7124 if (GetStat(STAT_INTELLECT
)> stat
) { trigger_spell_id
= 60234;stat
= GetStat(STAT_INTELLECT
);}
7126 if (GetStat(STAT_SPIRIT
) > stat
) { trigger_spell_id
= 60235; }
7129 //case 55580: break: // Mana Link
7130 //case 57587: break: // Steal Ranged ()
7131 //case 57594: break; // Copy Ranged Weapon
7132 //case 59237: break; // Beast's Mark
7133 // trigger_spell_id = 59233; break;
7134 //case 59288: break; // Infra-Green Shield
7135 //case 59532: break; // Abandon Passengers on Poly
7136 //case 59735: break: // Woe Strike
7137 case 67702: // Death's Choice, Item - Coliseum 25 Normal Melee Trinket
7141 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67708;stat
= GetStat(STAT_STRENGTH
); }
7143 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67703; }
7146 case 67771: // Death's Choice (heroic), Item - Coliseum 25 Heroic Melee Trinket
7150 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67773;stat
= GetStat(STAT_STRENGTH
); }
7152 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67772; }
7157 case SPELLFAMILY_MAGE
:
7158 if (auraSpellInfo
->SpellIconID
== 2127) // Blazing Speed
7160 switch (auraSpellInfo
->Id
)
7162 case 31641: // Rank 1
7163 case 31642: // Rank 2
7164 trigger_spell_id
= 31643;
7167 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
7171 // Persistent Shield (Scarab Brooch trinket)
7172 else if(auraSpellInfo
->Id
== 26467)
7174 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
7175 basepoints
[0] = damage
* 15 / 100;
7177 trigger_spell_id
= 26470;
7180 case SPELLFAMILY_WARRIOR
:
7181 // Deep Wounds (replace triggered spells to directly apply DoT), dot spell have finilyflags
7182 if (auraSpellInfo
->SpellFamilyFlags
== UI64LIT(0x0) && auraSpellInfo
->SpellIconID
== 243)
7185 // DW should benefit of attack power, damage percent mods etc.
7186 // TODO: check if using offhand damage is correct and if it should be divided by 2
7187 if (haveOffhandWeapon() && getAttackTimer(BASE_ATTACK
) > getAttackTimer(OFF_ATTACK
))
7188 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
))/2;
7190 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXDAMAGE
))/2;
7192 switch (auraSpellInfo
->Id
)
7194 case 12834: basepoints
[0] = int32(weaponDamage
* 16 / 100); break;
7195 case 12849: basepoints
[0] = int32(weaponDamage
* 32 / 100); break;
7196 case 12867: basepoints
[0] = int32(weaponDamage
* 48 / 100); break;
7199 sLog
.outError("Unit::HandleProcTriggerSpell: DW unknown spell rank %u",auraSpellInfo
->Id
);
7203 // 1 tick/sec * 6 sec = 6 ticks
7206 trigger_spell_id
= 12721;
7209 if (auraSpellInfo
->Id
== 50421) // Scent of Blood
7210 trigger_spell_id
= 50422;
7212 case SPELLFAMILY_WARLOCK
:
7215 if (auraSpellInfo
->SpellIconID
== 1137)
7217 if(!pVictim
|| !pVictim
->isAlive() || pVictim
== this || procSpell
== NULL
)
7219 // Calculate spell tick count for spells
7220 uint32 tick
= 1; // Default tick = 1
7222 // Hellfire have 15 tick
7223 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000040))
7225 // Rain of Fire have 4 tick
7226 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000020))
7231 // Calculate chance = baseChance / tick
7233 switch (auraSpellInfo
->Id
)
7235 case 18096: chance
= 13.0f
/ tick
; break;
7236 case 18073: chance
= 26.0f
/ tick
; break;
7239 if (!roll_chance_f(chance
))
7242 trigger_spell_id
= 18093;
7245 else if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
7247 Unit::AuraList
const& mAddFlatModifier
= GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER
);
7248 for(Unit::AuraList::const_iterator i
= mAddFlatModifier
.begin(); i
!= mAddFlatModifier
.end(); ++i
)
7250 if ((*i
)->GetModifier()->m_miscvalue
== SPELLMOD_CHANCE_OF_SUCCESS
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
7253 CastCustomSpell(this, 18371, &basepoints
[0], NULL
, NULL
, true, castItem
, triggeredByAura
);
7257 // Not remove charge (aura removed on death in any cases)
7258 // Need for correct work Drain Soul SPELL_AURA_CHANNEL_DEATH_ITEM aura
7261 // Nether Protection
7262 else if (auraSpellInfo
->SpellIconID
== 1985)
7266 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7268 case SPELL_SCHOOL_NORMAL
:
7269 return false; // ignore
7270 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 54370; break;
7271 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 54371; break;
7272 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 54375; break;
7273 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 54372; break;
7274 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 54374; break;
7275 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
7281 else if (auraSpellInfo
->Id
== 28845)
7283 // When your health drops below 20% ....
7284 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
7288 else if (auraSpellInfo
->Id
== 63156 || auraSpellInfo
->Id
== 63158)
7290 // Looking for dummy effect
7291 Aura
*aur
= GetAura(auraSpellInfo
->Id
, 1);
7295 // If target's health is not below equal certain value (35%) not proc
7296 if ((pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth()) > aur
->GetModifier()->m_amount
)
7301 case SPELLFAMILY_PRIEST
:
7303 // Greater Heal Refund (Avatar Raiment set)
7304 if (auraSpellInfo
->Id
==37594)
7306 // Not give if target already have full health
7307 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
7309 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
7310 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
7312 trigger_spell_id
= 37595;
7315 else if (auraSpellInfo
->SpellIconID
== 1875)
7317 switch (auraSpellInfo
->Id
)
7319 case 27811: trigger_spell_id
= 27813; break;
7320 case 27815: trigger_spell_id
= 27817; break;
7321 case 27816: trigger_spell_id
= 27818; break;
7323 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
7326 basepoints
[0] = damage
* triggerAmount
/ 100 / 3;
7331 case SPELLFAMILY_DRUID
:
7333 // Druid Forms Trinket
7334 if (auraSpellInfo
->Id
==37336)
7338 case FORM_NONE
: trigger_spell_id
= 37344;break;
7339 case FORM_CAT
: trigger_spell_id
= 37341;break;
7341 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
7342 case FORM_TREE
: trigger_spell_id
= 37342;break;
7343 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
7348 // Druid T9 Feral Relic (Lacerate, Swipe, Mangle, and Shred)
7349 else if (auraSpellInfo
->Id
==67353)
7353 case FORM_CAT
: trigger_spell_id
= 67355; break;
7355 case FORM_DIREBEAR
: trigger_spell_id
= 67354; break;
7362 case SPELLFAMILY_HUNTER
:
7364 if (auraSpellInfo
->SpellIconID
== 3247 && auraSpellInfo
->SpellVisual
[0] == 0)
7366 basepoints
[0] = damage
* triggerAmount
/ 100 / 8;
7367 trigger_spell_id
= 63468;
7370 // Rapid Recuperation
7371 else if (auraSpellInfo
->Id
== 53228 || auraSpellInfo
->Id
== 53232)
7373 // This effect only from Rapid Fire (ability cast)
7374 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000020)))
7378 case SPELLFAMILY_PALADIN
:
7382 if (auraSpellInfo->SpellIconID == 2137)
7384 switch (auraSpellInfo->Id)
7386 case 31828: // Rank 1
7387 case 31829: // Rank 2
7388 case 31830: // Rank 3
7391 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
7397 if (auraSpellInfo
->Id
==37705)
7399 trigger_spell_id
= 37706;
7403 if (auraSpellInfo
->Id
==60510)
7405 trigger_spell_id
= 60515;
7409 else if (auraSpellInfo
->SpellIconID
==241)
7413 // procspell is triggered spell but we need mana cost of original casted spell
7414 uint32 originalSpellId
= procSpell
->Id
;
7416 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0001000000000000))
7418 switch(procSpell
->Id
)
7420 case 25914: originalSpellId
= 20473; break;
7421 case 25913: originalSpellId
= 20929; break;
7422 case 25903: originalSpellId
= 20930; break;
7423 case 27175: originalSpellId
= 27174; break;
7424 case 33074: originalSpellId
= 33072; break;
7425 case 48820: originalSpellId
= 48824; break;
7426 case 48821: originalSpellId
= 48825; break;
7428 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
7432 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
7435 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
7438 // percent stored in effect 1 (class scripts) base points
7439 int32 cost
= originalSpell
->manaCost
+ originalSpell
->ManaCostPercentage
* GetCreateMana() / 100;
7440 basepoints
[0] = cost
*auraSpellInfo
->CalculateSimpleValue(1)/100;
7441 trigger_spell_id
= 20272;
7444 // Lightning Capacitor
7445 else if (auraSpellInfo
->Id
==37657)
7447 if(!pVictim
|| !pVictim
->isAlive())
7450 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
7452 Aura
* dummy
= GetDummyAura(37658);
7453 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7454 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7457 RemoveAurasDueToSpell(37658);
7458 trigger_spell_id
= 37661;
7461 // Bonus Healing (Crystal Spire of Karabor mace)
7462 else if (auraSpellInfo
->Id
== 40971)
7464 // If your target is below $s1% health
7465 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
7468 // Thunder Capacitor
7469 else if (auraSpellInfo
->Id
== 54841)
7471 if(!pVictim
|| !pVictim
->isAlive())
7474 CastSpell(this, 54842, true, NULL
, triggeredByAura
);
7477 Aura
* dummy
= GetDummyAura(54842);
7478 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7479 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7482 RemoveAurasDueToSpell(54842);
7483 trigger_spell_id
= 54843;
7488 case SPELLFAMILY_SHAMAN
:
7490 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc
7491 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000400))
7493 switch(auraSpellInfo
->Id
)
7496 trigger_spell_id
= 26364; break;
7498 trigger_spell_id
= 26365; break;
7500 trigger_spell_id
= 26366; break;
7502 trigger_spell_id
= 26367; break;
7503 case 8134: // Rank 5
7504 trigger_spell_id
= 26369; break;
7505 case 10431: // Rank 6
7506 trigger_spell_id
= 26370; break;
7507 case 10432: // Rank 7
7508 trigger_spell_id
= 26363; break;
7509 case 25469: // Rank 8
7510 trigger_spell_id
= 26371; break;
7511 case 25472: // Rank 9
7512 trigger_spell_id
= 26372; break;
7513 case 49280: // Rank 10
7514 trigger_spell_id
= 49278; break;
7515 case 49281: // Rank 11
7516 trigger_spell_id
= 49279; break;
7518 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
7522 // Lightning Shield (The Ten Storms set)
7523 else if (auraSpellInfo
->Id
== 23551)
7525 trigger_spell_id
= 23552;
7528 // Damage from Lightning Shield (The Ten Storms set)
7529 else if (auraSpellInfo
->Id
== 23552)
7530 trigger_spell_id
= 27635;
7531 // Mana Surge (The Earthfury set)
7532 else if (auraSpellInfo
->Id
== 23572)
7536 basepoints
[0] = procSpell
->manaCost
* 35 / 100;
7537 trigger_spell_id
= 23571;
7540 // Nature's Guardian
7541 else if (auraSpellInfo
->SpellIconID
== 2013)
7543 // Check health condition - should drop to less 30% (damage deal after this!)
7544 if (!(10*(int32(GetHealth() - damage
)) < 3 * GetMaxHealth()))
7547 if(pVictim
&& pVictim
->isAlive())
7548 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
7550 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
7551 trigger_spell_id
= 31616;
7556 case SPELLFAMILY_DEATHKNIGHT
:
7559 if (auraSpellInfo
->SpellIconID
== 1930)
7563 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7565 case SPELL_SCHOOL_NORMAL
:
7566 return false; // ignore
7567 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 50490; break;
7568 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 50362; break;
7569 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 50488; break;
7570 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 50485; break;
7571 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 50489; break;
7572 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 50486; break;
7578 else if (auraSpellInfo
->Id
== 48266)
7580 if (GetTypeId() != TYPEID_PLAYER
)
7582 if (!((Player
*)this)->isHonorOrXPTarget(pVictim
))
7584 trigger_spell_id
= 50475;
7585 basepoints
[0] = damage
* triggerAmount
/ 100;
7588 else if (auraSpellInfo
->SpellIconID
== 85)
7590 if (GetTypeId() != TYPEID_PLAYER
|| getClass() != CLASS_DEATH_KNIGHT
||
7591 !((Player
*)this)->IsBaseRuneSlotsOnCooldown(RUNE_BLOOD
))
7600 // All ok. Check current trigger spell
7601 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
7604 // Not cast unknown spell
7605 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
7609 // not allow proc extra attack spell at extra attack
7610 if (m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
))
7613 // Custom basepoints/target for exist spell
7614 // dummy basepoints or other customs
7615 switch(trigger_spell_id
)
7617 // Cast positive spell on enemy target
7618 case 7099: // Curse of Mending
7619 case 39647: // Curse of Mending
7620 case 29494: // Temptation
7621 case 20233: // Improved Lay on Hands (cast on target)
7626 // Combo points add triggers (need add combopoint only for main target, and after possible combopoints reset)
7627 case 15250: // Rogue Setup
7629 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
7631 break; // continue normal case
7633 // Finish movies that add combo
7634 case 14189: // Seal Fate (Netherblade set)
7635 case 14157: // Ruthlessness
7637 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
7640 // Bloodthirst (($m/100)% of max health)
7643 basepoints
[0] = int32(GetMaxHealth() * triggerAmount
/ 100);
7646 // Shamanistic Rage triggered spell
7649 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7652 // Enlightenment (trigger only from mana cost spells)
7655 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
7662 // As the spell is proced from pet's attack - find owner
7663 Unit
* owner
= GetOwner();
7664 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
7667 // This spell doesn't stack, but refreshes duration. So we receive current bonuses to minus them later.
7669 if (Aura
* aur
= owner
->GetAura(48090,0))
7670 curBonus
= aur
->GetModifier()->m_amount
;
7671 int32 spellDamage
= owner
->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_MAGIC
) - curBonus
;
7672 if(spellDamage
<= 0)
7675 // percent stored in owner talent dummy
7676 AuraList
const& dummyAuras
= owner
->GetAurasByType(SPELL_AURA_DUMMY
);
7677 for (AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
7679 if ((*i
)->GetSpellProto()->SpellIconID
== 3220)
7681 basepoints
[0] = basepoints
[1] = int32(spellDamage
* (*i
)->GetModifier()->m_amount
/ 100);
7690 // Remove cooldown on Shield Slam
7691 if (GetTypeId() == TYPEID_PLAYER
)
7692 ((Player
*)this)->RemoveSpellCategoryCooldown(1209, true);
7698 // have rank dependent proc chance, ignore too often cases
7699 // PPM = 2.5 * (rank of talent),
7700 uint32 rank
= sSpellMgr
.GetSpellRank(auraSpellInfo
->Id
);
7701 // 5 rank -> 100% 4 rank -> 80% and etc from full rate
7702 if(!roll_chance_i(20*rank
))
7711 // For trigger from Blizzard need exist Improved Blizzard
7712 if (procSpell
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)))
7715 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7716 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7718 int32 script
= (*i
)->GetModifier()->m_miscvalue
;
7719 if(script
==836 || script
==988 || script
==989)
7733 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7736 // Need stun, fear or silence mechanic
7737 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_SILENCE_AND_STUN_AND_FEAR_MASK
))
7741 // Burning Determination
7746 // Need Interrupt or Silenced mechanic
7747 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_INTERRUPT_AND_SILENCE_MASK
))
7754 // Proc only from trap activation (from periodic proc another aura of this spell)
7755 if (!(procFlags
& PROC_FLAG_ON_TRAP_ACTIVATION
) || !roll_chance_i(triggerAmount
))
7759 // Freezing Fog (Rime triggered)
7762 // Howling Blast cooldown reset
7763 if (GetTypeId() == TYPEID_PLAYER
)
7764 ((Player
*)this)->RemoveSpellCategoryCooldown(1248, true);
7767 // Druid - Savage Defense
7770 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7775 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
7778 // try detect target manually if not set
7779 if ( target
== NULL
)
7780 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
7783 if(!target
|| target
!=this && !target
->isAlive())
7786 if(basepoints
[0] || basepoints
[1] || basepoints
[2])
7787 CastCustomSpell(target
,trigger_spell_id
,
7788 basepoints
[0] ? &basepoints
[0] : NULL
,
7789 basepoints
[1] ? &basepoints
[1] : NULL
,
7790 basepoints
[2] ? &basepoints
[2] : NULL
,
7791 true,castItem
,triggeredByAura
);
7793 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
7795 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7796 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
7801 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32 damage
, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
7803 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
7805 if(!pVictim
|| !pVictim
->isAlive())
7808 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7809 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7811 // Basepoints of trigger aura
7812 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7814 uint32 triggered_spell_id
= 0;
7818 case 836: // Improved Blizzard (Rank 1)
7820 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7822 triggered_spell_id
= 12484;
7825 case 988: // Improved Blizzard (Rank 2)
7827 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7829 triggered_spell_id
= 12485;
7832 case 989: // Improved Blizzard (Rank 3)
7834 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7836 triggered_spell_id
= 12486;
7839 case 4086: // Improved Mend Pet (Rank 1)
7840 case 4087: // Improved Mend Pet (Rank 2)
7842 if(!roll_chance_i(triggerAmount
))
7845 triggered_spell_id
= 24406;
7848 case 4533: // Dreamwalker Raiment 2 pieces bonus
7851 if (!roll_chance_i(50))
7854 switch (pVictim
->getPowerType())
7856 case POWER_MANA
: triggered_spell_id
= 28722; break;
7857 case POWER_RAGE
: triggered_spell_id
= 28723; break;
7858 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
7864 case 4537: // Dreamwalker Raiment 6 pieces bonus
7865 triggered_spell_id
= 28750; // Blessing of the Claw
7867 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
7868 triggered_spell_id
= 37445; // Mana Surge
7870 case 6953: // Warbringer
7871 RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK
,0,true);
7873 case 7010: // Revitalize (rank 1)
7874 case 7011: // Revitalize (rank 2)
7875 case 7012: // Revitalize (rank 3)
7877 if(!roll_chance_i(triggerAmount
))
7880 switch( pVictim
->getPowerType() )
7882 case POWER_MANA
: triggered_spell_id
= 48542; break;
7883 case POWER_RAGE
: triggered_spell_id
= 48541; break;
7884 case POWER_ENERGY
: triggered_spell_id
= 48540; break;
7885 case POWER_RUNIC_POWER
: triggered_spell_id
= 48543; break;
7886 default: return false;
7893 if(!triggered_spell_id
)
7896 // standard non-dummy case
7897 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
7901 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
7905 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
7908 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
7910 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7911 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
7916 void Unit::setPowerType(Powers new_powertype
)
7918 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
7920 if(GetTypeId() == TYPEID_PLAYER
)
7922 if(((Player
*)this)->GetGroup())
7923 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
7925 else if(((Creature
*)this)->isPet())
7927 Pet
*pet
= ((Pet
*)this);
7928 if(pet
->isControlled())
7930 Unit
*owner
= GetOwner();
7931 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
7932 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
7936 switch(new_powertype
)
7942 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
7943 SetPower( POWER_RAGE
,0);
7946 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
7947 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
7950 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
7952 case POWER_HAPPINESS
:
7953 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
7954 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
7959 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
7961 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
7964 static uint64 guid
= 0; // prevent repeating spam same faction problem
7966 if(GetGUID() != guid
)
7968 if(GetTypeId() == TYPEID_PLAYER
)
7969 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
7971 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
7978 bool Unit::IsHostileTo(Unit
const* unit
) const
7980 // always non-hostile to self
7984 // always non-hostile to GM in GM mode
7985 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
7988 // always hostile to enemy
7989 if(getVictim()==unit
|| unit
->getVictim()==this)
7992 // test pet/charm masters instead pers/charmeds
7993 Unit
const* testerOwner
= GetCharmerOrOwner();
7994 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
7996 // always hostile to owner's enemy
7997 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
8000 // always hostile to enemy owner
8001 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
8004 // always hostile to owner of owner's enemy
8005 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
8008 Unit
const* tester
= testerOwner
? testerOwner
: this;
8009 Unit
const* target
= targetOwner
? targetOwner
: unit
;
8011 // always non-hostile to target with common owner, or to owner/pet
8015 // special cases (Duel, etc)
8016 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
8018 Player
const* pTester
= (Player
const*)tester
;
8019 Player
const* pTarget
= (Player
const*)target
;
8022 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
8026 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
8030 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
8034 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
8038 // Green/Blue (can't attack)
8039 if(pTester
->GetTeam()==pTarget
->GetTeam())
8042 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
8043 return pTester
->IsPvP() && pTarget
->IsPvP();
8046 // faction base cases
8047 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8048 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8049 if(!tester_faction
|| !target_faction
)
8052 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8055 // PvC forced reaction and reputation case
8056 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8059 if(target_faction
->faction
)
8061 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8062 return *force
<= REP_HOSTILE
;
8064 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
8065 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8066 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8067 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8070 // CvP forced reaction and reputation case
8071 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8074 if(tester_faction
->faction
)
8076 if(ReputationRank
const* force
= ((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8077 return *force
<= REP_HOSTILE
;
8079 // apply reputation state
8080 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
8081 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
8082 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) <= REP_HOSTILE
;
8086 // common faction based case (CvC,PvC,CvP)
8087 return tester_faction
->IsHostileTo(*target_faction
);
8090 bool Unit::IsFriendlyTo(Unit
const* unit
) const
8092 // always friendly to self
8096 // always friendly to GM in GM mode
8097 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
8100 // always non-friendly to enemy
8101 if(getVictim()==unit
|| unit
->getVictim()==this)
8104 // test pet/charm masters instead pers/charmeds
8105 Unit
const* testerOwner
= GetCharmerOrOwner();
8106 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
8108 // always non-friendly to owner's enemy
8109 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
8112 // always non-friendly to enemy owner
8113 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
8116 // always non-friendly to owner of owner's enemy
8117 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
8120 Unit
const* tester
= testerOwner
? testerOwner
: this;
8121 Unit
const* target
= targetOwner
? targetOwner
: unit
;
8123 // always friendly to target with common owner, or to owner/pet
8127 // special cases (Duel)
8128 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
8130 Player
const* pTester
= (Player
const*)tester
;
8131 Player
const* pTarget
= (Player
const*)target
;
8134 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
8138 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
8142 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
8146 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
8150 // Green/Blue (non-attackable)
8151 if(pTester
->GetTeam()==pTarget
->GetTeam())
8154 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
8155 return !pTarget
->IsPvP();
8158 // faction base cases
8159 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8160 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8161 if(!tester_faction
|| !target_faction
)
8164 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8167 // PvC forced reaction and reputation case
8168 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8171 if(target_faction
->faction
)
8173 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8174 return *force
>= REP_FRIENDLY
;
8176 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
8177 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8178 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8179 return !(factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8182 // CvP forced reaction and reputation case
8183 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8186 if(tester_faction
->faction
)
8188 if(ReputationRank
const* force
=((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8189 return *force
>= REP_FRIENDLY
;
8191 // apply reputation state
8192 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
8193 if(raw_tester_faction
->reputationListID
>=0 )
8194 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) >= REP_FRIENDLY
;
8198 // common faction based case (CvC,PvC,CvP)
8199 return tester_faction
->IsFriendlyTo(*target_faction
);
8202 bool Unit::IsHostileToPlayers() const
8204 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8205 if(!my_faction
|| !my_faction
->faction
)
8208 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8209 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8212 return my_faction
->IsHostileToPlayers();
8215 bool Unit::IsNeutralToAll() const
8217 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8218 if(!my_faction
|| !my_faction
->faction
)
8221 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8222 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8225 return my_faction
->IsNeutralToAll();
8228 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
8230 if(!victim
|| victim
== this)
8233 // dead units can neither attack nor be attacked
8234 if(!isAlive() || !victim
->IsInWorld() || !victim
->isAlive())
8237 // player cannot attack in mount state
8238 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
8241 // nobody can attack GM in GM-mode
8242 if(victim
->GetTypeId()==TYPEID_PLAYER
)
8244 if(((Player
*)victim
)->isGameMaster())
8249 if(((Creature
*)victim
)->IsInEvadeMode())
8253 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
8254 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
8255 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
8257 // in fighting already
8260 if (m_attacking
== victim
)
8262 // switch to melee attack from ranged/magic
8263 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
8265 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8266 SendMeleeAttackStart(victim
);
8272 // remove old target data
8278 // set position before any AI calls/assistance
8279 if(GetTypeId()==TYPEID_UNIT
)
8280 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
8284 SetTargetGUID(victim
->GetGUID());
8287 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8289 m_attacking
= victim
;
8290 m_attacking
->_addAttacker(this);
8292 if (GetTypeId() == TYPEID_UNIT
)
8294 ((Creature
*)this)->SendAIReaction(AI_REACTION_AGGRO
);
8295 ((Creature
*)this)->CallAssistance();
8298 // delay offhand weapon attack to next attack time
8299 if(haveOffhandWeapon())
8300 resetAttackTimer(OFF_ATTACK
);
8303 SendMeleeAttackStart(victim
);
8308 bool Unit::AttackStop(bool targetSwitch
/*=false*/)
8313 Unit
* victim
= m_attacking
;
8315 m_attacking
->_removeAttacker(this);
8321 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
8323 InterruptSpell(CURRENT_MELEE_SPELL
);
8325 // reset only at real combat stop
8326 if(!targetSwitch
&& GetTypeId()==TYPEID_UNIT
)
8328 ((Creature
*)this)->SetNoCallAssistance(false);
8330 if (((Creature
*)this)->HasSearchedAssistance())
8332 ((Creature
*)this)->SetNoSearchAssistance(false);
8333 UpdateSpeed(MOVE_RUN
, false);
8337 SendMeleeAttackStop(victim
);
8342 void Unit::CombatStop(bool includingCast
)
8344 if (includingCast
&& IsNonMeleeSpellCasted(false))
8345 InterruptNonMeleeSpells(false);
8348 RemoveAllAttackers();
8349 if( GetTypeId()==TYPEID_PLAYER
)
8350 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
8354 struct CombatStopWithPetsHelper
8356 explicit CombatStopWithPetsHelper(bool _includingCast
) : includingCast(_includingCast
) {}
8357 void operator()(Unit
* unit
) const { unit
->CombatStop(includingCast
); }
8361 void Unit::CombatStopWithPets(bool includingCast
)
8363 CombatStop(includingCast
);
8364 CallForAllControlledUnits(CombatStopWithPetsHelper(includingCast
),false,true,true);
8367 struct IsAttackingPlayerHelper
8369 explicit IsAttackingPlayerHelper() {}
8370 bool operator()(Unit
* unit
) const { return unit
->isAttackingPlayer(); }
8373 bool Unit::isAttackingPlayer() const
8375 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
8378 return CheckAllControlledUnits(IsAttackingPlayerHelper(),true,true,true);
8381 void Unit::RemoveAllAttackers()
8383 while (!m_attackers
.empty())
8385 AttackerSet::iterator iter
= m_attackers
.begin();
8386 if(!(*iter
)->AttackStop())
8388 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
8389 m_attackers
.erase(iter
);
8394 bool Unit::HasAuraStateForCaster(AuraState flag
, uint64 caster
) const
8396 if(!HasAuraState(flag
))
8399 // single per-caster aura state
8400 if(flag
== AURA_STATE_CONFLAGRATE
)
8402 Unit::AuraList
const& dotList
= GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
8403 for(Unit::AuraList::const_iterator i
= dotList
.begin(); i
!= dotList
.end(); ++i
)
8405 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
8406 (*i
)->GetCasterGUID() == caster
&&
8408 (((*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000004)) ||
8410 ((*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x00000002)))
8422 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
8426 if (!HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)))
8428 SetFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8429 if(GetTypeId() == TYPEID_PLAYER
)
8431 const PlayerSpellMap
& sp_list
= ((Player
*)this)->GetSpellMap();
8432 for (PlayerSpellMap::const_iterator itr
= sp_list
.begin(); itr
!= sp_list
.end(); ++itr
)
8434 if(itr
->second
->state
== PLAYERSPELL_REMOVED
) continue;
8435 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
8436 if (!spellInfo
|| !IsPassiveSpell(itr
->first
)) continue;
8437 if (spellInfo
->CasterAuraState
== flag
)
8438 CastSpell(this, itr
->first
, true, NULL
);
8445 if (HasFlag(UNIT_FIELD_AURASTATE
,1<<(flag
-1)))
8447 RemoveFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8449 if (flag
!= AURA_STATE_ENRAGE
) // enrage aura state triggering continues auras
8451 Unit::AuraMap
& tAuras
= GetAuras();
8452 for (Unit::AuraMap::iterator itr
= tAuras
.begin(); itr
!= tAuras
.end();)
8454 SpellEntry
const* spellProto
= (*itr
).second
->GetSpellProto();
8455 if (spellProto
->CasterAuraState
== flag
)
8457 // exceptions (applied at state but not removed at state change)
8459 if(spellProto
->SpellIconID
==2006 && spellProto
->SpellFamilyName
==SPELLFAMILY_WARRIOR
&& spellProto
->SpellFamilyFlags
==0x100000)
8475 Unit
*Unit::GetOwner() const
8477 if(uint64 ownerid
= GetOwnerGUID())
8478 return ObjectAccessor::GetUnit(*this, ownerid
);
8482 Unit
*Unit::GetCharmer() const
8484 if(uint64 charmerid
= GetCharmerGUID())
8485 return ObjectAccessor::GetUnit(*this, charmerid
);
8489 bool Unit::IsCharmerOrOwnerPlayerOrPlayerItself() const
8491 if (GetTypeId()==TYPEID_PLAYER
)
8494 return IS_PLAYER_GUID(GetCharmerOrOwnerGUID());
8497 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
8499 uint64 guid
= GetCharmerOrOwnerGUID();
8500 if(IS_PLAYER_GUID(guid
))
8501 return ObjectAccessor::FindPlayer(guid
);
8503 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
8506 Pet
* Unit::GetPet() const
8508 if(uint64 pet_guid
= GetPetGUID())
8510 if(Pet
* pet
= GetMap()->GetPet(pet_guid
))
8513 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
8514 const_cast<Unit
*>(this)->SetPet(0);
8520 Unit
* Unit::GetCharm() const
8522 if (uint64 charm_guid
= GetCharmGUID())
8524 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
8527 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
8528 const_cast<Unit
*>(this)->SetCharm(NULL
);
8534 void Unit::Uncharm()
8536 if (Unit
* charm
= GetCharm())
8538 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM
);
8539 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS
);
8543 float Unit::GetCombatDistance( const Unit
* target
) const
8545 float radius
= target
->GetFloatValue(UNIT_FIELD_COMBATREACH
) + GetFloatValue(UNIT_FIELD_COMBATREACH
);
8546 float dx
= GetPositionX() - target
->GetPositionX();
8547 float dy
= GetPositionY() - target
->GetPositionY();
8548 float dz
= GetPositionZ() - target
->GetPositionZ();
8549 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - radius
;
8550 return ( dist
> 0 ? dist
: 0);
8553 void Unit::SetPet(Pet
* pet
)
8555 SetPetGUID(pet
? pet
->GetGUID() : 0);
8557 if(pet
&& GetTypeId() == TYPEID_PLAYER
)
8558 ((Player
*)this)->SendPetGUIDs();
8560 // FIXME: hack, speed must be set only at follow
8561 if(pet
&& GetTypeId()==TYPEID_PLAYER
)
8562 for(int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
8563 pet
->SetSpeedRate(UnitMoveType(i
), m_speed_rate
[i
], true);
8566 void Unit::SetCharm(Unit
* pet
)
8568 SetCharmGUID(pet
? pet
->GetGUID() : 0);
8571 void Unit::AddGuardian( Pet
* pet
)
8573 m_guardianPets
.insert(pet
->GetGUID());
8576 void Unit::RemoveGuardian( Pet
* pet
)
8578 m_guardianPets
.erase(pet
->GetGUID());
8581 void Unit::RemoveGuardians()
8583 while(!m_guardianPets
.empty())
8585 uint64 guid
= *m_guardianPets
.begin();
8586 if(Pet
* pet
= GetMap()->GetPet(guid
))
8587 pet
->Remove(PET_SAVE_AS_DELETED
);
8589 m_guardianPets
.erase(guid
);
8593 Pet
* Unit::FindGuardianWithEntry(uint32 entry
)
8595 // pet guid middle part is entry (and creature also)
8596 // and in guardian list must be guardians with same entry _always_
8597 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
8598 if(Pet
* pet
= GetMap()->GetPet(*itr
))
8599 if (pet
->GetEntry() == entry
)
8605 Unit
* Unit::_GetTotem(uint8 slot
) const
8607 return GetTotem(slot
);
8610 Totem
* Unit::GetTotem( uint8 slot
) const
8612 if(slot
>= MAX_TOTEM
|| !IsInWorld())
8615 Creature
*totem
= GetMap()->GetCreature(m_TotemSlot
[slot
]);
8616 return totem
&& totem
->isTotem() ? (Totem
*)totem
: NULL
;
8619 void Unit::UnsummonAllTotems()
8621 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
8626 Creature
*OldTotem
= GetMap()->GetCreature(m_TotemSlot
[i
]);
8627 if (OldTotem
&& OldTotem
->isTotem())
8628 ((Totem
*)OldTotem
)->UnSummon();
8632 int32
Unit::DealHeal(Unit
*pVictim
, uint32 addhealth
, SpellEntry
const *spellProto
, bool critical
)
8634 int32 gain
= pVictim
->ModifyHealth(int32(addhealth
));
8638 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8641 if (unit
->GetTypeId()==TYPEID_PLAYER
)
8643 // overheal = addhealth - gain
8644 unit
->SendHealSpellLog(pVictim
, spellProto
->Id
, addhealth
, addhealth
- gain
, critical
);
8646 if (BattleGround
*bg
= ((Player
*)unit
)->GetBattleGround())
8647 bg
->UpdatePlayerScore((Player
*)unit
, SCORE_HEALING_DONE
, gain
);
8649 // use the actual gain, as the overheal shall not be counted, skip gain 0 (it ignored anyway in to criteria)
8651 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE
, gain
, 0, pVictim
);
8653 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED
, addhealth
);
8656 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
8658 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED
, gain
);
8659 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED
, addhealth
);
8665 Unit
* Unit::SelectMagnetTarget(Unit
*victim
, SpellEntry
const *spellInfo
)
8671 if(spellInfo
&& (spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
|| spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
))
8673 Unit::AuraList
const& magnetAuras
= victim
->GetAurasByType(SPELL_AURA_SPELL_MAGNET
);
8674 for(Unit::AuraList::const_iterator itr
= magnetAuras
.begin(); itr
!= magnetAuras
.end(); ++itr
)
8675 if(Unit
* magnet
= (*itr
)->GetCaster())
8676 if(magnet
->IsWithinLOSInMap(this) && magnet
->isAlive())
8679 // Melee && ranged case
8682 AuraList
const& hitTriggerAuras
= victim
->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER
);
8683 for(AuraList::const_iterator i
= hitTriggerAuras
.begin(); i
!= hitTriggerAuras
.end(); ++i
)
8684 if(Unit
* magnet
= (*i
)->GetCaster())
8685 if(magnet
->isAlive() && magnet
->IsWithinLOSInMap(this))
8686 if(roll_chance_i((*i
)->GetModifier()->m_amount
))
8693 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, uint32 OverHeal
, bool critical
)
8696 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
8697 data
.append(pVictim
->GetPackGUID());
8698 data
.append(GetPackGUID());
8699 data
<< uint32(SpellID
);
8700 data
<< uint32(Damage
);
8701 data
<< uint32(OverHeal
);
8702 data
<< uint8(critical
? 1 : 0);
8703 data
<< uint8(0); // unused in client?
8704 SendMessageToSet(&data
, true);
8707 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8709 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
8710 data
.append(pVictim
->GetPackGUID());
8711 data
.append(GetPackGUID());
8712 data
<< uint32(SpellID
);
8713 data
<< uint32(powertype
);
8714 data
<< uint32(Damage
);
8715 SendMessageToSet(&data
, true);
8718 void Unit::EnergizeBySpell(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8720 SendEnergizeSpellLog(pVictim
, SpellID
, Damage
, powertype
);
8721 // needs to be called after sending spell log
8722 pVictim
->ModifyPower(powertype
, Damage
);
8725 uint32
Unit::SpellDamageBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
8727 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
8730 // For totems get damage bonus from owner (statue isn't totem in fact)
8731 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8733 if(Unit
* owner
= GetOwner())
8734 return owner
->SpellDamageBonus(pVictim
, spellProto
, pdamage
, damagetype
);
8737 // Taken/Done total percent damage auras
8738 float DoneTotalMod
= 1.0f
;
8739 float TakenTotalMod
= 1.0f
;
8740 int32 DoneTotal
= 0;
8741 int32 TakenTotal
= 0;
8745 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
8746 DoneTotalMod
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
8748 if (!(spellProto
->AttributesEx6
& SPELL_ATTR_EX6_NO_DMG_PERCENT_MODS
))
8750 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
8751 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
8753 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
8754 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
8755 // -1 == any item class (not wand then)
8756 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
8757 // 0 == any inventory type (not wand then)
8759 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8764 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8765 // Add flat bonus from spell damage versus
8766 DoneTotal
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
8767 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
8768 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
8769 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8770 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8772 // done scripted mod (take it from owner)
8773 Unit
*owner
= GetOwner();
8774 if (!owner
) owner
= this;
8775 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8776 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
8778 if (!(*i
)->isAffectedOnSpell(spellProto
))
8780 switch((*i
)->GetModifier()->m_miscvalue
)
8782 case 4920: // Molten Fury
8784 case 6917: // Death's Embrace
8788 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8789 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8796 // effect 1 m_amount
8797 int32 maxPercent
= (*i
)->GetModifier()->m_amount
;
8798 // effect 0 m_amount
8799 int32 stepPercent
= CalculateSpellDamage((*i
)->GetSpellProto(), 0, (*i
)->GetSpellProto()->EffectBasePoints
[0], this);
8800 // count affliction effects and calc additional damage in percentage
8801 int32 modPercent
= 0;
8802 AuraMap
const& victimAuras
= pVictim
->GetAuras();
8803 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
8805 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
8806 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_WARLOCK
|| !(m_spell
->SpellFamilyFlags
& UI64LIT(0x0004071B8044C402)))
8808 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
8809 if (modPercent
>= maxPercent
)
8811 modPercent
= maxPercent
;
8815 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
8818 case 6916: // Death's Embrace
8821 if (HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
))
8822 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8824 case 5481: // Starfire Bonus
8826 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000200002)))
8827 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8830 case 4418: // Increased Shock Damage
8831 case 4554: // Increased Lightning Damage
8832 case 4555: // Improved Moonfire
8833 case 5142: // Increased Lightning Damage
8834 case 5147: // Improved Consecration / Libram of Resurgence
8835 case 5148: // Idol of the Shooting Star
8836 case 6008: // Increased Lightning Damage / Totem of Hex
8838 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
8846 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
8848 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8849 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8851 else // Tundra Stalker
8853 // Frost Fever (target debuff)
8854 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
8855 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8860 case 7293: // Rage of Rivendare
8862 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
8863 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8869 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000000000008000), 0, GetGUID()))
8870 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8880 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
8881 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8887 // Custom scripted damage
8888 switch(spellProto
->SpellFamilyName
)
8890 case SPELLFAMILY_MAGE
:
8893 if (spellProto
->SpellIconID
== 186)
8895 if (pVictim
->isFrozen())
8897 float multiplier
= 3.0f
;
8899 // if target have higher level
8900 if (pVictim
->getLevel() > getLevel())
8901 // Glyph of Ice Lance
8902 if (Aura
* glyph
= GetDummyAura(56377))
8903 multiplier
= glyph
->GetModifier()->m_amount
;
8905 DoneTotalMod
*= multiplier
;
8908 // Torment the weak affected (Arcane Barrage, Arcane Blast, Frostfire Bolt, Arcane Missiles, Fireball)
8909 if ((spellProto
->SpellFamilyFlags
& UI64LIT(0x0000900020200021)) &&
8910 (pVictim
->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED
) || pVictim
->HasAuraType(SPELL_AURA_MELEE_SLOW
)))
8912 //Search for Torment the weak dummy aura
8913 Unit::AuraList
const& ttw
= GetAurasByType(SPELL_AURA_DUMMY
);
8914 for(Unit::AuraList::const_iterator i
= ttw
.begin(); i
!= ttw
.end(); ++i
)
8916 if ((*i
)->GetSpellProto()->SpellIconID
== 3263)
8918 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
8925 case SPELLFAMILY_WARLOCK
:
8928 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
8930 if (pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth() <= 25)
8935 case SPELLFAMILY_DEATHKNIGHT
:
8937 // Icy Touch, Howling Blast and Frost Strike
8938 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000600000002))
8942 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
8943 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
8945 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
8954 // search for Glacier Rot dummy aura
8955 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
8956 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
8958 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
8960 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
8973 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
8974 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
8976 if ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
))
8977 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
8980 // .. taken pct: dummy auras
8981 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
8984 if (Aura
*dummy
= pVictim
->GetDummyAura(45182))
8986 float mod
= -((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
8987 if (mod
< dummy
->GetModifier()->m_amount
)
8988 mod
= dummy
->GetModifier()->m_amount
;
8989 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
8993 // From caster spells
8994 AuraList
const& mOwnerTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_FROM_CASTER
);
8995 for(AuraList::const_iterator i
= mOwnerTaken
.begin(); i
!= mOwnerTaken
.end(); ++i
)
8997 if ((*i
)->GetCasterGUID() == GetGUID() && (*i
)->isAffectedOnSpell(spellProto
))
8998 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9001 // Mod damage from spell mechanic
9002 TakenTotalMod
*= pVictim
->GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,GetAllSpellMechanicMask(spellProto
));
9004 // Mod damage taken from AoE spells
9005 if(IsAreaOfEffectSpell(spellProto
))
9007 AuraList
const& avoidAuras
= pVictim
->GetAurasByType(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
9008 for(AuraList::const_iterator itr
= avoidAuras
.begin(); itr
!= avoidAuras
.end(); ++itr
)
9009 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9012 // Taken/Done fixed damage bonus auras
9013 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonus(GetSpellSchoolMask(spellProto
));
9014 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
9016 // Pets just add their bonus damage to their spell damage
9017 // note that their spell damage is just gain of their own auras
9018 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9019 DoneAdvertisedBenefit
+= ((Pet
*)this)->GetBonusDamage();
9021 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9022 // Spellmod SpellDamage
9023 float SpellModSpellDamage
= 100.0f
;
9024 if(Player
* modOwner
= GetSpellModOwner())
9025 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
9026 SpellModSpellDamage
/= 100.0f
;
9028 // Check for table values
9029 if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9032 if (damagetype
== DOT
)
9033 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
9035 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
9037 if (bonus
->ap_bonus
)
9038 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
) * stack
);
9040 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* SpellModSpellDamage
);
9041 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
);
9043 // Default calculation
9044 else if (DoneAdvertisedBenefit
|| TakenAdvertisedBenefit
)
9046 // Damage over Time spells bonus calculation
9047 float DotFactor
= 1.0f
;
9048 if (damagetype
== DOT
)
9050 if (!IsChanneledSpell(spellProto
))
9051 DotFactor
= GetSpellDuration(spellProto
) / 15000.0f
;
9053 if (uint16 DotTicks
= GetSpellAuraMaxTicks(spellProto
))
9055 DoneAdvertisedBenefit
= DoneAdvertisedBenefit
* int32(stack
) / DotTicks
;
9056 TakenAdvertisedBenefit
= TakenAdvertisedBenefit
* int32(stack
) / DotTicks
;
9059 // Distribute Damage over multiple effects, reduce by AoE
9060 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
9061 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
9062 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
9063 for(int j
= 0; j
< 3; ++j
)
9065 if (spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
9066 (spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&&
9067 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
))
9073 DoneTotal
+= int32(DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* SpellModSpellDamage
);
9074 TakenTotal
+= int32(TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
);
9077 float tmpDamage
= (pdamage
+ DoneTotal
) * DoneTotalMod
;
9078 // apply spellmod to Done damage (flat and pct)
9079 if(Player
* modOwner
= GetSpellModOwner())
9080 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
9082 tmpDamage
= (tmpDamage
+ TakenTotal
) * TakenTotalMod
;
9084 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9087 int32
Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask
)
9089 int32 DoneAdvertisedBenefit
= 0;
9092 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9093 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
9095 if (((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
9096 (*i
)->GetSpellProto()->EquippedItemClass
== -1 && // -1 == any item class (not wand then)
9097 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0) // 0 == any inventory type (not wand then)
9098 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9101 if (GetTypeId() == TYPEID_PLAYER
)
9104 DoneAdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9106 // Damage bonus from stats
9107 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
9108 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
9110 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9112 // stat used stored in miscValueB for this aura
9113 Stats usedStat
= Stats((*i
)->GetMiscBValue());
9114 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9117 // ... and attack power
9118 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
9119 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
9121 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9122 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9126 return DoneAdvertisedBenefit
;
9129 int32
Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
9131 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9133 int32 TakenAdvertisedBenefit
= 0;
9134 // ..done (for creature type by mask) in taken
9135 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
9136 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
9138 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
9139 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9143 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
9144 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9146 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9147 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9150 return TakenAdvertisedBenefit
;
9153 bool Unit::isSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
9155 // not critting spell
9156 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
9159 float crit_chance
= 0.0f
;
9160 switch(spellProto
->DmgClass
)
9162 case SPELL_DAMAGE_CLASS_NONE
:
9164 case SPELL_DAMAGE_CLASS_MAGIC
:
9166 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
9168 // For other schools
9169 else if (GetTypeId() == TYPEID_PLAYER
)
9170 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
9173 crit_chance
= m_baseSpellCritChance
;
9174 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9179 if (!IsPositiveSpell(spellProto
->Id
))
9181 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
9182 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
9183 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
9184 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
9185 // Modify by player victim resilience
9186 crit_chance
-= pVictim
->GetSpellCritChanceReduction();
9189 // scripted (increase crit chance ... against ... target by x%)
9190 // scripted (Increases the critical effect chance of your .... by x% on targets ...)
9191 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9192 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9194 if (!((*i
)->isAffectedOnSpell(spellProto
)))
9196 switch((*i
)->GetModifier()->m_miscvalue
)
9198 case 849: if (pVictim
->isFrozen()) crit_chance
+= 17.0f
; break; //Shatter Rank 1
9199 case 910: if (pVictim
->isFrozen()) crit_chance
+= 34.0f
; break; //Shatter Rank 2
9200 case 911: if (pVictim
->isFrozen()) crit_chance
+= 50.0f
; break; //Shatter Rank 3
9201 case 7917: // Glyph of Shadowburn
9202 if (pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9203 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9205 case 7997: // Renewed Hope
9207 if (pVictim
->HasAura(6788))
9208 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9214 // Custom crit by class
9215 switch(spellProto
->SpellFamilyName
)
9217 case SPELLFAMILY_PRIEST
:
9219 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000800))
9221 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth()/2)
9223 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9224 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9226 // Improved Flash Heal
9227 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_PRIEST
&&
9228 (*i
)->GetSpellProto()->SpellIconID
== 2542)
9230 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9236 case SPELLFAMILY_PALADIN
:
9238 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000040000000))
9240 Aura
*aura
= pVictim
->GetDummyAura(58597);
9241 if (aura
&& aura
->GetCasterGUID() == GetGUID())
9242 crit_chance
+=aura
->GetModifier()->m_amount
;
9245 else if (spellProto
->Category
== 19)
9247 if (pVictim
->GetCreatureTypeMask() & CREATURE_TYPEMASK_DEMON_OR_UNDEAD
)
9251 case SPELLFAMILY_SHAMAN
:
9253 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000100000000000))
9256 if (Aura
*flameShock
= pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000000010000000), 0, GetGUID()))
9264 case SPELL_DAMAGE_CLASS_MELEE
:
9265 case SPELL_DAMAGE_CLASS_RANGED
:
9268 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
9270 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9277 // only players use intelligence for critical chance computations
9278 if(Player
* modOwner
= GetSpellModOwner())
9279 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
9281 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
9282 if (roll_chance_f(crit_chance
))
9287 uint32
Unit::SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9289 // Calculate critical bonus
9291 switch(spellProto
->DmgClass
)
9293 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9294 case SPELL_DAMAGE_CLASS_RANGED
:
9295 crit_bonus
= damage
;
9298 crit_bonus
= damage
/ 2; // for spells is 50%
9302 // adds additional damage to crit_bonus (from talents)
9303 if(Player
* modOwner
= GetSpellModOwner())
9304 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
9307 return damage
+= crit_bonus
;
9309 int32 critPctDamageMod
= 0;
9310 if(spellProto
->DmgClass
>= SPELL_DAMAGE_CLASS_MELEE
)
9312 if(GetWeaponAttackType(spellProto
) == RANGED_ATTACK
)
9313 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
9315 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
9318 critPctDamageMod
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_DAMAGE
,GetSpellSchoolMask(spellProto
));
9320 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, GetSpellSchoolMask(spellProto
));
9322 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9323 critPctDamageMod
+= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
);
9325 if(critPctDamageMod
!=0)
9326 crit_bonus
= int32(crit_bonus
* float((100.0f
+ critPctDamageMod
)/100.0f
));
9329 damage
+= crit_bonus
;
9334 uint32
Unit::SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9336 // Calculate critical bonus
9338 switch(spellProto
->DmgClass
)
9340 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9341 case SPELL_DAMAGE_CLASS_RANGED
:
9342 // TODO: write here full calculation for melee/ranged spells
9343 crit_bonus
= damage
;
9346 crit_bonus
= damage
/ 2; // for spells is 50%
9352 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9353 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
9357 damage
+= crit_bonus
;
9359 damage
= int32(damage
* GetTotalAuraMultiplier(SPELL_AURA_MOD_CRITICAL_HEALING_AMOUNT
));
9364 uint32
Unit::SpellHealingBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9366 // For totems get healing bonus from owner (statue isn't totem in fact)
9367 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
9368 if(Unit
* owner
= GetOwner())
9369 return owner
->SpellHealingBonus(pVictim
, spellProto
, healamount
, damagetype
, stack
);
9371 float TakenTotalMod
= 1.0f
;
9373 // Healing taken percent
9374 float minval
= pVictim
->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
9376 TakenTotalMod
*= (100.0f
+ minval
) / 100.0f
;
9378 float maxval
= pVictim
->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
9380 TakenTotalMod
*= (100.0f
+ maxval
) / 100.0f
;
9382 // No heal amount for this class spells
9383 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9385 healamount
= healamount
* TakenTotalMod
;
9386 return healamount
< 0 ? 0 : uint32(healamount
);
9390 // Taken/Done total percent damage auras
9391 float DoneTotalMod
= 1.0f
;
9392 int32 DoneTotal
= 0;
9393 int32 TakenTotal
= 0;
9395 // Healing done percent
9396 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
9397 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
9398 DoneTotalMod
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
9400 // done scripted mod (take it from owner)
9401 Unit
*owner
= GetOwner();
9402 if (!owner
) owner
= this;
9403 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9404 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9406 if (!(*i
)->isAffectedOnSpell(spellProto
))
9408 switch((*i
)->GetModifier()->m_miscvalue
)
9410 case 4415: // Increased Rejuvenation Healing
9412 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
9413 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
9415 case 7997: // Renewed Hope
9417 if (pVictim
->HasAura(6788))
9418 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9420 case 21: // Test of Faith
9423 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
9424 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9426 case 7798: // Glyph of Regrowth
9428 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_HEAL
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000000040)))
9429 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9432 case 8477: // Nourish Heal Boost
9434 int32 stepPercent
= (*i
)->GetModifier()->m_amount
;
9435 int32 modPercent
= 0;
9436 AuraMap
const& victimAuras
= pVictim
->GetAuras();
9437 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
9439 if (itr
->second
->GetCasterGUID()!=GetGUID())
9441 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
9442 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_DRUID
||
9443 !(m_spell
->SpellFamilyFlags
& UI64LIT(0x0000001000000050)))
9445 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
9447 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
9450 case 7871: // Glyph of Lesser Healing Wave
9452 if (pVictim
->GetAura(SPELL_AURA_DUMMY
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000040000000000), 0, GetGUID()))
9453 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9461 // Taken/Done fixed damage bonus auras
9462 int32 DoneAdvertisedBenefit
= SpellBaseHealingBonus(GetSpellSchoolMask(spellProto
));
9463 int32 TakenAdvertisedBenefit
= SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
9465 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9466 // Spellmod SpellDamage
9467 float SpellModSpellDamage
= 100.0f
;
9468 if(Player
* modOwner
= GetSpellModOwner())
9469 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_SPELL_BONUS_DAMAGE
, SpellModSpellDamage
);
9470 SpellModSpellDamage
/= 100.0f
;
9472 // Check for table values
9473 SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
);
9477 if (damagetype
== DOT
)
9478 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
9480 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
9482 if (bonus
->ap_bonus
)
9483 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
) * stack
);
9485 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* SpellModSpellDamage
);
9486 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
);
9488 // Default calculation
9489 else if (DoneAdvertisedBenefit
|| TakenAdvertisedBenefit
)
9491 // Damage over Time spells bonus calculation
9492 float DotFactor
= 1.0f
;
9493 if(damagetype
== DOT
)
9495 if(!IsChanneledSpell(spellProto
))
9496 DotFactor
= GetSpellDuration(spellProto
) / 15000.0f
;
9497 uint16 DotTicks
= GetSpellAuraMaxTicks(spellProto
);
9500 DoneAdvertisedBenefit
= DoneAdvertisedBenefit
* int32(stack
) / DotTicks
;
9501 TakenAdvertisedBenefit
= TakenAdvertisedBenefit
* int32(stack
) / DotTicks
;
9504 // Distribute Damage over multiple effects, reduce by AoE
9505 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
9506 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
9507 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
9508 for(int j
= 0; j
< 3; ++j
)
9510 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
9511 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
9517 DoneTotal
+= int32(DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* SpellModSpellDamage
* 1.88f
);
9518 TakenTotal
+= int32(TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* 1.88f
);
9521 // use float as more appropriate for negative values and percent applying
9522 float heal
= (healamount
+ DoneTotal
)*DoneTotalMod
;
9523 // apply spellmod to Done amount
9524 if(Player
* modOwner
= GetSpellModOwner())
9525 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
9528 // Healing Wave cast
9529 if (spellProto
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000040)))
9531 // Search for Healing Way on Victim
9532 Unit::AuraList
const& auraDummy
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
9533 for(Unit::AuraList::const_iterator itr
= auraDummy
.begin(); itr
!=auraDummy
.end(); ++itr
)
9534 if((*itr
)->GetId() == 29203)
9535 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9538 AuraList
const& mHealingGet
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING_RECEIVED
);
9539 for(AuraList::const_iterator i
= mHealingGet
.begin(); i
!= mHealingGet
.end(); ++i
)
9540 if ((*i
)->isAffectedOnSpell(spellProto
))
9541 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9543 heal
= (heal
+ TakenTotal
) * TakenTotalMod
;
9545 return heal
< 0 ? 0 : uint32(heal
);
9548 int32
Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask
)
9550 int32 AdvertisedBenefit
= 0;
9552 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
9553 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
9554 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9555 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9557 // Healing bonus of spirit, intellect and strength
9558 if (GetTypeId() == TYPEID_PLAYER
)
9561 AdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9563 // Healing bonus from stats
9564 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
9565 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
9567 // stat used dependent from misc value (stat index)
9568 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
9569 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9572 // ... and attack power
9573 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
9574 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
9575 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9576 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9578 return AdvertisedBenefit
;
9581 int32
Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
9583 int32 AdvertisedBenefit
= 0;
9584 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING
);
9585 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9586 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9587 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9589 return AdvertisedBenefit
;
9592 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
)
9594 //If m_immuneToSchool type contain this school type, IMMUNE damage.
9595 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9596 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9597 if (itr
->type
& shoolMask
)
9600 //If m_immuneToDamage type contain magic, IMMUNE damage.
9601 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
9602 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
9603 if (itr
->type
& shoolMask
)
9609 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
)
9614 //TODO add spellEffect immunity checks!, player with flag in bg is imune to imunity buffs from other friendly players!
9615 //SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_EFFECT];
9617 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
9618 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
9619 if (itr
->type
== spellInfo
->Dispel
)
9622 if (!(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
) && // unaffected by school immunity
9623 !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)) // can remove immune (by dispell or immune it)
9625 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9626 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9627 if (!(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
9628 (itr
->type
& GetSpellSchoolMask(spellInfo
)))
9632 if(uint32 mechanic
= spellInfo
->Mechanic
)
9634 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9635 for(SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9636 if (itr
->type
== mechanic
)
9639 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9640 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9641 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9648 bool Unit::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, uint32 index
) const
9650 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
9651 uint32 effect
= spellInfo
->Effect
[index
];
9652 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
9653 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
9654 if (itr
->type
== effect
)
9657 if(uint32 mechanic
= spellInfo
->EffectMechanic
[index
])
9659 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9660 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9661 if (itr
->type
== mechanic
)
9664 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9665 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9666 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9670 if(uint32 aura
= spellInfo
->EffectApplyAuraName
[index
])
9672 SpellImmuneList
const& list
= m_spellImmune
[IMMUNITY_STATE
];
9673 for(SpellImmuneList::const_iterator itr
= list
.begin(); itr
!= list
.end(); ++itr
)
9674 if (itr
->type
== aura
)
9677 // Check for immune to application of harmful magical effects
9678 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL
);
9679 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9680 if (spellInfo
->Dispel
== DISPEL_MAGIC
&& // Magic debuff
9681 ((*iter
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellInfo
)) && // Check school
9682 !IsPositiveEffect(spellInfo
->Id
, index
)) // Harmful
9689 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
9694 uint32 family
= spellInfo
->SpellFamilyName
;
9695 uint64 flags
= spellInfo
->SpellFamilyFlags
;
9697 if ((family
== 5 && flags
== 256) || //Searing Pain
9698 (family
== 6 && flags
== 8192) || //Mind Blast
9699 (family
== 11 && flags
== 1048576)) //Earth Shock
9705 uint32
Unit::MeleeDamageBonus(Unit
*pVictim
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
9713 // differentiate for weapon damage based spells
9714 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
9715 Item
* pWeapon
= GetTypeId() == TYPEID_PLAYER
? ((Player
*)this)->GetWeaponForAttack(attType
,true,false) : NULL
;
9716 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9717 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
9718 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
9720 // Shred also have bonus as MECHANIC_BLEED damages
9721 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
9722 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
9725 // FLAT damage bonus auras
9726 // =======================
9728 int32 TakenFlat
= 0;
9731 // ..done flat, already included in wepon damage based spells
9732 if (!isWeaponDamageBasedSpell
)
9734 AuraList
const& mModDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9735 for(AuraList::const_iterator i
= mModDamageDone
.begin(); i
!= mModDamageDone
.end(); ++i
)
9737 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9738 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9739 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9740 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
9742 DoneFlat
+= (*i
)->GetModifier()->m_amount
;
9746 // Pets just add their bonus damage to their melee damage
9747 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9748 DoneFlat
+= ((Pet
*)this)->GetBonusDamage();
9751 // ..done flat (by creature type mask)
9752 DoneFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
, creatureTypeMask
);
9754 // ..done flat (base at attack power for marked target and base at attack power for creature type)
9755 if (attType
== RANGED_ATTACK
)
9757 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
9758 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9759 TakenFlat
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
9763 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
9764 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9765 TakenFlat
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
9768 // ..taken flat (by school mask)
9769 TakenFlat
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_TAKEN
, schoolMask
);
9771 // PERCENT damage auras
9772 // ====================
9773 float DonePercent
= 1.0f
;
9774 float TakenPercent
= 1.0f
;
9776 // ..done pct, already included in weapon damage based spells
9777 if(!isWeaponDamageBasedSpell
)
9779 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
9780 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
9782 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9783 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9784 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9785 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
9787 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9791 if (attType
== OFF_ATTACK
)
9792 DonePercent
*= GetModifierValue(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_PCT
); // no school check required
9795 // ..done pct (by creature type mask)
9796 DonePercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
, creatureTypeMask
);
9798 // ..taken pct (by school mask)
9799 TakenPercent
*= pVictim
->GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
, schoolMask
);
9801 // ..taken pct (by mechanic mask)
9802 TakenPercent
*= pVictim
->GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,mechanicMask
);
9804 // ..taken pct (melee/ranged)
9805 if(attType
== RANGED_ATTACK
)
9806 TakenPercent
*= pVictim
->GetTotalAuraMultiplier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
9808 TakenPercent
*= pVictim
->GetTotalAuraMultiplier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
9810 // ..taken pct (aoe avoidance)
9811 if(spellProto
&& IsAreaOfEffectSpell(spellProto
))
9812 TakenPercent
*= pVictim
->GetTotalAuraMultiplier(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
9815 // special dummys/class sripts and other effects
9816 // =============================================
9817 Unit
*owner
= GetOwner();
9821 // ..done (class scripts)
9824 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9825 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9827 if (!(*i
)->isAffectedOnSpell(spellProto
))
9830 switch((*i
)->GetModifier()->m_miscvalue
)
9837 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
9839 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9840 DonePercent
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
9842 else // Tundra Stalker
9844 // Frost Fever (target debuff)
9845 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
9846 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9851 case 7293: // Rage of Rivendare
9853 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
9854 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9864 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
9865 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9872 // .. taken (dummy auras)
9873 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
9874 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9876 switch((*i
)->GetSpellProto()->SpellIconID
)
9880 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
9882 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
9885 float mod
= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
9886 if (mod
< (*i
)->GetModifier()->m_amount
)
9887 mod
= (*i
)->GetModifier()->m_amount
;
9889 TakenPercent
*= (mod
+ 100.0f
) / 100.0f
;
9895 // .. taken (class scripts)
9896 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9897 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
9899 switch((*i
)->GetMiscValue())
9904 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9906 Aura
* eff0
= GetAura((*i
)->GetId(), 0);
9907 if (!eff0
|| (*i
)->GetEffIndex() != 1)
9909 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
9913 // effect 0 have expected value but in negative state
9914 TakenPercent
*= (-eff0
->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9921 // final calculation
9922 // =================
9924 // scaling of non weapon based spells
9925 if (!isWeaponDamageBasedSpell
)
9927 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9929 // Check for table values
9930 if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9933 if (damagetype
== DOT
)
9934 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
9936 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
9938 if (bonus
->ap_bonus
)
9939 DoneFlat
+= bonus
->ap_bonus
* (GetTotalAttackPowerValue(BASE_ATTACK
) + APbonus
) * stack
;
9944 // Default calculation
9945 else if (DoneFlat
|| TakenFlat
)
9947 // Damage over Time spells bonus calculation
9948 float DotFactor
= 1.0f
;
9949 if(damagetype
== DOT
)
9951 if(!IsChanneledSpell(spellProto
))
9952 DotFactor
= GetSpellDuration(spellProto
) / 15000.0f
;
9953 uint16 DotTicks
= GetSpellAuraMaxTicks(spellProto
);
9956 DoneFlat
= DoneFlat
* int32(stack
) / DotTicks
;
9957 TakenFlat
= TakenFlat
* int32(stack
) / DotTicks
;
9960 // Distribute Damage over multiple effects, reduce by AoE
9961 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
9962 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
9963 DoneFlat
*= (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
;
9964 TakenFlat
*= (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
;
9967 // weapon damage based spells
9968 else if( APbonus
|| DoneFlat
)
9970 bool normalized
= spellProto
? IsSpellHaveEffect(spellProto
, SPELL_EFFECT_NORMALIZED_WEAPON_DMG
) : false;
9971 DoneFlat
+= int32(APbonus
/ 14.0f
* GetAPMultiplier(attType
,normalized
));
9973 // for weapon damage based spells we still have to apply damage done percent mods
9974 // (that are already included into pdamage) to not-yet included DoneFlat
9975 // e.g. from doneVersusCreature, apBonusVs...
9980 case BASE_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_MAINHAND
; break;
9981 case OFF_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_OFFHAND
; break;
9982 case RANGED_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_RANGED
; break;
9985 DoneFlat
*= GetModifierValue(unitMod
, TOTAL_PCT
);
9988 float tmpDamage
= float(int32(pdamage
) + DoneFlat
) * DonePercent
;
9990 // apply spellmod to Done damage
9993 if(Player
* modOwner
= GetSpellModOwner())
9994 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
9997 tmpDamage
= (tmpDamage
+ TakenFlat
) * TakenPercent
;
9999 // bonus result can be negative
10000 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
10003 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
10007 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
10009 next
= itr
; ++next
;
10010 if(itr
->type
== type
)
10012 m_spellImmune
[op
].erase(itr
);
10013 next
= m_spellImmune
[op
].begin();
10016 SpellImmune Immune
;
10017 Immune
.spellId
= spellId
;
10018 Immune
.type
= type
;
10019 m_spellImmune
[op
].push_back(Immune
);
10023 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
10025 if(itr
->spellId
== spellId
)
10027 m_spellImmune
[op
].erase(itr
);
10035 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
10037 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
10039 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
10040 RemoveAurasWithDispelType(type
);
10043 float Unit::GetWeaponProcChance() const
10045 // normalized proc chance for weapon attack speed
10046 // (odd formula...)
10047 if (isAttackReady(BASE_ATTACK
))
10048 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
10049 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
10050 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
10055 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
10057 // proc per minute chance calculation
10058 if (PPM
<= 0.0f
) return 0.0f
;
10059 return WeaponSpeed
* PPM
/ 600.0f
; // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
10062 void Unit::Mount(uint32 mount
, uint32 spellId
)
10067 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
10069 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
10071 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
10073 if (GetTypeId() == TYPEID_PLAYER
)
10075 // Called by Taxi system / GM command
10077 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10078 // Called by mount aura
10079 else if (SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellId
))
10081 // Flying case (Unsummon any pet)
10082 if (IsSpellHaveAura(spellInfo
, SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
))
10083 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10084 // Normal case (Unsummon only permanent pet)
10085 else if (Pet
* pet
= GetPet())
10087 if (pet
->IsPermanentPetFor((Player
*)this) && !((Player
*)this)->InArena())
10088 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10090 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,true);
10096 void Unit::Unmount()
10101 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
10103 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
10104 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
10106 // only resummon old pet if the player is already added to a map
10107 // this prevents adding a pet to a not created map which would otherwise cause a crash
10108 // (it could probably happen when logging in after a previous crash)
10109 if(GetTypeId() == TYPEID_PLAYER
)
10111 if(Pet
* pet
= GetPet())
10112 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,false);
10114 ((Player
*)this)->ResummonPetTemporaryUnSummonedIfAny();
10118 void Unit::SetInCombatWith(Unit
* enemy
)
10120 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
10121 if (eOwner
->IsPvP())
10123 SetInCombatState(true,enemy
);
10128 if (eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
10130 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
10131 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
10133 SetInCombatState(true,enemy
);
10138 SetInCombatState(false,enemy
);
10141 void Unit::SetInCombatState(bool PvP
, Unit
* enemy
)
10143 // only alive units can be in combat
10148 m_CombatTimer
= 5000;
10150 bool creatureNotInCombat
= GetTypeId()==TYPEID_UNIT
&& !HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10152 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10154 if (isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10155 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10157 if (creatureNotInCombat
)
10159 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10161 if (((Creature
*)this)->AI())
10162 ((Creature
*)this)->AI()->EnterCombat(enemy
);
10166 void Unit::ClearInCombat()
10169 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10171 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10172 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10174 // Player's state will be cleared in Player::UpdateContestedPvP
10175 if (GetTypeId() != TYPEID_PLAYER
)
10177 Creature
* creature
= (Creature
*)this;
10178 if (creature
->GetCreatureInfo() && creature
->GetCreatureInfo()->unit_flags
& UNIT_FLAG_OOC_NOT_ATTACKABLE
)
10179 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10181 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
10184 ((Player
*)this)->UpdatePotionCooldown();
10187 bool Unit::isTargetableForAttack(bool inverseAlive
/*=false*/) const
10189 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
10192 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
10195 // to be removed if unit by any reason enter combat
10196 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
))
10199 // inversealive is needed for some spells which need to be casted at dead targets (aoe)
10200 if (isAlive() == inverseAlive
)
10203 return IsInWorld() && !hasUnitState(UNIT_STAT_DIED
) && !isInFlight();
10206 int32
Unit::ModifyHealth(int32 dVal
)
10213 int32 curHealth
= (int32
)GetHealth();
10215 int32 val
= dVal
+ curHealth
;
10222 int32 maxHealth
= (int32
)GetMaxHealth();
10224 if(val
< maxHealth
)
10227 gain
= val
- curHealth
;
10229 else if(curHealth
!= maxHealth
)
10231 SetHealth(maxHealth
);
10232 gain
= maxHealth
- curHealth
;
10238 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
10245 int32 curPower
= (int32
)GetPower(power
);
10247 int32 val
= dVal
+ curPower
;
10254 int32 maxPower
= (int32
)GetMaxPower(power
);
10258 SetPower(power
,val
);
10259 gain
= val
- curPower
;
10261 else if(curPower
!= maxPower
)
10263 SetPower(power
,maxPower
);
10264 gain
= maxPower
- curPower
;
10270 bool Unit::isVisibleForOrDetect(Unit
const* u
, WorldObject
const* viewPoint
, bool detect
, bool inVisibleList
, bool is3dDistance
) const
10272 if(!u
|| !IsInMap(u
))
10275 // Always can see self
10279 // player visible for other player if not logout and at same transport
10280 // including case when player is out of world
10281 bool at_same_transport
=
10282 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
10283 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
10284 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
10285 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
10288 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
10291 // forbidden to seen (at GM respawn command)
10292 if(m_Visibility
==VISIBILITY_RESPAWN
)
10295 Map
& _map
= *u
->GetMap();
10296 // Grid dead/alive checks
10297 if (u
->GetTypeId()==TYPEID_PLAYER
)
10299 // non visible at grid for any stealth state
10300 if(!IsVisibleInGridForPlayer((Player
*)u
))
10303 // if player is dead then he can't detect anyone in any cases
10309 // all dead creatures/players not visible for any creatures
10310 if(!u
->isAlive() || !isAlive())
10314 // always seen by far sight caster
10315 if (u
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)u
)->GetFarSight()==GetGUID())
10318 // different visible distance checks
10319 if (u
->isInFlight()) // what see player in flight
10321 // use object grey distance for all (only see objects any way)
10322 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10325 else if(!isAlive()) // distance for show body
10327 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10330 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
10332 if(u
->GetTypeId()==TYPEID_PLAYER
)
10334 // Players far than max visible distance for player or not in our map are not visible too
10335 if (!at_same_transport
&& !IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10340 // Units far than max visible distance for creature or not in our map are not visible too
10341 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10345 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
10347 // Pet/charmed far than max visible distance for player or not in our map are not visible too
10348 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10351 else // distance for show creature
10353 // Units far than max visible distance for creature or not in our map are not visible too
10354 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10358 // always seen by owner
10359 if (GetCharmerOrOwnerGUID()==u
->GetGUID())
10362 // isInvisibleForAlive() those units can only be seen by dead or if other
10363 // unit is also invisible for alive.. if an isinvisibleforalive unit dies we
10364 // should be able to see it too
10365 if (u
->isAlive() && isAlive() && isInvisibleForAlive() != u
->isInvisibleForAlive())
10366 if (u
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)u
)->isGameMaster())
10369 // Visible units, always are visible for all units, except for units under invisibility and phases
10370 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0 && InSamePhase(u
))
10373 // GMs see any players, not higher GMs and all units in any phase
10374 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
10376 if(GetTypeId() == TYPEID_PLAYER
)
10377 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
10382 // non faction visibility non-breakable for non-GMs
10383 if (m_Visibility
== VISIBILITY_OFF
)
10386 // phased visibility (both must phased in same way)
10387 if(!InSamePhase(u
))
10390 // raw invisibility
10391 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
10393 // detectable invisibility case
10395 // Invisible units, always are visible for units under same invisibility type
10396 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
10397 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
10398 u
->canDetectInvisibilityOf(this) ||
10399 // Units that can detect invisibility always are visible for units that can be detected
10400 canDetectInvisibilityOf(u
) ))
10405 // special cases for always overwrite invisibility/stealth
10406 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
10408 // non-hostile case
10409 if (!u
->IsHostileTo(this))
10411 // 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)
10412 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
10414 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
10417 // else apply same rules as for hostile case (detecting check for stealth)
10423 // Hunter mark functionality
10424 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
10425 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
10426 if((*iter
)->GetCasterGUID()==u
->GetGUID())
10429 // else apply detecting check for stealth
10432 // none other cases for detect invisibility, so invisible
10436 // else apply stealth detecting check
10439 // unit got in stealth in this moment and must ignore old detected state
10440 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
10443 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
10444 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
10447 // NOW ONLY STEALTH CASE
10449 //if in non-detect mode then invisible for unit
10450 //mobs always detect players (detect == true)... return 'false' for those mobs which have (detect == false)
10451 //players detect players only in Player::HandleStealthedUnitsDetection()
10453 return (u
->GetTypeId() == TYPEID_PLAYER
) ? ((Player
*)u
)->HaveAtClient(this) : false;
10457 // If is attacked then stealth is lost, some creature can use stealth too
10458 if( !getAttackers().empty() )
10461 // If there is collision rogue is seen regardless of level difference
10462 if (IsWithinDist(u
,0.24f
))
10465 //If a mob or player is stunned he will not be able to detect stealth
10466 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
10470 float visibleDistance
= (u
->GetTypeId() == TYPEID_PLAYER
) ? MAX_PLAYER_STEALTH_DETECT_RANGE
: ((Creature
const*)u
)->GetAttackDistance(this);
10472 //Always invisible from back (when stealth detection is on), also filter max distance cases
10473 bool isInFront
= viewPoint
->isInFrontInMap(this, visibleDistance
);
10477 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
10478 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
10480 //Calculation if target is in front
10482 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
10483 visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
10485 //Visible distance is modified by
10486 //-Level Diff (every level diff = 1.0f in visible distance)
10487 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
10489 //This allows to check talent tree and will add addition stealth dependent on used points)
10490 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
10494 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
10495 //based on wowwiki every 5 mod we have 1 more level diff in calculation
10496 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_DETECT
)) - stealthMod
)/5.0f
;
10497 visibleDistance
= visibleDistance
> MAX_PLAYER_STEALTH_DETECT_RANGE
? MAX_PLAYER_STEALTH_DETECT_RANGE
: visibleDistance
;
10499 // recheck new distance
10500 if(visibleDistance
<= 0 || !IsWithinDist(viewPoint
,visibleDistance
))
10504 // Now check is target visible with LoS
10506 viewPoint
->GetPosition(ox
,oy
,oz
);
10507 return IsWithinLOS(ox
,oy
,oz
);
10510 void Unit::SetVisibility(UnitVisibility x
)
10518 if(GetTypeId()==TYPEID_PLAYER
)
10519 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10521 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10525 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
10527 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
10529 for(uint32 i
= 0; i
< 10; ++i
)
10531 if(((1 << i
) & mask
)==0)
10534 // find invisibility level
10535 uint32 invLevel
= 0;
10536 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
10537 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
10538 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
10539 invLevel
= (*itr
)->GetModifier()->m_amount
;
10541 // find invisibility detect level
10542 uint32 detectLevel
= 0;
10543 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
10544 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
10545 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
10546 detectLevel
= (*itr
)->GetModifier()->m_amount
;
10548 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
10550 detectLevel
= ((Player
*)this)->GetDrunkValue();
10553 if(invLevel
<= detectLevel
)
10561 struct UpdateWalkModeHelper
10563 explicit UpdateWalkModeHelper(Unit
* _source
) : source(_source
) {}
10564 void operator()(Unit
* unit
) const { unit
->UpdateWalkMode(source
, true); }
10568 void Unit::UpdateWalkMode(Unit
* source
, bool self
)
10570 if (GetTypeId() == TYPEID_PLAYER
)
10571 ((Player
*)this)->CallForAllControlledUnits(UpdateWalkModeHelper(source
),false,true,true,true);
10574 bool on
= source
->GetTypeId() == TYPEID_PLAYER
10575 ? ((Player
*)source
)->HasMovementFlag(MOVEFLAG_WALK_MODE
)
10576 : ((Creature
*)source
)->HasMonsterMoveFlag(MONSTER_MOVE_WALK
);
10580 if (((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10581 ((Creature
*)this)->AddMonsterMoveFlag(MONSTER_MOVE_WALK
);
10585 if (((Creature
*)this)->isPet())
10586 ((Creature
*)this)->RemoveMonsterMoveFlag(MONSTER_MOVE_WALK
);
10590 CallForAllControlledUnits(UpdateWalkModeHelper(source
),false,true,true);
10593 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
)
10595 // not in combat pet have same speed as owner
10601 if (GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10603 if(Unit
* owner
= GetOwner())
10605 SetSpeedRate(mtype
,owner
->GetSpeedRate(mtype
),forced
);
10612 int32 main_speed_mod
= 0;
10613 float stack_bonus
= 1.0f
;
10614 float non_stack_bonus
= 1.0f
;
10622 if (IsMounted()) // Use on mount auras
10624 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
10625 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
10626 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
10630 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
10631 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
10632 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
10636 case MOVE_RUN_BACK
:
10640 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
10643 case MOVE_SWIM_BACK
:
10647 if (IsMounted()) // Use on mount auras
10648 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
);
10649 else // Use not mount (shapeshift for example) auras (should stack)
10650 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT
);
10651 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS
);
10652 non_stack_bonus
= (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
))/100.0f
;
10655 case MOVE_FLIGHT_BACK
:
10658 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
10662 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
10663 // now we ready for speed calculation
10664 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
10672 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
10673 // TODO: possible affect only on MOVE_RUN
10674 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
10676 // Use speed from aura
10677 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
10678 if (speed
> max_speed
)
10687 // for creature case, we check explicit if mob searched for assistance
10688 if (GetTypeId() == TYPEID_UNIT
)
10690 if (((Creature
*)this)->HasSearchedAssistance())
10691 speed
*= 0.66f
; // best guessed value, so this will be 33% reduction. Based off initial speed, mob can then "run", "walk fast" or "walk".
10694 // Apply strongest slow aura mod to speed
10695 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
10698 speed
*=(100.0f
+ slow
)/100.0f
;
10699 float min_speed
= (float)GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MINIMUM_SPEED
) / 100.0f
;
10700 if (speed
< min_speed
)
10703 SetSpeedRate(mtype
, speed
, forced
);
10706 float Unit::GetSpeed( UnitMoveType mtype
) const
10708 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
10711 struct SetSpeedRateHelper
10713 explicit SetSpeedRateHelper(UnitMoveType _mtype
, bool _forced
) : mtype(_mtype
), forced(_forced
) {}
10714 void operator()(Unit
* unit
) const { unit
->UpdateSpeed(mtype
,forced
); }
10715 UnitMoveType mtype
;
10719 void Unit::SetSpeedRate(UnitMoveType mtype
, float rate
, bool forced
)
10724 // Update speed only on change
10725 if (m_speed_rate
[mtype
] == rate
)
10728 m_speed_rate
[mtype
] = rate
;
10730 propagateSpeedChange();
10738 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10741 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10743 case MOVE_RUN_BACK
:
10744 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10747 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10749 case MOVE_SWIM_BACK
:
10750 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10752 case MOVE_TURN_RATE
:
10753 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+2+4+4+4+4+4+4+4);
10756 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10758 case MOVE_FLIGHT_BACK
:
10759 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10761 case MOVE_PITCH_RATE
:
10762 data
.Initialize(MSG_MOVE_SET_PITCH_RATE
, 8+4+2+4+4+4+4+4+4+4);
10765 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
10769 data
.append(GetPackGUID());
10770 data
<< uint32(0); // movement flags
10771 data
<< uint16(0); // unk flags
10772 data
<< uint32(getMSTime());
10773 data
<< float(GetPositionX());
10774 data
<< float(GetPositionY());
10775 data
<< float(GetPositionZ());
10776 data
<< float(GetOrientation());
10777 data
<< uint32(0); // fall time
10778 data
<< float(GetSpeed(mtype
));
10779 SendMessageToSet( &data
, true );
10783 if(GetTypeId() == TYPEID_PLAYER
)
10785 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
10786 // and do it only for real sent packets and use run for run/mounted as client expected
10787 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
10793 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
10796 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
10798 case MOVE_RUN_BACK
:
10799 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
10802 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
10804 case MOVE_SWIM_BACK
:
10805 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
10807 case MOVE_TURN_RATE
:
10808 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
10811 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
10813 case MOVE_FLIGHT_BACK
:
10814 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
10816 case MOVE_PITCH_RATE
:
10817 data
.Initialize(SMSG_FORCE_PITCH_RATE_CHANGE
, 16);
10820 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
10823 data
.append(GetPackGUID());
10824 data
<< (uint32
)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
10825 if (mtype
== MOVE_RUN
)
10826 data
<< uint8(0); // new 2.1.0
10827 data
<< float(GetSpeed(mtype
));
10828 SendMessageToSet( &data
, true );
10831 if (GetTypeId() == TYPEID_PLAYER
) // need include minpet
10832 ((Player
*)this)->CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true,true);
10834 CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true);
10837 void Unit::SetHover(bool on
)
10840 CastSpell(this, 11010, true);
10842 RemoveAurasDueToSpell(11010);
10845 void Unit::setDeathState(DeathState s
)
10847 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
10850 DeleteThreatList();
10851 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
10853 if(IsNonMeleeSpellCasted(false))
10854 InterruptNonMeleeSpells(false);
10857 if (s
== JUST_DIED
)
10859 RemoveAllAurasOnDeath();
10861 UnsummonAllTotems();
10863 // after removing a Fearaura (in RemoveAllAurasOnDeath)
10864 // Unit::SetFeared is called and makes that creatures attack player again
10867 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
10868 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
10869 // remove aurastates allowing special moves
10870 ClearAllReactives();
10871 ClearDiminishings();
10873 else if(s
== JUST_ALIVED
)
10875 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
10878 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
10880 //_ApplyAllAuraMods();
10885 /*########################################
10887 ######## AGGRO SYSTEM ########
10889 ########################################*/
10890 bool Unit::CanHaveThreatList() const
10892 // only creatures can have threat list
10893 if( GetTypeId() != TYPEID_UNIT
)
10896 // only alive units can have threat list
10900 // totems can not have threat list
10901 if( ((Creature
*)this)->isTotem() )
10904 // vehicles can not have threat list
10905 if( ((Creature
*)this)->isVehicle() )
10908 // pets can not have a threat list, unless they are controlled by a creature
10909 if( ((Creature
*)this)->isPet() && IS_PLAYER_GUID(((Pet
*)this)->GetOwnerGUID()) )
10915 //======================================================================
10917 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
10919 if (!HasAuraType(SPELL_AURA_MOD_THREAT
))
10922 if (schoolMask
== SPELL_SCHOOL_MASK_NONE
)
10925 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
10927 return threat
* m_threatModifier
[school
];
10930 //======================================================================
10932 void Unit::AddThreat(Unit
* pVictim
, float threat
/*= 0.0f*/, bool crit
/*= false*/, SpellSchoolMask schoolMask
/*= SPELL_SCHOOL_MASK_NONE*/, SpellEntry
const *threatSpell
/*= NULL*/)
10934 // Only mobs can manage threat lists
10935 if(CanHaveThreatList())
10936 m_ThreatManager
.addThreat(pVictim
, threat
, crit
, schoolMask
, threatSpell
);
10939 //======================================================================
10941 void Unit::DeleteThreatList()
10943 if(CanHaveThreatList() && !m_ThreatManager
.isThreatListEmpty())
10945 m_ThreatManager
.clearReferences();
10948 //======================================================================
10950 void Unit::TauntApply(Unit
* taunter
)
10952 assert(GetTypeId()== TYPEID_UNIT
);
10954 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
10957 if(!CanHaveThreatList())
10960 Unit
*target
= getVictim();
10961 if(target
&& target
== taunter
)
10964 SetInFront(taunter
);
10965 if (((Creature
*)this)->AI())
10966 ((Creature
*)this)->AI()->AttackStart(taunter
);
10968 m_ThreatManager
.tauntApply(taunter
);
10971 //======================================================================
10973 void Unit::TauntFadeOut(Unit
*taunter
)
10975 assert(GetTypeId()== TYPEID_UNIT
);
10977 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
10980 if(!CanHaveThreatList())
10983 Unit
*target
= getVictim();
10984 if(!target
|| target
!= taunter
)
10987 if(m_ThreatManager
.isThreatListEmpty())
10989 if(((Creature
*)this)->AI())
10990 ((Creature
*)this)->AI()->EnterEvadeMode();
10994 m_ThreatManager
.tauntFadeOut(taunter
);
10995 target
= m_ThreatManager
.getHostileTarget();
10997 if (target
&& target
!= taunter
)
10999 SetInFront(target
);
11000 if (((Creature
*)this)->AI())
11001 ((Creature
*)this)->AI()->AttackStart(target
);
11005 //======================================================================
11007 bool Unit::SelectHostileTarget()
11009 //function provides main threat functionality
11010 //next-victim-selection algorithm and evade mode are called
11011 //threat list sorting etc.
11013 assert(GetTypeId()== TYPEID_UNIT
);
11015 if (!this->isAlive())
11017 //This function only useful once AI has been initialized
11018 if (!((Creature
*)this)->AI())
11021 Unit
* target
= NULL
;
11023 // First checking if we have some taunt on us
11024 const AuraList
& tauntAuras
= GetAurasByType(SPELL_AURA_MOD_TAUNT
);
11025 if ( !tauntAuras
.empty() )
11029 // The last taunt aura caster is alive an we are happy to attack him
11030 if ( (caster
= tauntAuras
.back()->GetCaster()) && caster
->isAlive() )
11032 else if (tauntAuras
.size() > 1)
11034 // We do not have last taunt aura caster but we have more taunt auras,
11035 // so find first available target
11037 // Auras are pushed_back, last caster will be on the end
11038 AuraList::const_iterator aura
= --tauntAuras
.end();
11042 if ( (caster
= (*aura
)->GetCaster()) &&
11043 caster
->IsInMap(this) && caster
->isTargetableForAttack() && caster
->isInAccessablePlaceFor((Creature
*)this) )
11048 }while (aura
!= tauntAuras
.begin());
11052 if ( !target
&& !m_ThreatManager
.isThreatListEmpty() )
11053 // No taunt aura or taunt aura caster is dead standart target selection
11054 target
= m_ThreatManager
.getHostileTarget();
11058 if(!hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_DIED
))
11059 SetInFront(target
);
11060 ((Creature
*)this)->AI()->AttackStart(target
);
11064 // no target but something prevent go to evade mode
11065 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
11068 // last case when creature don't must go to evade mode:
11069 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
11070 // for example at owner command to pet attack some far away creature
11071 // Note: creature not have targeted movement generator but have attacker in this case
11072 if (GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE
)
11074 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
11076 if ((*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this))
11081 // enter in evade mode in other case
11082 ((Creature
*)this)->AI()->EnterEvadeMode();
11087 //======================================================================
11088 //======================================================================
11089 //======================================================================
11091 int32
Unit::CalculateSpellDamage(SpellEntry
const* spellProto
, uint8 effect_index
, int32 effBasePoints
, Unit
const* target
)
11093 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
11095 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
11097 int32 level
= int32(getLevel());
11098 if (level
> (int32
)spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
11099 level
= (int32
)spellProto
->maxLevel
;
11100 else if (level
< (int32
)spellProto
->baseLevel
)
11101 level
= (int32
)spellProto
->baseLevel
;
11102 level
-= (int32
)spellProto
->spellLevel
;
11104 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
11105 float randomPointsPerLevel
= spellProto
->EffectDicePerLevel
[effect_index
];
11106 int32 basePoints
= int32(effBasePoints
+ level
* basePointsPerLevel
);
11107 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
] + level
* randomPointsPerLevel
);
11108 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
11110 // range can have possitive and negative values, so order its for irand
11111 int32 randvalue
= int32(spellProto
->EffectBaseDice
[effect_index
]) >= randomPoints
11112 ? irand(randomPoints
, int32(spellProto
->EffectBaseDice
[effect_index
]))
11113 : irand(int32(spellProto
->EffectBaseDice
[effect_index
]), randomPoints
);
11115 int32 value
= basePoints
+ randvalue
;
11117 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
11118 value
+= (int32
)(comboDamage
* comboPoints
);
11120 if(Player
* modOwner
= GetSpellModOwner())
11122 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_ALL_EFFECTS
, value
);
11123 switch(effect_index
)
11126 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT1
, value
);
11129 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT2
, value
);
11132 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT3
, value
);
11137 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
11138 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
11139 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
&&
11140 (spellProto
->Effect
[effect_index
] != SPELL_EFFECT_APPLY_AURA
|| spellProto
->EffectApplyAuraName
[effect_index
] != SPELL_AURA_MOD_DECREASE_SPEED
))
11141 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
11146 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, uint8 effect_index
, Unit
const* target
)
11148 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
11150 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
11152 int32 minduration
= GetSpellDuration(spellProto
);
11153 int32 maxduration
= GetSpellMaxDuration(spellProto
);
11157 if( minduration
!= -1 && minduration
!= maxduration
)
11158 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
11160 duration
= minduration
;
11164 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
11165 // Find total mod value (negative bonus)
11166 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
11167 // Modify from SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL aura (stack always ?)
11168 durationMod_always
+=target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
, spellProto
->Dispel
);
11169 // Find max mod (negative bonus)
11170 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
11172 if (!IsPositiveSpell(spellProto
->Id
))
11173 durationMod_always
+= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS
, spellProto
->DmgClass
);
11175 int32 durationMod
= 0;
11176 // Select strongest negative mod
11177 if (durationMod_always
> durationMod_not_stack
)
11178 durationMod
= durationMod_not_stack
;
11180 durationMod
= durationMod_always
;
11182 if (durationMod
!= 0)
11183 duration
= int32(int64(duration
) * (100+durationMod
) /100);
11185 if (duration
< 0) duration
= 0;
11191 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
11193 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11195 if(i
->DRGroup
!= group
)
11199 return DIMINISHING_LEVEL_1
;
11202 return DIMINISHING_LEVEL_1
;
11204 // If last spell was casted more than 15 seconds ago - reset the count.
11205 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
11207 i
->hitCount
= DIMINISHING_LEVEL_1
;
11208 return DIMINISHING_LEVEL_1
;
11210 // or else increase the count.
11213 return DiminishingLevels(i
->hitCount
);
11216 return DIMINISHING_LEVEL_1
;
11219 void Unit::IncrDiminishing(DiminishingGroup group
)
11221 // Checking for existing in the table
11222 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11224 if(i
->DRGroup
!= group
)
11226 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
11230 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
11233 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
, int32 limitduration
)
11235 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
11238 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
11239 if(limitduration
> 0 && duration
> limitduration
)
11241 // test pet/charm masters instead pets/charmeds
11242 Unit
const* targetOwner
= GetCharmerOrOwner();
11243 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
11245 Unit
const* target
= targetOwner
? targetOwner
: this;
11246 Unit
const* source
= casterOwner
? casterOwner
: caster
;
11248 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
11249 duration
= limitduration
;
11254 // Some diminishings applies to mobs too (for example, Stun)
11255 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
11257 DiminishingLevels diminish
= Level
;
11260 case DIMINISHING_LEVEL_1
: break;
11261 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
11262 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
11263 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
11268 duration
= int32(duration
* mod
);
11271 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
11273 // Checking for existing in the table
11274 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11276 if(i
->DRGroup
!= group
)
11284 // Remember time after last aura from group removed
11286 i
->hitTime
= getMSTime();
11292 Unit
* Unit::GetUnit(WorldObject
const& object
, uint64 guid
)
11294 return ObjectAccessor::GetUnit(object
,guid
);
11297 bool Unit::isVisibleForInState( Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const
11299 return isVisibleForOrDetect(u
, viewPoint
, false, inVisibleList
, false);
11302 /// returns true if creature can't be seen by alive units
11303 bool Unit::isInvisibleForAlive() const
11305 if (m_AuraFlags
& UNIT_AURAFLAG_ALIVE_INVISIBLE
)
11307 // TODO: maybe spiritservices also have just an aura
11308 return isSpiritService();
11311 uint32
Unit::GetCreatureType() const
11313 if(GetTypeId() == TYPEID_PLAYER
)
11315 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(m_form
);
11316 if(ssEntry
&& ssEntry
->creatureType
> 0)
11317 return ssEntry
->creatureType
;
11319 return CREATURE_TYPE_HUMANOID
;
11322 return ((Creature
*)this)->GetCreatureInfo()->type
;
11325 /*#######################################
11327 ######## STAT SYSTEM ########
11329 #######################################*/
11331 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
11333 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11335 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
11341 switch(modifierType
)
11345 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
11349 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
11352 val
= (100.0f
+ amount
) / 100.0f
;
11353 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
11360 if(!CanModifyStats())
11365 case UNIT_MOD_STAT_STRENGTH
:
11366 case UNIT_MOD_STAT_AGILITY
:
11367 case UNIT_MOD_STAT_STAMINA
:
11368 case UNIT_MOD_STAT_INTELLECT
:
11369 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
11371 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
11372 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
11374 case UNIT_MOD_MANA
:
11375 case UNIT_MOD_RAGE
:
11376 case UNIT_MOD_FOCUS
:
11377 case UNIT_MOD_ENERGY
:
11378 case UNIT_MOD_HAPPINESS
:
11379 case UNIT_MOD_RUNE
:
11380 case UNIT_MOD_RUNIC_POWER
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
11382 case UNIT_MOD_RESISTANCE_HOLY
:
11383 case UNIT_MOD_RESISTANCE_FIRE
:
11384 case UNIT_MOD_RESISTANCE_NATURE
:
11385 case UNIT_MOD_RESISTANCE_FROST
:
11386 case UNIT_MOD_RESISTANCE_SHADOW
:
11387 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
11389 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
11390 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
11392 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
11393 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
11394 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
11403 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
11405 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11407 sLog
.outError("trial to access non existed modifier value from UnitMods!");
11411 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
11414 return m_auraModifiersGroup
[unitMod
][modifierType
];
11417 float Unit::GetTotalStatValue(Stats stat
) const
11419 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
11421 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11424 // value = ((base_value * base_pct) + total_value) * total_pct
11425 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
11426 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11427 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11428 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11433 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
11435 if(unitMod
>= UNIT_MOD_END
)
11437 sLog
.outError("trial to access non existed UnitMods in GetTotalAuraModValue()!");
11441 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11444 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
11445 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11446 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11447 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11452 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
11454 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
11458 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
11459 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
11460 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
11461 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
11462 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
11463 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
11472 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
11474 Stats stat
= STAT_STRENGTH
;
11478 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
11479 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
11480 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
11481 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
11482 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
11491 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
11495 case UNIT_MOD_MANA
: return POWER_MANA
;
11496 case UNIT_MOD_RAGE
: return POWER_RAGE
;
11497 case UNIT_MOD_FOCUS
: return POWER_FOCUS
;
11498 case UNIT_MOD_ENERGY
: return POWER_ENERGY
;
11499 case UNIT_MOD_HAPPINESS
: return POWER_HAPPINESS
;
11500 case UNIT_MOD_RUNE
: return POWER_RUNE
;
11501 case UNIT_MOD_RUNIC_POWER
:return POWER_RUNIC_POWER
;
11502 default: return POWER_MANA
;
11508 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
11510 if (attType
== RANGED_ATTACK
)
11512 int32 ap
= GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER_MODS
);
11515 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER
));
11519 int32 ap
= GetInt32Value(UNIT_FIELD_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_ATTACK_POWER_MODS
);
11522 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER
));
11526 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
11528 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
11531 return m_weaponDamage
[attType
][type
];
11534 void Unit::SetLevel(uint32 lvl
)
11536 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
11539 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
11540 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
11543 void Unit::SetHealth(uint32 val
)
11545 uint32 maxHealth
= GetMaxHealth();
11546 if(maxHealth
< val
)
11549 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
11552 if(GetTypeId() == TYPEID_PLAYER
)
11554 if(((Player
*)this)->GetGroup())
11555 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
11557 else if(((Creature
*)this)->isPet())
11559 Pet
*pet
= ((Pet
*)this);
11560 if(pet
->isControlled())
11562 Unit
*owner
= GetOwner();
11563 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11564 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
11569 void Unit::SetMaxHealth(uint32 val
)
11571 uint32 health
= GetHealth();
11572 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
11575 if(GetTypeId() == TYPEID_PLAYER
)
11577 if(((Player
*)this)->GetGroup())
11578 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
11580 else if(((Creature
*)this)->isPet())
11582 Pet
*pet
= ((Pet
*)this);
11583 if(pet
->isControlled())
11585 Unit
*owner
= GetOwner();
11586 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11587 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP
);
11595 void Unit::SetPower(Powers power
, uint32 val
)
11597 if(GetPower(power
) == val
)
11600 uint32 maxPower
= GetMaxPower(power
);
11604 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
11606 WorldPacket
data(SMSG_POWER_UPDATE
);
11607 data
.append(GetPackGUID());
11608 data
<< uint8(power
);
11609 data
<< uint32(val
);
11610 SendMessageToSet(&data
, GetTypeId() == TYPEID_PLAYER
? true : false);
11613 if(GetTypeId() == TYPEID_PLAYER
)
11615 if(((Player
*)this)->GetGroup())
11616 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11618 else if(((Creature
*)this)->isPet())
11620 Pet
*pet
= ((Pet
*)this);
11621 if(pet
->isControlled())
11623 Unit
*owner
= GetOwner();
11624 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11625 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11628 // Update the pet's character sheet with happiness damage bonus
11629 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
11631 pet
->UpdateDamagePhysical(BASE_ATTACK
);
11636 void Unit::SetMaxPower(Powers power
, uint32 val
)
11638 uint32 cur_power
= GetPower(power
);
11639 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
11642 if(GetTypeId() == TYPEID_PLAYER
)
11644 if(((Player
*)this)->GetGroup())
11645 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
11647 else if(((Creature
*)this)->isPet())
11649 Pet
*pet
= ((Pet
*)this);
11650 if(pet
->isControlled())
11652 Unit
*owner
= GetOwner();
11653 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11654 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
11658 if(val
< cur_power
)
11659 SetPower(power
, val
);
11662 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
11664 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
11667 if(GetTypeId() == TYPEID_PLAYER
)
11669 if(((Player
*)this)->GetGroup())
11670 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11672 else if(((Creature
*)this)->isPet())
11674 Pet
*pet
= ((Pet
*)this);
11675 if(pet
->isControlled())
11677 Unit
*owner
= GetOwner();
11678 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11679 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11684 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
11686 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
11689 if(GetTypeId() == TYPEID_PLAYER
)
11691 if(((Player
*)this)->GetGroup())
11692 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
11694 else if(((Creature
*)this)->isPet())
11696 Pet
*pet
= ((Pet
*)this);
11697 if(pet
->isControlled())
11699 Unit
*owner
= GetOwner();
11700 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11701 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
11706 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
11708 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
11710 tAuraProcTriggerDamage
.push_back(aura
);
11712 tAuraProcTriggerDamage
.remove(aura
);
11715 uint32
Unit::GetCreatePowers( Powers power
) const
11717 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
11720 case POWER_MANA
: return GetCreateMana();
11721 case POWER_RAGE
: return 1000;
11722 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
11723 case POWER_ENERGY
: return 100;
11724 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
11725 case POWER_RUNIC_POWER
: return 1000;
11726 case POWER_RUNE
: return 0;
11727 case POWER_HEALTH
: return 0;
11733 void Unit::AddToWorld()
11735 Object::AddToWorld();
11738 void Unit::RemoveFromWorld()
11744 RemoveNotOwnSingleTargetAuras();
11746 RemoveAllGameObjects();
11747 RemoveAllDynObjects();
11748 CleanupDeletedAuras();
11751 Object::RemoveFromWorld();
11754 void Unit::CleanupsBeforeDelete()
11756 if(m_uint32Values
) // only for fully created object
11758 InterruptNonMeleeSpells(true);
11759 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
11761 ClearComboPointHolders();
11762 DeleteThreatList();
11763 getHostileRefManager().setOnlineOfflineState(false);
11764 RemoveAllAuras(AURA_REMOVE_BY_DELETE
);
11765 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
11767 WorldObject::CleanupsBeforeDelete();
11770 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
11773 m_charmInfo
= new CharmInfo(charm
);
11774 return m_charmInfo
;
11777 CharmInfo::CharmInfo(Unit
* unit
)
11778 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
11780 for(int i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
11781 m_charmspells
[i
].SetActionAndType(0,ACT_DISABLED
);
11784 void CharmInfo::InitPetActionBar()
11786 // the first 3 SpellOrActions are attack, follow and stay
11787 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_START
- ACTION_BAR_INDEX_START
; ++i
)
11788 SetActionBar(ACTION_BAR_INDEX_START
+ i
,COMMAND_ATTACK
- i
,ACT_COMMAND
);
11790 // middle 4 SpellOrActions are spells/special attacks/abilities
11791 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_END
-ACTION_BAR_INDEX_PET_SPELL_START
; ++i
)
11792 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_START
+ i
,0,ACT_DISABLED
);
11794 // last 3 SpellOrActions are reactions
11795 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_END
- ACTION_BAR_INDEX_PET_SPELL_END
; ++i
)
11796 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_END
+ i
,COMMAND_ATTACK
- i
,ACT_REACTION
);
11799 void CharmInfo::InitEmptyActionBar()
11801 SetActionBar(ACTION_BAR_INDEX_START
,COMMAND_ATTACK
,ACT_COMMAND
);
11802 for(uint32 x
= ACTION_BAR_INDEX_START
+1; x
< ACTION_BAR_INDEX_END
; ++x
)
11803 SetActionBar(x
,0,ACT_PASSIVE
);
11806 void CharmInfo::InitPossessCreateSpells()
11808 InitEmptyActionBar(); //charm action bar
11810 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //possessed players don't have spells, keep the action bar empty
11813 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11815 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
11816 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
11818 AddSpellToActionBar(((Creature
*)m_unit
)->m_spells
[x
], ACT_PASSIVE
);
11822 void CharmInfo::InitCharmCreateSpells()
11824 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
11826 InitEmptyActionBar();
11830 InitPetActionBar();
11832 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11834 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
11838 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
11842 if (IsPassiveSpell(spellId
))
11844 m_unit
->CastSpell(m_unit
, spellId
, true);
11845 m_charmspells
[x
].SetActionAndType(spellId
,ACT_PASSIVE
);
11849 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
11851 ActiveStates newstate
;
11852 bool onlyselfcast
= true;
11853 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
11855 if(!spellInfo
) onlyselfcast
= false;
11856 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
11858 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
11859 onlyselfcast
= false;
11862 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
11863 newstate
= ACT_DISABLED
;
11865 newstate
= ACT_PASSIVE
;
11867 AddSpellToActionBar(spellId
, newstate
);
11872 bool CharmInfo::AddSpellToActionBar(uint32 spell_id
, ActiveStates newstate
)
11874 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
11876 // new spell rank can be already listed
11877 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11879 if (uint32 action
= PetActionBar
[i
].GetAction())
11881 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
11883 PetActionBar
[i
].SetAction(spell_id
);
11889 // or use empty slot in other case
11890 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11892 if (!PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
11894 SetActionBar(i
,spell_id
,newstate
== ACT_DECIDE
? ACT_DISABLED
: newstate
);
11901 bool CharmInfo::RemoveSpellFromActionBar(uint32 spell_id
)
11903 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
11905 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11907 if (uint32 action
= PetActionBar
[i
].GetAction())
11909 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
11911 SetActionBar(i
,0,ACT_DISABLED
);
11920 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
11922 if(IsPassiveSpell(spellid
))
11925 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11926 if(spellid
== m_charmspells
[x
].GetAction())
11927 m_charmspells
[x
].SetType(apply
? ACT_ENABLED
: ACT_DISABLED
);
11930 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
11932 m_petnumber
= petnumber
;
11934 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
11936 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
11939 void CharmInfo::LoadPetActionBar(const std::string
& data
)
11941 InitPetActionBar();
11943 Tokens tokens
= StrSplit(data
, " ");
11945 if (tokens
.size() != (ACTION_BAR_INDEX_END
-ACTION_BAR_INDEX_START
)*2)
11946 return; // non critical, will reset to default
11949 Tokens::iterator iter
;
11950 for(iter
= tokens
.begin(), index
= ACTION_BAR_INDEX_START
; index
< ACTION_BAR_INDEX_END
; ++iter
, ++index
)
11952 // use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
11953 uint8 type
= atol((*iter
).c_str());
11955 uint32 action
= atol((*iter
).c_str());
11957 PetActionBar
[index
].SetActionAndType(action
,ActiveStates(type
));
11959 // check correctness
11960 if(PetActionBar
[index
].IsActionBarForSpell() && !sSpellStore
.LookupEntry(PetActionBar
[index
].GetAction()))
11961 SetActionBar(index
,0,ACT_DISABLED
);
11965 void CharmInfo::BuildActionBar( WorldPacket
* data
)
11967 for(uint32 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11968 *data
<< uint32(PetActionBar
[i
].packedData
);
11971 void CharmInfo::SetSpellAutocast( uint32 spell_id
, bool state
)
11973 for(int i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11975 if(spell_id
== PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
11977 PetActionBar
[i
].SetType(state
? ACT_ENABLED
: ACT_DISABLED
);
11983 bool Unit::isFrozen() const
11985 return HasAuraState(AURA_STATE_FROZEN
);
11988 struct ProcTriggeredData
11990 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
11991 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
11992 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
11994 SpellProcEventEntry
const *spellProcEvent
;
11995 Aura
* triggeredByAura
;
11996 Unit::spellEffectPair triggeredByAura_SpellPair
;
11999 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
12000 typedef std::list
< uint32
> RemoveSpellList
;
12002 // List of auras that CAN be trigger but may not exist in spell_proc_event
12003 // in most case need for drop charges
12004 // in some types of aura need do additional check
12005 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
12006 bool InitTriggerAuraData()
12008 for (int i
=0;i
<TOTAL_AURAS
;++i
)
12010 isTriggerAura
[i
]=false;
12011 isNonTriggerAura
[i
] = false;
12013 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
12014 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
12015 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
12016 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
12017 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
12018 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
12019 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
12020 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
12021 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
12022 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
12023 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
12024 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
12025 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
] = true;
12026 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
12027 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
12028 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
12029 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
12030 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
12031 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
12032 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
12033 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
12034 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
12035 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
12036 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
12037 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
12038 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
12039 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
12040 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
] = true;
12041 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_FROM_CASTER
] = true;
12042 isTriggerAura
[SPELL_AURA_MOD_SPELL_CRIT_CHANCE
] = true;
12043 isTriggerAura
[SPELL_AURA_MAELSTROM_WEAPON
] = true;
12045 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
12046 isNonTriggerAura
[SPELL_AURA_REDUCE_PUSHBACK
]=true;
12051 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
12053 uint32 procEx
= PROC_EX_NONE
;
12054 // Check victim state
12055 if (missCondition
!=SPELL_MISS_NONE
)
12056 switch (missCondition
)
12058 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
12059 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
12060 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
12061 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
12062 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
12063 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
12064 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
12065 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
12066 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
12067 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
12068 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
12075 if (damageInfo
->blocked
)
12076 procEx
|=PROC_EX_BLOCK
;
12078 if (damageInfo
->absorb
)
12079 procEx
|=PROC_EX_ABSORB
;
12081 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
12082 procEx
|=PROC_EX_CRITICAL_HIT
;
12084 procEx
|=PROC_EX_NORMAL_HIT
;
12089 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
12091 // For melee/ranged based attack need update skills and set some Aura states
12092 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
12094 // Update skills here for players
12095 if (GetTypeId() == TYPEID_PLAYER
)
12097 // On melee based hit/miss/resist need update skill (for victim and attacker)
12098 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
12100 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
12101 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, isVictim
);
12103 // Update defence if player is victim and parry/dodge/block
12104 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
12105 ((Player
*)this)->UpdateDefense();
12107 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
12108 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
12113 // if victim and dodge attack
12114 if (procExtra
&PROC_EX_DODGE
)
12116 //Update AURA_STATE on dodge
12117 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
12119 ModifyAuraState(AURA_STATE_DEFENSE
, true);
12120 StartReactiveTimer( REACTIVE_DEFENSE
);
12123 // if victim and parry attack
12124 if (procExtra
& PROC_EX_PARRY
)
12126 // For Hunters only Counterattack (skip Mongoose bite)
12127 if (getClass() == CLASS_HUNTER
)
12129 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
12130 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
12134 ModifyAuraState(AURA_STATE_DEFENSE
, true);
12135 StartReactiveTimer( REACTIVE_DEFENSE
);
12138 // if and victim block attack
12139 if (procExtra
& PROC_EX_BLOCK
)
12141 ModifyAuraState(AURA_STATE_DEFENSE
,true);
12142 StartReactiveTimer( REACTIVE_DEFENSE
);
12145 else //For attacker
12147 // Overpower on victim dodge
12148 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
12150 ((Player
*)this)->AddComboPoints(pTarget
, 1);
12151 StartReactiveTimer( REACTIVE_OVERPOWER
);
12157 RemoveSpellList removedSpells
;
12158 ProcTriggeredList procTriggered
;
12159 // Fill procTriggered list
12160 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
12162 // skip deleted auras (possible at recursive triggered call
12163 if(itr
->second
->IsDeleted())
12166 SpellProcEventEntry
const* spellProcEvent
= NULL
;
12167 if(!IsTriggeredAtSpellProcEvent(pTarget
, itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
12170 itr
->second
->SetInUse(true); // prevent aura deletion
12171 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
12175 if (procTriggered
.empty())
12178 // Handle effects proceed this time
12179 for(ProcTriggeredList::const_iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
12181 // Some auras can be deleted in function called in this loop (except first, ofc)
12182 Aura
*triggeredByAura
= i
->triggeredByAura
;
12183 if(triggeredByAura
->IsDeleted())
12186 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
12187 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
12188 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
12189 bool useCharges
= triggeredByAura
->GetAuraCharges() > 0;
12190 // For players set spell cooldown if need
12191 uint32 cooldown
= 0;
12192 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
12193 cooldown
= spellProcEvent
->cooldown
;
12195 switch(auraModifier
->m_auraname
)
12197 case SPELL_AURA_PROC_TRIGGER_SPELL
:
12199 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12200 // Don`t drop charge or add cooldown for not started trigger
12201 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12203 triggeredByAura
->SetInUse(false);
12208 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
12210 sLog
.outDebug("ProcDamageAndSpell: doing %u damage from spell id %u (triggered by %s aura of spell %u)", auraModifier
->m_amount
, spellInfo
->Id
, (isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12211 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, spellInfo
->SchoolMask
);
12212 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
12213 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
12214 SendSpellNonMeleeDamageLog(&damageInfo
);
12215 DealSpellDamage(&damageInfo
, true);
12218 case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
:
12219 case SPELL_AURA_MANA_SHIELD
:
12220 case SPELL_AURA_OBS_MOD_MANA
:
12221 case SPELL_AURA_ADD_PCT_MODIFIER
:
12222 case SPELL_AURA_DUMMY
:
12224 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12225 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12227 triggeredByAura
->SetInUse(false);
12232 case SPELL_AURA_MOD_HASTE
:
12234 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12235 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12237 triggeredByAura
->SetInUse(false);
12242 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
12244 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12245 if (!HandleOverrideClassScriptAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, cooldown
))
12247 triggeredByAura
->SetInUse(false);
12252 case SPELL_AURA_PRAYER_OF_MENDING
:
12254 sLog
.outDebug("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
12255 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
12257 HandleMendingAuraProc(triggeredByAura
);
12260 case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
:
12262 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered with value by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12264 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12266 triggeredByAura
->SetInUse(false);
12271 case SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
:
12272 // Skip melee hits or instant cast spells
12273 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
12275 triggeredByAura
->SetInUse(false);
12279 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
12280 // Skip Melee hits and spells ws wrong school
12281 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
12283 triggeredByAura
->SetInUse(false);
12287 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
12288 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
12289 // Skip melee hits and spells ws wrong school or zero cost
12290 if (procSpell
== NULL
||
12291 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
12292 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
12294 triggeredByAura
->SetInUse(false);
12298 case SPELL_AURA_MECHANIC_IMMUNITY
:
12299 // Compare mechanic
12300 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12302 triggeredByAura
->SetInUse(false);
12306 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
12307 // Compare mechanic
12308 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12310 triggeredByAura
->SetInUse(false);
12314 case SPELL_AURA_MOD_DAMAGE_FROM_CASTER
:
12316 if (triggeredByAura
->GetCasterGUID() != pTarget
->GetGUID())
12318 triggeredByAura
->SetInUse(false);
12322 case SPELL_AURA_MOD_SPELL_CRIT_CHANCE
:
12325 triggeredByAura
->SetInUse(false);
12328 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s spell crit chance aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12329 if (!HandleSpellCritChanceAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12331 triggeredByAura
->SetInUse(false);
12335 case SPELL_AURA_MAELSTROM_WEAPON
:
12336 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s maelstrom aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12338 // remove all stack;
12339 RemoveSpellsCausingAura(SPELL_AURA_MAELSTROM_WEAPON
);
12340 triggeredByAura
->SetInUse(false); // this safe, aura locked
12341 continue; // avoid re-remove attempts
12343 // nothing do, just charges counter
12347 // Remove charge (aura can be removed by triggers)
12348 if(useCharges
&& !triggeredByAura
->IsDeleted())
12350 // If last charge dropped add spell to remove list
12351 if(triggeredByAura
->DropAuraCharge())
12352 removedSpells
.push_back(triggeredByAura
->GetId());
12355 triggeredByAura
->SetInUse(false);
12357 if (!removedSpells
.empty())
12359 // Sort spells and remove dublicates
12360 removedSpells
.sort();
12361 removedSpells
.unique();
12362 // Remove auras from removedAuras
12363 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();++i
)
12364 RemoveSingleSpellAurasFromStack(*i
);
12368 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
12370 return SPELL_SCHOOL_MASK_NORMAL
;
12373 Player
* Unit::GetSpellModOwner()
12375 if(GetTypeId()==TYPEID_PLAYER
)
12376 return (Player
*)this;
12377 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
12379 Unit
* owner
= GetOwner();
12380 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
12381 return (Player
*)owner
;
12386 ///----------Pet responses methods-----------------
12387 void Unit::SendPetCastFail(uint32 spellid
, SpellCastResult msg
)
12389 if(msg
== SPELL_CAST_OK
)
12392 Unit
*owner
= GetCharmerOrOwner();
12393 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12396 WorldPacket
data(SMSG_PET_CAST_FAILED
, 1 + 4 + 1);
12397 data
<< uint8(0); // cast count?
12398 data
<< uint32(spellid
);
12399 data
<< uint8(msg
);
12400 // uint32 for some reason
12401 // uint32 for some reason
12402 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12405 void Unit::SendPetActionFeedback (uint8 msg
)
12407 Unit
* owner
= GetOwner();
12408 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12411 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
12412 data
<< uint8(msg
);
12413 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12416 void Unit::SendPetTalk (uint32 pettalk
)
12418 Unit
* owner
= GetOwner();
12419 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12422 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8 + 4);
12423 data
<< uint64(GetGUID());
12424 data
<< uint32(pettalk
);
12425 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12428 void Unit::SendPetAIReaction(uint64 guid
)
12430 Unit
* owner
= GetOwner();
12431 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12434 WorldPacket
data(SMSG_AI_REACTION
, 8 + 4);
12435 data
<< uint64(guid
);
12436 data
<< uint32(AI_REACTION_AGGRO
);
12437 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12440 ///----------End of Pet responses methods----------
12442 void Unit::StopMoving()
12444 clearUnitState(UNIT_STAT_MOVING
);
12446 // send explicit stop packet
12447 // player expected for correct work MONSTER_MOVE_WALK
12448 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, GetTypeId()==TYPEID_PLAYER
? MONSTER_MOVE_WALK
: MONSTER_MOVE_NONE
, 0);
12450 // update position and orientation for near players
12452 BuildHeartBeatMsg(&data
);
12453 SendMessageToSet(&data
,false);
12456 void Unit::SetFeared(bool apply
, uint64
const& casterGUID
, uint32 spellID
, uint32 time
)
12460 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
12463 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12465 GetMotionMaster()->MovementExpired(false);
12466 CastStop(GetGUID()==casterGUID
? spellID
: 0);
12468 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
12470 GetMotionMaster()->MoveFleeing(caster
, time
); // caster==NULL processed in MoveFleeing
12474 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12476 GetMotionMaster()->MovementExpired(false);
12478 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
12480 // restore appropriate movement generator
12482 GetMotionMaster()->MoveChase(getVictim());
12484 GetMotionMaster()->Initialize();
12486 // attack caster if can
12487 Unit
* caster
= Unit::GetUnit(*this, casterGUID
);
12488 if(caster
&& ((Creature
*)this)->AI())
12489 ((Creature
*)this)->AI()->AttackedBy(caster
);
12493 if (GetTypeId() == TYPEID_PLAYER
)
12494 ((Player
*)this)->SetClientControl(this, !apply
);
12497 void Unit::SetConfused(bool apply
, uint64
const& casterGUID
, uint32 spellID
)
12501 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12503 CastStop(GetGUID()==casterGUID
? spellID
: 0);
12505 GetMotionMaster()->MoveConfused();
12509 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12511 GetMotionMaster()->MovementExpired(false);
12513 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12515 // restore appropriate movement generator
12517 GetMotionMaster()->MoveChase(getVictim());
12519 GetMotionMaster()->Initialize();
12523 if(GetTypeId() == TYPEID_PLAYER
)
12524 ((Player
*)this)->SetClientControl(this, !apply
);
12527 void Unit::SetFeignDeath(bool apply
, uint64
const& casterGUID
, uint32 spellID
)
12532 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12535 SendMessageToSet(&data,true);
12538 if(GetTypeId() != TYPEID_PLAYER
)
12541 ((Player
*)this)->m_movementInfo
.SetMovementFlags(MOVEFLAG_NONE
);
12543 // blizz like 2.0.x
12544 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12545 // blizz like 2.0.x
12546 SetFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12547 // blizz like 2.0.x
12548 SetFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12550 addUnitState(UNIT_STAT_DIED
);
12552 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION
);
12554 // prevent interrupt message
12555 if (casterGUID
== GetGUID())
12556 FinishSpell(CURRENT_GENERIC_SPELL
,false);
12557 InterruptNonMeleeSpells(true);
12558 getHostileRefManager().deleteReferences();
12563 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12566 SendMessageToSet(&data,true);
12568 // blizz like 2.0.x
12569 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12570 // blizz like 2.0.x
12571 RemoveFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12572 // blizz like 2.0.x
12573 RemoveFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12575 clearUnitState(UNIT_STAT_DIED
);
12577 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12579 // restore appropriate movement generator
12581 GetMotionMaster()->MoveChase(getVictim());
12583 GetMotionMaster()->Initialize();
12589 bool Unit::IsSitState() const
12591 uint8 s
= getStandState();
12593 s
== UNIT_STAND_STATE_SIT_CHAIR
|| s
== UNIT_STAND_STATE_SIT_LOW_CHAIR
||
12594 s
== UNIT_STAND_STATE_SIT_MEDIUM_CHAIR
|| s
== UNIT_STAND_STATE_SIT_HIGH_CHAIR
||
12595 s
== UNIT_STAND_STATE_SIT
;
12598 bool Unit::IsStandState() const
12600 uint8 s
= getStandState();
12601 return !IsSitState() && s
!= UNIT_STAND_STATE_SLEEP
&& s
!= UNIT_STAND_STATE_KNEEL
;
12604 void Unit::SetStandState(uint8 state
)
12606 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
12608 if (IsStandState())
12609 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
12611 if(GetTypeId()==TYPEID_PLAYER
)
12613 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
12614 data
<< (uint8
)state
;
12615 ((Player
*)this)->GetSession()->SendPacket(&data
);
12619 bool Unit::IsPolymorphed() const
12621 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
12624 void Unit::SetDisplayId(uint32 modelId
)
12626 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
12628 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
12630 Pet
*pet
= ((Pet
*)this);
12631 if(!pet
->isControlled())
12633 Unit
*owner
= GetOwner();
12634 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12635 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
12639 void Unit::ClearComboPointHolders()
12641 while(!m_ComboPointHolders
.empty())
12643 uint32 lowguid
= *m_ComboPointHolders
.begin();
12645 Player
* plr
= sObjectMgr
.GetPlayer(MAKE_NEW_GUID(lowguid
, 0, HIGHGUID_PLAYER
));
12646 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
12647 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
12649 m_ComboPointHolders
.erase(lowguid
); // or remove manually
12653 void Unit::ClearAllReactives()
12655 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
12656 m_reactiveTimer
[i
] = 0;
12658 if (HasAuraState( AURA_STATE_DEFENSE
))
12659 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12660 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
12661 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12662 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12663 ((Player
*)this)->ClearComboPoints();
12666 void Unit::UpdateReactives( uint32 p_time
)
12668 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
12670 ReactiveType reactive
= ReactiveType(i
);
12672 if(!m_reactiveTimer
[reactive
])
12675 if ( m_reactiveTimer
[reactive
] <= p_time
)
12677 m_reactiveTimer
[reactive
] = 0;
12679 switch ( reactive
)
12681 case REACTIVE_DEFENSE
:
12682 if (HasAuraState(AURA_STATE_DEFENSE
))
12683 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12685 case REACTIVE_HUNTER_PARRY
:
12686 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
12687 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12689 case REACTIVE_OVERPOWER
:
12690 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12691 ((Player
*)this)->ClearComboPoints();
12699 m_reactiveTimer
[reactive
] -= p_time
;
12704 Unit
* Unit::SelectNearbyTarget(Unit
* except
/*= NULL*/) const
12706 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
12708 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
12709 cell
.SetNoCreate();
12711 std::list
<Unit
*> targets
;
12713 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, ATTACK_DISTANCE
);
12714 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
12716 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
12717 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
12719 cell
.Visit(p
, world_unit_searcher
, *GetMap(), *this, ATTACK_DISTANCE
);
12720 cell
.Visit(p
, grid_unit_searcher
, *GetMap(), *this, ATTACK_DISTANCE
);
12722 // remove current target
12724 targets
.remove(except
);
12726 // remove not LoS targets
12727 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
12729 if(!IsWithinLOSInMap(*tIter
))
12731 std::list
<Unit
*>::iterator tIter2
= tIter
;
12733 targets
.erase(tIter2
);
12739 // no appropriate targets
12740 if(targets
.empty())
12744 uint32 rIdx
= urand(0,targets
.size()-1);
12745 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
12746 for(uint32 i
= 0; i
< rIdx
; ++i
)
12752 bool Unit::hasNegativeAuraWithInterruptFlag(uint32 flag
)
12754 for (AuraMap::const_iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); ++iter
)
12756 if (!iter
->second
->IsPositive() && iter
->second
->GetSpellProto()->AuraInterruptFlags
& flag
)
12762 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
12766 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
12767 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
12771 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
12772 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
12776 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
12779 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
12781 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
12784 uint32
Unit::GetCastingTimeForBonus( SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 CastingTime
)
12786 // Not apply this to creature casted spells with casttime==0
12787 if(CastingTime
==0 && GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
12790 if (CastingTime
> 7000) CastingTime
= 7000;
12791 if (CastingTime
< 1500) CastingTime
= 1500;
12793 if(damagetype
== DOT
&& !IsChanneledSpell(spellProto
))
12794 CastingTime
= 3500;
12796 int32 overTime
= 0;
12798 bool DirectDamage
= false;
12799 bool AreaEffect
= false;
12801 for ( uint32 i
=0; i
<3;++i
)
12803 switch ( spellProto
->Effect
[i
] )
12805 case SPELL_EFFECT_SCHOOL_DAMAGE
:
12806 case SPELL_EFFECT_POWER_DRAIN
:
12807 case SPELL_EFFECT_HEALTH_LEECH
:
12808 case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
:
12809 case SPELL_EFFECT_POWER_BURN
:
12810 case SPELL_EFFECT_HEAL
:
12811 DirectDamage
= true;
12813 case SPELL_EFFECT_APPLY_AURA
:
12814 switch ( spellProto
->EffectApplyAuraName
[i
] )
12816 case SPELL_AURA_PERIODIC_DAMAGE
:
12817 case SPELL_AURA_PERIODIC_HEAL
:
12818 case SPELL_AURA_PERIODIC_LEECH
:
12819 if ( GetSpellDuration(spellProto
) )
12820 overTime
= GetSpellDuration(spellProto
);
12823 // -5% per additional effect
12831 if(IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetA
[i
])) || IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetB
[i
])))
12835 // Combined Spells with Both Over Time and Direct Damage
12836 if ( overTime
> 0 && CastingTime
> 0 && DirectDamage
)
12838 // mainly for DoTs which are 3500 here otherwise
12839 uint32 OriginalCastTime
= GetSpellCastTime(spellProto
);
12840 if (OriginalCastTime
> 7000) OriginalCastTime
= 7000;
12841 if (OriginalCastTime
< 1500) OriginalCastTime
= 1500;
12842 // Portion to Over Time
12843 float PtOT
= (overTime
/ 15000.0f
) / ((overTime
/ 15000.0f
) + (OriginalCastTime
/ 3500.0f
));
12845 if ( damagetype
== DOT
)
12846 CastingTime
= uint32(CastingTime
* PtOT
);
12847 else if ( PtOT
< 1.0f
)
12848 CastingTime
= uint32(CastingTime
* (1 - PtOT
));
12853 // Area Effect Spells receive only half of bonus
12857 // -5% of total per any additional effect
12858 for ( uint8 i
=0; i
<effects
; ++i
)
12860 if ( CastingTime
> 175 )
12862 CastingTime
-= 175;
12871 return CastingTime
;
12874 void Unit::UpdateAuraForGroup(uint8 slot
)
12876 if(GetTypeId() == TYPEID_PLAYER
)
12878 Player
* player
= (Player
*)this;
12879 if(player
->GetGroup())
12881 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
12882 player
->SetAuraUpdateMask(slot
);
12885 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
12887 Pet
*pet
= ((Pet
*)this);
12888 if(pet
->isControlled())
12890 Unit
*owner
= GetOwner();
12891 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12893 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
12894 pet
->SetAuraUpdateMask(slot
);
12900 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
12902 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
12903 return float(GetAttackTime(attType
))/1000.0f
;
12905 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
, true, false);
12907 return 2.4; // fist attack
12909 switch (Weapon
->GetProto()->InventoryType
)
12911 case INVTYPE_2HWEAPON
:
12913 case INVTYPE_RANGED
:
12914 case INVTYPE_RANGEDRIGHT
:
12915 case INVTYPE_THROWN
:
12917 case INVTYPE_WEAPON
:
12918 case INVTYPE_WEAPONMAINHAND
:
12919 case INVTYPE_WEAPONOFFHAND
:
12921 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7 : 2.4;
12925 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
12927 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
12928 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
12929 if ((*itr
)->GetId() == spell_id
)
12935 void Unit::SetContestedPvP(Player
*attackedPlayer
)
12937 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
12939 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
12942 player
->SetContestedPvPTimer(30000);
12943 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
12945 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
12946 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
12947 // call MoveInLineOfSight for nearby contested guards
12948 SetVisibility(GetVisibility());
12950 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
12952 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
12953 // call MoveInLineOfSight for nearby contested guards
12954 SetVisibility(GetVisibility());
12958 void Unit::AddPetAura(PetAura
const* petSpell
)
12960 m_petAuras
.insert(petSpell
);
12961 if(Pet
* pet
= GetPet())
12962 pet
->CastPetAura(petSpell
);
12965 void Unit::RemovePetAura(PetAura
const* petSpell
)
12967 m_petAuras
.erase(petSpell
);
12968 if(Pet
* pet
= GetPet())
12969 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
12972 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
12974 Pet
* pet
= new Pet(HUNTER_PET
);
12976 if(!pet
->CreateBaseAtCreature(creatureTarget
))
12982 pet
->SetOwnerGUID(GetGUID());
12983 pet
->SetCreatorGUID(GetGUID());
12984 pet
->setFaction(getFaction());
12985 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
12987 if(GetTypeId()==TYPEID_PLAYER
)
12988 pet
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
12994 pet
->SetFFAPvP(true);
12996 uint32 level
= (creatureTarget
->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget
->getLevel();
12998 if(!pet
->InitStatsForLevel(level
))
13000 sLog
.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
13005 pet
->GetCharmInfo()->SetPetNumber(sObjectMgr
.GeneratePetNumber(), true);
13006 // this enables pet details window (Shift+P)
13007 pet
->AIM_Initialize();
13008 pet
->InitPetCreateSpells();
13009 pet
->InitLevelupSpellsForLevel();
13010 pet
->InitTalentForLevel();
13011 pet
->SetHealth(pet
->GetMaxHealth());
13016 bool Unit::IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
13018 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
13020 // Get proc Event Entry
13021 spellProcEvent
= sSpellMgr
.GetSpellProcEvent(spellProto
->Id
);
13023 // Aura info stored here
13024 Modifier
*mod
= aura
->GetModifier();
13026 if (isNonTriggerAura
[mod
->m_auraname
])
13028 // If not trigger by default and spellProcEvent==NULL - skip
13029 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
13032 // Get EventProcFlag
13033 uint32 EventProcFlag
;
13034 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
13035 EventProcFlag
= spellProcEvent
->procFlags
;
13037 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
13038 // Continue if no trigger exist
13039 if (!EventProcFlag
)
13042 // Check spellProcEvent data requirements
13043 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
13046 // In most cases req get honor or XP from kill
13047 if (EventProcFlag
& PROC_FLAG_KILL
&& GetTypeId() == TYPEID_PLAYER
)
13049 bool allow
= ((Player
*)this)->isHonorOrXPTarget(pVictim
);
13050 // Shadow Word: Death - can trigger from every kill
13051 if (aura
->GetId() == 32409)
13056 // Aura added by spell can`t trogger from self (prevent drop charges/do triggers)
13057 // But except periodic triggers (can triggered from self)
13058 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
& PROC_FLAG_ON_TAKE_PERIODIC
))
13061 // Check if current equipment allows aura to proc
13062 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
13064 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
13067 if(attType
== BASE_ATTACK
)
13068 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
13069 else if (attType
== OFF_ATTACK
)
13070 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
13072 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
13074 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
13077 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
13079 // Check if player is wearing shield
13080 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
13081 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
13085 // Get chance from spell
13086 float chance
= (float)spellProto
->procChance
;
13087 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
13088 if(spellProcEvent
&& spellProcEvent
->customChance
)
13089 chance
= spellProcEvent
->customChance
;
13090 // If PPM exist calculate chance from PPM
13091 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
13093 uint32 WeaponSpeed
= GetAttackTime(attType
);
13094 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
13096 // Apply chance modifer aura
13097 if(Player
* modOwner
= GetSpellModOwner())
13099 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
13100 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_FREQUENCY_OF_SUCCESS
,chance
);
13103 return roll_chance_f(chance
);
13106 bool Unit::HandleMendingAuraProc( Aura
* triggeredByAura
)
13108 // aura can be deleted at casts
13109 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
13110 uint32 effIdx
= triggeredByAura
->GetEffIndex();
13111 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
13112 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
13115 int32 jumps
= triggeredByAura
->GetAuraCharges()-1;
13117 // current aura expire
13118 triggeredByAura
->SetAuraCharges(1); // will removed at next charges decrease
13120 // next target selection
13121 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
13124 if (spellProto
->EffectRadiusIndex
[effIdx
])
13125 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
13127 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
13129 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
13131 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
13133 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
13135 // aura will applied from caster, but spell casted from current aura holder
13136 SpellModifier
*mod
= new SpellModifier(SPELLMOD_CHARGES
,SPELLMOD_FLAT
,jumps
-5,spellProto
->Id
,spellProto
->SpellFamilyFlags
,spellProto
->SpellFamilyFlags2
);
13138 // remove before apply next (locked against deleted)
13139 triggeredByAura
->SetInUse(true);
13140 RemoveAurasByCasterSpell(spellProto
->Id
,caster
->GetGUID());
13142 caster
->AddSpellMod(mod
, true);
13143 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
13144 caster
->AddSpellMod(mod
, false);
13145 triggeredByAura
->SetInUse(false);
13151 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
13155 void Unit::RemoveAurasAtMechanicImmunity(uint32 mechMask
, uint32 exceptSpellId
, bool non_positive
/*= false*/)
13157 Unit::AuraMap
& auras
= GetAuras();
13158 for(Unit::AuraMap::iterator iter
= auras
.begin(); iter
!= auras
.end();)
13160 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
13161 if (spell
->Id
== exceptSpellId
)
13163 else if (non_positive
&& iter
->second
->IsPositive())
13165 else if (spell
->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
)
13167 else if (GetSpellMechanicMask(spell
, iter
->second
->GetEffIndex()) & mechMask
)
13169 RemoveAurasDueToSpell(spell
->Id
);
13173 iter
= auras
.begin();
13180 void Unit::SetPhaseMask(uint32 newPhaseMask
, bool update
)
13182 if(newPhaseMask
==GetPhaseMask())
13186 RemoveNotOwnSingleTargetAuras(newPhaseMask
); // we can lost access to caster or target
13188 WorldObject::SetPhaseMask(newPhaseMask
,update
);
13191 if(Pet
* pet
= GetPet())
13192 pet
->SetPhaseMask(newPhaseMask
,true);
13195 void Unit::NearTeleportTo( float x
, float y
, float z
, float orientation
, bool casting
/*= false*/ )
13197 if(GetTypeId() == TYPEID_PLAYER
)
13198 ((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));
13201 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, orientation
);
13204 BuildHeartBeatMsg(&data
);
13205 SendMessageToSet(&data
, false);
13209 struct SetPvPHelper
13211 explicit SetPvPHelper(bool _state
) : state(_state
) {}
13212 void operator()(Unit
* unit
) const { unit
->SetPvP(state
); }
13216 void Unit::SetPvP( bool state
)
13219 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13221 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13223 CallForAllControlledUnits(SetPvPHelper(state
),true,true,true);
13226 struct SetFFAPvPHelper
13228 explicit SetFFAPvPHelper(bool _state
) : state(_state
) {}
13229 void operator()(Unit
* unit
) const { unit
->SetFFAPvP(state
); }
13233 void Unit::SetFFAPvP( bool state
)
13236 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13238 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13240 CallForAllControlledUnits(SetFFAPvPHelper(state
),true,true,true);
13243 void Unit::KnockBackFrom(Unit
* target
, float horizintalSpeed
, float verticalSpeed
)
13245 float angle
= this == target
? GetOrientation() + M_PI
: target
->GetAngle(this);
13246 float vsin
= sin(angle
);
13247 float vcos
= cos(angle
);
13249 // Effect propertly implemented only for players
13250 if(GetTypeId()==TYPEID_PLAYER
)
13252 WorldPacket
data(SMSG_MOVE_KNOCK_BACK
, 8+4+4+4+4+4);
13253 data
.append(GetPackGUID());
13254 data
<< uint32(0); // Sequence
13255 data
<< float(vcos
); // x direction
13256 data
<< float(vsin
); // y direction
13257 data
<< float(horizintalSpeed
); // Horizontal speed
13258 data
<< float(-verticalSpeed
); // Z Movement speed (vertical)
13259 ((Player
*)this)->GetSession()->SendPacket(&data
);
13263 float dis
= horizintalSpeed
;
13266 GetPosition(ox
, oy
, oz
);
13268 float fx
= ox
+ dis
* vcos
;
13269 float fy
= oy
+ dis
* vsin
;
13272 float fx2
, fy2
, fz2
; // getObjectHitPos overwrite last args in any result case
13273 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), ox
,oy
,oz
+0.5, fx
,fy
,oz
+0.5,fx2
,fy2
,fz2
, -0.5))
13278 UpdateGroundPositionZ(fx
, fy
, fz
);
13281 //FIXME: this mostly hack, must exist some packet for proper creature move at client side
13282 // with CreatureRelocation at server side
13283 NearTeleportTo(fx
, fy
, fz
, GetOrientation(), this == target
);
13287 float Unit::GetCombatRatingReduction(CombatRating cr
) const
13289 if (GetTypeId() == TYPEID_PLAYER
)
13290 return ((Player
const*)this)->GetRatingBonusValue(cr
);
13291 else if (((Creature
const*)this)->isPet())
13293 // Player's pet have 0.4 resilience from owner
13294 if (Unit
* owner
= GetOwner())
13295 if(owner
->GetTypeId() == TYPEID_PLAYER
)
13296 return ((Player
*)owner
)->GetRatingBonusValue(cr
) * 0.4f
;
13302 uint32
Unit::GetCombatRatingDamageReduction(CombatRating cr
, float rate
, float cap
, uint32 damage
) const
13304 float percent
= GetCombatRatingReduction(cr
) * rate
;
13307 return uint32 (percent
* damage
/ 100.0f
);
13310 void Unit::SendThreatUpdate()
13312 ThreatList
const& tlist
= getThreatManager().getThreatList();
13313 if (uint32 count
= tlist
.size())
13315 sLog
.outDebug( "WORLD: Send SMSG_THREAT_UPDATE Message" );
13316 WorldPacket
data(SMSG_THREAT_UPDATE
, 8 + count
* 8);
13317 data
.append(GetPackGUID());
13318 data
<< uint32(count
);
13319 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13321 data
.appendPackGUID((*itr
)->getUnitGuid());
13322 data
<< uint32((*itr
)->getThreat());
13324 SendMessageToSet(&data
, false);
13328 void Unit::SendHighestThreatUpdate(HostileReference
* pHostilReference
)
13330 ThreatList
const& tlist
= getThreatManager().getThreatList();
13331 if (uint32 count
= tlist
.size())
13333 sLog
.outDebug( "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message" );
13334 WorldPacket
data(SMSG_HIGHEST_THREAT_UPDATE
, 8 + 8 + count
* 8);
13335 data
.append(GetPackGUID());
13336 data
.appendPackGUID(pHostilReference
->getUnitGuid());
13337 data
<< uint32(count
);
13338 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13340 data
.appendPackGUID((*itr
)->getUnitGuid());
13341 data
<< uint32((*itr
)->getThreat());
13343 SendMessageToSet(&data
, false);
13347 void Unit::SendThreatClear()
13349 sLog
.outDebug( "WORLD: Send SMSG_THREAT_CLEAR Message" );
13350 WorldPacket
data(SMSG_THREAT_CLEAR
, 8);
13351 data
.append(GetPackGUID());
13352 SendMessageToSet(&data
, false);
13355 void Unit::SendThreatRemove(HostileReference
* pHostileReference
)
13357 sLog
.outDebug( "WORLD: Send SMSG_THREAT_REMOVE Message" );
13358 WorldPacket
data(SMSG_THREAT_REMOVE
, 8 + 8);
13359 data
.append(GetPackGUID());
13360 data
.appendPackGUID(pHostileReference
->getUnitGuid());
13361 SendMessageToSet(&data
, false);
13364 struct StopAttackFactionHelper
13366 explicit StopAttackFactionHelper(uint32 _faction_id
) : faction_id(_faction_id
) {}
13367 void operator()(Unit
* unit
) const { unit
->StopAttackFaction(faction_id
); }
13371 void Unit::StopAttackFaction(uint32 faction_id
)
13373 if (Unit
* victim
= getVictim())
13375 if (victim
->getFactionTemplateEntry()->faction
==faction_id
)
13378 if (IsNonMeleeSpellCasted(false))
13379 InterruptNonMeleeSpells(false);
13381 // melee and ranged forced attack cancel
13382 if (GetTypeId() == TYPEID_PLAYER
)
13383 ((Player
*)this)->SendAttackSwingCancelAttack();
13387 AttackerSet
const& attackers
= getAttackers();
13388 for(AttackerSet::const_iterator itr
= attackers
.begin(); itr
!= attackers
.end();)
13390 if ((*itr
)->getFactionTemplateEntry()->faction
==faction_id
)
13392 (*itr
)->AttackStop();
13393 itr
= attackers
.begin();
13399 getHostileRefManager().deleteReferencesForFaction(faction_id
);
13401 CallForAllControlledUnits(StopAttackFactionHelper(faction_id
),false,true,true);
13404 void Unit::CleanupDeletedAuras()
13406 // really delete auras "deleted" while processing its ApplyModify code
13407 for(AuraList::const_iterator itr
= m_deletedAuras
.begin(); itr
!= m_deletedAuras
.end(); ++itr
)
13409 m_deletedAuras
.clear();