2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "WorldPacket.h"
23 #include "WorldSession.h"
25 #include "ObjectMgr.h"
26 #include "ObjectGuid.h"
34 #include "SpellAuras.h"
35 #include "MapManager.h"
36 #include "ObjectAccessor.h"
37 #include "CreatureAI.h"
38 #include "TemporarySummon.h"
43 #include "BattleGround.h"
44 #include "InstanceSaveMgr.h"
45 #include "GridNotifiersImpl.h"
48 #include "Traveller.h"
49 #include "VMapFactory.h"
50 #include "MovementGenerator.h"
55 float baseMoveSpeed
[MAX_MOVE_TYPE
] =
59 2.5f
, // MOVE_RUN_BACK
60 4.722222f
, // MOVE_SWIM
61 4.5f
, // MOVE_SWIM_BACK
62 3.141594f
, // MOVE_TURN_RATE
64 4.5f
, // MOVE_FLIGHT_BACK
65 3.14f
// MOVE_PITCH_RATE
68 // Used for prepare can/can`t trigger aura
69 static bool InitTriggerAuraData();
70 // Define can trigger auras
71 static bool isTriggerAura
[TOTAL_AURAS
];
72 // Define can`t trigger auras (need for disable second trigger)
73 static bool isNonTriggerAura
[TOTAL_AURAS
];
75 static bool procPrepared
= InitTriggerAuraData();
77 void MovementInfo::Read(ByteBuffer
&data
)
87 if(HasMovementFlag(MOVEFLAG_ONTRANSPORT
))
89 data
>> t_guid
.ReadAsPacked();
97 if(moveFlags2
& MOVEFLAG2_INTERP_MOVEMENT
)
101 if((HasMovementFlag(MovementFlags(MOVEFLAG_SWIMMING
| MOVEFLAG_FLYING
))) || (moveFlags2
& MOVEFLAG2_ALLOW_PITCHING
))
108 if(HasMovementFlag(MOVEFLAG_FALLING
))
116 if(HasMovementFlag(MOVEFLAG_SPLINE_ELEVATION
))
122 void MovementInfo::Write(ByteBuffer
&data
) const
132 if(HasMovementFlag(MOVEFLAG_ONTRANSPORT
))
134 data
<< t_guid
.WriteAsPacked();
142 if(moveFlags2
& MOVEFLAG2_INTERP_MOVEMENT
)
146 if((HasMovementFlag(MovementFlags(MOVEFLAG_SWIMMING
| MOVEFLAG_FLYING
))) || (moveFlags2
& MOVEFLAG2_ALLOW_PITCHING
))
153 if(HasMovementFlag(MOVEFLAG_FALLING
))
161 if(HasMovementFlag(MOVEFLAG_SPLINE_ELEVATION
))
168 : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostileRefManager(this)
170 m_objectType
|= TYPEMASK_UNIT
;
171 m_objectTypeId
= TYPEID_UNIT
;
173 m_updateFlag
= (UPDATEFLAG_HIGHGUID
| UPDATEFLAG_LIVING
| UPDATEFLAG_HAS_POSITION
);
175 m_attackTimer
[BASE_ATTACK
] = 0;
176 m_attackTimer
[OFF_ATTACK
] = 0;
177 m_attackTimer
[RANGED_ATTACK
] = 0;
178 m_modAttackSpeedPct
[BASE_ATTACK
] = 1.0f
;
179 m_modAttackSpeedPct
[OFF_ATTACK
] = 1.0f
;
180 m_modAttackSpeedPct
[RANGED_ATTACK
] = 1.0f
;
186 m_deathState
= ALIVE
;
188 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
189 m_currentSpells
[i
] = NULL
;
195 for(int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
198 m_ObjectSlot
[0] = m_ObjectSlot
[1] = m_ObjectSlot
[2] = m_ObjectSlot
[3] = 0;
200 //m_AurasCheck = 2000;
201 //m_removeAuraTimer = 4;
202 m_AurasUpdateIterator
= m_Auras
.end();
205 m_Visibility
= VISIBILITY_ON
;
207 m_detectInvisibilityMask
= 0;
208 m_invisibilityMask
= 0;
210 m_ShapeShiftFormSpellId
= 0;
211 m_canModifyStats
= false;
213 for (int i
= 0; i
< MAX_SPELL_IMMUNITY
; ++i
)
214 m_spellImmune
[i
].clear();
215 for (int i
= 0; i
< UNIT_MOD_END
; ++i
)
217 m_auraModifiersGroup
[i
][BASE_VALUE
] = 0.0f
;
218 m_auraModifiersGroup
[i
][BASE_PCT
] = 1.0f
;
219 m_auraModifiersGroup
[i
][TOTAL_VALUE
] = 0.0f
;
220 m_auraModifiersGroup
[i
][TOTAL_PCT
] = 1.0f
;
222 // implement 50% base damage from offhand
223 m_auraModifiersGroup
[UNIT_MOD_DAMAGE_OFFHAND
][TOTAL_PCT
] = 0.5f
;
225 for (int i
= 0; i
< MAX_ATTACK
; ++i
)
227 m_weaponDamage
[i
][MINDAMAGE
] = BASE_MINDAMAGE
;
228 m_weaponDamage
[i
][MAXDAMAGE
] = BASE_MAXDAMAGE
;
230 for (int i
= 0; i
< MAX_STATS
; ++i
)
231 m_createStats
[i
] = 0.0f
;
234 m_modMeleeHitChance
= 0.0f
;
235 m_modRangedHitChance
= 0.0f
;
236 m_modSpellHitChance
= 0.0f
;
237 m_baseSpellCritChance
= 5;
240 m_lastManaUseTimer
= 0;
242 //m_victimThreat = 0.0f;
243 for (int i
= 0; i
< MAX_SPELL_SCHOOL
; ++i
)
244 m_threatModifier
[i
] = 1.0f
;
246 for (int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
247 m_speed_rate
[i
] = 1.0f
;
251 // remove aurastates allowing special moves
252 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
253 m_reactiveTimer
[i
] = 0;
258 // set current spells as deletable
259 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
261 if (m_currentSpells
[i
])
263 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
264 m_currentSpells
[i
] = NULL
;
271 // those should be already removed at "RemoveFromWorld()" call
272 ASSERT(m_gameObj
.size() == 0);
273 ASSERT(m_dynObjGUIDs
.size() == 0);
274 ASSERT(m_deletedAuras
.size() == 0);
277 void Unit::Update( uint32 p_time
)
282 /*if(p_time > m_AurasCheck)
287 m_AurasCheck -= p_time;*/
289 // WARNING! Order of execution here is important, do not change.
290 // Spells must be processed with event system BEFORE they go to _UpdateSpells.
291 // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
292 m_Events
.Update( p_time
);
293 _UpdateSpells( p_time
);
295 CleanupDeletedAuras();
297 if (m_lastManaUseTimer
)
299 if (p_time
>= m_lastManaUseTimer
)
300 m_lastManaUseTimer
= 0;
302 m_lastManaUseTimer
-= p_time
;
305 if (CanHaveThreatList())
306 getThreatManager().UpdateForClient(p_time
);
308 // update combat timer only for players and pets
309 if (isInCombat() && (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet() || ((Creature
*)this)->isCharmed()))
311 // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away
312 // targets without stopping half way there and running off.
313 // These flags are reset after target dies or another command is given.
314 if (m_HostileRefManager
.isEmpty())
316 // m_CombatTimer set at aura start and it will be freeze until aura removing
317 if (m_CombatTimer
<= p_time
)
320 m_CombatTimer
-= p_time
;
324 if (uint32 base_att
= getAttackTimer(BASE_ATTACK
))
326 setAttackTimer(BASE_ATTACK
, (p_time
>= base_att
? 0 : base_att
- p_time
) );
329 // update abilities available only for fraction of time
330 UpdateReactives( p_time
);
332 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, GetHealth() < GetMaxHealth()*0.20f
);
333 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, GetHealth() < GetMaxHealth()*0.35f
);
334 ModifyAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT
, GetHealth() > GetMaxHealth()*0.75f
);
336 i_motionMaster
.UpdateMotion(p_time
);
339 bool Unit::haveOffhandWeapon() const
341 if(GetTypeId() == TYPEID_PLAYER
)
342 return ((Player
*)this)->GetWeaponForAttack(OFF_ATTACK
,true,true);
347 void Unit::SendMonsterMove(float NewPosX
, float NewPosY
, float NewPosZ
, SplineType type
, SplineFlags flags
, uint32 Time
, Player
* player
, ...)
351 va_start(vargs
,player
);
353 float moveTime
= (float)Time
;
355 WorldPacket
data( SMSG_MONSTER_MOVE
, (41 + GetPackGUID().size()) );
356 data
<< GetPackGUID();
357 data
<< uint8(0); // new in 3.1 bool, used to toggle MOVEFLAG2_UNK4 = 0x0040 on client side
358 data
<< GetPositionX() << GetPositionY() << GetPositionZ();
359 data
<< uint32(getMSTime());
361 data
<< uint8(type
); // unknown
364 case SPLINETYPE_NORMAL
: // normal packet
366 case SPLINETYPE_STOP
: // stop packet (raw pos?)
368 SendMessageToSet( &data
, true );
370 case SPLINETYPE_FACINGSPOT
: // facing spot, not used currently
372 data
<< float(va_arg(vargs
,double));
373 data
<< float(va_arg(vargs
,double));
374 data
<< float(va_arg(vargs
,double));
377 case SPLINETYPE_FACINGTARGET
:
378 data
<< uint64(va_arg(vargs
,uint64
));
380 case SPLINETYPE_FACINGANGLE
: // not used currently
381 data
<< float(va_arg(vargs
,double)); // facing angle
385 data
<< uint32(flags
);
387 // enable me if things goes wrong or looks ugly, it is however an old hack
388 // if(flags & SPLINEFLAG_WALKMODE)
389 // moveTime *= 1.05f;
391 data
<< uint32(moveTime
); // Time in between points
392 data
<< uint32(1); // 1 single waypoint
393 data
<< NewPosX
<< NewPosY
<< NewPosZ
; // the single waypoint Point B
398 player
->GetSession()->SendPacket(&data
);
400 SendMessageToSet( &data
, true );
403 void Unit::SendMonsterMoveWithSpeed(float x
, float y
, float z
, uint32 transitTime
, Player
* player
)
407 if(GetTypeId()==TYPEID_PLAYER
)
409 Traveller
<Player
> traveller(*(Player
*)this);
410 transitTime
= traveller
.GetTotalTrevelTimeTo(x
, y
, z
);
414 Traveller
<Creature
> traveller(*(Creature
*)this);
415 transitTime
= traveller
.GetTotalTrevelTimeTo(x
, y
, z
);
418 //float orientation = (float)atan2((double)dy, (double)dx);
419 SplineFlags flags
= GetTypeId() == TYPEID_PLAYER
? SPLINEFLAG_WALKMODE
: ((Creature
*)this)->GetSplineFlags();
420 SendMonsterMove(x
, y
, z
, SPLINETYPE_NORMAL
, flags
, transitTime
, player
);
423 void Unit::BuildHeartBeatMsg(WorldPacket
*data
) const
425 MovementFlags move_flags
= GetTypeId()==TYPEID_PLAYER
426 ? ((Player
const*)this)->m_movementInfo
.GetMovementFlags()
429 data
->Initialize(MSG_MOVE_HEARTBEAT
, 32);
430 *data
<< GetPackGUID();
431 *data
<< uint32(move_flags
); // movement flags
432 *data
<< uint16(0); // 2.3.0
433 *data
<< uint32(getMSTime()); // time
434 *data
<< float(GetPositionX());
435 *data
<< float(GetPositionY());
436 *data
<< float(GetPositionZ());
437 *data
<< float(GetOrientation());
441 void Unit::resetAttackTimer(WeaponAttackType type
)
443 m_attackTimer
[type
] = uint32(GetAttackTime(type
) * m_modAttackSpeedPct
[type
]);
446 bool Unit::canReachWithAttack(Unit
*pVictim
) const
449 float reach
= GetFloatValue(UNIT_FIELD_COMBATREACH
);
452 return IsWithinDistInMap(pVictim
, reach
);
455 void Unit::RemoveSpellsCausingAura(AuraType auraType
)
457 if (auraType
>= TOTAL_AURAS
) return;
458 AuraList::const_iterator iter
, next
;
459 for (iter
= m_modAuras
[auraType
].begin(); iter
!= m_modAuras
[auraType
].end(); iter
= next
)
466 RemoveAurasDueToSpell((*iter
)->GetId());
467 if (!m_modAuras
[auraType
].empty())
468 next
= m_modAuras
[auraType
].begin();
475 bool Unit::HasAuraType(AuraType auraType
) const
477 return (!m_modAuras
[auraType
].empty());
480 /* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */
481 void Unit::RemoveSpellbyDamageTaken(AuraType auraType
, uint32 damage
)
483 if(!HasAuraType(auraType
))
486 // The chance to dispel an aura depends on the damage taken with respect to the casters level.
487 uint32 max_dmg
= getLevel() > 8 ? 25 * getLevel() - 150 : 50;
488 float chance
= float(damage
) / max_dmg
* 100.0f
;
489 if (roll_chance_f(chance
))
490 RemoveSpellsCausingAura(auraType
);
493 void Unit::DealDamageMods(Unit
*pVictim
, uint32
&damage
, uint32
* absorb
)
495 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
503 //You don't lose health from damage taken from another player while in a sanctuary
504 //You still see it in the combat log though
505 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
507 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
508 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) //sanctuary
516 uint32 originalDamage
= damage
;
518 //Script Event damage Deal
519 if( GetTypeId()== TYPEID_UNIT
&& ((Creature
*)this)->AI())
520 ((Creature
*)this)->AI()->DamageDeal(pVictim
, damage
);
521 //Script Event damage taken
522 if( pVictim
->GetTypeId()== TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI() )
523 ((Creature
*)pVictim
)->AI()->DamageTaken(this, damage
);
525 if(absorb
&& originalDamage
> damage
)
526 absorb
+= (originalDamage
- damage
);
529 uint32
Unit::DealDamage(Unit
*pVictim
, uint32 damage
, CleanDamage
const* cleanDamage
, DamageEffectType damagetype
, SpellSchoolMask damageSchoolMask
, SpellEntry
const *spellProto
, bool durabilityLoss
)
531 // remove affects from victim (including from 0 damage and DoTs)
533 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
535 // remove affects from attacker at any non-DoT damage (including 0 damage)
536 if( damagetype
!= DOT
)
538 RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
539 RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
542 RemoveSpellsCausingAura(SPELL_AURA_MOD_INVISIBILITY
);
544 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->IsStandState() && !pVictim
->hasUnitState(UNIT_STAT_STUNNED
))
545 pVictim
->SetStandState(UNIT_STAND_STATE_STAND
);
550 // Rage from physical damage received .
551 if(cleanDamage
&& cleanDamage
->damage
&& (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
) && pVictim
->GetTypeId() == TYPEID_PLAYER
&& (pVictim
->getPowerType() == POWER_RAGE
))
552 ((Player
*)pVictim
)->RewardRage(cleanDamage
->damage
, 0, false);
556 if (!spellProto
|| !IsSpellHaveAura(spellProto
,SPELL_AURA_MOD_FEAR
))
557 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_FEAR
, damage
);
558 // root type spells do not dispel the root effect
559 if (!spellProto
|| !(spellProto
->Mechanic
== MECHANIC_ROOT
|| IsSpellHaveAura(spellProto
,SPELL_AURA_MOD_ROOT
)))
560 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_ROOT
, damage
);
562 // no xp,health if type 8 /critters/
563 if(pVictim
->GetTypeId() != TYPEID_PLAYER
&& pVictim
->GetCreatureType() == CREATURE_TYPE_CRITTER
)
565 pVictim
->setDeathState(JUST_DIED
);
566 pVictim
->SetHealth(0);
568 // allow loot only if has loot_id in creature_template
569 CreatureInfo
const* cInfo
= ((Creature
*)pVictim
)->GetCreatureInfo();
570 if(cInfo
&& cInfo
->lootid
)
571 pVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
573 // some critters required for quests (need normal entry instead possible heroic in any cases)
574 if(GetTypeId() == TYPEID_PLAYER
)
575 if(CreatureInfo
const* normalInfo
= ObjectMgr::GetCreatureTemplate(pVictim
->GetEntry()))
576 ((Player
*)this)->KilledMonster(normalInfo
,pVictim
->GetObjectGuid());
581 DEBUG_LOG("DealDamageStart");
583 uint32 health
= pVictim
->GetHealth();
584 DETAIL_LOG("deal dmg:%d to health:%d ",damage
,health
);
586 // duel ends when player has 1 or less hp
587 bool duel_hasEnded
= false;
588 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->duel
&& damage
>= (health
-1))
590 // prevent kill only if killed in duel and killed by opponent or opponent controlled creature
591 if(((Player
*)pVictim
)->duel
->opponent
==this || ((Player
*)pVictim
)->duel
->opponent
->GetGUID() == GetOwnerGUID())
594 duel_hasEnded
= true;
597 if(pVictim
!= this && damagetype
!= DOT
)
599 SetInCombatWith(pVictim
);
600 pVictim
->SetInCombatWith(this);
602 if(Player
* attackedPlayer
= pVictim
->GetCharmerOrOwnerPlayerOrPlayerItself())
603 SetContestedPvP(attackedPlayer
);
606 // Rage from Damage made (only from direct weapon damage)
607 if( cleanDamage
&& damagetype
==DIRECT_DAMAGE
&& this != pVictim
&& GetTypeId() == TYPEID_PLAYER
&& (getPowerType() == POWER_RAGE
))
609 uint32 weaponSpeedHitFactor
;
611 switch(cleanDamage
->attackType
)
615 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
616 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 7);
618 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
620 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
626 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
627 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
629 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 1.75f
);
631 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
640 if (GetTypeId() == TYPEID_PLAYER
&& this != pVictim
)
642 Player
*killer
= ((Player
*)this);
644 // in bg, count dmg if victim is also a player
645 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
647 if (BattleGround
*bg
= killer
->GetBattleGround())
649 // FIXME: kept by compatibility. don't know in BG if the restriction apply.
650 bg
->UpdatePlayerScore(killer
, SCORE_DAMAGE_DONE
, damage
);
654 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DAMAGE_DONE
, damage
, 0, pVictim
);
655 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_DEALT
, damage
);
658 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
659 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_RECEIVED
, damage
);
661 if (pVictim
->GetTypeId() == TYPEID_UNIT
&& !((Creature
*)pVictim
)->isPet() && !((Creature
*)pVictim
)->HasLootRecipient())
662 ((Creature
*)pVictim
)->SetLootRecipient(this);
664 if (health
<= damage
)
666 DEBUG_LOG("DealDamage: victim just died");
668 // find player: owner of controlled `this` or `this` itself maybe
669 // for loot will be sued only if group_tap==NULL
670 Player
*player_tap
= GetCharmerOrOwnerPlayerOrPlayerItself();
671 Group
*group_tap
= NULL
;
673 // find owner of pVictim, used for creature cases, AI calls
674 Unit
* pOwner
= pVictim
->GetCharmerOrOwner();
676 // in creature kill case group/player tap stored for creature
677 if (pVictim
->GetTypeId() == TYPEID_UNIT
)
679 group_tap
= ((Creature
*)pVictim
)->GetGroupLootRecipient();
681 if (Player
* recipient
= ((Creature
*)pVictim
)->GetOriginalLootRecipient())
682 player_tap
= recipient
;
684 // in player kill case group tap selected by player_tap (killer-player itself, or charmer, or owner, etc)
688 group_tap
= player_tap
->GetGroup();
691 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
693 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, health
);
695 player_tap
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_SPECIAL_PVP_KILL
,1,0,pVictim
);
698 // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop)
699 if(player_tap
&& player_tap
!= pVictim
)
701 player_tap
->ProcDamageAndSpell(pVictim
, PROC_FLAG_KILL
, PROC_FLAG_KILLED
, PROC_EX_NONE
, 0);
703 WorldPacket
data(SMSG_PARTYKILLLOG
, (8+8)); //send event PARTY_KILL
704 data
<< player_tap
->GetObjectGuid(); //player with killing blow
705 data
<< pVictim
->GetObjectGuid(); //victim
708 group_tap
->BroadcastPacket(&data
, false, group_tap
->GetMemberGroup(player_tap
->GetGUID()),player_tap
->GetGUID());
710 player_tap
->SendDirectMessage(&data
);
713 // Reward player, his pets, and group/raid members
714 if (player_tap
!= pVictim
)
717 group_tap
->RewardGroupAtKill(pVictim
);
719 player_tap
->RewardSinglePlayerAtKill(pVictim
);
722 DEBUG_LOG("DealDamageAttackStop");
725 pVictim
->CombatStop();
726 pVictim
->getHostileRefManager().deleteReferences();
728 bool damageFromSpiritOfRedemtionTalent
= spellProto
&& spellProto
->Id
== 27795;
730 // if talent known but not triggered (check priest class for speedup check)
731 Aura
* spiritOfRedemtionTalentReady
= NULL
;
732 if( !damageFromSpiritOfRedemtionTalent
&& // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION
733 pVictim
->GetTypeId()==TYPEID_PLAYER
&& pVictim
->getClass()==CLASS_PRIEST
)
735 AuraList
const& vDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
736 for(AuraList::const_iterator itr
= vDummyAuras
.begin(); itr
!= vDummyAuras
.end(); ++itr
)
738 if((*itr
)->GetSpellProto()->SpellIconID
==1654)
740 spiritOfRedemtionTalentReady
= *itr
;
746 DEBUG_LOG("SET JUST_DIED");
747 if(!spiritOfRedemtionTalentReady
)
748 pVictim
->setDeathState(JUST_DIED
);
750 DEBUG_LOG("DealDamageHealth1");
752 if(spiritOfRedemtionTalentReady
)
754 // save value before aura remove
755 uint32 ressSpellId
= pVictim
->GetUInt32Value(PLAYER_SELF_RES_SPELL
);
757 ressSpellId
= ((Player
*)pVictim
)->GetResurrectionSpellId();
759 //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers)
760 pVictim
->RemoveAllAurasOnDeath();
762 // restore for use at real death
763 pVictim
->SetUInt32Value(PLAYER_SELF_RES_SPELL
,ressSpellId
);
765 // FORM_SPIRITOFREDEMPTION and related auras
766 pVictim
->CastSpell(pVictim
,27827,true,NULL
,spiritOfRedemtionTalentReady
);
769 pVictim
->SetHealth(0);
771 // remember victim PvP death for corpse type and corpse reclaim delay
772 // at original death (not at SpiritOfRedemtionTalent timeout)
773 if( pVictim
->GetTypeId()==TYPEID_PLAYER
&& !damageFromSpiritOfRedemtionTalent
)
774 ((Player
*)pVictim
)->SetPvPDeath(player_tap
!= NULL
);
776 // Call KilledUnit for creatures
777 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->AI())
778 ((Creature
*)this)->AI()->KilledUnit(pVictim
);
781 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
783 if (GetTypeId() == TYPEID_UNIT
)
784 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE
, GetEntry());
785 else if(GetTypeId() == TYPEID_PLAYER
&& pVictim
!= this)
786 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER
, 1, ((Player
*)this)->GetTeam());
789 // 10% durability loss on death
790 // clean InHateListOf
791 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
793 // only if not player and not controlled by player pet. And not at BG
794 if (durabilityLoss
&& !player_tap
&& !((Player
*)pVictim
)->InBattleGround())
796 DEBUG_LOG("We are dead, loosing 10 percents durability");
797 ((Player
*)pVictim
)->DurabilityLossAll(0.10f
,false);
798 // durability lost message
799 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
800 ((Player
*)pVictim
)->GetSession()->SendPacket(&data
);
803 else // creature died
805 DEBUG_LOG("DealDamageNotPlayer");
806 Creature
*cVictim
= (Creature
*)pVictim
;
808 if(!cVictim
->isPet())
810 cVictim
->DeleteThreatList();
811 // only lootable if it has loot or can drop gold
812 if(cVictim
->GetCreatureInfo()->lootid
|| cVictim
->GetCreatureInfo()->maxgold
> 0)
813 cVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
815 cVictim
->lootForBody
= true; // needed for skinning
817 // Call creature just died function
819 cVictim
->AI()->JustDied(this);
821 if (cVictim
->isTemporarySummon())
823 TemporarySummon
* pSummon
= (TemporarySummon
*)cVictim
;
824 if (pSummon
->GetSummonerGuid().IsCreature())
825 if(Creature
* pSummoner
= cVictim
->GetMap()->GetCreature(pSummon
->GetSummonerGuid()))
827 pSummoner
->AI()->SummonedCreatureJustDied(cVictim
);
829 else if (pOwner
&& pOwner
->GetTypeId() == TYPEID_UNIT
)
831 if (((Creature
*)pOwner
)->AI())
832 ((Creature
*)pOwner
)->AI()->SummonedCreatureJustDied(cVictim
);
835 // Dungeon specific stuff, only applies to players killing creatures
836 if(cVictim
->GetInstanceId())
838 Map
*m
= cVictim
->GetMap();
839 Player
*creditedPlayer
= GetCharmerOrOwnerPlayerOrPlayerItself();
840 // TODO: do instance binding anyway if the charmer/owner is offline
842 if(m
->IsDungeon() && creditedPlayer
)
844 if (m
->IsRaidOrHeroicDungeon())
846 if(cVictim
->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
847 ((InstanceMap
*)m
)->PermBindAllPlayers(creditedPlayer
);
851 // the reset time is set but not added to the scheduler
852 // until the players leave the instance
853 time_t resettime
= cVictim
->GetRespawnTimeEx() + 2 * HOUR
;
854 if(InstanceSave
*save
= sInstanceSaveMgr
.GetInstanceSave(cVictim
->GetInstanceId()))
855 if(save
->GetResetTime() < resettime
) save
->SetResetTime(resettime
);
861 // last damage from non duel opponent or opponent controlled creature
864 ASSERT(pVictim
->GetTypeId()==TYPEID_PLAYER
);
865 Player
*he
= (Player
*)pVictim
;
869 he
->duel
->opponent
->CombatStopWithPets(true);
870 he
->CombatStopWithPets(true);
872 he
->DuelComplete(DUEL_INTERUPTED
);
875 // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill)
876 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->InBattleGround())
878 Player
*killed
= ((Player
*)pVictim
);
879 if(BattleGround
*bg
= killed
->GetBattleGround())
881 bg
->HandleKillPlayer(killed
, player_tap
);
883 else if(pVictim
->GetTypeId() == TYPEID_UNIT
)
886 if (BattleGround
*bg
= player_tap
->GetBattleGround())
887 bg
->HandleKillUnit((Creature
*)pVictim
, player_tap
);
890 else // if (health <= damage)
892 DEBUG_LOG("DealDamageAlive");
894 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
895 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, damage
);
897 pVictim
->ModifyHealth(- (int32
)damage
);
899 if(damagetype
!= DOT
)
903 // if not have main target then attack state with target (including AI call)
904 //start melee attacks only after melee hit
905 Attack(pVictim
,(damagetype
== DIRECT_DAMAGE
));
908 // if damage pVictim call AI reaction
909 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
910 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
913 // polymorphed, hex and other negative transformed cases
914 uint32 morphSpell
= pVictim
->getTransForm();
915 if (morphSpell
&& !IsPositiveSpell(morphSpell
))
917 if (SpellEntry
const* morphEntry
= sSpellStore
.LookupEntry(morphSpell
))
919 if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_CONFUSE
))
920 pVictim
->RemoveAurasDueToSpell(morphSpell
);
921 else if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_PACIFY_SILENCE
))
922 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_PACIFY_SILENCE
, damage
);
926 if(damagetype
== DIRECT_DAMAGE
|| damagetype
== SPELL_DIRECT_DAMAGE
)
928 if (!spellProto
|| !(spellProto
->AuraInterruptFlags
&AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
))
929 pVictim
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
);
931 if (pVictim
->GetTypeId() != TYPEID_PLAYER
)
933 if(spellProto
&& IsDamageToThreatSpell(spellProto
))
934 pVictim
->AddThreat(this, float(damage
*2), (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
936 pVictim
->AddThreat(this, float(damage
), (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
938 else // victim is a player
940 // Rage from damage received
941 if(this != pVictim
&& pVictim
->getPowerType() == POWER_RAGE
)
943 uint32 rage_damage
= damage
+ (cleanDamage
? cleanDamage
->damage
: 0);
944 ((Player
*)pVictim
)->RewardRage(rage_damage
, 0, false);
947 // random durability for items (HIT TAKEN)
948 if (roll_chance_f(sWorld
.getConfig(CONFIG_FLOAT_RATE_DURABILITY_LOSS_DAMAGE
)))
950 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
951 ((Player
*)pVictim
)->DurabilityPointLossForEquipSlot(slot
);
955 if(GetTypeId()==TYPEID_PLAYER
)
957 // random durability for items (HIT DONE)
958 if (roll_chance_f(sWorld
.getConfig(CONFIG_FLOAT_RATE_DURABILITY_LOSS_DAMAGE
)))
960 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
961 ((Player
*)this)->DurabilityPointLossForEquipSlot(slot
);
965 // TODO: Store auras by interrupt flag to speed this up.
966 AuraMap
& vAuras
= pVictim
->GetAuras();
967 for (AuraMap::const_iterator i
= vAuras
.begin(), next
; i
!= vAuras
.end(); i
= next
)
969 const SpellEntry
*se
= i
->second
->GetSpellProto();
971 if (spellProto
&& spellProto
->Id
== se
->Id
) // Not drop auras added by self
973 if( se
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_DAMAGE
)
976 if (se
->procFlags
& (1<<3))
978 if (!roll_chance_i(se
->procChance
))
983 pVictim
->RemoveAurasDueToSpell(i
->second
->GetId());
984 // FIXME: this may cause the auras with proc chance to be rerolled several times
985 next
= vAuras
.begin();
990 if (damagetype
!= NODAMAGE
&& damage
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
992 if( damagetype
!= DOT
)
994 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
996 // skip channeled spell (processed differently below)
997 if (i
== CURRENT_CHANNELED_SPELL
)
1000 if(Spell
* spell
= pVictim
->GetCurrentSpell(CurrentSpellTypes(i
)))
1002 if(spell
->getState() == SPELL_STATE_PREPARING
)
1004 if(spell
->m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_ABORT_ON_DMG
)
1005 pVictim
->InterruptSpell(CurrentSpellTypes(i
));
1013 if(Spell
* spell
= pVictim
->m_currentSpells
[CURRENT_CHANNELED_SPELL
])
1015 if (spell
->getState() == SPELL_STATE_CASTING
)
1017 uint32 channelInterruptFlags
= spell
->m_spellInfo
->ChannelInterruptFlags
;
1018 if( channelInterruptFlags
& CHANNEL_FLAG_DELAY
)
1020 if(pVictim
!=this) //don't shorten the duration of channeling if you damage yourself
1021 spell
->DelayedChannel();
1023 else if( (channelInterruptFlags
& (CHANNEL_FLAG_DAMAGE
| CHANNEL_FLAG_DAMAGE2
)) )
1025 DETAIL_LOG("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
1026 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
1029 else if (spell
->getState() == SPELL_STATE_DELAYED
)
1030 // break channeled spell in delayed state on damage
1032 DETAIL_LOG("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
1033 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
1038 // last damage from duel opponent
1041 ASSERT(pVictim
->GetTypeId()==TYPEID_PLAYER
);
1042 Player
*he
= (Player
*)pVictim
;
1048 he
->duel
->opponent
->CombatStopWithPets(true);
1049 he
->CombatStopWithPets(true);
1051 he
->CastSpell(he
, 7267, true); // beg
1052 he
->DuelComplete(DUEL_WON
);
1056 DEBUG_LOG("DealDamageEnd returned %d damage", damage
);
1061 void Unit::CastStop(uint32 except_spellid
)
1063 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
1064 if (m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
!=except_spellid
)
1065 InterruptSpell(CurrentSpellTypes(i
),false);
1068 void Unit::CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1070 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1074 sLog
.outError("CastSpell: unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1078 CastSpell(Victim
, spellInfo
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1081 void Unit::CastSpell(Unit
* Victim
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1085 sLog
.outError("CastSpell: unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1090 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1092 if(originalCaster
.IsEmpty() && triggeredByAura
)
1093 originalCaster
= triggeredByAura
->GetCasterGUID();
1095 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1097 SpellCastTargets targets
;
1098 targets
.setUnitTarget( Victim
);
1099 spell
->m_CastItem
= castItem
;
1100 spell
->prepare(&targets
, triggeredByAura
);
1103 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1105 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1109 sLog
.outError("CastCustomSpell: unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1113 CastCustomSpell(Victim
, spellInfo
, bp0
, bp1
, bp2
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1116 void Unit::CastCustomSpell(Unit
* Victim
, SpellEntry
const *spellInfo
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1120 sLog
.outError("CastCustomSpell: unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1125 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1127 if(originalCaster
.IsEmpty() && triggeredByAura
)
1128 originalCaster
= triggeredByAura
->GetCasterGUID();
1130 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1133 spell
->m_currentBasePoints
[EFFECT_INDEX_0
] = *bp0
;
1136 spell
->m_currentBasePoints
[EFFECT_INDEX_1
] = *bp1
;
1139 spell
->m_currentBasePoints
[EFFECT_INDEX_2
] = *bp2
;
1141 SpellCastTargets targets
;
1142 targets
.setUnitTarget( Victim
);
1143 spell
->m_CastItem
= castItem
;
1144 spell
->prepare(&targets
, triggeredByAura
);
1147 // used for scripting
1148 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1150 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1154 sLog
.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s", spellId
, GetObjectGuid().GetString().c_str());
1158 CastSpell(x
, y
, z
, spellInfo
, triggered
, castItem
, triggeredByAura
, originalCaster
);
1161 // used for scripting
1162 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, ObjectGuid originalCaster
)
1166 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s", GetObjectGuid().GetString().c_str());
1171 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1173 if(originalCaster
.IsEmpty() && triggeredByAura
)
1174 originalCaster
= triggeredByAura
->GetCasterGUID();
1176 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1178 SpellCastTargets targets
;
1179 targets
.setDestination(x
, y
, z
);
1180 spell
->m_CastItem
= castItem
;
1181 spell
->prepare(&targets
, triggeredByAura
);
1184 // Obsolete func need remove, here only for comotability vs another patches
1185 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
)
1187 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
1188 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, spellInfo
->SchoolMask
);
1189 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
1190 damageInfo
.target
->CalculateAbsorbResistBlock(this, &damageInfo
, spellInfo
);
1191 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
1192 SendSpellNonMeleeDamageLog(&damageInfo
);
1193 DealSpellDamage(&damageInfo
, true);
1194 return damageInfo
.damage
;
1197 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
1199 SpellSchoolMask damageSchoolMask
= SpellSchoolMask(damageInfo
->schoolMask
);
1200 Unit
*pVictim
= damageInfo
->target
;
1205 if(!this || !pVictim
)
1207 if(!this->isAlive() || !pVictim
->isAlive())
1210 // Check spell crit chance
1211 bool crit
= IsSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
1213 // damage bonus (per damage class)
1214 switch (spellInfo
->DmgClass
)
1216 // Melee and Ranged Spells
1217 case SPELL_DAMAGE_CLASS_RANGED
:
1218 case SPELL_DAMAGE_CLASS_MELEE
:
1220 //Calculate damage bonus
1221 damage
= MeleeDamageBonusDone(pVictim
, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1222 damage
= pVictim
->MeleeDamageBonusTaken(this, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1224 // if crit add critical bonus
1227 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1228 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1229 // Resilience - reduce crit damage
1230 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1231 if (attackType
!= RANGED_ATTACK
)
1232 damage
-= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1234 damage
-= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1239 case SPELL_DAMAGE_CLASS_NONE
:
1240 case SPELL_DAMAGE_CLASS_MAGIC
:
1242 // Calculate damage bonus
1243 damage
= SpellDamageBonusDone(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1244 damage
= pVictim
->SpellDamageBonusTaken(this, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1246 // If crit add critical bonus
1249 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1250 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1251 // Resilience - reduce crit damage
1252 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1253 damage
-= pVictim
->GetSpellCritDamageReduction(redunction_affected_damage
);
1259 // only from players
1260 if (GetTypeId() == TYPEID_PLAYER
)
1262 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1263 damage
-= pVictim
->GetSpellDamageReduction(redunction_affected_damage
);
1266 // damage mitigation
1269 // physical damage => armor
1270 if (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
1272 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1273 damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(pVictim
, armor_affected_damage
);
1278 damageInfo
->damage
= damage
;
1281 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1286 Unit
*pVictim
= damageInfo
->target
;
1288 if(!this || !pVictim
)
1291 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1294 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1295 if (spellProto
== NULL
)
1297 DEBUG_LOG("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1301 //You don't lose health from damage taken from another player while in a sanctuary
1302 //You still see it in the combat log though
1303 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1305 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1306 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1310 // Call default DealDamage (send critical in hit info for threat calculation)
1311 CleanDamage
cleanDamage(0, BASE_ATTACK
, damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
? MELEE_HIT_CRIT
: MELEE_HIT_NORMAL
);
1312 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->schoolMask
), spellProto
, durabilityLoss
);
1315 //TODO for melee need create structure as in
1316 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1318 damageInfo
->attacker
= this;
1319 damageInfo
->target
= pVictim
;
1320 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1321 damageInfo
->attackType
= attackType
;
1322 damageInfo
->damage
= 0;
1323 damageInfo
->cleanDamage
= 0;
1324 damageInfo
->absorb
= 0;
1325 damageInfo
->resist
= 0;
1326 damageInfo
->blocked_amount
= 0;
1328 damageInfo
->TargetState
= 0;
1329 damageInfo
->HitInfo
= 0;
1330 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1331 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1332 damageInfo
->procEx
= PROC_EX_NONE
;
1333 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1335 if(!this || !pVictim
)
1337 if(!this->isAlive() || !pVictim
->isAlive())
1340 // Select HitInfo/procAttacker/procVictim flag based on attack type
1344 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
;
1345 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1346 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1349 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1350 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1351 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1354 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1355 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1356 damageInfo
->HitInfo
= 0x08;// test
1362 // Physical Immune check
1363 if (damageInfo
->target
->IsImmunedToDamage(damageInfo
->damageSchoolMask
))
1365 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1366 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1368 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1369 damageInfo
->damage
= 0;
1370 damageInfo
->cleanDamage
= 0;
1373 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1374 // Add melee damage bonus
1375 damage
= MeleeDamageBonusDone(damageInfo
->target
, damage
, damageInfo
->attackType
);
1376 damage
= damageInfo
->target
->MeleeDamageBonusTaken(this, damage
, damageInfo
->attackType
);
1377 // Calculate armor reduction
1379 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageInfo
->damageSchoolMask
);
1380 damageInfo
->damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(damageInfo
->target
, armor_affected_damage
);
1381 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1383 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1385 // Disable parry or dodge for ranged attack
1386 if (damageInfo
->attackType
== RANGED_ATTACK
)
1388 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1389 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1392 switch(damageInfo
->hitOutCome
)
1394 case MELEE_HIT_EVADE
:
1396 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1397 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1399 damageInfo
->procEx
|=PROC_EX_EVADE
;
1400 damageInfo
->damage
= 0;
1401 damageInfo
->cleanDamage
= 0;
1404 case MELEE_HIT_MISS
:
1406 damageInfo
->HitInfo
|= HITINFO_MISS
;
1407 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1409 damageInfo
->procEx
|=PROC_EX_MISS
;
1410 damageInfo
->damage
= 0;
1411 damageInfo
->cleanDamage
= 0;
1414 case MELEE_HIT_NORMAL
:
1415 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1416 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1418 case MELEE_HIT_CRIT
:
1420 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1421 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1423 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1425 damageInfo
->damage
+= damageInfo
->damage
;
1427 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1428 if(damageInfo
->attackType
== RANGED_ATTACK
)
1429 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1431 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1433 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, SPELL_SCHOOL_MASK_NORMAL
);
1435 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1437 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1438 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1440 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1442 // Resilience - reduce crit damage
1443 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1444 uint32 resilienceReduction
;
1445 if (attackType
!= RANGED_ATTACK
)
1446 resilienceReduction
= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1448 resilienceReduction
= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1450 damageInfo
->damage
-= resilienceReduction
;
1451 damageInfo
->cleanDamage
+= resilienceReduction
;
1454 case MELEE_HIT_PARRY
:
1455 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1456 damageInfo
->procEx
|= PROC_EX_PARRY
;
1457 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1458 damageInfo
->damage
= 0;
1461 case MELEE_HIT_DODGE
:
1462 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1463 damageInfo
->procEx
|=PROC_EX_DODGE
;
1464 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1465 damageInfo
->damage
= 0;
1467 case MELEE_HIT_BLOCK
:
1469 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1470 damageInfo
->HitInfo
|= HITINFO_BLOCK
;
1471 damageInfo
->procEx
|= PROC_EX_BLOCK
;
1472 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1474 // Target has a chance to double the blocked amount if it has SPELL_AURA_MOD_BLOCK_CRIT_CHANCE
1475 if (roll_chance_i(pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_CRIT_CHANCE
)))
1476 damageInfo
->blocked_amount
*= 2;
1478 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1480 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1481 damageInfo
->blocked_amount
= damageInfo
->damage
;
1482 damageInfo
->procEx
|= PROC_EX_FULL_BLOCK
;
1485 damageInfo
->procEx
|= PROC_EX_NORMAL_HIT
; // Partial blocks can still cause attacker procs
1487 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1488 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1491 case MELEE_HIT_GLANCING
:
1493 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1494 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1495 damageInfo
->procEx
|= PROC_EX_NORMAL_HIT
;
1496 float reducePercent
= 1.0f
; //damage factor
1497 // calculate base values and mods
1498 float baseLowEnd
= 1.3f
;
1499 float baseHighEnd
= 1.2f
;
1500 switch(getClass()) // lowering base values for casters
1508 baseHighEnd
-= 0.3f
;
1512 float maxLowEnd
= 0.6f
;
1513 switch(getClass()) // upper for melee classes
1517 maxLowEnd
= 0.91f
; //If the attacker is a melee class then instead the lower value of 0.91
1521 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1522 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1523 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1525 // apply max/min bounds
1526 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1528 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1531 if ( highEnd
< 0.2f
) //high end limits
1533 if ( highEnd
> 0.99f
)
1536 if(lowEnd
> highEnd
) // prevent negative range size
1539 reducePercent
= lowEnd
+ rand_norm_f() * ( highEnd
- lowEnd
);
1541 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1542 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1545 case MELEE_HIT_CRUSHING
:
1547 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1548 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1549 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1550 // 150% normal damage
1551 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1559 // only from players
1560 if (GetTypeId() == TYPEID_PLAYER
)
1562 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1563 uint32 resilienceReduction
;
1564 if (attackType
!= RANGED_ATTACK
)
1565 resilienceReduction
= pVictim
->GetMeleeDamageReduction(redunction_affected_damage
);
1567 resilienceReduction
= pVictim
->GetRangedDamageReduction(redunction_affected_damage
);
1568 damageInfo
->damage
-= resilienceReduction
;
1569 damageInfo
->cleanDamage
+= resilienceReduction
;
1572 // Calculate absorb resist
1573 if(int32(damageInfo
->damage
) > 0)
1575 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1577 // Calculate absorb & resists
1578 uint32 absorb_affected_damage
= CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1579 damageInfo
->target
->CalculateAbsorbAndResist(this, damageInfo
->damageSchoolMask
, DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, true);
1580 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1581 if (damageInfo
->absorb
)
1583 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1584 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1586 if (damageInfo
->resist
)
1587 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1590 else // Umpossible get negative result but....
1591 damageInfo
->damage
= 0;
1594 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1596 if (damageInfo
==0) return;
1597 Unit
*pVictim
= damageInfo
->target
;
1599 if(!this || !pVictim
)
1602 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1605 //You don't lose health from damage taken from another player while in a sanctuary
1606 //You still see it in the combat log though
1607 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1609 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1610 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1614 // Hmmmm dont like this emotes client must by self do all animations
1615 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1616 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1617 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1618 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1620 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1622 // Get attack timers
1623 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1624 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1625 // Reduce attack time
1626 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1628 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20f
;
1629 float percent60
= 3.0f
* percent20
;
1630 if(offtime
> percent20
&& offtime
<= percent60
)
1632 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1634 else if(offtime
> percent60
)
1636 offtime
-= 2.0f
* percent20
;
1637 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1642 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20f
;
1643 float percent60
= 3.0f
* percent20
;
1644 if(basetime
> percent20
&& basetime
<= percent60
)
1646 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1648 else if(basetime
> percent60
)
1650 basetime
-= 2.0f
* percent20
;
1651 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1656 // Call default DealDamage
1657 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1658 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, damageInfo
->damageSchoolMask
, NULL
, durabilityLoss
);
1660 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1661 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1662 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI_F
, this) )
1664 // -probability is between 0% and 40%
1666 float Probability
= 20.0f
;
1668 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1669 if( pVictim
->getLevel() < 30 )
1670 Probability
= 0.65f
*pVictim
->getLevel()+0.5f
;
1672 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1673 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1675 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1677 if(Probability
> 40.0f
)
1678 Probability
= 40.0f
;
1680 if(roll_chance_f(Probability
))
1681 CastSpell(pVictim
, 1604, true);
1685 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1687 // on weapon hit casts
1688 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1689 ((Player
*)this)->CastItemCombatSpell(pVictim
, damageInfo
->attackType
);
1691 // victim's damage shield
1692 std::set
<Aura
*> alreadyDone
;
1693 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1694 for(AuraList::const_iterator i
= vDamageShields
.begin(); i
!= vDamageShields
.end();)
1696 if (alreadyDone
.find(*i
) == alreadyDone
.end())
1698 alreadyDone
.insert(*i
);
1699 uint32 damage
=(*i
)->GetModifier()->m_amount
;
1700 SpellEntry
const *i_spellProto
= (*i
)->GetSpellProto();
1701 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
1704 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1705 //damage-=absorb + resist;
1707 pVictim
->DealDamageMods(this,damage
,NULL
);
1709 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4+4+4));
1710 data
<< uint64(pVictim
->GetGUID());
1711 data
<< uint64(GetGUID());
1712 data
<< uint32(i_spellProto
->Id
);
1713 data
<< uint32(damage
); // Damage
1714 data
<< uint32(0); // Overkill
1715 data
<< uint32(i_spellProto
->SchoolMask
);
1716 pVictim
->SendMessageToSet(&data
, true );
1718 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(i_spellProto
), i_spellProto
, true);
1720 i
= vDamageShields
.begin();
1729 void Unit::HandleEmoteCommand(uint32 anim_id
)
1731 WorldPacket
data( SMSG_EMOTE
, 4 + 8 );
1732 data
<< uint32(anim_id
);
1733 data
<< uint64(GetGUID());
1734 SendMessageToSet(&data
, true);
1737 void Unit::HandleEmoteState(uint32 anim_id
)
1739 SetUInt32Value(UNIT_NPC_EMOTESTATE
, anim_id
);
1742 void Unit::HandleEmote(uint32 anim_id
)
1745 HandleEmoteState(0);
1746 else if (EmotesEntry
const* emoteEntry
= sEmotesStore
.LookupEntry(anim_id
))
1748 if (emoteEntry
->EmoteType
) // 1,2 states, 0 command
1749 HandleEmoteState(anim_id
);
1751 HandleEmoteCommand(anim_id
);
1755 uint32
Unit::CalcNotIgnoreAbsorbDamage( uint32 damage
, SpellSchoolMask damageSchoolMask
, SpellEntry
const* spellInfo
/*= NULL*/)
1757 float absorb_affected_rate
= 1.0f
;
1758 Unit::AuraList
const& ignoreAbsorbSchool
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_SCHOOL
);
1759 for(Unit::AuraList::const_iterator i
= ignoreAbsorbSchool
.begin(); i
!= ignoreAbsorbSchool
.end(); ++i
)
1760 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1761 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1765 Unit::AuraList
const& ignoreAbsorbForSpell
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL
);
1766 for(Unit::AuraList::const_iterator citr
= ignoreAbsorbForSpell
.begin(); citr
!= ignoreAbsorbForSpell
.end(); ++citr
)
1767 if ((*citr
)->isAffectedOnSpell(spellInfo
))
1768 absorb_affected_rate
*= (100.0f
- (*citr
)->GetModifier()->m_amount
)/100.0f
;
1771 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1774 uint32
Unit::CalcNotIgnoreDamageRedunction( uint32 damage
, SpellSchoolMask damageSchoolMask
)
1776 float absorb_affected_rate
= 1.0f
;
1777 Unit::AuraList
const& ignoreAbsorb
= GetAurasByType(SPELL_AURA_MOD_IGNORE_DAMAGE_REDUCTION_SCHOOL
);
1778 for(Unit::AuraList::const_iterator i
= ignoreAbsorb
.begin(); i
!= ignoreAbsorb
.end(); ++i
)
1779 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1780 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1782 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1785 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
1787 uint32 newdamage
= 0;
1788 float armor
= (float)pVictim
->GetArmor();
1790 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
1791 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
1793 // Apply Player CR_ARMOR_PENETRATION rating and percent talents
1794 if (GetTypeId()==TYPEID_PLAYER
)
1795 armor
*= 1.0f
- ((Player
*)this)->GetArmorPenetrationPct() / 100.0f
;
1800 float levelModifier
= (float)getLevel();
1801 if (levelModifier
> 59)
1802 levelModifier
= levelModifier
+ (4.5f
* (levelModifier
-59));
1804 float tmpvalue
= 0.1f
* armor
/ (8.5f
* levelModifier
+ 40);
1805 tmpvalue
= tmpvalue
/(1.0f
+ tmpvalue
);
1807 if (tmpvalue
< 0.0f
)
1809 if (tmpvalue
> 0.75f
)
1812 newdamage
= uint32(damage
- (damage
* tmpvalue
));
1814 return (newdamage
> 1) ? newdamage
: 1;
1817 void Unit::CalculateAbsorbAndResist(Unit
*pCaster
, SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
, bool canReflect
)
1819 if(!pCaster
|| !isAlive() || !damage
)
1822 // Magic damage, check for resists
1823 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
1825 // Get base victim resistance for school
1826 float tmpvalue2
= (float)GetResistance(GetFirstSchoolInMask(schoolMask
));
1827 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
1828 tmpvalue2
+= (float)pCaster
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
1830 tmpvalue2
*= (float)(0.15f
/ getLevel());
1831 if (tmpvalue2
< 0.0f
)
1833 if (tmpvalue2
> 0.75f
)
1835 uint32 ran
= urand(0, 100);
1836 float faq
[4] = {24.0f
,6.0f
,4.0f
,6.0f
};
1839 for (uint8 i
= 0; i
< 4; ++i
)
1841 Binom
+= 2400 *( powf(tmpvalue2
, float(i
)) * powf( (1-tmpvalue2
), float(4-i
)))/faq
[i
];
1847 if (damagetype
== DOT
&& m
== 4)
1848 *resist
+= uint32(damage
- 1);
1850 *resist
+= uint32(damage
* m
/ 4);
1851 if(*resist
> damage
)
1857 int32 RemainingDamage
= damage
- *resist
;
1859 // Get unit state (need for some absorb check)
1860 uint32 unitflag
= GetUInt32Value(UNIT_FIELD_FLAGS
);
1861 // Reflect damage spells (not cast any damage spell in aura lookup)
1862 uint32 reflectSpell
= 0;
1863 int32 reflectDamage
= 0;
1864 Aura
* reflectTriggeredBy
= NULL
; // expected as not expired at reflect as in current cases
1865 // Death Prevention Aura
1866 SpellEntry
const* preventDeathSpell
= NULL
;
1867 int32 preventDeathAmount
= 0;
1869 // full absorb cases (by chance)
1870 AuraList
const& vAbsorb
= GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1871 for(AuraList::const_iterator i
= vAbsorb
.begin(); i
!= vAbsorb
.end() && RemainingDamage
> 0; ++i
)
1873 // only work with proper school mask damage
1874 Modifier
* i_mod
= (*i
)->GetModifier();
1875 if (!(i_mod
->m_miscvalue
& schoolMask
))
1878 SpellEntry
const* i_spellProto
= (*i
)->GetSpellProto();
1879 // Fire Ward or Frost Ward
1880 if(i_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& i_spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000108))
1883 Unit::AuraList
const& auras
= GetAurasByType(SPELL_AURA_ADD_PCT_MODIFIER
);
1884 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
1886 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
1887 // Frost Warding (chance full absorb)
1888 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& itr_spellProto
->SpellIconID
== 501)
1890 // chance stored in next dummy effect
1891 chance
= itr_spellProto
->CalculateSimpleValue(EFFECT_INDEX_1
);
1895 if(roll_chance_i(chance
))
1897 int32 amount
= RemainingDamage
;
1898 RemainingDamage
= 0;
1900 // Frost Warding (mana regen)
1901 CastCustomSpell(this, 57776, &amount
, NULL
, NULL
, true, NULL
, *i
);
1907 // Need remove expired auras after
1908 bool existExpired
= false;
1910 // Incanter's Absorption, for converting to spell power
1911 int32 incanterAbsorption
= 0;
1913 // absorb without mana cost
1914 AuraList
const& vSchoolAbsorb
= GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1915 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; ++i
)
1917 Modifier
* mod
= (*i
)->GetModifier();
1918 if (!(mod
->m_miscvalue
& schoolMask
))
1921 SpellEntry
const* spellProto
= (*i
)->GetSpellProto();
1923 // Max Amount can be absorbed by this aura
1924 int32 currentAbsorb
= mod
->m_amount
;
1926 // Found empty aura (impossible but..)
1927 if (currentAbsorb
<=0)
1929 existExpired
= true;
1932 // Handle custom absorb auras
1933 // TODO: try find better way
1934 switch(spellProto
->SpellFamilyName
)
1936 case SPELLFAMILY_GENERIC
:
1939 if (spellProto
->SpellIconID
== 3066)
1941 //reduces all damage taken while stun, fear or silence
1942 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1943 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1947 if (spellProto
->SpellIconID
== 2115)
1949 // while affected by Stun and Fear
1950 if (unitflag
&(UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
))
1951 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1955 if (spellProto
->SpellIconID
== 3006)
1957 // You have a chance equal to your Parry chance
1958 if (damagetype
== DIRECT_DAMAGE
&& // Only for direct damage
1959 roll_chance_f(GetUnitParryChance())) // Roll chance
1960 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1963 // Reflective Shield (Lady Malande boss)
1964 if (spellProto
->Id
== 41475 && canReflect
)
1966 if(RemainingDamage
< currentAbsorb
)
1967 reflectDamage
= RemainingDamage
/ 2;
1969 reflectDamage
= currentAbsorb
/ 2;
1970 reflectSpell
= 33619;
1971 reflectTriggeredBy
= *i
;
1974 if (spellProto
->Id
== 39228 || // Argussian Compass
1975 spellProto
->Id
== 60218) // Essence of Gossamer
1977 // Max absorb stored in 1 dummy effect
1978 int32 max_absorb
= spellProto
->CalculateSimpleValue(EFFECT_INDEX_1
);
1979 if (max_absorb
< currentAbsorb
)
1980 currentAbsorb
= max_absorb
;
1985 case SPELLFAMILY_DRUID
:
1988 if (spellProto
->SpellIconID
== 2253)
1990 //reduces all damage taken while Stunned and in Cat Form
1991 if (m_form
== FORM_CAT
&& (unitflag
& UNIT_FLAG_STUNNED
))
1992 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1997 case SPELLFAMILY_ROGUE
:
1999 // Cheat Death (make less prio with Guardian Spirit case)
2000 if (!preventDeathSpell
&& spellProto
->SpellIconID
== 2109 &&
2001 GetTypeId()==TYPEID_PLAYER
&& // Only players
2002 !((Player
*)this)->HasSpellCooldown(31231) &&
2003 // Only if no cooldown
2004 roll_chance_i((*i
)->GetModifier()->m_amount
))
2007 preventDeathSpell
= (*i
)->GetSpellProto();
2012 case SPELLFAMILY_PRIEST
:
2015 if (spellProto
->SpellIconID
== 2873)
2017 preventDeathSpell
= (*i
)->GetSpellProto();
2018 preventDeathAmount
= (*i
)->GetModifier()->m_amount
;
2021 // Reflective Shield
2022 if (spellProto
->SpellFamilyFlags
== 0x1 && canReflect
)
2024 if (pCaster
== this)
2026 Unit
* caster
= (*i
)->GetCaster();
2029 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
2030 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
2032 switch((*k
)->GetModifier()->m_miscvalue
)
2034 case 5065: // Rank 1
2035 case 5064: // Rank 2
2037 if(RemainingDamage
>= currentAbsorb
)
2038 reflectDamage
= (*k
)->GetModifier()->m_amount
* currentAbsorb
/100;
2040 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
2041 reflectSpell
= 33619;
2042 reflectTriggeredBy
= *i
;
2051 case SPELLFAMILY_SHAMAN
:
2054 if (spellProto
->SpellIconID
== 3066)
2056 //reduces all damage taken while stun, fear or silence
2057 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
2058 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2063 case SPELLFAMILY_DEATHKNIGHT
:
2066 if (spellProto
->SpellIconID
== 1958)
2068 // TODO: absorb only while transform
2071 // Anti-Magic Shell (on self)
2072 if (spellProto
->Id
== 48707)
2074 // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power.
2075 // This, if I'm not mistaken, shows that we get back ~2% of the absorbed damage as runic power.
2076 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
2077 int32 regen
= absorbed
* 2 / 10;
2078 CastCustomSpell(this, 49088, ®en
, NULL
, NULL
, true, NULL
, *i
);
2079 RemainingDamage
-= absorbed
;
2082 // Anti-Magic Shell (on single party/raid member)
2083 if (spellProto
->Id
== 50462)
2085 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
2089 if (spellProto
->Id
== 50461)
2091 Unit
* caster
= (*i
)->GetCaster();
2094 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
2095 int32 canabsorb
= caster
->GetHealth();
2096 if (canabsorb
< absorbed
)
2097 absorbed
= canabsorb
;
2099 RemainingDamage
-= absorbed
;
2101 uint32 ab_damage
= absorbed
;
2102 pCaster
->DealDamageMods(caster
,ab_damage
,NULL
);
2103 pCaster
->DealDamage(caster
, ab_damage
, NULL
, damagetype
, schoolMask
, 0, false);
2112 // currentAbsorb - damage can be absorbed by shield
2113 // If need absorb less damage
2114 if (RemainingDamage
< currentAbsorb
)
2115 currentAbsorb
= RemainingDamage
;
2117 RemainingDamage
-= currentAbsorb
;
2119 // Fire Ward or Frost Ward or Ice Barrier (or Mana Shield)
2120 // for Incanter's Absorption converting to spell power
2121 if (spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& spellProto
->SpellFamilyFlags2
& 0x000008)
2122 incanterAbsorption
+= currentAbsorb
;
2124 // Reduce shield amount
2125 mod
->m_amount
-=currentAbsorb
;
2126 if((*i
)->DropAuraCharge())
2128 // Need remove it later
2129 if (mod
->m_amount
<=0)
2130 existExpired
= true;
2133 // Remove all expired absorb auras
2136 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end();)
2138 if ((*i
)->GetModifier()->m_amount
<=0)
2140 RemoveAurasDueToSpell((*i
)->GetId());
2141 i
= vSchoolAbsorb
.begin();
2148 // Cast back reflect damage spell
2149 if (canReflect
&& reflectSpell
)
2150 CastCustomSpell(pCaster
, reflectSpell
, &reflectDamage
, NULL
, NULL
, true, NULL
, reflectTriggeredBy
);
2152 // absorb by mana cost
2153 AuraList
const& vManaShield
= GetAurasByType(SPELL_AURA_MANA_SHIELD
);
2154 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
2158 // check damage school mask
2159 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2162 int32 currentAbsorb
;
2163 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2164 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2166 currentAbsorb
= RemainingDamage
;
2168 if (float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()])
2170 if(Player
*modOwner
= GetSpellModOwner())
2171 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
2173 int32 maxAbsorb
= int32(GetPower(POWER_MANA
) / manaMultiplier
);
2174 if (currentAbsorb
> maxAbsorb
)
2175 currentAbsorb
= maxAbsorb
;
2177 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
2178 ApplyPowerMod(POWER_MANA
, manaReduction
, false);
2181 // Mana Shield (or Fire Ward or Frost Ward or Ice Barrier)
2182 // for Incanter's Absorption converting to spell power
2183 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_MAGE
&& (*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x000008)
2184 incanterAbsorption
+= currentAbsorb
;
2186 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
2187 if((*i
)->GetModifier()->m_amount
<= 0)
2189 RemoveAurasDueToSpell((*i
)->GetId());
2190 next
= vManaShield
.begin();
2193 RemainingDamage
-= currentAbsorb
;
2196 // effects dependent from full absorb amount
2197 // Incanter's Absorption, if have affective absorbing
2198 if (incanterAbsorption
)
2200 Unit::AuraList
const& auras
= GetAurasByType(SPELL_AURA_DUMMY
);
2201 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
2203 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
2205 // Incanter's Absorption
2206 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_GENERIC
&&
2207 itr_spellProto
->SpellIconID
== 2941)
2210 int32 amount
= int32(incanterAbsorption
* (*itr
)->GetModifier()->m_amount
/ 100);
2212 // apply normalized part of already accumulated amount in aura
2213 if (Aura
* spdAura
= GetAura(44413, EFFECT_INDEX_0
))
2214 amount
+= spdAura
->GetModifier()->m_amount
* spdAura
->GetAuraDuration() / spdAura
->GetAuraMaxDuration();
2216 // Incanter's Absorption (triggered absorb based spell power, will replace existed if any)
2217 CastCustomSpell(this, 44413, &amount
, NULL
, NULL
, true);
2223 // only split damage if not damaging yourself
2226 AuraList
const& vSplitDamageFlat
= GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
2227 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
2231 // check damage school mask
2232 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2235 // Damage can be splitted only if aura has an alive caster
2236 Unit
*caster
= (*i
)->GetCaster();
2237 if(!caster
|| caster
== this || !caster
->IsInWorld() || !caster
->isAlive())
2240 int32 currentAbsorb
;
2241 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2242 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2244 currentAbsorb
= RemainingDamage
;
2246 RemainingDamage
-= currentAbsorb
;
2249 uint32 splitted
= currentAbsorb
;
2250 uint32 splitted_absorb
= 0;
2251 pCaster
->DealDamageMods(caster
,splitted
,&splitted_absorb
);
2253 pCaster
->SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, splitted_absorb
, 0, false, 0, false);
2255 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2256 pCaster
->DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2259 AuraList
const& vSplitDamagePct
= GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
2260 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
2264 // check damage school mask
2265 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2268 // Damage can be splitted only if aura has an alive caster
2269 Unit
*caster
= (*i
)->GetCaster();
2270 if(!caster
|| caster
== this || !caster
->IsInWorld() || !caster
->isAlive())
2273 uint32 splitted
= uint32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
2275 RemainingDamage
-= int32(splitted
);
2277 uint32 split_absorb
= 0;
2278 pCaster
->DealDamageMods(caster
,splitted
,&split_absorb
);
2280 pCaster
->SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, split_absorb
, 0, false, 0, false);
2282 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2283 pCaster
->DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2287 // Apply death prevention spells effects
2288 if (preventDeathSpell
&& RemainingDamage
>= (int32
)GetHealth())
2290 switch(preventDeathSpell
->SpellFamilyName
)
2293 case SPELLFAMILY_ROGUE
:
2296 if (preventDeathSpell
->SpellIconID
== 2109)
2298 CastSpell(this,31231,true);
2299 ((Player
*)this)->AddSpellCooldown(31231,0,time(NULL
)+60);
2300 // with health > 10% lost health until health==10%, in other case no losses
2301 uint32 health10
= GetMaxHealth()/10;
2302 RemainingDamage
= GetHealth() > health10
? GetHealth() - health10
: 0;
2307 case SPELLFAMILY_PRIEST
:
2310 if (preventDeathSpell
->SpellIconID
== 2873)
2312 int32 healAmount
= GetMaxHealth() * preventDeathAmount
/ 100;
2313 CastCustomSpell(this, 48153, &healAmount
, NULL
, NULL
, true);
2314 RemoveAurasDueToSpell(preventDeathSpell
->Id
);
2315 RemainingDamage
= 0;
2322 *absorb
= damage
- RemainingDamage
- *resist
;
2325 void Unit::CalculateAbsorbResistBlock(Unit
*pCaster
, SpellNonMeleeDamage
*damageInfo
, SpellEntry
const* spellProto
, WeaponAttackType attType
)
2327 bool blocked
= false;
2328 // Get blocked status
2329 switch (spellProto
->DmgClass
)
2331 // Melee and Ranged Spells
2332 case SPELL_DAMAGE_CLASS_RANGED
:
2333 case SPELL_DAMAGE_CLASS_MELEE
:
2334 blocked
= IsSpellBlocked(pCaster
, spellProto
, attType
);
2342 damageInfo
->blocked
= GetShieldBlockValue();
2343 if (damageInfo
->damage
< (int32
)damageInfo
->blocked
)
2344 damageInfo
->blocked
= damageInfo
->damage
;
2345 damageInfo
->damage
-=damageInfo
->blocked
;
2348 uint32 absorb_affected_damage
= pCaster
->CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,GetSpellSchoolMask(spellProto
),spellProto
);
2349 CalculateAbsorbAndResist(pCaster
, GetSpellSchoolMask(spellProto
), SPELL_DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, !(spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
));
2350 damageInfo
->damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
2353 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
2355 if(hasUnitState(UNIT_STAT_CAN_NOT_REACT
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
2358 if (!pVictim
->isAlive())
2361 if(IsNonMeleeSpellCasted(false))
2365 if (attType
== BASE_ATTACK
)
2366 hitInfo
= HITINFO_NORMALSWING2
;
2367 else if (attType
== OFF_ATTACK
)
2368 hitInfo
= HITINFO_LEFTSWING
;
2370 return; // ignore ranged case
2372 uint32 extraAttacks
= m_extraAttacks
;
2374 // melee attack spell casted at main hand attack only
2375 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
2377 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
2379 // not recent extra attack only at any non extra attack (melee spell case)
2380 if(!extra
&& extraAttacks
)
2382 while(m_extraAttacks
)
2384 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2385 if(m_extraAttacks
> 0)
2392 // attack can be redirected to another target
2393 pVictim
= SelectMagnetTarget(pVictim
);
2395 CalcDamageInfo damageInfo
;
2396 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
2397 // Send log damage message to client
2398 DealDamageMods(pVictim
,damageInfo
.damage
,&damageInfo
.absorb
);
2399 SendAttackStateUpdate(&damageInfo
);
2400 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
2401 DealMeleeDamage(&damageInfo
,true);
2403 if (GetTypeId() == TYPEID_PLAYER
)
2404 DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2405 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2407 DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2408 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2410 // if damage pVictim call AI reaction
2411 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
2412 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
2414 // extra attack only at any non extra attack (normal case)
2415 if(!extra
&& extraAttacks
)
2417 while(m_extraAttacks
)
2419 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2420 if(m_extraAttacks
> 0)
2426 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
2428 // This is only wrapper
2430 // Miss chance based on melee
2431 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
2433 // Critical hit chance
2434 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
2436 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
2437 float dodge_chance
= pVictim
->GetUnitDodgeChance();
2438 float block_chance
= pVictim
->GetUnitBlockChance();
2439 float parry_chance
= pVictim
->GetUnitParryChance();
2441 // Useful if want to specify crit & miss chances for melee, else it could be removed
2442 DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance
,crit_chance
,dodge_chance
,parry_chance
,block_chance
);
2444 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100));
2447 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const
2449 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2450 return MELEE_HIT_EVADE
;
2452 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
2453 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
2455 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
2456 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
2458 // bonus from skills is 0.04%
2459 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
2460 int32 sum
= 0, tmp
= 0;
2461 int32 roll
= urand (0, 10000);
2463 DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
2464 DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
2465 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
2469 if (tmp
> 0 && roll
< (sum
+= tmp
))
2471 DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS");
2472 return MELEE_HIT_MISS
;
2475 // always crit against a sitting target (except 0 crit chance)
2476 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
2478 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)");
2479 return MELEE_HIT_CRIT
;
2484 // only players can't dodge if attacker is behind
2485 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI_F
,this))
2487 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
2491 // Reduce dodge chance by attacker expertise rating
2492 if (GetTypeId() == TYPEID_PLAYER
)
2493 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2495 dodge_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2497 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2498 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2501 if ( (tmp
> 0) // check if unit _can_ dodge
2502 && ((tmp
-= skillBonus
) > 0)
2503 && roll
< (sum
+= tmp
))
2505 DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
2506 return MELEE_HIT_DODGE
;
2510 // parry & block chances
2512 // check if attack comes from behind, nobody can parry or block if attacker is behind
2513 if (!pVictim
->HasInArc(M_PI_F
,this))
2515 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind.");
2519 // Reduce parry chance by attacker expertise rating
2520 if (GetTypeId() == TYPEID_PLAYER
)
2521 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2523 parry_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2525 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
2527 int32 tmp2
= int32(parry_chance
);
2528 if ( (tmp2
> 0) // check if unit _can_ parry
2529 && ((tmp2
-= skillBonus
) > 0)
2530 && (roll
< (sum
+= tmp2
)))
2532 DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp2
, sum
);
2533 return MELEE_HIT_PARRY
;
2537 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
2540 if ( (tmp
> 0) // check if unit _can_ block
2541 && ((tmp
-= skillBonus
) > 0)
2542 && (roll
< (sum
+= tmp
)))
2544 DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
2545 return MELEE_HIT_BLOCK
;
2553 if (tmp
> 0 && roll
< (sum
+= tmp
))
2555 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
2556 return MELEE_HIT_CRIT
;
2559 // 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)
2560 if( attType
!= RANGED_ATTACK
&&
2561 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
2562 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
2563 getLevel() < pVictim
->getLevelForTarget(this) )
2565 // cap possible value (with bonuses > max skill)
2566 int32 skill
= attackerWeaponSkill
;
2567 int32 maxskill
= attackerMaxSkillValueForLevel
;
2568 skill
= (skill
> maxskill
) ? maxskill
: skill
;
2570 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
2571 tmp
= tmp
> 4000 ? 4000 : tmp
;
2572 if (roll
< (sum
+= tmp
))
2574 DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
2575 return MELEE_HIT_GLANCING
;
2579 // mobs can score crushing blows if they're 4 or more levels above victim
2580 if (getLevelForTarget(pVictim
) >= pVictim
->getLevelForTarget(this) + 4 &&
2581 // can be from by creature (if can) or from controlled player that considered as creature
2582 (GetTypeId()!=TYPEID_PLAYER
&& !((Creature
*)this)->isPet() &&
2583 !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) ||
2584 GetTypeId()==TYPEID_PLAYER
&& GetCharmerOrOwnerGUID()))
2586 // when their weapon skill is 15 or more above victim's defense skill
2587 tmp
= victimDefenseSkill
;
2588 int32 tmpmax
= victimMaxSkillValueForLevel
;
2589 // having defense above your maximum (from items, talents etc.) has no effect
2590 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
2591 // tmp = mob's level * 5 - player's current defense skill
2592 tmp
= attackerMaxSkillValueForLevel
- tmp
;
2595 // add 2% chance per lacking skill point, min. is 15%
2596 tmp
= tmp
* 200 - 1500;
2597 if (roll
< (sum
+= tmp
))
2599 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
2600 return MELEE_HIT_CRUSHING
;
2605 DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL");
2606 return MELEE_HIT_NORMAL
;
2609 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
2611 float min_damage
, max_damage
;
2613 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
2614 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
2620 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
2621 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
2624 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
2625 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
2628 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
2629 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
2631 // Just for good manner
2639 if (min_damage
> max_damage
)
2641 std::swap(min_damage
,max_damage
);
2644 if(max_damage
== 0.0f
)
2647 return urand((uint32
)min_damage
, (uint32
)max_damage
);
2650 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
2652 if(spellProto
->spellLevel
<= 0)
2655 float LvlPenalty
= 0.0f
;
2657 if(spellProto
->spellLevel
< 20)
2658 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
2659 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
2660 if(LvlFactor
> 1.0f
)
2663 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
2666 void Unit::SendMeleeAttackStart(Unit
* pVictim
)
2668 WorldPacket
data( SMSG_ATTACKSTART
, 8 + 8 );
2669 data
<< uint64(GetGUID());
2670 data
<< uint64(pVictim
->GetGUID());
2672 SendMessageToSet(&data
, true);
2673 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
2676 void Unit::SendMeleeAttackStop(Unit
* victim
)
2681 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
2682 data
<< GetPackGUID();
2683 data
<< victim
->GetPackGUID(); // can be 0x00...
2684 data
<< uint32(0); // can be 0x1
2685 SendMessageToSet(&data
, true);
2686 DETAIL_LOG("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER
? "player" : "creature"), GetGUIDLow(), (victim
->GetTypeId()==TYPEID_PLAYER
? "player" : "creature"),victim
->GetGUIDLow());
2688 /*if(victim->GetTypeId() == TYPEID_UNIT)
2689 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
2692 bool Unit::IsSpellBlocked(Unit
*pCaster
, SpellEntry
const * /*spellProto*/, WeaponAttackType attackType
)
2694 if (HasInArc(M_PI_F
,pCaster
))
2696 /* Currently not exist spells with ignore block
2697 // Ignore combat result aura (parry/dodge check on prepare)
2698 AuraList const& ignore = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2699 for(AuraList::const_iterator i = ignore.begin(); i != ignore.end(); ++i)
2701 if (!(*i)->isAffectedOnSpell(spellProto))
2703 if ((*i)->GetModifier()->m_miscvalue == )
2708 // Check creatures flags_extra for disable block
2709 if(GetTypeId()==TYPEID_UNIT
&&
2710 ((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
)
2713 float blockChance
= GetUnitBlockChance();
2714 blockChance
+= (int32(pCaster
->GetWeaponSkillValue(attackType
)) - int32(GetMaxSkillValueForLevel()))*0.04f
;
2715 if (roll_chance_f(blockChance
))
2721 // Melee based spells can be miss, parry or dodge on this step
2722 // Crit or block - determined on damage calculation phase! (and can be both in some time)
2723 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
2725 // Calculate hit chance (more correct for chance mod)
2728 // PvP - PvE melee chances
2729 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2730 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
2732 HitChance
= 95 - leveldif
;
2734 HitChance
= 93 - (leveldif
- 2) * lchance
;
2736 // Hit chance depends from victim auras
2737 if(attType
== RANGED_ATTACK
)
2738 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2740 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2742 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2743 if(Player
*modOwner
= GetSpellModOwner())
2744 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
2747 float miss_chance
= 100.0f
- HitChance
;
2749 // Bonuses from attacker aura and ratings
2750 if (attType
== RANGED_ATTACK
)
2751 miss_chance
-= m_modRangedHitChance
;
2753 miss_chance
-= m_modMeleeHitChance
;
2755 // bonus from skills is 0.04%
2756 miss_chance
-= skillDiff
* 0.04f
;
2758 // Limit miss chance from 0 to 60%
2759 if (miss_chance
< 0.0f
)
2761 if (miss_chance
> 60.0f
)
2766 // Melee based spells hit result calculations
2767 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2769 WeaponAttackType attType
= BASE_ATTACK
;
2771 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
2772 attType
= RANGED_ATTACK
;
2774 // bonus from skills is 0.04% per skill Diff
2775 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
2776 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
2777 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
2779 uint32 roll
= urand (0, 10000);
2781 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
2783 uint32 tmp
= missChance
;
2785 return SPELL_MISS_MISS
;
2787 // Chance resist mechanic (select max value from every mechanic spell effect)
2788 int32 resist_mech
= 0;
2789 // Get effects mechanic and chance
2790 for(int eff
= 0; eff
< MAX_EFFECT_INDEX
; ++eff
)
2792 int32 effect_mech
= GetEffectMechanic(spell
, SpellEffectIndex(eff
));
2795 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2796 if (resist_mech
< temp
*100)
2797 resist_mech
= temp
*100;
2803 return SPELL_MISS_RESIST
;
2805 bool canDodge
= true;
2806 bool canParry
= true;
2808 // Same spells cannot be parry/dodge
2809 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
2810 return SPELL_MISS_NONE
;
2812 // Ranged attack cannot be parry/dodge only deflect
2813 if (attType
== RANGED_ATTACK
)
2816 if (pVictim
->HasInArc(M_PI_F
,this))
2818 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2819 tmp
+=deflect_chance
;
2821 return SPELL_MISS_DEFLECT
;
2823 return SPELL_MISS_NONE
;
2826 // Check for attack from behind
2827 if (!pVictim
->HasInArc(M_PI_F
,this))
2829 // Can`t dodge from behind in PvP (but its possible in PvE)
2830 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
2835 // Check creatures flags_extra for disable parry
2836 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
2838 uint32 flagEx
= ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
;
2839 if( flagEx
& CREATURE_FLAG_EXTRA_NO_PARRY
)
2842 // Ignore combat result aura
2843 AuraList
const& ignore
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
2844 for(AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
2846 if (!(*i
)->isAffectedOnSpell(spell
))
2848 switch((*i
)->GetModifier()->m_miscvalue
)
2850 case MELEE_HIT_DODGE
: canDodge
= false; break;
2851 case MELEE_HIT_BLOCK
: break; // Block check in hit step
2852 case MELEE_HIT_PARRY
: canParry
= false; break;
2854 DEBUG_LOG("Spell %u SPELL_AURA_IGNORE_COMBAT_RESULT have unhandled state %d", (*i
)->GetId(), (*i
)->GetModifier()->m_miscvalue
);
2862 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
2863 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2864 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
)*100;
2865 // Reduce dodge chance by attacker expertise rating
2866 if (GetTypeId() == TYPEID_PLAYER
)
2867 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2869 dodgeChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2870 if (dodgeChance
< 0)
2875 return SPELL_MISS_DODGE
;
2881 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
2882 // Reduce parry chance by attacker expertise rating
2883 if (GetTypeId() == TYPEID_PLAYER
)
2884 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2886 parryChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2887 if (parryChance
< 0)
2892 return SPELL_MISS_PARRY
;
2895 return SPELL_MISS_NONE
;
2898 // TODO need use unit spell resistances in calculations
2899 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2901 // Can`t miss on dead target (on skinning for example)
2902 if (!pVictim
->isAlive())
2903 return SPELL_MISS_NONE
;
2905 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
2906 // PvP - PvE spell misschances per leveldif > 2
2907 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
2908 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2910 // Base hit chance from attacker and victim levels
2913 modHitChance
= 96 - leveldif
;
2915 modHitChance
= 94 - (leveldif
- 2) * lchance
;
2917 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2918 if(Player
*modOwner
= GetSpellModOwner())
2919 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
2920 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
2921 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
2922 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
2923 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
2924 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
2925 if (IsAreaOfEffectSpell(spell
))
2926 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
2927 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
2928 if (IsDispelSpell(spell
))
2929 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
2930 // Chance resist mechanic (select max value from every mechanic spell effect)
2931 int32 resist_mech
= 0;
2932 // Get effects mechanic and chance
2933 for(int eff
= 0; eff
< MAX_EFFECT_INDEX
; ++eff
)
2935 int32 effect_mech
= GetEffectMechanic(spell
, SpellEffectIndex(eff
));
2938 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2939 if (resist_mech
< temp
)
2944 modHitChance
-=resist_mech
;
2946 // Chance resist debuff
2947 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
2949 int32 HitChance
= modHitChance
* 100;
2950 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
2951 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
2953 // Decrease hit chance from victim rating bonus
2954 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2955 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
2957 if (HitChance
< 100) HitChance
= 100;
2958 if (HitChance
> 10000) HitChance
= 10000;
2960 int32 tmp
= 10000 - HitChance
;
2962 int32 rand
= irand(0,10000);
2965 return SPELL_MISS_MISS
;
2967 // cast by caster in front of victim
2968 if (pVictim
->HasInArc(M_PI_F
,this))
2970 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2971 tmp
+=deflect_chance
;
2973 return SPELL_MISS_DEFLECT
;
2976 return SPELL_MISS_NONE
;
2979 // Calculate spell hit result can be:
2980 // Every spell can: Evade/Immune/Reflect/Sucesful hit
2981 // For melee based spells:
2987 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
2989 // Return evade for units in evade mode
2990 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2991 return SPELL_MISS_EVADE
;
2994 if (pVictim
->IsImmunedToSpell(spell
))
2995 return SPELL_MISS_IMMUNE
;
2997 // All positive spells can`t miss
2998 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
2999 if (IsPositiveSpell(spell
->Id
))
3000 return SPELL_MISS_NONE
;
3003 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
)))
3004 return SPELL_MISS_IMMUNE
;
3006 // Try victim reflect spell
3009 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
3010 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
3011 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
3012 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
3013 reflectchance
+= (*i
)->GetModifier()->m_amount
;
3014 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
3016 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
3017 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
3018 return SPELL_MISS_REFLECT
;
3022 switch (spell
->DmgClass
)
3024 case SPELL_DAMAGE_CLASS_NONE
:
3025 return SPELL_MISS_NONE
;
3026 case SPELL_DAMAGE_CLASS_MAGIC
:
3027 return MagicSpellHitResult(pVictim
, spell
);
3028 case SPELL_DAMAGE_CLASS_MELEE
:
3029 case SPELL_DAMAGE_CLASS_RANGED
:
3030 return MeleeSpellHitResult(pVictim
, spell
);
3032 return SPELL_MISS_NONE
;
3035 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
3040 // Base misschance 5%
3041 float misschance
= 5.0f
;
3043 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
3044 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
3046 bool isNormal
= false;
3047 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
3049 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
3055 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
3061 // PvP : PvE melee misschances per leveldif > 2
3062 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
3064 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
3068 // Hit chance from attacker based on ratings and auras
3069 float m_modHitChance
;
3070 if (attType
== RANGED_ATTACK
)
3071 m_modHitChance
= m_modRangedHitChance
;
3073 m_modHitChance
= m_modMeleeHitChance
;
3076 misschance
+= (leveldif
- m_modHitChance
);
3078 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
3080 // Hit chance for victim based on ratings
3081 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
3083 if (attType
== RANGED_ATTACK
)
3084 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
3086 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
3089 // Modify miss chance by victim auras
3090 if(attType
== RANGED_ATTACK
)
3091 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
3093 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
3095 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
3096 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
3097 misschance
-= skillBonus
* 0.04f
;
3099 // Limit miss chance from 0 to 60%
3100 if ( misschance
< 0.0f
)
3102 if ( misschance
> 60.0f
)
3108 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
3110 if(GetTypeId() == TYPEID_PLAYER
)
3112 // in PvP use full skill instead current skill value
3113 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3114 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
3115 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
3116 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
3120 return GetUnitMeleeSkill(target
);
3123 float Unit::GetUnitDodgeChance() const
3125 if(hasUnitState(UNIT_STAT_STUNNED
))
3127 if( GetTypeId() == TYPEID_PLAYER
)
3128 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
3131 if(((Creature
const*)this)->isTotem())
3136 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
3137 return dodge
> 0.0f
? dodge
: 0.0f
;
3142 float Unit::GetUnitParryChance() const
3144 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3147 float chance
= 0.0f
;
3149 if(GetTypeId() == TYPEID_PLAYER
)
3151 Player
const* player
= (Player
const*)this;
3152 if(player
->CanParry() )
3154 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true,true);
3156 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true,true);
3159 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
3162 else if(GetTypeId() == TYPEID_UNIT
)
3164 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
3167 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
3171 return chance
> 0.0f
? chance
: 0.0f
;
3174 float Unit::GetUnitBlockChance() const
3176 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3179 if(GetTypeId() == TYPEID_PLAYER
)
3181 Player
const* player
= (Player
const*)this;
3182 if(player
->CanBlock() )
3184 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
3185 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
3186 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
3188 // is player but has no block ability or no not broken shield equipped
3193 if(((Creature
const*)this)->isTotem())
3198 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
3199 return block
> 0.0f
? block
: 0.0f
;
3204 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
3208 if(GetTypeId() == TYPEID_PLAYER
)
3213 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
3216 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
3219 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
3221 // Just for good manner
3230 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
3234 if(attackType
== RANGED_ATTACK
)
3235 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
3237 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
3239 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
3241 // reduce crit chance from Rating for players
3242 if (attackType
!= RANGED_ATTACK
)
3243 crit
-= pVictim
->GetMeleeCritChanceReduction();
3245 crit
-= pVictim
->GetRangedCritChanceReduction();
3247 // Apply crit chance from defence skill
3248 crit
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
3255 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
3258 if(GetTypeId() == TYPEID_PLAYER
)
3260 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true,true);
3262 // feral or unarmed skill only for base attack
3263 if(attType
!= BASE_ATTACK
&& !item
)
3267 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
3269 // weapon skill or (unarmed for base attack)
3270 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
3272 // in PvP use full skill instead current skill value
3273 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3274 ? ((Player
*)this)->GetMaxSkillValue(skill
)
3275 : ((Player
*)this)->GetSkillValue(skill
);
3276 // Modify value from ratings
3277 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
3280 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
3281 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
3282 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
3286 value
= GetUnitMeleeSkill(target
);
3290 void Unit::_UpdateSpells( uint32 time
)
3292 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
3293 _UpdateAutoRepeatSpell();
3295 // remove finished spells from current pointers
3296 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3298 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
3300 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
3301 m_currentSpells
[i
] = NULL
; // remove pointer
3306 // m_AurasUpdateIterator can be updated in inderect called code at aura remove to skip next planned to update but removed auras
3307 for (m_AurasUpdateIterator
= m_Auras
.begin(); m_AurasUpdateIterator
!= m_Auras
.end();)
3309 Aura
* i_aura
= m_AurasUpdateIterator
->second
;
3310 ++m_AurasUpdateIterator
; // need shift to next for allow update if need into aura update
3311 i_aura
->UpdateAura(time
);
3314 // remove expired auras
3315 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
3319 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
3328 if(!m_gameObj
.empty())
3330 GameObjectList::iterator ite1
, dnext1
;
3331 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
3334 //(*i)->Update( difftime );
3335 if( !(*ite1
)->isSpawned() )
3337 (*ite1
)->SetOwnerGUID(0);
3338 (*ite1
)->SetRespawnTime(0);
3340 dnext1
= m_gameObj
.erase(ite1
);
3348 void Unit::_UpdateAutoRepeatSpell()
3350 bool isAutoShot
= m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
== SPELL_ID_AUTOSHOT
;
3353 if (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving())
3355 // cancel wand shoot
3357 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3358 // auto shot just waits
3362 // check spell casts
3363 if (IsNonMeleeSpellCasted(false, false, true))
3365 // cancel wand shoot
3368 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3371 // auto shot is delayed by everythihng, except ranged(!) CURRENT_GENERIC_SPELL's -> recheck that
3372 else if (!(m_currentSpells
[CURRENT_GENERIC_SPELL
] && m_currentSpells
[CURRENT_GENERIC_SPELL
]->IsRangedSpell()))
3377 if (isAttackReady(RANGED_ATTACK
))
3379 // Check if able to cast
3380 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CheckCast(true) != SPELL_CAST_OK
)
3382 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3387 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
3388 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
3390 // all went good, reset attack
3391 resetAttackTimer(RANGED_ATTACK
);
3395 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
3397 ASSERT(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
3399 CurrentSpellTypes CSpellType
= pSpell
->GetCurrentContainer();
3401 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
3403 // break same type spell if it is not delayed
3404 InterruptSpell(CSpellType
,false);
3406 // special breakage effects:
3409 case CURRENT_GENERIC_SPELL
:
3411 // generic spells always break channeled not delayed spells
3412 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3414 // autorepeat breaking
3415 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3417 // break autorepeat if not Auto Shot
3418 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3419 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3423 case CURRENT_CHANNELED_SPELL
:
3425 // channel spells always break generic non-delayed and any channeled spells
3426 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3427 InterruptSpell(CURRENT_CHANNELED_SPELL
);
3429 // it also does break autorepeat if not Auto Shot
3430 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
3431 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3432 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3435 case CURRENT_AUTOREPEAT_SPELL
:
3437 // only Auto Shoot does not break anything
3438 if (pSpell
->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3440 // generic autorepeats break generic non-delayed and channeled non-delayed spells
3441 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3442 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3443 // special action: first cast delay
3444 if ( getAttackTimer(RANGED_ATTACK
) < 500 )
3445 setAttackTimer(RANGED_ATTACK
,500);
3451 // other spell types don't break anything now
3455 // current spell (if it is still here) may be safely deleted now
3456 if (m_currentSpells
[CSpellType
])
3457 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
3459 // set new current spell
3460 m_currentSpells
[CSpellType
] = pSpell
;
3461 pSpell
->SetReferencedFromCurrent(true);
3463 pSpell
->m_selfContainer
= &(m_currentSpells
[pSpell
->GetCurrentContainer()]);
3466 void Unit::InterruptSpell(CurrentSpellTypes spellType
, bool withDelayed
, bool sendAutoRepeatCancelToClient
)
3468 ASSERT(spellType
< CURRENT_MAX_SPELL
);
3470 if (m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
3472 // send autorepeat cancel message for autorepeat spells
3473 if (spellType
== CURRENT_AUTOREPEAT_SPELL
&& sendAutoRepeatCancelToClient
)
3475 if(GetTypeId() == TYPEID_PLAYER
)
3476 ((Player
*)this)->SendAutoRepeatCancel(this);
3479 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
3480 m_currentSpells
[spellType
]->cancel();
3482 // cancel can interrupt spell already (caster cancel ->target aura remove -> caster iterrupt)
3483 if (m_currentSpells
[spellType
])
3485 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
3486 m_currentSpells
[spellType
] = NULL
;
3491 void Unit::FinishSpell(CurrentSpellTypes spellType
, bool ok
/*= true*/)
3493 Spell
* spell
= m_currentSpells
[spellType
];
3497 if (spellType
== CURRENT_CHANNELED_SPELL
)
3498 spell
->SendChannelUpdate(0);
3504 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
3506 // We don't do loop here to explicitly show that melee spell is excluded.
3507 // Maybe later some special spells will be excluded too.
3509 // generic spells are casted when they are not finished and not delayed
3510 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
3511 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3512 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3515 // channeled spells may be delayed, but they are still considered casted
3516 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
3517 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
3520 // autorepeat spells may be finished or delayed, but they are still considered casted
3521 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3527 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
3529 // generic spells are interrupted if they are not finished or delayed
3530 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
3531 InterruptSpell(CURRENT_GENERIC_SPELL
,withDelayed
);
3533 // autorepeat spells are interrupted if they are not finished or delayed
3534 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
3535 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
,withDelayed
);
3537 // channeled spells are interrupted if they are not finished, even if they are delayed
3538 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
3539 InterruptSpell(CURRENT_CHANNELED_SPELL
,true);
3542 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
3544 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3545 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
3546 return m_currentSpells
[i
];
3550 void Unit::SetInFront(Unit
const* target
)
3552 SetOrientation(GetAngle(target
));
3555 void Unit::SetFacingTo(float ori
)
3557 // update orientation at server
3558 SetOrientation(ori
);
3562 BuildHeartBeatMsg(&data
);
3563 SendMessageToSet(&data
, false);
3566 // Consider move this to Creature:: since only creature appear to be able to use this
3567 void Unit::SetFacingToObject(WorldObject
* pObject
)
3569 if (GetTypeId() != TYPEID_UNIT
)
3572 // never face when already moving
3576 // TODO: figure out under what conditions creature will move towards object instead of facing it where it currently is.
3578 SetOrientation(GetAngle(pObject
));
3579 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_FACINGTARGET
, ((Creature
*)this)->GetSplineFlags(), 0, NULL
, pObject
->GetGUID());
3582 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
3585 return c
->canSwim();
3587 return c
->canWalk() || c
->canFly();
3590 bool Unit::IsInWater() const
3592 return GetBaseMap()->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
3595 bool Unit::IsUnderWater() const
3597 return GetBaseMap()->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3600 void Unit::DeMorph()
3602 SetDisplayId(GetNativeDisplayId());
3605 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3609 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3610 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3611 modifier
+= (*i
)->GetModifier()->m_amount
;
3616 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3618 float multiplier
= 1.0f
;
3620 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3621 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3622 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3627 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3631 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3632 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3633 if ((*i
)->GetModifier()->m_amount
> modifier
)
3634 modifier
= (*i
)->GetModifier()->m_amount
;
3639 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
3643 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3644 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3645 if ((*i
)->GetModifier()->m_amount
< modifier
)
3646 modifier
= (*i
)->GetModifier()->m_amount
;
3651 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3658 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3659 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3661 Modifier
* mod
= (*i
)->GetModifier();
3662 if (mod
->m_miscvalue
& misc_mask
)
3663 modifier
+= mod
->m_amount
;
3668 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3673 float multiplier
= 1.0f
;
3675 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3676 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3678 Modifier
* mod
= (*i
)->GetModifier();
3679 if (mod
->m_miscvalue
& misc_mask
)
3680 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3685 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3692 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3693 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3695 Modifier
* mod
= (*i
)->GetModifier();
3696 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
> modifier
)
3697 modifier
= mod
->m_amount
;
3703 int32
Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3710 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3711 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3713 Modifier
* mod
= (*i
)->GetModifier();
3714 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
< modifier
)
3715 modifier
= mod
->m_amount
;
3721 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3725 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3726 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3728 Modifier
* mod
= (*i
)->GetModifier();
3729 if (mod
->m_miscvalue
== misc_value
)
3730 modifier
+= mod
->m_amount
;
3735 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
3737 float multiplier
= 1.0f
;
3739 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3740 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3742 Modifier
* mod
= (*i
)->GetModifier();
3743 if (mod
->m_miscvalue
== misc_value
)
3744 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3749 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3753 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3754 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3756 Modifier
* mod
= (*i
)->GetModifier();
3757 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
3758 modifier
= mod
->m_amount
;
3764 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3768 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3769 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3771 Modifier
* mod
= (*i
)->GetModifier();
3772 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
< modifier
)
3773 modifier
= mod
->m_amount
;
3779 float Unit::GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype
, uint32 mask
) const
3784 float multiplier
= 1.0f
;
3786 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3787 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3789 Modifier
* mod
= (*i
)->GetModifier();
3790 if (mask
& (1 << (mod
->m_miscvalue
-1)))
3791 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3796 bool Unit::AddAura(Aura
*Aur
)
3798 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
3800 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
3801 if( !isAlive() && !IsDeathPersistentSpell(aurSpellInfo
) &&
3802 !IsDeathOnlySpell(aurSpellInfo
) &&
3803 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
3809 if(Aur
->GetTarget() != this)
3811 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
3812 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
3813 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
3818 // m_auraname can be modified to SPELL_AURA_NONE for area auras, this expected for this value
3819 AuraType aurName
= Aur
->GetModifier()->m_auraname
;
3821 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
3822 AuraMap::iterator i
= m_Auras
.find( spair
);
3824 // take out same spell
3825 if (i
!= m_Auras
.end())
3827 // passive and persistent auras can stack with themselves any number of times
3828 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
3830 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
3832 Aura
* aur2
= i2
->second
;
3833 if(aur2
->GetCasterGUID()==Aur
->GetCasterGUID())
3835 // Aura can stack on self -> Stack it;
3836 if(aurSpellInfo
->StackAmount
)
3838 // can be created with >1 stack by some spell mods
3839 aur2
->modStackAmount(Aur
->GetStackAmount());
3844 // Check for coexisting Weapon-proced Auras
3845 if (Aur
->isWeaponBuffCoexistableWith(aur2
))
3848 // Carry over removed Aura's remaining damage if Aura still has ticks remaining
3849 if (aur2
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_STACK_DOT_MODIFIER
&& aurName
== SPELL_AURA_PERIODIC_DAMAGE
&& aur2
->GetAuraDuration() > 0)
3851 int32 remainingTicks
= aur2
->GetAuraMaxTicks() - aur2
->GetAuraTicks();
3852 int32 remainingDamage
= aur2
->GetModifier()->m_amount
* remainingTicks
;
3854 Aur
->GetModifier()->m_amount
+= int32(remainingDamage
/ Aur
->GetAuraMaxTicks());
3856 // can be only single (this check done at _each_ aura add
3857 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3863 // m_auraname can be modified to SPELL_AURA_NONE for area auras, use original
3864 AuraType aurNameReal
= AuraType(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()]);
3869 case SPELL_AURA_DUMMY
: // allow stack
3870 case SPELL_AURA_PERIODIC_DAMAGE
:
3871 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
3872 case SPELL_AURA_PERIODIC_LEECH
:
3873 case SPELL_AURA_PERIODIC_HEAL
:
3874 case SPELL_AURA_OBS_MOD_HEALTH
:
3875 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3876 case SPELL_AURA_OBS_MOD_MANA
:
3877 case SPELL_AURA_POWER_BURN_MANA
:
3879 case SPELL_AURA_PERIODIC_ENERGIZE
: // all or self or clear non-stackable
3880 default: // not allow
3881 // can be only single (this check done at _each_ aura add
3882 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3893 // passive auras not stacable with other ranks
3894 if (!IsPassiveSpellStackableWithRanks(aurSpellInfo
))
3896 if (!RemoveNoStackAurasDueToAura(Aur
))
3899 return false; // couldn't remove conflicting aura with higher rank
3903 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
3904 if (Aur
->IsSingleTarget() && Aur
->GetTarget())
3906 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
3909 Unit
* caster
= Aur
->GetCaster();
3910 if(!caster
) // caster deleted and not required adding scAura
3913 bool restart
= false;
3914 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3915 for(AuraList::const_iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
3917 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
3918 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
3920 if ((*itr
)->IsInUse())
3922 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());
3925 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
3934 scAuras
.push_back(Aur
);
3940 // add aura, register in lists and arrays
3942 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
3943 if (aurName
< TOTAL_AURAS
)
3945 m_modAuras
[aurName
].push_back(Aur
);
3948 Aur
->ApplyModifier(true,true);
3949 DEBUG_LOG("Aura %u now is in use", aurName
);
3951 // if aura deleted before boosts apply ignore
3952 // this can be possible it it removed indirectly by triggered spell effect at ApplyModifier
3953 if (Aur
->IsDeleted())
3956 if(IsSpellLastAuraEffect(aurSpellInfo
,Aur
->GetEffIndex()))
3957 Aur
->HandleSpellSpecificBoosts(true);
3962 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
3964 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3967 AuraMap::const_iterator i
,next
;
3968 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3972 uint32 i_spellId
= (*i
).second
->GetId();
3973 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
3975 if(sSpellMgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
3977 RemoveAurasDueToSpell(i_spellId
);
3979 if( m_Auras
.empty() )
3982 next
= m_Auras
.begin();
3988 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
3993 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
3997 uint32 spellId
= Aur
->GetId();
3998 SpellEffectIndex effIndex
= Aur
->GetEffIndex();
4000 // passive spell special case (only non stackable with ranks)
4001 if(IsPassiveSpell(spellId
))
4003 if(IsPassiveSpellStackableWithRanks(spellProto
))
4007 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
4009 AuraMap::iterator i
,next
;
4010 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
4014 if (!(*i
).second
) continue;
4016 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
4021 uint32 i_spellId
= i_spellProto
->Id
;
4023 // early checks that spellId is passive non stackable spell
4024 if(IsPassiveSpell(i_spellId
))
4026 // passive non-stackable spells not stackable only for same caster
4027 if(Aur
->GetCasterGUID()!=i
->second
->GetCasterGUID())
4030 // passive non-stackable spells not stackable only with another rank of same spell
4031 if (!sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4035 SpellEffectIndex i_effIndex
= (*i
).second
->GetEffIndex();
4037 if(i_spellId
== spellId
) continue;
4039 bool is_triggered_by_spell
= false;
4040 // prevent triggering aura of removing aura that triggered it
4041 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4042 if (i_spellProto
->EffectTriggerSpell
[j
] == spellId
)
4043 is_triggered_by_spell
= true;
4045 // prevent triggered aura of removing aura that triggering it (triggered effect early some aura of parent spell
4046 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4047 if (spellProto
->EffectTriggerSpell
[j
] == i_spellId
)
4048 is_triggered_by_spell
= true;
4050 if (is_triggered_by_spell
)
4053 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
4055 // single allowed spell specific from same caster or from any caster at target
4056 bool is_spellSpecPerTargetPerCaster
= IsSingleFromSpellSpecificPerTargetPerCaster(spellId_spec
,i_spellId_spec
);
4057 bool is_spellSpecPerTarget
= IsSingleFromSpellSpecificPerTarget(spellId_spec
,i_spellId_spec
);
4058 if( is_spellSpecPerTarget
|| is_spellSpecPerTargetPerCaster
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
4060 // cannot remove higher rank
4061 if (sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4062 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4065 // Its a parent aura (create this aura in ApplyModifier)
4066 if ((*i
).second
->IsInUse())
4068 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());
4071 RemoveAurasDueToSpell(i_spellId
);
4073 if( m_Auras
.empty() )
4076 next
= m_Auras
.begin();
4081 // spell with spell specific that allow single ranks for spell from diff caster
4082 // same caster case processed or early or later
4083 bool is_spellPerTarget
= IsSingleFromSpellSpecificSpellRanksPerTarget(spellId_spec
,i_spellId_spec
);
4084 if ( is_spellPerTarget
&& Aur
->GetCasterGUID() != (*i
).second
->GetCasterGUID() && sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4086 // cannot remove higher rank
4087 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4090 // Its a parent aura (create this aura in ApplyModifier)
4091 if ((*i
).second
->IsInUse())
4093 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());
4096 RemoveAurasDueToSpell(i_spellId
);
4098 if( m_Auras
.empty() )
4101 next
= m_Auras
.begin();
4106 // non single (per caster) per target spell specific (possible single spell per target at caster)
4107 if( !is_spellSpecPerTargetPerCaster
&& !is_spellSpecPerTarget
&& sSpellMgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
4109 // Its a parent aura (create this aura in ApplyModifier)
4110 if ((*i
).second
->IsInUse())
4112 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());
4115 RemoveAurasDueToSpell(i_spellId
);
4117 if( m_Auras
.empty() )
4120 next
= m_Auras
.begin();
4125 // Potions stack aura by aura (elixirs/flask already checked)
4126 if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
4128 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
4130 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4131 return false; // cannot remove higher rank
4133 // Its a parent aura (create this aura in ApplyModifier)
4134 if ((*i
).second
->IsInUse())
4136 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());
4147 void Unit::RemoveAura(uint32 spellId
, SpellEffectIndex effindex
, Aura
* except
)
4149 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4150 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4152 if(iter
->second
!=except
)
4155 iter
= m_Auras
.lower_bound(spair
);
4162 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
)
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
)
4174 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, SpellEffectIndex effindex
, uint64 casterGUID
)
4176 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4177 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4179 Aura
*aur
= iter
->second
;
4180 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4183 iter
= m_Auras
.lower_bound(spair
);
4190 void Unit::RemoveSingleAuraDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
4192 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(spellId
);
4194 // Custom dispel cases
4195 // Unstable Affliction
4196 if(spellEntry
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x010000000000)))
4198 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
,SPELLFAMILY_WARLOCK
,UI64LIT(0x010000000000),0x00000000,casterGUID
))
4200 // use clean value for initial damage
4201 int32 damage
= dotAura
->GetSpellProto()->CalculateSimpleValue(EFFECT_INDEX_0
);
4204 // Remove spell auras from stack
4205 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4207 // backfire damage and silence
4208 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,casterGUID
);
4213 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x10000000)))
4215 Unit
* caster
= NULL
;
4216 uint32 triggeredSpell
= 0;
4218 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x10000000), 0x00000000, casterGUID
))
4219 caster
= dotAura
->GetCaster();
4221 if (caster
&& !caster
->isDead())
4223 Unit::AuraList
const& auras
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
4224 for (Unit::AuraList::const_iterator i
= auras
.begin(); i
!= auras
.end(); ++i
)
4226 switch((*i
)->GetId())
4228 case 51480: triggeredSpell
=64694; break;// Lava Flows, Rank 1
4229 case 51481: triggeredSpell
=65263; break;// Lava Flows, Rank 2
4230 case 51482: triggeredSpell
=65264; break;// Lava Flows, Rank 3
4237 // Remove spell auras from stack
4238 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4242 caster
->CastSpell(caster
, triggeredSpell
, true);
4245 // Vampiric touch (first dummy aura)
4246 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_PRIEST
&& spellEntry
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
4248 if (Aura
*dot
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000040000000000), 0x00000000, casterGUID
))
4250 if(Unit
* caster
= dot
->GetCaster())
4252 // use clean value for initial damage
4253 int32 bp0
= dot
->GetSpellProto()->CalculateSimpleValue(EFFECT_INDEX_1
);
4256 // Remove spell auras from stack
4257 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4259 CastCustomSpell(this, 64085, &bp0
, NULL
, NULL
, true, NULL
, NULL
, casterGUID
);
4265 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4268 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
4270 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4272 Aura
*aur
= iter
->second
;
4273 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4275 int32 basePoints
= aur
->GetBasePoints();
4276 // construct the new aura for the attacker - will never return NULL, it's just a wrapper for
4277 // some different constructors
4278 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
, this);
4280 // set its duration and maximum duration
4281 // max duration 2 minutes (in msecs)
4282 int32 dur
= aur
->GetAuraDuration();
4283 int32 max_dur
= 2*MINUTE
*IN_MILLISECONDS
;
4284 int32 new_max_dur
= max_dur
> dur
? dur
: max_dur
;
4285 new_aur
->SetAuraMaxDuration( new_max_dur
);
4286 new_aur
->SetAuraDuration( new_max_dur
);
4288 // set periodic to do at least one tick (for case when original aura has been at last tick preparing)
4289 int32 periodic
= aur
->GetModifier()->periodictime
;
4290 new_aur
->GetModifier()->periodictime
= periodic
< new_max_dur
? periodic
: new_max_dur
;
4292 // Unregister _before_ adding to stealer
4293 aur
->UnregisterSingleCastAura();
4295 // strange but intended behaviour: Stolen single target auras won't be treated as single targeted
4296 new_aur
->SetIsSingleTarget(false);
4298 // add the new aura to stealer
4299 stealer
->AddAura(new_aur
);
4301 // Remove aura as dispel
4302 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
4309 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
4311 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4313 if (iter
->second
->GetId() == spellId
)
4314 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
4320 void Unit::RemoveAurasWithDispelType( DispelType type
)
4322 // Create dispel mask by dispel type
4323 uint32 dispelMask
= GetDispellMask(type
);
4324 // Dispel all existing auras vs current dispel type
4325 AuraMap
& auras
= GetAuras();
4326 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
4328 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
4329 if( (1<<spell
->Dispel
) & dispelMask
)
4332 RemoveAurasDueToSpell(spell
->Id
);
4333 itr
= auras
.begin();
4340 void Unit::RemoveSingleAuraFromStack(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4342 if (i
->second
->modStackAmount(-1))
4347 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, SpellEffectIndex effindex
, AuraRemoveMode mode
)
4349 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4350 if(iter
!= m_Auras
.end())
4351 RemoveSingleAuraFromStack(iter
,mode
);
4354 void Unit::RemoveSingleSpellAurasFromStack(uint32 spellId
, AuraRemoveMode mode
)
4356 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4357 RemoveSingleAuraFromStack(spellId
, SpellEffectIndex(i
), mode
);
4360 void Unit::RemoveSingleSpellAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
, AuraRemoveMode mode
)
4362 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4363 RemoveSingleAuraByCasterSpell(spellId
, SpellEffectIndex(i
), casterGUID
, mode
);
4366 void Unit::RemoveSingleAuraByCasterSpell(uint32 spellId
, SpellEffectIndex effindex
, uint64 casterGUID
, AuraRemoveMode mode
)
4368 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4369 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
); ++iter
)
4371 Aura
*aur
= iter
->second
;
4372 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4374 RemoveSingleAuraFromStack(iter
,mode
);
4381 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
)
4383 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4384 RemoveAura(spellId
,SpellEffectIndex(i
),except
);
4387 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
4389 for (int k
=0; k
< MAX_EFFECT_INDEX
; ++k
)
4391 spellEffectPair spair
= spellEffectPair(spellId
, SpellEffectIndex(k
));
4392 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4394 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
4397 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
4405 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
4407 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4409 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
4416 void Unit::RemoveNotOwnSingleTargetAuras(uint32 newPhase
)
4418 // single target auras from other casters
4419 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4421 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
4427 Unit
* caster
= iter
->second
->GetCaster();
4428 if(!caster
|| !caster
->InSamePhase(newPhase
))
4438 // single target auras at other targets
4439 AuraList
& scAuras
= GetSingleCastAuras();
4440 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
4443 if (aura
->GetTarget() != this && !aura
->GetTarget()->InSamePhase(newPhase
))
4445 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
4446 aura
->GetTarget()->RemoveAura(aura
);
4447 iter
= scAuras
.begin();
4455 void Unit::RemoveAura(Aura
* aura
, AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4457 AuraMap::iterator i
= m_Auras
.lower_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4458 AuraMap::iterator upperBound
= m_Auras
.upper_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4459 for (; i
!= upperBound
; ++i
)
4461 if (i
->second
== aura
)
4467 DEBUG_LOG("Trying to remove aura id %u effect %u by pointer but aura not found on target", aura
->GetId(), aura
->GetEffIndex());
4470 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4472 Aura
* Aur
= i
->second
;
4473 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
4475 Aur
->UnregisterSingleCastAura();
4477 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
4478 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
4480 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
4484 Aur
->SetRemoveMode(mode
);
4486 // if unit currently update aura list then make safe update iterator shift to next
4487 if (m_AurasUpdateIterator
== i
)
4488 ++m_AurasUpdateIterator
;
4490 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
4491 // remove aura from list before to prevent deleting it before
4494 // now aura removed from from list and can't be deleted by indirect call but can be referenced from callers
4496 // Statue unsummoned at aura remove
4497 Totem
* statue
= NULL
;
4498 if(IsChanneledSpell(AurSpellInfo
))
4499 if(Unit
* caster
= Aur
->GetCaster())
4500 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
4501 statue
= ((Totem
*)caster
);
4503 DEBUG_LOG("Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
4505 // some auras also need to apply modifier (on caster) on remove
4506 if (mode
!= AURA_REMOVE_BY_DELETE
|| Aur
->GetModifier()->m_auraname
== SPELL_AURA_MOD_POSSESS
)
4507 Aur
->ApplyModifier(false,true);
4509 if (Aur
->_RemoveAura())
4511 // last aura in stack removed
4512 if (mode
!= AURA_REMOVE_BY_DELETE
&& IsSpellLastAuraEffect(Aur
->GetSpellProto(),Aur
->GetEffIndex()))
4513 Aur
->HandleSpellSpecificBoosts(false);
4516 // If aura in use (removed from code that plan access to it data after return)
4517 // store it in aura list with delayed deletion
4519 m_deletedAuras
.push_back(Aur
);
4526 // only way correctly remove all auras from list
4527 if( m_Auras
.empty() )
4530 i
= m_Auras
.begin();
4534 void Unit::RemoveAllAuras(AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4536 while (!m_Auras
.empty())
4538 AuraMap::iterator iter
= m_Auras
.begin();
4539 RemoveAura(iter
,mode
);
4543 void Unit::RemoveArenaAuras(bool onleave
)
4545 // in join, remove positive buffs, on end, remove negative
4546 // used to remove positive visible auras in arenas
4547 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4549 if (!(iter
->second
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_UNK21
) &&
4550 // don't remove stances, shadowform, pally/hunter auras
4551 !iter
->second
->IsPassive() && // don't remove passive auras
4552 (!(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
) ||
4553 !(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNK8
)) &&
4554 // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable)
4555 (iter
->second
->IsPositive() != onleave
)) // remove positive buffs on enter, negative buffs on leave
4562 void Unit::RemoveAllAurasOnDeath()
4564 // used just after dieing to remove all visible auras
4565 // and disable the mods for the passive ones
4566 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4568 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
4569 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
4575 void Unit::DelayAura(uint32 spellId
, SpellEffectIndex effindex
, int32 delaytime
)
4577 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4578 if (iter
!= m_Auras
.end())
4580 if (iter
->second
->GetAuraDuration() < delaytime
)
4581 iter
->second
->SetAuraDuration(0);
4583 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
4584 iter
->second
->SendAuraUpdate(false);
4585 DEBUG_LOG("Aura %u partially interrupted on unit %u, new duration: %u ms",iter
->second
->GetModifier()->m_auraname
, GetGUIDLow(), iter
->second
->GetAuraDuration());
4589 void Unit::_RemoveAllAuraMods()
4591 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4593 (*i
).second
->ApplyModifier(false);
4597 void Unit::_ApplyAllAuraMods()
4599 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4601 (*i
).second
->ApplyModifier(true);
4605 Aura
* Unit::GetAura(uint32 spellId
, SpellEffectIndex effindex
)
4607 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4608 if (iter
!= m_Auras
.end())
4609 return iter
->second
;
4613 Aura
* Unit::GetAura(AuraType type
, uint32 family
, uint64 familyFlag
, uint32 familyFlag2
, uint64 casterGUID
)
4615 AuraList
const& auras
= GetAurasByType(type
);
4616 for(AuraList::const_iterator i
= auras
.begin();i
!= auras
.end(); ++i
)
4618 SpellEntry
const *spell
= (*i
)->GetSpellProto();
4619 if (spell
->SpellFamilyName
== family
&& (spell
->SpellFamilyFlags
& familyFlag
|| spell
->SpellFamilyFlags2
& familyFlag2
))
4621 if (casterGUID
&& (*i
)->GetCasterGUID()!=casterGUID
)
4629 bool Unit::HasAura(uint32 spellId
) const
4631 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4633 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, SpellEffectIndex(i
)));
4634 if (iter
!= m_Auras
.end())
4640 void Unit::AddDynObject(DynamicObject
* dynObj
)
4642 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
4645 void Unit::RemoveDynObject(uint32 spellid
)
4647 if(m_dynObjGUIDs
.empty())
4649 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4651 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4654 i
= m_dynObjGUIDs
.erase(i
);
4656 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
4659 i
= m_dynObjGUIDs
.erase(i
);
4666 void Unit::RemoveAllDynObjects()
4668 while(!m_dynObjGUIDs
.empty())
4670 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*m_dynObjGUIDs
.begin());
4673 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
4677 DynamicObject
* Unit::GetDynObject(uint32 spellId
, SpellEffectIndex effIndex
)
4679 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4681 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4684 i
= m_dynObjGUIDs
.erase(i
);
4688 if (dynObj
->GetSpellId() == spellId
&& dynObj
->GetEffIndex() == effIndex
)
4695 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
4697 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4699 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4702 i
= m_dynObjGUIDs
.erase(i
);
4706 if (dynObj
->GetSpellId() == spellId
)
4713 GameObject
* Unit::GetGameObject(uint32 spellId
) const
4715 for (GameObjectList::const_iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); ++i
)
4716 if ((*i
)->GetSpellId() == spellId
)
4722 void Unit::AddGameObject(GameObject
* gameObj
)
4724 ASSERT(gameObj
&& gameObj
->GetOwnerGUID()==0);
4725 m_gameObj
.push_back(gameObj
);
4726 gameObj
->SetOwnerGUID(GetGUID());
4728 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
4730 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
4731 // Need disable spell use for owner
4732 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4733 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4734 ((Player
*)this)->AddSpellAndCategoryCooldowns(createBySpell
,0,NULL
,true);
4738 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
4740 ASSERT(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
4742 gameObj
->SetOwnerGUID(0);
4744 // GO created by some spell
4745 if (uint32 spellid
= gameObj
->GetSpellId())
4747 RemoveAurasDueToSpell(spellid
);
4749 if (GetTypeId()==TYPEID_PLAYER
)
4751 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(spellid
);
4752 // Need activate spell use for owner
4753 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4754 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4755 ((Player
*)this)->SendCooldownEvent(createBySpell
);
4759 m_gameObj
.remove(gameObj
);
4763 gameObj
->SetRespawnTime(0);
4768 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
4770 if(m_gameObj
.empty())
4772 GameObjectList::iterator i
, next
;
4773 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
4776 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
4778 (*i
)->SetOwnerGUID(0);
4781 (*i
)->SetRespawnTime(0);
4785 next
= m_gameObj
.erase(i
);
4792 void Unit::RemoveAllGameObjects()
4794 // remove references to unit
4795 for(GameObjectList::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4797 (*i
)->SetOwnerGUID(0);
4798 (*i
)->SetRespawnTime(0);
4800 i
= m_gameObj
.erase(i
);
4804 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
4806 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+4+1+4+4+1+1+4+4+1)); // we guess size
4807 data
<< log
->target
->GetPackGUID();
4808 data
<< log
->attacker
->GetPackGUID();
4809 data
<< uint32(log
->SpellID
);
4810 data
<< uint32(log
->damage
); // damage amount
4811 data
<< uint32(log
->overkill
); // overkill
4812 data
<< uint8 (log
->schoolMask
); // damage school
4813 data
<< uint32(log
->absorb
); // AbsorbedDamage
4814 data
<< uint32(log
->resist
); // resist
4815 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
4816 data
<< uint8 (log
->unused
); // unused
4817 data
<< uint32(log
->blocked
); // blocked
4818 data
<< uint32(log
->HitInfo
);
4819 data
<< uint8 (0); // flag to use extend data
4820 SendMessageToSet( &data
, true );
4823 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
, uint32 SpellID
, uint32 Damage
, SpellSchoolMask damageSchoolMask
, uint32 AbsorbedDamage
, uint32 Resist
, bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
4825 SpellNonMeleeDamage
log(this, target
, SpellID
, damageSchoolMask
);
4826 log
.damage
= Damage
- AbsorbedDamage
- Resist
- Blocked
;
4827 log
.absorb
= AbsorbedDamage
;
4828 log
.resist
= Resist
;
4829 log
.physicalLog
= PhysicalDamage
;
4830 log
.blocked
= Blocked
;
4831 log
.HitInfo
= SPELL_HIT_TYPE_UNK1
| SPELL_HIT_TYPE_UNK3
| SPELL_HIT_TYPE_UNK6
;
4833 log
.HitInfo
|= SPELL_HIT_TYPE_CRIT
;
4834 SendSpellNonMeleeDamageLog(&log
);
4837 void Unit::SendPeriodicAuraLog(SpellPeriodicAuraLogInfo
*pInfo
)
4839 Aura
*aura
= pInfo
->aura
;
4840 Modifier
*mod
= aura
->GetModifier();
4842 WorldPacket
data(SMSG_PERIODICAURALOG
, 30);
4843 data
<< aura
->GetTarget()->GetPackGUID();
4844 data
.appendPackGUID(aura
->GetCasterGUID());
4845 data
<< uint32(aura
->GetId()); // spellId
4846 data
<< uint32(1); // count
4847 data
<< uint32(mod
->m_auraname
); // auraId
4848 switch(mod
->m_auraname
)
4850 case SPELL_AURA_PERIODIC_DAMAGE
:
4851 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
4852 data
<< uint32(pInfo
->damage
); // damage
4853 data
<< uint32(pInfo
->overDamage
); // overkill?
4854 data
<< uint32(GetSpellSchoolMask(aura
->GetSpellProto()));
4855 data
<< uint32(pInfo
->absorb
); // absorb
4856 data
<< uint32(pInfo
->resist
); // resist
4857 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4859 case SPELL_AURA_PERIODIC_HEAL
:
4860 case SPELL_AURA_OBS_MOD_HEALTH
:
4861 data
<< uint32(pInfo
->damage
); // damage
4862 data
<< uint32(pInfo
->overDamage
); // overheal?
4863 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4865 case SPELL_AURA_OBS_MOD_MANA
:
4866 case SPELL_AURA_PERIODIC_ENERGIZE
:
4867 data
<< uint32(mod
->m_miscvalue
); // power type
4868 data
<< uint32(pInfo
->damage
); // damage
4870 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4871 data
<< uint32(mod
->m_miscvalue
); // power type
4872 data
<< uint32(pInfo
->damage
); // amount
4873 data
<< float(pInfo
->multiplier
); // gain multiplier
4876 sLog
.outError("Unit::SendPeriodicAuraLog: unknown aura %u", uint32(mod
->m_auraname
));
4880 aura
->GetTarget()->SendMessageToSet(&data
, true);
4883 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
4885 // Not much to do if no flags are set.
4887 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
4888 // Now go on with a victim's events'n'auras
4889 // Not much to do if no flags are set or there is no victim
4890 if(pVictim
&& pVictim
->isAlive() && procVictim
)
4891 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4894 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4896 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4897 data
<< uint32(spellID
);
4898 data
<< uint64(GetGUID());
4899 data
<< uint8(0); // can be 0 or 1
4900 data
<< uint32(1); // target count
4901 // for(i = 0; i < target count; ++i)
4902 data
<< uint64(target
->GetGUID()); // target GUID
4903 data
<< uint8(missInfo
);
4905 SendMessageToSet(&data
, true);
4908 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4910 DEBUG_LOG("WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4913 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, 16 + 45); // we guess size
4914 data
<< uint32(damageInfo
->HitInfo
);
4915 data
<< damageInfo
->attacker
->GetPackGUID();
4916 data
<< damageInfo
->target
->GetPackGUID();
4917 data
<< uint32(damageInfo
->damage
); // Full damage
4918 data
<< uint32(0); // overkill value
4919 data
<< uint8(count
); // Sub damage count
4921 for(uint32 i
= 0; i
< count
; ++i
)
4923 data
<< uint32(damageInfo
->damageSchoolMask
); // School of sub damage
4924 data
<< float(damageInfo
->damage
); // sub damage
4925 data
<< uint32(damageInfo
->damage
); // Sub Damage
4928 if(damageInfo
->HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4930 for(uint32 i
= 0; i
< count
; ++i
)
4931 data
<< uint32(damageInfo
->absorb
); // Absorb
4934 if(damageInfo
->HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4936 for(uint32 i
= 0; i
< count
; ++i
)
4937 data
<< uint32(damageInfo
->resist
); // Resist
4940 data
<< uint8(damageInfo
->TargetState
);
4944 if(damageInfo
->HitInfo
& HITINFO_BLOCK
)
4945 data
<< uint32(damageInfo
->blocked_amount
);
4947 if(damageInfo
->HitInfo
& HITINFO_UNK3
)
4950 if(damageInfo
->HitInfo
& HITINFO_UNK1
)
4961 for(uint8 i
= 0; i
< 5; ++i
)
4969 SendMessageToSet( &data
, true );
4972 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8
/*SwingType*/, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4974 CalcDamageInfo dmgInfo
;
4975 dmgInfo
.HitInfo
= HitInfo
;
4976 dmgInfo
.attacker
= this;
4977 dmgInfo
.target
= target
;
4978 dmgInfo
.damage
= Damage
- AbsorbDamage
- Resist
- BlockedAmount
;
4979 dmgInfo
.damageSchoolMask
= damageSchoolMask
;
4980 dmgInfo
.absorb
= AbsorbDamage
;
4981 dmgInfo
.resist
= Resist
;
4982 dmgInfo
.TargetState
= TargetState
;
4983 dmgInfo
.blocked_amount
= BlockedAmount
;
4984 SendAttackStateUpdate(&dmgInfo
);
4987 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4989 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
4991 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4992 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4994 uint32 triggered_spell_id
= 0;
4995 Unit
* target
= pVictim
;
4996 int32 basepoints0
= 0;
4998 switch(hasteSpell
->SpellFamilyName
)
5000 case SPELLFAMILY_ROGUE
:
5002 switch(hasteSpell
->Id
)
5008 target
= SelectRandomUnfriendlyTarget(pVictim
);
5011 basepoints0
= damage
;
5012 triggered_spell_id
= 22482;
5020 // processed charge only counting case
5021 if(!triggered_spell_id
)
5024 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5028 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
5033 if(!target
|| target
!=this && !target
->isAlive())
5036 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5040 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5042 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5044 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5045 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5050 bool Unit::HandleSpellCritChanceAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
5052 SpellEntry
const *triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
5054 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5055 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5057 uint32 triggered_spell_id
= 0;
5058 Unit
* target
= pVictim
;
5059 int32 basepoints0
= 0;
5061 switch(triggeredByAuraSpell
->SpellFamilyName
)
5063 case SPELLFAMILY_MAGE
:
5065 switch(triggeredByAuraSpell
->Id
)
5070 Unit
* caster
= triggeredByAura
->GetCaster();
5074 triggered_spell_id
= 54648;
5082 // processed charge only counting case
5083 if(!triggered_spell_id
)
5086 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5090 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",triggeredByAuraSpell
->Id
,triggered_spell_id
);
5095 if(!target
|| target
!=this && !target
->isAlive())
5098 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5102 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5104 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5106 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5107 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5112 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
5114 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
5115 SpellEffectIndex effIndex
= triggeredByAura
->GetEffIndex();
5116 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
5118 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5119 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5121 uint32 triggered_spell_id
= 0;
5122 Unit
* target
= pVictim
;
5123 int32 basepoints
[MAX_EFFECT_INDEX
] = {0, 0, 0};
5125 switch(dummySpell
->SpellFamilyName
)
5127 case SPELLFAMILY_GENERIC
:
5129 switch (dummySpell
->Id
)
5135 // return damage % to attacker but < 50% own total health
5136 basepoints
[0] = triggerAmount
*int32(damage
)/100;
5137 if (basepoints
[0] > (int32
)GetMaxHealth()/2)
5138 basepoints
[0] = (int32
)GetMaxHealth()/2;
5140 triggered_spell_id
= 25997;
5143 // Sweeping Strikes (NPC spells may be)
5147 // prevent chain of triggered spell from same triggered spell
5148 if (procSpell
&& procSpell
->Id
== 26654)
5151 target
= SelectRandomUnfriendlyTarget(pVictim
);
5155 triggered_spell_id
= 26654;
5158 // Twisted Reflection (boss spell)
5160 triggered_spell_id
= 21064;
5165 if (!procSpell
|| procSpell
->Id
== 24659)
5167 // Need remove one 24659 aura
5168 RemoveSingleSpellAurasFromStack(24659);
5171 // Restless Strength
5174 // Need remove one 24662 aura
5175 RemoveSingleSpellAurasFromStack(24662);
5178 // Adaptive Warding (Frostfire Regalia set)
5186 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
5187 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
5189 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
5191 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& UI64LIT(0x10000000)))
5201 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5203 case SPELL_SCHOOL_NORMAL
:
5204 case SPELL_SCHOOL_HOLY
:
5205 return false; // ignored
5206 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
5207 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
5208 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
5209 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
5210 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
5218 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
5224 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5226 case SPELL_SCHOOL_NORMAL
:
5227 return false; // ignore
5228 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
5229 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
5230 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
5231 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
5232 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
5233 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
5241 // Mana Leech (Passive) (Priest Pet Aura)
5245 target
= GetOwner();
5249 triggered_spell_id
= 34650;
5257 if (!roll_chance_i(triggerAmount
))
5260 // Remove any stun effect on target
5261 AuraMap
& Auras
= pVictim
->GetAuras();
5262 for(AuraMap::const_iterator iter
= Auras
.begin(); iter
!= Auras
.end();)
5264 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
5265 if( spell
->Mechanic
== MECHANIC_STUN
||
5266 spell
->EffectMechanic
[iter
->second
->GetEffIndex()] == MECHANIC_STUN
)
5268 pVictim
->RemoveAurasDueToSpell(spell
->Id
);
5269 iter
= Auras
.begin();
5279 // Cast finish spell at last charge
5280 if (triggeredByAura
->GetAuraCharges() > 1)
5284 triggered_spell_id
= 33494;
5287 // Vampiric Aura (boss spell)
5290 basepoints
[0] = 3 * damage
; // 300%
5291 if (basepoints
[0] < 0)
5294 triggered_spell_id
= 31285;
5298 // Aura of Madness (Darkmoon Card: Madness trinket)
5299 //=====================================================
5300 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
5301 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
5302 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
5303 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5304 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
5305 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
5306 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
5307 // 41011 Martyr Complex: +35 stamina (All classes)
5308 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5309 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5312 if(GetTypeId() != TYPEID_PLAYER
)
5315 // Select class defined buff
5318 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5319 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5321 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
5322 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5325 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
5326 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
5328 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
5329 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5332 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
5333 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
5334 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
5335 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
5337 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
5338 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5341 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
5343 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
5344 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5352 if (roll_chance_i(10))
5353 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
5356 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
5357 // cast 45479 Light's Wrath if Exalted by Aldor
5358 // cast 45429 Arcane Bolt if Exalted by Scryers
5361 if(GetTypeId() != TYPEID_PLAYER
)
5364 // Get Aldor reputation rank
5365 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5368 triggered_spell_id
= 45479;
5371 // Get Scryers reputation rank
5372 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5374 // triggered at positive/self casts also, current attack target used then
5375 if(IsFriendlyTo(target
))
5377 target
= getVictim();
5380 uint64 selected_guid
= ((Player
*)this)->GetSelection();
5381 target
= ObjectAccessor::GetUnit(*this,selected_guid
);
5385 if(IsFriendlyTo(target
))
5389 triggered_spell_id
= 45429;
5394 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
5395 // cast 45480 Light's Strength if Exalted by Aldor
5396 // cast 45428 Arcane Strike if Exalted by Scryers
5399 if(GetTypeId() != TYPEID_PLAYER
)
5402 // Get Aldor reputation rank
5403 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5406 triggered_spell_id
= 45480;
5409 // Get Scryers reputation rank
5410 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5412 triggered_spell_id
= 45428;
5417 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
5418 // cast 45431 Arcane Insight if Exalted by Aldor
5419 // cast 45432 Light's Ward if Exalted by Scryers
5422 if(GetTypeId() != TYPEID_PLAYER
)
5425 // Get Aldor reputation rank
5426 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5429 triggered_spell_id
= 45432;
5432 // Get Scryers reputation rank
5433 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5436 triggered_spell_id
= 45431;
5441 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
5442 // cast 45478 Light's Salvation if Exalted by Aldor
5443 // cast 45430 Arcane Surge if Exalted by Scryers
5446 if(GetTypeId() != TYPEID_PLAYER
)
5449 // Get Aldor reputation rank
5450 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5453 triggered_spell_id
= 45478;
5456 // Get Scryers reputation rank
5457 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5459 triggered_spell_id
= 45430;
5465 // Sunwell Exalted Caster Neck (??? neck)
5466 // cast ??? Light's Wrath if Exalted by Aldor
5467 // cast ??? Arcane Bolt if Exalted by Scryers*/
5469 return false; // old unused version
5473 triggered_spell_id
= 48503;
5474 basepoints
[0] = triggerAmount
;
5478 // Vampiric Touch (generic, used by some boss)
5482 triggered_spell_id
= 52724;
5483 basepoints
[0] = damage
/ 2;
5487 // Shadowfiend Death (Gain mana if pet dies with Glyph of Shadowfiend)
5490 Unit
*owner
= GetOwner();
5491 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
5494 // Glyph of Shadowfiend (need cast as self cast for owner, no hidden cooldown)
5495 owner
->CastSpell(owner
,58227,true,castItem
,triggeredByAura
);
5498 // Glyph of Life Tap
5500 triggered_spell_id
= 63321;
5502 // Item - Shadowmourne Legendary
5505 if (!roll_chance_i(triggerAmount
))
5508 Aura
*aur
= GetAura(71905, EFFECT_INDEX_0
);
5509 if (aur
&& uint32(aur
->GetStackAmount() + 1) >= aur
->GetSpellProto()->StackAmount
)
5511 RemoveAurasDueToSpell(71905);
5512 CastSpell(this, 71904, true); // Chaos Bane
5516 triggered_spell_id
= 71905;
5523 case SPELLFAMILY_MAGE
:
5526 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
5528 if (getPowerType() != POWER_MANA
)
5532 basepoints
[0] = (triggerAmount
* GetMaxPower(POWER_MANA
) / 100);
5534 triggered_spell_id
= 29442;
5537 // Master of Elements
5538 if (dummySpell
->SpellIconID
== 1920)
5544 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5545 basepoints
[0] = cost
* triggerAmount
/100;
5546 if (basepoints
[0] <=0)
5550 triggered_spell_id
= 29077;
5555 if (dummySpell
->SpellIconID
== 2120)
5561 switch (dummySpell
->Id
)
5563 case 31571: triggered_spell_id
= 57529; break;
5564 case 31572: triggered_spell_id
= 57531; break;
5566 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u",dummySpell
->Id
);
5573 if (dummySpell
->SpellIconID
== 2999)
5575 if (effIndex
!= EFFECT_INDEX_0
)
5577 Aura
*counter
= GetAura(triggeredByAura
->GetId(), EFFECT_INDEX_1
);
5581 // Count spell criticals in a row in second aura
5582 Modifier
*mod
= counter
->GetModifier();
5583 if (procEx
& PROC_EX_CRITICAL_HIT
)
5586 if (mod
->m_amount
< 100) // not enough
5588 // Crititcal counted -> roll chance
5589 if (roll_chance_i(triggerAmount
))
5590 CastSpell(this, 48108, true, castItem
, triggeredByAura
);
5596 if (dummySpell
->SpellIconID
== 2998)
5601 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5602 basepoints
[0] = cost
* triggerAmount
/100;
5603 if (basepoints
[0] <=0)
5605 triggered_spell_id
= 44450;
5609 // Incanter's Regalia set (add trigger chance to Mana Shield)
5610 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5612 if (GetTypeId() != TYPEID_PLAYER
)
5616 triggered_spell_id
= 37436;
5619 switch(dummySpell
->Id
)
5628 switch (dummySpell
->Id
)
5630 case 11119: basepoints
[0] = int32(0.04f
*damage
); break;
5631 case 11120: basepoints
[0] = int32(0.08f
*damage
); break;
5632 case 12846: basepoints
[0] = int32(0.12f
*damage
); break;
5633 case 12847: basepoints
[0] = int32(0.16f
*damage
); break;
5634 case 12848: basepoints
[0] = int32(0.20f
*damage
); break;
5636 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
5640 triggered_spell_id
= 12654;
5646 //last charge and crit
5647 if (triggeredByAura
->GetAuraCharges() <= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
5648 return true; // charge counting (will removed)
5650 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
5651 return (procEx
& PROC_EX_CRITICAL_HIT
); // charge update only at crit hits, no hidden cooldowns
5653 // Glyph of Ice Block
5656 if (GetTypeId() != TYPEID_PLAYER
)
5659 // not 100% safe with client version switches but for 3.1.3 no spells with cooldown that can have mage player except Frost Nova.
5660 ((Player
*)this)->RemoveSpellCategoryCooldown(35, true);
5663 // Glyph of Polymorph
5666 if (!pVictim
|| !pVictim
->isAlive())
5669 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE
);
5670 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE_PERCENT
);
5673 // Blessing of Ancient Kings
5677 if (!IsPositiveSpell(procSpell
->Id
))
5680 triggered_spell_id
= 64413;
5681 basepoints
[0] = damage
* 15 / 100;
5687 case SPELLFAMILY_WARRIOR
:
5690 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0000000800000000))
5692 // check attack comes not from behind
5693 if (!HasInArc(M_PI_F
, pVictim
))
5696 triggered_spell_id
= 22858;
5700 if (dummySpell
->SpellIconID
== 1697)
5702 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
5703 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
5705 // Need stun or root mechanic
5706 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_STUN_MASK
))
5709 switch (dummySpell
->Id
)
5711 case 29838: triggered_spell_id
=29842; break;
5712 case 29834: triggered_spell_id
=29841; break;
5713 case 42770: triggered_spell_id
=42771; break;
5715 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
5723 if (dummySpell
->SpellIconID
== 3214)
5725 triggered_spell_id
= 59653;
5726 basepoints
[0] = GetShieldBlockValue() * triggerAmount
/ 100;
5731 if (dummySpell
->Id
== 12328)
5733 // prevent chain of triggered spell from same triggered spell
5734 if(procSpell
&& procSpell
->Id
== 26654)
5737 target
= SelectRandomUnfriendlyTarget(pVictim
);
5741 triggered_spell_id
= 26654;
5746 case SPELLFAMILY_WARLOCK
:
5748 // Seed of Corruption
5749 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
5751 Modifier
* mod
= triggeredByAura
->GetModifier();
5752 // if damage is more than need or target die from damage deal finish spell
5753 if( mod
->m_amount
<= (int32
)damage
|| GetHealth() <= damage
)
5755 // remember guid before aura delete
5756 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5758 // Remove aura (before cast for prevent infinite loop handlers)
5759 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5761 // Cast finish spell (triggeredByAura already not exist!)
5762 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
5763 return true; // no hidden cooldown
5767 mod
->m_amount
-=damage
;
5770 // Seed of Corruption (Mobs cast) - no die req
5771 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0) && dummySpell
->SpellIconID
== 1932)
5773 Modifier
* mod
= triggeredByAura
->GetModifier();
5774 // if damage is more than need deal finish spell
5775 if( mod
->m_amount
<= (int32
)damage
)
5777 // remember guid before aura delete
5778 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5780 // Remove aura (before cast for prevent infinite loop handlers)
5781 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5783 // Cast finish spell (triggeredByAura already not exist!)
5784 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
5785 return true; // no hidden cooldown
5788 mod
->m_amount
-=damage
;
5792 if (dummySpell
->SpellIconID
== 3222)
5797 basepoints
[0] = damage
* triggerAmount
/ 100;
5798 triggered_spell_id
= 54181;
5801 switch(dummySpell
->Id
)
5803 // Nightfall & Glyph of Corruption
5809 triggered_spell_id
= 17941;
5818 basepoints
[0] = int32(damage
*triggerAmount
/100);
5820 triggered_spell_id
= 30294;
5823 // Shadowflame (Voidheart Raiment set bonus)
5826 triggered_spell_id
= 37379;
5829 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
5837 basepoints
[0] = damage
* triggerAmount
/100;
5838 triggered_spell_id
= 37382;
5841 // Shadowflame Hellfire (Voidheart Raiment set bonus)
5844 triggered_spell_id
= 37378;
5850 if (triggeredByAura
->GetEffIndex() != EFFECT_INDEX_0
)
5853 // Glyph of Siphon Life
5854 if (Aura
*aur
= GetAura(56216, EFFECT_INDEX_0
))
5855 triggerAmount
+= triggerAmount
* aur
->GetModifier()->m_amount
/ 100;
5857 basepoints
[0] = int32(damage
* triggerAmount
/ 100);
5858 triggered_spell_id
= 63106;
5864 case SPELLFAMILY_PRIEST
:
5867 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
5869 if(!pVictim
|| !pVictim
->isAlive())
5872 // pVictim is caster of aura
5873 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5876 // Energize 0.25% of max. mana
5877 pVictim
->CastSpell(pVictim
,57669,true,castItem
,triggeredByAura
);
5878 return true; // no hidden cooldown
5881 switch(dummySpell
->SpellIconID
)
5883 // Improved Shadowform
5886 if(!roll_chance_i(triggerAmount
))
5889 RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT
);
5890 RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED
);
5896 basepoints
[0] = damage
* triggerAmount
/100;
5897 triggered_spell_id
= 47753;
5906 Aura
* healingAura
= pVictim
->GetAura(procSpell
->Id
, EFFECT_INDEX_0
);
5910 int32 healingfromticks
= healingAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
);
5912 basepoints
[0] = healingfromticks
* triggerAmount
/ 100;
5913 triggered_spell_id
= 63544;
5916 // Improved Devouring Plague
5922 if (triggeredByAura
->GetEffIndex() != EFFECT_INDEX_1
)
5925 Aura
* leachAura
= pVictim
->GetAura(SPELL_AURA_PERIODIC_LEECH
, SPELLFAMILY_PRIEST
, UI64LIT(0x02000000), NULL
, GetGUID());
5929 int32 damagefromticks
= leachAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
);
5930 basepoints
[0] = damagefromticks
* triggerAmount
/ 100;
5931 triggered_spell_id
= 63675;
5936 switch(dummySpell
->Id
)
5941 // Return if self damage
5942 if (this == pVictim
)
5945 // Heal amount - Self/Team
5946 int32 team
= triggerAmount
*damage
/500;
5947 int32 self
= triggerAmount
*damage
/100 - team
;
5948 CastCustomSpell(this,15290,&team
,&self
,NULL
,true,castItem
,triggeredByAura
);
5949 return true; // no hidden cooldown
5951 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
5954 // Shadow Word: Pain
5955 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5956 triggered_spell_id
= 40441;
5958 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
5959 triggered_spell_id
= 40440;
5966 // Oracle Healing Bonus ("Garments of the Oracle" set)
5970 basepoints
[0] = int32(damage
* 10/100);
5972 triggered_spell_id
= 26170;
5975 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
5978 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
5982 basepoints
[0] = damage
* triggerAmount
/100;
5984 triggered_spell_id
= 39373;
5987 // Greater Heal (Vestments of Faith (Priest Tier 3) - 4 pieces bonus)
5990 triggered_spell_id
= 28810;
5993 // Glyph of Dispel Magic
5996 if(!target
->IsFriendlyTo(this))
5999 basepoints
[0] = int32(target
->GetMaxHealth() * triggerAmount
/ 100);
6000 triggered_spell_id
= 56131;
6006 case SPELLFAMILY_DRUID
:
6008 switch(dummySpell
->Id
)
6010 // Leader of the Pack
6013 // dummy m_amount store health percent (!=0 if Improved Leader of the Pack applied)
6014 int32 heal_percent
= triggeredByAura
->GetModifier()->m_amount
;
6018 // check explicitly only to prevent mana cast when halth cast cooldown
6019 if (cooldown
&& ((Player
*)this)->HasSpellCooldown(34299))
6023 triggered_spell_id
= 34299;
6024 basepoints
[0] = GetMaxHealth() * heal_percent
/ 100;
6028 if (triggeredByAura
->GetCasterGUID() == GetGUID())
6030 if (SpellEntry
const* manaCastEntry
= sSpellStore
.LookupEntry(60889))
6032 int32 mana_percent
= manaCastEntry
->CalculateSimpleValue(EFFECT_INDEX_0
) * heal_percent
;
6033 CastCustomSpell(this, manaCastEntry
, &mana_percent
, NULL
, NULL
, true, castItem
, triggeredByAura
);
6038 // Healing Touch (Dreamwalker Raiment set)
6042 basepoints
[0] = int32(procSpell
->manaCost
* 30 / 100);
6044 triggered_spell_id
= 28742;
6047 // Healing Touch Refund (Idol of Longevity trinket)
6051 triggered_spell_id
= 28848;
6054 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
6059 triggered_spell_id
= 37238;
6062 // Druid Tier 6 Trinket
6068 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
6070 triggered_spell_id
= 40445;
6074 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
6076 triggered_spell_id
= 40446;
6079 // Mangle (Bear) and Mangle (Cat)
6080 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000044000000000))
6082 triggered_spell_id
= 40452;
6088 if (!roll_chance_f(chance
))
6097 // Deadly Interrupt Effect
6098 triggered_spell_id
= 32747;
6101 // Glyph of Rejuvenation
6105 if (pVictim
->GetMaxHealth() < 2 * pVictim
->GetHealth())
6107 basepoints
[0] = triggerAmount
* damage
/ 100;
6108 triggered_spell_id
= 54755;
6111 // Item - Druid T10 Restoration 4P Bonus (Rejuvenation)
6114 if (!procSpell
|| GetTypeId() != TYPEID_PLAYER
)
6118 if (procSpell
->EffectRadiusIndex
[EFFECT_INDEX_0
])
6119 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(procSpell
->EffectRadiusIndex
[EFFECT_INDEX_0
]));
6121 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(procSpell
->rangeIndex
));
6123 ((Player
*)this)->ApplySpellMod(procSpell
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
6125 Unit
*second
= pVictim
->SelectRandomFriendlyTarget(pVictim
, radius
);
6130 pVictim
->CastSpell(second
, procSpell
, true, NULL
, triggeredByAura
, GetGUID());
6135 if (dummySpell
->SpellIconID
== 2856)
6139 // Only 0 aura can proc
6140 if (effIndex
!= EFFECT_INDEX_0
)
6143 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6147 if (!roll_chance_i(60))
6149 triggered_spell_id
= 48518;
6154 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
6158 triggered_spell_id
= 48517;
6165 else if (dummySpell
->SpellIconID
== 2860)
6167 triggered_spell_id
= 48504;
6168 basepoints
[0] = triggerAmount
* damage
/ 100;
6173 case SPELLFAMILY_ROGUE
:
6175 switch(dummySpell
->Id
)
6177 // Deadly Throw Interrupt
6180 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
6181 if (this == pVictim
)
6184 triggered_spell_id
= 32747;
6189 if (dummySpell
->SpellIconID
== 2909)
6191 // "refresh your Slice and Dice duration to its 5 combo point maximum"
6192 // lookup Slice and Dice
6193 AuraList
const& sd
= GetAurasByType(SPELL_AURA_MOD_HASTE
);
6194 for(AuraList::const_iterator itr
= sd
.begin(); itr
!= sd
.end(); ++itr
)
6196 SpellEntry
const *spellProto
= (*itr
)->GetSpellProto();
6197 if (spellProto
->SpellFamilyName
== SPELLFAMILY_ROGUE
&&
6198 (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000040000)))
6200 (*itr
)->SetAuraMaxDuration(GetSpellMaxDuration(spellProto
));
6201 (*itr
)->RefreshAura();
6208 if (dummySpell
->SpellIconID
== 2963)
6210 triggered_spell_id
= 44289;
6214 if (dummySpell
->SpellIconID
== 2116)
6220 basepoints
[0] = procSpell
->manaCost
* triggerAmount
/100;
6221 if (basepoints
[0] <= 0)
6225 triggered_spell_id
= 31663;
6230 case SPELLFAMILY_HUNTER
:
6232 // Aspect of the Viper
6233 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x4000000000000))
6235 uint32 maxmana
= GetMaxPower(POWER_MANA
);
6236 basepoints
[0] = int32(maxmana
* GetAttackTime(RANGED_ATTACK
)/1000.0f
/100.0f
);
6239 triggered_spell_id
= 34075;
6242 // Thrill of the Hunt
6243 if (dummySpell
->SpellIconID
== 2236)
6249 int32 mana
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
6250 basepoints
[0] = mana
* 40/100;
6251 if (basepoints
[0] <= 0)
6255 triggered_spell_id
= 34720;
6259 if (dummySpell
->SpellIconID
== 3406)
6261 triggered_spell_id
= 57669;
6266 if ( dummySpell
->SpellIconID
== 3579 )
6268 // Proc only from periodic (from trap activation proc another aura of this spell)
6269 if (!(procFlag
& PROC_FLAG_ON_DO_PERIODIC
) || !roll_chance_i(triggerAmount
))
6271 triggered_spell_id
= 56453;
6275 // Rapid Recuperation
6276 if ( dummySpell
->SpellIconID
== 3560 )
6278 // This effect only from Rapid Killing (mana regen)
6279 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0100000000000000)))
6284 switch(dummySpell
->Id
)
6286 case 53228: // Rank 1
6287 triggered_spell_id
= 56654;
6289 case 53232: // Rank 2
6290 triggered_spell_id
= 58882;
6295 // Glyph of Mend Pet
6296 if(dummySpell
->Id
== 57870)
6298 pVictim
->CastSpell(pVictim
, 57894, true, NULL
, NULL
, GetGUID());
6303 case SPELLFAMILY_PALADIN
:
6305 // Seal of Righteousness - melee proc dummy (addition ${$MWS*(0.022*$AP+0.044*$SPH)} damage)
6306 if ((dummySpell
->SpellFamilyFlags
& UI64LIT(0x000000008000000)) && effIndex
== EFFECT_INDEX_0
)
6308 triggered_spell_id
= 25742;
6309 float ap
= GetTotalAttackPowerValue(BASE_ATTACK
);
6310 int32 holy
= SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_HOLY
);
6313 basepoints
[0] = GetAttackTime(BASE_ATTACK
) * int32(ap
*0.022f
+ 0.044f
* holy
) / 1000;
6316 // Righteous Vengeance
6317 if (dummySpell
->SpellIconID
== 3025)
6320 basepoints
[0] = triggerAmount
*damage
/400;
6321 triggered_spell_id
= 61840;
6325 if (dummySpell
->SpellIconID
== 3030)
6328 basepoints
[0] = triggerAmount
*damage
/400;
6329 triggered_spell_id
= 54203;
6332 switch(dummySpell
->Id
)
6334 // Judgement of Light
6337 basepoints
[0] = int32( pVictim
->GetMaxHealth() * triggeredByAura
->GetModifier()->m_amount
/ 100 );
6338 pVictim
->CastCustomSpell(pVictim
, 20267, &basepoints
[0], NULL
, NULL
, true, NULL
, triggeredByAura
);
6341 // Judgement of Wisdom
6344 if (pVictim
->getPowerType() == POWER_MANA
)
6346 // 2% of maximum base mana
6347 basepoints
[0] = int32(pVictim
->GetCreateMana() * 2 / 100);
6348 pVictim
->CastCustomSpell(pVictim
, 20268, &basepoints
[0], NULL
, NULL
, true, NULL
, triggeredByAura
);
6352 // Heart of the Crusader (Rank 1)
6354 triggered_spell_id
= 21183;
6356 // Heart of the Crusader (Rank 2)
6358 triggered_spell_id
= 54498;
6360 // Heart of the Crusader (Rank 3)
6362 triggered_spell_id
= 54499;
6364 case 20911: // Blessing of Sanctuary
6365 case 25899: // Greater Blessing of Sanctuary
6368 switch (target
->getPowerType())
6371 triggered_spell_id
= 57319;
6378 // Holy Power (Redemption Armor set)
6384 // Set class defined buff
6385 switch (pVictim
->getClass())
6391 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6395 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6399 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
6402 triggered_spell_id
= 28790; // Increases the friendly target's armor
6409 // Spiritual Attunement
6413 // if healed by another unit (pVictim)
6414 if (this == pVictim
)
6418 basepoints
[0] = triggerAmount
*damage
/100;
6420 triggered_spell_id
= 31786;
6423 // Seal of Vengeance (damage calc on apply aura)
6426 if (effIndex
!= EFFECT_INDEX_0
) // effect 1,2 used by seal unleashing code
6429 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6430 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595) )
6431 triggered_spell_id
= 31803; // Holy Vengeance
6433 // Add 5-stack effect from Holy Vengeance
6435 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6436 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6438 if( ((*itr
)->GetId() == 31803) && (*itr
)->GetCasterGUID()==GetGUID())
6440 stacks
= (*itr
)->GetStackAmount();
6445 CastSpell(target
,42463,true,NULL
,triggeredByAura
);
6448 // Judgements of the Wise
6452 // triggered only at casted Judgement spells, not at additional Judgement effects
6453 if(!procSpell
|| procSpell
->Category
!= 1210)
6457 triggered_spell_id
= 31930;
6460 CastSpell(this, 57669, true, NULL
, triggeredByAura
);
6462 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
6470 // Flash of light/Holy light
6471 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x00000000C0000000))
6473 triggered_spell_id
= 40471;
6477 else if (GetSpellSpecific(procSpell
->Id
)==SPELL_JUDGEMENT
)
6479 triggered_spell_id
= 40472;
6485 if (!roll_chance_f(chance
))
6490 // Light's Beacon (heal target area aura)
6493 // not do bonus heal for explicit beacon focus healing
6494 if (GetGUID() == triggeredByAura
->GetCasterGUID())
6498 Unit
* beacon
= triggeredByAura
->GetCaster();
6502 // find caster main aura at beacon
6504 Unit::AuraList
const& baa
= beacon
->GetAurasByType(SPELL_AURA_PERIODIC_TRIGGER_SPELL
);
6505 for(Unit::AuraList::const_iterator i
= baa
.begin(); i
!= baa
.end(); ++i
)
6507 if ((*i
)->GetId() == 53563 && (*i
)->GetCasterGUID() == pVictim
->GetGUID())
6514 // original heal must be form beacon caster
6518 triggered_spell_id
= 53652; // Beacon of Light
6519 basepoints
[0] = triggeredByAura
->GetModifier()->m_amount
*damage
/100;
6521 // cast with original caster set but beacon to beacon for apply caster mods and avoid LoS check
6522 beacon
->CastCustomSpell(beacon
,triggered_spell_id
,&basepoints
[0],NULL
,NULL
,true,castItem
,triggeredByAura
,pVictim
->GetGUID());
6525 // Seal of Corruption (damage calc on apply aura)
6528 if (effIndex
!= EFFECT_INDEX_0
) // effect 1,2 used by seal unleashing code
6531 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6532 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595))
6533 triggered_spell_id
= 53742; // Blood Corruption
6535 // Add 5-stack effect from Blood Corruption
6537 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6538 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6540 if( ((*itr
)->GetId() == 53742) && (*itr
)->GetCasterGUID()==GetGUID())
6542 stacks
= (*itr
)->GetStackAmount();
6547 CastSpell(target
,53739,true,NULL
,triggeredByAura
);
6550 // Glyph of Holy Light
6553 triggered_spell_id
= 54968;
6554 basepoints
[0] = triggerAmount
*damage
/100;
6557 // Glyph of Divinity
6560 // Lookup base amount mana restore
6561 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
6563 if (procSpell
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
6565 int32 mana
= procSpell
->CalculateSimpleValue(SpellEffectIndex(i
));
6566 CastCustomSpell(this, 54986, NULL
, &mana
, NULL
, true, castItem
, triggeredByAura
);
6572 // Sacred Shield (buff)
6575 triggered_spell_id
= 66922;
6576 SpellEntry
const* triggeredEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6577 if (!triggeredEntry
)
6580 basepoints
[0] = int32(damage
/ (GetSpellDuration(triggeredEntry
) / triggeredEntry
->EffectAmplitude
[EFFECT_INDEX_0
]));
6584 // Sacred Shield (talent rank)
6587 triggered_spell_id
= 58597;
6594 case SPELLFAMILY_SHAMAN
:
6596 switch(dummySpell
->Id
)
6598 // Totemic Power (The Earthshatterer set)
6604 // Set class defined buff
6605 switch (pVictim
->getClass())
6611 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6615 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6619 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
6622 triggered_spell_id
= 28827; // Increases the friendly target's armor
6629 // Lesser Healing Wave (Totem of Flowing Water Relic)
6633 triggered_spell_id
= 28850;
6636 // Windfury Weapon (Passive) 1-5 Ranks
6639 if(GetTypeId()!=TYPEID_PLAYER
)
6642 if(!castItem
|| !castItem
->IsEquipped())
6645 // custom cooldown processing case
6646 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6649 // Now amount of extra power stored in 1 effect of Enchant spell
6650 // Get it by item enchant id
6652 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
6654 case 283: spellId
= 8232; break; // 1 Rank
6655 case 284: spellId
= 8235; break; // 2 Rank
6656 case 525: spellId
= 10486; break; // 3 Rank
6657 case 1669:spellId
= 16362; break; // 4 Rank
6658 case 2636:spellId
= 25505; break; // 5 Rank
6659 case 3785:spellId
= 58801; break; // 6 Rank
6660 case 3786:spellId
= 58803; break; // 7 Rank
6661 case 3787:spellId
= 58804; break; // 8 Rank
6664 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
6665 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
6670 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
6671 if(!windfurySpellEntry
)
6673 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
6677 int32 extra_attack_power
= CalculateSpellDamage(pVictim
, windfurySpellEntry
, EFFECT_INDEX_1
);
6680 if (castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
6682 // Value gained from additional AP
6683 basepoints
[0] = int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
6684 triggered_spell_id
= 33750;
6689 // Value gained from additional AP
6690 basepoints
[0] = int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
6691 triggered_spell_id
= 25504;
6694 // apply cooldown before cast to prevent processing itself
6696 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6699 for ( uint32 i
= 0; i
<2; ++i
)
6700 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints
[0],NULL
,NULL
,true,castItem
,triggeredByAura
);
6704 // Shaman Tier 6 Trinket
6711 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6713 triggered_spell_id
= 40465; // Lightning Bolt
6716 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080))
6718 triggered_spell_id
= 40465; // Lesser Healing Wave
6721 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
6723 triggered_spell_id
= 40466; // Stormstrike
6729 if (!roll_chance_f(chance
))
6735 // Glyph of Healing Wave
6738 // Not proc from self heals
6741 basepoints
[0] = triggerAmount
* damage
/ 100;
6743 triggered_spell_id
= 55533;
6750 target
= GetOwner();
6753 basepoints
[0] = triggerAmount
* damage
/ 100;
6754 triggered_spell_id
= 58879;
6757 // Glyph of Totem of Wrath
6760 Totem
* totem
= GetTotem(TOTEM_SLOT_FIRE
);
6764 // find totem aura bonus
6765 AuraList
const& spellPower
= totem
->GetAurasByType(SPELL_AURA_NONE
);
6766 for(AuraList::const_iterator i
= spellPower
.begin();i
!= spellPower
.end(); ++i
)
6768 // select proper aura for format aura type in spell proto
6769 if ((*i
)->GetTarget()==totem
&& (*i
)->GetSpellProto()->EffectApplyAuraName
[(*i
)->GetEffIndex()] == SPELL_AURA_MOD_HEALING_DONE
&&
6770 (*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000004000000))
6772 basepoints
[0] = triggerAmount
* (*i
)->GetModifier()->m_amount
/ 100;
6780 basepoints
[1] = basepoints
[0];
6781 triggered_spell_id
= 63283; // Totem of Wrath, caster bonus
6785 // Shaman T8 Elemental 4P Bonus
6788 basepoints
[0] = int32( triggerAmount
* damage
/ 100 );
6789 triggered_spell_id
= 64930; // Electrified
6792 // Shaman T9 Elemental 4P Bonus
6795 basepoints
[0] = int32( triggerAmount
* damage
/ 100 );
6796 triggered_spell_id
= 71824;
6800 // Storm, Earth and Fire
6801 if (dummySpell
->SpellIconID
== 3063)
6803 // Earthbind Totem summon only
6804 if(procSpell
->Id
!= 2484)
6807 if (!roll_chance_i(triggerAmount
))
6810 triggered_spell_id
= 64695;
6813 // Ancestral Awakening
6814 if (dummySpell
->SpellIconID
== 3065)
6816 triggered_spell_id
= 52759;
6817 basepoints
[0] = triggerAmount
* damage
/ 100;
6822 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
6825 basepoints
[0] = triggerAmount
;
6827 // Glyph of Earth Shield
6828 if (Aura
* aur
= GetDummyAura(63279))
6830 int32 aur_mod
= aur
->GetModifier()->m_amount
;
6831 basepoints
[0] = int32(basepoints
[0] * (aur_mod
+ 100.0f
) / 100.0f
);
6834 triggered_spell_id
= 379;
6837 // Improved Water Shield
6838 if (dummySpell
->SpellIconID
== 2287)
6840 // Lesser Healing Wave need aditional 60% roll
6841 if ((procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)) && !roll_chance_i(60))
6843 // lookup water shield
6844 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6845 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6847 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6848 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000002000000000)))
6850 uint32 spell
= (*itr
)->GetSpellProto()->EffectTriggerSpell
[(*itr
)->GetEffIndex()];
6851 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
6852 if ((*itr
)->DropAuraCharge())
6853 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6860 // Lightning Overload
6861 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
6863 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
6866 // custom cooldown processing case
6867 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6871 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
6872 switch (procSpell
->Id
)
6875 case 403: spellId
= 45284; break; // Rank 1
6876 case 529: spellId
= 45286; break; // Rank 2
6877 case 548: spellId
= 45287; break; // Rank 3
6878 case 915: spellId
= 45288; break; // Rank 4
6879 case 943: spellId
= 45289; break; // Rank 5
6880 case 6041: spellId
= 45290; break; // Rank 6
6881 case 10391: spellId
= 45291; break; // Rank 7
6882 case 10392: spellId
= 45292; break; // Rank 8
6883 case 15207: spellId
= 45293; break; // Rank 9
6884 case 15208: spellId
= 45294; break; // Rank 10
6885 case 25448: spellId
= 45295; break; // Rank 11
6886 case 25449: spellId
= 45296; break; // Rank 12
6887 case 49237: spellId
= 49239; break; // Rank 13
6888 case 49238: spellId
= 49240; break; // Rank 14
6890 case 421: spellId
= 45297; break; // Rank 1
6891 case 930: spellId
= 45298; break; // Rank 2
6892 case 2860: spellId
= 45299; break; // Rank 3
6893 case 10605: spellId
= 45300; break; // Rank 4
6894 case 25439: spellId
= 45301; break; // Rank 5
6895 case 25442: spellId
= 45302; break; // Rank 6
6896 case 49270: spellId
= 49268; break; // Rank 7
6897 case 49271: spellId
= 49269; break; // Rank 8
6899 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
6902 // No thread generated mod
6903 // TODO: exist special flag in spell attributes for this, need found and use!
6904 SpellModifier
*mod
= new SpellModifier(SPELLMOD_THREAT
,SPELLMOD_PCT
,-100,triggeredByAura
);
6906 ((Player
*)this)->AddSpellMod(mod
, true);
6908 // Remove cooldown (Chain Lightning - have Category Recovery time)
6909 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000002))
6910 ((Player
*)this)->RemoveSpellCooldown(spellId
);
6912 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
6914 ((Player
*)this)->AddSpellMod(mod
, false);
6916 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6917 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6922 if(dummySpell
->SpellIconID
== 3059)
6924 // lookup Lightning Shield
6925 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6926 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6928 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6929 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000400)))
6932 switch ((*itr
)->GetId())
6934 case 324: spell
= 26364; break;
6935 case 325: spell
= 26365; break;
6936 case 905: spell
= 26366; break;
6937 case 945: spell
= 26367; break;
6938 case 8134: spell
= 26369; break;
6939 case 10431: spell
= 26370; break;
6940 case 10432: spell
= 26363; break;
6941 case 25469: spell
= 26371; break;
6942 case 25472: spell
= 26372; break;
6943 case 49280: spell
= 49278; break;
6944 case 49281: spell
= 49279; break;
6948 CastSpell(target
, spell
, true, castItem
, triggeredByAura
);
6949 if ((*itr
)->DropAuraCharge())
6950 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6957 if (dummySpell
->SpellIconID
== 3780)
6959 Unit
*caster
= triggeredByAura
->GetCaster();
6961 if (!procSpell
|| !caster
)
6964 float distance
= caster
->GetDistance(pVictim
);
6965 int32 chance
= triggerAmount
;
6967 if (distance
< 15.0f
|| !roll_chance_i(chance
))
6970 // make triggered cast apply after current damage spell processing for prevent remove by it
6971 if(Spell
* spell
= GetCurrentSpell(CURRENT_GENERIC_SPELL
))
6972 spell
->AddTriggeredSpell(63685);
6977 case SPELLFAMILY_DEATHKNIGHT
:
6980 if (dummySpell
->SpellIconID
== 2664)
6982 basepoints
[0] = triggerAmount
;
6983 triggered_spell_id
= 50163;
6987 // Dancing Rune Weapon
6988 if (dummySpell
->Id
== 49028)
6990 // 1 dummy aura for dismiss rune blade
6991 if (effIndex
!= EFFECT_INDEX_2
)
6993 // TODO: wite script for this "fights on its own, doing the same attacks"
6994 // NOTE: Trigger here on every attack and spell cast
6998 if (dummySpell
->Id
== 49005)
7000 // TODO: need more info (cooldowns/PPM)
7001 triggered_spell_id
= 61607;
7005 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000010000))
7007 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
7008 triggered_spell_id
= 50181;
7013 if (dummySpell
->SpellIconID
== 2709)
7015 basepoints
[0] = triggerAmount
* damage
/ 100;
7016 triggered_spell_id
= 51460;
7019 // Threat of Thassarian
7020 if (dummySpell
->SpellIconID
== 2023)
7023 if (!procSpell
|| !haveOffhandWeapon())
7025 // Chance as basepoints for dummy aura
7026 if (!roll_chance_i(triggerAmount
))
7029 switch (procSpell
->Id
)
7032 case 49020: // Rank 1
7033 triggered_spell_id
= 66198; break;
7034 case 51423: // Rank 2
7035 triggered_spell_id
= 66972; break;
7036 case 51424: // Rank 3
7037 triggered_spell_id
= 66973; break;
7038 case 51425: // Rank 4
7039 triggered_spell_id
= 66974; break;
7041 case 49143: // Rank 1
7042 triggered_spell_id
= 66196; break;
7043 case 51416: // Rank 2
7044 triggered_spell_id
= 66958; break;
7045 case 51417: // Rank 3
7046 triggered_spell_id
= 66959; break;
7047 case 51418: // Rank 4
7048 triggered_spell_id
= 66960; break;
7049 case 51419: // Rank 5
7050 triggered_spell_id
= 66961; break;
7051 case 55268: // Rank 6
7052 triggered_spell_id
= 66962; break;
7054 case 45462: // Rank 1
7055 triggered_spell_id
= 66216; break;
7056 case 49917: // Rank 2
7057 triggered_spell_id
= 66988; break;
7058 case 49918: // Rank 3
7059 triggered_spell_id
= 66989; break;
7060 case 49919: // Rank 4
7061 triggered_spell_id
= 66990; break;
7062 case 49920: // Rank 5
7063 triggered_spell_id
= 66991; break;
7064 case 49921: // Rank 6
7065 triggered_spell_id
= 66992; break;
7067 case 49998: // Rank 1
7068 triggered_spell_id
= 66188; break;
7069 case 49999: // Rank 2
7070 triggered_spell_id
= 66950; break;
7071 case 45463: // Rank 3
7072 triggered_spell_id
= 66951; break;
7073 case 49923: // Rank 4
7074 triggered_spell_id
= 66952; break;
7075 case 49924: // Rank 5
7076 triggered_spell_id
= 66953; break;
7079 triggered_spell_id
= 66217; break;
7081 case 45902: // Rank 1
7082 triggered_spell_id
= 66215; break;
7083 case 49926: // Rank 2
7084 triggered_spell_id
= 66975; break;
7085 case 49927: // Rank 3
7086 triggered_spell_id
= 66976; break;
7087 case 49928: // Rank 4
7088 triggered_spell_id
= 66977; break;
7089 case 49929: // Rank 5
7090 triggered_spell_id
= 66978; break;
7091 case 49930: // Rank 6
7092 triggered_spell_id
= 66979; break;
7098 // Runic Power Back on Snare/Root
7099 if (dummySpell
->Id
== 61257)
7101 // only for spells and hit/crit (trigger start always) and not start from self casted spells
7102 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7104 // Need snare or root mechanic
7105 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_SNARE_MASK
))
7107 triggered_spell_id
= 61258;
7112 if (dummySpell
->SpellIconID
== 1614)
7114 if (!roll_chance_f(GetUnitCriticalChance(BASE_ATTACK
, pVictim
)))
7116 basepoints
[0] = triggerAmount
* damage
/ 100;
7117 triggered_spell_id
= 50526;
7120 // Blood-Caked Blade
7121 if (dummySpell
->SpellIconID
== 138)
7123 triggered_spell_id
= dummySpell
->EffectTriggerSpell
[effIndex
];
7132 // processed charge only counting case
7133 if(!triggered_spell_id
)
7136 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
7140 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
7145 if(!target
|| target
!=this && !target
->isAlive())
7148 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
7151 if (basepoints
[EFFECT_INDEX_0
] || basepoints
[EFFECT_INDEX_1
] || basepoints
[EFFECT_INDEX_2
])
7152 CastCustomSpell(target
, triggered_spell_id
,
7153 basepoints
[EFFECT_INDEX_0
] ? &basepoints
[EFFECT_INDEX_0
] : NULL
,
7154 basepoints
[EFFECT_INDEX_1
] ? &basepoints
[EFFECT_INDEX_1
] : NULL
,
7155 basepoints
[EFFECT_INDEX_2
] ? &basepoints
[EFFECT_INDEX_2
] : NULL
,
7156 true, castItem
, triggeredByAura
);
7158 CastSpell(target
, triggered_spell_id
, true, castItem
, triggeredByAura
);
7160 if (cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7161 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
7166 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
7168 // Get triggered aura spell info
7169 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
7171 // Basepoints of trigger aura
7172 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7174 // Set trigger spell id, target, custom basepoints
7175 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
7176 Unit
* target
= NULL
;
7177 int32 basepoints
[MAX_EFFECT_INDEX
] = {0, 0, 0};
7179 if(triggeredByAura
->GetModifier()->m_auraname
== SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
)
7180 basepoints
[0] = triggerAmount
;
7182 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7183 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7185 // Try handle unknown trigger spells
7186 // Custom requirements (not listed in procEx) Warning! damage dealing after this
7187 // Custom triggered spells
7188 switch (auraSpellInfo
->SpellFamilyName
)
7190 case SPELLFAMILY_GENERIC
:
7191 switch(auraSpellInfo
->Id
)
7193 //case 191: // Elemental Response
7194 // switch (procSpell->School)
7196 // case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192; break;
7197 // case SPELL_SCHOOL_FROST: trigger_spell_id = 34193; break;
7198 // case SPELL_SCHOOL_ARCANE:trigger_spell_id = 34194; break;
7199 // case SPELL_SCHOOL_NATURE:trigger_spell_id = 34195; break;
7200 // case SPELL_SCHOOL_SHADOW:trigger_spell_id = 34196; break;
7201 // case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197; break;
7202 // case SPELL_SCHOOL_NORMAL:trigger_spell_id = 34198; break;
7205 //case 5301: break; // Defensive State (DND)
7206 //case 7137: break: // Shadow Charge (Rank 1)
7207 //case 7377: break: // Take Immune Periodic Damage <Not Working>
7208 //case 13358: break; // Defensive State (DND)
7209 //case 16092: break; // Defensive State (DND)
7210 //case 18943: break; // Double Attack
7211 //case 19194: break; // Double Attack
7212 //case 19817: break; // Double Attack
7213 //case 19818: break; // Double Attack
7214 //case 22835: break; // Drunken Rage
7215 // trigger_spell_id = 14822; break;
7216 case 23780: // Aegis of Preservation (Aegis of Preservation trinket)
7217 trigger_spell_id
= 23781;
7219 //case 24949: break; // Defensive State 2 (DND)
7220 case 27522: // Mana Drain Trigger
7221 case 40336: // Mana Drain Trigger
7222 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
7224 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
7225 if (pVictim
&& pVictim
->isAlive())
7226 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
7228 case 31255: // Deadly Swiftness (Rank 1)
7229 // whenever you deal damage to a target who is below 20% health.
7230 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
7234 trigger_spell_id
= 22588;
7236 //case 33207: break; // Gossip NPC Periodic - Fidget
7237 case 33896: // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
7238 trigger_spell_id
= 33898;
7240 //case 34082: break; // Advantaged State (DND)
7241 //case 34783: break: // Spell Reflection
7242 //case 35205: break: // Vanish
7243 //case 35321: break; // Gushing Wound
7244 //case 36096: break: // Spell Reflection
7245 //case 36207: break: // Steal Weapon
7246 //case 36576: break: // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
7247 //case 37030: break; // Chaotic Temperament
7248 //case 38363: break; // Gushing Wound
7249 //case 39215: break; // Gushing Wound
7250 //case 40250: break; // Improved Duration
7251 //case 40329: break; // Demo Shout Sensor
7252 //case 40364: break; // Entangling Roots Sensor
7253 //case 41054: break; // Copy Weapon
7254 // trigger_spell_id = 41055; break;
7255 //case 41248: break; // Consuming Strikes
7256 // trigger_spell_id = 41249; break;
7257 //case 42730: break: // Woe Strike
7258 //case 43453: break: // Rune Ward
7259 //case 43504: break; // Alterac Valley OnKill Proc Aura
7260 //case 44326: break: // Pure Energy Passive
7261 //case 44526: break; // Hate Monster (Spar) (30 sec)
7262 //case 44527: break; // Hate Monster (Spar Buddy) (30 sec)
7263 //case 44819: break; // Hate Monster (Spar Buddy) (>30% Health)
7264 //case 44820: break; // Hate Monster (Spar) (<30%)
7265 case 45057: // Evasive Maneuvers (Commendation of Kael`thas trinket)
7266 // reduce you below $s1% health
7267 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
7270 //case 45903: break: // Offensive State
7271 //case 46146: break: // [PH] Ahune Spanky Hands
7272 //case 46939: break; // Black Bow of the Betrayer
7273 // trigger_spell_id = 29471; - gain mana
7274 // 27526; - drain mana if possible
7275 case 43820: // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
7276 // Pct value stored in dummy
7277 basepoints
[0] = pVictim
->GetCreateHealth() * auraSpellInfo
->CalculateSimpleValue(EFFECT_INDEX_1
) / 100;
7280 //case 45205: break; // Copy Offhand Weapon
7281 //case 45343: break; // Dark Flame Aura
7282 //case 47300: break; // Dark Flame Aura
7283 //case 48876: break; // Beast's Mark
7284 // trigger_spell_id = 48877; break;
7285 //case 49059: break; // Horde, Hate Monster (Spar Buddy) (>30% Health)
7286 //case 50051: break; // Ethereal Pet Aura
7287 //case 50689: break; // Blood Presence (Rank 1)
7288 //case 50844: break; // Blood Mirror
7289 //case 52856: break; // Charge
7290 //case 54072: break; // Knockback Ball Passive
7291 //case 54476: break; // Blood Presence
7292 //case 54775: break; // Abandon Vehicle on Poly
7293 case 57345: // Darkmoon Card: Greatness
7297 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 60229;stat
= GetStat(STAT_STRENGTH
); }
7299 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 60233;stat
= GetStat(STAT_AGILITY
); }
7301 if (GetStat(STAT_INTELLECT
)> stat
) { trigger_spell_id
= 60234;stat
= GetStat(STAT_INTELLECT
);}
7303 if (GetStat(STAT_SPIRIT
) > stat
) { trigger_spell_id
= 60235; }
7306 //case 55580: break: // Mana Link
7307 //case 57587: break: // Steal Ranged ()
7308 //case 57594: break; // Copy Ranged Weapon
7309 //case 59237: break; // Beast's Mark
7310 // trigger_spell_id = 59233; break;
7311 //case 59288: break; // Infra-Green Shield
7312 //case 59532: break; // Abandon Passengers on Poly
7313 //case 59735: break: // Woe Strike
7314 case 64415: // // Val'anyr Hammer of Ancient Kings - Equip Effect
7317 if (!IsPositiveSpell(procSpell
->Id
))
7321 case 67702: // Death's Choice, Item - Coliseum 25 Normal Melee Trinket
7325 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67708;stat
= GetStat(STAT_STRENGTH
); }
7327 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67703; }
7330 case 67771: // Death's Choice (heroic), Item - Coliseum 25 Heroic Melee Trinket
7334 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67773;stat
= GetStat(STAT_STRENGTH
); }
7336 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67772; }
7341 case SPELLFAMILY_MAGE
:
7342 if (auraSpellInfo
->SpellIconID
== 2127) // Blazing Speed
7344 switch (auraSpellInfo
->Id
)
7346 case 31641: // Rank 1
7347 case 31642: // Rank 2
7348 trigger_spell_id
= 31643;
7351 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
7355 // Persistent Shield (Scarab Brooch trinket)
7356 else if(auraSpellInfo
->Id
== 26467)
7358 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
7359 basepoints
[0] = damage
* 15 / 100;
7361 trigger_spell_id
= 26470;
7364 case SPELLFAMILY_WARRIOR
:
7365 // Deep Wounds (replace triggered spells to directly apply DoT), dot spell have finilyflags
7366 if (auraSpellInfo
->SpellFamilyFlags
== UI64LIT(0x0) && auraSpellInfo
->SpellIconID
== 243)
7369 // DW should benefit of attack power, damage percent mods etc.
7370 // TODO: check if using offhand damage is correct and if it should be divided by 2
7371 if (haveOffhandWeapon() && getAttackTimer(BASE_ATTACK
) > getAttackTimer(OFF_ATTACK
))
7372 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
))/2;
7374 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXDAMAGE
))/2;
7376 switch (auraSpellInfo
->Id
)
7378 case 12834: basepoints
[0] = int32(weaponDamage
* 16 / 100); break;
7379 case 12849: basepoints
[0] = int32(weaponDamage
* 32 / 100); break;
7380 case 12867: basepoints
[0] = int32(weaponDamage
* 48 / 100); break;
7383 sLog
.outError("Unit::HandleProcTriggerSpell: DW unknown spell rank %u",auraSpellInfo
->Id
);
7387 // 1 tick/sec * 6 sec = 6 ticks
7390 trigger_spell_id
= 12721;
7393 if (auraSpellInfo
->Id
== 50421) // Scent of Blood
7394 trigger_spell_id
= 50422;
7396 case SPELLFAMILY_WARLOCK
:
7399 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
7401 Unit::AuraList
const& mAddFlatModifier
= GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER
);
7402 for(Unit::AuraList::const_iterator i
= mAddFlatModifier
.begin(); i
!= mAddFlatModifier
.end(); ++i
)
7404 if ((*i
)->GetModifier()->m_miscvalue
== SPELLMOD_CHANCE_OF_SUCCESS
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
7407 CastCustomSpell(this, 18371, &basepoints
[0], NULL
, NULL
, true, castItem
, triggeredByAura
);
7411 // Not remove charge (aura removed on death in any cases)
7412 // Need for correct work Drain Soul SPELL_AURA_CHANNEL_DEATH_ITEM aura
7415 // Nether Protection
7416 else if (auraSpellInfo
->SpellIconID
== 1985)
7420 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7422 case SPELL_SCHOOL_NORMAL
:
7423 return false; // ignore
7424 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 54370; break;
7425 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 54371; break;
7426 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 54375; break;
7427 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 54372; break;
7428 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 54374; break;
7429 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
7435 else if (auraSpellInfo
->Id
== 28845)
7437 // When your health drops below 20% ....
7438 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
7442 else if (auraSpellInfo
->Id
== 63156 || auraSpellInfo
->Id
== 63158)
7444 // Looking for dummy effect
7445 Aura
*aur
= GetAura(auraSpellInfo
->Id
, EFFECT_INDEX_1
);
7449 // If target's health is not below equal certain value (35%) not proc
7450 if (int32(pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth()) > aur
->GetModifier()->m_amount
)
7455 case SPELLFAMILY_PRIEST
:
7457 // Greater Heal Refund (Avatar Raiment set)
7458 if (auraSpellInfo
->Id
==37594)
7460 // Not give if target already have full health
7461 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
7463 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
7464 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
7466 trigger_spell_id
= 37595;
7469 else if (auraSpellInfo
->SpellIconID
== 1875)
7471 switch (auraSpellInfo
->Id
)
7473 case 27811: trigger_spell_id
= 27813; break;
7474 case 27815: trigger_spell_id
= 27817; break;
7475 case 27816: trigger_spell_id
= 27818; break;
7477 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
7480 basepoints
[0] = damage
* triggerAmount
/ 100 / 3;
7485 case SPELLFAMILY_DRUID
:
7487 // Druid Forms Trinket
7488 if (auraSpellInfo
->Id
==37336)
7492 case FORM_NONE
: trigger_spell_id
= 37344;break;
7493 case FORM_CAT
: trigger_spell_id
= 37341;break;
7495 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
7496 case FORM_TREE
: trigger_spell_id
= 37342;break;
7497 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
7502 // Druid T9 Feral Relic (Lacerate, Swipe, Mangle, and Shred)
7503 else if (auraSpellInfo
->Id
==67353)
7507 case FORM_CAT
: trigger_spell_id
= 67355; break;
7509 case FORM_DIREBEAR
: trigger_spell_id
= 67354; break;
7516 case SPELLFAMILY_HUNTER
:
7518 if (auraSpellInfo
->SpellIconID
== 3247 && auraSpellInfo
->SpellVisual
[0] == 0)
7520 basepoints
[0] = damage
* triggerAmount
/ 100 / 8;
7521 trigger_spell_id
= 63468;
7524 // Rapid Recuperation
7525 else if (auraSpellInfo
->Id
== 53228 || auraSpellInfo
->Id
== 53232)
7527 // This effect only from Rapid Fire (ability cast)
7528 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000020)))
7532 case SPELLFAMILY_PALADIN
:
7536 if (auraSpellInfo->SpellIconID == 2137)
7538 switch (auraSpellInfo->Id)
7540 case 31828: // Rank 1
7541 case 31829: // Rank 2
7542 case 31830: // Rank 3
7545 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
7551 if (auraSpellInfo
->Id
==37705)
7553 trigger_spell_id
= 37706;
7557 if (auraSpellInfo
->Id
==60510)
7559 trigger_spell_id
= 60515;
7563 else if (auraSpellInfo
->SpellIconID
==241)
7567 // procspell is triggered spell but we need mana cost of original casted spell
7568 uint32 originalSpellId
= procSpell
->Id
;
7570 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0001000000000000))
7572 switch(procSpell
->Id
)
7574 case 25914: originalSpellId
= 20473; break;
7575 case 25913: originalSpellId
= 20929; break;
7576 case 25903: originalSpellId
= 20930; break;
7577 case 27175: originalSpellId
= 27174; break;
7578 case 33074: originalSpellId
= 33072; break;
7579 case 48820: originalSpellId
= 48824; break;
7580 case 48821: originalSpellId
= 48825; break;
7582 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
7586 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
7589 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
7592 // percent stored in effect 1 (class scripts) base points
7593 int32 cost
= originalSpell
->manaCost
+ originalSpell
->ManaCostPercentage
* GetCreateMana() / 100;
7594 basepoints
[0] = cost
*auraSpellInfo
->CalculateSimpleValue(EFFECT_INDEX_1
)/100;
7595 trigger_spell_id
= 20272;
7598 // Lightning Capacitor
7599 else if (auraSpellInfo
->Id
==37657)
7601 if(!pVictim
|| !pVictim
->isAlive())
7604 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
7606 Aura
* dummy
= GetDummyAura(37658);
7607 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7608 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7611 RemoveAurasDueToSpell(37658);
7612 trigger_spell_id
= 37661;
7615 // Bonus Healing (Crystal Spire of Karabor mace)
7616 else if (auraSpellInfo
->Id
== 40971)
7618 // If your target is below $s1% health
7619 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
7622 // Thunder Capacitor
7623 else if (auraSpellInfo
->Id
== 54841)
7625 if(!pVictim
|| !pVictim
->isAlive())
7628 CastSpell(this, 54842, true, NULL
, triggeredByAura
);
7631 Aura
* dummy
= GetDummyAura(54842);
7632 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7633 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7636 RemoveAurasDueToSpell(54842);
7637 trigger_spell_id
= 54843;
7642 case SPELLFAMILY_SHAMAN
:
7644 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc
7645 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000400))
7647 switch(auraSpellInfo
->Id
)
7650 trigger_spell_id
= 26364; break;
7652 trigger_spell_id
= 26365; break;
7654 trigger_spell_id
= 26366; break;
7656 trigger_spell_id
= 26367; break;
7657 case 8134: // Rank 5
7658 trigger_spell_id
= 26369; break;
7659 case 10431: // Rank 6
7660 trigger_spell_id
= 26370; break;
7661 case 10432: // Rank 7
7662 trigger_spell_id
= 26363; break;
7663 case 25469: // Rank 8
7664 trigger_spell_id
= 26371; break;
7665 case 25472: // Rank 9
7666 trigger_spell_id
= 26372; break;
7667 case 49280: // Rank 10
7668 trigger_spell_id
= 49278; break;
7669 case 49281: // Rank 11
7670 trigger_spell_id
= 49279; break;
7672 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
7676 // Lightning Shield (The Ten Storms set)
7677 else if (auraSpellInfo
->Id
== 23551)
7679 trigger_spell_id
= 23552;
7682 // Damage from Lightning Shield (The Ten Storms set)
7683 else if (auraSpellInfo
->Id
== 23552)
7684 trigger_spell_id
= 27635;
7685 // Mana Surge (The Earthfury set)
7686 else if (auraSpellInfo
->Id
== 23572)
7690 basepoints
[0] = procSpell
->manaCost
* 35 / 100;
7691 trigger_spell_id
= 23571;
7694 // Nature's Guardian
7695 else if (auraSpellInfo
->SpellIconID
== 2013)
7697 // Check health condition - should drop to less 30% (damage deal after this!)
7698 if (!(10*(int32(GetHealth() - damage
)) < int32(3 * GetMaxHealth())))
7701 if(pVictim
&& pVictim
->isAlive())
7702 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
7704 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
7705 trigger_spell_id
= 31616;
7710 case SPELLFAMILY_DEATHKNIGHT
:
7713 if (auraSpellInfo
->SpellIconID
== 1930)
7717 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7719 case SPELL_SCHOOL_NORMAL
:
7720 return false; // ignore
7721 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 50490; break;
7722 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 50362; break;
7723 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 50488; break;
7724 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 50485; break;
7725 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 50489; break;
7726 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 50486; break;
7732 else if (auraSpellInfo
->SpellIconID
== 85)
7734 if (GetTypeId() != TYPEID_PLAYER
|| getClass() != CLASS_DEATH_KNIGHT
||
7735 !((Player
*)this)->IsBaseRuneSlotsOnCooldown(RUNE_BLOOD
))
7738 // Improved Blood Presence
7739 else if (auraSpellInfo
->Id
== 63611)
7741 if (GetTypeId() != TYPEID_PLAYER
|| !((Player
*)this)->isHonorOrXPTarget(pVictim
) || !damage
)
7743 basepoints
[0] = triggerAmount
* damage
/ 100;
7744 trigger_spell_id
= 50475;
7752 // All ok. Check current trigger spell
7753 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
7756 // Not cast unknown spell
7757 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
7761 // not allow proc extra attack spell at extra attack
7762 if (m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
))
7765 // Custom basepoints/target for exist spell
7766 // dummy basepoints or other customs
7767 switch(trigger_spell_id
)
7769 // Cast positive spell on enemy target
7770 case 7099: // Curse of Mending
7771 case 39647: // Curse of Mending
7772 case 29494: // Temptation
7773 case 20233: // Improved Lay on Hands (cast on target)
7778 // Combo points add triggers (need add combopoint only for main target, and after possible combopoints reset)
7779 case 15250: // Rogue Setup
7781 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
7783 break; // continue normal case
7785 // Finish movies that add combo
7786 case 14189: // Seal Fate (Netherblade set)
7787 case 14157: // Ruthlessness
7789 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
7792 // Bloodthirst (($m/100)% of max health)
7795 basepoints
[0] = int32(GetMaxHealth() * triggerAmount
/ 100);
7798 // Shamanistic Rage triggered spell
7801 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7804 // Enlightenment (trigger only from mana cost spells)
7807 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
7814 // As the spell is proced from pet's attack - find owner
7815 Unit
* owner
= GetOwner();
7816 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
7819 // This spell doesn't stack, but refreshes duration. So we receive current bonuses to minus them later.
7821 if (Aura
* aur
= owner
->GetAura(48090, EFFECT_INDEX_0
))
7822 curBonus
= aur
->GetModifier()->m_amount
;
7823 int32 spellDamage
= owner
->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_MAGIC
) - curBonus
;
7824 if(spellDamage
<= 0)
7827 // percent stored in owner talent dummy
7828 AuraList
const& dummyAuras
= owner
->GetAurasByType(SPELL_AURA_DUMMY
);
7829 for (AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
7831 if ((*i
)->GetSpellProto()->SpellIconID
== 3220)
7833 basepoints
[0] = basepoints
[1] = int32(spellDamage
* (*i
)->GetModifier()->m_amount
/ 100);
7842 // Remove cooldown on Shield Slam
7843 if (GetTypeId() == TYPEID_PLAYER
)
7844 ((Player
*)this)->RemoveSpellCategoryCooldown(1209, true);
7850 // have rank dependent proc chance, ignore too often cases
7851 // PPM = 2.5 * (rank of talent),
7852 uint32 rank
= sSpellMgr
.GetSpellRank(auraSpellInfo
->Id
);
7853 // 5 rank -> 100% 4 rank -> 80% and etc from full rate
7854 if(!roll_chance_i(20*rank
))
7863 // For trigger from Blizzard need exist Improved Blizzard
7864 if (procSpell
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)))
7867 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7868 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7870 int32 script
= (*i
)->GetModifier()->m_miscvalue
;
7871 if(script
==836 || script
==988 || script
==989)
7885 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7888 // Need stun, fear or silence mechanic
7889 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_SILENCE_AND_STUN_AND_FEAR_MASK
))
7893 // Burning Determination
7898 // Need Interrupt or Silenced mechanic
7899 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_INTERRUPT_AND_SILENCE_MASK
))
7906 // Proc only from trap activation (from periodic proc another aura of this spell)
7907 if (!(procFlags
& PROC_FLAG_ON_TRAP_ACTIVATION
) || !roll_chance_i(triggerAmount
))
7911 // Freezing Fog (Rime triggered)
7914 // Howling Blast cooldown reset
7915 if (GetTypeId() == TYPEID_PLAYER
)
7916 ((Player
*)this)->RemoveSpellCategoryCooldown(1248, true);
7919 // Druid - Savage Defense
7922 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7927 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
7930 // try detect target manually if not set
7932 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
7935 if (!target
|| target
!=this && !target
->isAlive())
7938 if (basepoints
[EFFECT_INDEX_0
] || basepoints
[EFFECT_INDEX_1
] || basepoints
[EFFECT_INDEX_2
])
7939 CastCustomSpell(target
,trigger_spell_id
,
7940 basepoints
[EFFECT_INDEX_0
] ? &basepoints
[EFFECT_INDEX_0
] : NULL
,
7941 basepoints
[EFFECT_INDEX_1
] ? &basepoints
[EFFECT_INDEX_1
] : NULL
,
7942 basepoints
[EFFECT_INDEX_2
] ? &basepoints
[EFFECT_INDEX_2
] : NULL
,
7943 true, castItem
, triggeredByAura
);
7945 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
7947 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7948 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
7953 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
7955 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
7957 if(!pVictim
|| !pVictim
->isAlive())
7960 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7961 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7963 // Basepoints of trigger aura
7964 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7966 uint32 triggered_spell_id
= 0;
7970 case 836: // Improved Blizzard (Rank 1)
7972 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7974 triggered_spell_id
= 12484;
7977 case 988: // Improved Blizzard (Rank 2)
7979 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7981 triggered_spell_id
= 12485;
7984 case 989: // Improved Blizzard (Rank 3)
7986 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7988 triggered_spell_id
= 12486;
7991 case 4086: // Improved Mend Pet (Rank 1)
7992 case 4087: // Improved Mend Pet (Rank 2)
7994 if(!roll_chance_i(triggerAmount
))
7997 triggered_spell_id
= 24406;
8000 case 4533: // Dreamwalker Raiment 2 pieces bonus
8003 if (!roll_chance_i(50))
8006 switch (pVictim
->getPowerType())
8008 case POWER_MANA
: triggered_spell_id
= 28722; break;
8009 case POWER_RAGE
: triggered_spell_id
= 28723; break;
8010 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
8016 case 4537: // Dreamwalker Raiment 6 pieces bonus
8017 triggered_spell_id
= 28750; // Blessing of the Claw
8019 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
8020 triggered_spell_id
= 37445; // Mana Surge
8022 case 6953: // Warbringer
8023 RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK
,0,true);
8025 case 7010: // Revitalize (rank 1)
8026 case 7011: // Revitalize (rank 2)
8027 case 7012: // Revitalize (rank 3)
8029 if(!roll_chance_i(triggerAmount
))
8032 switch( pVictim
->getPowerType() )
8034 case POWER_MANA
: triggered_spell_id
= 48542; break;
8035 case POWER_RAGE
: triggered_spell_id
= 48541; break;
8036 case POWER_ENERGY
: triggered_spell_id
= 48540; break;
8037 case POWER_RUNIC_POWER
: triggered_spell_id
= 48543; break;
8038 default: return false;
8045 if(!triggered_spell_id
)
8048 // standard non-dummy case
8049 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
8053 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
8057 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
8060 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
8062 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
8063 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
8068 void Unit::setPowerType(Powers new_powertype
)
8070 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
8072 if(GetTypeId() == TYPEID_PLAYER
)
8074 if(((Player
*)this)->GetGroup())
8075 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
8077 else if(((Creature
*)this)->isPet())
8079 Pet
*pet
= ((Pet
*)this);
8080 if(pet
->isControlled())
8082 Unit
*owner
= GetOwner();
8083 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
8084 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
8088 switch(new_powertype
)
8094 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
8095 SetPower( POWER_RAGE
,0);
8098 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
8099 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
8102 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
8104 case POWER_HAPPINESS
:
8105 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
8106 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
8111 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
8113 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
8116 static uint64 guid
= 0; // prevent repeating spam same faction problem
8118 if(GetGUID() != guid
)
8120 if(GetTypeId() == TYPEID_PLAYER
)
8121 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
8123 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
8130 bool Unit::IsHostileTo(Unit
const* unit
) const
8132 // always non-hostile to self
8136 // always non-hostile to GM in GM mode
8137 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
8140 // always hostile to enemy
8141 if(getVictim()==unit
|| unit
->getVictim()==this)
8144 // test pet/charm masters instead pers/charmeds
8145 Unit
const* testerOwner
= GetCharmerOrOwner();
8146 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
8148 // always hostile to owner's enemy
8149 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
8152 // always hostile to enemy owner
8153 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
8156 // always hostile to owner of owner's enemy
8157 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
8160 Unit
const* tester
= testerOwner
? testerOwner
: this;
8161 Unit
const* target
= targetOwner
? targetOwner
: unit
;
8163 // always non-hostile to target with common owner, or to owner/pet
8167 // special cases (Duel, etc)
8168 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
8170 Player
const* pTester
= (Player
const*)tester
;
8171 Player
const* pTarget
= (Player
const*)target
;
8174 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
8178 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
8182 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
8186 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
8190 // Green/Blue (can't attack)
8191 if(pTester
->GetTeam()==pTarget
->GetTeam())
8194 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
8195 return pTester
->IsPvP() && pTarget
->IsPvP();
8198 // faction base cases
8199 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8200 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8201 if(!tester_faction
|| !target_faction
)
8204 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8207 // PvC forced reaction and reputation case
8208 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8211 if(target_faction
->faction
)
8213 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8214 return *force
<= REP_HOSTILE
;
8216 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
8217 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8218 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8219 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8222 // CvP forced reaction and reputation case
8223 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8226 if(tester_faction
->faction
)
8228 if(ReputationRank
const* force
= ((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8229 return *force
<= REP_HOSTILE
;
8231 // apply reputation state
8232 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
8233 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
8234 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) <= REP_HOSTILE
;
8238 // common faction based case (CvC,PvC,CvP)
8239 return tester_faction
->IsHostileTo(*target_faction
);
8242 bool Unit::IsFriendlyTo(Unit
const* unit
) const
8244 // always friendly to self
8248 // always friendly to GM in GM mode
8249 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
8252 // always non-friendly to enemy
8253 if(getVictim()==unit
|| unit
->getVictim()==this)
8256 // test pet/charm masters instead pers/charmeds
8257 Unit
const* testerOwner
= GetCharmerOrOwner();
8258 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
8260 // always non-friendly to owner's enemy
8261 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
8264 // always non-friendly to enemy owner
8265 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
8268 // always non-friendly to owner of owner's enemy
8269 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
8272 Unit
const* tester
= testerOwner
? testerOwner
: this;
8273 Unit
const* target
= targetOwner
? targetOwner
: unit
;
8275 // always friendly to target with common owner, or to owner/pet
8279 // special cases (Duel)
8280 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
8282 Player
const* pTester
= (Player
const*)tester
;
8283 Player
const* pTarget
= (Player
const*)target
;
8286 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
8290 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
8294 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
8298 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
8302 // Green/Blue (non-attackable)
8303 if(pTester
->GetTeam()==pTarget
->GetTeam())
8306 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
8307 return !pTarget
->IsPvP();
8310 // faction base cases
8311 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8312 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8313 if(!tester_faction
|| !target_faction
)
8316 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8319 // PvC forced reaction and reputation case
8320 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8323 if(target_faction
->faction
)
8325 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8326 return *force
>= REP_FRIENDLY
;
8328 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
8329 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8330 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8331 return !(factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8334 // CvP forced reaction and reputation case
8335 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8338 if(tester_faction
->faction
)
8340 if(ReputationRank
const* force
=((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8341 return *force
>= REP_FRIENDLY
;
8343 // apply reputation state
8344 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
8345 if(raw_tester_faction
->reputationListID
>=0 )
8346 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) >= REP_FRIENDLY
;
8350 // common faction based case (CvC,PvC,CvP)
8351 return tester_faction
->IsFriendlyTo(*target_faction
);
8354 bool Unit::IsHostileToPlayers() const
8356 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8357 if(!my_faction
|| !my_faction
->faction
)
8360 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8361 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8364 return my_faction
->IsHostileToPlayers();
8367 bool Unit::IsNeutralToAll() const
8369 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8370 if(!my_faction
|| !my_faction
->faction
)
8373 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8374 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8377 return my_faction
->IsNeutralToAll();
8380 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
8382 if(!victim
|| victim
== this)
8385 // dead units can neither attack nor be attacked
8386 if(!isAlive() || !victim
->IsInWorld() || !victim
->isAlive())
8389 // player cannot attack in mount state
8390 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
8393 // nobody can attack GM in GM-mode
8394 if(victim
->GetTypeId()==TYPEID_PLAYER
)
8396 if(((Player
*)victim
)->isGameMaster())
8401 if(((Creature
*)victim
)->IsInEvadeMode())
8405 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
8406 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
8407 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
8409 // in fighting already
8412 if (m_attacking
== victim
)
8414 // switch to melee attack from ranged/magic
8415 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
8417 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8418 SendMeleeAttackStart(victim
);
8424 // remove old target data
8430 // set position before any AI calls/assistance
8431 if(GetTypeId()==TYPEID_UNIT
)
8432 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
8436 SetTargetGUID(victim
->GetGUID());
8439 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8441 m_attacking
= victim
;
8442 m_attacking
->_addAttacker(this);
8444 if (GetTypeId() == TYPEID_UNIT
)
8446 ((Creature
*)this)->SendAIReaction(AI_REACTION_HOSTILE
);
8447 ((Creature
*)this)->CallAssistance();
8450 // delay offhand weapon attack to next attack time
8451 if(haveOffhandWeapon())
8452 resetAttackTimer(OFF_ATTACK
);
8455 SendMeleeAttackStart(victim
);
8460 bool Unit::AttackStop(bool targetSwitch
/*=false*/)
8465 Unit
* victim
= m_attacking
;
8467 m_attacking
->_removeAttacker(this);
8473 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
8475 InterruptSpell(CURRENT_MELEE_SPELL
);
8477 // reset only at real combat stop
8478 if(!targetSwitch
&& GetTypeId()==TYPEID_UNIT
)
8480 ((Creature
*)this)->SetNoCallAssistance(false);
8482 if (((Creature
*)this)->HasSearchedAssistance())
8484 ((Creature
*)this)->SetNoSearchAssistance(false);
8485 UpdateSpeed(MOVE_RUN
, false);
8489 SendMeleeAttackStop(victim
);
8494 void Unit::CombatStop(bool includingCast
)
8496 if (includingCast
&& IsNonMeleeSpellCasted(false))
8497 InterruptNonMeleeSpells(false);
8500 RemoveAllAttackers();
8501 if( GetTypeId()==TYPEID_PLAYER
)
8502 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
8506 struct CombatStopWithPetsHelper
8508 explicit CombatStopWithPetsHelper(bool _includingCast
) : includingCast(_includingCast
) {}
8509 void operator()(Unit
* unit
) const { unit
->CombatStop(includingCast
); }
8513 void Unit::CombatStopWithPets(bool includingCast
)
8515 CombatStop(includingCast
);
8516 CallForAllControlledUnits(CombatStopWithPetsHelper(includingCast
),false,true,true);
8519 struct IsAttackingPlayerHelper
8521 explicit IsAttackingPlayerHelper() {}
8522 bool operator()(Unit
* unit
) const { return unit
->isAttackingPlayer(); }
8525 bool Unit::isAttackingPlayer() const
8527 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
8530 return CheckAllControlledUnits(IsAttackingPlayerHelper(),true,true,true);
8533 void Unit::RemoveAllAttackers()
8535 while (!m_attackers
.empty())
8537 AttackerSet::iterator iter
= m_attackers
.begin();
8538 if(!(*iter
)->AttackStop())
8540 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
8541 m_attackers
.erase(iter
);
8546 bool Unit::HasAuraStateForCaster(AuraState flag
, uint64 caster
) const
8548 if(!HasAuraState(flag
))
8551 // single per-caster aura state
8552 if(flag
== AURA_STATE_CONFLAGRATE
)
8554 Unit::AuraList
const& dotList
= GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
8555 for(Unit::AuraList::const_iterator i
= dotList
.begin(); i
!= dotList
.end(); ++i
)
8557 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
8558 (*i
)->GetCasterGUID() == caster
&&
8560 (((*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000004)) ||
8562 ((*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x00000002)))
8574 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
8578 if (!HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)))
8580 SetFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8581 if(GetTypeId() == TYPEID_PLAYER
)
8583 const PlayerSpellMap
& sp_list
= ((Player
*)this)->GetSpellMap();
8584 for (PlayerSpellMap::const_iterator itr
= sp_list
.begin(); itr
!= sp_list
.end(); ++itr
)
8586 if(itr
->second
.state
== PLAYERSPELL_REMOVED
) continue;
8587 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
8588 if (!spellInfo
|| !IsPassiveSpell(itr
->first
)) continue;
8589 if (spellInfo
->CasterAuraState
== flag
)
8590 CastSpell(this, itr
->first
, true, NULL
);
8597 if (HasFlag(UNIT_FIELD_AURASTATE
,1<<(flag
-1)))
8599 RemoveFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8601 if (flag
!= AURA_STATE_ENRAGE
) // enrage aura state triggering continues auras
8603 Unit::AuraMap
& tAuras
= GetAuras();
8604 for (Unit::AuraMap::iterator itr
= tAuras
.begin(); itr
!= tAuras
.end();)
8606 SpellEntry
const* spellProto
= (*itr
).second
->GetSpellProto();
8607 if (spellProto
->CasterAuraState
== flag
)
8617 Unit
*Unit::GetOwner() const
8619 if(uint64 ownerid
= GetOwnerGUID())
8620 return ObjectAccessor::GetUnit(*this, ownerid
);
8624 Unit
*Unit::GetCharmer() const
8626 if(uint64 charmerid
= GetCharmerGUID())
8627 return ObjectAccessor::GetUnit(*this, charmerid
);
8631 bool Unit::IsCharmerOrOwnerPlayerOrPlayerItself() const
8633 if (GetTypeId()==TYPEID_PLAYER
)
8636 return IS_PLAYER_GUID(GetCharmerOrOwnerGUID());
8639 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
8641 uint64 guid
= GetCharmerOrOwnerGUID();
8642 if(IS_PLAYER_GUID(guid
))
8643 return ObjectAccessor::FindPlayer(guid
);
8645 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
8648 Pet
* Unit::GetPet() const
8650 if(uint64 pet_guid
= GetPetGUID())
8652 if(Pet
* pet
= GetMap()->GetPet(pet_guid
))
8655 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
8656 const_cast<Unit
*>(this)->SetPet(0);
8662 Unit
* Unit::GetCharm() const
8664 if (uint64 charm_guid
= GetCharmGUID())
8666 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
8669 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
8670 const_cast<Unit
*>(this)->SetCharm(NULL
);
8676 void Unit::Uncharm()
8678 if (Unit
* charm
= GetCharm())
8680 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM
);
8681 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS
);
8685 float Unit::GetCombatDistance( const Unit
* target
) const
8687 float radius
= target
->GetFloatValue(UNIT_FIELD_COMBATREACH
) + GetFloatValue(UNIT_FIELD_COMBATREACH
);
8688 float dx
= GetPositionX() - target
->GetPositionX();
8689 float dy
= GetPositionY() - target
->GetPositionY();
8690 float dz
= GetPositionZ() - target
->GetPositionZ();
8691 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - radius
;
8692 return ( dist
> 0 ? dist
: 0);
8695 void Unit::SetPet(Pet
* pet
)
8697 SetPetGUID(pet
? pet
->GetGUID() : 0);
8699 if(pet
&& GetTypeId() == TYPEID_PLAYER
)
8700 ((Player
*)this)->SendPetGUIDs();
8703 void Unit::SetCharm(Unit
* pet
)
8705 SetCharmGUID(pet
? pet
->GetGUID() : 0);
8708 void Unit::AddGuardian( Pet
* pet
)
8710 m_guardianPets
.insert(pet
->GetGUID());
8713 void Unit::RemoveGuardian( Pet
* pet
)
8715 m_guardianPets
.erase(pet
->GetGUID());
8718 void Unit::RemoveGuardians()
8720 while(!m_guardianPets
.empty())
8722 uint64 guid
= *m_guardianPets
.begin();
8723 if(Pet
* pet
= GetMap()->GetPet(guid
))
8724 pet
->Remove(PET_SAVE_AS_DELETED
);
8726 m_guardianPets
.erase(guid
);
8730 Pet
* Unit::FindGuardianWithEntry(uint32 entry
)
8732 // pet guid middle part is entry (and creature also)
8733 // and in guardian list must be guardians with same entry _always_
8734 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
8735 if(Pet
* pet
= GetMap()->GetPet(*itr
))
8736 if (pet
->GetEntry() == entry
)
8742 Unit
* Unit::_GetTotem(TotemSlot slot
) const
8744 return GetTotem(slot
);
8747 Totem
* Unit::GetTotem(TotemSlot slot
) const
8749 if(slot
>= MAX_TOTEM_SLOT
|| !IsInWorld())
8752 Creature
*totem
= GetMap()->GetCreature(m_TotemSlot
[slot
]);
8753 return totem
&& totem
->isTotem() ? (Totem
*)totem
: NULL
;
8756 bool Unit::IsAllTotemSlotsUsed() const
8758 for (int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8759 if (!m_TotemSlot
[i
])
8764 void Unit::_AddTotem(TotemSlot slot
, Totem
* totem
)
8766 m_TotemSlot
[slot
] = totem
->GetGUID();
8769 void Unit::_RemoveTotem(Totem
* totem
)
8771 for(int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8773 if (m_TotemSlot
[i
] == totem
->GetGUID())
8783 void Unit::UnsummonAllTotems()
8785 for (int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
8786 if (Totem
* totem
= GetTotem(TotemSlot(i
)))
8790 int32
Unit::DealHeal(Unit
*pVictim
, uint32 addhealth
, SpellEntry
const *spellProto
, bool critical
)
8792 int32 gain
= pVictim
->ModifyHealth(int32(addhealth
));
8796 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8799 if (unit
->GetTypeId()==TYPEID_PLAYER
)
8801 // overheal = addhealth - gain
8802 unit
->SendHealSpellLog(pVictim
, spellProto
->Id
, addhealth
, addhealth
- gain
, critical
);
8804 if (BattleGround
*bg
= ((Player
*)unit
)->GetBattleGround())
8805 bg
->UpdatePlayerScore((Player
*)unit
, SCORE_HEALING_DONE
, gain
);
8807 // use the actual gain, as the overheal shall not be counted, skip gain 0 (it ignored anyway in to criteria)
8809 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE
, gain
, 0, pVictim
);
8811 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED
, addhealth
);
8814 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
8816 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED
, gain
);
8817 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED
, addhealth
);
8823 Unit
* Unit::SelectMagnetTarget(Unit
*victim
, SpellEntry
const *spellInfo
)
8829 if(spellInfo
&& (spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
|| spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
))
8831 Unit::AuraList
const& magnetAuras
= victim
->GetAurasByType(SPELL_AURA_SPELL_MAGNET
);
8832 for(Unit::AuraList::const_iterator itr
= magnetAuras
.begin(); itr
!= magnetAuras
.end(); ++itr
)
8833 if(Unit
* magnet
= (*itr
)->GetCaster())
8834 if(magnet
->IsWithinLOSInMap(this) && magnet
->isAlive())
8837 // Melee && ranged case
8840 AuraList
const& hitTriggerAuras
= victim
->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER
);
8841 for(AuraList::const_iterator i
= hitTriggerAuras
.begin(); i
!= hitTriggerAuras
.end(); ++i
)
8842 if(Unit
* magnet
= (*i
)->GetCaster())
8843 if(magnet
->isAlive() && magnet
->IsWithinLOSInMap(this))
8844 if(roll_chance_i((*i
)->GetModifier()->m_amount
))
8851 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, uint32 OverHeal
, bool critical
)
8854 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
8855 data
<< pVictim
->GetPackGUID();
8856 data
<< GetPackGUID();
8857 data
<< uint32(SpellID
);
8858 data
<< uint32(Damage
);
8859 data
<< uint32(OverHeal
);
8860 data
<< uint8(critical
? 1 : 0);
8861 data
<< uint8(0); // unused in client?
8862 SendMessageToSet(&data
, true);
8865 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8867 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
8868 data
<< pVictim
->GetPackGUID();
8869 data
<< GetPackGUID();
8870 data
<< uint32(SpellID
);
8871 data
<< uint32(powertype
);
8872 data
<< uint32(Damage
);
8873 SendMessageToSet(&data
, true);
8876 void Unit::EnergizeBySpell(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8878 SendEnergizeSpellLog(pVictim
, SpellID
, Damage
, powertype
);
8879 // needs to be called after sending spell log
8880 pVictim
->ModifyPower(powertype
, Damage
);
8884 * Calculates caster part of spell damage bonuses,
8885 * also includes different bonuses dependent from target auras
8887 uint32
Unit::SpellDamageBonusDone(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
8889 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
8892 // For totems get damage bonus from owner (statue isn't totem in fact)
8893 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8895 if(Unit
* owner
= GetOwner())
8896 return owner
->SpellDamageBonusDone(pVictim
, spellProto
, pdamage
, damagetype
);
8899 float DoneTotalMod
= 1.0f
;
8900 int32 DoneTotal
= 0;
8903 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
8904 DoneTotalMod
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
8906 if (!(spellProto
->AttributesEx6
& SPELL_ATTR_EX6_NO_DMG_PERCENT_MODS
))
8908 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
8909 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
8911 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
8912 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
8913 // -1 == any item class (not wand then)
8914 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
8915 // 0 == any inventory type (not wand then)
8917 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8922 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8923 // Add flat bonus from spell damage versus
8924 DoneTotal
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
8925 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
8926 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
8927 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8928 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8930 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
8931 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
8933 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8934 DoneTotalMod
+= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8937 // done scripted mod (take it from owner)
8938 Unit
*owner
= GetOwner();
8939 if (!owner
) owner
= this;
8940 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8941 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
8943 if (!(*i
)->isAffectedOnSpell(spellProto
))
8945 switch((*i
)->GetModifier()->m_miscvalue
)
8947 case 4920: // Molten Fury
8949 case 6917: // Death's Embrace
8953 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8954 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8961 // effect 1 m_amount
8962 int32 maxPercent
= (*i
)->GetModifier()->m_amount
;
8963 // effect 0 m_amount
8964 int32 stepPercent
= CalculateSpellDamage(this, (*i
)->GetSpellProto(), EFFECT_INDEX_0
);
8965 // count affliction effects and calc additional damage in percentage
8966 int32 modPercent
= 0;
8967 AuraMap
const& victimAuras
= pVictim
->GetAuras();
8968 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
8970 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
8971 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_WARLOCK
|| !(m_spell
->SpellFamilyFlags
& UI64LIT(0x0004071B8044C402)))
8973 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
8974 if (modPercent
>= maxPercent
)
8976 modPercent
= maxPercent
;
8980 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
8983 case 6916: // Death's Embrace
8986 if (HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
))
8987 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8989 case 5481: // Starfire Bonus
8991 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000200002)))
8992 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8995 case 4418: // Increased Shock Damage
8996 case 4554: // Increased Lightning Damage
8997 case 4555: // Improved Moonfire
8998 case 5142: // Increased Lightning Damage
8999 case 5147: // Improved Consecration / Libram of Resurgence
9000 case 5148: // Idol of the Shooting Star
9001 case 6008: // Increased Lightning Damage
9002 case 8627: // Totem of Hex
9004 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
9012 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
9014 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9015 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
9017 else // Tundra Stalker
9019 // Frost Fever (target debuff)
9020 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
9021 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9026 case 7293: // Rage of Rivendare
9028 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
9029 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9035 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000000000008000), 0, GetGUID()))
9036 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9046 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
9047 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9053 // Custom scripted damage
9054 switch(spellProto
->SpellFamilyName
)
9056 case SPELLFAMILY_MAGE
:
9059 if (spellProto
->SpellIconID
== 186)
9061 if (pVictim
->isFrozen())
9063 float multiplier
= 3.0f
;
9065 // if target have higher level
9066 if (pVictim
->getLevel() > getLevel())
9067 // Glyph of Ice Lance
9068 if (Aura
* glyph
= GetDummyAura(56377))
9069 multiplier
= glyph
->GetModifier()->m_amount
;
9071 DoneTotalMod
*= multiplier
;
9074 // Torment the weak affected (Arcane Barrage, Arcane Blast, Frostfire Bolt, Arcane Missiles, Fireball)
9075 if ((spellProto
->SpellFamilyFlags
& UI64LIT(0x0000900020200021)) &&
9076 (pVictim
->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED
) || pVictim
->HasAuraType(SPELL_AURA_HASTE_ALL
)))
9078 //Search for Torment the weak dummy aura
9079 Unit::AuraList
const& ttw
= GetAurasByType(SPELL_AURA_DUMMY
);
9080 for(Unit::AuraList::const_iterator i
= ttw
.begin(); i
!= ttw
.end(); ++i
)
9082 if ((*i
)->GetSpellProto()->SpellIconID
== 3263)
9084 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9091 case SPELLFAMILY_WARLOCK
:
9094 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
9096 if (pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth() <= 25)
9101 case SPELLFAMILY_PRIEST
:
9104 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x00000080))
9107 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x00100000), NULL
))
9108 if (Aura
*aur
= GetAura(55692, EFFECT_INDEX_0
))
9109 DoneTotalMod
*= (aur
->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9113 case SPELLFAMILY_DRUID
:
9115 // Improved Insect Swarm (Wrath part)
9116 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
9118 // if Insect Swarm on target
9119 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x000000000200000), 0, GetGUID()))
9121 Unit::AuraList
const& improvedSwarm
= GetAurasByType(SPELL_AURA_DUMMY
);
9122 for(Unit::AuraList::const_iterator iter
= improvedSwarm
.begin(); iter
!= improvedSwarm
.end(); ++iter
)
9124 if ((*iter
)->GetSpellProto()->SpellIconID
== 1771)
9126 DoneTotalMod
*= ((*iter
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9134 case SPELLFAMILY_DEATHKNIGHT
:
9136 // Icy Touch and Howling Blast
9137 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000200000002))
9141 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
9142 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
9144 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
9153 // search for Glacier Rot dummy aura
9154 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9155 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
9157 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
9159 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9170 // Done fixed damage bonus auras
9171 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonusDone(GetSpellSchoolMask(spellProto
));
9173 // Pets just add their bonus damage to their spell damage
9174 // note that their spell damage is just gain of their own auras
9175 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9176 DoneAdvertisedBenefit
+= ((Pet
*)this)->GetBonusDamage();
9178 if (DoneAdvertisedBenefit
)
9180 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9182 // Distribute Damage over multiple effects, reduce by AoE
9185 // Not apply this to creature casted spells
9186 if (GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
9188 // Check for table values
9189 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9191 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
9193 if (bonus
->ap_bonus
)
9194 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
));
9196 // Default calculation
9198 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
);
9200 // Spellmod SpellDamage
9201 if(Player
* modOwner
= GetSpellModOwner())
9204 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
, coeff
);
9208 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* LvlPenalty
);
9211 float tmpDamage
= (int32(pdamage
) + DoneTotal
* int32(stack
)) * DoneTotalMod
;
9212 // apply spellmod to Done damage (flat and pct)
9213 if(Player
* modOwner
= GetSpellModOwner())
9214 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
9216 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9220 * Calculates target part of spell damage bonuses,
9221 * will be called on each tick for periodic damage over time auras
9223 uint32
Unit::SpellDamageBonusTaken(Unit
*pCaster
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
9225 if(!spellProto
|| !pCaster
|| damagetype
==DIRECT_DAMAGE
)
9228 // Taken total percent damage auras
9229 float TakenTotalMod
= 1.0f
;
9230 int32 TakenTotal
= 0;
9233 AuraList
const& mModDamagePercentTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
9234 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
9236 if ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
))
9237 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9240 // .. taken pct: dummy auras
9241 if (GetTypeId() == TYPEID_PLAYER
)
9244 if (Aura
*dummy
= GetDummyAura(45182))
9246 float mod
= -((Player
*)this)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
9247 if (mod
< float(dummy
->GetModifier()->m_amount
))
9248 mod
= float(dummy
->GetModifier()->m_amount
);
9249 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
9253 // From caster spells
9254 AuraList
const& mOwnerTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_FROM_CASTER
);
9255 for(AuraList::const_iterator i
= mOwnerTaken
.begin(); i
!= mOwnerTaken
.end(); ++i
)
9257 if ((*i
)->GetCasterGUID() == pCaster
->GetGUID() && (*i
)->isAffectedOnSpell(spellProto
))
9258 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9261 // Mod damage from spell mechanic
9262 TakenTotalMod
*= GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,GetAllSpellMechanicMask(spellProto
));
9264 // Mod damage taken from AoE spells
9265 if(IsAreaOfEffectSpell(spellProto
))
9267 AuraList
const& avoidAuras
= GetAurasByType(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
9268 for(AuraList::const_iterator itr
= avoidAuras
.begin(); itr
!= avoidAuras
.end(); ++itr
)
9269 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9272 // Taken fixed damage bonus auras
9273 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusTaken(GetSpellSchoolMask(spellProto
));
9275 if (TakenAdvertisedBenefit
)
9277 float LvlPenalty
= pCaster
->CalculateLevelPenalty(spellProto
);
9279 // Distribute Damage over multiple effects, reduce by AoE
9282 // Not apply this to creature casted spells
9283 if (pCaster
->GetTypeId()==TYPEID_UNIT
&& !((Creature
*)pCaster
)->isPet())
9285 // Check for table values
9286 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9287 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
9288 // Default calculation
9290 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
);
9292 // Spellmod SpellDamage
9293 if(Player
* modOwner
= pCaster
->GetSpellModOwner())
9296 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
, coeff
);
9300 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
* LvlPenalty
);
9303 float tmpDamage
= (int32(pdamage
) + TakenTotal
* int32(stack
)) * TakenTotalMod
;
9305 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9308 int32
Unit::SpellBaseDamageBonusDone(SpellSchoolMask schoolMask
)
9310 int32 DoneAdvertisedBenefit
= 0;
9313 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9314 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
9316 if (((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
9317 (*i
)->GetSpellProto()->EquippedItemClass
== -1 && // -1 == any item class (not wand then)
9318 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0) // 0 == any inventory type (not wand then)
9319 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9322 if (GetTypeId() == TYPEID_PLAYER
)
9325 DoneAdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9327 // Damage bonus from stats
9328 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
9329 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
9331 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9333 // stat used stored in miscValueB for this aura
9334 Stats usedStat
= Stats((*i
)->GetMiscBValue());
9335 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9338 // ... and attack power
9339 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
9340 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
9342 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9343 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9347 return DoneAdvertisedBenefit
;
9350 int32
Unit::SpellBaseDamageBonusTaken(SpellSchoolMask schoolMask
)
9352 int32 TakenAdvertisedBenefit
= 0;
9355 AuraList
const& mDamageTaken
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
9356 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9358 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9359 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9362 return TakenAdvertisedBenefit
;
9365 bool Unit::IsSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
9367 // not critting spell
9368 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
9371 float crit_chance
= 0.0f
;
9372 switch(spellProto
->DmgClass
)
9374 case SPELL_DAMAGE_CLASS_NONE
:
9376 case SPELL_DAMAGE_CLASS_MAGIC
:
9378 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
9380 // For other schools
9381 else if (GetTypeId() == TYPEID_PLAYER
)
9382 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
9385 crit_chance
= float(m_baseSpellCritChance
);
9386 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9391 if (!IsPositiveSpell(spellProto
->Id
))
9393 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
9394 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
9395 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
9396 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
9397 // Modify by player victim resilience
9398 crit_chance
-= pVictim
->GetSpellCritChanceReduction();
9401 // scripted (increase crit chance ... against ... target by x%)
9402 // scripted (Increases the critical effect chance of your .... by x% on targets ...)
9403 AuraList
const& mOverrideClassScript
= 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 849: if (pVictim
->isFrozen()) crit_chance
+= 17.0f
; break; //Shatter Rank 1
9411 case 910: if (pVictim
->isFrozen()) crit_chance
+= 34.0f
; break; //Shatter Rank 2
9412 case 911: if (pVictim
->isFrozen()) crit_chance
+= 50.0f
; break; //Shatter Rank 3
9413 case 7917: // Glyph of Shadowburn
9414 if (pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9415 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9417 case 7997: // Renewed Hope
9419 if (pVictim
->HasAura(6788))
9420 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9426 // Custom crit by class
9427 switch(spellProto
->SpellFamilyName
)
9429 case SPELLFAMILY_PRIEST
:
9431 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000800))
9433 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth()/2)
9435 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9436 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9438 // Improved Flash Heal
9439 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_PRIEST
&&
9440 (*i
)->GetSpellProto()->SpellIconID
== 2542)
9442 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9448 case SPELLFAMILY_DRUID
:
9449 // Improved Insect Swarm (Starfire part)
9450 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
9452 // search for Moonfire on target
9453 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x000000000000002), 0, GetGUID()))
9455 Unit::AuraList
const& improvedSwarm
= GetAurasByType(SPELL_AURA_DUMMY
);
9456 for(Unit::AuraList::const_iterator iter
= improvedSwarm
.begin(); iter
!= improvedSwarm
.end(); ++iter
)
9458 if ((*iter
)->GetSpellProto()->SpellIconID
== 1771)
9460 crit_chance
+= (*iter
)->GetModifier()->m_amount
;
9467 case SPELLFAMILY_PALADIN
:
9469 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000040000000))
9471 Aura
*aura
= pVictim
->GetDummyAura(58597);
9472 if (aura
&& aura
->GetCasterGUID() == GetGUID())
9473 crit_chance
+=aura
->GetModifier()->m_amount
;
9476 else if (spellProto
->Category
== 19)
9478 if (pVictim
->GetCreatureTypeMask() & CREATURE_TYPEMASK_DEMON_OR_UNDEAD
)
9482 case SPELLFAMILY_SHAMAN
:
9484 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000100000000000))
9487 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000000010000000), 0, GetGUID()))
9495 case SPELL_DAMAGE_CLASS_MELEE
:
9496 case SPELL_DAMAGE_CLASS_RANGED
:
9499 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
9501 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9508 // only players use intelligence for critical chance computations
9509 if(Player
* modOwner
= GetSpellModOwner())
9510 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
9512 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
9513 if (roll_chance_f(crit_chance
))
9518 uint32
Unit::SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9520 // Calculate critical bonus
9522 switch(spellProto
->DmgClass
)
9524 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9525 case SPELL_DAMAGE_CLASS_RANGED
:
9526 crit_bonus
= damage
;
9529 crit_bonus
= damage
/ 2; // for spells is 50%
9533 // adds additional damage to crit_bonus (from talents)
9534 if(Player
* modOwner
= GetSpellModOwner())
9535 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
9538 return damage
+= crit_bonus
;
9540 int32 critPctDamageMod
= 0;
9541 if(spellProto
->DmgClass
>= SPELL_DAMAGE_CLASS_MELEE
)
9543 if(GetWeaponAttackType(spellProto
) == RANGED_ATTACK
)
9544 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
9546 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
9549 critPctDamageMod
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_DAMAGE
,GetSpellSchoolMask(spellProto
));
9551 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, GetSpellSchoolMask(spellProto
));
9553 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9554 critPctDamageMod
+= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
);
9556 if(critPctDamageMod
!=0)
9557 crit_bonus
= int32(crit_bonus
* float((100.0f
+ critPctDamageMod
)/100.0f
));
9560 damage
+= crit_bonus
;
9565 uint32
Unit::SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9567 // Calculate critical bonus
9569 switch(spellProto
->DmgClass
)
9571 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9572 case SPELL_DAMAGE_CLASS_RANGED
:
9573 // TODO: write here full calculation for melee/ranged spells
9574 crit_bonus
= damage
;
9577 crit_bonus
= damage
/ 2; // for spells is 50%
9583 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9584 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
9588 damage
+= crit_bonus
;
9590 damage
= int32(damage
* GetTotalAuraMultiplier(SPELL_AURA_MOD_CRITICAL_HEALING_AMOUNT
));
9596 * Calculates caster part of healing spell bonuses,
9597 * also includes different bonuses dependent from target auras
9599 uint32
Unit::SpellHealingBonusDone(Unit
*pVictim
, SpellEntry
const *spellProto
, int32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9601 // For totems get healing bonus from owner (statue isn't totem in fact)
9602 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
9603 if(Unit
* owner
= GetOwner())
9604 return owner
->SpellHealingBonusDone(pVictim
, spellProto
, healamount
, damagetype
, stack
);
9606 // No heal amount for this class spells
9607 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9608 return healamount
< 0 ? 0 : healamount
;
9611 // Done total percent damage auras
9612 float DoneTotalMod
= 1.0f
;
9613 int32 DoneTotal
= 0;
9615 // Healing done percent
9616 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
9617 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
9618 DoneTotalMod
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
9620 // done scripted mod (take it from owner)
9621 Unit
*owner
= GetOwner();
9622 if (!owner
) owner
= this;
9623 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9624 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9626 if (!(*i
)->isAffectedOnSpell(spellProto
))
9628 switch((*i
)->GetModifier()->m_miscvalue
)
9630 case 4415: // Increased Rejuvenation Healing
9632 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
9633 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
9635 case 7997: // Renewed Hope
9637 if (pVictim
->HasAura(6788))
9638 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9640 case 21: // Test of Faith
9643 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
9644 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9646 case 7798: // Glyph of Regrowth
9648 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_HEAL
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000000040)))
9649 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9652 case 8477: // Nourish Heal Boost
9654 int32 stepPercent
= (*i
)->GetModifier()->m_amount
;
9656 int ownHotCount
= 0; // counted HoT types amount, not stacks
9658 Unit::AuraList
const& RejorRegr
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_HEAL
);
9659 for(Unit::AuraList::const_iterator i
= RejorRegr
.begin(); i
!= RejorRegr
.end(); ++i
)
9660 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_DRUID
&&
9661 (*i
)->GetCasterGUID() == GetGUID())
9665 DoneTotalMod
*= (stepPercent
* ownHotCount
+ 100.0f
) / 100.0f
;
9668 case 7871: // Glyph of Lesser Healing Wave
9670 if (pVictim
->GetAura(SPELL_AURA_DUMMY
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000040000000000), 0, GetGUID()))
9671 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9679 // Nourish 20% of heal increase if target is affected by Druids HOTs
9680 if (spellProto
->SpellFamilyName
== SPELLFAMILY_DRUID
&& (spellProto
->SpellFamilyFlags
& UI64LIT(0x0200000000000000)))
9682 int ownHotCount
= 0; // counted HoT types amount, not stacks
9683 Unit::AuraList
const& RejorRegr
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_HEAL
);
9684 for(Unit::AuraList::const_iterator i
= RejorRegr
.begin(); i
!= RejorRegr
.end(); ++i
)
9685 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_DRUID
&&
9686 (*i
)->GetCasterGUID() == GetGUID())
9691 DoneTotalMod
*= 1.2f
; // base bonus at HoTs
9693 if (Aura
* glyph
= GetAura(62971, EFFECT_INDEX_0
))// Glyph of Nourish
9694 DoneTotalMod
*= (glyph
->GetModifier()->m_amount
* ownHotCount
+ 100.0f
) / 100.0f
;
9698 // Done fixed damage bonus auras
9699 int32 DoneAdvertisedBenefit
= SpellBaseHealingBonusDone(GetSpellSchoolMask(spellProto
));
9701 if (DoneAdvertisedBenefit
)
9703 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9705 // Distribute Damage over multiple effects, reduce by AoE
9708 // Not apply this to creature casted spells
9709 if (GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
9711 // Check for table values
9712 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9714 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
9716 if (bonus
->ap_bonus
)
9717 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
));
9719 // Default calculation
9721 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
) * 1.88f
;
9723 // Spellmod SpellDamage
9724 if(Player
* modOwner
= GetSpellModOwner())
9727 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
, coeff
);
9731 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* LvlPenalty
);
9734 // use float as more appropriate for negative values and percent applying
9735 float heal
= (healamount
+ DoneTotal
* int32(stack
))*DoneTotalMod
;
9736 // apply spellmod to Done amount
9737 if(Player
* modOwner
= GetSpellModOwner())
9738 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
9740 return heal
< 0 ? 0 : uint32(heal
);
9744 * Calculates target part of healing spell bonuses,
9745 * will be called on each tick for periodic damage over time auras
9747 uint32
Unit::SpellHealingBonusTaken(Unit
*pCaster
, SpellEntry
const *spellProto
, int32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9749 float TakenTotalMod
= 1.0f
;
9751 // Healing taken percent
9752 float minval
= float(GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
));
9754 TakenTotalMod
*= (100.0f
+ minval
) / 100.0f
;
9756 float maxval
= float(GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
));
9758 TakenTotalMod
*= (100.0f
+ maxval
) / 100.0f
;
9760 // No heal amount for this class spells
9761 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9763 healamount
= int32(healamount
* TakenTotalMod
);
9764 return healamount
< 0 ? 0 : healamount
;
9768 // Done total percent damage auras
9769 int32 TakenTotal
= 0;
9771 // Taken fixed damage bonus auras
9772 int32 TakenAdvertisedBenefit
= SpellBaseHealingBonusTaken(GetSpellSchoolMask(spellProto
));
9774 if (TakenAdvertisedBenefit
)
9776 float LvlPenalty
= pCaster
->CalculateLevelPenalty(spellProto
);
9778 // Distribute Damage over multiple effects, reduce by AoE
9781 // Not apply this to creature casted spells
9782 if (GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
9784 // Check for table values
9785 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9786 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
9787 // Default calculation
9789 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
) * 1.88f
;
9791 // Spellmod SpellDamage
9792 if(Player
* modOwner
= pCaster
->GetSpellModOwner())
9795 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
, coeff
);
9799 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
* LvlPenalty
);
9802 AuraList
const& mHealingGet
= GetAurasByType(SPELL_AURA_MOD_HEALING_RECEIVED
);
9803 for(AuraList::const_iterator i
= mHealingGet
.begin(); i
!= mHealingGet
.end(); ++i
)
9804 if ((*i
)->isAffectedOnSpell(spellProto
))
9805 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9807 // use float as more appropriate for negative values and percent applying
9808 float heal
= (healamount
+ TakenTotal
* int32(stack
)) * TakenTotalMod
;
9810 return heal
< 0 ? 0 : uint32(heal
);
9813 int32
Unit::SpellBaseHealingBonusDone(SpellSchoolMask schoolMask
)
9815 int32 AdvertisedBenefit
= 0;
9817 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
9818 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
9819 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9820 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9822 // Healing bonus of spirit, intellect and strength
9823 if (GetTypeId() == TYPEID_PLAYER
)
9826 AdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9828 // Healing bonus from stats
9829 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
9830 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
9832 // stat used dependent from misc value (stat index)
9833 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
9834 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9837 // ... and attack power
9838 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
9839 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
9840 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9841 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9843 return AdvertisedBenefit
;
9846 int32
Unit::SpellBaseHealingBonusTaken(SpellSchoolMask schoolMask
)
9848 int32 AdvertisedBenefit
= 0;
9849 AuraList
const& mDamageTaken
= GetAurasByType(SPELL_AURA_MOD_HEALING
);
9850 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9851 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9852 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9854 return AdvertisedBenefit
;
9857 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
)
9859 //If m_immuneToSchool type contain this school type, IMMUNE damage.
9860 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9861 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9862 if (itr
->type
& shoolMask
)
9865 //If m_immuneToDamage type contain magic, IMMUNE damage.
9866 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
9867 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
9868 if (itr
->type
& shoolMask
)
9874 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
)
9879 //TODO add spellEffect immunity checks!, player with flag in bg is imune to imunity buffs from other friendly players!
9880 //SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_EFFECT];
9882 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
9883 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
9884 if (itr
->type
== spellInfo
->Dispel
)
9887 if (!(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
) && // unaffected by school immunity
9888 !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)) // can remove immune (by dispell or immune it)
9890 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9891 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9892 if (!(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
9893 (itr
->type
& GetSpellSchoolMask(spellInfo
)))
9897 if(uint32 mechanic
= spellInfo
->Mechanic
)
9899 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9900 for(SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9901 if (itr
->type
== mechanic
)
9904 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9905 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9906 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9913 bool Unit::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, SpellEffectIndex index
) const
9915 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
9916 uint32 effect
= spellInfo
->Effect
[index
];
9917 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
9918 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
9919 if (itr
->type
== effect
)
9922 if(uint32 mechanic
= spellInfo
->EffectMechanic
[index
])
9924 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9925 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9926 if (itr
->type
== mechanic
)
9929 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9930 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9931 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9935 if(uint32 aura
= spellInfo
->EffectApplyAuraName
[index
])
9937 SpellImmuneList
const& list
= m_spellImmune
[IMMUNITY_STATE
];
9938 for(SpellImmuneList::const_iterator itr
= list
.begin(); itr
!= list
.end(); ++itr
)
9939 if (itr
->type
== aura
)
9942 // Check for immune to application of harmful magical effects
9943 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL
);
9944 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9945 if (spellInfo
->Dispel
== DISPEL_MAGIC
&& // Magic debuff
9946 ((*iter
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellInfo
)) && // Check school
9947 !IsPositiveEffect(spellInfo
->Id
, index
)) // Harmful
9954 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
9959 uint32 family
= spellInfo
->SpellFamilyName
;
9960 uint64 flags
= spellInfo
->SpellFamilyFlags
;
9962 if ((family
== 5 && flags
== 256) || //Searing Pain
9963 (family
== 6 && flags
== 8192) || //Mind Blast
9964 (family
== 11 && flags
== 1048576)) //Earth Shock
9971 * Calculates caster part of melee damage bonuses,
9972 * also includes different bonuses dependent from target auras
9974 uint32
Unit::MeleeDamageBonusDone(Unit
*pVictim
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
9982 // differentiate for weapon damage based spells
9983 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
9984 Item
* pWeapon
= GetTypeId() == TYPEID_PLAYER
? ((Player
*)this)->GetWeaponForAttack(attType
,true,false) : NULL
;
9985 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9986 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
9987 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
9989 // Shred also have bonus as MECHANIC_BLEED damages
9990 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
9991 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
9994 // FLAT damage bonus auras
9995 // =======================
9999 // ..done flat, already included in wepon damage based spells
10000 if (!isWeaponDamageBasedSpell
)
10002 AuraList
const& mModDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
10003 for(AuraList::const_iterator i
= mModDamageDone
.begin(); i
!= mModDamageDone
.end(); ++i
)
10005 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
10006 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
10007 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
10008 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
10010 DoneFlat
+= (*i
)->GetModifier()->m_amount
;
10014 // Pets just add their bonus damage to their melee damage
10015 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
10016 DoneFlat
+= ((Pet
*)this)->GetBonusDamage();
10019 // ..done flat (by creature type mask)
10020 DoneFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
, creatureTypeMask
);
10022 // ..done flat (base at attack power for marked target and base at attack power for creature type)
10023 if (attType
== RANGED_ATTACK
)
10025 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
10026 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
, creatureTypeMask
);
10030 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
10031 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
, creatureTypeMask
);
10034 // PERCENT damage auras
10035 // ====================
10036 float DonePercent
= 1.0f
;
10038 // ..done pct, already included in weapon damage based spells
10039 if(!isWeaponDamageBasedSpell
)
10041 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
10042 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
10044 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
10045 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
10046 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
10047 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
10049 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
10053 if (attType
== OFF_ATTACK
)
10054 DonePercent
*= GetModifierValue(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_PCT
); // no school check required
10057 // ..done pct (by creature type mask)
10058 DonePercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
, creatureTypeMask
);
10060 // special dummys/class sripts and other effects
10061 // =============================================
10062 Unit
*owner
= GetOwner();
10066 // ..done (class scripts)
10069 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
10070 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
10072 if (!(*i
)->isAffectedOnSpell(spellProto
))
10075 switch((*i
)->GetModifier()->m_miscvalue
)
10078 // Merciless Combat
10081 // Merciless Combat
10082 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
10084 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
10085 DonePercent
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
10087 else // Tundra Stalker
10089 // Frost Fever (target debuff)
10090 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
10091 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10096 case 7293: // Rage of Rivendare
10098 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
10099 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10102 // Marked for Death
10109 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
10110 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
10117 // .. done (class scripts)
10118 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
10119 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
10121 switch((*i
)->GetMiscValue())
10126 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
10128 Aura
* eff0
= GetAura((*i
)->GetId(), EFFECT_INDEX_0
);
10129 if (!eff0
|| (*i
)->GetEffIndex() != EFFECT_INDEX_1
)
10131 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
10135 // effect 0 have expected value but in negative state
10136 DonePercent
*= (-eff0
->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
10143 if (spellProto
&& spellProto
->SpellFamilyName
== SPELLFAMILY_DEATHKNIGHT
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000400000000))
10146 bool found
= false;
10147 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
10148 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
10150 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
10159 // search for Glacier Rot dummy aura
10160 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
10161 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
10163 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
10165 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
10173 // final calculation
10174 // =================
10176 float DoneTotal
= 0.0f
;
10178 // scaling of non weapon based spells
10179 if (!isWeaponDamageBasedSpell
)
10181 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
10183 // Distribute Damage over multiple effects, reduce by AoE
10184 float coeff
= 0.0f
;
10186 // Not apply this to creature casted spells
10187 if (GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
10189 // Check for table values
10190 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
10192 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
10194 if (bonus
->ap_bonus
)
10195 DoneTotal
+= bonus
->ap_bonus
* (GetTotalAttackPowerValue(BASE_ATTACK
) + APbonus
);
10197 // Default calculation
10199 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
);
10201 // Spellmod SpellDamage
10202 if(Player
* modOwner
= GetSpellModOwner())
10205 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
, coeff
);
10209 DoneTotal
+= DoneFlat
* coeff
* LvlPenalty
;
10211 // weapon damage based spells
10212 else if( APbonus
|| DoneFlat
)
10214 bool normalized
= spellProto
? IsSpellHaveEffect(spellProto
, SPELL_EFFECT_NORMALIZED_WEAPON_DMG
) : false;
10215 DoneTotal
+= int32(APbonus
/ 14.0f
* GetAPMultiplier(attType
,normalized
));
10217 // for weapon damage based spells we still have to apply damage done percent mods
10218 // (that are already included into pdamage) to not-yet included DoneFlat
10219 // e.g. from doneVersusCreature, apBonusVs...
10224 case BASE_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_MAINHAND
; break;
10225 case OFF_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_OFFHAND
; break;
10226 case RANGED_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_RANGED
; break;
10229 DoneTotal
+= DoneFlat
;
10231 DoneTotal
*= GetModifierValue(unitMod
, TOTAL_PCT
);
10234 float tmpDamage
= float(int32(pdamage
) + DoneTotal
* int32(stack
)) * DonePercent
;
10236 // apply spellmod to Done damage
10239 if(Player
* modOwner
= GetSpellModOwner())
10240 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
10243 // bonus result can be negative
10244 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
10248 * Calculates target part of melee damage bonuses,
10249 * will be called on each tick for periodic damage over time auras
10251 uint32
Unit::MeleeDamageBonusTaken(Unit
*pCaster
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
10259 // differentiate for weapon damage based spells
10260 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
10261 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
10262 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
10264 // Shred also have bonus as MECHANIC_BLEED damages
10265 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
10266 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
10269 // FLAT damage bonus auras
10270 // =======================
10271 int32 TakenFlat
= 0;
10273 // ..taken flat (base at attack power for marked target and base at attack power for creature type)
10274 if (attType
== RANGED_ATTACK
)
10275 TakenFlat
+= GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
10277 TakenFlat
+= GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
10279 // ..taken flat (by school mask)
10280 TakenFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_TAKEN
, schoolMask
);
10282 // PERCENT damage auras
10283 // ====================
10284 float TakenPercent
= 1.0f
;
10286 // ..taken pct (by school mask)
10287 TakenPercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
, schoolMask
);
10289 // ..taken pct (by mechanic mask)
10290 TakenPercent
*= GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,mechanicMask
);
10292 // ..taken pct (melee/ranged)
10293 if(attType
== RANGED_ATTACK
)
10294 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
10296 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
10298 // ..taken pct (aoe avoidance)
10299 if(spellProto
&& IsAreaOfEffectSpell(spellProto
))
10300 TakenPercent
*= GetTotalAuraMultiplier(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
10303 // special dummys/class scripts and other effects
10304 // =============================================
10306 // .. taken (dummy auras)
10307 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
10308 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
10310 switch((*i
)->GetSpellProto()->SpellIconID
)
10314 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
10316 if(GetTypeId() != TYPEID_PLAYER
)
10319 float mod
= ((Player
*)this)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
10320 if (mod
< float((*i
)->GetModifier()->m_amount
))
10321 mod
= float((*i
)->GetModifier()->m_amount
);
10323 TakenPercent
*= (mod
+ 100.0f
) / 100.0f
;
10329 // final calculation
10330 // =================
10332 // scaling of non weapon based spells
10333 if (!isWeaponDamageBasedSpell
)
10338 float LvlPenalty
= pCaster
->CalculateLevelPenalty(spellProto
);
10340 // Distribute Damage over multiple effects, reduce by AoE
10343 // Not apply this to creature casted spells
10344 if (pCaster
->GetTypeId()==TYPEID_UNIT
&& !((Creature
*)pCaster
)->isPet())
10346 // Check for table values
10347 else if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
10348 coeff
= damagetype
== DOT
? bonus
->dot_damage
: bonus
->direct_damage
;
10349 // Default calculation
10350 else if (TakenFlat
)
10351 coeff
= CalculateDefaultCoefficient(spellProto
, damagetype
);
10353 // Spellmod SpellDamage
10354 if(Player
* modOwner
= pCaster
->GetSpellModOwner())
10357 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
, coeff
);
10361 TakenFlat
*= coeff
* LvlPenalty
;
10365 float tmpDamage
= float(int32(pdamage
) + TakenFlat
* int32(stack
)) * TakenPercent
;
10367 // bonus result can be negative
10368 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
10371 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
10375 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
10377 next
= itr
; ++next
;
10378 if(itr
->type
== type
)
10380 m_spellImmune
[op
].erase(itr
);
10381 next
= m_spellImmune
[op
].begin();
10384 SpellImmune Immune
;
10385 Immune
.spellId
= spellId
;
10386 Immune
.type
= type
;
10387 m_spellImmune
[op
].push_back(Immune
);
10391 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
10393 if(itr
->spellId
== spellId
)
10395 m_spellImmune
[op
].erase(itr
);
10403 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
10405 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
10407 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
10408 RemoveAurasWithDispelType(type
);
10411 float Unit::GetWeaponProcChance() const
10413 // normalized proc chance for weapon attack speed
10414 // (odd formula...)
10415 if (isAttackReady(BASE_ATTACK
))
10416 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
10417 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
10418 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
10423 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
10425 // proc per minute chance calculation
10428 return WeaponSpeed
* PPM
/ 600.0f
; // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
10431 void Unit::Mount(uint32 mount
, uint32 spellId
)
10436 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
10438 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
10440 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
10442 if (GetTypeId() == TYPEID_PLAYER
)
10444 // Called by Taxi system / GM command
10446 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10447 // Called by mount aura
10448 else if (SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellId
))
10450 // Flying case (Unsummon any pet)
10451 if (IsSpellHaveAura(spellInfo
, SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED
))
10452 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10453 // Normal case (Unsummon only permanent pet)
10454 else if (Pet
* pet
= GetPet())
10456 if (pet
->IsPermanentPetFor((Player
*)this) && !((Player
*)this)->InArena())
10457 ((Player
*)this)->UnsummonPetTemporaryIfAny();
10459 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,true);
10465 void Unit::Unmount()
10470 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
10472 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
10473 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
10475 // only resummon old pet if the player is already added to a map
10476 // this prevents adding a pet to a not created map which would otherwise cause a crash
10477 // (it could probably happen when logging in after a previous crash)
10478 if(GetTypeId() == TYPEID_PLAYER
)
10480 if(Pet
* pet
= GetPet())
10481 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,false);
10483 ((Player
*)this)->ResummonPetTemporaryUnSummonedIfAny();
10487 void Unit::SetInCombatWith(Unit
* enemy
)
10489 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
10490 if (eOwner
->IsPvP())
10492 SetInCombatState(true,enemy
);
10497 if (eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
10499 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
10500 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
10502 SetInCombatState(true,enemy
);
10507 SetInCombatState(false,enemy
);
10510 void Unit::SetInCombatState(bool PvP
, Unit
* enemy
)
10512 // only alive units can be in combat
10517 m_CombatTimer
= 5000;
10519 bool creatureNotInCombat
= GetTypeId()==TYPEID_UNIT
&& !HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10521 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10523 if (isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10524 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10526 if (creatureNotInCombat
)
10528 // should probably be removed for the attacked (+ it's party/group) only, not global
10529 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10531 if (((Creature
*)this)->AI())
10532 ((Creature
*)this)->AI()->EnterCombat(enemy
);
10536 void Unit::ClearInCombat()
10539 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10541 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10542 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10544 // Player's state will be cleared in Player::UpdateContestedPvP
10545 if (GetTypeId() != TYPEID_PLAYER
)
10547 Creature
* creature
= (Creature
*)this;
10548 if (creature
->GetCreatureInfo() && creature
->GetCreatureInfo()->unit_flags
& UNIT_FLAG_OOC_NOT_ATTACKABLE
)
10549 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10551 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
10554 ((Player
*)this)->UpdatePotionCooldown();
10557 bool Unit::isTargetableForAttack(bool inverseAlive
/*=false*/) const
10559 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
10562 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
10565 // to be removed if unit by any reason enter combat
10566 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
))
10569 // inversealive is needed for some spells which need to be casted at dead targets (aoe)
10570 if (isAlive() == inverseAlive
)
10573 return IsInWorld() && !hasUnitState(UNIT_STAT_DIED
) && !isInFlight();
10576 int32
Unit::ModifyHealth(int32 dVal
)
10583 int32 curHealth
= (int32
)GetHealth();
10585 int32 val
= dVal
+ curHealth
;
10592 int32 maxHealth
= (int32
)GetMaxHealth();
10594 if(val
< maxHealth
)
10597 gain
= val
- curHealth
;
10599 else if(curHealth
!= maxHealth
)
10601 SetHealth(maxHealth
);
10602 gain
= maxHealth
- curHealth
;
10608 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
10615 int32 curPower
= (int32
)GetPower(power
);
10617 int32 val
= dVal
+ curPower
;
10624 int32 maxPower
= (int32
)GetMaxPower(power
);
10628 SetPower(power
,val
);
10629 gain
= val
- curPower
;
10631 else if(curPower
!= maxPower
)
10633 SetPower(power
,maxPower
);
10634 gain
= maxPower
- curPower
;
10640 bool Unit::isVisibleForOrDetect(Unit
const* u
, WorldObject
const* viewPoint
, bool detect
, bool inVisibleList
, bool is3dDistance
) const
10642 if(!u
|| !IsInMap(u
))
10645 // Always can see self
10649 // player visible for other player if not logout and at same transport
10650 // including case when player is out of world
10651 bool at_same_transport
=
10652 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
10653 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
10654 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
10655 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
10658 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
10661 // forbidden to seen (at GM respawn command)
10662 if(m_Visibility
==VISIBILITY_RESPAWN
)
10665 Map
& _map
= *u
->GetMap();
10666 // Grid dead/alive checks
10667 if (u
->GetTypeId()==TYPEID_PLAYER
)
10669 // non visible at grid for any stealth state
10670 if(!IsVisibleInGridForPlayer((Player
*)u
))
10673 // if player is dead then he can't detect anyone in any cases
10679 // all dead creatures/players not visible for any creatures
10680 if(!u
->isAlive() || !isAlive())
10684 // always seen by far sight caster
10685 if (u
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)u
)->GetFarSight()==GetGUID())
10688 // different visible distance checks
10689 if (u
->isInFlight()) // what see player in flight
10691 // use object grey distance for all (only see objects any way)
10692 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10695 else if(!isAlive()) // distance for show body
10697 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10700 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
10702 if(u
->GetTypeId()==TYPEID_PLAYER
)
10704 // Players far than max visible distance for player or not in our map are not visible too
10705 if (!at_same_transport
&& !IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10710 // Units far than max visible distance for creature or not in our map are not visible too
10711 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10715 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
10717 // Pet/charmed far than max visible distance for player or not in our map are not visible too
10718 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10721 else // distance for show creature
10723 // Units far than max visible distance for creature or not in our map are not visible too
10724 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10728 // always seen by owner
10729 if (GetCharmerOrOwnerGUID()==u
->GetGUID())
10732 // isInvisibleForAlive() those units can only be seen by dead or if other
10733 // unit is also invisible for alive.. if an isinvisibleforalive unit dies we
10734 // should be able to see it too
10735 if (u
->isAlive() && isAlive() && isInvisibleForAlive() != u
->isInvisibleForAlive())
10736 if (u
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)u
)->isGameMaster())
10739 // Visible units, always are visible for all units, except for units under invisibility and phases
10740 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0 && InSamePhase(u
))
10743 // GMs see any players, not higher GMs and all units in any phase
10744 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
10746 if(GetTypeId() == TYPEID_PLAYER
)
10747 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
10752 // non faction visibility non-breakable for non-GMs
10753 if (m_Visibility
== VISIBILITY_OFF
)
10756 // phased visibility (both must phased in same way)
10757 if(!InSamePhase(u
))
10760 // raw invisibility
10761 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
10763 // detectable invisibility case
10765 // Invisible units, always are visible for units under same invisibility type
10766 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
10767 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
10768 u
->canDetectInvisibilityOf(this) ||
10769 // Units that can detect invisibility always are visible for units that can be detected
10770 canDetectInvisibilityOf(u
) ))
10775 // special cases for always overwrite invisibility/stealth
10776 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
10778 // non-hostile case
10779 if (!u
->IsHostileTo(this))
10781 // 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)
10782 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
10784 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
10787 // else apply same rules as for hostile case (detecting check for stealth)
10793 // Hunter mark functionality
10794 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
10795 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
10796 if((*iter
)->GetCasterGUID()==u
->GetGUID())
10799 // else apply detecting check for stealth
10802 // none other cases for detect invisibility, so invisible
10806 // else apply stealth detecting check
10809 // unit got in stealth in this moment and must ignore old detected state
10810 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
10813 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
10814 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
10817 // NOW ONLY STEALTH CASE
10819 //if in non-detect mode then invisible for unit
10820 //mobs always detect players (detect == true)... return 'false' for those mobs which have (detect == false)
10821 //players detect players only in Player::HandleStealthedUnitsDetection()
10823 return (u
->GetTypeId() == TYPEID_PLAYER
) ? ((Player
*)u
)->HaveAtClient(this) : false;
10827 // If is attacked then stealth is lost, some creature can use stealth too
10828 if( !getAttackers().empty() )
10831 // If there is collision rogue is seen regardless of level difference
10832 if (IsWithinDist(u
,0.24f
))
10835 //If a mob or player is stunned he will not be able to detect stealth
10836 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
10840 float visibleDistance
= (u
->GetTypeId() == TYPEID_PLAYER
) ? MAX_PLAYER_STEALTH_DETECT_RANGE
: ((Creature
const*)u
)->GetAttackDistance(this);
10842 //Always invisible from back (when stealth detection is on), also filter max distance cases
10843 bool isInFront
= viewPoint
->isInFrontInMap(this, visibleDistance
);
10847 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
10848 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
10850 //Calculation if target is in front
10852 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
10853 visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
10855 //Visible distance is modified by
10856 //-Level Diff (every level diff = 1.0f in visible distance)
10857 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
10859 //This allows to check talent tree and will add addition stealth dependent on used points)
10860 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
10864 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
10865 //based on wowwiki every 5 mod we have 1 more level diff in calculation
10866 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_DETECT
)) - stealthMod
)/5.0f
;
10867 visibleDistance
= visibleDistance
> MAX_PLAYER_STEALTH_DETECT_RANGE
? MAX_PLAYER_STEALTH_DETECT_RANGE
: visibleDistance
;
10869 // recheck new distance
10870 if(visibleDistance
<= 0 || !IsWithinDist(viewPoint
,visibleDistance
))
10874 // Now check is target visible with LoS
10876 viewPoint
->GetPosition(ox
,oy
,oz
);
10877 return IsWithinLOS(ox
,oy
,oz
);
10880 void Unit::SetVisibility(UnitVisibility x
)
10888 if(GetTypeId()==TYPEID_PLAYER
)
10889 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10891 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10895 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
10897 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
10899 for(uint32 i
= 0; i
< 10; ++i
)
10901 if(((1 << i
) & mask
)==0)
10904 // find invisibility level
10905 int32 invLevel
= 0;
10906 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
10907 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
10908 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
10909 invLevel
= (*itr
)->GetModifier()->m_amount
;
10911 // find invisibility detect level
10912 int32 detectLevel
= 0;
10913 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
10914 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
10915 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
10916 detectLevel
= (*itr
)->GetModifier()->m_amount
;
10918 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
10920 detectLevel
= ((Player
*)this)->GetDrunkValue();
10923 if(invLevel
<= detectLevel
)
10931 struct UpdateWalkModeHelper
10933 explicit UpdateWalkModeHelper(Unit
* _source
) : source(_source
) {}
10934 void operator()(Unit
* unit
) const { unit
->UpdateWalkMode(source
, true); }
10938 void Unit::UpdateWalkMode(Unit
* source
, bool self
)
10940 if (GetTypeId() == TYPEID_PLAYER
)
10941 ((Player
*)this)->CallForAllControlledUnits(UpdateWalkModeHelper(source
), false, true, true, true);
10944 bool on
= source
->GetTypeId() == TYPEID_PLAYER
10945 ? ((Player
*)source
)->HasMovementFlag(MOVEFLAG_WALK_MODE
)
10946 : ((Creature
*)source
)->HasSplineFlag(SPLINEFLAG_WALKMODE
);
10950 if (((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10951 ((Creature
*)this)->AddSplineFlag(SPLINEFLAG_WALKMODE
);
10955 if (((Creature
*)this)->isPet())
10956 ((Creature
*)this)->RemoveSplineFlag(SPLINEFLAG_WALKMODE
);
10960 CallForAllControlledUnits(UpdateWalkModeHelper(source
), false, true, true);
10963 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
, float ratio
)
10965 // not in combat pet have same speed as owner
10971 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10973 if(Unit
* owner
= GetOwner())
10975 SetSpeedRate(mtype
, owner
->GetSpeedRate(mtype
), forced
);
10982 int32 main_speed_mod
= 0;
10983 float stack_bonus
= 1.0f
;
10984 float non_stack_bonus
= 1.0f
;
10992 if (IsMounted()) // Use on mount auras
10994 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
10995 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
10996 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
11000 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
11001 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
11002 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
11006 case MOVE_RUN_BACK
:
11010 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
11013 case MOVE_SWIM_BACK
:
11017 if (IsMounted()) // Use on mount auras
11019 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED
);
11020 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED_STACKING
);
11021 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED_NOT_STACKING
))/100.0f
;
11023 else // Use not mount (shapeshift for example) auras (should stack)
11025 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED
);
11026 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_STACKING
);
11027 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACKING
))/100.0f
;
11031 case MOVE_FLIGHT_BACK
:
11034 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
11038 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
11039 // now we ready for speed calculation
11040 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
11048 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
11049 // TODO: possible affect only on MOVE_RUN
11050 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
11052 // Use speed from aura
11053 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
11054 if (speed
> max_speed
)
11063 // for creature case, we check explicit if mob searched for assistance
11064 if (GetTypeId() == TYPEID_UNIT
)
11066 if (((Creature
*)this)->HasSearchedAssistance())
11067 speed
*= 0.66f
; // best guessed value, so this will be 33% reduction. Based off initial speed, mob can then "run", "walk fast" or "walk".
11070 // Apply strongest slow aura mod to speed
11071 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
11074 speed
*=(100.0f
+ slow
)/100.0f
;
11075 float min_speed
= (float)GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MINIMUM_SPEED
) / 100.0f
;
11076 if (speed
< min_speed
)
11079 SetSpeedRate(mtype
, speed
* ratio
, forced
);
11082 float Unit::GetSpeed( UnitMoveType mtype
) const
11084 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
11087 struct SetSpeedRateHelper
11089 explicit SetSpeedRateHelper(UnitMoveType _mtype
, bool _forced
) : mtype(_mtype
), forced(_forced
) {}
11090 void operator()(Unit
* unit
) const { unit
->UpdateSpeed(mtype
,forced
); }
11091 UnitMoveType mtype
;
11095 void Unit::SetSpeedRate(UnitMoveType mtype
, float rate
, bool forced
)
11100 // Update speed only on change
11101 if (m_speed_rate
[mtype
] == rate
)
11104 m_speed_rate
[mtype
] = rate
;
11106 propagateSpeedChange();
11114 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11117 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11119 case MOVE_RUN_BACK
:
11120 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11123 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11125 case MOVE_SWIM_BACK
:
11126 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11128 case MOVE_TURN_RATE
:
11129 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+2+4+4+4+4+4+4+4);
11132 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11134 case MOVE_FLIGHT_BACK
:
11135 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
11137 case MOVE_PITCH_RATE
:
11138 data
.Initialize(MSG_MOVE_SET_PITCH_RATE
, 8+4+2+4+4+4+4+4+4+4);
11141 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
11145 data
<< GetPackGUID();
11146 data
<< uint32(0); // movement flags
11147 data
<< uint16(0); // unk flags
11148 data
<< uint32(getMSTime());
11149 data
<< float(GetPositionX());
11150 data
<< float(GetPositionY());
11151 data
<< float(GetPositionZ());
11152 data
<< float(GetOrientation());
11153 data
<< uint32(0); // fall time
11154 data
<< float(GetSpeed(mtype
));
11155 SendMessageToSet( &data
, true );
11159 if(GetTypeId() == TYPEID_PLAYER
)
11161 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
11162 // and do it only for real sent packets and use run for run/mounted as client expected
11163 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
11169 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
11172 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
11174 case MOVE_RUN_BACK
:
11175 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
11178 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
11180 case MOVE_SWIM_BACK
:
11181 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
11183 case MOVE_TURN_RATE
:
11184 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
11187 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
11189 case MOVE_FLIGHT_BACK
:
11190 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
11192 case MOVE_PITCH_RATE
:
11193 data
.Initialize(SMSG_FORCE_PITCH_RATE_CHANGE
, 16);
11196 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
11199 data
<< GetPackGUID();
11200 data
<< (uint32
)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
11201 if (mtype
== MOVE_RUN
)
11202 data
<< uint8(0); // new 2.1.0
11203 data
<< float(GetSpeed(mtype
));
11204 SendMessageToSet( &data
, true );
11207 if (GetTypeId() == TYPEID_PLAYER
) // need include minpet
11208 ((Player
*)this)->CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true,true);
11210 CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true);
11213 void Unit::SetHover(bool on
)
11216 CastSpell(this, 11010, true);
11218 RemoveAurasDueToSpell(11010);
11221 void Unit::setDeathState(DeathState s
)
11223 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
11226 DeleteThreatList();
11227 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
11229 if(IsNonMeleeSpellCasted(false))
11230 InterruptNonMeleeSpells(false);
11233 if (s
== JUST_DIED
)
11235 RemoveAllAurasOnDeath();
11237 UnsummonAllTotems();
11239 // after removing a Fearaura (in RemoveAllAurasOnDeath)
11240 // Unit::SetFeared is called and makes that creatures attack player again
11243 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
11244 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
11245 // remove aurastates allowing special moves
11246 ClearAllReactives();
11247 ClearDiminishings();
11249 else if(s
== JUST_ALIVED
)
11251 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
11254 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
11256 //_ApplyAllAuraMods();
11261 /*########################################
11263 ######## AGGRO SYSTEM ########
11265 ########################################*/
11266 bool Unit::CanHaveThreatList() const
11268 // only creatures can have threat list
11269 if( GetTypeId() != TYPEID_UNIT
)
11272 // only alive units can have threat list
11276 // totems can not have threat list
11277 if( ((Creature
*)this)->isTotem() )
11280 // vehicles can not have threat list
11281 if( ((Creature
*)this)->isVehicle() )
11284 // pets can not have a threat list, unless they are controlled by a creature
11285 if( ((Creature
*)this)->isPet() && IS_PLAYER_GUID(((Pet
*)this)->GetOwnerGUID()) )
11291 //======================================================================
11293 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
11295 if (!HasAuraType(SPELL_AURA_MOD_THREAT
))
11298 if (schoolMask
== SPELL_SCHOOL_MASK_NONE
)
11301 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
11303 return threat
* m_threatModifier
[school
];
11306 //======================================================================
11308 void Unit::AddThreat(Unit
* pVictim
, float threat
/*= 0.0f*/, bool crit
/*= false*/, SpellSchoolMask schoolMask
/*= SPELL_SCHOOL_MASK_NONE*/, SpellEntry
const *threatSpell
/*= NULL*/)
11310 // Only mobs can manage threat lists
11311 if(CanHaveThreatList())
11312 m_ThreatManager
.addThreat(pVictim
, threat
, crit
, schoolMask
, threatSpell
);
11315 //======================================================================
11317 void Unit::DeleteThreatList()
11319 if(CanHaveThreatList() && !m_ThreatManager
.isThreatListEmpty())
11321 m_ThreatManager
.clearReferences();
11324 //======================================================================
11326 void Unit::TauntApply(Unit
* taunter
)
11328 ASSERT(GetTypeId()== TYPEID_UNIT
);
11330 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
11333 if(!CanHaveThreatList())
11336 Unit
*target
= getVictim();
11337 if(target
&& target
== taunter
)
11340 SetInFront(taunter
);
11341 if (((Creature
*)this)->AI())
11342 ((Creature
*)this)->AI()->AttackStart(taunter
);
11344 m_ThreatManager
.tauntApply(taunter
);
11347 //======================================================================
11349 void Unit::TauntFadeOut(Unit
*taunter
)
11351 ASSERT(GetTypeId()== TYPEID_UNIT
);
11353 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
11356 if(!CanHaveThreatList())
11359 Unit
*target
= getVictim();
11360 if(!target
|| target
!= taunter
)
11363 if(m_ThreatManager
.isThreatListEmpty())
11365 if(((Creature
*)this)->AI())
11366 ((Creature
*)this)->AI()->EnterEvadeMode();
11370 m_ThreatManager
.tauntFadeOut(taunter
);
11371 target
= m_ThreatManager
.getHostileTarget();
11373 if (target
&& target
!= taunter
)
11375 SetInFront(target
);
11376 if (((Creature
*)this)->AI())
11377 ((Creature
*)this)->AI()->AttackStart(target
);
11381 //======================================================================
11383 bool Unit::SelectHostileTarget()
11385 //function provides main threat functionality
11386 //next-victim-selection algorithm and evade mode are called
11387 //threat list sorting etc.
11389 ASSERT(GetTypeId()== TYPEID_UNIT
);
11391 if (!this->isAlive())
11393 //This function only useful once AI has been initialized
11394 if (!((Creature
*)this)->AI())
11397 Unit
* target
= NULL
;
11399 // First checking if we have some taunt on us
11400 const AuraList
& tauntAuras
= GetAurasByType(SPELL_AURA_MOD_TAUNT
);
11401 if ( !tauntAuras
.empty() )
11405 // The last taunt aura caster is alive an we are happy to attack him
11406 if ( (caster
= tauntAuras
.back()->GetCaster()) && caster
->isAlive() )
11408 else if (tauntAuras
.size() > 1)
11410 // We do not have last taunt aura caster but we have more taunt auras,
11411 // so find first available target
11413 // Auras are pushed_back, last caster will be on the end
11414 AuraList::const_iterator aura
= --tauntAuras
.end();
11418 if ( (caster
= (*aura
)->GetCaster()) &&
11419 caster
->IsInMap(this) && caster
->isTargetableForAttack() && caster
->isInAccessablePlaceFor((Creature
*)this) )
11424 }while (aura
!= tauntAuras
.begin());
11428 if ( !target
&& !m_ThreatManager
.isThreatListEmpty() )
11429 // No taunt aura or taunt aura caster is dead standart target selection
11430 target
= m_ThreatManager
.getHostileTarget();
11434 if (!hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_DIED
))
11436 SetInFront(target
);
11437 ((Creature
*)this)->AI()->AttackStart(target
);
11442 // no target but something prevent go to evade mode
11443 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
11446 // last case when creature don't must go to evade mode:
11447 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
11448 // for example at owner command to pet attack some far away creature
11449 // Note: creature not have targeted movement generator but have attacker in this case
11450 if (GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE
)
11452 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
11454 if ((*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this))
11459 // enter in evade mode in other case
11460 ((Creature
*)this)->AI()->EnterEvadeMode();
11465 //======================================================================
11466 //======================================================================
11467 //======================================================================
11469 int32
Unit::CalculateSpellDamage(Unit
const* target
, SpellEntry
const* spellProto
, SpellEffectIndex effect_index
, int32
const* effBasePoints
)
11471 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
11473 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
11475 int32 level
= int32(getLevel());
11476 if (level
> (int32
)spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
11477 level
= (int32
)spellProto
->maxLevel
;
11478 else if (level
< (int32
)spellProto
->baseLevel
)
11479 level
= (int32
)spellProto
->baseLevel
;
11480 level
-= (int32
)spellProto
->spellLevel
;
11482 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
11483 int32 basePoints
= effBasePoints
? *effBasePoints
- 1 : spellProto
->EffectBasePoints
[effect_index
];
11484 basePoints
+= int32(level
* basePointsPerLevel
);
11485 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
]);
11486 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
11488 switch(randomPoints
)
11490 case 0: // not used
11491 case 1: basePoints
+= 1; break; // range 1..1
11493 // range can have positive (1..rand) and negative (rand..1) values, so order its for irand
11494 int32 randvalue
= (randomPoints
>= 1)
11495 ? irand(1, randomPoints
)
11496 : irand(randomPoints
, 1);
11498 basePoints
+= randvalue
;
11502 int32 value
= basePoints
;
11505 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
11506 value
+= (int32
)(comboDamage
* comboPoints
);
11508 if(Player
* modOwner
= GetSpellModOwner())
11510 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_ALL_EFFECTS
, value
);
11511 switch(effect_index
)
11514 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT1
, value
);
11517 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT2
, value
);
11520 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_EFFECT3
, value
);
11525 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
11526 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
11527 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
&&
11528 (spellProto
->Effect
[effect_index
] != SPELL_EFFECT_APPLY_AURA
|| spellProto
->EffectApplyAuraName
[effect_index
] != SPELL_AURA_MOD_DECREASE_SPEED
))
11529 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
11534 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, SpellEffectIndex effect_index
, Unit
const* target
)
11536 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
11538 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
11540 int32 minduration
= GetSpellDuration(spellProto
);
11541 int32 maxduration
= GetSpellMaxDuration(spellProto
);
11545 if( minduration
!= -1 && minduration
!= maxduration
)
11546 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
11548 duration
= minduration
;
11552 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
11553 // Find total mod value (negative bonus)
11554 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
11555 // Modify from SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL aura for negatve effects (stack always ?)
11556 if (!IsPositiveEffect(spellProto
->Id
, effect_index
))
11557 durationMod_always
+=target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
, spellProto
->Dispel
);
11558 // Find max mod (negative bonus)
11559 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
11561 if (!IsPositiveSpell(spellProto
->Id
))
11562 durationMod_always
+= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS
, spellProto
->DmgClass
);
11564 int32 durationMod
= 0;
11565 // Select strongest negative mod
11566 if (durationMod_always
> durationMod_not_stack
)
11567 durationMod
= durationMod_not_stack
;
11569 durationMod
= durationMod_always
;
11571 if (durationMod
!= 0)
11572 duration
= int32(int64(duration
) * (100+durationMod
) /100);
11574 if (duration
< 0) duration
= 0;
11580 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
11582 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11584 if(i
->DRGroup
!= group
)
11588 return DIMINISHING_LEVEL_1
;
11591 return DIMINISHING_LEVEL_1
;
11593 // If last spell was casted more than 15 seconds ago - reset the count.
11594 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
11596 i
->hitCount
= DIMINISHING_LEVEL_1
;
11597 return DIMINISHING_LEVEL_1
;
11599 // or else increase the count.
11602 return DiminishingLevels(i
->hitCount
);
11605 return DIMINISHING_LEVEL_1
;
11608 void Unit::IncrDiminishing(DiminishingGroup group
)
11610 // Checking for existing in the table
11611 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11613 if(i
->DRGroup
!= group
)
11615 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
11619 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
11622 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
, int32 limitduration
)
11624 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
11627 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
11628 if(limitduration
> 0 && duration
> limitduration
)
11630 // test pet/charm masters instead pets/charmeds
11631 Unit
const* targetOwner
= GetCharmerOrOwner();
11632 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
11634 Unit
const* target
= targetOwner
? targetOwner
: this;
11635 Unit
const* source
= casterOwner
? casterOwner
: caster
;
11637 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
11638 duration
= limitduration
;
11643 // Some diminishings applies to mobs too (for example, Stun)
11644 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
11646 DiminishingLevels diminish
= Level
;
11649 case DIMINISHING_LEVEL_1
: break;
11650 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
11651 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
11652 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
11657 duration
= int32(duration
* mod
);
11660 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
11662 // Checking for existing in the table
11663 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11665 if(i
->DRGroup
!= group
)
11673 // Remember time after last aura from group removed
11675 i
->hitTime
= getMSTime();
11681 Unit
* Unit::GetUnit(WorldObject
const& object
, uint64 guid
)
11683 return ObjectAccessor::GetUnit(object
,guid
);
11686 bool Unit::isVisibleForInState( Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const
11688 return isVisibleForOrDetect(u
, viewPoint
, false, inVisibleList
, false);
11691 /// returns true if creature can't be seen by alive units
11692 bool Unit::isInvisibleForAlive() const
11694 if (m_AuraFlags
& UNIT_AURAFLAG_ALIVE_INVISIBLE
)
11696 // TODO: maybe spiritservices also have just an aura
11697 return isSpiritService();
11700 uint32
Unit::GetCreatureType() const
11702 if(GetTypeId() == TYPEID_PLAYER
)
11704 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(m_form
);
11705 if(ssEntry
&& ssEntry
->creatureType
> 0)
11706 return ssEntry
->creatureType
;
11708 return CREATURE_TYPE_HUMANOID
;
11711 return ((Creature
*)this)->GetCreatureInfo()->type
;
11714 /*#######################################
11716 ######## STAT SYSTEM ########
11718 #######################################*/
11720 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
11722 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11724 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
11730 switch(modifierType
)
11734 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
11738 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
11741 val
= (100.0f
+ amount
) / 100.0f
;
11742 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
11749 if(!CanModifyStats())
11754 case UNIT_MOD_STAT_STRENGTH
:
11755 case UNIT_MOD_STAT_AGILITY
:
11756 case UNIT_MOD_STAT_STAMINA
:
11757 case UNIT_MOD_STAT_INTELLECT
:
11758 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
11760 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
11761 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
11763 case UNIT_MOD_MANA
:
11764 case UNIT_MOD_RAGE
:
11765 case UNIT_MOD_FOCUS
:
11766 case UNIT_MOD_ENERGY
:
11767 case UNIT_MOD_HAPPINESS
:
11768 case UNIT_MOD_RUNE
:
11769 case UNIT_MOD_RUNIC_POWER
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
11771 case UNIT_MOD_RESISTANCE_HOLY
:
11772 case UNIT_MOD_RESISTANCE_FIRE
:
11773 case UNIT_MOD_RESISTANCE_NATURE
:
11774 case UNIT_MOD_RESISTANCE_FROST
:
11775 case UNIT_MOD_RESISTANCE_SHADOW
:
11776 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
11778 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
11779 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
11781 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
11782 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
11783 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
11792 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
11794 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11796 sLog
.outError("trial to access non existed modifier value from UnitMods!");
11800 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
11803 return m_auraModifiersGroup
[unitMod
][modifierType
];
11806 float Unit::GetTotalStatValue(Stats stat
) const
11808 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
11810 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11813 // value = ((base_value * base_pct) + total_value) * total_pct
11814 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
11815 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11816 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11817 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11822 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
11824 if(unitMod
>= UNIT_MOD_END
)
11826 sLog
.outError("trial to access non existed UnitMods in GetTotalAuraModValue()!");
11830 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11833 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
11834 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11835 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11836 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11841 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
11843 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
11847 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
11848 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
11849 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
11850 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
11851 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
11852 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
11861 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
11863 Stats stat
= STAT_STRENGTH
;
11867 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
11868 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
11869 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
11870 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
11871 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
11880 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
11884 case UNIT_MOD_MANA
: return POWER_MANA
;
11885 case UNIT_MOD_RAGE
: return POWER_RAGE
;
11886 case UNIT_MOD_FOCUS
: return POWER_FOCUS
;
11887 case UNIT_MOD_ENERGY
: return POWER_ENERGY
;
11888 case UNIT_MOD_HAPPINESS
: return POWER_HAPPINESS
;
11889 case UNIT_MOD_RUNE
: return POWER_RUNE
;
11890 case UNIT_MOD_RUNIC_POWER
:return POWER_RUNIC_POWER
;
11891 default: return POWER_MANA
;
11897 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
11899 if (attType
== RANGED_ATTACK
)
11901 int32 ap
= GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER_MODS
);
11904 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER
));
11908 int32 ap
= GetInt32Value(UNIT_FIELD_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_ATTACK_POWER_MODS
);
11911 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER
));
11915 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
11917 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
11920 return m_weaponDamage
[attType
][type
];
11923 void Unit::SetLevel(uint32 lvl
)
11925 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
11928 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
11929 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
11932 void Unit::SetHealth(uint32 val
)
11934 uint32 maxHealth
= GetMaxHealth();
11935 if(maxHealth
< val
)
11938 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
11941 if(GetTypeId() == TYPEID_PLAYER
)
11943 if(((Player
*)this)->GetGroup())
11944 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
11946 else if(((Creature
*)this)->isPet())
11948 Pet
*pet
= ((Pet
*)this);
11949 if(pet
->isControlled())
11951 Unit
*owner
= GetOwner();
11952 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11953 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
11958 void Unit::SetMaxHealth(uint32 val
)
11960 uint32 health
= GetHealth();
11961 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
11964 if(GetTypeId() == TYPEID_PLAYER
)
11966 if(((Player
*)this)->GetGroup())
11967 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
11969 else if(((Creature
*)this)->isPet())
11971 Pet
*pet
= ((Pet
*)this);
11972 if(pet
->isControlled())
11974 Unit
*owner
= GetOwner();
11975 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11976 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP
);
11984 void Unit::SetHealthPercent(float percent
)
11986 uint32 newHealth
= GetMaxHealth() * percent
/100.0f
;
11987 SetHealth(newHealth
);
11990 void Unit::SetPower(Powers power
, uint32 val
)
11992 if(GetPower(power
) == val
)
11995 uint32 maxPower
= GetMaxPower(power
);
11999 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
12001 WorldPacket
data(SMSG_POWER_UPDATE
);
12002 data
<< GetPackGUID();
12003 data
<< uint8(power
);
12004 data
<< uint32(val
);
12005 SendMessageToSet(&data
, GetTypeId() == TYPEID_PLAYER
? true : false);
12008 if(GetTypeId() == TYPEID_PLAYER
)
12010 if(((Player
*)this)->GetGroup())
12011 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
12013 else if(((Creature
*)this)->isPet())
12015 Pet
*pet
= ((Pet
*)this);
12016 if(pet
->isControlled())
12018 Unit
*owner
= GetOwner();
12019 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12020 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
12023 // Update the pet's character sheet with happiness damage bonus
12024 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
12026 pet
->UpdateDamagePhysical(BASE_ATTACK
);
12031 void Unit::SetMaxPower(Powers power
, uint32 val
)
12033 uint32 cur_power
= GetPower(power
);
12034 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
12037 if(GetTypeId() == TYPEID_PLAYER
)
12039 if(((Player
*)this)->GetGroup())
12040 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
12042 else if(((Creature
*)this)->isPet())
12044 Pet
*pet
= ((Pet
*)this);
12045 if(pet
->isControlled())
12047 Unit
*owner
= GetOwner();
12048 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12049 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
12053 if(val
< cur_power
)
12054 SetPower(power
, val
);
12057 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
12059 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
12062 if(GetTypeId() == TYPEID_PLAYER
)
12064 if(((Player
*)this)->GetGroup())
12065 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
12067 else if(((Creature
*)this)->isPet())
12069 Pet
*pet
= ((Pet
*)this);
12070 if(pet
->isControlled())
12072 Unit
*owner
= GetOwner();
12073 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12074 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
12079 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
12081 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
12084 if(GetTypeId() == TYPEID_PLAYER
)
12086 if(((Player
*)this)->GetGroup())
12087 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
12089 else if(((Creature
*)this)->isPet())
12091 Pet
*pet
= ((Pet
*)this);
12092 if(pet
->isControlled())
12094 Unit
*owner
= GetOwner();
12095 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12096 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
12101 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
12103 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
12105 tAuraProcTriggerDamage
.push_back(aura
);
12107 tAuraProcTriggerDamage
.remove(aura
);
12110 uint32
Unit::GetCreatePowers( Powers power
) const
12112 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
12115 case POWER_HEALTH
: return 0;
12116 case POWER_MANA
: return GetCreateMana();
12117 case POWER_RAGE
: return 1000;
12118 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
12119 case POWER_ENERGY
: return 100;
12120 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
12121 case POWER_RUNIC_POWER
: return 1000;
12122 case POWER_RUNE
: return 0;
12128 void Unit::AddToWorld()
12130 Object::AddToWorld();
12133 void Unit::RemoveFromWorld()
12139 RemoveNotOwnSingleTargetAuras();
12141 RemoveAllGameObjects();
12142 RemoveAllDynObjects();
12143 CleanupDeletedAuras();
12146 Object::RemoveFromWorld();
12149 void Unit::CleanupsBeforeDelete()
12151 if(m_uint32Values
) // only for fully created object
12153 InterruptNonMeleeSpells(true);
12154 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
12156 ClearComboPointHolders();
12157 DeleteThreatList();
12158 getHostileRefManager().setOnlineOfflineState(false);
12159 RemoveAllAuras(AURA_REMOVE_BY_DELETE
);
12160 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
12162 WorldObject::CleanupsBeforeDelete();
12165 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
12168 m_charmInfo
= new CharmInfo(charm
);
12169 return m_charmInfo
;
12172 CharmInfo::CharmInfo(Unit
* unit
)
12173 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
12175 for(int i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
12176 m_charmspells
[i
].SetActionAndType(0,ACT_DISABLED
);
12179 void CharmInfo::InitPetActionBar()
12181 // the first 3 SpellOrActions are attack, follow and stay
12182 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_START
- ACTION_BAR_INDEX_START
; ++i
)
12183 SetActionBar(ACTION_BAR_INDEX_START
+ i
,COMMAND_ATTACK
- i
,ACT_COMMAND
);
12185 // middle 4 SpellOrActions are spells/special attacks/abilities
12186 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_END
-ACTION_BAR_INDEX_PET_SPELL_START
; ++i
)
12187 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_START
+ i
,0,ACT_DISABLED
);
12189 // last 3 SpellOrActions are reactions
12190 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_END
- ACTION_BAR_INDEX_PET_SPELL_END
; ++i
)
12191 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_END
+ i
,COMMAND_ATTACK
- i
,ACT_REACTION
);
12194 void CharmInfo::InitEmptyActionBar()
12196 SetActionBar(ACTION_BAR_INDEX_START
,COMMAND_ATTACK
,ACT_COMMAND
);
12197 for(uint32 x
= ACTION_BAR_INDEX_START
+1; x
< ACTION_BAR_INDEX_END
; ++x
)
12198 SetActionBar(x
,0,ACT_PASSIVE
);
12201 void CharmInfo::InitPossessCreateSpells()
12203 InitEmptyActionBar(); //charm action bar
12205 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //possessed players don't have spells, keep the action bar empty
12208 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12210 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
12211 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
12213 AddSpellToActionBar(((Creature
*)m_unit
)->m_spells
[x
], ACT_PASSIVE
);
12217 void CharmInfo::InitCharmCreateSpells()
12219 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
12221 InitEmptyActionBar();
12225 InitPetActionBar();
12227 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12229 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
12233 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
12237 if (IsPassiveSpell(spellId
))
12239 m_unit
->CastSpell(m_unit
, spellId
, true);
12240 m_charmspells
[x
].SetActionAndType(spellId
,ACT_PASSIVE
);
12244 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
12246 ActiveStates newstate
;
12247 bool onlyselfcast
= true;
12248 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
12250 if(!spellInfo
) onlyselfcast
= false;
12251 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
12253 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
12254 onlyselfcast
= false;
12257 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
12258 newstate
= ACT_DISABLED
;
12260 newstate
= ACT_PASSIVE
;
12262 AddSpellToActionBar(spellId
, newstate
);
12267 bool CharmInfo::AddSpellToActionBar(uint32 spell_id
, ActiveStates newstate
)
12269 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
12271 // new spell rank can be already listed
12272 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12274 if (uint32 action
= PetActionBar
[i
].GetAction())
12276 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
12278 PetActionBar
[i
].SetAction(spell_id
);
12284 // or use empty slot in other case
12285 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12287 if (!PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
12289 SetActionBar(i
,spell_id
,newstate
== ACT_DECIDE
? ACT_DISABLED
: newstate
);
12296 bool CharmInfo::RemoveSpellFromActionBar(uint32 spell_id
)
12298 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
12300 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12302 if (uint32 action
= PetActionBar
[i
].GetAction())
12304 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
12306 SetActionBar(i
,0,ACT_DISABLED
);
12315 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
12317 if(IsPassiveSpell(spellid
))
12320 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
12321 if(spellid
== m_charmspells
[x
].GetAction())
12322 m_charmspells
[x
].SetType(apply
? ACT_ENABLED
: ACT_DISABLED
);
12325 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
12327 m_petnumber
= petnumber
;
12329 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
12331 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
12334 void CharmInfo::LoadPetActionBar(const std::string
& data
)
12336 InitPetActionBar();
12338 Tokens tokens
= StrSplit(data
, " ");
12340 if (tokens
.size() != (ACTION_BAR_INDEX_END
-ACTION_BAR_INDEX_START
)*2)
12341 return; // non critical, will reset to default
12344 Tokens::iterator iter
;
12345 for(iter
= tokens
.begin(), index
= ACTION_BAR_INDEX_START
; index
< ACTION_BAR_INDEX_END
; ++iter
, ++index
)
12347 // use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
12348 uint8 type
= (uint8
)atol((*iter
).c_str());
12350 uint32 action
= atol((*iter
).c_str());
12352 PetActionBar
[index
].SetActionAndType(action
,ActiveStates(type
));
12354 // check correctness
12355 if(PetActionBar
[index
].IsActionBarForSpell() && !sSpellStore
.LookupEntry(PetActionBar
[index
].GetAction()))
12356 SetActionBar(index
,0,ACT_DISABLED
);
12360 void CharmInfo::BuildActionBar( WorldPacket
* data
)
12362 for(uint32 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12363 *data
<< uint32(PetActionBar
[i
].packedData
);
12366 void CharmInfo::SetSpellAutocast( uint32 spell_id
, bool state
)
12368 for(int i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
12370 if(spell_id
== PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
12372 PetActionBar
[i
].SetType(state
? ACT_ENABLED
: ACT_DISABLED
);
12378 bool Unit::isFrozen() const
12380 return HasAuraState(AURA_STATE_FROZEN
);
12383 struct ProcTriggeredData
12385 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
12386 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
12387 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
12389 SpellProcEventEntry
const *spellProcEvent
;
12390 Aura
* triggeredByAura
;
12391 Unit::spellEffectPair triggeredByAura_SpellPair
;
12394 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
12395 typedef std::list
< uint32
> RemoveSpellList
;
12397 // List of auras that CAN be trigger but may not exist in spell_proc_event
12398 // in most case need for drop charges
12399 // in some types of aura need do additional check
12400 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
12401 bool InitTriggerAuraData()
12403 for (int i
=0;i
<TOTAL_AURAS
;++i
)
12405 isTriggerAura
[i
]=false;
12406 isNonTriggerAura
[i
] = false;
12408 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
12409 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
12410 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
12411 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
12412 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
12413 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
12414 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
12415 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
12416 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
12417 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
12418 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
12419 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
12420 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
] = true;
12421 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
12422 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
12423 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
12424 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
12425 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
12426 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
12427 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
12428 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
12429 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
12430 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
12431 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
12432 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
12433 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
12434 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
12435 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
] = true;
12436 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_FROM_CASTER
] = true;
12437 isTriggerAura
[SPELL_AURA_MOD_SPELL_CRIT_CHANCE
] = true;
12438 isTriggerAura
[SPELL_AURA_MAELSTROM_WEAPON
] = true;
12440 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
12441 isNonTriggerAura
[SPELL_AURA_REDUCE_PUSHBACK
]=true;
12446 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
12448 uint32 procEx
= PROC_EX_NONE
;
12449 // Check victim state
12450 if (missCondition
!=SPELL_MISS_NONE
)
12451 switch (missCondition
)
12453 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
12454 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
12455 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
12456 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
12457 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
12458 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
12459 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
12460 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
12461 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
12462 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
12463 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
12470 if (damageInfo
->blocked
)
12471 procEx
|=PROC_EX_BLOCK
;
12473 if (damageInfo
->absorb
)
12474 procEx
|=PROC_EX_ABSORB
;
12476 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
12477 procEx
|=PROC_EX_CRITICAL_HIT
;
12479 procEx
|=PROC_EX_NORMAL_HIT
;
12484 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
12486 // For melee/ranged based attack need update skills and set some Aura states
12487 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
12489 // Update skills here for players
12490 if (GetTypeId() == TYPEID_PLAYER
)
12492 // On melee based hit/miss/resist need update skill (for victim and attacker)
12493 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
12495 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
12496 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, isVictim
);
12498 // Update defence if player is victim and parry/dodge/block
12499 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
12500 ((Player
*)this)->UpdateDefense();
12502 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
12503 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
12508 // if victim and dodge attack
12509 if (procExtra
&PROC_EX_DODGE
)
12511 //Update AURA_STATE on dodge
12512 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
12514 ModifyAuraState(AURA_STATE_DEFENSE
, true);
12515 StartReactiveTimer( REACTIVE_DEFENSE
);
12518 // if victim and parry attack
12519 if (procExtra
& PROC_EX_PARRY
)
12521 // For Hunters only Counterattack (skip Mongoose bite)
12522 if (getClass() == CLASS_HUNTER
)
12524 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
12525 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
12529 ModifyAuraState(AURA_STATE_DEFENSE
, true);
12530 StartReactiveTimer( REACTIVE_DEFENSE
);
12533 // if and victim block attack
12534 if (procExtra
& PROC_EX_BLOCK
)
12536 ModifyAuraState(AURA_STATE_DEFENSE
,true);
12537 StartReactiveTimer( REACTIVE_DEFENSE
);
12540 else //For attacker
12542 // Overpower on victim dodge
12543 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
12545 ((Player
*)this)->AddComboPoints(pTarget
, 1);
12546 StartReactiveTimer( REACTIVE_OVERPOWER
);
12552 RemoveSpellList removedSpells
;
12553 ProcTriggeredList procTriggered
;
12554 // Fill procTriggered list
12555 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
12557 // skip deleted auras (possible at recursive triggered call
12558 if(itr
->second
->IsDeleted())
12561 SpellProcEventEntry
const* spellProcEvent
= NULL
;
12562 if(!IsTriggeredAtSpellProcEvent(pTarget
, itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
12565 itr
->second
->SetInUse(true); // prevent aura deletion
12566 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
12570 if (procTriggered
.empty())
12573 // Handle effects proceed this time
12574 for(ProcTriggeredList::const_iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
12576 // Some auras can be deleted in function called in this loop (except first, ofc)
12577 Aura
*triggeredByAura
= i
->triggeredByAura
;
12578 if(triggeredByAura
->IsDeleted())
12581 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
12582 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
12583 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
12584 bool useCharges
= triggeredByAura
->GetAuraCharges() > 0;
12585 // For players set spell cooldown if need
12586 uint32 cooldown
= 0;
12587 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
12588 cooldown
= spellProcEvent
->cooldown
;
12590 switch(auraModifier
->m_auraname
)
12592 case SPELL_AURA_PROC_TRIGGER_SPELL
:
12594 DEBUG_LOG("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12595 // Don`t drop charge or add cooldown for not started trigger
12596 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12598 triggeredByAura
->SetInUse(false);
12603 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
12605 DEBUG_LOG("ProcDamageAndSpell: doing %u damage from spell id %u (triggered by %s aura of spell %u)", auraModifier
->m_amount
, spellInfo
->Id
, (isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12606 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, spellInfo
->SchoolMask
);
12607 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
12608 damageInfo
.target
->CalculateAbsorbResistBlock(this, &damageInfo
, spellInfo
);
12609 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
12610 SendSpellNonMeleeDamageLog(&damageInfo
);
12611 DealSpellDamage(&damageInfo
, true);
12614 case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
:
12615 case SPELL_AURA_MANA_SHIELD
:
12616 case SPELL_AURA_OBS_MOD_MANA
:
12617 case SPELL_AURA_ADD_PCT_MODIFIER
:
12618 case SPELL_AURA_DUMMY
:
12620 DEBUG_LOG("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12621 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12623 triggeredByAura
->SetInUse(false);
12628 case SPELL_AURA_MOD_HASTE
:
12630 DEBUG_LOG("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12631 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12633 triggeredByAura
->SetInUse(false);
12638 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
12640 DEBUG_LOG("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12641 if (!HandleOverrideClassScriptAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, cooldown
))
12643 triggeredByAura
->SetInUse(false);
12648 case SPELL_AURA_PRAYER_OF_MENDING
:
12650 DEBUG_LOG("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
12651 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
12653 HandleMendingAuraProc(triggeredByAura
);
12656 case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
:
12658 DEBUG_LOG("ProcDamageAndSpell: casting spell %u (triggered with value by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12660 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12662 triggeredByAura
->SetInUse(false);
12667 case SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
:
12668 // Skip melee hits or instant cast spells
12669 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
12671 triggeredByAura
->SetInUse(false);
12675 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
12676 // Skip Melee hits and spells ws wrong school
12677 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
12679 triggeredByAura
->SetInUse(false);
12683 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
12684 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
12685 // Skip melee hits and spells ws wrong school or zero cost
12686 if (procSpell
== NULL
||
12687 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
12688 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
12690 triggeredByAura
->SetInUse(false);
12694 case SPELL_AURA_MECHANIC_IMMUNITY
:
12695 // Compare mechanic
12696 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12698 triggeredByAura
->SetInUse(false);
12702 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
12703 // Compare mechanic
12704 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12706 triggeredByAura
->SetInUse(false);
12710 case SPELL_AURA_MOD_DAMAGE_FROM_CASTER
:
12712 if (triggeredByAura
->GetCasterGUID() != pTarget
->GetGUID())
12714 triggeredByAura
->SetInUse(false);
12718 case SPELL_AURA_MOD_SPELL_CRIT_CHANCE
:
12721 triggeredByAura
->SetInUse(false);
12724 DEBUG_LOG("ProcDamageAndSpell: casting spell id %u (triggered by %s spell crit chance aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12725 if (!HandleSpellCritChanceAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12727 triggeredByAura
->SetInUse(false);
12731 case SPELL_AURA_MAELSTROM_WEAPON
:
12732 DEBUG_LOG("ProcDamageAndSpell: casting spell id %u (triggered by %s maelstrom aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12734 // remove all stack;
12735 RemoveSpellsCausingAura(SPELL_AURA_MAELSTROM_WEAPON
);
12736 triggeredByAura
->SetInUse(false); // this safe, aura locked
12737 continue; // avoid re-remove attempts
12739 // nothing do, just charges counter
12743 // Remove charge (aura can be removed by triggers)
12744 if(useCharges
&& !triggeredByAura
->IsDeleted())
12746 // If last charge dropped add spell to remove list
12747 if(triggeredByAura
->DropAuraCharge())
12748 removedSpells
.push_back(triggeredByAura
->GetId());
12751 triggeredByAura
->SetInUse(false);
12753 if (!removedSpells
.empty())
12755 // Sort spells and remove dublicates
12756 removedSpells
.sort();
12757 removedSpells
.unique();
12758 // Remove auras from removedAuras
12759 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();++i
)
12760 RemoveSingleSpellAurasFromStack(*i
);
12764 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
12766 return SPELL_SCHOOL_MASK_NORMAL
;
12769 Player
* Unit::GetSpellModOwner()
12771 if(GetTypeId()==TYPEID_PLAYER
)
12772 return (Player
*)this;
12773 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
12775 Unit
* owner
= GetOwner();
12776 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
12777 return (Player
*)owner
;
12782 ///----------Pet responses methods-----------------
12783 void Unit::SendPetCastFail(uint32 spellid
, SpellCastResult msg
)
12785 if(msg
== SPELL_CAST_OK
)
12788 Unit
*owner
= GetCharmerOrOwner();
12789 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12792 WorldPacket
data(SMSG_PET_CAST_FAILED
, 1 + 4 + 1);
12793 data
<< uint8(0); // cast count?
12794 data
<< uint32(spellid
);
12795 data
<< uint8(msg
);
12796 // uint32 for some reason
12797 // uint32 for some reason
12798 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12801 void Unit::SendPetActionFeedback (uint8 msg
)
12803 Unit
* owner
= GetOwner();
12804 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12807 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
12808 data
<< uint8(msg
);
12809 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12812 void Unit::SendPetTalk (uint32 pettalk
)
12814 Unit
* owner
= GetOwner();
12815 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12818 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8 + 4);
12819 data
<< uint64(GetGUID());
12820 data
<< uint32(pettalk
);
12821 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12824 void Unit::SendPetAIReaction(uint64 guid
)
12826 Unit
* owner
= GetOwner();
12827 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12830 WorldPacket
data(SMSG_AI_REACTION
, 8 + 4);
12831 data
<< uint64(guid
);
12832 data
<< uint32(AI_REACTION_HOSTILE
);
12833 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12836 ///----------End of Pet responses methods----------
12838 void Unit::StopMoving()
12840 clearUnitState(UNIT_STAT_MOVING
);
12842 // send explicit stop packet
12843 // player expected for correct work SPLINEFLAG_WALKMODE
12844 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), SPLINETYPE_NORMAL
, GetTypeId() == TYPEID_PLAYER
? SPLINEFLAG_WALKMODE
: SPLINEFLAG_NONE
, 0);
12846 // update position and orientation for near players
12848 BuildHeartBeatMsg(&data
);
12849 SendMessageToSet(&data
, false);
12852 void Unit::SetFeared(bool apply
, uint64
const& casterGUID
, uint32 spellID
, uint32 time
)
12856 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
12859 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12861 GetMotionMaster()->MovementExpired(false);
12862 CastStop(GetGUID() == casterGUID
? spellID
: 0);
12864 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
12866 GetMotionMaster()->MoveFleeing(caster
, time
); // caster==NULL processed in MoveFleeing
12870 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12872 GetMotionMaster()->MovementExpired(false);
12874 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
12876 // restore appropriate movement generator
12878 GetMotionMaster()->MoveChase(getVictim());
12880 GetMotionMaster()->Initialize();
12882 // attack caster if can
12883 Unit
* caster
= Unit::GetUnit(*this, casterGUID
);
12884 if(caster
&& ((Creature
*)this)->AI())
12885 ((Creature
*)this)->AI()->AttackedBy(caster
);
12889 if (GetTypeId() == TYPEID_PLAYER
)
12890 ((Player
*)this)->SetClientControl(this, !apply
);
12893 void Unit::SetConfused(bool apply
, uint64
const& casterGUID
, uint32 spellID
)
12897 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12899 CastStop(GetGUID()==casterGUID
? spellID
: 0);
12901 GetMotionMaster()->MoveConfused();
12905 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12907 GetMotionMaster()->MovementExpired(false);
12909 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12911 // restore appropriate movement generator
12913 GetMotionMaster()->MoveChase(getVictim());
12915 GetMotionMaster()->Initialize();
12919 if(GetTypeId() == TYPEID_PLAYER
)
12920 ((Player
*)this)->SetClientControl(this, !apply
);
12923 void Unit::SetFeignDeath(bool apply
, uint64
const& casterGUID
, uint32
/*spellID*/)
12928 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12931 SendMessageToSet(&data,true);
12934 if(GetTypeId() != TYPEID_PLAYER
)
12937 ((Player
*)this)->m_movementInfo
.SetMovementFlags(MOVEFLAG_NONE
);
12939 // blizz like 2.0.x
12940 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12941 // blizz like 2.0.x
12942 SetFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12943 // blizz like 2.0.x
12944 SetFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12946 addUnitState(UNIT_STAT_DIED
);
12948 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION
);
12950 // prevent interrupt message
12951 if (casterGUID
== GetGUID())
12952 FinishSpell(CURRENT_GENERIC_SPELL
,false);
12953 InterruptNonMeleeSpells(true);
12954 getHostileRefManager().deleteReferences();
12959 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12962 SendMessageToSet(&data,true);
12964 // blizz like 2.0.x
12965 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12966 // blizz like 2.0.x
12967 RemoveFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12968 // blizz like 2.0.x
12969 RemoveFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12971 clearUnitState(UNIT_STAT_DIED
);
12973 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12975 // restore appropriate movement generator
12977 GetMotionMaster()->MoveChase(getVictim());
12979 GetMotionMaster()->Initialize();
12985 bool Unit::IsSitState() const
12987 uint8 s
= getStandState();
12989 s
== UNIT_STAND_STATE_SIT_CHAIR
|| s
== UNIT_STAND_STATE_SIT_LOW_CHAIR
||
12990 s
== UNIT_STAND_STATE_SIT_MEDIUM_CHAIR
|| s
== UNIT_STAND_STATE_SIT_HIGH_CHAIR
||
12991 s
== UNIT_STAND_STATE_SIT
;
12994 bool Unit::IsStandState() const
12996 uint8 s
= getStandState();
12997 return !IsSitState() && s
!= UNIT_STAND_STATE_SLEEP
&& s
!= UNIT_STAND_STATE_KNEEL
;
13000 void Unit::SetStandState(uint8 state
)
13002 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
13004 if (IsStandState())
13005 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
13007 if(GetTypeId()==TYPEID_PLAYER
)
13009 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
13010 data
<< (uint8
)state
;
13011 ((Player
*)this)->GetSession()->SendPacket(&data
);
13015 bool Unit::IsPolymorphed() const
13017 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
13020 void Unit::SetDisplayId(uint32 modelId
)
13022 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
13024 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
13026 Pet
*pet
= ((Pet
*)this);
13027 if(!pet
->isControlled())
13029 Unit
*owner
= GetOwner();
13030 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
13031 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
13035 void Unit::ClearComboPointHolders()
13037 while(!m_ComboPointHolders
.empty())
13039 uint32 lowguid
= *m_ComboPointHolders
.begin();
13041 Player
* plr
= sObjectMgr
.GetPlayer(ObjectGuid(HIGHGUID_PLAYER
, lowguid
));
13042 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
13043 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
13045 m_ComboPointHolders
.erase(lowguid
); // or remove manually
13049 void Unit::ClearAllReactives()
13051 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
13052 m_reactiveTimer
[i
] = 0;
13054 if (HasAuraState( AURA_STATE_DEFENSE
))
13055 ModifyAuraState(AURA_STATE_DEFENSE
, false);
13056 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
13057 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
13058 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
13059 ((Player
*)this)->ClearComboPoints();
13062 void Unit::UpdateReactives( uint32 p_time
)
13064 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
13066 ReactiveType reactive
= ReactiveType(i
);
13068 if(!m_reactiveTimer
[reactive
])
13071 if ( m_reactiveTimer
[reactive
] <= p_time
)
13073 m_reactiveTimer
[reactive
] = 0;
13075 switch ( reactive
)
13077 case REACTIVE_DEFENSE
:
13078 if (HasAuraState(AURA_STATE_DEFENSE
))
13079 ModifyAuraState(AURA_STATE_DEFENSE
, false);
13081 case REACTIVE_HUNTER_PARRY
:
13082 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
13083 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
13085 case REACTIVE_OVERPOWER
:
13086 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
13087 ((Player
*)this)->ClearComboPoints();
13095 m_reactiveTimer
[reactive
] -= p_time
;
13100 Unit
* Unit::SelectRandomUnfriendlyTarget(Unit
* except
/*= NULL*/, float radius
/*= ATTACK_DISTANCE*/) const
13102 std::list
<Unit
*> targets
;
13104 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, radius
);
13105 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
13106 Cell::VisitAllObjects(this, searcher
, radius
);
13108 // remove current target
13110 targets
.remove(except
);
13112 // remove not LoS targets
13113 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
13115 if(!IsWithinLOSInMap(*tIter
))
13117 std::list
<Unit
*>::iterator tIter2
= tIter
;
13119 targets
.erase(tIter2
);
13125 // no appropriate targets
13126 if(targets
.empty())
13130 uint32 rIdx
= urand(0,targets
.size()-1);
13131 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
13132 for(uint32 i
= 0; i
< rIdx
; ++i
)
13138 Unit
* Unit::SelectRandomFriendlyTarget(Unit
* except
/*= NULL*/, float radius
/*= ATTACK_DISTANCE*/) const
13140 std::list
<Unit
*> targets
;
13142 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(this, radius
);
13143 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
13145 Cell::VisitAllObjects(this, searcher
, radius
);
13146 // remove current target
13148 targets
.remove(except
);
13150 // remove not LoS targets
13151 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
13153 if(!IsWithinLOSInMap(*tIter
))
13155 std::list
<Unit
*>::iterator tIter2
= tIter
;
13157 targets
.erase(tIter2
);
13163 // no appropriate targets
13164 if(targets
.empty())
13168 uint32 rIdx
= urand(0,targets
.size()-1);
13169 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
13170 for(uint32 i
= 0; i
< rIdx
; ++i
)
13176 bool Unit::hasNegativeAuraWithInterruptFlag(uint32 flag
)
13178 for (AuraMap::const_iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); ++iter
)
13180 if (!iter
->second
->IsPositive() && iter
->second
->GetSpellProto()->AuraInterruptFlags
& flag
)
13186 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
13190 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
13191 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
13195 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
13196 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
13200 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
13203 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
13205 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
13208 void Unit::UpdateAuraForGroup(uint8 slot
)
13210 if(GetTypeId() == TYPEID_PLAYER
)
13212 Player
* player
= (Player
*)this;
13213 if(player
->GetGroup())
13215 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
13216 player
->SetAuraUpdateMask(slot
);
13219 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
13221 Pet
*pet
= ((Pet
*)this);
13222 if(pet
->isControlled())
13224 Unit
*owner
= GetOwner();
13225 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
13227 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
13228 pet
->SetAuraUpdateMask(slot
);
13234 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
13236 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
13237 return float(GetAttackTime(attType
))/1000.0f
;
13239 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
, true, false);
13241 return 2.4f
; // fist attack
13243 switch (Weapon
->GetProto()->InventoryType
)
13245 case INVTYPE_2HWEAPON
:
13247 case INVTYPE_RANGED
:
13248 case INVTYPE_RANGEDRIGHT
:
13249 case INVTYPE_THROWN
:
13251 case INVTYPE_WEAPON
:
13252 case INVTYPE_WEAPONMAINHAND
:
13253 case INVTYPE_WEAPONOFFHAND
:
13255 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7f
: 2.4f
;
13259 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
13261 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
13262 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
13263 if ((*itr
)->GetId() == spell_id
)
13269 void Unit::SetContestedPvP(Player
*attackedPlayer
)
13271 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
13273 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
13276 player
->SetContestedPvPTimer(30000);
13277 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
13279 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
13280 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
13281 // call MoveInLineOfSight for nearby contested guards
13282 SetVisibility(GetVisibility());
13284 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
13286 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
13287 // call MoveInLineOfSight for nearby contested guards
13288 SetVisibility(GetVisibility());
13292 void Unit::AddPetAura(PetAura
const* petSpell
)
13294 m_petAuras
.insert(petSpell
);
13295 if(Pet
* pet
= GetPet())
13296 pet
->CastPetAura(petSpell
);
13299 void Unit::RemovePetAura(PetAura
const* petSpell
)
13301 m_petAuras
.erase(petSpell
);
13302 if(Pet
* pet
= GetPet())
13303 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
13306 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
13308 Pet
* pet
= new Pet(HUNTER_PET
);
13310 if(!pet
->CreateBaseAtCreature(creatureTarget
))
13316 pet
->SetOwnerGUID(GetGUID());
13317 pet
->SetCreatorGUID(GetGUID());
13318 pet
->setFaction(getFaction());
13319 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
13321 if(GetTypeId()==TYPEID_PLAYER
)
13322 pet
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
13328 pet
->SetFFAPvP(true);
13330 uint32 level
= (creatureTarget
->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget
->getLevel();
13332 if(!pet
->InitStatsForLevel(level
))
13334 sLog
.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
13339 pet
->GetCharmInfo()->SetPetNumber(sObjectMgr
.GeneratePetNumber(), true);
13340 // this enables pet details window (Shift+P)
13341 pet
->AIM_Initialize();
13342 pet
->InitPetCreateSpells();
13343 pet
->InitLevelupSpellsForLevel();
13344 pet
->InitTalentForLevel();
13345 pet
->SetHealth(pet
->GetMaxHealth());
13350 bool Unit::IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
13352 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
13354 // Get proc Event Entry
13355 spellProcEvent
= sSpellMgr
.GetSpellProcEvent(spellProto
->Id
);
13357 // Aura info stored here
13358 Modifier
*mod
= aura
->GetModifier();
13360 if (isNonTriggerAura
[mod
->m_auraname
])
13362 // If not trigger by default and spellProcEvent==NULL - skip
13363 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
13366 // Get EventProcFlag
13367 uint32 EventProcFlag
;
13368 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
13369 EventProcFlag
= spellProcEvent
->procFlags
;
13371 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
13372 // Continue if no trigger exist
13373 if (!EventProcFlag
)
13376 // Check spellProcEvent data requirements
13377 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
13380 // In most cases req get honor or XP from kill
13381 if (EventProcFlag
& PROC_FLAG_KILL
&& GetTypeId() == TYPEID_PLAYER
)
13383 bool allow
= ((Player
*)this)->isHonorOrXPTarget(pVictim
);
13384 // Shadow Word: Death - can trigger from every kill
13385 if (aura
->GetId() == 32409)
13390 // Aura added by spell can`t trogger from self (prevent drop charges/do triggers)
13391 // But except periodic triggers (can triggered from self)
13392 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
& PROC_FLAG_ON_TAKE_PERIODIC
))
13395 // Check if current equipment allows aura to proc
13396 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
13398 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
13401 if(attType
== BASE_ATTACK
)
13402 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
13403 else if (attType
== OFF_ATTACK
)
13404 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
13406 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
13408 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
13411 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
13413 // Check if player is wearing shield
13414 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
13415 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
13419 // Get chance from spell
13420 float chance
= (float)spellProto
->procChance
;
13421 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
13422 if(spellProcEvent
&& spellProcEvent
->customChance
)
13423 chance
= spellProcEvent
->customChance
;
13424 // If PPM exist calculate chance from PPM
13425 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
13427 uint32 WeaponSpeed
= GetAttackTime(attType
);
13428 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
13430 // Apply chance modifer aura
13431 if(Player
* modOwner
= GetSpellModOwner())
13433 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
13434 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_FREQUENCY_OF_SUCCESS
,chance
);
13437 return roll_chance_f(chance
);
13440 bool Unit::HandleMendingAuraProc( Aura
* triggeredByAura
)
13442 // aura can be deleted at casts
13443 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
13444 SpellEffectIndex effIdx
= triggeredByAura
->GetEffIndex();
13445 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
13446 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
13449 int32 jumps
= triggeredByAura
->GetAuraCharges()-1;
13451 // current aura expire
13452 triggeredByAura
->SetAuraCharges(1); // will removed at next charges decrease
13454 // next target selection
13455 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
13458 if (spellProto
->EffectRadiusIndex
[effIdx
])
13459 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
13461 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
13463 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
13465 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
13467 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
13469 // aura will applied from caster, but spell casted from current aura holder
13470 SpellModifier
*mod
= new SpellModifier(SPELLMOD_CHARGES
,SPELLMOD_FLAT
,jumps
-5,spellProto
->Id
,spellProto
->SpellFamilyFlags
,spellProto
->SpellFamilyFlags2
);
13472 // remove before apply next (locked against deleted)
13473 triggeredByAura
->SetInUse(true);
13474 RemoveAurasByCasterSpell(spellProto
->Id
,caster
->GetGUID());
13476 caster
->AddSpellMod(mod
, true);
13477 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
13478 caster
->AddSpellMod(mod
, false);
13479 triggeredByAura
->SetInUse(false);
13485 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
13489 void Unit::RemoveAurasAtMechanicImmunity(uint32 mechMask
, uint32 exceptSpellId
, bool non_positive
/*= false*/)
13491 Unit::AuraMap
& auras
= GetAuras();
13492 for(Unit::AuraMap::iterator iter
= auras
.begin(); iter
!= auras
.end();)
13494 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
13495 if (spell
->Id
== exceptSpellId
)
13497 else if (non_positive
&& iter
->second
->IsPositive())
13499 else if (spell
->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
)
13501 else if (GetSpellMechanicMask(spell
, iter
->second
->GetEffIndex()) & mechMask
)
13503 RemoveAurasDueToSpell(spell
->Id
);
13507 iter
= auras
.begin();
13514 void Unit::SetPhaseMask(uint32 newPhaseMask
, bool update
)
13516 if(newPhaseMask
==GetPhaseMask())
13520 RemoveNotOwnSingleTargetAuras(newPhaseMask
); // we can lost access to caster or target
13522 WorldObject::SetPhaseMask(newPhaseMask
,update
);
13525 if(Pet
* pet
= GetPet())
13526 pet
->SetPhaseMask(newPhaseMask
,true);
13529 void Unit::NearTeleportTo( float x
, float y
, float z
, float orientation
, bool casting
/*= false*/ )
13531 if(GetTypeId() == TYPEID_PLAYER
)
13532 ((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));
13535 Creature
* c
= (Creature
*)this;
13536 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13537 if (!c
->GetMotionMaster()->empty())
13538 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13539 movgen
->Interrupt(*c
);
13541 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, orientation
);
13544 BuildHeartBeatMsg(&data
);
13545 SendMessageToSet(&data
, false);
13546 // finished relocation, movegen can different from top before creature relocation,
13547 // but apply Reset expected to be safe in any case
13548 if (!c
->GetMotionMaster()->empty())
13549 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13554 void Unit::MonsterMove(float x
, float y
, float z
, uint32 transitTime
)
13556 SplineFlags flags
= GetTypeId() == TYPEID_PLAYER
? SPLINEFLAG_WALKMODE
: ((Creature
*)this)->GetSplineFlags();
13557 SendMonsterMove(x
, y
, z
, SPLINETYPE_NORMAL
, flags
, transitTime
);
13559 if (GetTypeId() != TYPEID_PLAYER
)
13561 Creature
* c
= (Creature
*)this;
13562 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13563 if (!c
->GetMotionMaster()->empty())
13564 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13565 movgen
->Interrupt(*c
);
13567 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, 0.0f
);
13569 // finished relocation, movegen can different from top before creature relocation,
13570 // but apply Reset expected to be safe in any case
13571 if (!c
->GetMotionMaster()->empty())
13572 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13577 void Unit::MonsterMoveWithSpeed(float x
, float y
, float z
, uint32 transitTime
)
13579 SendMonsterMoveWithSpeed(x
, y
, z
, transitTime
);
13581 if (GetTypeId() != TYPEID_PLAYER
)
13583 Creature
* c
= (Creature
*)this;
13584 // Creature relocation acts like instant movement generator, so current generator expects interrupt/reset calls to react properly
13585 if (!c
->GetMotionMaster()->empty())
13586 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13587 movgen
->Interrupt(*c
);
13589 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, 0.0f
);
13591 // finished relocation, movegen can different from top before creature relocation,
13592 // but apply Reset expected to be safe in any case
13593 if (!c
->GetMotionMaster()->empty())
13594 if (MovementGenerator
*movgen
= c
->GetMotionMaster()->top())
13599 struct SetPvPHelper
13601 explicit SetPvPHelper(bool _state
) : state(_state
) {}
13602 void operator()(Unit
* unit
) const { unit
->SetPvP(state
); }
13606 void Unit::SetPvP( bool state
)
13609 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13611 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13613 CallForAllControlledUnits(SetPvPHelper(state
),true,true,true);
13616 struct SetFFAPvPHelper
13618 explicit SetFFAPvPHelper(bool _state
) : state(_state
) {}
13619 void operator()(Unit
* unit
) const { unit
->SetFFAPvP(state
); }
13623 void Unit::SetFFAPvP( bool state
)
13626 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13628 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13630 CallForAllControlledUnits(SetFFAPvPHelper(state
),true,true,true);
13633 void Unit::KnockBackFrom(Unit
* target
, float horizontalSpeed
, float verticalSpeed
)
13635 float angle
= this == target
? GetOrientation() + M_PI_F
: target
->GetAngle(this);
13636 float vsin
= sin(angle
);
13637 float vcos
= cos(angle
);
13639 // Effect propertly implemented only for players
13640 if(GetTypeId()==TYPEID_PLAYER
)
13642 WorldPacket
data(SMSG_MOVE_KNOCK_BACK
, 8+4+4+4+4+4);
13643 data
<< GetPackGUID();
13644 data
<< uint32(0); // Sequence
13645 data
<< float(vcos
); // x direction
13646 data
<< float(vsin
); // y direction
13647 data
<< float(horizontalSpeed
); // Horizontal speed
13648 data
<< float(-verticalSpeed
); // Z Movement speed (vertical)
13649 ((Player
*)this)->GetSession()->SendPacket(&data
);
13653 float dis
= horizontalSpeed
;
13656 GetPosition(ox
, oy
, oz
);
13658 float fx
= ox
+ dis
* vcos
;
13659 float fy
= oy
+ dis
* vsin
;
13662 float fx2
, fy2
, fz2
; // getObjectHitPos overwrite last args in any result case
13663 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), ox
,oy
,oz
+0.5f
, fx
,fy
,oz
+0.5f
,fx2
,fy2
,fz2
, -0.5f
))
13670 UpdateGroundPositionZ(fx
, fy
, fz
);
13672 //FIXME: this mostly hack, must exist some packet for proper creature move at client side
13673 // with CreatureRelocation at server side
13674 NearTeleportTo(fx
, fy
, fz
, GetOrientation(), this == target
);
13678 float Unit::GetCombatRatingReduction(CombatRating cr
) const
13680 if (GetTypeId() == TYPEID_PLAYER
)
13681 return ((Player
const*)this)->GetRatingBonusValue(cr
);
13682 else if (((Creature
const*)this)->isPet())
13684 // Player's pet have 0.4 resilience from owner
13685 if (Unit
* owner
= GetOwner())
13686 if(owner
->GetTypeId() == TYPEID_PLAYER
)
13687 return ((Player
*)owner
)->GetRatingBonusValue(cr
) * 0.4f
;
13693 uint32
Unit::GetCombatRatingDamageReduction(CombatRating cr
, float rate
, float cap
, uint32 damage
) const
13695 float percent
= GetCombatRatingReduction(cr
) * rate
;
13698 return uint32 (percent
* damage
/ 100.0f
);
13701 void Unit::SendThreatUpdate()
13703 ThreatList
const& tlist
= getThreatManager().getThreatList();
13704 if (uint32 count
= tlist
.size())
13706 DEBUG_LOG( "WORLD: Send SMSG_THREAT_UPDATE Message" );
13707 WorldPacket
data(SMSG_THREAT_UPDATE
, 8 + count
* 8);
13708 data
<< GetPackGUID();
13709 data
<< uint32(count
);
13710 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13712 data
.appendPackGUID((*itr
)->getUnitGuid());
13713 data
<< uint32((*itr
)->getThreat());
13715 SendMessageToSet(&data
, false);
13719 void Unit::SendHighestThreatUpdate(HostileReference
* pHostilReference
)
13721 ThreatList
const& tlist
= getThreatManager().getThreatList();
13722 if (uint32 count
= tlist
.size())
13724 DEBUG_LOG( "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message" );
13725 WorldPacket
data(SMSG_HIGHEST_THREAT_UPDATE
, 8 + 8 + count
* 8);
13726 data
<< GetPackGUID();
13727 data
.appendPackGUID(pHostilReference
->getUnitGuid());
13728 data
<< uint32(count
);
13729 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13731 data
.appendPackGUID((*itr
)->getUnitGuid());
13732 data
<< uint32((*itr
)->getThreat());
13734 SendMessageToSet(&data
, false);
13738 void Unit::SendThreatClear()
13740 DEBUG_LOG( "WORLD: Send SMSG_THREAT_CLEAR Message" );
13741 WorldPacket
data(SMSG_THREAT_CLEAR
, 8);
13742 data
<< GetPackGUID();
13743 SendMessageToSet(&data
, false);
13746 void Unit::SendThreatRemove(HostileReference
* pHostileReference
)
13748 DEBUG_LOG( "WORLD: Send SMSG_THREAT_REMOVE Message" );
13749 WorldPacket
data(SMSG_THREAT_REMOVE
, 8 + 8);
13750 data
<< GetPackGUID();
13751 data
.appendPackGUID(pHostileReference
->getUnitGuid());
13752 SendMessageToSet(&data
, false);
13755 struct StopAttackFactionHelper
13757 explicit StopAttackFactionHelper(uint32 _faction_id
) : faction_id(_faction_id
) {}
13758 void operator()(Unit
* unit
) const { unit
->StopAttackFaction(faction_id
); }
13762 void Unit::StopAttackFaction(uint32 faction_id
)
13764 if (Unit
* victim
= getVictim())
13766 if (victim
->getFactionTemplateEntry()->faction
==faction_id
)
13769 if (IsNonMeleeSpellCasted(false))
13770 InterruptNonMeleeSpells(false);
13772 // melee and ranged forced attack cancel
13773 if (GetTypeId() == TYPEID_PLAYER
)
13774 ((Player
*)this)->SendAttackSwingCancelAttack();
13778 AttackerSet
const& attackers
= getAttackers();
13779 for(AttackerSet::const_iterator itr
= attackers
.begin(); itr
!= attackers
.end();)
13781 if ((*itr
)->getFactionTemplateEntry()->faction
==faction_id
)
13783 (*itr
)->AttackStop();
13784 itr
= attackers
.begin();
13790 getHostileRefManager().deleteReferencesForFaction(faction_id
);
13792 CallForAllControlledUnits(StopAttackFactionHelper(faction_id
),false,true,true);
13795 void Unit::CleanupDeletedAuras()
13797 // really delete auras "deleted" while processing its ApplyModify code
13798 for(AuraList::const_iterator itr
= m_deletedAuras
.begin(); itr
!= m_deletedAuras
.end(); ++itr
)
13800 m_deletedAuras
.clear();
13803 bool Unit::CheckAndIncreaseCastCounter()
13805 uint32 maxCasts
= sWorld
.getConfig(CONFIG_UINT32_MAX_SPELL_CASTS_IN_CHAIN
);
13807 if (maxCasts
&& m_castCounter
>= maxCasts
)