2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "WorldPacket.h"
23 #include "WorldSession.h"
25 #include "ObjectMgr.h"
26 #include "ObjectDefines.h"
34 #include "SpellAuras.h"
35 #include "MapManager.h"
36 #include "ObjectAccessor.h"
37 #include "CreatureAI.h"
42 #include "BattleGround.h"
43 #include "InstanceSaveMgr.h"
44 #include "GridNotifiersImpl.h"
47 #include "Traveller.h"
48 #include "VMapFactory.h"
52 float baseMoveSpeed
[MAX_MOVE_TYPE
] =
56 1.25f
, // MOVE_RUN_BACK
57 4.722222f
, // MOVE_SWIM
58 4.5f
, // MOVE_SWIM_BACK
59 3.141594f
, // MOVE_TURN_RATE
61 4.5f
, // MOVE_FLIGHT_BACK
62 3.14f
// MOVE_PITCH_RATE
65 // Used for prepare can/can`t triggr aura
66 static bool InitTriggerAuraData();
67 // Define can trigger auras
68 static bool isTriggerAura
[TOTAL_AURAS
];
69 // Define can`t trigger auras (need for disable second trigger)
70 static bool isNonTriggerAura
[TOTAL_AURAS
];
72 static bool procPrepared
= InitTriggerAuraData();
75 : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostileRefManager(this)
77 m_objectType
|= TYPEMASK_UNIT
;
78 m_objectTypeId
= TYPEID_UNIT
;
80 m_updateFlag
= (UPDATEFLAG_HIGHGUID
| UPDATEFLAG_LIVING
| UPDATEFLAG_HAS_POSITION
);
82 m_attackTimer
[BASE_ATTACK
] = 0;
83 m_attackTimer
[OFF_ATTACK
] = 0;
84 m_attackTimer
[RANGED_ATTACK
] = 0;
85 m_modAttackSpeedPct
[BASE_ATTACK
] = 1.0f
;
86 m_modAttackSpeedPct
[OFF_ATTACK
] = 1.0f
;
87 m_modAttackSpeedPct
[RANGED_ATTACK
] = 1.0f
;
95 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
96 m_currentSpells
[i
] = NULL
;
100 for(int i
= 0; i
< MAX_TOTEM
; ++i
)
103 m_ObjectSlot
[0] = m_ObjectSlot
[1] = m_ObjectSlot
[2] = m_ObjectSlot
[3] = 0;
105 //m_AurasCheck = 2000;
106 //m_removeAuraTimer = 4;
107 m_AurasUpdateIterator
= m_Auras
.end();
110 m_Visibility
= VISIBILITY_ON
;
112 m_detectInvisibilityMask
= 0;
113 m_invisibilityMask
= 0;
115 m_ShapeShiftFormSpellId
= 0;
116 m_canModifyStats
= false;
118 for (int i
= 0; i
< MAX_SPELL_IMMUNITY
; ++i
)
119 m_spellImmune
[i
].clear();
120 for (int i
= 0; i
< UNIT_MOD_END
; ++i
)
122 m_auraModifiersGroup
[i
][BASE_VALUE
] = 0.0f
;
123 m_auraModifiersGroup
[i
][BASE_PCT
] = 1.0f
;
124 m_auraModifiersGroup
[i
][TOTAL_VALUE
] = 0.0f
;
125 m_auraModifiersGroup
[i
][TOTAL_PCT
] = 1.0f
;
127 // implement 50% base damage from offhand
128 m_auraModifiersGroup
[UNIT_MOD_DAMAGE_OFFHAND
][TOTAL_PCT
] = 0.5f
;
130 for (int i
= 0; i
< MAX_ATTACK
; ++i
)
132 m_weaponDamage
[i
][MINDAMAGE
] = BASE_MINDAMAGE
;
133 m_weaponDamage
[i
][MAXDAMAGE
] = BASE_MAXDAMAGE
;
135 for (int i
= 0; i
< MAX_STATS
; ++i
)
136 m_createStats
[i
] = 0.0f
;
139 m_modMeleeHitChance
= 0.0f
;
140 m_modRangedHitChance
= 0.0f
;
141 m_modSpellHitChance
= 0.0f
;
142 m_baseSpellCritChance
= 5;
145 m_lastManaUseTimer
= 0;
147 //m_victimThreat = 0.0f;
148 for (int i
= 0; i
< MAX_SPELL_SCHOOL
; ++i
)
149 m_threatModifier
[i
] = 1.0f
;
151 for (int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
152 m_speed_rate
[i
] = 1.0f
;
156 // remove aurastates allowing special moves
157 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
158 m_reactiveTimer
[i
] = 0;
163 // set current spells as deletable
164 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
166 if (m_currentSpells
[i
])
168 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
169 m_currentSpells
[i
] = NULL
;
176 // those should be already removed at "RemoveFromWorld()" call
177 assert(m_gameObj
.size() == 0);
178 assert(m_dynObjGUIDs
.size() == 0);
179 assert(m_deletedAuras
.size() == 0);
182 void Unit::Update( uint32 p_time
)
187 /*if(p_time > m_AurasCheck)
192 m_AurasCheck -= p_time;*/
194 // WARNING! Order of execution here is important, do not change.
195 // Spells must be processed with event system BEFORE they go to _UpdateSpells.
196 // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
197 m_Events
.Update( p_time
);
198 _UpdateSpells( p_time
);
200 CleanupDeletedAuras();
202 if (m_lastManaUseTimer
)
204 if (p_time
>= m_lastManaUseTimer
)
205 m_lastManaUseTimer
= 0;
207 m_lastManaUseTimer
-= p_time
;
210 if (CanHaveThreatList())
211 getThreatManager().UpdateForClient(p_time
);
213 // update combat timer only for players and pets
214 if (isInCombat() && (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet() || ((Creature
*)this)->isCharmed()))
216 // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away
217 // targets without stopping half way there and running off.
218 // These flags are reset after target dies or another command is given.
219 if (m_HostileRefManager
.isEmpty())
221 // m_CombatTimer set at aura start and it will be freeze until aura removing
222 if (m_CombatTimer
<= p_time
)
225 m_CombatTimer
-= p_time
;
229 if (uint32 base_att
= getAttackTimer(BASE_ATTACK
))
231 setAttackTimer(BASE_ATTACK
, (p_time
>= base_att
? 0 : base_att
- p_time
) );
234 // update abilities available only for fraction of time
235 UpdateReactives( p_time
);
237 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, GetHealth() < GetMaxHealth()*0.20f
);
238 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, GetHealth() < GetMaxHealth()*0.35f
);
239 ModifyAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT
, GetHealth() > GetMaxHealth()*0.75f
);
241 i_motionMaster
.UpdateMotion(p_time
);
244 bool Unit::haveOffhandWeapon() const
246 if(GetTypeId() == TYPEID_PLAYER
)
247 return ((Player
*)this)->GetWeaponForAttack(OFF_ATTACK
,true,true);
252 void Unit::SendMonsterMove(float NewPosX
, float NewPosY
, float NewPosZ
, uint8 type
, MonsterMovementFlags flags
, uint32 Time
, Player
* player
)
254 float moveTime
= Time
;
256 WorldPacket
data( SMSG_MONSTER_MOVE
, (41 + GetPackGUID().size()) );
257 data
.append(GetPackGUID());
258 data
<< uint8(0); // new in 3.1
259 data
<< GetPositionX() << GetPositionY() << GetPositionZ();
260 data
<< uint32(getMSTime());
262 data
<< uint8(type
); // unknown
265 case 0: // normal packet
267 case 1: // stop packet (raw pos?)
268 SendMessageToSet( &data
, true );
270 case 2: // facing spot, not used currently
275 case 3: // not used currently
276 data
<< uint64(0); // probably target guid (facing target?)
278 case 4: // not used currently
279 data
<< float(0); // facing angle
283 data
<< uint32(flags
);
285 if(flags
& MONSTER_MOVE_WALK
)
288 data
<< uint32(moveTime
); // Time in between points
289 data
<< uint32(1); // 1 single waypoint
290 data
<< NewPosX
<< NewPosY
<< NewPosZ
; // the single waypoint Point B
293 player
->GetSession()->SendPacket(&data
);
295 SendMessageToSet( &data
, true );
298 void Unit::SendMonsterMoveByPath(Path
const& path
, uint32 start
, uint32 end
, MonsterMovementFlags flags
)
300 uint32 traveltime
= uint32(path
.GetTotalLength(start
, end
) * 32);
302 uint32 pathSize
= end
- start
;
304 WorldPacket
data( SMSG_MONSTER_MOVE
, (GetPackGUID().size()+1+4+4+4+4+1+4+4+4+pathSize
*4*3) );
305 data
.append(GetPackGUID());
307 data
<< GetPositionX();
308 data
<< GetPositionY();
309 data
<< GetPositionZ();
310 data
<< uint32(getMSTime());
312 data
<< uint32(flags
);
313 data
<< uint32(traveltime
);
314 data
<< uint32(pathSize
);
315 data
.append((char*)path
.GetNodes(start
), pathSize
* 4 * 3);
316 SendMessageToSet(&data
, true);
319 void Unit::BuildHeartBeatMsg(WorldPacket
*data
) const
321 MovementFlags move_flags
= GetTypeId()==TYPEID_PLAYER
322 ? ((Player
const*)this)->m_movementInfo
.GetMovementFlags()
325 data
->Initialize(MSG_MOVE_HEARTBEAT
, 32);
326 data
->append(GetPackGUID());
327 *data
<< uint32(move_flags
); // movement flags
328 *data
<< uint16(0); // 2.3.0
329 *data
<< uint32(getMSTime()); // time
330 *data
<< float(GetPositionX());
331 *data
<< float(GetPositionY());
332 *data
<< float(GetPositionZ());
333 *data
<< float(GetOrientation());
337 void Unit::resetAttackTimer(WeaponAttackType type
)
339 m_attackTimer
[type
] = uint32(GetAttackTime(type
) * m_modAttackSpeedPct
[type
]);
342 bool Unit::canReachWithAttack(Unit
*pVictim
) const
345 float reach
= GetFloatValue(UNIT_FIELD_COMBATREACH
);
348 return IsWithinDistInMap(pVictim
, reach
);
351 void Unit::RemoveSpellsCausingAura(AuraType auraType
)
353 if (auraType
>= TOTAL_AURAS
) return;
354 AuraList::const_iterator iter
, next
;
355 for (iter
= m_modAuras
[auraType
].begin(); iter
!= m_modAuras
[auraType
].end(); iter
= next
)
362 RemoveAurasDueToSpell((*iter
)->GetId());
363 if (!m_modAuras
[auraType
].empty())
364 next
= m_modAuras
[auraType
].begin();
371 bool Unit::HasAuraType(AuraType auraType
) const
373 return (!m_modAuras
[auraType
].empty());
376 /* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */
377 void Unit::RemoveSpellbyDamageTaken(AuraType auraType
, uint32 damage
)
379 if(!HasAuraType(auraType
))
382 // The chance to dispel an aura depends on the damage taken with respect to the casters level.
383 uint32 max_dmg
= getLevel() > 8 ? 25 * getLevel() - 150 : 50;
384 float chance
= float(damage
) / max_dmg
* 100.0f
;
385 if (roll_chance_f(chance
))
386 RemoveSpellsCausingAura(auraType
);
389 void Unit::DealDamageMods(Unit
*pVictim
, uint32
&damage
, uint32
* absorb
)
391 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
399 //You don't lose health from damage taken from another player while in a sanctuary
400 //You still see it in the combat log though
401 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
403 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
404 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) //sanctuary
412 uint32 originalDamage
= damage
;
414 //Script Event damage Deal
415 if( GetTypeId()== TYPEID_UNIT
&& ((Creature
*)this)->AI())
416 ((Creature
*)this)->AI()->DamageDeal(pVictim
, damage
);
417 //Script Event damage taken
418 if( pVictim
->GetTypeId()== TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI() )
419 ((Creature
*)pVictim
)->AI()->DamageTaken(this, damage
);
421 if(absorb
&& originalDamage
> damage
)
422 absorb
+= (originalDamage
- damage
);
425 uint32
Unit::DealDamage(Unit
*pVictim
, uint32 damage
, CleanDamage
const* cleanDamage
, DamageEffectType damagetype
, SpellSchoolMask damageSchoolMask
, SpellEntry
const *spellProto
, bool durabilityLoss
)
427 // remove affects from victim (including from 0 damage and DoTs)
429 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
431 // remove affects from attacker at any non-DoT damage (including 0 damage)
432 if( damagetype
!= DOT
)
434 RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
435 RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
438 RemoveSpellsCausingAura(SPELL_AURA_MOD_INVISIBILITY
);
440 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->IsStandState() && !pVictim
->hasUnitState(UNIT_STAT_STUNNED
))
441 pVictim
->SetStandState(UNIT_STAND_STATE_STAND
);
446 // Rage from physical damage received .
447 if(cleanDamage
&& cleanDamage
->damage
&& (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
) && pVictim
->GetTypeId() == TYPEID_PLAYER
&& (pVictim
->getPowerType() == POWER_RAGE
))
448 ((Player
*)pVictim
)->RewardRage(cleanDamage
->damage
, 0, false);
452 if (!spellProto
|| !IsSpellHaveAura(spellProto
,SPELL_AURA_MOD_FEAR
))
453 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_FEAR
, damage
);
454 // root type spells do not dispel the root effect
455 if (!spellProto
|| !(spellProto
->Mechanic
== MECHANIC_ROOT
|| IsSpellHaveAura(spellProto
,SPELL_AURA_MOD_ROOT
)))
456 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_ROOT
, damage
);
458 // no xp,health if type 8 /critters/
459 if(pVictim
->GetTypeId() != TYPEID_PLAYER
&& pVictim
->GetCreatureType() == CREATURE_TYPE_CRITTER
)
461 pVictim
->setDeathState(JUST_DIED
);
462 pVictim
->SetHealth(0);
464 // allow loot only if has loot_id in creature_template
465 CreatureInfo
const* cInfo
= ((Creature
*)pVictim
)->GetCreatureInfo();
466 if(cInfo
&& cInfo
->lootid
)
467 pVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
469 // some critters required for quests (need normal entry instead possible heroic in any cases)
470 if(GetTypeId() == TYPEID_PLAYER
)
471 if(CreatureInfo
const* normalInfo
= ObjectMgr::GetCreatureTemplate(pVictim
->GetEntry()))
472 ((Player
*)this)->KilledMonster(normalInfo
,pVictim
->GetGUID());
477 DEBUG_LOG("DealDamageStart");
479 uint32 health
= pVictim
->GetHealth();
480 sLog
.outDetail("deal dmg:%d to health:%d ",damage
,health
);
482 // duel ends when player has 1 or less hp
483 bool duel_hasEnded
= false;
484 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->duel
&& damage
>= (health
-1))
486 // prevent kill only if killed in duel and killed by opponent or opponent controlled creature
487 if(((Player
*)pVictim
)->duel
->opponent
==this || ((Player
*)pVictim
)->duel
->opponent
->GetGUID() == GetOwnerGUID())
490 duel_hasEnded
= true;
493 if(pVictim
!= this && damagetype
!= DOT
)
495 SetInCombatWith(pVictim
);
496 pVictim
->SetInCombatWith(this);
498 if(Player
* attackedPlayer
= pVictim
->GetCharmerOrOwnerPlayerOrPlayerItself())
499 SetContestedPvP(attackedPlayer
);
502 // Rage from Damage made (only from direct weapon damage)
503 if( cleanDamage
&& damagetype
==DIRECT_DAMAGE
&& this != pVictim
&& GetTypeId() == TYPEID_PLAYER
&& (getPowerType() == POWER_RAGE
))
505 uint32 weaponSpeedHitFactor
;
507 switch(cleanDamage
->attackType
)
511 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
512 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 7);
514 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
516 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
522 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
523 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
525 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 1.75f
);
527 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
536 if (GetTypeId() == TYPEID_PLAYER
&& this != pVictim
)
538 Player
*killer
= ((Player
*)this);
540 // in bg, count dmg if victim is also a player
541 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
543 if (BattleGround
*bg
= killer
->GetBattleGround())
545 // FIXME: kept by compatibility. don't know in BG if the restriction apply.
546 bg
->UpdatePlayerScore(killer
, SCORE_DAMAGE_DONE
, damage
);
550 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DAMAGE_DONE
, damage
, 0, pVictim
);
551 killer
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_DEALT
, damage
);
554 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
555 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_RECEIVED
, damage
);
557 if (pVictim
->GetTypeId() == TYPEID_UNIT
&& !((Creature
*)pVictim
)->isPet() && !((Creature
*)pVictim
)->hasLootRecipient())
558 ((Creature
*)pVictim
)->SetLootRecipient(this);
560 if (health
<= damage
)
562 DEBUG_LOG("DealDamage: victim just died");
564 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
565 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, health
);
567 // find player: owner of controlled `this` or `this` itself maybe
568 Player
*player
= GetCharmerOrOwnerPlayerOrPlayerItself();
570 if(pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->GetLootRecipient())
571 player
= ((Creature
*)pVictim
)->GetLootRecipient();
572 // Reward player, his pets, and group/raid members
573 // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop)
574 if(player
&& player
!=pVictim
)
576 player
->RewardPlayerAndGroupAtKill(pVictim
);
577 player
->ProcDamageAndSpell(pVictim
, PROC_FLAG_KILL
, PROC_FLAG_KILLED
, PROC_EX_NONE
, 0);
579 WorldPacket
data(SMSG_PARTYKILLLOG
, (8+8)); //send event PARTY_KILL
580 data
<< uint64(player
->GetGUID()); //player with killing blow
581 data
<< uint64(pVictim
->GetGUID()); //victim
582 if (Group
*group
= player
->GetGroup())
583 group
->BroadcastPacket(&data
, group
->GetMemberGroup(player
->GetGUID()));
585 player
->SendDirectMessage(&data
);
588 DEBUG_LOG("DealDamageAttackStop");
591 pVictim
->CombatStop();
592 pVictim
->getHostileRefManager().deleteReferences();
594 bool damageFromSpiritOfRedemtionTalent
= spellProto
&& spellProto
->Id
== 27795;
596 // if talent known but not triggered (check priest class for speedup check)
597 Aura
* spiritOfRedemtionTalentReady
= NULL
;
598 if( !damageFromSpiritOfRedemtionTalent
&& // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION
599 pVictim
->GetTypeId()==TYPEID_PLAYER
&& pVictim
->getClass()==CLASS_PRIEST
)
601 AuraList
const& vDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
602 for(AuraList::const_iterator itr
= vDummyAuras
.begin(); itr
!= vDummyAuras
.end(); ++itr
)
604 if((*itr
)->GetSpellProto()->SpellIconID
==1654)
606 spiritOfRedemtionTalentReady
= *itr
;
612 DEBUG_LOG("SET JUST_DIED");
613 if(!spiritOfRedemtionTalentReady
)
614 pVictim
->setDeathState(JUST_DIED
);
616 DEBUG_LOG("DealDamageHealth1");
618 if(spiritOfRedemtionTalentReady
)
620 // save value before aura remove
621 uint32 ressSpellId
= pVictim
->GetUInt32Value(PLAYER_SELF_RES_SPELL
);
623 ressSpellId
= ((Player
*)pVictim
)->GetResurrectionSpellId();
625 //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers)
626 pVictim
->RemoveAllAurasOnDeath();
628 // restore for use at real death
629 pVictim
->SetUInt32Value(PLAYER_SELF_RES_SPELL
,ressSpellId
);
631 // FORM_SPIRITOFREDEMPTION and related auras
632 pVictim
->CastSpell(pVictim
,27827,true,NULL
,spiritOfRedemtionTalentReady
);
635 pVictim
->SetHealth(0);
637 // remember victim PvP death for corpse type and corpse reclaim delay
638 // at original death (not at SpiritOfRedemtionTalent timeout)
639 if( pVictim
->GetTypeId()==TYPEID_PLAYER
&& !damageFromSpiritOfRedemtionTalent
)
640 ((Player
*)pVictim
)->SetPvPDeath(player
!=NULL
);
642 // Call KilledUnit for creatures
643 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->AI())
644 ((Creature
*)this)->AI()->KilledUnit(pVictim
);
647 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
649 if (GetTypeId() == TYPEID_UNIT
)
650 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE
, GetEntry());
651 else if(GetTypeId() == TYPEID_PLAYER
&& pVictim
!= this)
652 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER
, 1, ((Player
*)this)->GetTeam());
655 // 10% durability loss on death
656 // clean InHateListOf
657 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
659 // only if not player and not controlled by player pet. And not at BG
660 if (durabilityLoss
&& !player
&& !((Player
*)pVictim
)->InBattleGround())
662 DEBUG_LOG("We are dead, loosing 10 percents durability");
663 ((Player
*)pVictim
)->DurabilityLossAll(0.10f
,false);
664 // durability lost message
665 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
666 ((Player
*)pVictim
)->GetSession()->SendPacket(&data
);
669 else // creature died
671 DEBUG_LOG("DealDamageNotPlayer");
672 Creature
*cVictim
= (Creature
*)pVictim
;
674 if(!cVictim
->isPet())
676 cVictim
->DeleteThreatList();
677 // only lootable if it has loot or can drop gold
678 if(cVictim
->GetCreatureInfo()->lootid
|| cVictim
->GetCreatureInfo()->maxgold
> 0)
679 cVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
681 cVictim
->lootForBody
= true; // needed for skinning
683 // Call creature just died function
685 cVictim
->AI()->JustDied(this);
687 // Dungeon specific stuff, only applies to players killing creatures
688 if(cVictim
->GetInstanceId())
690 Map
*m
= cVictim
->GetMap();
691 Player
*creditedPlayer
= GetCharmerOrOwnerPlayerOrPlayerItself();
692 // TODO: do instance binding anyway if the charmer/owner is offline
694 if(m
->IsDungeon() && creditedPlayer
)
696 if (m
->IsRaidOrHeroicDungeon())
698 if(cVictim
->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
699 ((InstanceMap
*)m
)->PermBindAllPlayers(creditedPlayer
);
703 // the reset time is set but not added to the scheduler
704 // until the players leave the instance
705 time_t resettime
= cVictim
->GetRespawnTimeEx() + 2 * HOUR
;
706 if(InstanceSave
*save
= sInstanceSaveMgr
.GetInstanceSave(cVictim
->GetInstanceId()))
707 if(save
->GetResetTime() < resettime
) save
->SetResetTime(resettime
);
713 // last damage from non duel opponent or opponent controlled creature
716 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
717 Player
*he
= (Player
*)pVictim
;
721 he
->duel
->opponent
->CombatStopWithPets(true);
722 he
->CombatStopWithPets(true);
724 he
->DuelComplete(DUEL_INTERUPTED
);
727 // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill)
728 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->InBattleGround())
730 Player
*killed
= ((Player
*)pVictim
);
731 if(BattleGround
*bg
= killed
->GetBattleGround())
733 bg
->HandleKillPlayer(killed
, player
);
735 else if(pVictim
->GetTypeId() == TYPEID_UNIT
)
738 if (BattleGround
*bg
= player
->GetBattleGround())
739 bg
->HandleKillUnit((Creature
*)pVictim
, player
);
742 else // if (health <= damage)
744 DEBUG_LOG("DealDamageAlive");
746 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
747 ((Player
*)pVictim
)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED
, damage
);
749 pVictim
->ModifyHealth(- (int32
)damage
);
751 if(damagetype
!= DOT
)
755 // if not have main target then attack state with target (including AI call)
756 //start melee attacks only after melee hit
757 Attack(pVictim
,(damagetype
== DIRECT_DAMAGE
));
760 // if damage pVictim call AI reaction
761 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
762 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
765 // polymorphed, hex and other negative transformed cases
766 uint32 morphSpell
= pVictim
->getTransForm();
767 if (morphSpell
&& !IsPositiveSpell(morphSpell
))
769 if (SpellEntry
const* morphEntry
= sSpellStore
.LookupEntry(morphSpell
))
771 if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_CONFUSE
))
772 pVictim
->RemoveAurasDueToSpell(morphSpell
);
773 else if (IsSpellHaveAura(morphEntry
, SPELL_AURA_MOD_PACIFY_SILENCE
))
774 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_PACIFY_SILENCE
, damage
);
778 if(damagetype
== DIRECT_DAMAGE
|| damagetype
== SPELL_DIRECT_DAMAGE
)
780 if (!spellProto
|| !(spellProto
->AuraInterruptFlags
&AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
))
781 pVictim
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
);
783 if (pVictim
->GetTypeId() != TYPEID_PLAYER
)
785 if(spellProto
&& IsDamageToThreatSpell(spellProto
))
786 pVictim
->AddThreat(this, damage
*2, (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
788 pVictim
->AddThreat(this, damage
, (cleanDamage
&& cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
), damageSchoolMask
, spellProto
);
790 else // victim is a player
792 // Rage from damage received
793 if(this != pVictim
&& pVictim
->getPowerType() == POWER_RAGE
)
795 uint32 rage_damage
= damage
+ (cleanDamage
? cleanDamage
->damage
: 0);
796 ((Player
*)pVictim
)->RewardRage(rage_damage
, 0, false);
799 // random durability for items (HIT TAKEN)
800 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
802 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
803 ((Player
*)pVictim
)->DurabilityPointLossForEquipSlot(slot
);
807 if(GetTypeId()==TYPEID_PLAYER
)
809 // random durability for items (HIT DONE)
810 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
812 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
813 ((Player
*)this)->DurabilityPointLossForEquipSlot(slot
);
817 // TODO: Store auras by interrupt flag to speed this up.
818 AuraMap
& vAuras
= pVictim
->GetAuras();
819 for (AuraMap::const_iterator i
= vAuras
.begin(), next
; i
!= vAuras
.end(); i
= next
)
821 const SpellEntry
*se
= i
->second
->GetSpellProto();
823 if (spellProto
&& spellProto
->Id
== se
->Id
) // Not drop auras added by self
825 if( se
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_DAMAGE
)
828 if (se
->procFlags
& (1<<3))
830 if (!roll_chance_i(se
->procChance
))
835 pVictim
->RemoveAurasDueToSpell(i
->second
->GetId());
836 // FIXME: this may cause the auras with proc chance to be rerolled several times
837 next
= vAuras
.begin();
842 if (damagetype
!= NODAMAGE
&& damage
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
844 if( damagetype
!= DOT
)
846 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
848 // skip channeled spell (processed differently below)
849 if (i
== CURRENT_CHANNELED_SPELL
)
852 if(Spell
* spell
= pVictim
->GetCurrentSpell(CurrentSpellTypes(i
)))
854 if(spell
->getState() == SPELL_STATE_PREPARING
)
856 if(spell
->m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_ABORT_ON_DMG
)
857 pVictim
->InterruptSpell(CurrentSpellTypes(i
));
865 if(Spell
* spell
= pVictim
->m_currentSpells
[CURRENT_CHANNELED_SPELL
])
867 if (spell
->getState() == SPELL_STATE_CASTING
)
869 uint32 channelInterruptFlags
= spell
->m_spellInfo
->ChannelInterruptFlags
;
870 if( channelInterruptFlags
& CHANNEL_FLAG_DELAY
)
872 if(pVictim
!=this) //don't shorten the duration of channeling if you damage yourself
873 spell
->DelayedChannel();
875 else if( (channelInterruptFlags
& (CHANNEL_FLAG_DAMAGE
| CHANNEL_FLAG_DAMAGE2
)) )
877 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
878 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
881 else if (spell
->getState() == SPELL_STATE_DELAYED
)
882 // break channeled spell in delayed state on damage
884 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
885 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
890 // last damage from duel opponent
893 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
894 Player
*he
= (Player
*)pVictim
;
900 he
->duel
->opponent
->CombatStopWithPets(true);
901 he
->CombatStopWithPets(true);
903 he
->CastSpell(he
, 7267, true); // beg
904 he
->DuelComplete(DUEL_WON
);
908 DEBUG_LOG("DealDamageEnd returned %d damage", damage
);
913 void Unit::CastStop(uint32 except_spellid
)
915 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
916 if (m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
!=except_spellid
)
917 InterruptSpell(CurrentSpellTypes(i
),false);
920 void Unit::CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
922 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
926 sLog
.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId
,(GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
930 CastSpell(Victim
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
933 void Unit::CastSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
937 sLog
.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
942 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
944 if(!originalCaster
&& triggeredByAura
)
945 originalCaster
= triggeredByAura
->GetCasterGUID();
947 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
949 SpellCastTargets targets
;
950 targets
.setUnitTarget( Victim
);
951 spell
->m_CastItem
= castItem
;
952 spell
->prepare(&targets
, triggeredByAura
);
955 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
957 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
961 sLog
.outError("CastCustomSpell: unknown spell id %i", spellId
);
965 CastCustomSpell(Victim
,spellInfo
,bp0
,bp1
,bp2
,triggered
,castItem
,triggeredByAura
, originalCaster
);
968 void Unit::CastCustomSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
972 sLog
.outError("CastCustomSpell: unknown spell");
977 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
979 if(!originalCaster
&& triggeredByAura
)
980 originalCaster
= triggeredByAura
->GetCasterGUID();
982 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
985 spell
->m_currentBasePoints
[0] = *bp0
-int32(spellInfo
->EffectBaseDice
[0]);
988 spell
->m_currentBasePoints
[1] = *bp1
-int32(spellInfo
->EffectBaseDice
[1]);
991 spell
->m_currentBasePoints
[2] = *bp2
-int32(spellInfo
->EffectBaseDice
[2]);
993 SpellCastTargets targets
;
994 targets
.setUnitTarget( Victim
);
995 spell
->m_CastItem
= castItem
;
996 spell
->prepare(&targets
, triggeredByAura
);
999 // used for scripting
1000 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1002 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1006 sLog
.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s %u)", spellId
,(GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
1010 CastSpell(x
, y
, z
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
1013 // used for scripting
1014 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1018 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
1023 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1025 if(!originalCaster
&& triggeredByAura
)
1026 originalCaster
= triggeredByAura
->GetCasterGUID();
1028 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1030 SpellCastTargets targets
;
1031 targets
.setDestination(x
, y
, z
);
1032 spell
->m_CastItem
= castItem
;
1033 spell
->prepare(&targets
, triggeredByAura
);
1036 // Obsolete func need remove, here only for comotability vs another patches
1037 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
)
1039 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
1040 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, spellInfo
->SchoolMask
);
1041 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
1042 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
1043 SendSpellNonMeleeDamageLog(&damageInfo
);
1044 DealSpellDamage(&damageInfo
, true);
1045 return damageInfo
.damage
;
1048 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
1050 SpellSchoolMask damageSchoolMask
= SpellSchoolMask(damageInfo
->schoolMask
);
1051 Unit
*pVictim
= damageInfo
->target
;
1056 if(!this || !pVictim
)
1058 if(!this->isAlive() || !pVictim
->isAlive())
1061 uint32 crTypeMask
= pVictim
->GetCreatureTypeMask();
1062 // Check spell crit chance
1063 bool crit
= isSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
1064 bool blocked
= false;
1066 // damage bonus (per damage class)
1067 switch (spellInfo
->DmgClass
)
1069 // Melee and Ranged Spells
1070 case SPELL_DAMAGE_CLASS_RANGED
:
1071 case SPELL_DAMAGE_CLASS_MELEE
:
1073 //Calculate damage bonus
1074 damage
= MeleeDamageBonus(pVictim
, damage
, attackType
, spellInfo
, SPELL_DIRECT_DAMAGE
);
1075 // Get blocked status
1076 blocked
= isSpellBlocked(pVictim
, spellInfo
, attackType
);
1078 // if crit add critical bonus
1081 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1082 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1083 // Resilience - reduce crit damage
1084 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1085 if (attackType
!= RANGED_ATTACK
)
1086 damage
-= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1088 damage
-= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1093 case SPELL_DAMAGE_CLASS_NONE
:
1094 case SPELL_DAMAGE_CLASS_MAGIC
:
1096 // Calculate damage bonus
1097 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1098 // If crit add critical bonus
1101 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1102 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1103 // Resilience - reduce crit damage
1104 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1105 damage
-= pVictim
->GetSpellCritDamageReduction(redunction_affected_damage
);
1111 // only from players
1112 if (GetTypeId() == TYPEID_PLAYER
)
1114 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1115 damage
-= pVictim
->GetSpellDamageReduction(redunction_affected_damage
);
1118 // damage mitigation
1121 // physical damage => armor
1122 if (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
1124 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageSchoolMask
);
1125 damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(pVictim
, armor_affected_damage
);
1128 // block (only for damage class ranged and -melee, also non-physical damage possible)
1131 damageInfo
->blocked
= uint32(pVictim
->GetShieldBlockValue());
1132 if (damage
< damageInfo
->blocked
)
1133 damageInfo
->blocked
= damage
;
1134 damage
-=damageInfo
->blocked
;
1137 uint32 absorb_affected_damage
= CalcNotIgnoreAbsorbDamage(damage
,damageSchoolMask
,spellInfo
);
1138 CalcAbsorbResist(pVictim
, damageSchoolMask
, SPELL_DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, !(spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
));
1139 damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
1143 damageInfo
->damage
= damage
;
1146 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1151 Unit
*pVictim
= damageInfo
->target
;
1153 if(!this || !pVictim
)
1156 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1159 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1160 if (spellProto
== NULL
)
1162 sLog
.outDebug("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1166 //You don't lose health from damage taken from another player while in a sanctuary
1167 //You still see it in the combat log though
1168 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1170 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1171 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1175 // Call default DealDamage (send critical in hit info for threat calculation)
1176 CleanDamage
cleanDamage(damageInfo
->cleanDamage
, BASE_ATTACK
, damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
? MELEE_HIT_CRIT
: MELEE_HIT_NORMAL
);
1177 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->schoolMask
), spellProto
, durabilityLoss
);
1180 //TODO for melee need create structure as in
1181 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1183 damageInfo
->attacker
= this;
1184 damageInfo
->target
= pVictim
;
1185 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1186 damageInfo
->attackType
= attackType
;
1187 damageInfo
->damage
= 0;
1188 damageInfo
->cleanDamage
= 0;
1189 damageInfo
->absorb
= 0;
1190 damageInfo
->resist
= 0;
1191 damageInfo
->blocked_amount
= 0;
1193 damageInfo
->TargetState
= 0;
1194 damageInfo
->HitInfo
= 0;
1195 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1196 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1197 damageInfo
->procEx
= PROC_EX_NONE
;
1198 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1200 if(!this || !pVictim
)
1202 if(!this->isAlive() || !pVictim
->isAlive())
1205 // Select HitInfo/procAttacker/procVictim flag based on attack type
1209 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
;
1210 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1211 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1214 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1215 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1216 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1219 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1220 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1221 damageInfo
->HitInfo
= 0x08;// test
1227 // Physical Immune check
1228 if (damageInfo
->target
->IsImmunedToDamage(damageInfo
->damageSchoolMask
))
1230 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1231 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1233 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1234 damageInfo
->damage
= 0;
1235 damageInfo
->cleanDamage
= 0;
1238 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1239 // Add melee damage bonus
1240 damage
= MeleeDamageBonus(damageInfo
->target
, damage
, damageInfo
->attackType
);
1241 // Calculate armor reduction
1243 uint32 armor_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageInfo
->damageSchoolMask
);
1244 damageInfo
->damage
= damage
- armor_affected_damage
+ CalcArmorReducedDamage(damageInfo
->target
, armor_affected_damage
);
1245 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1247 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1249 // Disable parry or dodge for ranged attack
1250 if (damageInfo
->attackType
== RANGED_ATTACK
)
1252 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1253 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1256 switch(damageInfo
->hitOutCome
)
1258 case MELEE_HIT_EVADE
:
1260 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1261 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1263 damageInfo
->procEx
|=PROC_EX_EVADE
;
1264 damageInfo
->damage
= 0;
1265 damageInfo
->cleanDamage
= 0;
1268 case MELEE_HIT_MISS
:
1270 damageInfo
->HitInfo
|= HITINFO_MISS
;
1271 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1273 damageInfo
->procEx
|=PROC_EX_MISS
;
1274 damageInfo
->damage
= 0;
1275 damageInfo
->cleanDamage
= 0;
1278 case MELEE_HIT_NORMAL
:
1279 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1280 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1282 case MELEE_HIT_CRIT
:
1284 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1285 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1287 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1289 damageInfo
->damage
+= damageInfo
->damage
;
1291 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1292 if(damageInfo
->attackType
== RANGED_ATTACK
)
1293 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1295 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1297 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, SPELL_SCHOOL_MASK_NORMAL
);
1299 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1301 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1302 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1304 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1306 // Resilience - reduce crit damage
1307 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1308 uint32 resilienceReduction
;
1309 if (attackType
!= RANGED_ATTACK
)
1310 resilienceReduction
= pVictim
->GetMeleeCritDamageReduction(redunction_affected_damage
);
1312 resilienceReduction
= pVictim
->GetRangedCritDamageReduction(redunction_affected_damage
);
1314 damageInfo
->damage
-= resilienceReduction
;
1315 damageInfo
->cleanDamage
+= resilienceReduction
;
1318 case MELEE_HIT_PARRY
:
1319 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1320 damageInfo
->procEx
|= PROC_EX_PARRY
;
1321 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1322 damageInfo
->damage
= 0;
1325 case MELEE_HIT_DODGE
:
1326 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1327 damageInfo
->procEx
|=PROC_EX_DODGE
;
1328 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1329 damageInfo
->damage
= 0;
1331 case MELEE_HIT_BLOCK
:
1333 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1334 damageInfo
->HitInfo
|= HITINFO_BLOCK
;
1335 damageInfo
->procEx
|= PROC_EX_BLOCK
;
1336 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1337 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1339 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1340 damageInfo
->blocked_amount
= damageInfo
->damage
;
1341 damageInfo
->procEx
|= PROC_EX_FULL_BLOCK
;
1343 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1344 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1347 case MELEE_HIT_GLANCING
:
1349 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1350 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1351 damageInfo
->procEx
|= PROC_EX_NORMAL_HIT
;
1352 float reducePercent
= 1.0f
; //damage factor
1353 // calculate base values and mods
1354 float baseLowEnd
= 1.3f
;
1355 float baseHighEnd
= 1.2f
;
1356 switch(getClass()) // lowering base values for casters
1364 baseHighEnd
-= 0.3f
;
1368 float maxLowEnd
= 0.6f
;
1369 switch(getClass()) // upper for melee classes
1373 maxLowEnd
= 0.91f
; //If the attacker is a melee class then instead the lower value of 0.91
1377 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1378 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1379 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1381 // apply max/min bounds
1382 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1384 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1387 if ( highEnd
< 0.2f
) //high end limits
1389 if ( highEnd
> 0.99f
)
1392 if(lowEnd
> highEnd
) // prevent negative range size
1395 reducePercent
= lowEnd
+ rand_norm() * ( highEnd
- lowEnd
);
1397 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1398 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1401 case MELEE_HIT_CRUSHING
:
1403 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1404 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1405 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1406 // 150% normal damage
1407 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1415 // only from players
1416 if (GetTypeId() == TYPEID_PLAYER
)
1418 uint32 redunction_affected_damage
= CalcNotIgnoreDamageRedunction(damage
,damageInfo
->damageSchoolMask
);
1419 if (attackType
!= RANGED_ATTACK
)
1420 damage
-= pVictim
->GetMeleeDamageReduction(redunction_affected_damage
);
1422 damage
-= pVictim
->GetRangedDamageReduction(redunction_affected_damage
);
1425 // Calculate absorb resist
1426 if(int32(damageInfo
->damage
) > 0)
1428 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1430 // Calculate absorb & resists
1431 uint32 absorb_affected_damage
= CalcNotIgnoreAbsorbDamage(damageInfo
->damage
,damageInfo
->damageSchoolMask
);
1432 CalcAbsorbResist(damageInfo
->target
, damageInfo
->damageSchoolMask
, DIRECT_DAMAGE
, absorb_affected_damage
, &damageInfo
->absorb
, &damageInfo
->resist
, true);
1433 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1434 if (damageInfo
->absorb
)
1436 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1437 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1439 if (damageInfo
->resist
)
1440 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1443 else // Umpossible get negative result but....
1444 damageInfo
->damage
= 0;
1447 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1449 if (damageInfo
==0) return;
1450 Unit
*pVictim
= damageInfo
->target
;
1452 if(!this || !pVictim
)
1455 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1458 //You don't lose health from damage taken from another player while in a sanctuary
1459 //You still see it in the combat log though
1460 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1462 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1463 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) // sanctuary
1467 // Hmmmm dont like this emotes client must by self do all animations
1468 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1469 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1470 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1471 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1473 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1475 // Get attack timers
1476 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1477 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1478 // Reduce attack time
1479 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1481 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20f
;
1482 float percent60
= 3.0f
* percent20
;
1483 if(offtime
> percent20
&& offtime
<= percent60
)
1485 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1487 else if(offtime
> percent60
)
1489 offtime
-= 2.0f
* percent20
;
1490 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1495 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20;
1496 float percent60
= 3.0f
* percent20
;
1497 if(basetime
> percent20
&& basetime
<= percent60
)
1499 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1501 else if(basetime
> percent60
)
1503 basetime
-= 2.0f
* percent20
;
1504 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1509 // Call default DealDamage
1510 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1511 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, damageInfo
->damageSchoolMask
, NULL
, durabilityLoss
);
1513 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1514 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1515 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI
, this) )
1517 // -probability is between 0% and 40%
1519 float Probability
= 20.0f
;
1521 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1522 if( pVictim
->getLevel() < 30 )
1523 Probability
= 0.65f
*pVictim
->getLevel()+0.5f
;
1525 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1526 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1528 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1530 if(Probability
> 40.0f
)
1531 Probability
= 40.0f
;
1533 if(roll_chance_f(Probability
))
1534 CastSpell(pVictim
, 1604, true);
1538 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1540 // on weapon hit casts
1541 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1542 ((Player
*)this)->CastItemCombatSpell(pVictim
, damageInfo
->attackType
);
1544 // victim's damage shield
1545 std::set
<Aura
*> alreadyDone
;
1546 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1547 for(AuraList::const_iterator i
= vDamageShields
.begin(); i
!= vDamageShields
.end();)
1549 if (alreadyDone
.find(*i
) == alreadyDone
.end())
1551 alreadyDone
.insert(*i
);
1552 uint32 damage
=(*i
)->GetModifier()->m_amount
;
1553 SpellEntry
const *i_spellProto
= (*i
)->GetSpellProto();
1554 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
1557 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1558 //damage-=absorb + resist;
1560 pVictim
->DealDamageMods(this,damage
,NULL
);
1562 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4+4+4));
1563 data
<< uint64(pVictim
->GetGUID());
1564 data
<< uint64(GetGUID());
1565 data
<< uint32(i_spellProto
->Id
);
1566 data
<< uint32(damage
); // Damage
1567 data
<< uint32(0); // Overkill
1568 data
<< uint32(i_spellProto
->SchoolMask
);
1569 pVictim
->SendMessageToSet(&data
, true );
1571 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(i_spellProto
), i_spellProto
, true);
1573 i
= vDamageShields
.begin();
1582 void Unit::HandleEmoteCommand(uint32 anim_id
)
1584 WorldPacket
data( SMSG_EMOTE
, 4 + 8 );
1585 data
<< uint32(anim_id
);
1586 data
<< uint64(GetGUID());
1587 SendMessageToSet(&data
, true);
1590 uint32
Unit::CalcNotIgnoreAbsorbDamage( uint32 damage
, SpellSchoolMask damageSchoolMask
, SpellEntry
const* spellInfo
/*= NULL*/)
1592 float absorb_affected_rate
= 1.0f
;
1593 Unit::AuraList
const& ignoreAbsorbSchool
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_SCHOOL
);
1594 for(Unit::AuraList::const_iterator i
= ignoreAbsorbSchool
.begin(); i
!= ignoreAbsorbSchool
.end(); ++i
)
1595 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1596 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1600 Unit::AuraList
const& ignoreAbsorbForSpell
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL
);
1601 for(Unit::AuraList::const_iterator citr
= ignoreAbsorbForSpell
.begin(); citr
!= ignoreAbsorbForSpell
.end(); ++citr
)
1602 if ((*citr
)->isAffectedOnSpell(spellInfo
))
1603 absorb_affected_rate
*= (100.0f
- (*citr
)->GetModifier()->m_amount
)/100.0f
;
1606 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1609 uint32
Unit::CalcNotIgnoreDamageRedunction( uint32 damage
, SpellSchoolMask damageSchoolMask
)
1611 float absorb_affected_rate
= 1.0f
;
1612 Unit::AuraList
const& ignoreAbsorb
= GetAurasByType(SPELL_AURA_MOD_IGNORE_DAMAGE_REDUCTION_SCHOOL
);
1613 for(Unit::AuraList::const_iterator i
= ignoreAbsorb
.begin(); i
!= ignoreAbsorb
.end(); ++i
)
1614 if ((*i
)->GetMiscValue() & damageSchoolMask
)
1615 absorb_affected_rate
*= (100.0f
- (*i
)->GetModifier()->m_amount
)/100.0f
;
1617 return absorb_affected_rate
<= 0.0f
? 0 : (absorb_affected_rate
< 1.0f
? uint32(damage
* absorb_affected_rate
) : damage
);
1620 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
1622 uint32 newdamage
= 0;
1623 float armor
= pVictim
->GetArmor();
1625 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
1626 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
1628 // Apply Player CR_ARMOR_PENETRATION rating and percent talents
1629 if (GetTypeId()==TYPEID_PLAYER
)
1630 armor
*= 1.0f
- ((Player
*)this)->GetArmorPenetrationPct() / 100.0f
;
1635 float levelModifier
= getLevel();
1636 if (levelModifier
> 59)
1637 levelModifier
= levelModifier
+ (4.5f
* (levelModifier
-59));
1639 float tmpvalue
= 0.1f
* armor
/ (8.5f
* levelModifier
+ 40);
1640 tmpvalue
= tmpvalue
/(1.0f
+ tmpvalue
);
1642 if (tmpvalue
< 0.0f
)
1644 if (tmpvalue
> 0.75f
)
1647 newdamage
= uint32(damage
- (damage
* tmpvalue
));
1649 return (newdamage
> 1) ? newdamage
: 1;
1652 void Unit::CalcAbsorbResist(Unit
*pVictim
,SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
, bool canReflect
)
1654 if(!pVictim
|| !pVictim
->isAlive() || !damage
)
1657 // Magic damage, check for resists
1658 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
1660 // Get base victim resistance for school
1661 float tmpvalue2
= (float)pVictim
->GetResistance(GetFirstSchoolInMask(schoolMask
));
1662 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
1663 tmpvalue2
+= (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
1665 tmpvalue2
*= (float)(0.15f
/ getLevel());
1666 if (tmpvalue2
< 0.0f
)
1668 if (tmpvalue2
> 0.75f
)
1670 uint32 ran
= urand(0, 100);
1671 uint32 faq
[4] = {24,6,4,6};
1674 for (uint8 i
= 0; i
< 4; ++i
)
1676 Binom
+= 2400 *( powf(tmpvalue2
, i
) * powf( (1-tmpvalue2
), (4-i
)))/faq
[i
];
1682 if (damagetype
== DOT
&& m
== 4)
1683 *resist
+= uint32(damage
- 1);
1685 *resist
+= uint32(damage
* m
/ 4);
1686 if(*resist
> damage
)
1692 int32 RemainingDamage
= damage
- *resist
;
1694 // Get unit state (need for some absorb check)
1695 uint32 unitflag
= pVictim
->GetUInt32Value(UNIT_FIELD_FLAGS
);
1696 // Reflect damage spells (not cast any damage spell in aura lookup)
1697 uint32 reflectSpell
= 0;
1698 int32 reflectDamage
= 0;
1699 Aura
* reflectTriggeredBy
= NULL
; // expected as not expired at reflect as in current cases
1700 // Death Prevention Aura
1701 SpellEntry
const* preventDeathSpell
= NULL
;
1702 int32 preventDeathAmount
= 0;
1704 // full absorb cases (by chance)
1705 AuraList
const& vAbsorb
= pVictim
->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1706 for(AuraList::const_iterator i
= vAbsorb
.begin(); i
!= vAbsorb
.end() && RemainingDamage
> 0; ++i
)
1708 // only work with proper school mask damage
1709 Modifier
* i_mod
= (*i
)->GetModifier();
1710 if (!(i_mod
->m_miscvalue
& schoolMask
))
1713 SpellEntry
const* i_spellProto
= (*i
)->GetSpellProto();
1714 // Fire Ward or Frost Ward
1715 if(i_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& i_spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000108))
1718 Unit::AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_ADD_PCT_MODIFIER
);
1719 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
1721 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
1722 // Frost Warding (chance full absorb)
1723 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& itr_spellProto
->SpellIconID
== 501)
1725 // chance stored in next dummy effect
1726 chance
= itr_spellProto
->CalculateSimpleValue(1);
1730 if(roll_chance_i(chance
))
1732 int32 amount
= RemainingDamage
;
1733 RemainingDamage
= 0;
1734 // Frost Warding (mana regen)
1735 pVictim
->CastCustomSpell(pVictim
, 57776, &amount
, NULL
, NULL
, true, NULL
, *i
);
1741 // Need remove expired auras after
1742 bool existExpired
= false;
1744 // absorb without mana cost
1745 AuraList
const& vSchoolAbsorb
= pVictim
->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1746 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; ++i
)
1748 Modifier
* mod
= (*i
)->GetModifier();
1749 if (!(mod
->m_miscvalue
& schoolMask
))
1752 SpellEntry
const* spellProto
= (*i
)->GetSpellProto();
1754 // Max Amount can be absorbed by this aura
1755 int32 currentAbsorb
= mod
->m_amount
;
1757 // Found empty aura (impossible but..)
1758 if (currentAbsorb
<=0)
1760 existExpired
= true;
1763 // Handle custom absorb auras
1764 // TODO: try find better way
1765 switch(spellProto
->SpellFamilyName
)
1767 case SPELLFAMILY_GENERIC
:
1770 if (spellProto
->SpellIconID
== 3066)
1772 //reduces all damage taken while stun, fear or silence
1773 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1774 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1778 if (spellProto
->SpellIconID
== 2115)
1780 // while affected by Stun and Fear
1781 if (unitflag
&(UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
))
1782 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1786 if (spellProto
->SpellIconID
== 3006)
1788 // You have a chance equal to your Parry chance
1789 if (damagetype
== DIRECT_DAMAGE
&& // Only for direct damage
1790 roll_chance_f(pVictim
->GetUnitParryChance())) // Roll chance
1791 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1794 // Reflective Shield (Lady Malande boss)
1795 if (spellProto
->Id
== 41475 && canReflect
)
1797 if(RemainingDamage
< currentAbsorb
)
1798 reflectDamage
= RemainingDamage
/ 2;
1800 reflectDamage
= currentAbsorb
/ 2;
1801 reflectSpell
= 33619;
1802 reflectTriggeredBy
= *i
;
1805 if (spellProto
->Id
== 39228 || // Argussian Compass
1806 spellProto
->Id
== 60218) // Essence of Gossamer
1808 // Max absorb stored in 1 dummy effect
1809 if (spellProto
->EffectBasePoints
[1] < currentAbsorb
)
1810 currentAbsorb
= spellProto
->EffectBasePoints
[1];
1815 case SPELLFAMILY_DRUID
:
1818 if (spellProto
->SpellIconID
== 2253)
1820 //reduces all damage taken while Stunned
1821 if (unitflag
& UNIT_FLAG_STUNNED
)
1822 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1827 case SPELLFAMILY_ROGUE
:
1829 // Cheat Death (make less prio with Guardian Spirit case)
1830 if (!preventDeathSpell
&& spellProto
->SpellIconID
== 2109 &&
1831 pVictim
->GetTypeId()==TYPEID_PLAYER
&& // Only players
1832 !((Player
*)pVictim
)->HasSpellCooldown(31231) &&
1833 // Only if no cooldown
1834 roll_chance_i((*i
)->GetModifier()->m_amount
))
1837 preventDeathSpell
= (*i
)->GetSpellProto();
1842 case SPELLFAMILY_PRIEST
:
1845 if (spellProto
->SpellIconID
== 2873)
1847 preventDeathSpell
= (*i
)->GetSpellProto();
1848 preventDeathAmount
= (*i
)->GetModifier()->m_amount
;
1851 // Power Word: Shield
1852 if (spellProto
->SpellFamilyFlags
& UI64LIT(00000001) && spellProto
->Mechanic
== MECHANIC_SHIELD
)
1854 // Glyph of Power Word: Shield
1855 if (Aura
*glyph
= pVictim
->GetAura(55672,0))
1857 int32 heal
= int32(glyph
->GetModifier()->m_amount
*
1858 (RemainingDamage
>= currentAbsorb
? currentAbsorb
: RemainingDamage
) / 100);
1859 pVictim
->CastCustomSpell(pVictim
, 56160, &heal
, NULL
, NULL
, true, 0, *i
);
1862 // Reflective Shield
1863 if (spellProto
->SpellFamilyFlags
== 0x1 && canReflect
)
1865 if (pVictim
== this)
1867 Unit
* caster
= (*i
)->GetCaster();
1870 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
1871 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
1873 switch((*k
)->GetModifier()->m_miscvalue
)
1875 case 5065: // Rank 1
1876 case 5064: // Rank 2
1878 if(RemainingDamage
>= currentAbsorb
)
1879 reflectDamage
= (*k
)->GetModifier()->m_amount
* currentAbsorb
/100;
1881 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
1882 reflectSpell
= 33619;
1883 reflectTriggeredBy
= *i
;
1892 case SPELLFAMILY_SHAMAN
:
1895 if (spellProto
->SpellIconID
== 3066)
1897 //reduces all damage taken while stun, fear or silence
1898 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1899 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1904 case SPELLFAMILY_DEATHKNIGHT
:
1907 if (spellProto
->SpellIconID
== 1958)
1909 // TODO: absorb only while transform
1912 // Anti-Magic Shell (on self)
1913 if (spellProto
->Id
== 48707)
1915 // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power.
1916 // This, if I'm not mistaken, shows that we get back ~2% of the absorbed damage as runic power.
1917 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
1918 int32 regen
= absorbed
* 2 / 10;
1919 pVictim
->CastCustomSpell(pVictim
, 49088, ®en
, NULL
, NULL
, true, NULL
, *i
);
1920 RemainingDamage
-= absorbed
;
1923 // Anti-Magic Shell (on single party/raid member)
1924 if (spellProto
->Id
== 50462)
1926 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1930 if (spellProto
->Id
== 50461)
1932 Unit
* caster
= (*i
)->GetCaster();
1935 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
1936 int32 canabsorb
= caster
->GetHealth();
1937 if (canabsorb
< absorbed
)
1938 absorbed
= canabsorb
;
1940 RemainingDamage
-= absorbed
;
1942 uint32 ab_damage
= absorbed
;
1943 DealDamageMods(caster
,ab_damage
,NULL
);
1944 DealDamage(caster
, ab_damage
, NULL
, damagetype
, schoolMask
, 0, false);
1953 // currentAbsorb - damage can be absorbed by shield
1954 // If need absorb less damage
1955 if (RemainingDamage
< currentAbsorb
)
1956 currentAbsorb
= RemainingDamage
;
1958 RemainingDamage
-= currentAbsorb
;
1960 // Reduce shield amount
1961 mod
->m_amount
-=currentAbsorb
;
1962 if((*i
)->DropAuraCharge())
1964 // Need remove it later
1965 if (mod
->m_amount
<=0)
1966 existExpired
= true;
1969 // Remove all expired absorb auras
1972 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end();)
1974 if ((*i
)->GetModifier()->m_amount
<=0)
1976 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
1977 i
= vSchoolAbsorb
.begin();
1984 // Cast back reflect damage spell
1985 if (canReflect
&& reflectSpell
)
1986 pVictim
->CastCustomSpell(this, reflectSpell
, &reflectDamage
, NULL
, NULL
, true, NULL
, reflectTriggeredBy
);
1988 // absorb by mana cost
1989 AuraList
const& vManaShield
= pVictim
->GetAurasByType(SPELL_AURA_MANA_SHIELD
);
1990 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
1994 // check damage school mask
1995 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1998 int32 currentAbsorb
;
1999 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2000 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2002 currentAbsorb
= RemainingDamage
;
2004 if (float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()])
2006 if(Player
*modOwner
= pVictim
->GetSpellModOwner())
2007 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
2009 int32 maxAbsorb
= int32(pVictim
->GetPower(POWER_MANA
) / manaMultiplier
);
2010 if (currentAbsorb
> maxAbsorb
)
2011 currentAbsorb
= maxAbsorb
;
2013 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
2014 pVictim
->ApplyPowerMod(POWER_MANA
, manaReduction
, false);
2017 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
2018 if((*i
)->GetModifier()->m_amount
<= 0)
2020 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
2021 next
= vManaShield
.begin();
2024 RemainingDamage
-= currentAbsorb
;
2027 // effects dependent from full absorb amount
2028 if (int32 full_absorb
= damage
- RemainingDamage
- *resist
)
2030 Unit::AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
2031 for (Unit::AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
2033 SpellEntry
const* itr_spellProto
= (*itr
)->GetSpellProto();
2035 // Incanter's Absorption
2036 if (itr_spellProto
->SpellFamilyName
== SPELLFAMILY_GENERIC
&&
2037 itr_spellProto
->SpellIconID
== 2941)
2040 int32 amount
= int32(full_absorb
* (*itr
)->GetModifier()->m_amount
/ 100);
2042 // apply normalized part of already accumulated amount in aura
2043 if (Aura
* spdAura
= pVictim
->GetAura(44413,0))
2044 amount
+= spdAura
->GetModifier()->m_amount
* spdAura
->GetAuraDuration() / spdAura
->GetAuraMaxDuration();
2046 // limit 5 health percents
2047 int32 health_5percent
= pVictim
->GetMaxHealth()*5/100;
2048 if(amount
> health_5percent
)
2049 amount
= health_5percent
;
2051 // Incanter's Absorption (triggered absorb based spell power, will replace existed if any)
2052 pVictim
->CastCustomSpell(pVictim
, 44413, &amount
, NULL
, NULL
, true);
2058 // only split damage if not damaging yourself
2061 AuraList
const& vSplitDamageFlat
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
2062 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
2066 // check damage school mask
2067 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2070 // Damage can be splitted only if aura has an alive caster
2071 Unit
*caster
= (*i
)->GetCaster();
2072 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
2075 int32 currentAbsorb
;
2076 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2077 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2079 currentAbsorb
= RemainingDamage
;
2081 RemainingDamage
-= currentAbsorb
;
2084 uint32 splitted
= currentAbsorb
;
2085 uint32 splitted_absorb
= 0;
2086 DealDamageMods(caster
,splitted
,&splitted_absorb
);
2088 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, splitted_absorb
, 0, false, 0, false);
2090 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2091 DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2094 AuraList
const& vSplitDamagePct
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
2095 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
2099 // check damage school mask
2100 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2103 // Damage can be splitted only if aura has an alive caster
2104 Unit
*caster
= (*i
)->GetCaster();
2105 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
2108 uint32 splitted
= uint32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
2110 RemainingDamage
-= int32(splitted
);
2112 uint32 split_absorb
= 0;
2113 DealDamageMods(caster
,splitted
,&split_absorb
);
2115 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, split_absorb
, 0, false, 0, false);
2117 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2118 DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2122 // Apply death prevention spells effects
2123 if (preventDeathSpell
&& RemainingDamage
>= pVictim
->GetHealth())
2125 switch(preventDeathSpell
->SpellFamilyName
)
2128 case SPELLFAMILY_ROGUE
:
2131 if (preventDeathSpell
->SpellIconID
== 2109)
2133 pVictim
->CastSpell(pVictim
,31231,true);
2134 ((Player
*)pVictim
)->AddSpellCooldown(31231,0,time(NULL
)+60);
2135 // with health > 10% lost health until health==10%, in other case no losses
2136 uint32 health10
= pVictim
->GetMaxHealth()/10;
2137 RemainingDamage
= pVictim
->GetHealth() > health10
? pVictim
->GetHealth() - health10
: 0;
2142 case SPELLFAMILY_PRIEST
:
2145 if (preventDeathSpell
->SpellIconID
== 2873)
2147 int32 healAmount
= pVictim
->GetMaxHealth() * preventDeathAmount
/ 100;
2148 pVictim
->CastCustomSpell(pVictim
, 48153, &healAmount
, NULL
, NULL
, true);
2149 pVictim
->RemoveAurasDueToSpell(preventDeathSpell
->Id
);
2150 RemainingDamage
= 0;
2157 *absorb
= damage
- RemainingDamage
- *resist
;
2160 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
2162 if(hasUnitState(UNIT_STAT_CAN_NOT_REACT
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
2165 if (!pVictim
->isAlive())
2168 if(IsNonMeleeSpellCasted(false))
2172 if (attType
== BASE_ATTACK
)
2173 hitInfo
= HITINFO_NORMALSWING2
;
2174 else if (attType
== OFF_ATTACK
)
2175 hitInfo
= HITINFO_LEFTSWING
;
2177 return; // ignore ranged case
2179 uint32 extraAttacks
= m_extraAttacks
;
2181 // melee attack spell casted at main hand attack only
2182 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
2184 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
2186 // not recent extra attack only at any non extra attack (melee spell case)
2187 if(!extra
&& extraAttacks
)
2189 while(m_extraAttacks
)
2191 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2192 if(m_extraAttacks
> 0)
2199 // attack can be redirected to another target
2200 pVictim
= SelectMagnetTarget(pVictim
);
2202 CalcDamageInfo damageInfo
;
2203 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
2204 // Send log damage message to client
2205 DealDamageMods(pVictim
,damageInfo
.damage
,&damageInfo
.absorb
);
2206 SendAttackStateUpdate(&damageInfo
);
2207 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
2208 DealMeleeDamage(&damageInfo
,true);
2210 if (GetTypeId() == TYPEID_PLAYER
)
2211 DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2212 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2214 DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2215 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2217 // if damage pVictim call AI reaction
2218 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
2219 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
2221 // extra attack only at any non extra attack (normal case)
2222 if(!extra
&& extraAttacks
)
2224 while(m_extraAttacks
)
2226 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2227 if(m_extraAttacks
> 0)
2233 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
2235 // This is only wrapper
2237 // Miss chance based on melee
2238 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
2240 // Critical hit chance
2241 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
2243 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
2244 float dodge_chance
= pVictim
->GetUnitDodgeChance();
2245 float block_chance
= pVictim
->GetUnitBlockChance();
2246 float parry_chance
= pVictim
->GetUnitParryChance();
2248 // Useful if want to specify crit & miss chances for melee, else it could be removed
2249 DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance
,crit_chance
,dodge_chance
,parry_chance
,block_chance
);
2251 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100));
2254 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const
2256 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2257 return MELEE_HIT_EVADE
;
2259 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
2260 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
2262 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
2263 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
2265 // bonus from skills is 0.04%
2266 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
2267 int32 sum
= 0, tmp
= 0;
2268 int32 roll
= urand (0, 10000);
2270 DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
2271 DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
2272 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
2276 if (tmp
> 0 && roll
< (sum
+= tmp
))
2278 DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS");
2279 return MELEE_HIT_MISS
;
2282 // always crit against a sitting target (except 0 crit chance)
2283 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
2285 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)");
2286 return MELEE_HIT_CRIT
;
2291 // only players can't dodge if attacker is behind
2292 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI
,this))
2294 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
2298 // Reduce dodge chance by attacker expertise rating
2299 if (GetTypeId() == TYPEID_PLAYER
)
2300 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2302 dodge_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2304 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2305 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2308 if ( (tmp
> 0) // check if unit _can_ dodge
2309 && ((tmp
-= skillBonus
) > 0)
2310 && roll
< (sum
+= tmp
))
2312 DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
2313 return MELEE_HIT_DODGE
;
2317 // parry & block chances
2319 // check if attack comes from behind, nobody can parry or block if attacker is behind
2320 if (!pVictim
->HasInArc(M_PI
,this))
2322 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind.");
2326 // Reduce parry chance by attacker expertise rating
2327 if (GetTypeId() == TYPEID_PLAYER
)
2328 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2330 parry_chance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2332 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
2334 int32 tmp2
= int32(parry_chance
);
2335 if ( (tmp2
> 0) // check if unit _can_ parry
2336 && ((tmp2
-= skillBonus
) > 0)
2337 && (roll
< (sum
+= tmp2
)))
2339 DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp2
, sum
);
2340 return MELEE_HIT_PARRY
;
2344 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
2347 if ( (tmp
> 0) // check if unit _can_ block
2348 && ((tmp
-= skillBonus
) > 0)
2349 && (roll
< (sum
+= tmp
)))
2351 DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
2352 return MELEE_HIT_BLOCK
;
2360 if (tmp
> 0 && roll
< (sum
+= tmp
))
2362 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
2363 return MELEE_HIT_CRIT
;
2366 // 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)
2367 if( attType
!= RANGED_ATTACK
&&
2368 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
2369 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
2370 getLevel() < pVictim
->getLevelForTarget(this) )
2372 // cap possible value (with bonuses > max skill)
2373 int32 skill
= attackerWeaponSkill
;
2374 int32 maxskill
= attackerMaxSkillValueForLevel
;
2375 skill
= (skill
> maxskill
) ? maxskill
: skill
;
2377 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
2378 tmp
= tmp
> 4000 ? 4000 : tmp
;
2379 if (roll
< (sum
+= tmp
))
2381 DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
2382 return MELEE_HIT_GLANCING
;
2386 // mobs can score crushing blows if they're 4 or more levels above victim
2387 if (getLevelForTarget(pVictim
) >= pVictim
->getLevelForTarget(this) + 4 &&
2388 // can be from by creature (if can) or from controlled player that considered as creature
2389 (GetTypeId()!=TYPEID_PLAYER
&& !((Creature
*)this)->isPet() &&
2390 !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) ||
2391 GetTypeId()==TYPEID_PLAYER
&& GetCharmerOrOwnerGUID()))
2393 // when their weapon skill is 15 or more above victim's defense skill
2394 tmp
= victimDefenseSkill
;
2395 int32 tmpmax
= victimMaxSkillValueForLevel
;
2396 // having defense above your maximum (from items, talents etc.) has no effect
2397 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
2398 // tmp = mob's level * 5 - player's current defense skill
2399 tmp
= attackerMaxSkillValueForLevel
- tmp
;
2402 // add 2% chance per lacking skill point, min. is 15%
2403 tmp
= tmp
* 200 - 1500;
2404 if (roll
< (sum
+= tmp
))
2406 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
2407 return MELEE_HIT_CRUSHING
;
2412 DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL");
2413 return MELEE_HIT_NORMAL
;
2416 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
2418 float min_damage
, max_damage
;
2420 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
2421 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
2427 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
2428 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
2431 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
2432 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
2435 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
2436 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
2438 // Just for good manner
2446 if (min_damage
> max_damage
)
2448 std::swap(min_damage
,max_damage
);
2451 if(max_damage
== 0.0f
)
2454 return urand((uint32
)min_damage
, (uint32
)max_damage
);
2457 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
2459 if(spellProto
->spellLevel
<= 0)
2462 float LvlPenalty
= 0.0f
;
2464 if(spellProto
->spellLevel
< 20)
2465 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
2466 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
2467 if(LvlFactor
> 1.0f
)
2470 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
2473 void Unit::SendMeleeAttackStart(Unit
* pVictim
)
2475 WorldPacket
data( SMSG_ATTACKSTART
, 8 + 8 );
2476 data
<< uint64(GetGUID());
2477 data
<< uint64(pVictim
->GetGUID());
2479 SendMessageToSet(&data
, true);
2480 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
2483 void Unit::SendMeleeAttackStop(Unit
* victim
)
2488 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
2489 data
.append(GetPackGUID());
2490 data
.append(victim
->GetPackGUID()); // can be 0x00...
2491 data
<< uint32(0); // can be 0x1
2492 SendMessageToSet(&data
, true);
2493 sLog
.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER
? "player" : "creature"), GetGUIDLow(), (victim
->GetTypeId()==TYPEID_PLAYER
? "player" : "creature"),victim
->GetGUIDLow());
2495 /*if(victim->GetTypeId() == TYPEID_UNIT)
2496 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
2499 bool Unit::isSpellBlocked(Unit
*pVictim
, SpellEntry
const * /*spellProto*/, WeaponAttackType attackType
)
2501 if (pVictim
->HasInArc(M_PI
,this))
2503 /* Currently not exist spells with ignore block
2504 // Ignore combat result aura (parry/dodge check on prepare)
2505 AuraList const& ignore = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2506 for(AuraList::const_iterator i = ignore.begin(); i != ignore.end(); ++i)
2508 if (!(*i)->isAffectedOnSpell(spellProto))
2510 if ((*i)->GetModifier()->m_miscvalue == )
2515 // Check creatures flags_extra for disable block
2516 if(pVictim
->GetTypeId()==TYPEID_UNIT
&&
2517 ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
)
2520 float blockChance
= pVictim
->GetUnitBlockChance();
2521 blockChance
+= (int32(GetWeaponSkillValue(attackType
)) - int32(pVictim
->GetMaxSkillValueForLevel()))*0.04f
;
2522 if (roll_chance_f(blockChance
))
2528 // Melee based spells can be miss, parry or dodge on this step
2529 // Crit or block - determined on damage calculation phase! (and can be both in some time)
2530 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
2532 // Calculate hit chance (more correct for chance mod)
2535 // PvP - PvE melee chances
2536 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2537 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
2539 HitChance
= 95 - leveldif
;
2541 HitChance
= 93 - (leveldif
- 2) * lchance
;
2543 // Hit chance depends from victim auras
2544 if(attType
== RANGED_ATTACK
)
2545 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2547 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2549 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2550 if(Player
*modOwner
= GetSpellModOwner())
2551 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
2554 float miss_chance
= 100.0f
- HitChance
;
2556 // Bonuses from attacker aura and ratings
2557 if (attType
== RANGED_ATTACK
)
2558 miss_chance
-= m_modRangedHitChance
;
2560 miss_chance
-= m_modMeleeHitChance
;
2562 // bonus from skills is 0.04%
2563 miss_chance
-= skillDiff
* 0.04f
;
2565 // Limit miss chance from 0 to 60%
2566 if (miss_chance
< 0.0f
)
2568 if (miss_chance
> 60.0f
)
2573 // Melee based spells hit result calculations
2574 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2576 WeaponAttackType attType
= BASE_ATTACK
;
2578 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
2579 attType
= RANGED_ATTACK
;
2581 // bonus from skills is 0.04% per skill Diff
2582 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
2583 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
2584 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
2586 uint32 roll
= urand (0, 10000);
2588 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
2590 uint32 tmp
= missChance
;
2592 return SPELL_MISS_MISS
;
2594 // Chance resist mechanic (select max value from every mechanic spell effect)
2595 int32 resist_mech
= 0;
2596 // Get effects mechanic and chance
2597 for(int eff
= 0; eff
< 3; ++eff
)
2599 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2602 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2603 if (resist_mech
< temp
*100)
2604 resist_mech
= temp
*100;
2610 return SPELL_MISS_RESIST
;
2612 bool canDodge
= true;
2613 bool canParry
= true;
2615 // Same spells cannot be parry/dodge
2616 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
2617 return SPELL_MISS_NONE
;
2619 // Ranged attack cannot be parry/dodge only deflect
2620 if (attType
== RANGED_ATTACK
)
2623 if (pVictim
->HasInArc(M_PI
,this))
2625 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2626 tmp
+=deflect_chance
;
2628 return SPELL_MISS_DEFLECT
;
2630 return SPELL_MISS_NONE
;
2633 // Check for attack from behind
2634 if (!pVictim
->HasInArc(M_PI
,this))
2636 // Can`t dodge from behind in PvP (but its possible in PvE)
2637 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
2642 // Check creatures flags_extra for disable parry
2643 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
2645 uint32 flagEx
= ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
;
2646 if( flagEx
& CREATURE_FLAG_EXTRA_NO_PARRY
)
2649 // Ignore combat result aura
2650 AuraList
const& ignore
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
2651 for(AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
2653 if (!(*i
)->isAffectedOnSpell(spell
))
2655 switch((*i
)->GetModifier()->m_miscvalue
)
2657 case MELEE_HIT_DODGE
: canDodge
= false; break;
2658 case MELEE_HIT_BLOCK
: break; // Block check in hit step
2659 case MELEE_HIT_PARRY
: canParry
= false; break;
2661 DEBUG_LOG("Spell %u SPELL_AURA_IGNORE_COMBAT_RESULT have unhandled state %d", (*i
)->GetId(), (*i
)->GetModifier()->m_miscvalue
);
2669 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
2670 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2671 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
)*100;
2672 // Reduce dodge chance by attacker expertise rating
2673 if (GetTypeId() == TYPEID_PLAYER
)
2674 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2676 dodgeChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2677 if (dodgeChance
< 0)
2682 return SPELL_MISS_DODGE
;
2688 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
2689 // Reduce parry chance by attacker expertise rating
2690 if (GetTypeId() == TYPEID_PLAYER
)
2691 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2693 parryChance
-= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE
)*25;
2694 if (parryChance
< 0)
2699 return SPELL_MISS_PARRY
;
2702 return SPELL_MISS_NONE
;
2705 // TODO need use unit spell resistances in calculations
2706 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2708 // Can`t miss on dead target (on skinning for example)
2709 if (!pVictim
->isAlive())
2710 return SPELL_MISS_NONE
;
2712 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
2713 // PvP - PvE spell misschances per leveldif > 2
2714 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
2715 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2717 // Base hit chance from attacker and victim levels
2720 modHitChance
= 96 - leveldif
;
2722 modHitChance
= 94 - (leveldif
- 2) * lchance
;
2724 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2725 if(Player
*modOwner
= GetSpellModOwner())
2726 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
2727 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
2728 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
2729 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
2730 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
2731 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
2732 if (IsAreaOfEffectSpell(spell
))
2733 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
2734 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
2735 if (IsDispelSpell(spell
))
2736 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
2737 // Chance resist mechanic (select max value from every mechanic spell effect)
2738 int32 resist_mech
= 0;
2739 // Get effects mechanic and chance
2740 for(int eff
= 0; eff
< 3; ++eff
)
2742 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2745 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2746 if (resist_mech
< temp
)
2751 modHitChance
-=resist_mech
;
2753 // Chance resist debuff
2754 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
2756 int32 HitChance
= modHitChance
* 100;
2757 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
2758 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
2760 // Decrease hit chance from victim rating bonus
2761 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2762 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
2764 if (HitChance
< 100) HitChance
= 100;
2765 if (HitChance
> 10000) HitChance
= 10000;
2767 int32 tmp
= 10000 - HitChance
;
2769 uint32 rand
= urand(0,10000);
2772 return SPELL_MISS_MISS
;
2774 // cast by caster in front of victim
2775 if (pVictim
->HasInArc(M_PI
,this))
2777 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2778 tmp
+=deflect_chance
;
2780 return SPELL_MISS_DEFLECT
;
2783 return SPELL_MISS_NONE
;
2786 // Calculate spell hit result can be:
2787 // Every spell can: Evade/Immune/Reflect/Sucesful hit
2788 // For melee based spells:
2794 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
2796 // Return evade for units in evade mode
2797 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2798 return SPELL_MISS_EVADE
;
2801 if (pVictim
->IsImmunedToSpell(spell
))
2802 return SPELL_MISS_IMMUNE
;
2804 // All positive spells can`t miss
2805 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
2806 if (IsPositiveSpell(spell
->Id
))
2807 return SPELL_MISS_NONE
;
2810 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
)))
2811 return SPELL_MISS_IMMUNE
;
2813 // Try victim reflect spell
2816 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
2817 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
2818 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
2819 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
2820 reflectchance
+= (*i
)->GetModifier()->m_amount
;
2821 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
2823 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
2824 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
2825 return SPELL_MISS_REFLECT
;
2829 switch (spell
->DmgClass
)
2831 case SPELL_DAMAGE_CLASS_RANGED
:
2832 case SPELL_DAMAGE_CLASS_MELEE
:
2833 return MeleeSpellHitResult(pVictim
, spell
);
2834 case SPELL_DAMAGE_CLASS_NONE
:
2835 case SPELL_DAMAGE_CLASS_MAGIC
:
2836 return MagicSpellHitResult(pVictim
, spell
);
2838 return SPELL_MISS_NONE
;
2841 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
2846 // Base misschance 5%
2847 float misschance
= 5.0f
;
2849 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
2850 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
2852 bool isNormal
= false;
2853 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; ++i
)
2855 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
2861 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
2867 // PvP : PvE melee misschances per leveldif > 2
2868 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2870 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2874 // Hit chance from attacker based on ratings and auras
2875 float m_modHitChance
;
2876 if (attType
== RANGED_ATTACK
)
2877 m_modHitChance
= m_modRangedHitChance
;
2879 m_modHitChance
= m_modMeleeHitChance
;
2882 misschance
+= (leveldif
- m_modHitChance
);
2884 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
2886 // Hit chance for victim based on ratings
2887 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2889 if (attType
== RANGED_ATTACK
)
2890 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
2892 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
2895 // Modify miss chance by victim auras
2896 if(attType
== RANGED_ATTACK
)
2897 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2899 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2901 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
2902 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
2903 misschance
-= skillBonus
* 0.04f
;
2905 // Limit miss chance from 0 to 60%
2906 if ( misschance
< 0.0f
)
2908 if ( misschance
> 60.0f
)
2914 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
2916 if(GetTypeId() == TYPEID_PLAYER
)
2918 // in PvP use full skill instead current skill value
2919 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
2920 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
2921 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
2922 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
2926 return GetUnitMeleeSkill(target
);
2929 float Unit::GetUnitDodgeChance() const
2931 if(hasUnitState(UNIT_STAT_STUNNED
))
2933 if( GetTypeId() == TYPEID_PLAYER
)
2934 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
2937 if(((Creature
const*)this)->isTotem())
2942 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
2943 return dodge
> 0.0f
? dodge
: 0.0f
;
2948 float Unit::GetUnitParryChance() const
2950 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
2953 float chance
= 0.0f
;
2955 if(GetTypeId() == TYPEID_PLAYER
)
2957 Player
const* player
= (Player
const*)this;
2958 if(player
->CanParry() )
2960 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true,true);
2962 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true,true);
2965 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
2968 else if(GetTypeId() == TYPEID_UNIT
)
2970 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
2973 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
2977 return chance
> 0.0f
? chance
: 0.0f
;
2980 float Unit::GetUnitBlockChance() const
2982 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
2985 if(GetTypeId() == TYPEID_PLAYER
)
2987 Player
const* player
= (Player
const*)this;
2988 if(player
->CanBlock() )
2990 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
2991 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
2992 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
2994 // is player but has no block ability or no not broken shield equipped
2999 if(((Creature
const*)this)->isTotem())
3004 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
3005 return block
> 0.0f
? block
: 0.0f
;
3010 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
3014 if(GetTypeId() == TYPEID_PLAYER
)
3019 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
3022 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
3025 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
3027 // Just for good manner
3036 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
3040 if(attackType
== RANGED_ATTACK
)
3041 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
3043 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
3045 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
3047 // reduce crit chance from Rating for players
3048 if (attackType
!= RANGED_ATTACK
)
3049 crit
-= pVictim
->GetMeleeCritChanceReduction();
3051 crit
-= pVictim
->GetRangedCritChanceReduction();
3053 // Apply crit chance from defence skill
3054 crit
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
3061 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
3064 if(GetTypeId() == TYPEID_PLAYER
)
3066 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true,true);
3068 // feral or unarmed skill only for base attack
3069 if(attType
!= BASE_ATTACK
&& !item
)
3073 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
3075 // weapon skill or (unarmed for base attack)
3076 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
3078 // in PvP use full skill instead current skill value
3079 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3080 ? ((Player
*)this)->GetMaxSkillValue(skill
)
3081 : ((Player
*)this)->GetSkillValue(skill
);
3082 // Modify value from ratings
3083 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
3086 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
3087 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
3088 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
3092 value
= GetUnitMeleeSkill(target
);
3096 void Unit::_UpdateSpells( uint32 time
)
3098 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
3099 _UpdateAutoRepeatSpell();
3101 // remove finished spells from current pointers
3102 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3104 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
3106 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
3107 m_currentSpells
[i
] = NULL
; // remove pointer
3112 // m_AurasUpdateIterator can be updated in inderect called code at aura remove to skip next planned to update but removed auras
3113 for (m_AurasUpdateIterator
= m_Auras
.begin(); m_AurasUpdateIterator
!= m_Auras
.end();)
3115 Aura
* i_aura
= m_AurasUpdateIterator
->second
;
3116 ++m_AurasUpdateIterator
; // need shift to next for allow update if need into aura update
3117 i_aura
->UpdateAura(time
);
3120 // remove expired auras
3121 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
3125 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
3134 if(!m_gameObj
.empty())
3136 GameObjectList::iterator ite1
, dnext1
;
3137 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
3140 //(*i)->Update( difftime );
3141 if( !(*ite1
)->isSpawned() )
3143 (*ite1
)->SetOwnerGUID(0);
3144 (*ite1
)->SetRespawnTime(0);
3146 dnext1
= m_gameObj
.erase(ite1
);
3154 void Unit::_UpdateAutoRepeatSpell()
3156 //check "realtime" interrupts
3157 if ( (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) )
3159 // cancel wand shoot
3160 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3161 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3162 m_AutoRepeatFirstCast
= true;
3167 if ( m_AutoRepeatFirstCast
&& getAttackTimer(RANGED_ATTACK
) < 500 )
3168 setAttackTimer(RANGED_ATTACK
,500);
3169 m_AutoRepeatFirstCast
= false;
3172 if (isAttackReady(RANGED_ATTACK
))
3174 // Check if able to cast
3175 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CheckCast(true) != SPELL_CAST_OK
)
3177 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3182 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
3183 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
3185 // all went good, reset attack
3186 resetAttackTimer(RANGED_ATTACK
);
3190 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
3192 assert(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
3194 CurrentSpellTypes CSpellType
= pSpell
->GetCurrentContainer();
3196 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
3198 // break same type spell if it is not delayed
3199 InterruptSpell(CSpellType
,false);
3201 // special breakage effects:
3204 case CURRENT_GENERIC_SPELL
:
3206 // generic spells always break channeled not delayed spells
3207 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3209 // autorepeat breaking
3210 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3212 // break autorepeat if not Auto Shot
3213 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3214 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3215 m_AutoRepeatFirstCast
= true;
3219 case CURRENT_CHANNELED_SPELL
:
3221 // channel spells always break generic non-delayed and any channeled spells
3222 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3223 InterruptSpell(CURRENT_CHANNELED_SPELL
);
3225 // it also does break autorepeat if not Auto Shot
3226 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
3227 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3228 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3231 case CURRENT_AUTOREPEAT_SPELL
:
3233 // only Auto Shoot does not break anything
3234 if (pSpell
->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3236 // generic autorepeats break generic non-delayed and channeled non-delayed spells
3237 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3238 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3240 // special action: set first cast flag
3241 m_AutoRepeatFirstCast
= true;
3246 // other spell types don't break anything now
3250 // current spell (if it is still here) may be safely deleted now
3251 if (m_currentSpells
[CSpellType
])
3252 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
3254 // set new current spell
3255 m_currentSpells
[CSpellType
] = pSpell
;
3256 pSpell
->SetReferencedFromCurrent(true);
3258 pSpell
->m_selfContainer
= &(m_currentSpells
[pSpell
->GetCurrentContainer()]);
3261 void Unit::InterruptSpell(CurrentSpellTypes spellType
, bool withDelayed
)
3263 assert(spellType
< CURRENT_MAX_SPELL
);
3265 if (m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
3267 // send autorepeat cancel message for autorepeat spells
3268 if (spellType
== CURRENT_AUTOREPEAT_SPELL
)
3270 if(GetTypeId() == TYPEID_PLAYER
)
3271 ((Player
*)this)->SendAutoRepeatCancel(this);
3274 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
3275 m_currentSpells
[spellType
]->cancel();
3277 // cancel can interrupt spell already (caster cancel ->target aura remove -> caster iterrupt)
3278 if (m_currentSpells
[spellType
])
3280 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
3281 m_currentSpells
[spellType
] = NULL
;
3286 void Unit::FinishSpell(CurrentSpellTypes spellType
, bool ok
/*= true*/)
3288 Spell
* spell
= m_currentSpells
[spellType
];
3292 if (spellType
== CURRENT_CHANNELED_SPELL
)
3293 spell
->SendChannelUpdate(0);
3299 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
3301 // We don't do loop here to explicitly show that melee spell is excluded.
3302 // Maybe later some special spells will be excluded too.
3304 // generic spells are casted when they are not finished and not delayed
3305 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
3306 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3307 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3310 // channeled spells may be delayed, but they are still considered casted
3311 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
3312 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
3315 // autorepeat spells may be finished or delayed, but they are still considered casted
3316 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3322 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
3324 // generic spells are interrupted if they are not finished or delayed
3325 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
3326 InterruptSpell(CURRENT_GENERIC_SPELL
,withDelayed
);
3328 // autorepeat spells are interrupted if they are not finished or delayed
3329 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
3330 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
,withDelayed
);
3332 // channeled spells are interrupted if they are not finished, even if they are delayed
3333 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
3334 InterruptSpell(CURRENT_CHANNELED_SPELL
,true);
3337 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
3339 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; ++i
)
3340 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
3341 return m_currentSpells
[i
];
3345 void Unit::SetInFront(Unit
const* target
)
3347 SetOrientation(GetAngle(target
));
3350 void Unit::SetFacingTo(float ori
)
3352 // update orientation at server
3353 SetOrientation(ori
);
3357 BuildHeartBeatMsg(&data
);
3358 SendMessageToSet(&data
, false);
3361 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
3364 return c
->canSwim();
3366 return c
->canWalk() || c
->canFly();
3369 bool Unit::IsInWater() const
3371 return GetBaseMap()->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
3374 bool Unit::IsUnderWater() const
3376 return GetBaseMap()->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3379 void Unit::DeMorph()
3381 SetDisplayId(GetNativeDisplayId());
3384 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3388 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3389 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3390 modifier
+= (*i
)->GetModifier()->m_amount
;
3395 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3397 float multiplier
= 1.0f
;
3399 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3400 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3401 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3406 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3410 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3411 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3412 if ((*i
)->GetModifier()->m_amount
> modifier
)
3413 modifier
= (*i
)->GetModifier()->m_amount
;
3418 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
3422 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3423 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3424 if ((*i
)->GetModifier()->m_amount
< modifier
)
3425 modifier
= (*i
)->GetModifier()->m_amount
;
3430 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3437 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3438 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3440 Modifier
* mod
= (*i
)->GetModifier();
3441 if (mod
->m_miscvalue
& misc_mask
)
3442 modifier
+= mod
->m_amount
;
3447 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3452 float multiplier
= 1.0f
;
3454 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3455 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3457 Modifier
* mod
= (*i
)->GetModifier();
3458 if (mod
->m_miscvalue
& misc_mask
)
3459 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3464 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3471 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3472 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3474 Modifier
* mod
= (*i
)->GetModifier();
3475 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
> modifier
)
3476 modifier
= mod
->m_amount
;
3482 int32
Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3489 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3490 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3492 Modifier
* mod
= (*i
)->GetModifier();
3493 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
< modifier
)
3494 modifier
= mod
->m_amount
;
3500 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3504 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3505 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3507 Modifier
* mod
= (*i
)->GetModifier();
3508 if (mod
->m_miscvalue
== misc_value
)
3509 modifier
+= mod
->m_amount
;
3514 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
3516 float multiplier
= 1.0f
;
3518 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3519 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3521 Modifier
* mod
= (*i
)->GetModifier();
3522 if (mod
->m_miscvalue
== misc_value
)
3523 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3528 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3532 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3533 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3535 Modifier
* mod
= (*i
)->GetModifier();
3536 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
3537 modifier
= mod
->m_amount
;
3543 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3547 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3548 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3550 Modifier
* mod
= (*i
)->GetModifier();
3551 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
< modifier
)
3552 modifier
= mod
->m_amount
;
3558 float Unit::GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype
, uint32 mask
) const
3563 float multiplier
= 1.0f
;
3565 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3566 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3568 Modifier
* mod
= (*i
)->GetModifier();
3569 if (mask
& (1 << (mod
->m_miscvalue
-1)))
3570 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3575 bool Unit::AddAura(Aura
*Aur
)
3577 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
3579 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
3580 if( !isAlive() && !IsDeathPersistentSpell(aurSpellInfo
) &&
3581 !IsDeathOnlySpell(aurSpellInfo
) &&
3582 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
3588 if(Aur
->GetTarget() != this)
3590 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
3591 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
3592 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
3597 // m_auraname can be modified to SPELL_AURA_NONE for area auras, this expected for this value
3598 AuraType aurName
= Aur
->GetModifier()->m_auraname
;
3600 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
3601 AuraMap::iterator i
= m_Auras
.find( spair
);
3603 // take out same spell
3604 if (i
!= m_Auras
.end())
3606 // passive and persistent auras can stack with themselves any number of times
3607 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
3609 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
3611 Aura
* aur2
= i2
->second
;
3612 if(aur2
->GetCasterGUID()==Aur
->GetCasterGUID())
3614 // Aura can stack on self -> Stack it;
3615 if(aurSpellInfo
->StackAmount
)
3617 // can be created with >1 stack by some spell mods
3618 aur2
->modStackAmount(Aur
->GetStackAmount());
3622 // Carry over removed Aura's remaining damage if Aura still has ticks remaining
3623 else if (aur2
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_STACK_DOT_MODIFIER
&& aurName
== SPELL_AURA_PERIODIC_DAMAGE
&& aur2
->GetAuraDuration() > 0)
3625 int32 remainingTicks
= aur2
->GetAuraMaxTicks() - aur2
->GetAuraTicks();
3626 int32 remainingDamage
= aur2
->GetModifier()->m_amount
* remainingTicks
;
3628 Aur
->GetModifier()->m_amount
+= int32(remainingDamage
/ Aur
->GetAuraMaxTicks());
3630 // can be only single (this check done at _each_ aura add
3631 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3637 // m_auraname can be modified to SPELL_AURA_NONE for area auras, use original
3638 AuraType aurNameReal
= AuraType(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()]);
3643 case SPELL_AURA_DUMMY
: // allow stack
3644 case SPELL_AURA_PERIODIC_DAMAGE
:
3645 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
3646 case SPELL_AURA_PERIODIC_LEECH
:
3647 case SPELL_AURA_PERIODIC_HEAL
:
3648 case SPELL_AURA_OBS_MOD_HEALTH
:
3649 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3650 case SPELL_AURA_OBS_MOD_MANA
:
3651 case SPELL_AURA_POWER_BURN_MANA
:
3653 case SPELL_AURA_PERIODIC_ENERGIZE
: // all or self or clear non-stackable
3654 default: // not allow
3655 // can be only single (this check done at _each_ aura add
3656 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3667 // passive auras not stacable with other ranks
3668 if (!IsPassiveSpellStackableWithRanks(aurSpellInfo
))
3670 if (!RemoveNoStackAurasDueToAura(Aur
))
3673 return false; // couldn't remove conflicting aura with higher rank
3677 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
3678 if (Aur
->IsSingleTarget() && Aur
->GetTarget())
3680 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
3683 Unit
* caster
= Aur
->GetCaster();
3684 if(!caster
) // caster deleted and not required adding scAura
3687 bool restart
= false;
3688 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3689 for(AuraList::const_iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
3691 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
3692 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
3694 if ((*itr
)->IsInUse())
3696 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());
3699 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
3708 scAuras
.push_back(Aur
);
3714 // add aura, register in lists and arrays
3716 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
3717 if (aurName
< TOTAL_AURAS
)
3719 m_modAuras
[aurName
].push_back(Aur
);
3722 Aur
->ApplyModifier(true,true);
3723 sLog
.outDebug("Aura %u now is in use", aurName
);
3725 // if aura deleted before boosts apply ignore
3726 // this can be possible it it removed indirectly by triggered spell effect at ApplyModifier
3727 if (Aur
->IsDeleted())
3730 if(IsSpellLastAuraEffect(aurSpellInfo
,Aur
->GetEffIndex()))
3731 Aur
->HandleSpellSpecificBoosts(true);
3736 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
3738 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3741 AuraMap::const_iterator i
,next
;
3742 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3746 uint32 i_spellId
= (*i
).second
->GetId();
3747 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
3749 if(sSpellMgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
3751 RemoveAurasDueToSpell(i_spellId
);
3753 if( m_Auras
.empty() )
3756 next
= m_Auras
.begin();
3762 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
3767 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
3771 uint32 spellId
= Aur
->GetId();
3772 uint32 effIndex
= Aur
->GetEffIndex();
3774 // passive spell special case (only non stackable with ranks)
3775 if(IsPassiveSpell(spellId
))
3777 if(IsPassiveSpellStackableWithRanks(spellProto
))
3781 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
3783 AuraMap::iterator i
,next
;
3784 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3788 if (!(*i
).second
) continue;
3790 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
3795 uint32 i_spellId
= i_spellProto
->Id
;
3797 // early checks that spellId is passive non stackable spell
3798 if(IsPassiveSpell(i_spellId
))
3800 // passive non-stackable spells not stackable only for same caster
3801 if(Aur
->GetCasterGUID()!=i
->second
->GetCasterGUID())
3804 // passive non-stackable spells not stackable only with another rank of same spell
3805 if (!sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3809 uint32 i_effIndex
= (*i
).second
->GetEffIndex();
3811 if(i_spellId
== spellId
) continue;
3813 bool is_triggered_by_spell
= false;
3814 // prevent triggering aura of removing aura that triggered it
3815 for(int j
= 0; j
< 3; ++j
)
3816 if (i_spellProto
->EffectTriggerSpell
[j
] == spellId
)
3817 is_triggered_by_spell
= true;
3819 // prevent triggered aura of removing aura that triggering it (triggered effect early some aura of parent spell
3820 for(int j
= 0; j
< 3; ++j
)
3821 if (spellProto
->EffectTriggerSpell
[j
] == i_spellId
)
3822 is_triggered_by_spell
= true;
3824 if (is_triggered_by_spell
)
3827 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
3829 // single allowed spell specific from same caster or from any caster at target
3830 bool is_spellSpecPerTargetPerCaster
= IsSingleFromSpellSpecificPerTargetPerCaster(spellId_spec
,i_spellId_spec
);
3831 bool is_spellSpecPerTarget
= IsSingleFromSpellSpecificPerTarget(spellId_spec
,i_spellId_spec
);
3832 if( is_spellSpecPerTarget
|| is_spellSpecPerTargetPerCaster
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
3834 // cannot remove higher rank
3835 if (sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3836 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3839 // Its a parent aura (create this aura in ApplyModifier)
3840 if ((*i
).second
->IsInUse())
3842 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());
3845 RemoveAurasDueToSpell(i_spellId
);
3847 if( m_Auras
.empty() )
3850 next
= m_Auras
.begin();
3855 // spell with spell specific that allow single ranks for spell from diff caster
3856 // same caster case processed or early or later
3857 bool is_spellPerTarget
= IsSingleFromSpellSpecificSpellRanksPerTarget(spellId_spec
,i_spellId_spec
);
3858 if ( is_spellPerTarget
&& Aur
->GetCasterGUID() != (*i
).second
->GetCasterGUID() && sSpellMgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3860 // cannot remove higher rank
3861 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3864 // Its a parent aura (create this aura in ApplyModifier)
3865 if ((*i
).second
->IsInUse())
3867 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());
3870 RemoveAurasDueToSpell(i_spellId
);
3872 if( m_Auras
.empty() )
3875 next
= m_Auras
.begin();
3880 // non single (per caster) per target spell specific (possible single spell per target at caster)
3881 if( !is_spellSpecPerTargetPerCaster
&& !is_spellSpecPerTarget
&& sSpellMgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
3883 // Its a parent aura (create this aura in ApplyModifier)
3884 if ((*i
).second
->IsInUse())
3886 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());
3889 RemoveAurasDueToSpell(i_spellId
);
3891 if( m_Auras
.empty() )
3894 next
= m_Auras
.begin();
3899 // Potions stack aura by aura (elixirs/flask already checked)
3900 if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
3902 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
3904 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3905 return false; // cannot remove higher rank
3907 // Its a parent aura (create this aura in ApplyModifier)
3908 if ((*i
).second
->IsInUse())
3910 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());
3921 void Unit::RemoveAura(uint32 spellId
, uint32 effindex
, Aura
* except
)
3923 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
3924 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
3926 if(iter
->second
!=except
)
3929 iter
= m_Auras
.lower_bound(spair
);
3936 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
)
3938 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3940 Aura
*aur
= iter
->second
;
3941 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3948 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint32 effindex
, uint64 casterGUID
)
3950 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
3951 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
3953 Aura
*aur
= iter
->second
;
3954 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3957 iter
= m_Auras
.lower_bound(spair
);
3964 void Unit::RemoveSingleAuraDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
3966 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(spellId
);
3968 // Custom dispel cases
3969 // Unstable Affliction
3970 if(spellEntry
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x010000000000)))
3972 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
,SPELLFAMILY_WARLOCK
,UI64LIT(0x010000000000),0x00000000,casterGUID
))
3974 int32 damage
= dotAura
->GetModifier()->m_amount
*9;
3976 // Remove spell auras from stack
3977 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
3979 // backfire damage and silence
3980 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,casterGUID
);
3985 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (spellEntry
->SpellFamilyFlags
& UI64LIT(0x10000000)))
3987 Unit
* caster
= NULL
;
3988 uint32 triggeredSpell
= 0;
3990 if (Aura
* dotAura
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x10000000), 0x00000000, casterGUID
))
3991 caster
= dotAura
->GetCaster();
3993 if (caster
&& !caster
->isDead())
3995 Unit::AuraList
const& auras
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
3996 for (Unit::AuraList::const_iterator i
= auras
.begin(); i
!= auras
.end(); ++i
)
3998 switch((*i
)->GetId())
4000 case 51480: triggeredSpell
=64694; break;// Lava Flows, Rank 1
4001 case 51481: triggeredSpell
=65263; break;// Lava Flows, Rank 2
4002 case 51482: triggeredSpell
=65264; break;// Lava Flows, Rank 3
4009 // Remove spell auras from stack
4010 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4014 caster
->CastSpell(caster
, triggeredSpell
, true);
4017 // Vampiric touch (first dummy aura)
4018 else if (spellEntry
->SpellFamilyName
== SPELLFAMILY_PRIEST
&& spellEntry
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
4020 if (Aura
*dot
= GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000040000000000), 0x00000000, casterGUID
))
4022 if(Unit
* caster
= dot
->GetCaster())
4024 int32 bp0
= dot
->GetModifier()->m_amount
;
4025 bp0
= 8 * caster
->SpellDamageBonus(this, spellEntry
, bp0
, DOT
, 1);
4027 // Remove spell auras from stack
4028 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4030 CastCustomSpell(this, 64085, &bp0
, NULL
, NULL
, true, NULL
, NULL
, casterGUID
);
4036 RemoveSingleSpellAurasByCasterSpell(spellId
, casterGUID
, AURA_REMOVE_BY_DISPEL
);
4039 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
4041 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4043 Aura
*aur
= iter
->second
;
4044 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4046 int32 basePoints
= aur
->GetBasePoints();
4047 // construct the new aura for the attacker - will never return NULL, it's just a wrapper for
4048 // some different constructors
4049 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
, this);
4051 // set its duration and maximum duration
4052 // max duration 2 minutes (in msecs)
4053 int32 dur
= aur
->GetAuraDuration();
4054 int32 max_dur
= 2*MINUTE
*IN_MILISECONDS
;
4055 int32 new_max_dur
= max_dur
> dur
? dur
: max_dur
;
4056 new_aur
->SetAuraMaxDuration( new_max_dur
);
4057 new_aur
->SetAuraDuration( new_max_dur
);
4059 // set periodic to do at least one tick (for case when original aura has been at last tick preparing)
4060 int32 periodic
= aur
->GetModifier()->periodictime
;
4061 new_aur
->GetModifier()->periodictime
= periodic
< new_max_dur
? periodic
: new_max_dur
;
4063 // Unregister _before_ adding to stealer
4064 aur
->UnregisterSingleCastAura();
4066 // strange but intended behaviour: Stolen single target auras won't be treated as single targeted
4067 new_aur
->SetIsSingleTarget(false);
4069 // add the new aura to stealer
4070 stealer
->AddAura(new_aur
);
4072 // Remove aura as dispel
4073 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
4080 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
4082 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4084 if (iter
->second
->GetId() == spellId
)
4085 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
4091 void Unit::RemoveAurasWithDispelType( DispelType type
)
4093 // Create dispel mask by dispel type
4094 uint32 dispelMask
= GetDispellMask(type
);
4095 // Dispel all existing auras vs current dispel type
4096 AuraMap
& auras
= GetAuras();
4097 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
4099 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
4100 if( (1<<spell
->Dispel
) & dispelMask
)
4103 RemoveAurasDueToSpell(spell
->Id
);
4104 itr
= auras
.begin();
4111 void Unit::RemoveSingleAuraFromStack(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4113 if (i
->second
->modStackAmount(-1))
4118 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, uint32 effindex
, AuraRemoveMode mode
)
4120 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4121 if(iter
!= m_Auras
.end())
4122 RemoveSingleAuraFromStack(iter
,mode
);
4125 void Unit::RemoveSingleSpellAurasFromStack(uint32 spellId
, AuraRemoveMode mode
)
4127 for (int i
=0; i
<3; ++i
)
4128 RemoveSingleAuraFromStack(spellId
, i
, mode
);
4131 void Unit::RemoveSingleSpellAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
, AuraRemoveMode mode
)
4133 for (int i
=0; i
<3; ++i
)
4134 RemoveSingleAuraByCasterSpell(spellId
, i
, casterGUID
, mode
);
4137 void Unit::RemoveSingleAuraByCasterSpell(uint32 spellId
, uint32 effindex
, uint64 casterGUID
, AuraRemoveMode mode
)
4139 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4140 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
); ++iter
)
4142 Aura
*aur
= iter
->second
;
4143 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4145 RemoveSingleAuraFromStack(iter
,mode
);
4152 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
)
4154 for (int i
= 0; i
< 3; ++i
)
4155 RemoveAura(spellId
,i
,except
);
4158 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
4160 for (int k
=0; k
< 3; ++k
)
4162 spellEffectPair spair
= spellEffectPair(spellId
, k
);
4163 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4165 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
4168 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
4176 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
4178 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4180 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
4187 void Unit::RemoveNotOwnSingleTargetAuras(uint32 newPhase
)
4189 // single target auras from other casters
4190 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4192 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
4198 Unit
* caster
= iter
->second
->GetCaster();
4199 if(!caster
|| !caster
->InSamePhase(newPhase
))
4209 // single target auras at other targets
4210 AuraList
& scAuras
= GetSingleCastAuras();
4211 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
4214 if (aura
->GetTarget() != this && !aura
->GetTarget()->InSamePhase(newPhase
))
4216 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
4217 aura
->GetTarget()->RemoveAura(aura
);
4218 iter
= scAuras
.begin();
4226 void Unit::RemoveAura(Aura
* aura
, AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4228 AuraMap::iterator i
= m_Auras
.lower_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4229 AuraMap::iterator upperBound
= m_Auras
.upper_bound(spellEffectPair(aura
->GetId(), aura
->GetEffIndex()));
4230 for (; i
!= upperBound
; ++i
)
4232 if (i
->second
== aura
)
4238 sLog
.outDebug("Trying to remove aura id %u effect %u by pointer but aura not found on target", aura
->GetId(), aura
->GetEffIndex());
4241 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4243 Aura
* Aur
= i
->second
;
4244 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
4246 Aur
->UnregisterSingleCastAura();
4248 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
4249 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
4251 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
4255 Aur
->SetRemoveMode(mode
);
4257 // if unit currently update aura list then make safe update iterator shift to next
4258 if (m_AurasUpdateIterator
== i
)
4259 ++m_AurasUpdateIterator
;
4261 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
4262 // remove aura from list before to prevent deleting it before
4265 // now aura removed from from list and can't be deleted by indirect call but can be referenced from callers
4267 // Statue unsummoned at aura remove
4268 Totem
* statue
= NULL
;
4269 if(IsChanneledSpell(AurSpellInfo
))
4270 if(Unit
* caster
= Aur
->GetCaster())
4271 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
4272 statue
= ((Totem
*)caster
);
4274 sLog
.outDebug("Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
4275 if (mode
!= AURA_REMOVE_BY_DELETE
) // not unapply if target will deleted
4276 Aur
->ApplyModifier(false,true);
4278 if (Aur
->_RemoveAura())
4280 // last aura in stack removed
4281 if (mode
!= AURA_REMOVE_BY_DELETE
&& IsSpellLastAuraEffect(Aur
->GetSpellProto(),Aur
->GetEffIndex()))
4282 Aur
->HandleSpellSpecificBoosts(false);
4285 // If aura in use (removed from code that plan access to it data after return)
4286 // store it in aura list with delayed deletion
4288 m_deletedAuras
.push_back(Aur
);
4295 // only way correctly remove all auras from list
4296 if( m_Auras
.empty() )
4299 i
= m_Auras
.begin();
4303 void Unit::RemoveAllAuras(AuraRemoveMode mode
/*= AURA_REMOVE_BY_DEFAULT*/)
4305 while (!m_Auras
.empty())
4307 AuraMap::iterator iter
= m_Auras
.begin();
4308 RemoveAura(iter
,mode
);
4312 void Unit::RemoveArenaAuras(bool onleave
)
4314 // in join, remove positive buffs, on end, remove negative
4315 // used to remove positive visible auras in arenas
4316 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4318 if (!(iter
->second
->GetSpellProto()->AttributesEx4
& SPELL_ATTR_EX4_UNK21
) &&
4319 // don't remove stances, shadowform, pally/hunter auras
4320 !iter
->second
->IsPassive() && // don't remove passive auras
4321 (!(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
) ||
4322 !(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNK8
)) &&
4323 // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable)
4324 (iter
->second
->IsPositive() != onleave
)) // remove positive buffs on enter, negative buffs on leave
4331 void Unit::RemoveAllAurasOnDeath()
4333 // used just after dieing to remove all visible auras
4334 // and disable the mods for the passive ones
4335 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4337 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
4338 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
4344 void Unit::DelayAura(uint32 spellId
, uint32 effindex
, int32 delaytime
)
4346 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4347 if (iter
!= m_Auras
.end())
4349 if (iter
->second
->GetAuraDuration() < delaytime
)
4350 iter
->second
->SetAuraDuration(0);
4352 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
4353 iter
->second
->SendAuraUpdate(false);
4354 sLog
.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter
->second
->GetModifier()->m_auraname
, GetGUIDLow(), iter
->second
->GetAuraDuration());
4358 void Unit::_RemoveAllAuraMods()
4360 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4362 (*i
).second
->ApplyModifier(false);
4366 void Unit::_ApplyAllAuraMods()
4368 for (AuraMap::const_iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4370 (*i
).second
->ApplyModifier(true);
4374 Aura
* Unit::GetAura(uint32 spellId
, uint32 effindex
)
4376 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4377 if (iter
!= m_Auras
.end())
4378 return iter
->second
;
4382 Aura
* Unit::GetAura(AuraType type
, uint32 family
, uint64 familyFlag
, uint32 familyFlag2
, uint64 casterGUID
)
4384 AuraList
const& auras
= GetAurasByType(type
);
4385 for(AuraList::const_iterator i
= auras
.begin();i
!= auras
.end(); ++i
)
4387 SpellEntry
const *spell
= (*i
)->GetSpellProto();
4388 if (spell
->SpellFamilyName
== family
&& (spell
->SpellFamilyFlags
& familyFlag
|| spell
->SpellFamilyFlags2
& familyFlag2
))
4390 if (casterGUID
&& (*i
)->GetCasterGUID()!=casterGUID
)
4398 bool Unit::HasAura(uint32 spellId
) const
4400 for (int i
= 0; i
< 3 ; ++i
)
4402 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, i
));
4403 if (iter
!= m_Auras
.end())
4409 void Unit::AddDynObject(DynamicObject
* dynObj
)
4411 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
4414 void Unit::RemoveDynObject(uint32 spellid
)
4416 if(m_dynObjGUIDs
.empty())
4418 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4420 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4423 i
= m_dynObjGUIDs
.erase(i
);
4425 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
4428 i
= m_dynObjGUIDs
.erase(i
);
4435 void Unit::RemoveAllDynObjects()
4437 while(!m_dynObjGUIDs
.empty())
4439 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*m_dynObjGUIDs
.begin());
4442 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
4446 DynamicObject
* Unit::GetDynObject(uint32 spellId
, uint32 effIndex
)
4448 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4450 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4453 i
= m_dynObjGUIDs
.erase(i
);
4457 if (dynObj
->GetSpellId() == spellId
&& dynObj
->GetEffIndex() == effIndex
)
4464 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
4466 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4468 DynamicObject
* dynObj
= GetMap()->GetDynamicObject(*i
);
4471 i
= m_dynObjGUIDs
.erase(i
);
4475 if (dynObj
->GetSpellId() == spellId
)
4482 GameObject
* Unit::GetGameObject(uint32 spellId
) const
4484 for (GameObjectList::const_iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); ++i
)
4485 if ((*i
)->GetSpellId() == spellId
)
4491 void Unit::AddGameObject(GameObject
* gameObj
)
4493 assert(gameObj
&& gameObj
->GetOwnerGUID()==0);
4494 m_gameObj
.push_back(gameObj
);
4495 gameObj
->SetOwnerGUID(GetGUID());
4497 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
4499 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
4500 // Need disable spell use for owner
4501 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4502 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4503 ((Player
*)this)->AddSpellAndCategoryCooldowns(createBySpell
,0,NULL
,true);
4507 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
4509 assert(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
4511 gameObj
->SetOwnerGUID(0);
4513 // GO created by some spell
4514 if (uint32 spellid
= gameObj
->GetSpellId())
4516 RemoveAurasDueToSpell(spellid
);
4518 if (GetTypeId()==TYPEID_PLAYER
)
4520 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(spellid
);
4521 // Need activate spell use for owner
4522 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4523 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4524 ((Player
*)this)->SendCooldownEvent(createBySpell
);
4528 m_gameObj
.remove(gameObj
);
4532 gameObj
->SetRespawnTime(0);
4537 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
4539 if(m_gameObj
.empty())
4541 GameObjectList::iterator i
, next
;
4542 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
4545 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
4547 (*i
)->SetOwnerGUID(0);
4550 (*i
)->SetRespawnTime(0);
4554 next
= m_gameObj
.erase(i
);
4561 void Unit::RemoveAllGameObjects()
4563 // remove references to unit
4564 for(GameObjectList::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4566 (*i
)->SetOwnerGUID(0);
4567 (*i
)->SetRespawnTime(0);
4569 i
= m_gameObj
.erase(i
);
4573 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
4575 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+4+1+4+4+1+1+4+4+1)); // we guess size
4576 data
.append(log
->target
->GetPackGUID());
4577 data
.append(log
->attacker
->GetPackGUID());
4578 data
<< uint32(log
->SpellID
);
4579 data
<< uint32(log
->damage
); // damage amount
4580 data
<< uint32(log
->overkill
); // overkill
4581 data
<< uint8 (log
->schoolMask
); // damage school
4582 data
<< uint32(log
->absorb
); // AbsorbedDamage
4583 data
<< uint32(log
->resist
); // resist
4584 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
4585 data
<< uint8 (log
->unused
); // unused
4586 data
<< uint32(log
->blocked
); // blocked
4587 data
<< uint32(log
->HitInfo
);
4588 data
<< uint8 (0); // flag to use extend data
4589 SendMessageToSet( &data
, true );
4592 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
, uint32 SpellID
, uint32 Damage
, SpellSchoolMask damageSchoolMask
, uint32 AbsorbedDamage
, uint32 Resist
, bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
4594 SpellNonMeleeDamage
log(this, target
, SpellID
, damageSchoolMask
);
4595 log
.damage
= Damage
- AbsorbedDamage
- Resist
- Blocked
;
4596 log
.absorb
= AbsorbedDamage
;
4597 log
.resist
= Resist
;
4598 log
.physicalLog
= PhysicalDamage
;
4599 log
.blocked
= Blocked
;
4600 log
.HitInfo
= SPELL_HIT_TYPE_UNK1
| SPELL_HIT_TYPE_UNK3
| SPELL_HIT_TYPE_UNK6
;
4602 log
.HitInfo
|= SPELL_HIT_TYPE_CRIT
;
4603 SendSpellNonMeleeDamageLog(&log
);
4606 void Unit::SendPeriodicAuraLog(SpellPeriodicAuraLogInfo
*pInfo
)
4608 Aura
*aura
= pInfo
->aura
;
4609 Modifier
*mod
= aura
->GetModifier();
4611 WorldPacket
data(SMSG_PERIODICAURALOG
, 30);
4612 data
.append(aura
->GetTarget()->GetPackGUID());
4613 data
.appendPackGUID(aura
->GetCasterGUID());
4614 data
<< uint32(aura
->GetId()); // spellId
4615 data
<< uint32(1); // count
4616 data
<< uint32(mod
->m_auraname
); // auraId
4617 switch(mod
->m_auraname
)
4619 case SPELL_AURA_PERIODIC_DAMAGE
:
4620 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
4621 data
<< uint32(pInfo
->damage
); // damage
4622 data
<< uint32(pInfo
->overDamage
); // overkill?
4623 data
<< uint32(GetSpellSchoolMask(aura
->GetSpellProto()));
4624 data
<< uint32(pInfo
->absorb
); // absorb
4625 data
<< uint32(pInfo
->resist
); // resist
4626 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4628 case SPELL_AURA_PERIODIC_HEAL
:
4629 case SPELL_AURA_OBS_MOD_HEALTH
:
4630 data
<< uint32(pInfo
->damage
); // damage
4631 data
<< uint32(pInfo
->overDamage
); // overheal?
4632 data
<< uint8(pInfo
->critical
? 1 : 0); // new 3.1.2 critical flag
4634 case SPELL_AURA_OBS_MOD_MANA
:
4635 case SPELL_AURA_PERIODIC_ENERGIZE
:
4636 data
<< uint32(mod
->m_miscvalue
); // power type
4637 data
<< uint32(pInfo
->damage
); // damage
4639 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4640 data
<< uint32(mod
->m_miscvalue
); // power type
4641 data
<< uint32(pInfo
->damage
); // amount
4642 data
<< float(pInfo
->multiplier
); // gain multiplier
4645 sLog
.outError("Unit::SendPeriodicAuraLog: unknown aura %u", uint32(mod
->m_auraname
));
4649 aura
->GetTarget()->SendMessageToSet(&data
, true);
4652 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
4654 // Not much to do if no flags are set.
4656 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
4657 // Now go on with a victim's events'n'auras
4658 // Not much to do if no flags are set or there is no victim
4659 if(pVictim
&& pVictim
->isAlive() && procVictim
)
4660 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4663 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4665 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4666 data
<< uint32(spellID
);
4667 data
<< uint64(GetGUID());
4668 data
<< uint8(0); // can be 0 or 1
4669 data
<< uint32(1); // target count
4670 // for(i = 0; i < target count; ++i)
4671 data
<< uint64(target
->GetGUID()); // target GUID
4672 data
<< uint8(missInfo
);
4674 SendMessageToSet(&data
, true);
4677 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4679 sLog
.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4682 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, 16 + 45); // we guess size
4683 data
<< uint32(damageInfo
->HitInfo
);
4684 data
.append(damageInfo
->attacker
->GetPackGUID());
4685 data
.append(damageInfo
->target
->GetPackGUID());
4686 data
<< uint32(damageInfo
->damage
); // Full damage
4687 data
<< uint32(0); // overkill value
4688 data
<< uint8(count
); // Sub damage count
4690 for(int i
= 0; i
< count
; ++i
)
4692 data
<< uint32(damageInfo
->damageSchoolMask
); // School of sub damage
4693 data
<< float(damageInfo
->damage
); // sub damage
4694 data
<< uint32(damageInfo
->damage
); // Sub Damage
4697 if(damageInfo
->HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4699 for(int i
= 0; i
< count
; ++i
)
4700 data
<< uint32(damageInfo
->absorb
); // Absorb
4703 if(damageInfo
->HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4705 for(int i
= 0; i
< count
; ++i
)
4706 data
<< uint32(damageInfo
->resist
); // Resist
4709 data
<< uint8(damageInfo
->TargetState
);
4713 if(damageInfo
->HitInfo
& HITINFO_BLOCK
)
4714 data
<< uint32(damageInfo
->blocked_amount
);
4716 if(damageInfo
->HitInfo
& HITINFO_UNK3
)
4719 if(damageInfo
->HitInfo
& HITINFO_UNK1
)
4730 for(uint8 i
= 0; i
< 5; ++i
)
4738 SendMessageToSet( &data
, true );
4741 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8 SwingType
, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4743 CalcDamageInfo dmgInfo
;
4744 dmgInfo
.HitInfo
= HitInfo
;
4745 dmgInfo
.attacker
= this;
4746 dmgInfo
.target
= target
;
4747 dmgInfo
.damage
= Damage
- AbsorbDamage
- Resist
- BlockedAmount
;
4748 dmgInfo
.damageSchoolMask
= damageSchoolMask
;
4749 dmgInfo
.absorb
= AbsorbDamage
;
4750 dmgInfo
.resist
= Resist
;
4751 dmgInfo
.TargetState
= TargetState
;
4752 dmgInfo
.blocked_amount
= BlockedAmount
;
4753 SendAttackStateUpdate(&dmgInfo
);
4756 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4758 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
4760 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4761 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4763 uint32 triggered_spell_id
= 0;
4764 Unit
* target
= pVictim
;
4765 int32 basepoints0
= 0;
4767 switch(hasteSpell
->SpellFamilyName
)
4769 case SPELLFAMILY_ROGUE
:
4771 switch(hasteSpell
->Id
)
4777 target
= SelectNearbyTarget(pVictim
);
4780 basepoints0
= damage
;
4781 triggered_spell_id
= 22482;
4789 // processed charge only counting case
4790 if(!triggered_spell_id
)
4793 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
4797 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
4802 if(!target
|| target
!=this && !target
->isAlive())
4805 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
4809 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4811 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
4813 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
4814 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
4819 bool Unit::HandleSpellCritChanceAuraProc(Unit
*pVictim
, uint32
/*damage*/, Aura
* triggeredByAura
, SpellEntry
const * /*procSpell*/, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4821 SpellEntry
const *triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
4823 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4824 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4826 uint32 triggered_spell_id
= 0;
4827 Unit
* target
= pVictim
;
4828 int32 basepoints0
= 0;
4830 switch(triggeredByAuraSpell
->SpellFamilyName
)
4832 case SPELLFAMILY_MAGE
:
4834 switch(triggeredByAuraSpell
->Id
)
4839 Unit
* caster
= triggeredByAura
->GetCaster();
4843 triggered_spell_id
= 54648;
4851 // processed charge only counting case
4852 if(!triggered_spell_id
)
4855 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
4859 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",triggeredByAuraSpell
->Id
,triggered_spell_id
);
4864 if(!target
|| target
!=this && !target
->isAlive())
4867 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
4871 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4873 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
4875 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
4876 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
4881 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
4883 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
4884 uint32 effIndex
= triggeredByAura
->GetEffIndex();
4885 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
4887 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4888 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4890 uint32 triggered_spell_id
= 0;
4891 Unit
* target
= pVictim
;
4892 int32 basepoints0
= 0;
4894 switch(dummySpell
->SpellFamilyName
)
4896 case SPELLFAMILY_GENERIC
:
4898 switch (dummySpell
->Id
)
4904 // return damage % to attacker but < 50% own total health
4905 basepoints0
= triggerAmount
*int32(damage
)/100;
4906 if(basepoints0
> GetMaxHealth()/2)
4907 basepoints0
= GetMaxHealth()/2;
4909 triggered_spell_id
= 25997;
4912 // Sweeping Strikes (NPC spells may be)
4916 // prevent chain of triggered spell from same triggered spell
4917 if(procSpell
&& procSpell
->Id
== 26654)
4920 target
= SelectNearbyTarget(pVictim
);
4924 triggered_spell_id
= 26654;
4927 // Twisted Reflection (boss spell)
4929 triggered_spell_id
= 21064;
4934 if (!procSpell
|| procSpell
->Id
== 24659)
4936 // Need remove one 24659 aura
4937 RemoveSingleSpellAurasFromStack(24659);
4940 // Restless Strength
4943 // Need remove one 24662 aura
4944 RemoveSingleSpellAurasFromStack(24662);
4947 // Adaptive Warding (Frostfire Regalia set)
4955 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
4956 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
4958 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
4960 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& UI64LIT(0x10000000)))
4970 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
4972 case SPELL_SCHOOL_NORMAL
:
4973 case SPELL_SCHOOL_HOLY
:
4974 return false; // ignored
4975 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
4976 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
4977 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
4978 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
4979 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
4987 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
4993 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
4995 case SPELL_SCHOOL_NORMAL
:
4996 return false; // ignore
4997 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
4998 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
4999 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
5000 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
5001 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
5002 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
5010 // Mana Leech (Passive) (Priest Pet Aura)
5014 target
= GetOwner();
5018 triggered_spell_id
= 34650;
5026 if (!roll_chance_i(triggerAmount
))
5029 // Remove any stun effect on target
5030 AuraMap
& Auras
= pVictim
->GetAuras();
5031 for(AuraMap::const_iterator iter
= Auras
.begin(); iter
!= Auras
.end();)
5033 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
5034 if( spell
->Mechanic
== MECHANIC_STUN
||
5035 spell
->EffectMechanic
[iter
->second
->GetEffIndex()] == MECHANIC_STUN
)
5037 pVictim
->RemoveAurasDueToSpell(spell
->Id
);
5038 iter
= Auras
.begin();
5048 // Cast finish spell at last charge
5049 if (triggeredByAura
->GetAuraCharges() > 1)
5053 triggered_spell_id
= 33494;
5056 // Vampiric Aura (boss spell)
5059 basepoints0
= 3 * damage
; // 300%
5060 if (basepoints0
< 0)
5063 triggered_spell_id
= 31285;
5067 // Aura of Madness (Darkmoon Card: Madness trinket)
5068 //=====================================================
5069 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
5070 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
5071 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
5072 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5073 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
5074 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
5075 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
5076 // 41011 Martyr Complex: +35 stamina (All classes)
5077 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5078 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5081 if(GetTypeId() != TYPEID_PLAYER
)
5084 // Select class defined buff
5087 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5088 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5090 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
5091 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5094 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
5095 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
5097 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
5098 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5101 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
5102 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
5103 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
5104 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
5106 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
5107 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5110 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
5112 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
5113 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5121 if (roll_chance_i(10))
5122 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
5125 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
5126 // cast 45479 Light's Wrath if Exalted by Aldor
5127 // cast 45429 Arcane Bolt if Exalted by Scryers
5130 if(GetTypeId() != TYPEID_PLAYER
)
5133 // Get Aldor reputation rank
5134 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5137 triggered_spell_id
= 45479;
5140 // Get Scryers reputation rank
5141 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5143 // triggered at positive/self casts also, current attack target used then
5144 if(IsFriendlyTo(target
))
5146 target
= getVictim();
5149 uint64 selected_guid
= ((Player
*)this)->GetSelection();
5150 target
= ObjectAccessor::GetUnit(*this,selected_guid
);
5154 if(IsFriendlyTo(target
))
5158 triggered_spell_id
= 45429;
5163 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
5164 // cast 45480 Light's Strength if Exalted by Aldor
5165 // cast 45428 Arcane Strike if Exalted by Scryers
5168 if(GetTypeId() != TYPEID_PLAYER
)
5171 // Get Aldor reputation rank
5172 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5175 triggered_spell_id
= 45480;
5178 // Get Scryers reputation rank
5179 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5181 triggered_spell_id
= 45428;
5186 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
5187 // cast 45431 Arcane Insight if Exalted by Aldor
5188 // cast 45432 Light's Ward if Exalted by Scryers
5191 if(GetTypeId() != TYPEID_PLAYER
)
5194 // Get Aldor reputation rank
5195 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5198 triggered_spell_id
= 45432;
5201 // Get Scryers reputation rank
5202 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5205 triggered_spell_id
= 45431;
5210 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
5211 // cast 45478 Light's Salvation if Exalted by Aldor
5212 // cast 45430 Arcane Surge if Exalted by Scryers
5215 if(GetTypeId() != TYPEID_PLAYER
)
5218 // Get Aldor reputation rank
5219 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5222 triggered_spell_id
= 45478;
5225 // Get Scryers reputation rank
5226 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5228 triggered_spell_id
= 45430;
5234 // Sunwell Exalted Caster Neck (??? neck)
5235 // cast ??? Light's Wrath if Exalted by Aldor
5236 // cast ??? Arcane Bolt if Exalted by Scryers*/
5238 return false; // old unused version
5242 triggered_spell_id
= 48503;
5243 basepoints0
= triggerAmount
;
5247 // Vampiric Touch (generic, used by some boss)
5251 triggered_spell_id
= 52724;
5252 basepoints0
= damage
/ 2;
5256 // Shadowfiend Death (Gain mana if pet dies with Glyph of Shadowfiend)
5259 Unit
*owner
= GetOwner();
5260 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
5263 // Glyph of Shadowfiend (need cast as self cast for owner, no hidden cooldown)
5264 owner
->CastSpell(owner
,58227,true,castItem
,triggeredByAura
);
5267 // Glyph of Life Tap
5269 triggered_spell_id
= 63321;
5274 case SPELLFAMILY_MAGE
:
5277 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
5279 if (getPowerType() != POWER_MANA
)
5283 basepoints0
= (triggerAmount
* GetMaxPower(POWER_MANA
) / 100);
5285 triggered_spell_id
= 29442;
5288 // Master of Elements
5289 if (dummySpell
->SpellIconID
== 1920)
5295 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5296 basepoints0
= cost
* triggerAmount
/100;
5297 if( basepoints0
<=0 )
5301 triggered_spell_id
= 29077;
5306 if (dummySpell
->SpellIconID
== 2120)
5312 switch (dummySpell
->Id
)
5314 case 31571: triggered_spell_id
= 57529; break;
5315 case 31572: triggered_spell_id
= 57531; break;
5317 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u",dummySpell
->Id
);
5324 if (dummySpell
->SpellIconID
== 2999)
5328 Aura
*counter
= GetAura(triggeredByAura
->GetId(), 1);
5332 // Count spell criticals in a row in second aura
5333 Modifier
*mod
= counter
->GetModifier();
5334 if (procEx
& PROC_EX_CRITICAL_HIT
)
5337 if (mod
->m_amount
< 100) // not enough
5339 // Crititcal counted -> roll chance
5340 if (roll_chance_i(triggerAmount
))
5341 CastSpell(this, 48108, true, castItem
, triggeredByAura
);
5347 if (dummySpell
->SpellIconID
== 2998)
5352 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5353 basepoints0
= cost
* triggerAmount
/100;
5354 if( basepoints0
<=0 )
5356 triggered_spell_id
= 44450;
5360 // Incanter's Regalia set (add trigger chance to Mana Shield)
5361 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5363 if(GetTypeId() != TYPEID_PLAYER
)
5367 triggered_spell_id
= 37436;
5370 switch(dummySpell
->Id
)
5379 switch (dummySpell
->Id
)
5381 case 11119: basepoints0
= int32(0.04f
*damage
); break;
5382 case 11120: basepoints0
= int32(0.08f
*damage
); break;
5383 case 12846: basepoints0
= int32(0.12f
*damage
); break;
5384 case 12847: basepoints0
= int32(0.16f
*damage
); break;
5385 case 12848: basepoints0
= int32(0.20f
*damage
); break;
5387 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
5391 triggered_spell_id
= 12654;
5397 //last charge and crit
5398 if (triggeredByAura
->GetAuraCharges() <= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
5399 return true; // charge counting (will removed)
5401 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
5402 return (procEx
& PROC_EX_CRITICAL_HIT
); // charge update only at crit hits, no hidden cooldowns
5404 // Glyph of Ice Block
5407 if (GetTypeId() != TYPEID_PLAYER
)
5410 // not 100% safe with client version switches but for 3.1.3 no spells with cooldown that can have mage player except Frost Nova.
5411 ((Player
*)this)->RemoveSpellCategoryCooldown(35, true);
5414 // Glyph of Polymorph
5417 if (!pVictim
|| !pVictim
->isAlive())
5420 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE
);
5421 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_PERIODIC_DAMAGE_PERCENT
);
5427 case SPELLFAMILY_WARRIOR
:
5430 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0000000800000000))
5432 // check attack comes not from behind
5433 if (!HasInArc(M_PI
, pVictim
))
5436 triggered_spell_id
= 22858;
5440 if (dummySpell
->SpellIconID
== 1697)
5442 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
5443 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
5445 // Need stun or root mechanic
5446 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_STUN_MASK
))
5449 switch (dummySpell
->Id
)
5451 case 29838: triggered_spell_id
=29842; break;
5452 case 29834: triggered_spell_id
=29841; break;
5453 case 42770: triggered_spell_id
=42771; break;
5455 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
5463 if (dummySpell
->SpellIconID
== 3214)
5465 triggered_spell_id
= 59653;
5466 basepoints0
= GetShieldBlockValue() * triggerAmount
/ 100;
5471 if (dummySpell
->Id
== 12328)
5473 // prevent chain of triggered spell from same triggered spell
5474 if(procSpell
&& procSpell
->Id
== 26654)
5477 target
= SelectNearbyTarget(pVictim
);
5481 triggered_spell_id
= 26654;
5486 case SPELLFAMILY_WARLOCK
:
5488 // Seed of Corruption
5489 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
5491 Modifier
* mod
= triggeredByAura
->GetModifier();
5492 // if damage is more than need or target die from damage deal finish spell
5493 if( mod
->m_amount
<= damage
|| GetHealth() <= damage
)
5495 // remember guid before aura delete
5496 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5498 // Remove aura (before cast for prevent infinite loop handlers)
5499 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5501 // Cast finish spell (triggeredByAura already not exist!)
5502 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
5503 return true; // no hidden cooldown
5507 mod
->m_amount
-=damage
;
5510 // Seed of Corruption (Mobs cast) - no die req
5511 if (dummySpell
->SpellFamilyFlags
== UI64LIT(0x0) && dummySpell
->SpellIconID
== 1932)
5513 Modifier
* mod
= triggeredByAura
->GetModifier();
5514 // if damage is more than need deal finish spell
5515 if( mod
->m_amount
<= damage
)
5517 // remember guid before aura delete
5518 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5520 // Remove aura (before cast for prevent infinite loop handlers)
5521 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5523 // Cast finish spell (triggeredByAura already not exist!)
5524 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
5525 return true; // no hidden cooldown
5528 mod
->m_amount
-=damage
;
5532 if (dummySpell
->SpellIconID
== 3222)
5537 basepoints0
= damage
* triggerAmount
/ 100;
5538 triggered_spell_id
= 54181;
5541 switch(dummySpell
->Id
)
5543 // Nightfall & Glyph of Corruption
5549 triggered_spell_id
= 17941;
5558 basepoints0
= int32(damage
*triggerAmount
/100);
5560 triggered_spell_id
= 30294;
5563 // Shadowflame (Voidheart Raiment set bonus)
5566 triggered_spell_id
= 37379;
5569 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
5577 basepoints0
= damage
* triggerAmount
/100;
5578 triggered_spell_id
= 37382;
5581 // Shadowflame Hellfire (Voidheart Raiment set bonus)
5584 triggered_spell_id
= 37378;
5590 basepoints0
= int32(damage
* triggerAmount
/ 100);
5591 triggered_spell_id
= 63106;
5597 case SPELLFAMILY_PRIEST
:
5600 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
5602 if(!pVictim
|| !pVictim
->isAlive())
5605 // pVictim is caster of aura
5606 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5609 // Energize 0.25% of max. mana
5610 pVictim
->CastSpell(pVictim
,57669,true,castItem
,triggeredByAura
);
5611 return true; // no hidden cooldown
5614 switch(dummySpell
->SpellIconID
)
5616 // Improved Shadowform
5619 if(!roll_chance_i(triggerAmount
))
5622 RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT
);
5623 RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED
);
5629 basepoints0
= damage
* triggerAmount
/100;
5630 triggered_spell_id
= 47753;
5639 Aura
* healingAura
= pVictim
->GetAura(procSpell
->Id
,0);
5643 int32 healingfromticks
= SpellHealingBonus(pVictim
, procSpell
, (healingAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
)), DOT
);
5644 basepoints0
= healingfromticks
* triggerAmount
/ 100;
5645 triggered_spell_id
= 63544;
5648 // Improved Devouring Plague
5654 Aura
* leachAura
= pVictim
->GetAura(procSpell
->Id
,0);
5658 int32 damagefromticks
= SpellDamageBonus(pVictim
, procSpell
, (leachAura
->GetModifier()->m_amount
* GetSpellAuraMaxTicks(procSpell
)), DOT
);
5659 basepoints0
= damagefromticks
* triggerAmount
/ 100;
5660 triggered_spell_id
= 63675;
5665 switch(dummySpell
->Id
)
5670 // Return if self damage
5671 if (this == pVictim
)
5674 // Heal amount - Self/Team
5675 int32 team
= triggerAmount
*damage
/500;
5676 int32 self
= triggerAmount
*damage
/100 - team
;
5677 CastCustomSpell(this,15290,&team
,&self
,NULL
,true,castItem
,triggeredByAura
);
5678 return true; // no hidden cooldown
5680 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
5683 // Shadow Word: Pain
5684 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000008000))
5685 triggered_spell_id
= 40441;
5687 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
5688 triggered_spell_id
= 40440;
5695 // Oracle Healing Bonus ("Garments of the Oracle" set)
5699 basepoints0
= int32(damage
* 10/100);
5701 triggered_spell_id
= 26170;
5704 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
5707 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
5711 basepoints0
= damage
* triggerAmount
/100;
5713 triggered_spell_id
= 39373;
5716 // Greater Heal (Vestments of Faith (Priest Tier 3) - 4 pieces bonus)
5719 triggered_spell_id
= 28810;
5722 // Glyph of Dispel Magic
5725 if(!target
->IsFriendlyTo(this))
5728 basepoints0
= int32(target
->GetMaxHealth() * triggerAmount
/ 100);
5729 triggered_spell_id
= 56131;
5735 case SPELLFAMILY_DRUID
:
5737 switch(dummySpell
->Id
)
5739 // Leader of the Pack
5742 // dummy m_amount store health percent (!=0 if Improved Leader of the Pack applied)
5743 int32 heal_percent
= triggeredByAura
->GetModifier()->m_amount
;
5747 // check explicitly only to prevent mana cast when halth cast cooldown
5748 if (cooldown
&& ((Player
*)this)->HasSpellCooldown(34299))
5752 triggered_spell_id
= 34299;
5753 basepoints0
= GetMaxHealth() * heal_percent
/ 100;
5757 if (triggeredByAura
->GetCasterGUID() == GetGUID())
5759 if (SpellEntry
const* manaCastEntry
= sSpellStore
.LookupEntry(60889))
5761 int32 mana_percent
= manaCastEntry
->CalculateSimpleValue(0) * heal_percent
;
5762 CastCustomSpell(this, manaCastEntry
, &mana_percent
, NULL
, NULL
, true, castItem
, triggeredByAura
);
5767 // Healing Touch (Dreamwalker Raiment set)
5771 basepoints0
= int32(procSpell
->manaCost
* 30 / 100);
5773 triggered_spell_id
= 28742;
5776 // Healing Touch Refund (Idol of Longevity trinket)
5780 triggered_spell_id
= 28848;
5783 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
5788 triggered_spell_id
= 37238;
5791 // Druid Tier 6 Trinket
5797 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
5799 triggered_spell_id
= 40445;
5803 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000010))
5805 triggered_spell_id
= 40446;
5808 // Mangle (Bear) and Mangle (Cat)
5809 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000044000000000))
5811 triggered_spell_id
= 40452;
5817 if (!roll_chance_f(chance
))
5826 // Deadly Interrupt Effect
5827 triggered_spell_id
= 32747;
5830 // Glyph of Rejuvenation
5834 if (pVictim
->GetMaxHealth() < 2 * pVictim
->GetHealth())
5836 basepoints0
= triggerAmount
* damage
/ 100;
5837 triggered_spell_id
= 54755;
5842 if (dummySpell
->SpellIconID
== 2856)
5846 // Only 0 aura can proc
5850 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
5854 if (!roll_chance_i(60))
5856 triggered_spell_id
= 48518;
5861 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000004))
5865 triggered_spell_id
= 48517;
5872 else if (dummySpell
->SpellIconID
== 2860)
5874 triggered_spell_id
= 48504;
5875 basepoints0
= triggerAmount
* damage
/ 100;
5880 case SPELLFAMILY_ROGUE
:
5882 switch(dummySpell
->Id
)
5884 // Deadly Throw Interrupt
5887 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
5888 if (this == pVictim
)
5891 triggered_spell_id
= 32747;
5896 if (dummySpell
->SpellIconID
== 2909)
5898 // "refresh your Slice and Dice duration to its 5 combo point maximum"
5899 // lookup Slice and Dice
5900 AuraList
const& sd
= GetAurasByType(SPELL_AURA_MOD_HASTE
);
5901 for(AuraList::const_iterator itr
= sd
.begin(); itr
!= sd
.end(); ++itr
)
5903 SpellEntry
const *spellProto
= (*itr
)->GetSpellProto();
5904 if (spellProto
->SpellFamilyName
== SPELLFAMILY_ROGUE
&&
5905 (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000040000)))
5907 (*itr
)->SetAuraMaxDuration(GetSpellMaxDuration(spellProto
));
5908 (*itr
)->RefreshAura();
5915 if (dummySpell
->SpellIconID
== 2963)
5917 triggered_spell_id
= 44289;
5921 if (dummySpell
->SpellIconID
== 2116)
5927 basepoints0
= procSpell
->manaCost
* triggerAmount
/100;
5928 if (basepoints0
<= 0)
5932 triggered_spell_id
= 31663;
5937 case SPELLFAMILY_HUNTER
:
5939 // Aspect of the Viper
5940 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x4000000000000))
5942 uint32 maxmana
= GetMaxPower(POWER_MANA
);
5943 basepoints0
= int32(maxmana
* GetAttackTime(RANGED_ATTACK
)/1000.0f
/100.0f
);
5946 triggered_spell_id
= 34075;
5949 // Thrill of the Hunt
5950 if (dummySpell
->SpellIconID
== 2236)
5956 int32 mana
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5957 basepoints0
= mana
* 40/100;
5958 if(basepoints0
<= 0)
5962 triggered_spell_id
= 34720;
5966 if ( dummySpell
->SpellIconID
== 3406 )
5968 triggered_spell_id
= 57669;
5973 if ( dummySpell
->SpellIconID
== 3579 )
5975 // Proc only from periodic (from trap activation proc another aura of this spell)
5976 if (!(procFlag
& PROC_FLAG_ON_DO_PERIODIC
) || !roll_chance_i(triggerAmount
))
5978 triggered_spell_id
= 56453;
5982 // Rapid Recuperation
5983 if ( dummySpell
->SpellIconID
== 3560 )
5985 // This effect only from Rapid Killing (mana regen)
5986 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0100000000000000)))
5991 switch(dummySpell
->Id
)
5993 case 53228: // Rank 1
5994 triggered_spell_id
= 56654;
5996 case 53232: // Rank 2
5997 triggered_spell_id
= 58882;
6004 case SPELLFAMILY_PALADIN
:
6006 // Seal of Righteousness - melee proc dummy (addition ${$MWS*(0.022*$AP+0.044*$SPH)} damage)
6007 if ((dummySpell
->SpellFamilyFlags
& UI64LIT(0x000000008000000)) && effIndex
==0)
6009 triggered_spell_id
= 25742;
6010 float ap
= GetTotalAttackPowerValue(BASE_ATTACK
);
6011 int32 holy
= SpellBaseDamageBonus(SPELL_SCHOOL_MASK_HOLY
) +
6012 SpellBaseDamageBonusForVictim(SPELL_SCHOOL_MASK_HOLY
, pVictim
);
6013 basepoints0
= GetAttackTime(BASE_ATTACK
) * int32(ap
*0.022f
+ 0.044f
* holy
) / 1000;
6016 // Righteous Vengeance
6017 if (dummySpell
->SpellIconID
== 3025)
6020 basepoints0
= triggerAmount
*damage
/400;
6021 triggered_spell_id
= 61840;
6025 if (dummySpell
->SpellIconID
== 3030)
6028 basepoints0
= triggerAmount
*damage
/400;
6029 triggered_spell_id
= 54203;
6032 switch(dummySpell
->Id
)
6034 // Judgement of Light
6037 basepoints0
= int32( pVictim
->GetMaxHealth() * triggeredByAura
->GetModifier()->m_amount
/ 100 );
6038 pVictim
->CastCustomSpell(pVictim
, 20267, &basepoints0
, NULL
, NULL
, true, NULL
, triggeredByAura
);
6041 // Judgement of Wisdom
6044 if (pVictim
->getPowerType() == POWER_MANA
)
6046 // 2% of maximum base mana
6047 basepoints0
= int32(pVictim
->GetCreateMana() * 2 / 100);
6048 pVictim
->CastCustomSpell(pVictim
, 20268, &basepoints0
, NULL
, NULL
, true, NULL
, triggeredByAura
);
6052 // Heart of the Crusader (Rank 1)
6054 triggered_spell_id
= 21183;
6056 // Heart of the Crusader (Rank 2)
6058 triggered_spell_id
= 54498;
6060 // Heart of the Crusader (Rank 3)
6062 triggered_spell_id
= 54499;
6064 case 20911: // Blessing of Sanctuary
6065 case 25899: // Greater Blessing of Sanctuary
6068 switch (target
->getPowerType())
6071 triggered_spell_id
= 57319;
6078 // Holy Power (Redemption Armor set)
6084 // Set class defined buff
6085 switch (pVictim
->getClass())
6091 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6095 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6099 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
6102 triggered_spell_id
= 28790; // Increases the friendly target's armor
6109 // Spiritual Attunement
6113 // if healed by another unit (pVictim)
6118 basepoints0
= triggerAmount
*damage
/100;
6120 triggered_spell_id
= 31786;
6123 // Seal of Vengeance (damage calc on apply aura)
6126 if(effIndex
!= 0) // effect 1,2 used by seal unleashing code
6129 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6130 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595) )
6131 triggered_spell_id
= 31803; // Holy Vengeance
6133 // Add 5-stack effect from Holy Vengeance
6135 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6136 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6138 if( ((*itr
)->GetId() == 31803) && (*itr
)->GetCasterGUID()==GetGUID())
6140 stacks
= (*itr
)->GetStackAmount();
6145 CastSpell(target
,42463,true,NULL
,triggeredByAura
);
6148 // Judgements of the Wise
6152 // triggered only at casted Judgement spells, not at additional Judgement effects
6153 if(!procSpell
|| procSpell
->Category
!= 1210)
6157 triggered_spell_id
= 31930;
6160 CastSpell(this, 57669, true, NULL
, triggeredByAura
);
6162 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
6170 // Flash of light/Holy light
6171 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x00000000C0000000))
6173 triggered_spell_id
= 40471;
6177 else if (GetSpellSpecific(procSpell
->Id
)==SPELL_JUDGEMENT
)
6179 triggered_spell_id
= 40472;
6185 if (!roll_chance_f(chance
))
6190 // Light's Beacon (heal target area aura)
6193 // not do bonus heal for explicit beacon focus healing
6194 if (GetGUID() == triggeredByAura
->GetCasterGUID())
6198 Unit
* beacon
= triggeredByAura
->GetCaster();
6202 // find caster main aura at beacon
6204 Unit::AuraList
const& baa
= beacon
->GetAurasByType(SPELL_AURA_PERIODIC_TRIGGER_SPELL
);
6205 for(Unit::AuraList::const_iterator i
= baa
.begin(); i
!= baa
.end(); ++i
)
6207 if ((*i
)->GetId() == 53563 && (*i
)->GetCasterGUID() == pVictim
->GetGUID())
6214 // original heal must be form beacon caster
6218 triggered_spell_id
= 53652; // Beacon of Light
6219 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*damage
/100;
6221 // cast with original caster set but beacon to beacon for apply caster mods and avoid LoS check
6222 beacon
->CastCustomSpell(beacon
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
,pVictim
->GetGUID());
6225 // Seal of Corruption (damage calc on apply aura)
6228 if(effIndex
!= 0) // effect 1,2 used by seal unleashing code
6231 // At melee attack or Hammer of the Righteous spell damage considered as melee attack
6232 if ((procFlag
& PROC_FLAG_SUCCESSFUL_MELEE_HIT
) || (procSpell
&& procSpell
->Id
== 53595))
6233 triggered_spell_id
= 53742; // Blood Corruption
6235 // Add 5-stack effect from Blood Corruption
6237 AuraList
const& auras
= target
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
6238 for(AuraList::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
6240 if( ((*itr
)->GetId() == 53742) && (*itr
)->GetCasterGUID()==GetGUID())
6242 stacks
= (*itr
)->GetStackAmount();
6247 CastSpell(target
,53739,true,NULL
,triggeredByAura
);
6250 // Glyph of Flash of Light
6253 triggered_spell_id
= 54957;
6254 basepoints0
= triggerAmount
*damage
/100;
6257 // Glyph of Holy Light
6260 triggered_spell_id
= 54968;
6261 basepoints0
= triggerAmount
*damage
/100;
6264 // Glyph of Divinity
6267 // Lookup base amount mana restore
6268 for (int i
=0; i
<3;++i
)
6269 if (procSpell
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
6271 int32 mana
= procSpell
->EffectBasePoints
[i
];
6272 CastCustomSpell(this, 54986, NULL
, &mana
, NULL
, true, castItem
, triggeredByAura
);
6277 // Sacred Shield (buff)
6280 triggered_spell_id
= 66922;
6281 SpellEntry
const* triggeredEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6282 if (!triggeredEntry
)
6285 basepoints0
= int32(damage
/ (GetSpellDuration(triggeredEntry
) / triggeredEntry
->EffectAmplitude
[0]));
6289 // Sacred Shield (talent rank)
6292 triggered_spell_id
= 58597;
6299 case SPELLFAMILY_SHAMAN
:
6301 switch(dummySpell
->Id
)
6303 // Totemic Power (The Earthshatterer set)
6309 // Set class defined buff
6310 switch (pVictim
->getClass())
6316 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6320 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6324 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
6327 triggered_spell_id
= 28827; // Increases the friendly target's armor
6334 // Lesser Healing Wave (Totem of Flowing Water Relic)
6338 triggered_spell_id
= 28850;
6341 // Windfury Weapon (Passive) 1-5 Ranks
6344 if(GetTypeId()!=TYPEID_PLAYER
)
6347 if(!castItem
|| !castItem
->IsEquipped())
6350 // custom cooldown processing case
6351 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6354 // Now amount of extra power stored in 1 effect of Enchant spell
6355 // Get it by item enchant id
6357 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
6359 case 283: spellId
= 8232; break; // 1 Rank
6360 case 284: spellId
= 8235; break; // 2 Rank
6361 case 525: spellId
= 10486; break; // 3 Rank
6362 case 1669:spellId
= 16362; break; // 4 Rank
6363 case 2636:spellId
= 25505; break; // 5 Rank
6364 case 3785:spellId
= 58801; break; // 6 Rank
6365 case 3786:spellId
= 58803; break; // 7 Rank
6366 case 3787:spellId
= 58804; break; // 8 Rank
6369 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
6370 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
6375 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
6376 if(!windfurySpellEntry
)
6378 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
6382 int32 extra_attack_power
= CalculateSpellDamage(windfurySpellEntry
, 1, windfurySpellEntry
->EffectBasePoints
[1], pVictim
);
6385 if ( castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
6387 // Value gained from additional AP
6388 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
6389 triggered_spell_id
= 33750;
6394 // Value gained from additional AP
6395 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
6396 triggered_spell_id
= 25504;
6399 // apply cooldown before cast to prevent processing itself
6401 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6404 for ( uint32 i
= 0; i
<2; ++i
)
6405 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6409 // Shaman Tier 6 Trinket
6416 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000001))
6418 triggered_spell_id
= 40465; // Lightning Bolt
6421 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080))
6423 triggered_spell_id
= 40465; // Lesser Healing Wave
6426 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000001000000000))
6428 triggered_spell_id
= 40466; // Stormstrike
6434 if (!roll_chance_f(chance
))
6440 // Glyph of Healing Wave
6443 // Not proc from self heals
6446 basepoints0
= triggerAmount
* damage
/ 100;
6448 triggered_spell_id
= 55533;
6455 target
= GetOwner();
6458 basepoints0
= triggerAmount
* damage
/ 100;
6459 triggered_spell_id
= 58879;
6462 // Shaman T8 Elemental 4P Bonus
6465 basepoints0
= int32( triggerAmount
* damage
/ 100 );
6466 triggered_spell_id
= 64930; // Electrified
6470 // Storm, Earth and Fire
6471 if (dummySpell
->SpellIconID
== 3063)
6473 // Earthbind Totem summon only
6474 if(procSpell
->Id
!= 2484)
6477 float chance
= triggerAmount
;
6478 if (!roll_chance_f(chance
))
6481 triggered_spell_id
= 64695;
6484 // Ancestral Awakening
6485 if (dummySpell
->SpellIconID
== 3065)
6487 triggered_spell_id
= 52759;
6488 basepoints0
= triggerAmount
* damage
/ 100;
6493 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000040000000000))
6496 basepoints0
= triggerAmount
;
6498 // Glyph of Earth Shield
6499 if (Aura
* aur
= GetDummyAura(63279))
6501 int32 aur_mod
= aur
->GetModifier()->m_amount
;
6502 basepoints0
= int32(basepoints0
* (aur_mod
+ 100.0f
) / 100.0f
);
6505 triggered_spell_id
= 379;
6508 // Improved Water Shield
6509 if (dummySpell
->SpellIconID
== 2287)
6511 // Lesser Healing Wave need aditional 60% roll
6512 if ((procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)) && !roll_chance_i(60))
6514 // lookup water shield
6515 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6516 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6518 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6519 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000002000000000)))
6521 uint32 spell
= (*itr
)->GetSpellProto()->EffectTriggerSpell
[(*itr
)->GetEffIndex()];
6522 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
6523 if ((*itr
)->DropAuraCharge())
6524 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6531 // Lightning Overload
6532 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
6534 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
6537 // custom cooldown processing case
6538 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6542 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
6543 switch (procSpell
->Id
)
6546 case 403: spellId
= 45284; break; // Rank 1
6547 case 529: spellId
= 45286; break; // Rank 2
6548 case 548: spellId
= 45287; break; // Rank 3
6549 case 915: spellId
= 45288; break; // Rank 4
6550 case 943: spellId
= 45289; break; // Rank 5
6551 case 6041: spellId
= 45290; break; // Rank 6
6552 case 10391: spellId
= 45291; break; // Rank 7
6553 case 10392: spellId
= 45292; break; // Rank 8
6554 case 15207: spellId
= 45293; break; // Rank 9
6555 case 15208: spellId
= 45294; break; // Rank 10
6556 case 25448: spellId
= 45295; break; // Rank 11
6557 case 25449: spellId
= 45296; break; // Rank 12
6558 case 49237: spellId
= 49239; break; // Rank 13
6559 case 49238: spellId
= 49240; break; // Rank 14
6561 case 421: spellId
= 45297; break; // Rank 1
6562 case 930: spellId
= 45298; break; // Rank 2
6563 case 2860: spellId
= 45299; break; // Rank 3
6564 case 10605: spellId
= 45300; break; // Rank 4
6565 case 25439: spellId
= 45301; break; // Rank 5
6566 case 25442: spellId
= 45302; break; // Rank 6
6567 case 49270: spellId
= 49268; break; // Rank 7
6568 case 49271: spellId
= 49269; break; // Rank 8
6570 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
6573 // No thread generated mod
6574 // TODO: exist special flag in spell attributes for this, need found and use!
6575 SpellModifier
*mod
= new SpellModifier(SPELLMOD_THREAT
,SPELLMOD_PCT
,-100,triggeredByAura
);
6577 ((Player
*)this)->AddSpellMod(mod
, true);
6579 // Remove cooldown (Chain Lightning - have Category Recovery time)
6580 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000002))
6581 ((Player
*)this)->RemoveSpellCooldown(spellId
);
6583 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
6585 ((Player
*)this)->AddSpellMod(mod
, false);
6587 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6588 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6593 if(dummySpell
->SpellIconID
== 3059)
6595 // lookup Lightning Shield
6596 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
6597 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
6599 if ((*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
6600 ((*itr
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000400)))
6603 switch ((*itr
)->GetId())
6605 case 324: spell
= 26364; break;
6606 case 325: spell
= 26365; break;
6607 case 905: spell
= 26366; break;
6608 case 945: spell
= 26367; break;
6609 case 8134: spell
= 26369; break;
6610 case 10431: spell
= 26370; break;
6611 case 10432: spell
= 26363; break;
6612 case 25469: spell
= 26371; break;
6613 case 25472: spell
= 26372; break;
6614 case 49280: spell
= 49278; break;
6615 case 49281: spell
= 49279; break;
6619 CastSpell(target
, spell
, true, castItem
, triggeredByAura
);
6620 if ((*itr
)->DropAuraCharge())
6621 RemoveSingleSpellAurasFromStack((*itr
)->GetId());
6628 if (dummySpell
->SpellIconID
== 3780)
6630 Unit
*caster
= triggeredByAura
->GetCaster();
6632 if (!procSpell
|| !caster
)
6635 float distance
= caster
->GetDistance(pVictim
);
6636 int32 chance
= triggerAmount
;
6638 if (distance
< 15.0f
|| !roll_chance_i(chance
))
6641 // make triggered cast apply after current damage spell processing for prevent remove by it
6642 if(Spell
* spell
= GetCurrentSpell(CURRENT_GENERIC_SPELL
))
6643 spell
->AddTriggeredSpell(63685);
6648 case SPELLFAMILY_DEATHKNIGHT
:
6651 if (dummySpell
->SpellIconID
== 2636)
6653 if (GetTypeId() != TYPEID_PLAYER
|| !((Player
*)this)->isHonorOrXPTarget(pVictim
))
6655 basepoints0
= triggerAmount
* damage
/ 100;
6656 triggered_spell_id
= 53168;
6660 if (dummySpell
->SpellIconID
== 2664)
6662 basepoints0
= triggerAmount
;
6663 triggered_spell_id
= 50163;
6667 // Dancing Rune Weapon
6668 if (dummySpell
->Id
== 49028)
6670 // 1 dummy aura for dismiss rune blade
6673 // TODO: wite script for this "fights on its own, doing the same attacks"
6674 // NOTE: Trigger here on every attack and spell cast
6678 if (dummySpell
->Id
== 49005)
6680 // TODO: need more info (cooldowns/PPM)
6681 triggered_spell_id
= 61607;
6685 if (dummySpell
->SpellFamilyFlags
& UI64LIT(0x0000000000010000))
6687 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
6688 triggered_spell_id
= 50181;
6693 if (dummySpell
->SpellIconID
== 2709)
6695 basepoints0
= triggerAmount
* damage
/ 100;
6696 triggered_spell_id
= 51460;
6699 // Threat of Thassarian
6700 if (dummySpell
->SpellIconID
== 2023)
6703 if (!procSpell
|| !haveOffhandWeapon())
6705 // Chance as basepoints for dummy aura
6706 if (!roll_chance_i(triggerAmount
))
6709 switch (procSpell
->Id
)
6712 case 49020: // Rank 1
6713 triggered_spell_id
= 66198; break;
6714 case 51423: // Rank 2
6715 triggered_spell_id
= 66972; break;
6716 case 51424: // Rank 3
6717 triggered_spell_id
= 66973; break;
6718 case 51425: // Rank 4
6719 triggered_spell_id
= 66974; break;
6721 case 49143: // Rank 1
6722 triggered_spell_id
= 66196; break;
6723 case 51416: // Rank 2
6724 triggered_spell_id
= 66958; break;
6725 case 51417: // Rank 3
6726 triggered_spell_id
= 66959; break;
6727 case 51418: // Rank 4
6728 triggered_spell_id
= 66960; break;
6729 case 51419: // Rank 5
6730 triggered_spell_id
= 66961; break;
6731 case 51420: // Rank 6
6732 triggered_spell_id
= 66962; break;
6734 case 45462: // Rank 1
6735 triggered_spell_id
= 66216; break;
6736 case 49917: // Rank 2
6737 triggered_spell_id
= 66988; break;
6738 case 49918: // Rank 3
6739 triggered_spell_id
= 66989; break;
6740 case 49919: // Rank 4
6741 triggered_spell_id
= 66990; break;
6742 case 49920: // Rank 5
6743 triggered_spell_id
= 66991; break;
6744 case 49921: // Rank 6
6745 triggered_spell_id
= 66992; break;
6747 case 49998: // Rank 1
6748 triggered_spell_id
= 66188; break;
6749 case 49999: // Rank 2
6750 triggered_spell_id
= 66950; break;
6751 case 45463: // Rank 3
6752 triggered_spell_id
= 66951; break;
6753 case 49923: // Rank 4
6754 triggered_spell_id
= 66952; break;
6755 case 49924: // Rank 5
6756 triggered_spell_id
= 66953; break;
6759 triggered_spell_id
= 66217; break;
6761 case 45902: // Rank 1
6762 triggered_spell_id
= 66215; break;
6763 case 49926: // Rank 2
6764 triggered_spell_id
= 66975; break;
6765 case 49927: // Rank 3
6766 triggered_spell_id
= 66976; break;
6767 case 49928: // Rank 4
6768 triggered_spell_id
= 66977; break;
6769 case 49929: // Rank 5
6770 triggered_spell_id
= 66978; break;
6771 case 49930: // Rank 6
6772 triggered_spell_id
= 66979; break;
6778 // Runic Power Back on Snare/Root
6779 if (dummySpell
->Id
== 61257)
6781 // only for spells and hit/crit (trigger start always) and not start from self casted spells
6782 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
6784 // Need snare or root mechanic
6785 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_ROOT_AND_SNARE_MASK
))
6787 triggered_spell_id
= 61258;
6792 if (dummySpell
->SpellIconID
== 1614)
6794 if (!roll_chance_f(GetUnitCriticalChance(BASE_ATTACK
, pVictim
)))
6796 basepoints0
= triggerAmount
* damage
/ 100;
6797 triggered_spell_id
= 50526;
6800 // Blood-Caked Blade
6801 if (dummySpell
->SpellIconID
== 138)
6803 triggered_spell_id
= dummySpell
->EffectTriggerSpell
[effIndex
];
6812 // processed charge only counting case
6813 if(!triggered_spell_id
)
6816 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6820 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
6825 if(!target
|| target
!=this && !target
->isAlive())
6828 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
6832 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6834 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
6836 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6837 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
6842 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
6844 // Get triggered aura spell info
6845 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
6847 // Basepoints of trigger aura
6848 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
6850 // Set trigger spell id, target, custom basepoints
6851 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
6852 Unit
* target
= NULL
;
6853 int32 basepoints
[3] = {0, 0, 0};
6855 if(triggeredByAura
->GetModifier()->m_auraname
== SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
)
6856 basepoints
[0] = triggerAmount
;
6858 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
6859 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
6861 // Try handle unknown trigger spells
6862 // Custom requirements (not listed in procEx) Warning! damage dealing after this
6863 // Custom triggered spells
6864 switch (auraSpellInfo
->SpellFamilyName
)
6866 case SPELLFAMILY_GENERIC
:
6867 switch(auraSpellInfo
->Id
)
6869 //case 191: // Elemental Response
6870 // switch (procSpell->School)
6872 // case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192; break;
6873 // case SPELL_SCHOOL_FROST: trigger_spell_id = 34193; break;
6874 // case SPELL_SCHOOL_ARCANE:trigger_spell_id = 34194; break;
6875 // case SPELL_SCHOOL_NATURE:trigger_spell_id = 34195; break;
6876 // case SPELL_SCHOOL_SHADOW:trigger_spell_id = 34196; break;
6877 // case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197; break;
6878 // case SPELL_SCHOOL_NORMAL:trigger_spell_id = 34198; break;
6881 //case 5301: break; // Defensive State (DND)
6882 //case 7137: break: // Shadow Charge (Rank 1)
6883 //case 7377: break: // Take Immune Periodic Damage <Not Working>
6884 //case 13358: break; // Defensive State (DND)
6885 //case 16092: break; // Defensive State (DND)
6886 //case 18943: break; // Double Attack
6887 //case 19194: break; // Double Attack
6888 //case 19817: break; // Double Attack
6889 //case 19818: break; // Double Attack
6890 //case 22835: break; // Drunken Rage
6891 // trigger_spell_id = 14822; break;
6892 case 23780: // Aegis of Preservation (Aegis of Preservation trinket)
6893 trigger_spell_id
= 23781;
6895 //case 24949: break; // Defensive State 2 (DND)
6896 case 27522: // Mana Drain Trigger
6897 case 40336: // Mana Drain Trigger
6898 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
6900 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
6901 if (pVictim
&& pVictim
->isAlive())
6902 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
6904 case 31255: // Deadly Swiftness (Rank 1)
6905 // whenever you deal damage to a target who is below 20% health.
6906 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
6910 trigger_spell_id
= 22588;
6912 //case 33207: break; // Gossip NPC Periodic - Fidget
6913 case 33896: // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
6914 trigger_spell_id
= 33898;
6916 //case 34082: break; // Advantaged State (DND)
6917 //case 34783: break: // Spell Reflection
6918 //case 35205: break: // Vanish
6919 //case 35321: break; // Gushing Wound
6920 //case 36096: break: // Spell Reflection
6921 //case 36207: break: // Steal Weapon
6922 //case 36576: break: // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
6923 //case 37030: break; // Chaotic Temperament
6924 //case 38363: break; // Gushing Wound
6925 //case 39215: break; // Gushing Wound
6926 //case 40250: break; // Improved Duration
6927 //case 40329: break; // Demo Shout Sensor
6928 //case 40364: break; // Entangling Roots Sensor
6929 //case 41054: break; // Copy Weapon
6930 // trigger_spell_id = 41055; break;
6931 //case 41248: break; // Consuming Strikes
6932 // trigger_spell_id = 41249; break;
6933 //case 42730: break: // Woe Strike
6934 //case 43453: break: // Rune Ward
6935 //case 43504: break; // Alterac Valley OnKill Proc Aura
6936 //case 44326: break: // Pure Energy Passive
6937 //case 44526: break; // Hate Monster (Spar) (30 sec)
6938 //case 44527: break; // Hate Monster (Spar Buddy) (30 sec)
6939 //case 44819: break; // Hate Monster (Spar Buddy) (>30% Health)
6940 //case 44820: break; // Hate Monster (Spar) (<30%)
6941 case 45057: // Evasive Maneuvers (Commendation of Kael`thas trinket)
6942 // reduce you below $s1% health
6943 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
6946 //case 45903: break: // Offensive State
6947 //case 46146: break: // [PH] Ahune Spanky Hands
6948 //case 46939: break; // Black Bow of the Betrayer
6949 // trigger_spell_id = 29471; - gain mana
6950 // 27526; - drain mana if possible
6951 case 43820: // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
6952 // Pct value stored in dummy
6953 basepoints
[0] = pVictim
->GetCreateHealth() * auraSpellInfo
->EffectBasePoints
[1] / 100;
6956 //case 45205: break; // Copy Offhand Weapon
6957 //case 45343: break; // Dark Flame Aura
6958 //case 47300: break; // Dark Flame Aura
6959 //case 48876: break; // Beast's Mark
6960 // trigger_spell_id = 48877; break;
6961 //case 49059: break; // Horde, Hate Monster (Spar Buddy) (>30% Health)
6962 //case 50051: break; // Ethereal Pet Aura
6963 //case 50689: break; // Blood Presence (Rank 1)
6964 //case 50844: break; // Blood Mirror
6965 //case 52856: break; // Charge
6966 //case 54072: break; // Knockback Ball Passive
6967 //case 54476: break; // Blood Presence
6968 //case 54775: break; // Abandon Vehicle on Poly
6969 case 57345: // Darkmoon Card: Greatness
6973 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 60229;stat
= GetStat(STAT_STRENGTH
); }
6975 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 60233;stat
= GetStat(STAT_AGILITY
); }
6977 if (GetStat(STAT_INTELLECT
)> stat
) { trigger_spell_id
= 60234;stat
= GetStat(STAT_INTELLECT
);}
6979 if (GetStat(STAT_SPIRIT
) > stat
) { trigger_spell_id
= 60235; }
6982 //case 55580: break: // Mana Link
6983 //case 57587: break: // Steal Ranged ()
6984 //case 57594: break; // Copy Ranged Weapon
6985 //case 59237: break; // Beast's Mark
6986 // trigger_spell_id = 59233; break;
6987 //case 59288: break; // Infra-Green Shield
6988 //case 59532: break; // Abandon Passengers on Poly
6989 //case 59735: break: // Woe Strike
6990 case 67702: // Death's Choice, Item - Coliseum 25 Normal Melee Trinket
6994 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67708;stat
= GetStat(STAT_STRENGTH
); }
6996 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67703; }
6999 case 67771: // Death's Choice (heroic), Item - Coliseum 25 Heroic Melee Trinket
7003 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 67773;stat
= GetStat(STAT_STRENGTH
); }
7005 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 67772; }
7010 case SPELLFAMILY_MAGE
:
7011 if (auraSpellInfo
->SpellIconID
== 2127) // Blazing Speed
7013 switch (auraSpellInfo
->Id
)
7015 case 31641: // Rank 1
7016 case 31642: // Rank 2
7017 trigger_spell_id
= 31643;
7020 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
7024 // Persistent Shield (Scarab Brooch trinket)
7025 else if(auraSpellInfo
->Id
== 26467)
7027 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
7028 basepoints
[0] = damage
* 15 / 100;
7030 trigger_spell_id
= 26470;
7033 case SPELLFAMILY_WARRIOR
:
7034 // Deep Wounds (replace triggered spells to directly apply DoT), dot spell have finilyflags
7035 if (auraSpellInfo
->SpellFamilyFlags
== UI64LIT(0x0) && auraSpellInfo
->SpellIconID
== 243)
7038 // DW should benefit of attack power, damage percent mods etc.
7039 // TODO: check if using offhand damage is correct and if it should be divided by 2
7040 if (haveOffhandWeapon() && getAttackTimer(BASE_ATTACK
) > getAttackTimer(OFF_ATTACK
))
7041 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
))/2;
7043 weaponDamage
= (GetFloatValue(UNIT_FIELD_MINDAMAGE
) + GetFloatValue(UNIT_FIELD_MAXDAMAGE
))/2;
7045 switch (auraSpellInfo
->Id
)
7047 case 12834: basepoints
[0] = int32(weaponDamage
* 16 / 100); break;
7048 case 12849: basepoints
[0] = int32(weaponDamage
* 32 / 100); break;
7049 case 12867: basepoints
[0] = int32(weaponDamage
* 48 / 100); break;
7052 sLog
.outError("Unit::HandleProcTriggerSpell: DW unknown spell rank %u",auraSpellInfo
->Id
);
7056 // 1 tick/sec * 6 sec = 6 ticks
7059 trigger_spell_id
= 12721;
7062 if (auraSpellInfo
->Id
== 50421) // Scent of Blood
7063 trigger_spell_id
= 50422;
7065 case SPELLFAMILY_WARLOCK
:
7068 if (auraSpellInfo
->SpellIconID
== 1137)
7070 if(!pVictim
|| !pVictim
->isAlive() || pVictim
== this || procSpell
== NULL
)
7072 // Calculate spell tick count for spells
7073 uint32 tick
= 1; // Default tick = 1
7075 // Hellfire have 15 tick
7076 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000040))
7078 // Rain of Fire have 4 tick
7079 else if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000020))
7084 // Calculate chance = baseChance / tick
7086 switch (auraSpellInfo
->Id
)
7088 case 18096: chance
= 13.0f
/ tick
; break;
7089 case 18073: chance
= 26.0f
/ tick
; break;
7092 if (!roll_chance_f(chance
))
7095 trigger_spell_id
= 18093;
7098 else if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
7100 Unit::AuraList
const& mAddFlatModifier
= GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER
);
7101 for(Unit::AuraList::const_iterator i
= mAddFlatModifier
.begin(); i
!= mAddFlatModifier
.end(); ++i
)
7103 if ((*i
)->GetModifier()->m_miscvalue
== SPELLMOD_CHANCE_OF_SUCCESS
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
7106 CastCustomSpell(this, 18371, &basepoints
[0], NULL
, NULL
, true, castItem
, triggeredByAura
);
7110 // Not remove charge (aura removed on death in any cases)
7111 // Need for correct work Drain Soul SPELL_AURA_CHANNEL_DEATH_ITEM aura
7114 // Nether Protection
7115 else if (auraSpellInfo
->SpellIconID
== 1985)
7119 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7121 case SPELL_SCHOOL_NORMAL
:
7122 return false; // ignore
7123 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 54370; break;
7124 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 54371; break;
7125 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 54375; break;
7126 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 54372; break;
7127 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 54374; break;
7128 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
7134 else if (auraSpellInfo
->Id
== 28845)
7136 // When your health drops below 20% ....
7137 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
7141 else if (auraSpellInfo
->Id
== 63156 || auraSpellInfo
->Id
== 63158)
7143 // Looking for dummy effect
7144 Aura
*aur
= GetAura(auraSpellInfo
->Id
, 1);
7148 // If target's health is not below equal certain value (35%) not proc
7149 if ((pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth()) > aur
->GetModifier()->m_amount
)
7154 case SPELLFAMILY_PRIEST
:
7156 // Greater Heal Refund (Avatar Raiment set)
7157 if (auraSpellInfo
->Id
==37594)
7159 // Not give if target already have full health
7160 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
7162 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
7163 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
7165 trigger_spell_id
= 37595;
7168 else if (auraSpellInfo
->SpellIconID
== 1875)
7170 switch (auraSpellInfo
->Id
)
7172 case 27811: trigger_spell_id
= 27813; break;
7173 case 27815: trigger_spell_id
= 27817; break;
7174 case 27816: trigger_spell_id
= 27818; break;
7176 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
7179 basepoints
[0] = damage
* triggerAmount
/ 100 / 3;
7184 case SPELLFAMILY_DRUID
:
7186 // Druid Forms Trinket
7187 if (auraSpellInfo
->Id
==37336)
7191 case FORM_NONE
: trigger_spell_id
= 37344;break;
7192 case FORM_CAT
: trigger_spell_id
= 37341;break;
7194 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
7195 case FORM_TREE
: trigger_spell_id
= 37342;break;
7196 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
7201 // Druid T9 Feral Relic (Lacerate, Swipe, Mangle, and Shred)
7202 else if (auraSpellInfo
->Id
==67353)
7206 case FORM_CAT
: trigger_spell_id
= 67355; break;
7208 case FORM_DIREBEAR
: trigger_spell_id
= 67354; break;
7215 case SPELLFAMILY_HUNTER
:
7217 if (auraSpellInfo
->SpellIconID
== 3247 && auraSpellInfo
->SpellVisual
[0] == 0)
7219 basepoints
[0] = damage
* triggerAmount
/ 100 / 8;
7220 trigger_spell_id
= 63468;
7223 // Rapid Recuperation
7224 else if (auraSpellInfo
->Id
== 53228 || auraSpellInfo
->Id
== 53232)
7226 // This effect only from Rapid Fire (ability cast)
7227 if (!(procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000020)))
7231 case SPELLFAMILY_PALADIN
:
7235 if (auraSpellInfo->SpellIconID == 2137)
7237 switch (auraSpellInfo->Id)
7239 case 31828: // Rank 1
7240 case 31829: // Rank 2
7241 case 31830: // Rank 3
7244 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
7250 if (auraSpellInfo
->Id
==37705)
7252 trigger_spell_id
= 37706;
7256 if (auraSpellInfo
->Id
==60510)
7258 trigger_spell_id
= 60515;
7262 else if (auraSpellInfo
->SpellIconID
==241)
7266 // procspell is triggered spell but we need mana cost of original casted spell
7267 uint32 originalSpellId
= procSpell
->Id
;
7269 if (procSpell
->SpellFamilyFlags
& UI64LIT(0x0001000000000000))
7271 switch(procSpell
->Id
)
7273 case 25914: originalSpellId
= 20473; break;
7274 case 25913: originalSpellId
= 20929; break;
7275 case 25903: originalSpellId
= 20930; break;
7276 case 27175: originalSpellId
= 27174; break;
7277 case 33074: originalSpellId
= 33072; break;
7278 case 48820: originalSpellId
= 48824; break;
7279 case 48821: originalSpellId
= 48825; break;
7281 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
7285 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
7288 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
7291 // percent stored in effect 1 (class scripts) base points
7292 int32 cost
= originalSpell
->manaCost
+ originalSpell
->ManaCostPercentage
* GetCreateMana() / 100;
7293 basepoints
[0] = cost
*auraSpellInfo
->CalculateSimpleValue(1)/100;
7294 trigger_spell_id
= 20272;
7297 // Lightning Capacitor
7298 else if (auraSpellInfo
->Id
==37657)
7300 if(!pVictim
|| !pVictim
->isAlive())
7303 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
7305 Aura
* dummy
= GetDummyAura(37658);
7306 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7307 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7310 RemoveAurasDueToSpell(37658);
7311 trigger_spell_id
= 37661;
7314 // Bonus Healing (Crystal Spire of Karabor mace)
7315 else if (auraSpellInfo
->Id
== 40971)
7317 // If your target is below $s1% health
7318 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
7321 // Thunder Capacitor
7322 else if (auraSpellInfo
->Id
== 54841)
7324 if(!pVictim
|| !pVictim
->isAlive())
7327 CastSpell(this, 54842, true, NULL
, triggeredByAura
);
7330 Aura
* dummy
= GetDummyAura(54842);
7331 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7332 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
7335 RemoveAurasDueToSpell(54842);
7336 trigger_spell_id
= 54843;
7341 case SPELLFAMILY_SHAMAN
:
7343 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc
7344 if (auraSpellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000400))
7346 switch(auraSpellInfo
->Id
)
7349 trigger_spell_id
= 26364; break;
7351 trigger_spell_id
= 26365; break;
7353 trigger_spell_id
= 26366; break;
7355 trigger_spell_id
= 26367; break;
7356 case 8134: // Rank 5
7357 trigger_spell_id
= 26369; break;
7358 case 10431: // Rank 6
7359 trigger_spell_id
= 26370; break;
7360 case 10432: // Rank 7
7361 trigger_spell_id
= 26363; break;
7362 case 25469: // Rank 8
7363 trigger_spell_id
= 26371; break;
7364 case 25472: // Rank 9
7365 trigger_spell_id
= 26372; break;
7366 case 49280: // Rank 10
7367 trigger_spell_id
= 49278; break;
7368 case 49281: // Rank 11
7369 trigger_spell_id
= 49279; break;
7371 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
7375 // Lightning Shield (The Ten Storms set)
7376 else if (auraSpellInfo
->Id
== 23551)
7378 trigger_spell_id
= 23552;
7381 // Damage from Lightning Shield (The Ten Storms set)
7382 else if (auraSpellInfo
->Id
== 23552)
7383 trigger_spell_id
= 27635;
7384 // Mana Surge (The Earthfury set)
7385 else if (auraSpellInfo
->Id
== 23572)
7389 basepoints
[0] = procSpell
->manaCost
* 35 / 100;
7390 trigger_spell_id
= 23571;
7393 // Nature's Guardian
7394 else if (auraSpellInfo
->SpellIconID
== 2013)
7396 // Check health condition - should drop to less 30% (damage deal after this!)
7397 if (!(10*(int32(GetHealth() - damage
)) < 3 * GetMaxHealth()))
7400 if(pVictim
&& pVictim
->isAlive())
7401 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
7403 basepoints
[0] = triggerAmount
* GetMaxHealth() / 100;
7404 trigger_spell_id
= 31616;
7409 case SPELLFAMILY_DEATHKNIGHT
:
7412 if (auraSpellInfo
->SpellIconID
== 1930)
7416 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
7418 case SPELL_SCHOOL_NORMAL
:
7419 return false; // ignore
7420 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 50490; break;
7421 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 50362; break;
7422 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 50488; break;
7423 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 50485; break;
7424 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 50489; break;
7425 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 50486; break;
7431 else if (auraSpellInfo
->Id
== 48266)
7433 if (GetTypeId() != TYPEID_PLAYER
)
7435 if (!((Player
*)this)->isHonorOrXPTarget(pVictim
))
7437 trigger_spell_id
= 50475;
7438 basepoints
[0] = damage
* triggerAmount
/ 100;
7441 else if (auraSpellInfo
->SpellIconID
== 85)
7443 if (GetTypeId() != TYPEID_PLAYER
|| getClass() != CLASS_DEATH_KNIGHT
||
7444 !((Player
*)this)->IsBaseRuneSlotsOnCooldown(RUNE_BLOOD
))
7453 // All ok. Check current trigger spell
7454 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
7457 // Not cast unknown spell
7458 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
7462 // not allow proc extra attack spell at extra attack
7463 if (m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
))
7466 // Custom basepoints/target for exist spell
7467 // dummy basepoints or other customs
7468 switch(trigger_spell_id
)
7470 // Cast positive spell on enemy target
7471 case 7099: // Curse of Mending
7472 case 39647: // Curse of Mending
7473 case 29494: // Temptation
7474 case 20233: // Improved Lay on Hands (cast on target)
7479 // Combo points add triggers (need add combopoint only for main target, and after possible combopoints reset)
7480 case 15250: // Rogue Setup
7482 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
7484 break; // continue normal case
7486 // Finish movies that add combo
7487 case 14189: // Seal Fate (Netherblade set)
7488 case 14157: // Ruthlessness
7490 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
7493 // Bloodthirst (($m/100)% of max health)
7496 basepoints
[0] = int32(GetMaxHealth() * triggerAmount
/ 100);
7499 // Shamanistic Rage triggered spell
7502 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7505 // Enlightenment (trigger only from mana cost spells)
7508 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
7515 // As the spell is proced from pet's attack - find owner
7516 Unit
* owner
= GetOwner();
7517 if (!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
7520 // This spell doesn't stack, but refreshes duration. So we receive current bonuses to minus them later.
7522 if (Aura
* aur
= owner
->GetAura(48090,0))
7523 curBonus
= aur
->GetModifier()->m_amount
;
7524 int32 spellDamage
= owner
->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_MAGIC
) - curBonus
;
7525 if(spellDamage
<= 0)
7528 // percent stored in owner talent dummy
7529 AuraList
const& dummyAuras
= owner
->GetAurasByType(SPELL_AURA_DUMMY
);
7530 for (AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
7532 if ((*i
)->GetSpellProto()->SpellIconID
== 3220)
7534 basepoints
[0] = basepoints
[1] = int32(spellDamage
* (*i
)->GetModifier()->m_amount
/ 100);
7543 // Remove cooldown on Shield Slam
7544 if (GetTypeId() == TYPEID_PLAYER
)
7545 ((Player
*)this)->RemoveSpellCategoryCooldown(1209, true);
7551 // have rank dependent proc chance, ignore too often cases
7552 // PPM = 2.5 * (rank of talent),
7553 uint32 rank
= sSpellMgr
.GetSpellRank(auraSpellInfo
->Id
);
7554 // 5 rank -> 100% 4 rank -> 80% and etc from full rate
7555 if(!roll_chance_i(20*rank
))
7564 // For trigger from Blizzard need exist Improved Blizzard
7565 if (procSpell
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (procSpell
->SpellFamilyFlags
& UI64LIT(0x0000000000000080)))
7568 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7569 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7571 int32 script
= (*i
)->GetModifier()->m_miscvalue
;
7572 if(script
==836 || script
==988 || script
==989)
7586 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
7589 // Need stun, fear or silence mechanic
7590 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_SILENCE_AND_STUN_AND_FEAR_MASK
))
7594 // Burning Determination
7599 // Need Interrupt or Silenced mechanic
7600 if (!(GetAllSpellMechanicMask(procSpell
) & IMMUNE_TO_INTERRUPT_AND_SILENCE_MASK
))
7607 // Proc only from trap activation (from periodic proc another aura of this spell)
7608 if (!(procFlags
& PROC_FLAG_ON_TRAP_ACTIVATION
) || !roll_chance_i(triggerAmount
))
7612 // Druid - Savage Defense
7615 basepoints
[0] = int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7620 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
7623 // try detect target manually if not set
7624 if ( target
== NULL
)
7625 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
7628 if(!target
|| target
!=this && !target
->isAlive())
7631 if(basepoints
[0] || basepoints
[1] || basepoints
[2])
7632 CastCustomSpell(target
,trigger_spell_id
,
7633 basepoints
[0] ? &basepoints
[0] : NULL
,
7634 basepoints
[1] ? &basepoints
[1] : NULL
,
7635 basepoints
[2] ? &basepoints
[2] : NULL
,
7636 true,castItem
,triggeredByAura
);
7638 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
7640 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7641 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
7646 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32 damage
, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
7648 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
7650 if(!pVictim
|| !pVictim
->isAlive())
7653 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7654 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7656 // Basepoints of trigger aura
7657 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7659 uint32 triggered_spell_id
= 0;
7663 case 836: // Improved Blizzard (Rank 1)
7665 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7667 triggered_spell_id
= 12484;
7670 case 988: // Improved Blizzard (Rank 2)
7672 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7674 triggered_spell_id
= 12485;
7677 case 989: // Improved Blizzard (Rank 3)
7679 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
7681 triggered_spell_id
= 12486;
7684 case 4086: // Improved Mend Pet (Rank 1)
7685 case 4087: // Improved Mend Pet (Rank 2)
7687 if(!roll_chance_i(triggerAmount
))
7690 triggered_spell_id
= 24406;
7693 case 4533: // Dreamwalker Raiment 2 pieces bonus
7696 if (!roll_chance_i(50))
7699 switch (pVictim
->getPowerType())
7701 case POWER_MANA
: triggered_spell_id
= 28722; break;
7702 case POWER_RAGE
: triggered_spell_id
= 28723; break;
7703 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
7709 case 4537: // Dreamwalker Raiment 6 pieces bonus
7710 triggered_spell_id
= 28750; // Blessing of the Claw
7712 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
7713 triggered_spell_id
= 37445; // Mana Surge
7715 case 6953: // Warbringer
7716 RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK
,0,true);
7718 case 7010: // Revitalize (rank 1)
7719 case 7011: // Revitalize (rank 2)
7720 case 7012: // Revitalize (rank 3)
7722 if(!roll_chance_i(triggerAmount
))
7725 switch( pVictim
->getPowerType() )
7727 case POWER_MANA
: triggered_spell_id
= 48542; break;
7728 case POWER_RAGE
: triggered_spell_id
= 48541; break;
7729 case POWER_ENERGY
: triggered_spell_id
= 48540; break;
7730 case POWER_RUNIC_POWER
: triggered_spell_id
= 48543; break;
7731 default: return false;
7738 if(!triggered_spell_id
)
7741 // standard non-dummy case
7742 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
7746 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
7750 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
7753 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
7755 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7756 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
7761 void Unit::setPowerType(Powers new_powertype
)
7763 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
7765 if(GetTypeId() == TYPEID_PLAYER
)
7767 if(((Player
*)this)->GetGroup())
7768 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
7770 else if(((Creature
*)this)->isPet())
7772 Pet
*pet
= ((Pet
*)this);
7773 if(pet
->isControlled())
7775 Unit
*owner
= GetOwner();
7776 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
7777 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
7781 switch(new_powertype
)
7787 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
7788 SetPower( POWER_RAGE
,0);
7791 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
7792 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
7795 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
7797 case POWER_HAPPINESS
:
7798 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
7799 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
7804 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
7806 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
7809 static uint64 guid
= 0; // prevent repeating spam same faction problem
7811 if(GetGUID() != guid
)
7813 if(GetTypeId() == TYPEID_PLAYER
)
7814 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
7816 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
7823 bool Unit::IsHostileTo(Unit
const* unit
) const
7825 // always non-hostile to self
7829 // always non-hostile to GM in GM mode
7830 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
7833 // always hostile to enemy
7834 if(getVictim()==unit
|| unit
->getVictim()==this)
7837 // test pet/charm masters instead pers/charmeds
7838 Unit
const* testerOwner
= GetCharmerOrOwner();
7839 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
7841 // always hostile to owner's enemy
7842 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
7845 // always hostile to enemy owner
7846 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
7849 // always hostile to owner of owner's enemy
7850 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
7853 Unit
const* tester
= testerOwner
? testerOwner
: this;
7854 Unit
const* target
= targetOwner
? targetOwner
: unit
;
7856 // always non-hostile to target with common owner, or to owner/pet
7860 // special cases (Duel, etc)
7861 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
7863 Player
const* pTester
= (Player
const*)tester
;
7864 Player
const* pTarget
= (Player
const*)target
;
7867 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
7871 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
7875 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
7879 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
7883 // Green/Blue (can't attack)
7884 if(pTester
->GetTeam()==pTarget
->GetTeam())
7887 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
7888 return pTester
->IsPvP() && pTarget
->IsPvP();
7891 // faction base cases
7892 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
7893 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
7894 if(!tester_faction
|| !target_faction
)
7897 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
7900 // PvC forced reaction and reputation case
7901 if(tester
->GetTypeId()==TYPEID_PLAYER
)
7904 if(target_faction
->faction
)
7906 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
7907 return *force
<= REP_HOSTILE
;
7909 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
7910 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
7911 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
7912 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
7915 // CvP forced reaction and reputation case
7916 else if(target
->GetTypeId()==TYPEID_PLAYER
)
7919 if(tester_faction
->faction
)
7921 if(ReputationRank
const* force
= ((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
7922 return *force
<= REP_HOSTILE
;
7924 // apply reputation state
7925 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
7926 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
7927 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) <= REP_HOSTILE
;
7931 // common faction based case (CvC,PvC,CvP)
7932 return tester_faction
->IsHostileTo(*target_faction
);
7935 bool Unit::IsFriendlyTo(Unit
const* unit
) const
7937 // always friendly to self
7941 // always friendly to GM in GM mode
7942 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
7945 // always non-friendly to enemy
7946 if(getVictim()==unit
|| unit
->getVictim()==this)
7949 // test pet/charm masters instead pers/charmeds
7950 Unit
const* testerOwner
= GetCharmerOrOwner();
7951 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
7953 // always non-friendly to owner's enemy
7954 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
7957 // always non-friendly to enemy owner
7958 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
7961 // always non-friendly to owner of owner's enemy
7962 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
7965 Unit
const* tester
= testerOwner
? testerOwner
: this;
7966 Unit
const* target
= targetOwner
? targetOwner
: unit
;
7968 // always friendly to target with common owner, or to owner/pet
7972 // special cases (Duel)
7973 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
7975 Player
const* pTester
= (Player
const*)tester
;
7976 Player
const* pTarget
= (Player
const*)target
;
7979 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
7983 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
7987 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
7991 if(pTester
->IsFFAPvP() && pTarget
->IsFFAPvP())
7995 // Green/Blue (non-attackable)
7996 if(pTester
->GetTeam()==pTarget
->GetTeam())
7999 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
8000 return !pTarget
->IsPvP();
8003 // faction base cases
8004 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8005 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8006 if(!tester_faction
|| !target_faction
)
8009 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8012 // PvC forced reaction and reputation case
8013 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8016 if(target_faction
->faction
)
8018 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
8019 return *force
>= REP_FRIENDLY
;
8021 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
8022 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8023 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
8024 return !(factionState
->Flags
& FACTION_FLAG_AT_WAR
);
8027 // CvP forced reaction and reputation case
8028 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8031 if(tester_faction
->faction
)
8033 if(ReputationRank
const* force
=((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
8034 return *force
>= REP_FRIENDLY
;
8036 // apply reputation state
8037 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
8038 if(raw_tester_faction
->reputationListID
>=0 )
8039 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) >= REP_FRIENDLY
;
8043 // common faction based case (CvC,PvC,CvP)
8044 return tester_faction
->IsFriendlyTo(*target_faction
);
8047 bool Unit::IsHostileToPlayers() const
8049 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8050 if(!my_faction
|| !my_faction
->faction
)
8053 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8054 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8057 return my_faction
->IsHostileToPlayers();
8060 bool Unit::IsNeutralToAll() const
8062 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8063 if(!my_faction
|| !my_faction
->faction
)
8066 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8067 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8070 return my_faction
->IsNeutralToAll();
8073 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
8075 if(!victim
|| victim
== this)
8078 // dead units can neither attack nor be attacked
8079 if(!isAlive() || !victim
->IsInWorld() || !victim
->isAlive())
8082 // player cannot attack in mount state
8083 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
8086 // nobody can attack GM in GM-mode
8087 if(victim
->GetTypeId()==TYPEID_PLAYER
)
8089 if(((Player
*)victim
)->isGameMaster())
8094 if(((Creature
*)victim
)->IsInEvadeMode())
8098 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
8099 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
8100 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
8102 // in fighting already
8105 if (m_attacking
== victim
)
8107 // switch to melee attack from ranged/magic
8108 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
8110 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8111 SendMeleeAttackStart(victim
);
8117 // remove old target data
8123 // set position before any AI calls/assistance
8124 if(GetTypeId()==TYPEID_UNIT
)
8125 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
8129 SetTargetGUID(victim
->GetGUID());
8132 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8134 m_attacking
= victim
;
8135 m_attacking
->_addAttacker(this);
8137 if (GetTypeId() == TYPEID_UNIT
)
8139 ((Creature
*)this)->SendAIReaction(AI_REACTION_AGGRO
);
8140 ((Creature
*)this)->CallAssistance();
8143 // delay offhand weapon attack to next attack time
8144 if(haveOffhandWeapon())
8145 resetAttackTimer(OFF_ATTACK
);
8148 SendMeleeAttackStart(victim
);
8153 bool Unit::AttackStop(bool targetSwitch
/*=false*/)
8158 Unit
* victim
= m_attacking
;
8160 m_attacking
->_removeAttacker(this);
8166 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
8168 InterruptSpell(CURRENT_MELEE_SPELL
);
8170 // reset only at real combat stop
8171 if(!targetSwitch
&& GetTypeId()==TYPEID_UNIT
)
8173 ((Creature
*)this)->SetNoCallAssistance(false);
8175 if (((Creature
*)this)->HasSearchedAssistance())
8177 ((Creature
*)this)->SetNoSearchAssistance(false);
8178 UpdateSpeed(MOVE_RUN
, false);
8182 SendMeleeAttackStop(victim
);
8187 void Unit::CombatStop(bool includingCast
)
8189 if (includingCast
&& IsNonMeleeSpellCasted(false))
8190 InterruptNonMeleeSpells(false);
8193 RemoveAllAttackers();
8194 if( GetTypeId()==TYPEID_PLAYER
)
8195 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
8199 struct CombatStopWithPetsHelper
8201 explicit CombatStopWithPetsHelper(bool _includingCast
) : includingCast(_includingCast
) {}
8202 void operator()(Unit
* unit
) const { unit
->CombatStop(includingCast
); }
8206 void Unit::CombatStopWithPets(bool includingCast
)
8208 CombatStop(includingCast
);
8209 CallForAllControlledUnits(CombatStopWithPetsHelper(includingCast
),false,true,true);
8212 struct IsAttackingPlayerHelper
8214 explicit IsAttackingPlayerHelper() {}
8215 bool operator()(Unit
* unit
) const { return unit
->isAttackingPlayer(); }
8218 bool Unit::isAttackingPlayer() const
8220 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
8223 return CheckAllControlledUnits(IsAttackingPlayerHelper(),true,true,true);
8226 void Unit::RemoveAllAttackers()
8228 while (!m_attackers
.empty())
8230 AttackerSet::iterator iter
= m_attackers
.begin();
8231 if(!(*iter
)->AttackStop())
8233 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
8234 m_attackers
.erase(iter
);
8239 bool Unit::HasAuraStateForCaster(AuraState flag
, uint64 caster
) const
8241 if(!HasAuraState(flag
))
8244 // single per-caster aura state
8245 if(flag
== AURA_STATE_CONFLAGRATE
)
8247 Unit::AuraList
const& dotList
= GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
8248 for(Unit::AuraList::const_iterator i
= dotList
.begin(); i
!= dotList
.end(); ++i
)
8250 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
8251 (*i
)->GetCasterGUID() == caster
&&
8253 (((*i
)->GetSpellProto()->SpellFamilyFlags
& UI64LIT(0x0000000000000004)) ||
8255 ((*i
)->GetSpellProto()->SpellFamilyFlags2
& 0x00000002)))
8267 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
8271 if (!HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)))
8273 SetFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8274 if(GetTypeId() == TYPEID_PLAYER
)
8276 const PlayerSpellMap
& sp_list
= ((Player
*)this)->GetSpellMap();
8277 for (PlayerSpellMap::const_iterator itr
= sp_list
.begin(); itr
!= sp_list
.end(); ++itr
)
8279 if(itr
->second
->state
== PLAYERSPELL_REMOVED
) continue;
8280 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
8281 if (!spellInfo
|| !IsPassiveSpell(itr
->first
)) continue;
8282 if (spellInfo
->CasterAuraState
== flag
)
8283 CastSpell(this, itr
->first
, true, NULL
);
8290 if (HasFlag(UNIT_FIELD_AURASTATE
,1<<(flag
-1)))
8292 RemoveFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8294 if (flag
!= AURA_STATE_ENRAGE
) // enrage aura state triggering continues auras
8296 Unit::AuraMap
& tAuras
= GetAuras();
8297 for (Unit::AuraMap::iterator itr
= tAuras
.begin(); itr
!= tAuras
.end();)
8299 SpellEntry
const* spellProto
= (*itr
).second
->GetSpellProto();
8300 if (spellProto
->CasterAuraState
== flag
)
8302 // exceptions (applied at state but not removed at state change)
8304 if(spellProto
->SpellIconID
==2006 && spellProto
->SpellFamilyName
==SPELLFAMILY_WARRIOR
&& spellProto
->SpellFamilyFlags
==0x100000)
8320 Unit
*Unit::GetOwner() const
8322 if(uint64 ownerid
= GetOwnerGUID())
8323 return ObjectAccessor::GetUnit(*this, ownerid
);
8327 Unit
*Unit::GetCharmer() const
8329 if(uint64 charmerid
= GetCharmerGUID())
8330 return ObjectAccessor::GetUnit(*this, charmerid
);
8334 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
8336 uint64 guid
= GetCharmerOrOwnerGUID();
8337 if(IS_PLAYER_GUID(guid
))
8338 return ObjectAccessor::FindPlayer(guid
);
8340 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
8343 Pet
* Unit::GetPet() const
8345 if(uint64 pet_guid
= GetPetGUID())
8347 if(Pet
* pet
= GetMap()->GetPet(pet_guid
))
8350 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
8351 const_cast<Unit
*>(this)->SetPet(0);
8357 Unit
* Unit::GetCharm() const
8359 if (uint64 charm_guid
= GetCharmGUID())
8361 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
8364 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
8365 const_cast<Unit
*>(this)->SetCharm(NULL
);
8371 void Unit::Uncharm()
8373 if (Unit
* charm
= GetCharm())
8375 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM
);
8376 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS
);
8380 float Unit::GetCombatDistance( const Unit
* target
) const
8382 float radius
= target
->GetFloatValue(UNIT_FIELD_COMBATREACH
) + GetFloatValue(UNIT_FIELD_COMBATREACH
);
8383 float dx
= GetPositionX() - target
->GetPositionX();
8384 float dy
= GetPositionY() - target
->GetPositionY();
8385 float dz
= GetPositionZ() - target
->GetPositionZ();
8386 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - radius
;
8387 return ( dist
> 0 ? dist
: 0);
8390 void Unit::SetPet(Pet
* pet
)
8392 SetPetGUID(pet
? pet
->GetGUID() : 0);
8394 if(pet
&& GetTypeId() == TYPEID_PLAYER
)
8395 ((Player
*)this)->SendPetGUIDs();
8397 // FIXME: hack, speed must be set only at follow
8398 if(pet
&& GetTypeId()==TYPEID_PLAYER
)
8399 for(int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
8400 pet
->SetSpeedRate(UnitMoveType(i
), m_speed_rate
[i
], true);
8403 void Unit::SetCharm(Unit
* pet
)
8405 SetCharmGUID(pet
? pet
->GetGUID() : 0);
8408 void Unit::AddGuardian( Pet
* pet
)
8410 m_guardianPets
.insert(pet
->GetGUID());
8413 void Unit::RemoveGuardian( Pet
* pet
)
8415 m_guardianPets
.erase(pet
->GetGUID());
8418 void Unit::RemoveGuardians()
8420 while(!m_guardianPets
.empty())
8422 uint64 guid
= *m_guardianPets
.begin();
8423 if(Pet
* pet
= GetMap()->GetPet(guid
))
8424 pet
->Remove(PET_SAVE_AS_DELETED
);
8426 m_guardianPets
.erase(guid
);
8430 Pet
* Unit::FindGuardianWithEntry(uint32 entry
)
8432 // pet guid middle part is entry (and creature also)
8433 // and in guardian list must be guardians with same entry _always_
8434 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
8435 if(Pet
* pet
= GetMap()->GetPet(*itr
))
8436 if (pet
->GetEntry() == entry
)
8442 Unit
* Unit::_GetTotem(uint8 slot
) const
8444 return GetTotem(slot
);
8447 Totem
* Unit::GetTotem( uint8 slot
) const
8449 if(slot
>= MAX_TOTEM
|| !IsInWorld())
8452 Creature
*totem
= GetMap()->GetCreature(m_TotemSlot
[slot
]);
8453 return totem
&& totem
->isTotem() ? (Totem
*)totem
: NULL
;
8456 void Unit::UnsummonAllTotems()
8458 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
8463 Creature
*OldTotem
= GetMap()->GetCreature(m_TotemSlot
[i
]);
8464 if (OldTotem
&& OldTotem
->isTotem())
8465 ((Totem
*)OldTotem
)->UnSummon();
8469 int32
Unit::DealHeal(Unit
*pVictim
, uint32 addhealth
, SpellEntry
const *spellProto
, bool critical
)
8471 int32 gain
= pVictim
->ModifyHealth(int32(addhealth
));
8475 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8478 if (unit
->GetTypeId()==TYPEID_PLAYER
)
8480 // overheal = addhealth - gain
8481 unit
->SendHealSpellLog(pVictim
, spellProto
->Id
, addhealth
, addhealth
- gain
, critical
);
8483 if (BattleGround
*bg
= ((Player
*)unit
)->GetBattleGround())
8484 bg
->UpdatePlayerScore((Player
*)unit
, SCORE_HEALING_DONE
, gain
);
8486 // use the actual gain, as the overheal shall not be counted, skip gain 0 (it ignored anyway in to criteria)
8488 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE
, gain
, 0, pVictim
);
8490 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED
, addhealth
);
8493 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
8495 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED
, gain
);
8496 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED
, addhealth
);
8502 Unit
* Unit::SelectMagnetTarget(Unit
*victim
, SpellEntry
const *spellInfo
)
8508 if(spellInfo
&& (spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
|| spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
))
8510 Unit::AuraList
const& magnetAuras
= victim
->GetAurasByType(SPELL_AURA_SPELL_MAGNET
);
8511 for(Unit::AuraList::const_iterator itr
= magnetAuras
.begin(); itr
!= magnetAuras
.end(); ++itr
)
8512 if(Unit
* magnet
= (*itr
)->GetCaster())
8513 if(magnet
->IsWithinLOSInMap(this) && magnet
->isAlive())
8516 // Melee && ranged case
8519 AuraList
const& hitTriggerAuras
= victim
->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER
);
8520 for(AuraList::const_iterator i
= hitTriggerAuras
.begin(); i
!= hitTriggerAuras
.end(); ++i
)
8521 if(Unit
* magnet
= (*i
)->GetCaster())
8522 if(magnet
->isAlive() && magnet
->IsWithinLOSInMap(this))
8523 if(roll_chance_i((*i
)->GetModifier()->m_amount
))
8530 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, uint32 OverHeal
, bool critical
)
8533 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
8534 data
.append(pVictim
->GetPackGUID());
8535 data
.append(GetPackGUID());
8536 data
<< uint32(SpellID
);
8537 data
<< uint32(Damage
);
8538 data
<< uint32(OverHeal
);
8539 data
<< uint8(critical
? 1 : 0);
8540 data
<< uint8(0); // unused in client?
8541 SendMessageToSet(&data
, true);
8544 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8546 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
8547 data
.append(pVictim
->GetPackGUID());
8548 data
.append(GetPackGUID());
8549 data
<< uint32(SpellID
);
8550 data
<< uint32(powertype
);
8551 data
<< uint32(Damage
);
8552 SendMessageToSet(&data
, true);
8555 void Unit::EnergizeBySpell(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8557 SendEnergizeSpellLog(pVictim
, SpellID
, Damage
, powertype
);
8558 // needs to be called after sending spell log
8559 pVictim
->ModifyPower(powertype
, Damage
);
8562 uint32
Unit::SpellDamageBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
8564 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
8567 // For totems get damage bonus from owner (statue isn't totem in fact)
8568 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8570 if(Unit
* owner
= GetOwner())
8571 return owner
->SpellDamageBonus(pVictim
, spellProto
, pdamage
, damagetype
);
8574 // Taken/Done total percent damage auras
8575 float DoneTotalMod
= 1.0f
;
8576 float TakenTotalMod
= 1.0f
;
8577 int32 DoneTotal
= 0;
8578 int32 TakenTotal
= 0;
8582 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
8583 DoneTotalMod
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
8585 if (!(spellProto
->AttributesEx6
& SPELL_ATTR_EX6_NO_DMG_PERCENT_MODS
))
8587 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
8588 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
8590 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
8591 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
8592 // -1 == any item class (not wand then)
8593 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
8594 // 0 == any inventory type (not wand then)
8596 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8601 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8602 // Add flat bonus from spell damage versus
8603 DoneTotal
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
8604 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
8605 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
8606 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8607 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8609 // done scripted mod (take it from owner)
8610 Unit
*owner
= GetOwner();
8611 if (!owner
) owner
= this;
8612 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8613 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
8615 if (!(*i
)->isAffectedOnSpell(spellProto
))
8617 switch((*i
)->GetModifier()->m_miscvalue
)
8619 case 4920: // Molten Fury
8621 case 6917: // Death's Embrace
8625 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8626 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8633 // effect 1 m_amount
8634 int32 maxPercent
= (*i
)->GetModifier()->m_amount
;
8635 // effect 0 m_amount
8636 int32 stepPercent
= CalculateSpellDamage((*i
)->GetSpellProto(), 0, (*i
)->GetSpellProto()->EffectBasePoints
[0], this);
8637 // count affliction effects and calc additional damage in percentage
8638 int32 modPercent
= 0;
8639 AuraMap
const& victimAuras
= pVictim
->GetAuras();
8640 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
8642 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
8643 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_WARLOCK
|| !(m_spell
->SpellFamilyFlags
& UI64LIT(0x0004071B8044C402)))
8645 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
8646 if (modPercent
>= maxPercent
)
8648 modPercent
= maxPercent
;
8652 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
8655 case 6916: // Death's Embrace
8658 if (HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
))
8659 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8661 case 5481: // Starfire Bonus
8663 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000200002)))
8664 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8667 case 4418: // Increased Shock Damage
8668 case 4554: // Increased Lightning Damage
8669 case 4555: // Improved Moonfire
8670 case 5142: // Increased Lightning Damage
8671 case 5147: // Improved Consecration / Libram of Resurgence
8672 case 5148: // Idol of the Shooting Star
8673 case 6008: // Increased Lightning Damage / Totem of Hex
8675 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
8683 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
8685 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8686 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8688 else // Tundra Stalker
8690 // Frost Fever (target debuff)
8691 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
8692 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8697 case 7293: // Rage of Rivendare
8699 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
8700 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8706 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, UI64LIT(0x0000000000008000), 0, GetGUID()))
8707 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8717 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
8718 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8724 // Custom scripted damage
8725 switch(spellProto
->SpellFamilyName
)
8727 case SPELLFAMILY_MAGE
:
8730 if (spellProto
->SpellIconID
== 186)
8732 if (pVictim
->isFrozen())
8734 float multiplier
= 3.0f
;
8736 // if target have higher level
8737 if (pVictim
->getLevel() > getLevel())
8738 // Glyph of Ice Lance
8739 if (Aura
* glyph
= GetDummyAura(56377))
8740 multiplier
= glyph
->GetModifier()->m_amount
;
8742 DoneTotalMod
*= multiplier
;
8745 // Torment the weak affected (Arcane Barrage, Arcane Blast, Frostfire Bolt, Arcane Missiles, Fireball)
8746 if ((spellProto
->SpellFamilyFlags
& UI64LIT(0x0000900020200021)) &&
8747 (pVictim
->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED
) || pVictim
->HasAuraType(SPELL_AURA_MELEE_SLOW
)))
8749 //Search for Torment the weak dummy aura
8750 Unit::AuraList
const& ttw
= GetAurasByType(SPELL_AURA_DUMMY
);
8751 for(Unit::AuraList::const_iterator i
= ttw
.begin(); i
!= ttw
.end(); ++i
)
8753 if ((*i
)->GetSpellProto()->SpellIconID
== 3263)
8755 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
8762 case SPELLFAMILY_WARLOCK
:
8765 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000004000))
8767 if (pVictim
->GetHealth() * 100 / pVictim
->GetMaxHealth() <= 25)
8772 case SPELLFAMILY_DEATHKNIGHT
:
8774 // Icy Touch, Howling Blast and Frost Strike
8775 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000600000002))
8779 Unit::AuraMap
const& auras
= pVictim
->GetAuras();
8780 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
8782 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
)
8791 // search for Glacier Rot dummy aura
8792 Unit::AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
8793 for(Unit::AuraList::const_iterator i
= dummyAuras
.begin(); i
!= dummyAuras
.end(); ++i
)
8795 if ((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()] == 7244)
8797 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
8810 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
8811 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
8813 if ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
))
8814 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
8817 // .. taken pct: dummy auras
8818 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
8821 if (Aura
*dummy
= pVictim
->GetDummyAura(45182))
8823 float mod
= -((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
8824 if (mod
< dummy
->GetModifier()->m_amount
)
8825 mod
= dummy
->GetModifier()->m_amount
;
8826 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
8830 // From caster spells
8831 AuraList
const& mOwnerTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_FROM_CASTER
);
8832 for(AuraList::const_iterator i
= mOwnerTaken
.begin(); i
!= mOwnerTaken
.end(); ++i
)
8834 if ((*i
)->GetCasterGUID() == GetGUID() && (*i
)->isAffectedOnSpell(spellProto
))
8835 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
8838 // Mod damage from spell mechanic
8839 TakenTotalMod
*= pVictim
->GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,GetAllSpellMechanicMask(spellProto
));
8841 // Mod damage taken from AoE spells
8842 if(IsAreaOfEffectSpell(spellProto
))
8844 AuraList
const& avoidAuras
= pVictim
->GetAurasByType(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
8845 for(AuraList::const_iterator itr
= avoidAuras
.begin(); itr
!= avoidAuras
.end(); ++itr
)
8846 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
8849 // Taken/Done fixed damage bonus auras
8850 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonus(GetSpellSchoolMask(spellProto
));
8851 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
8853 // Pets just add their bonus damage to their spell damage
8854 // note that their spell damage is just gain of their own auras
8855 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
8856 DoneAdvertisedBenefit
+= ((Pet
*)this)->GetBonusDamage();
8858 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
8859 // Spellmod SpellDamage
8860 float SpellModSpellDamage
= 100.0f
;
8861 if(Player
* modOwner
= GetSpellModOwner())
8862 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
8863 SpellModSpellDamage
/= 100.0f
;
8865 // Check for table values
8866 if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
8869 if (damagetype
== DOT
)
8870 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
8872 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
8874 if (bonus
->ap_bonus
)
8875 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
) * stack
);
8877 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* SpellModSpellDamage
);
8878 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
);
8880 // Default calculation
8881 else if (DoneAdvertisedBenefit
|| TakenAdvertisedBenefit
)
8883 // Damage over Time spells bonus calculation
8884 float DotFactor
= 1.0f
;
8885 if (damagetype
== DOT
)
8887 if (!IsChanneledSpell(spellProto
))
8888 DotFactor
= GetSpellDuration(spellProto
) / 15000.0f
;
8890 if (uint16 DotTicks
= GetSpellAuraMaxTicks(spellProto
))
8892 DoneAdvertisedBenefit
= DoneAdvertisedBenefit
* int32(stack
) / DotTicks
;
8893 TakenAdvertisedBenefit
= TakenAdvertisedBenefit
* int32(stack
) / DotTicks
;
8896 // Distribute Damage over multiple effects, reduce by AoE
8897 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
8898 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
8899 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
8900 for(int j
= 0; j
< 3; ++j
)
8902 if (spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
8903 (spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&&
8904 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
))
8910 DoneTotal
+= int32(DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* SpellModSpellDamage
);
8911 TakenTotal
+= int32(TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
);
8914 float tmpDamage
= (pdamage
+ DoneTotal
) * DoneTotalMod
;
8915 // apply spellmod to Done damage (flat and pct)
8916 if(Player
* modOwner
= GetSpellModOwner())
8917 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
8919 tmpDamage
= (tmpDamage
+ TakenTotal
) * TakenTotalMod
;
8921 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
8924 int32
Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask
)
8926 int32 DoneAdvertisedBenefit
= 0;
8929 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
8930 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
8932 if (((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
8933 (*i
)->GetSpellProto()->EquippedItemClass
== -1 && // -1 == any item class (not wand then)
8934 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0) // 0 == any inventory type (not wand then)
8935 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8938 if (GetTypeId() == TYPEID_PLAYER
)
8941 DoneAdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
8943 // Damage bonus from stats
8944 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
8945 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
8947 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
8949 // stat used stored in miscValueB for this aura
8950 Stats usedStat
= Stats((*i
)->GetMiscBValue());
8951 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
8954 // ... and attack power
8955 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
8956 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
8958 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
8959 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
8963 return DoneAdvertisedBenefit
;
8966 int32
Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
8968 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8970 int32 TakenAdvertisedBenefit
= 0;
8971 // ..done (for creature type by mask) in taken
8972 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
8973 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
8975 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8976 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8980 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
8981 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
8983 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
8984 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8987 return TakenAdvertisedBenefit
;
8990 bool Unit::isSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
8992 // not critting spell
8993 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
8996 float crit_chance
= 0.0f
;
8997 switch(spellProto
->DmgClass
)
8999 case SPELL_DAMAGE_CLASS_NONE
:
9001 case SPELL_DAMAGE_CLASS_MAGIC
:
9003 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
9005 // For other schools
9006 else if (GetTypeId() == TYPEID_PLAYER
)
9007 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
9010 crit_chance
= m_baseSpellCritChance
;
9011 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9016 if (!IsPositiveSpell(spellProto
->Id
))
9018 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
9019 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
9020 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
9021 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
9022 // Modify by player victim resilience
9023 crit_chance
-= pVictim
->GetSpellCritChanceReduction();
9026 // scripted (increase crit chance ... against ... target by x%)
9027 // scripted (Increases the critical effect chance of your .... by x% on targets ...)
9028 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9029 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9031 if (!((*i
)->isAffectedOnSpell(spellProto
)))
9033 switch((*i
)->GetModifier()->m_miscvalue
)
9035 case 849: if (pVictim
->isFrozen()) crit_chance
+= 17.0f
; break; //Shatter Rank 1
9036 case 910: if (pVictim
->isFrozen()) crit_chance
+= 34.0f
; break; //Shatter Rank 2
9037 case 911: if (pVictim
->isFrozen()) crit_chance
+= 50.0f
; break; //Shatter Rank 3
9038 case 7917: // Glyph of Shadowburn
9039 if (pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9040 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9042 case 7997: // Renewed Hope
9044 if (pVictim
->HasAura(6788))
9045 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9051 // Custom crit by class
9052 switch(spellProto
->SpellFamilyName
)
9054 case SPELLFAMILY_PRIEST
:
9056 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000800))
9058 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth()/2)
9060 AuraList
const& mDummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
9061 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9063 // Improved Flash Heal
9064 if ((*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_PRIEST
&&
9065 (*i
)->GetSpellProto()->SpellIconID
== 2542)
9067 crit_chance
+=(*i
)->GetModifier()->m_amount
;
9073 case SPELLFAMILY_PALADIN
:
9075 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000040000000))
9077 Aura
*aura
= pVictim
->GetDummyAura(58597);
9078 if (aura
&& aura
->GetCasterGUID() == GetGUID())
9079 crit_chance
+=aura
->GetModifier()->m_amount
;
9082 else if (spellProto
->Category
== 19)
9084 if (pVictim
->GetCreatureTypeMask() & CREATURE_TYPEMASK_DEMON_OR_UNDEAD
)
9088 case SPELLFAMILY_SHAMAN
:
9090 if (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000100000000000))
9093 if (Aura
*flameShock
= pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000000010000000), 0, GetGUID()))
9101 case SPELL_DAMAGE_CLASS_MELEE
:
9102 case SPELL_DAMAGE_CLASS_RANGED
:
9105 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
9107 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
9114 // only players use intelligence for critical chance computations
9115 if(Player
* modOwner
= GetSpellModOwner())
9116 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
9118 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
9119 if (roll_chance_f(crit_chance
))
9124 uint32
Unit::SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9126 // Calculate critical bonus
9128 switch(spellProto
->DmgClass
)
9130 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9131 case SPELL_DAMAGE_CLASS_RANGED
:
9132 crit_bonus
= damage
;
9135 crit_bonus
= damage
/ 2; // for spells is 50%
9139 // adds additional damage to crit_bonus (from talents)
9140 if(Player
* modOwner
= GetSpellModOwner())
9141 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
9144 return damage
+= crit_bonus
;
9146 int32 critPctDamageMod
= 0;
9147 if(spellProto
->DmgClass
>= SPELL_DAMAGE_CLASS_MELEE
)
9149 if(GetWeaponAttackType(spellProto
) == RANGED_ATTACK
)
9150 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
9152 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
9155 critPctDamageMod
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_DAMAGE
,GetSpellSchoolMask(spellProto
));
9157 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS
, GetSpellSchoolMask(spellProto
));
9159 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9160 critPctDamageMod
+= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
);
9162 if(critPctDamageMod
!=0)
9163 crit_bonus
= int32(crit_bonus
* float((100.0f
+ critPctDamageMod
)/100.0f
));
9166 damage
+= crit_bonus
;
9171 uint32
Unit::SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
9173 // Calculate critical bonus
9175 switch(spellProto
->DmgClass
)
9177 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
9178 case SPELL_DAMAGE_CLASS_RANGED
:
9179 // TODO: write here full calculation for melee/ranged spells
9180 crit_bonus
= damage
;
9183 crit_bonus
= damage
/ 2; // for spells is 50%
9189 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9190 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
9194 damage
+= crit_bonus
;
9196 damage
= int32(damage
* GetTotalAuraMultiplier(SPELL_AURA_MOD_CRITICAL_HEALING_AMOUNT
));
9201 uint32
Unit::SpellHealingBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 healamount
, DamageEffectType damagetype
, uint32 stack
)
9203 // No heal amount for this class spells
9204 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
9207 // For totems get healing bonus from owner (statue isn't totem in fact)
9208 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
9209 if(Unit
* owner
= GetOwner())
9210 return owner
->SpellHealingBonus(pVictim
, spellProto
, healamount
, damagetype
, stack
);
9213 // Taken/Done total percent damage auras
9214 float DoneTotalMod
= 1.0f
;
9215 float TakenTotalMod
= 1.0f
;
9216 int32 DoneTotal
= 0;
9217 int32 TakenTotal
= 0;
9219 // Healing done percent
9220 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
9221 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
9222 DoneTotalMod
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
9224 // done scripted mod (take it from owner)
9225 Unit
*owner
= GetOwner();
9226 if (!owner
) owner
= this;
9227 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9228 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9230 if (!(*i
)->isAffectedOnSpell(spellProto
))
9232 switch((*i
)->GetModifier()->m_miscvalue
)
9234 case 4415: // Increased Rejuvenation Healing
9236 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
9237 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
9239 case 7997: // Renewed Hope
9241 if (pVictim
->HasAura(6788))
9242 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9244 case 21: // Test of Faith
9247 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
9248 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
9250 case 7798: // Glyph of Regrowth
9252 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_HEAL
, SPELLFAMILY_DRUID
, UI64LIT(0x0000000000000040)))
9253 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9256 case 8477: // Nourish Heal Boost
9258 int32 stepPercent
= (*i
)->GetModifier()->m_amount
;
9259 int32 modPercent
= 0;
9260 AuraMap
const& victimAuras
= pVictim
->GetAuras();
9261 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
9263 if (itr
->second
->GetCasterGUID()!=GetGUID())
9265 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
9266 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_DRUID
||
9267 !(m_spell
->SpellFamilyFlags
& UI64LIT(0x0000001000000050)))
9269 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
9271 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
9274 case 7871: // Glyph of Lesser Healing Wave
9276 if (pVictim
->GetAura(SPELL_AURA_DUMMY
, SPELLFAMILY_SHAMAN
, UI64LIT(0x0000040000000000), 0, GetGUID()))
9277 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9285 // Taken/Done fixed damage bonus auras
9286 int32 DoneAdvertisedBenefit
= SpellBaseHealingBonus(GetSpellSchoolMask(spellProto
));
9287 int32 TakenAdvertisedBenefit
= SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
9289 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9290 // Spellmod SpellDamage
9291 float SpellModSpellDamage
= 100.0f
;
9292 if(Player
* modOwner
= GetSpellModOwner())
9293 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_SPELL_BONUS_DAMAGE
, SpellModSpellDamage
);
9294 SpellModSpellDamage
/= 100.0f
;
9296 // Check for table values
9297 SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
);
9301 if (damagetype
== DOT
)
9302 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
9304 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
9306 if (bonus
->ap_bonus
)
9307 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
) * stack
);
9309 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* SpellModSpellDamage
);
9310 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
);
9312 // Default calculation
9313 else if (DoneAdvertisedBenefit
|| TakenAdvertisedBenefit
)
9315 // Damage over Time spells bonus calculation
9316 float DotFactor
= 1.0f
;
9317 if(damagetype
== DOT
)
9319 if(!IsChanneledSpell(spellProto
))
9320 DotFactor
= GetSpellDuration(spellProto
) / 15000.0f
;
9321 uint16 DotTicks
= GetSpellAuraMaxTicks(spellProto
);
9324 DoneAdvertisedBenefit
= DoneAdvertisedBenefit
* int32(stack
) / DotTicks
;
9325 TakenAdvertisedBenefit
= TakenAdvertisedBenefit
* int32(stack
) / DotTicks
;
9328 // Distribute Damage over multiple effects, reduce by AoE
9329 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
9330 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
9331 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
9332 for(int j
= 0; j
< 3; ++j
)
9334 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
9335 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
9341 DoneTotal
+= int32(DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* SpellModSpellDamage
* 1.88f
);
9342 TakenTotal
+= int32(TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* 1.88f
);
9345 // use float as more appropriate for negative values and percent applying
9346 float heal
= (healamount
+ DoneTotal
)*DoneTotalMod
;
9347 // apply spellmod to Done amount
9348 if(Player
* modOwner
= GetSpellModOwner())
9349 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
9352 // Healing Wave cast
9353 if (spellProto
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& (spellProto
->SpellFamilyFlags
& UI64LIT(0x0000000000000040)))
9355 // Search for Healing Way on Victim
9356 Unit::AuraList
const& auraDummy
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
9357 for(Unit::AuraList::const_iterator itr
= auraDummy
.begin(); itr
!=auraDummy
.end(); ++itr
)
9358 if((*itr
)->GetId() == 29203)
9359 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9362 // Healing taken percent
9363 float minval
= pVictim
->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
9365 TakenTotalMod
*= (100.0f
+ minval
) / 100.0f
;
9367 float maxval
= pVictim
->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
9369 TakenTotalMod
*= (100.0f
+ maxval
) / 100.0f
;
9371 AuraList
const& mHealingGet
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING_RECEIVED
);
9372 for(AuraList::const_iterator i
= mHealingGet
.begin(); i
!= mHealingGet
.end(); ++i
)
9373 if ((*i
)->isAffectedOnSpell(spellProto
))
9374 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9376 heal
= (heal
+ TakenTotal
) * TakenTotalMod
;
9378 return heal
< 0 ? 0 : uint32(heal
);
9381 int32
Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask
)
9383 int32 AdvertisedBenefit
= 0;
9385 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
9386 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
9387 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9388 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9390 // Healing bonus of spirit, intellect and strength
9391 if (GetTypeId() == TYPEID_PLAYER
)
9394 AdvertisedBenefit
+=((Player
*)this)->GetBaseSpellPowerBonus();
9396 // Healing bonus from stats
9397 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
9398 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
9400 // stat used dependent from misc value (stat index)
9401 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
9402 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9405 // ... and attack power
9406 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
9407 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
9408 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9409 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9411 return AdvertisedBenefit
;
9414 int32
Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
9416 int32 AdvertisedBenefit
= 0;
9417 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING
);
9418 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9419 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9420 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9422 return AdvertisedBenefit
;
9425 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
)
9427 //If m_immuneToSchool type contain this school type, IMMUNE damage.
9428 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9429 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9430 if (itr
->type
& shoolMask
)
9433 //If m_immuneToDamage type contain magic, IMMUNE damage.
9434 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
9435 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
9436 if (itr
->type
& shoolMask
)
9442 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
)
9447 //TODO add spellEffect immunity checks!, player with flag in bg is imune to imunity buffs from other friendly players!
9448 //SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_EFFECT];
9450 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
9451 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
9452 if (itr
->type
== spellInfo
->Dispel
)
9455 if (!(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
) && // unaffected by school immunity
9456 !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)) // can remove immune (by dispell or immune it)
9458 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9459 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9460 if (!(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
9461 (itr
->type
& GetSpellSchoolMask(spellInfo
)))
9465 if(uint32 mechanic
= spellInfo
->Mechanic
)
9467 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9468 for(SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9469 if (itr
->type
== mechanic
)
9472 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9473 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9474 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9481 bool Unit::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, uint32 index
) const
9483 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
9484 uint32 effect
= spellInfo
->Effect
[index
];
9485 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
9486 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
9487 if (itr
->type
== effect
)
9490 if(uint32 mechanic
= spellInfo
->EffectMechanic
[index
])
9492 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9493 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9494 if (itr
->type
== mechanic
)
9497 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY_MASK
);
9498 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9499 if ((*iter
)->GetModifier()->m_miscvalue
& (1 << (mechanic
-1)))
9503 if(uint32 aura
= spellInfo
->EffectApplyAuraName
[index
])
9505 SpellImmuneList
const& list
= m_spellImmune
[IMMUNITY_STATE
];
9506 for(SpellImmuneList::const_iterator itr
= list
.begin(); itr
!= list
.end(); ++itr
)
9507 if (itr
->type
== aura
)
9510 // Check for immune to application of harmful magical effects
9511 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL
);
9512 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
9513 if (spellInfo
->Dispel
== DISPEL_MAGIC
&& // Magic debuff
9514 ((*iter
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellInfo
)) && // Check school
9515 !IsPositiveEffect(spellInfo
->Id
, index
)) // Harmful
9522 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
9527 uint32 family
= spellInfo
->SpellFamilyName
;
9528 uint64 flags
= spellInfo
->SpellFamilyFlags
;
9530 if ((family
== 5 && flags
== 256) || //Searing Pain
9531 (family
== 6 && flags
== 8192) || //Mind Blast
9532 (family
== 11 && flags
== 1048576)) //Earth Shock
9538 uint32
Unit::MeleeDamageBonus(Unit
*pVictim
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 stack
)
9546 // differentiate for weapon damage based spells
9547 bool isWeaponDamageBasedSpell
= !(spellProto
&& (damagetype
== DOT
|| IsSpellHaveEffect(spellProto
, SPELL_EFFECT_SCHOOL_DAMAGE
)));
9548 Item
* pWeapon
= GetTypeId() == TYPEID_PLAYER
? ((Player
*)this)->GetWeaponForAttack(attType
,true,false) : NULL
;
9549 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9550 uint32 schoolMask
= spellProto
? spellProto
->SchoolMask
: GetMeleeDamageSchoolMask();
9551 uint32 mechanicMask
= spellProto
? GetAllSpellMechanicMask(spellProto
) : 0;
9553 // Shred also have bonus as MECHANIC_BLEED damages
9554 if (spellProto
&& spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& spellProto
->SpellFamilyFlags
& UI64LIT(0x00008000))
9555 mechanicMask
|= (1 << (MECHANIC_BLEED
-1));
9558 // FLAT damage bonus auras
9559 // =======================
9561 int32 TakenFlat
= 0;
9564 // ..done flat, already included in wepon damage based spells
9565 if (!isWeaponDamageBasedSpell
)
9567 AuraList
const& mModDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
9568 for(AuraList::const_iterator i
= mModDamageDone
.begin(); i
!= mModDamageDone
.end(); ++i
)
9570 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9571 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9572 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9573 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
9575 DoneFlat
+= (*i
)->GetModifier()->m_amount
;
9579 // Pets just add their bonus damage to their melee damage
9580 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
9581 DoneFlat
+= ((Pet
*)this)->GetBonusDamage();
9584 // ..done flat (by creature type mask)
9585 DoneFlat
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
, creatureTypeMask
);
9587 // ..done flat (base at attack power for marked target and base at attack power for creature type)
9588 if (attType
== RANGED_ATTACK
)
9590 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
9591 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9592 TakenFlat
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
9596 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
9597 APbonus
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
, creatureTypeMask
);
9598 TakenFlat
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
9601 // ..taken flat (by school mask)
9602 TakenFlat
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_DAMAGE_TAKEN
, schoolMask
);
9604 // PERCENT damage auras
9605 // ====================
9606 float DonePercent
= 1.0f
;
9607 float TakenPercent
= 1.0f
;
9609 // ..done pct, already included in weapon damage based spells
9610 if(!isWeaponDamageBasedSpell
)
9612 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
9613 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
9615 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
&& // schoolmask has to fit with the intrinsic spell school
9616 (*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask() && // AND schoolmask has to fit with weapon damage school (essential for non-physical spells)
9617 ((*i
)->GetSpellProto()->EquippedItemClass
== -1 || // general, weapon independent
9618 pWeapon
&& pWeapon
->IsFitToSpellRequirements((*i
)->GetSpellProto()))) // OR used weapon fits aura requirements
9620 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
9624 if (attType
== OFF_ATTACK
)
9625 DonePercent
*= GetModifierValue(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_PCT
); // no school check required
9628 // ..done pct (by creature type mask)
9629 DonePercent
*= GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
, creatureTypeMask
);
9631 // ..taken pct (by school mask)
9632 TakenPercent
*= pVictim
->GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
, schoolMask
);
9634 // ..taken pct (by mechanic mask)
9635 TakenPercent
*= pVictim
->GetTotalAuraMultiplierByMiscValueForMask(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
,mechanicMask
);
9637 // ..taken pct (melee/ranged)
9638 if(attType
== RANGED_ATTACK
)
9639 TakenPercent
*= pVictim
->GetTotalAuraMultiplier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
9641 TakenPercent
*= pVictim
->GetTotalAuraMultiplier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
9643 // ..taken pct (aoe avoidance)
9644 if(spellProto
&& IsAreaOfEffectSpell(spellProto
))
9645 TakenPercent
*= pVictim
->GetTotalAuraMultiplier(SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE
);
9648 // special dummys/class sripts and other effects
9649 // =============================================
9650 Unit
*owner
= GetOwner();
9654 // ..done (class scripts)
9657 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9658 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
9660 if (!(*i
)->isAffectedOnSpell(spellProto
))
9663 switch((*i
)->GetModifier()->m_miscvalue
)
9670 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
9672 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9673 DonePercent
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
9675 else // Tundra Stalker
9677 // Frost Fever (target debuff)
9678 if (pVictim
->GetAura(SPELL_AURA_MOD_HASTE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0000000000000000), 0x00000002))
9679 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9684 case 7293: // Rage of Rivendare
9686 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, UI64LIT(0x0200000000000000)))
9687 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9697 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, UI64LIT(0x0000000000000400)))
9698 DonePercent
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9705 // .. taken (dummy auras)
9706 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
9707 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9709 switch((*i
)->GetSpellProto()->SpellIconID
)
9713 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
9715 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
9718 float mod
= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
9719 if (mod
< (*i
)->GetModifier()->m_amount
)
9720 mod
= (*i
)->GetModifier()->m_amount
;
9722 TakenPercent
*= (mod
+ 100.0f
) / 100.0f
;
9728 // .. taken (class scripts)
9729 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9730 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
9732 switch((*i
)->GetMiscValue())
9737 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9739 Aura
* eff0
= GetAura((*i
)->GetId(), 0);
9740 if (!eff0
|| (*i
)->GetEffIndex() != 1)
9742 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
9746 // effect 0 have expected value but in negative state
9747 TakenPercent
*= (-eff0
->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
9754 // final calculation
9755 // =================
9757 // scaling of non weapon based spells
9758 if (!isWeaponDamageBasedSpell
)
9760 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9762 // Check for table values
9763 if (SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellProto
->Id
))
9766 if (damagetype
== DOT
)
9767 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
9769 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
9771 if (bonus
->ap_bonus
)
9772 DoneFlat
+= bonus
->ap_bonus
* (GetTotalAttackPowerValue(BASE_ATTACK
) + APbonus
) * stack
;
9777 // Default calculation
9778 else if (DoneFlat
|| TakenFlat
)
9780 // Damage over Time spells bonus calculation
9781 float DotFactor
= 1.0f
;
9782 if(damagetype
== DOT
)
9784 if(!IsChanneledSpell(spellProto
))
9785 DotFactor
= GetSpellDuration(spellProto
) / 15000.0f
;
9786 uint16 DotTicks
= GetSpellAuraMaxTicks(spellProto
);
9789 DoneFlat
= DoneFlat
* int32(stack
) / DotTicks
;
9790 TakenFlat
= TakenFlat
* int32(stack
) / DotTicks
;
9793 // Distribute Damage over multiple effects, reduce by AoE
9794 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
9795 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
9796 DoneFlat
*= (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
;
9797 TakenFlat
*= (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
;
9800 // weapon damage based spells
9801 else if( APbonus
|| DoneFlat
)
9803 bool normalized
= spellProto
? IsSpellHaveEffect(spellProto
, SPELL_EFFECT_NORMALIZED_WEAPON_DMG
) : false;
9804 DoneFlat
+= int32(APbonus
/ 14.0f
* GetAPMultiplier(attType
,normalized
));
9806 // for weapon damage based spells we still have to apply damage done percent mods
9807 // (that are already included into pdamage) to not-yet included DoneFlat
9808 // e.g. from doneVersusCreature, apBonusVs...
9813 case BASE_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_MAINHAND
; break;
9814 case OFF_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_OFFHAND
; break;
9815 case RANGED_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_RANGED
; break;
9818 DoneFlat
*= GetModifierValue(unitMod
, TOTAL_PCT
);
9821 float tmpDamage
= float(int32(pdamage
) + DoneFlat
) * DonePercent
;
9823 // apply spellmod to Done damage
9826 if(Player
* modOwner
= GetSpellModOwner())
9827 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
9830 tmpDamage
= (tmpDamage
+ TakenFlat
) * TakenPercent
;
9832 // bonus result can be negative
9833 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9836 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
9840 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
9843 if(itr
->type
== type
)
9845 m_spellImmune
[op
].erase(itr
);
9846 next
= m_spellImmune
[op
].begin();
9850 Immune
.spellId
= spellId
;
9852 m_spellImmune
[op
].push_back(Immune
);
9856 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
9858 if(itr
->spellId
== spellId
)
9860 m_spellImmune
[op
].erase(itr
);
9868 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
9870 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
9872 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
9873 RemoveAurasWithDispelType(type
);
9876 float Unit::GetWeaponProcChance() const
9878 // normalized proc chance for weapon attack speed
9880 if (isAttackReady(BASE_ATTACK
))
9881 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
9882 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
9883 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
9888 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
9890 // proc per minute chance calculation
9891 if (PPM
<= 0.0f
) return 0.0f
;
9892 return WeaponSpeed
* PPM
/ 600.0f
; // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
9895 void Unit::Mount(uint32 mount
, uint32 spellId
)
9900 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
9902 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
9904 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
9906 if (GetTypeId() == TYPEID_PLAYER
)
9908 // Called by Taxi system / GM command
9910 ((Player
*)this)->UnsummonPetTemporaryIfAny();
9911 // Called by mount aura
9912 else if (SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellId
))
9914 // Flying case (Unsummon any pet)
9915 if (IsSpellHaveAura(spellInfo
, SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
))
9916 ((Player
*)this)->UnsummonPetTemporaryIfAny();
9917 // Normal case (Unsummon only permanent pet)
9918 else if (Pet
* pet
= GetPet())
9920 if (pet
->IsPermanentPetFor((Player
*)this) && !((Player
*)this)->InArena())
9921 ((Player
*)this)->UnsummonPetTemporaryIfAny();
9923 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,true);
9929 void Unit::Unmount()
9934 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
9936 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
9937 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
9939 // only resummon old pet if the player is already added to a map
9940 // this prevents adding a pet to a not created map which would otherwise cause a crash
9941 // (it could probably happen when logging in after a previous crash)
9942 if(GetTypeId() == TYPEID_PLAYER
)
9944 if(Pet
* pet
= GetPet())
9945 pet
->ApplyModeFlags(PET_MODE_DISABLE_ACTIONS
,false);
9947 ((Player
*)this)->ResummonPetTemporaryUnSummonedIfAny();
9951 void Unit::SetInCombatWith(Unit
* enemy
)
9953 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
9954 if (eOwner
->IsPvP())
9956 SetInCombatState(true,enemy
);
9961 if (eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
9963 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
9964 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
9966 SetInCombatState(true,enemy
);
9971 SetInCombatState(false,enemy
);
9974 void Unit::SetInCombatState(bool PvP
, Unit
* enemy
)
9976 // only alive units can be in combat
9981 m_CombatTimer
= 5000;
9983 bool creatureNotInCombat
= GetTypeId()==TYPEID_UNIT
&& !HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
9985 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
9987 if (isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
9988 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
9990 if (creatureNotInCombat
)
9992 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
9994 if (((Creature
*)this)->AI())
9995 ((Creature
*)this)->AI()->EnterCombat(enemy
);
9999 void Unit::ClearInCombat()
10002 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
10004 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
10005 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
10007 // Player's state will be cleared in Player::UpdateContestedPvP
10008 if (GetTypeId() != TYPEID_PLAYER
)
10010 Creature
* creature
= (Creature
*)this;
10011 if (creature
->GetCreatureInfo() && creature
->GetCreatureInfo()->unit_flags
& UNIT_FLAG_OOC_NOT_ATTACKABLE
)
10012 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
);
10014 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
10017 ((Player
*)this)->UpdatePotionCooldown();
10020 bool Unit::isTargetableForAttack(bool inverseAlive
/*=false*/) const
10022 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
10025 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
10028 // to be removed if unit by any reason enter combat
10029 if (HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_OOC_NOT_ATTACKABLE
))
10032 // inversealive is needed for some spells which need to be casted at dead targets (aoe)
10033 if (isAlive() == inverseAlive
)
10036 return IsInWorld() && !hasUnitState(UNIT_STAT_DIED
) && !isInFlight();
10039 int32
Unit::ModifyHealth(int32 dVal
)
10046 int32 curHealth
= (int32
)GetHealth();
10048 int32 val
= dVal
+ curHealth
;
10055 int32 maxHealth
= (int32
)GetMaxHealth();
10057 if(val
< maxHealth
)
10060 gain
= val
- curHealth
;
10062 else if(curHealth
!= maxHealth
)
10064 SetHealth(maxHealth
);
10065 gain
= maxHealth
- curHealth
;
10071 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
10078 int32 curPower
= (int32
)GetPower(power
);
10080 int32 val
= dVal
+ curPower
;
10087 int32 maxPower
= (int32
)GetMaxPower(power
);
10091 SetPower(power
,val
);
10092 gain
= val
- curPower
;
10094 else if(curPower
!= maxPower
)
10096 SetPower(power
,maxPower
);
10097 gain
= maxPower
- curPower
;
10103 bool Unit::isVisibleForOrDetect(Unit
const* u
, WorldObject
const* viewPoint
, bool detect
, bool inVisibleList
, bool is3dDistance
) const
10105 if(!u
|| !IsInMap(u
))
10108 // Always can see self
10112 // player visible for other player if not logout and at same transport
10113 // including case when player is out of world
10114 bool at_same_transport
=
10115 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
10116 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
10117 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
10118 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
10121 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
10124 // forbidden to seen (at GM respawn command)
10125 if(m_Visibility
==VISIBILITY_RESPAWN
)
10128 Map
& _map
= *u
->GetMap();
10129 // Grid dead/alive checks
10130 if (u
->GetTypeId()==TYPEID_PLAYER
)
10132 // non visible at grid for any stealth state
10133 if(!IsVisibleInGridForPlayer((Player
*)u
))
10136 // if player is dead then he can't detect anyone in any cases
10142 // all dead creatures/players not visible for any creatures
10143 if(!u
->isAlive() || !isAlive())
10147 // always seen by far sight caster
10148 if (u
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)u
)->GetFarSight()==GetGUID())
10151 // different visible distance checks
10152 if (u
->isInFlight()) // what see player in flight
10154 // use object grey distance for all (only see objects any way)
10155 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10158 else if(!isAlive()) // distance for show body
10160 if (!IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
10163 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
10165 if(u
->GetTypeId()==TYPEID_PLAYER
)
10167 // Players far than max visible distance for player or not in our map are not visible too
10168 if (!at_same_transport
&& !IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10173 // Units far than max visible distance for creature or not in our map are not visible too
10174 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10178 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
10180 // Pet/charmed far than max visible distance for player or not in our map are not visible too
10181 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10184 else // distance for show creature
10186 // Units far than max visible distance for creature or not in our map are not visible too
10187 if (!IsWithinDistInMap(viewPoint
, _map
.GetVisibilityDistance() + (inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
10191 // always seen by owner
10192 if (GetCharmerOrOwnerGUID()==u
->GetGUID())
10195 // isInvisibleForAlive() those units can only be seen by dead or if other
10196 // unit is also invisible for alive.. if an isinvisibleforalive unit dies we
10197 // should be able to see it too
10198 if (u
->isAlive() && isAlive() && isInvisibleForAlive() != u
->isInvisibleForAlive())
10199 if (u
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)u
)->isGameMaster())
10202 // Visible units, always are visible for all units, except for units under invisibility and phases
10203 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0 && InSamePhase(u
))
10206 // GMs see any players, not higher GMs and all units in any phase
10207 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
10209 if(GetTypeId() == TYPEID_PLAYER
)
10210 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
10215 // non faction visibility non-breakable for non-GMs
10216 if (m_Visibility
== VISIBILITY_OFF
)
10219 // phased visibility (both must phased in same way)
10220 if(!InSamePhase(u
))
10223 // raw invisibility
10224 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
10226 // detectable invisibility case
10228 // Invisible units, always are visible for units under same invisibility type
10229 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
10230 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
10231 u
->canDetectInvisibilityOf(this) ||
10232 // Units that can detect invisibility always are visible for units that can be detected
10233 canDetectInvisibilityOf(u
) ))
10238 // special cases for always overwrite invisibility/stealth
10239 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
10241 // non-hostile case
10242 if (!u
->IsHostileTo(this))
10244 // 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)
10245 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
10247 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
10250 // else apply same rules as for hostile case (detecting check for stealth)
10256 // Hunter mark functionality
10257 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
10258 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
10259 if((*iter
)->GetCasterGUID()==u
->GetGUID())
10262 // else apply detecting check for stealth
10265 // none other cases for detect invisibility, so invisible
10269 // else apply stealth detecting check
10272 // unit got in stealth in this moment and must ignore old detected state
10273 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
10276 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
10277 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
10280 // NOW ONLY STEALTH CASE
10282 //if in non-detect mode then invisible for unit
10283 //mobs always detect players (detect == true)... return 'false' for those mobs which have (detect == false)
10284 //players detect players only in Player::HandleStealthedUnitsDetection()
10286 return (u
->GetTypeId() == TYPEID_PLAYER
) ? ((Player
*)u
)->HaveAtClient(this) : false;
10290 // If is attacked then stealth is lost, some creature can use stealth too
10291 if( !getAttackers().empty() )
10294 // If there is collision rogue is seen regardless of level difference
10295 if (IsWithinDist(u
,0.24f
))
10298 //If a mob or player is stunned he will not be able to detect stealth
10299 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
10303 float visibleDistance
= (u
->GetTypeId() == TYPEID_PLAYER
) ? MAX_PLAYER_STEALTH_DETECT_RANGE
: ((Creature
const*)u
)->GetAttackDistance(this);
10305 //Always invisible from back (when stealth detection is on), also filter max distance cases
10306 bool isInFront
= viewPoint
->isInFrontInMap(this, visibleDistance
);
10310 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
10311 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
10313 //Calculation if target is in front
10315 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
10316 visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
10318 //Visible distance is modified by
10319 //-Level Diff (every level diff = 1.0f in visible distance)
10320 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
10322 //This allows to check talent tree and will add addition stealth dependent on used points)
10323 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
10327 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
10328 //based on wowwiki every 5 mod we have 1 more level diff in calculation
10329 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_DETECT
)) - stealthMod
)/5.0f
;
10330 visibleDistance
= visibleDistance
> MAX_PLAYER_STEALTH_DETECT_RANGE
? MAX_PLAYER_STEALTH_DETECT_RANGE
: visibleDistance
;
10332 // recheck new distance
10333 if(visibleDistance
<= 0 || !IsWithinDist(viewPoint
,visibleDistance
))
10337 // Now check is target visible with LoS
10339 viewPoint
->GetPosition(ox
,oy
,oz
);
10340 return IsWithinLOS(ox
,oy
,oz
);
10343 void Unit::SetVisibility(UnitVisibility x
)
10351 if(GetTypeId()==TYPEID_PLAYER
)
10352 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10354 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
10358 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
10360 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
10362 for(uint32 i
= 0; i
< 10; ++i
)
10364 if(((1 << i
) & mask
)==0)
10367 // find invisibility level
10368 uint32 invLevel
= 0;
10369 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
10370 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
10371 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
10372 invLevel
= (*itr
)->GetModifier()->m_amount
;
10374 // find invisibility detect level
10375 uint32 detectLevel
= 0;
10376 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
10377 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
10378 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
10379 detectLevel
= (*itr
)->GetModifier()->m_amount
;
10381 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
10383 detectLevel
= ((Player
*)this)->GetDrunkValue();
10386 if(invLevel
<= detectLevel
)
10394 struct UpdateWalkModeHelper
10396 explicit UpdateWalkModeHelper(Unit
* _source
) : source(_source
) {}
10397 void operator()(Unit
* unit
) const { unit
->UpdateWalkMode(source
, true); }
10401 void Unit::UpdateWalkMode(Unit
* source
, bool self
)
10403 if (GetTypeId() == TYPEID_PLAYER
)
10404 ((Player
*)this)->CallForAllControlledUnits(UpdateWalkModeHelper(source
),false,true,true,true);
10407 bool on
= source
->GetTypeId() == TYPEID_PLAYER
10408 ? ((Player
*)source
)->HasMovementFlag(MOVEMENTFLAG_WALK_MODE
)
10409 : ((Creature
*)source
)->HasMonsterMoveFlag(MONSTER_MOVE_WALK
);
10413 if (((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10414 ((Creature
*)this)->AddMonsterMoveFlag(MONSTER_MOVE_WALK
);
10418 if (((Creature
*)this)->isPet())
10419 ((Creature
*)this)->RemoveMonsterMoveFlag(MONSTER_MOVE_WALK
);
10423 CallForAllControlledUnits(UpdateWalkModeHelper(source
),false,true,true);
10426 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
)
10428 // not in combat pet have same speed as owner
10434 if (GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW
))
10436 if(Unit
* owner
= GetOwner())
10438 SetSpeedRate(mtype
,owner
->GetSpeedRate(mtype
),forced
);
10445 int32 main_speed_mod
= 0;
10446 float stack_bonus
= 1.0f
;
10447 float non_stack_bonus
= 1.0f
;
10455 if (IsMounted()) // Use on mount auras
10457 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
10458 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
10459 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
10463 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
10464 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
10465 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
10469 case MOVE_RUN_BACK
:
10473 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
10476 case MOVE_SWIM_BACK
:
10480 if (IsMounted()) // Use on mount auras
10481 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
);
10482 else // Use not mount (shapeshift for example) auras (should stack)
10483 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT
);
10484 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS
);
10485 non_stack_bonus
= (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
))/100.0f
;
10488 case MOVE_FLIGHT_BACK
:
10491 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
10495 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
10496 // now we ready for speed calculation
10497 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
10505 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
10506 // TODO: possible affect only on MOVE_RUN
10507 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
10509 // Use speed from aura
10510 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
10511 if (speed
> max_speed
)
10520 // for creature case, we check explicit if mob searched for assistance
10521 if (GetTypeId() == TYPEID_UNIT
)
10523 if (((Creature
*)this)->HasSearchedAssistance())
10524 speed
*= 0.66f
; // best guessed value, so this will be 33% reduction. Based off initial speed, mob can then "run", "walk fast" or "walk".
10527 // Apply strongest slow aura mod to speed
10528 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
10531 speed
*=(100.0f
+ slow
)/100.0f
;
10532 float min_speed
= (float)GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MINIMUM_SPEED
) / 100.0f
;
10533 if (speed
< min_speed
)
10536 SetSpeedRate(mtype
, speed
, forced
);
10539 float Unit::GetSpeed( UnitMoveType mtype
) const
10541 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
10544 struct SetSpeedRateHelper
10546 explicit SetSpeedRateHelper(UnitMoveType _mtype
, bool _forced
) : mtype(_mtype
), forced(_forced
) {}
10547 void operator()(Unit
* unit
) const { unit
->UpdateSpeed(mtype
,forced
); }
10548 UnitMoveType mtype
;
10552 void Unit::SetSpeedRate(UnitMoveType mtype
, float rate
, bool forced
)
10557 // Update speed only on change
10558 if (m_speed_rate
[mtype
] == rate
)
10561 m_speed_rate
[mtype
] = rate
;
10563 propagateSpeedChange();
10571 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10574 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10576 case MOVE_RUN_BACK
:
10577 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10580 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10582 case MOVE_SWIM_BACK
:
10583 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10585 case MOVE_TURN_RATE
:
10586 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+2+4+4+4+4+4+4+4);
10589 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10591 case MOVE_FLIGHT_BACK
:
10592 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
10594 case MOVE_PITCH_RATE
:
10595 data
.Initialize(MSG_MOVE_SET_PITCH_RATE
, 8+4+2+4+4+4+4+4+4+4);
10598 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
10602 data
.append(GetPackGUID());
10603 data
<< uint32(0); // movement flags
10604 data
<< uint16(0); // unk flags
10605 data
<< uint32(getMSTime());
10606 data
<< float(GetPositionX());
10607 data
<< float(GetPositionY());
10608 data
<< float(GetPositionZ());
10609 data
<< float(GetOrientation());
10610 data
<< uint32(0); // fall time
10611 data
<< float(GetSpeed(mtype
));
10612 SendMessageToSet( &data
, true );
10616 if(GetTypeId() == TYPEID_PLAYER
)
10618 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
10619 // and do it only for real sent packets and use run for run/mounted as client expected
10620 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
10626 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
10629 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
10631 case MOVE_RUN_BACK
:
10632 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
10635 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
10637 case MOVE_SWIM_BACK
:
10638 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
10640 case MOVE_TURN_RATE
:
10641 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
10644 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
10646 case MOVE_FLIGHT_BACK
:
10647 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
10649 case MOVE_PITCH_RATE
:
10650 data
.Initialize(SMSG_FORCE_PITCH_RATE_CHANGE
, 16);
10653 sLog
.outError("Unit::SetSpeedRate: Unsupported move type (%d), data not sent to client.",mtype
);
10656 data
.append(GetPackGUID());
10657 data
<< (uint32
)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
10658 if (mtype
== MOVE_RUN
)
10659 data
<< uint8(0); // new 2.1.0
10660 data
<< float(GetSpeed(mtype
));
10661 SendMessageToSet( &data
, true );
10664 if (GetTypeId() == TYPEID_PLAYER
) // need include minpet
10665 ((Player
*)this)->CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true,true);
10667 CallForAllControlledUnits(SetSpeedRateHelper(mtype
,forced
),false,true,true);
10670 void Unit::SetHover(bool on
)
10673 CastSpell(this, 11010, true);
10675 RemoveAurasDueToSpell(11010);
10678 void Unit::setDeathState(DeathState s
)
10680 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
10683 DeleteThreatList();
10684 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
10686 if(IsNonMeleeSpellCasted(false))
10687 InterruptNonMeleeSpells(false);
10690 if (s
== JUST_DIED
)
10692 RemoveAllAurasOnDeath();
10694 UnsummonAllTotems();
10696 // after removing a Fearaura (in RemoveAllAurasOnDeath)
10697 // Unit::SetFeared is called and makes that creatures attack player again
10700 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
10701 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
10702 // remove aurastates allowing special moves
10703 ClearAllReactives();
10704 ClearDiminishings();
10706 else if(s
== JUST_ALIVED
)
10708 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
10711 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
10713 //_ApplyAllAuraMods();
10718 /*########################################
10720 ######## AGGRO SYSTEM ########
10722 ########################################*/
10723 bool Unit::CanHaveThreatList() const
10725 // only creatures can have threat list
10726 if( GetTypeId() != TYPEID_UNIT
)
10729 // only alive units can have threat list
10733 // totems can not have threat list
10734 if( ((Creature
*)this)->isTotem() )
10737 // vehicles can not have threat list
10738 if( ((Creature
*)this)->isVehicle() )
10741 // pets can not have a threat list, unless they are controlled by a creature
10742 if( ((Creature
*)this)->isPet() && IS_PLAYER_GUID(((Pet
*)this)->GetOwnerGUID()) )
10748 //======================================================================
10750 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
10752 if (!HasAuraType(SPELL_AURA_MOD_THREAT
))
10755 if (schoolMask
== SPELL_SCHOOL_MASK_NONE
)
10758 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
10760 return threat
* m_threatModifier
[school
];
10763 //======================================================================
10765 void Unit::AddThreat(Unit
* pVictim
, float threat
/*= 0.0f*/, bool crit
/*= false*/, SpellSchoolMask schoolMask
/*= SPELL_SCHOOL_MASK_NONE*/, SpellEntry
const *threatSpell
/*= NULL*/)
10767 // Only mobs can manage threat lists
10768 if(CanHaveThreatList())
10769 m_ThreatManager
.addThreat(pVictim
, threat
, crit
, schoolMask
, threatSpell
);
10772 //======================================================================
10774 void Unit::DeleteThreatList()
10776 if(CanHaveThreatList() && !m_ThreatManager
.isThreatListEmpty())
10778 m_ThreatManager
.clearReferences();
10781 //======================================================================
10783 void Unit::TauntApply(Unit
* taunter
)
10785 assert(GetTypeId()== TYPEID_UNIT
);
10787 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
10790 if(!CanHaveThreatList())
10793 Unit
*target
= getVictim();
10794 if(target
&& target
== taunter
)
10797 SetInFront(taunter
);
10798 if (((Creature
*)this)->AI())
10799 ((Creature
*)this)->AI()->AttackStart(taunter
);
10801 m_ThreatManager
.tauntApply(taunter
);
10804 //======================================================================
10806 void Unit::TauntFadeOut(Unit
*taunter
)
10808 assert(GetTypeId()== TYPEID_UNIT
);
10810 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
10813 if(!CanHaveThreatList())
10816 Unit
*target
= getVictim();
10817 if(!target
|| target
!= taunter
)
10820 if(m_ThreatManager
.isThreatListEmpty())
10822 if(((Creature
*)this)->AI())
10823 ((Creature
*)this)->AI()->EnterEvadeMode();
10827 m_ThreatManager
.tauntFadeOut(taunter
);
10828 target
= m_ThreatManager
.getHostileTarget();
10830 if (target
&& target
!= taunter
)
10832 SetInFront(target
);
10833 if (((Creature
*)this)->AI())
10834 ((Creature
*)this)->AI()->AttackStart(target
);
10838 //======================================================================
10840 bool Unit::SelectHostileTarget()
10842 //function provides main threat functionality
10843 //next-victim-selection algorithm and evade mode are called
10844 //threat list sorting etc.
10846 assert(GetTypeId()== TYPEID_UNIT
);
10848 if (!this->isAlive())
10850 //This function only useful once AI has been initialized
10851 if (!((Creature
*)this)->AI())
10854 Unit
* target
= NULL
;
10856 // First checking if we have some taunt on us
10857 const AuraList
& tauntAuras
= GetAurasByType(SPELL_AURA_MOD_TAUNT
);
10858 if ( !tauntAuras
.empty() )
10862 // The last taunt aura caster is alive an we are happy to attack him
10863 if ( (caster
= tauntAuras
.back()->GetCaster()) && caster
->isAlive() )
10865 else if (tauntAuras
.size() > 1)
10867 // We do not have last taunt aura caster but we have more taunt auras,
10868 // so find first available target
10870 // Auras are pushed_back, last caster will be on the end
10871 AuraList::const_iterator aura
= --tauntAuras
.end();
10875 if ( (caster
= (*aura
)->GetCaster()) &&
10876 caster
->IsInMap(this) && caster
->isTargetableForAttack() && caster
->isInAccessablePlaceFor((Creature
*)this) )
10881 }while (aura
!= tauntAuras
.begin());
10885 if ( !target
&& !m_ThreatManager
.isThreatListEmpty() )
10886 // No taunt aura or taunt aura caster is dead standart target selection
10887 target
= m_ThreatManager
.getHostileTarget();
10891 if(!hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_DIED
))
10892 SetInFront(target
);
10893 ((Creature
*)this)->AI()->AttackStart(target
);
10897 // no target but something prevent go to evade mode
10898 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
10901 // last case when creature don't must go to evade mode:
10902 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
10903 // for example at owner command to pet attack some far away creature
10904 // Note: creature not have targeted movement generator but have attacker in this case
10905 if (GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE
)
10907 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
10909 if ((*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this))
10914 // enter in evade mode in other case
10915 ((Creature
*)this)->AI()->EnterEvadeMode();
10920 //======================================================================
10921 //======================================================================
10922 //======================================================================
10924 int32
Unit::CalculateSpellDamage(SpellEntry
const* spellProto
, uint8 effect_index
, int32 effBasePoints
, Unit
const* target
)
10926 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
10928 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
10930 int32 level
= int32(getLevel());
10931 if (level
> (int32
)spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
10932 level
= (int32
)spellProto
->maxLevel
;
10933 else if (level
< (int32
)spellProto
->baseLevel
)
10934 level
= (int32
)spellProto
->baseLevel
;
10935 level
-= (int32
)spellProto
->spellLevel
;
10937 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
10938 float randomPointsPerLevel
= spellProto
->EffectDicePerLevel
[effect_index
];
10939 int32 basePoints
= int32(effBasePoints
+ level
* basePointsPerLevel
);
10940 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
] + level
* randomPointsPerLevel
);
10941 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
10943 // range can have possitive and negative values, so order its for irand
10944 int32 randvalue
= int32(spellProto
->EffectBaseDice
[effect_index
]) >= randomPoints
10945 ? irand(randomPoints
, int32(spellProto
->EffectBaseDice
[effect_index
]))
10946 : irand(int32(spellProto
->EffectBaseDice
[effect_index
]), randomPoints
);
10948 int32 value
= basePoints
+ randvalue
;
10950 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
10951 value
+= (int32
)(comboDamage
* comboPoints
);
10953 if(Player
* modOwner
= GetSpellModOwner())
10955 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_ALL_EFFECTS
, value
);
10956 switch(effect_index
)
10959 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT1
, value
);
10962 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT2
, value
);
10965 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT3
, value
);
10970 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
10971 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
10972 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
&&
10973 (spellProto
->Effect
[effect_index
] != SPELL_EFFECT_APPLY_AURA
|| spellProto
->EffectApplyAuraName
[effect_index
] != SPELL_AURA_MOD_DECREASE_SPEED
))
10974 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
10979 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, uint8 effect_index
, Unit
const* target
)
10981 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
10983 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
10985 int32 minduration
= GetSpellDuration(spellProto
);
10986 int32 maxduration
= GetSpellMaxDuration(spellProto
);
10990 if( minduration
!= -1 && minduration
!= maxduration
)
10991 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
10993 duration
= minduration
;
10997 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
10998 // Find total mod value (negative bonus)
10999 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
11000 // Modify from SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL aura (stack always ?)
11001 durationMod_always
+=target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
, spellProto
->Dispel
);
11002 // Find max mod (negative bonus)
11003 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
11005 if (!IsPositiveSpell(spellProto
->Id
))
11006 durationMod_always
+= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_MAGIC_EFFECTS
, spellProto
->DmgClass
);
11008 int32 durationMod
= 0;
11009 // Select strongest negative mod
11010 if (durationMod_always
> durationMod_not_stack
)
11011 durationMod
= durationMod_not_stack
;
11013 durationMod
= durationMod_always
;
11015 if (durationMod
!= 0)
11016 duration
= int32(int64(duration
) * (100+durationMod
) /100);
11018 if (duration
< 0) duration
= 0;
11024 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
11026 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11028 if(i
->DRGroup
!= group
)
11032 return DIMINISHING_LEVEL_1
;
11035 return DIMINISHING_LEVEL_1
;
11037 // If last spell was casted more than 15 seconds ago - reset the count.
11038 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
11040 i
->hitCount
= DIMINISHING_LEVEL_1
;
11041 return DIMINISHING_LEVEL_1
;
11043 // or else increase the count.
11046 return DiminishingLevels(i
->hitCount
);
11049 return DIMINISHING_LEVEL_1
;
11052 void Unit::IncrDiminishing(DiminishingGroup group
)
11054 // Checking for existing in the table
11055 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11057 if(i
->DRGroup
!= group
)
11059 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
11063 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
11066 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
, int32 limitduration
)
11068 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
11071 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
11072 if(limitduration
> 0 && duration
> limitduration
)
11074 // test pet/charm masters instead pets/charmeds
11075 Unit
const* targetOwner
= GetCharmerOrOwner();
11076 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
11078 Unit
const* target
= targetOwner
? targetOwner
: this;
11079 Unit
const* source
= casterOwner
? casterOwner
: caster
;
11081 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
11082 duration
= limitduration
;
11087 // Some diminishings applies to mobs too (for example, Stun)
11088 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
11090 DiminishingLevels diminish
= Level
;
11093 case DIMINISHING_LEVEL_1
: break;
11094 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
11095 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
11096 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
11101 duration
= int32(duration
* mod
);
11104 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
11106 // Checking for existing in the table
11107 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
11109 if(i
->DRGroup
!= group
)
11117 // Remember time after last aura from group removed
11119 i
->hitTime
= getMSTime();
11125 Unit
* Unit::GetUnit(WorldObject
const& object
, uint64 guid
)
11127 return ObjectAccessor::GetUnit(object
,guid
);
11130 bool Unit::isVisibleForInState( Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const
11132 return isVisibleForOrDetect(u
, viewPoint
, false, inVisibleList
, false);
11135 /// returns true if creature can't be seen by alive units
11136 bool Unit::isInvisibleForAlive() const
11138 if (m_AuraFlags
& UNIT_AURAFLAG_ALIVE_INVISIBLE
)
11140 // TODO: maybe spiritservices also have just an aura
11141 return isSpiritService();
11144 uint32
Unit::GetCreatureType() const
11146 if(GetTypeId() == TYPEID_PLAYER
)
11148 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(m_form
);
11149 if(ssEntry
&& ssEntry
->creatureType
> 0)
11150 return ssEntry
->creatureType
;
11152 return CREATURE_TYPE_HUMANOID
;
11155 return ((Creature
*)this)->GetCreatureInfo()->type
;
11158 /*#######################################
11160 ######## STAT SYSTEM ########
11162 #######################################*/
11164 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
11166 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11168 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
11174 switch(modifierType
)
11178 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
11182 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
11185 val
= (100.0f
+ amount
) / 100.0f
;
11186 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
11193 if(!CanModifyStats())
11198 case UNIT_MOD_STAT_STRENGTH
:
11199 case UNIT_MOD_STAT_AGILITY
:
11200 case UNIT_MOD_STAT_STAMINA
:
11201 case UNIT_MOD_STAT_INTELLECT
:
11202 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
11204 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
11205 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
11207 case UNIT_MOD_MANA
:
11208 case UNIT_MOD_RAGE
:
11209 case UNIT_MOD_FOCUS
:
11210 case UNIT_MOD_ENERGY
:
11211 case UNIT_MOD_HAPPINESS
:
11212 case UNIT_MOD_RUNE
:
11213 case UNIT_MOD_RUNIC_POWER
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
11215 case UNIT_MOD_RESISTANCE_HOLY
:
11216 case UNIT_MOD_RESISTANCE_FIRE
:
11217 case UNIT_MOD_RESISTANCE_NATURE
:
11218 case UNIT_MOD_RESISTANCE_FROST
:
11219 case UNIT_MOD_RESISTANCE_SHADOW
:
11220 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
11222 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
11223 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
11225 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
11226 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
11227 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
11236 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
11238 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
11240 sLog
.outError("trial to access non existed modifier value from UnitMods!");
11244 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
11247 return m_auraModifiersGroup
[unitMod
][modifierType
];
11250 float Unit::GetTotalStatValue(Stats stat
) const
11252 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
11254 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11257 // value = ((base_value * base_pct) + total_value) * total_pct
11258 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
11259 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11260 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11261 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11266 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
11268 if(unitMod
>= UNIT_MOD_END
)
11270 sLog
.outError("trial to access non existed UnitMods in GetTotalAuraModValue()!");
11274 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
11277 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
11278 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
11279 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
11280 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
11285 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
11287 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
11291 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
11292 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
11293 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
11294 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
11295 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
11296 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
11305 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
11307 Stats stat
= STAT_STRENGTH
;
11311 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
11312 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
11313 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
11314 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
11315 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
11324 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
11328 case UNIT_MOD_MANA
: return POWER_MANA
;
11329 case UNIT_MOD_RAGE
: return POWER_RAGE
;
11330 case UNIT_MOD_FOCUS
: return POWER_FOCUS
;
11331 case UNIT_MOD_ENERGY
: return POWER_ENERGY
;
11332 case UNIT_MOD_HAPPINESS
: return POWER_HAPPINESS
;
11333 case UNIT_MOD_RUNE
: return POWER_RUNE
;
11334 case UNIT_MOD_RUNIC_POWER
:return POWER_RUNIC_POWER
;
11335 default: return POWER_MANA
;
11341 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
11343 if (attType
== RANGED_ATTACK
)
11345 int32 ap
= GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER_MODS
);
11348 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER
));
11352 int32 ap
= GetInt32Value(UNIT_FIELD_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_ATTACK_POWER_MODS
);
11355 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER
));
11359 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
11361 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
11364 return m_weaponDamage
[attType
][type
];
11367 void Unit::SetLevel(uint32 lvl
)
11369 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
11372 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
11373 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
11376 void Unit::SetHealth(uint32 val
)
11378 uint32 maxHealth
= GetMaxHealth();
11379 if(maxHealth
< val
)
11382 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
11385 if(GetTypeId() == TYPEID_PLAYER
)
11387 if(((Player
*)this)->GetGroup())
11388 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
11390 else if(((Creature
*)this)->isPet())
11392 Pet
*pet
= ((Pet
*)this);
11393 if(pet
->isControlled())
11395 Unit
*owner
= GetOwner();
11396 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11397 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
11402 void Unit::SetMaxHealth(uint32 val
)
11404 uint32 health
= GetHealth();
11405 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
11408 if(GetTypeId() == TYPEID_PLAYER
)
11410 if(((Player
*)this)->GetGroup())
11411 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
11413 else if(((Creature
*)this)->isPet())
11415 Pet
*pet
= ((Pet
*)this);
11416 if(pet
->isControlled())
11418 Unit
*owner
= GetOwner();
11419 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11420 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP
);
11428 void Unit::SetPower(Powers power
, uint32 val
)
11430 if(GetPower(power
) == val
)
11433 uint32 maxPower
= GetMaxPower(power
);
11437 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
11439 WorldPacket
data(SMSG_POWER_UPDATE
);
11440 data
.append(GetPackGUID());
11441 data
<< uint8(power
);
11442 data
<< uint32(val
);
11443 SendMessageToSet(&data
, GetTypeId() == TYPEID_PLAYER
? true : false);
11446 if(GetTypeId() == TYPEID_PLAYER
)
11448 if(((Player
*)this)->GetGroup())
11449 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11451 else if(((Creature
*)this)->isPet())
11453 Pet
*pet
= ((Pet
*)this);
11454 if(pet
->isControlled())
11456 Unit
*owner
= GetOwner();
11457 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11458 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11461 // Update the pet's character sheet with happiness damage bonus
11462 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
11464 pet
->UpdateDamagePhysical(BASE_ATTACK
);
11469 void Unit::SetMaxPower(Powers power
, uint32 val
)
11471 uint32 cur_power
= GetPower(power
);
11472 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
11475 if(GetTypeId() == TYPEID_PLAYER
)
11477 if(((Player
*)this)->GetGroup())
11478 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
11480 else if(((Creature
*)this)->isPet())
11482 Pet
*pet
= ((Pet
*)this);
11483 if(pet
->isControlled())
11485 Unit
*owner
= GetOwner();
11486 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11487 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
11491 if(val
< cur_power
)
11492 SetPower(power
, val
);
11495 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
11497 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
11500 if(GetTypeId() == TYPEID_PLAYER
)
11502 if(((Player
*)this)->GetGroup())
11503 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
11505 else if(((Creature
*)this)->isPet())
11507 Pet
*pet
= ((Pet
*)this);
11508 if(pet
->isControlled())
11510 Unit
*owner
= GetOwner();
11511 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11512 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
11517 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
11519 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
11522 if(GetTypeId() == TYPEID_PLAYER
)
11524 if(((Player
*)this)->GetGroup())
11525 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
11527 else if(((Creature
*)this)->isPet())
11529 Pet
*pet
= ((Pet
*)this);
11530 if(pet
->isControlled())
11532 Unit
*owner
= GetOwner();
11533 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11534 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
11539 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
11541 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
11543 tAuraProcTriggerDamage
.push_back(aura
);
11545 tAuraProcTriggerDamage
.remove(aura
);
11548 uint32
Unit::GetCreatePowers( Powers power
) const
11550 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
11553 case POWER_MANA
: return GetCreateMana();
11554 case POWER_RAGE
: return 1000;
11555 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
11556 case POWER_ENERGY
: return 100;
11557 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
11558 case POWER_RUNIC_POWER
: return 1000;
11559 case POWER_RUNE
: return 0;
11560 case POWER_HEALTH
: return 0;
11566 void Unit::AddToWorld()
11568 Object::AddToWorld();
11571 void Unit::RemoveFromWorld()
11577 RemoveNotOwnSingleTargetAuras();
11579 RemoveAllGameObjects();
11580 RemoveAllDynObjects();
11581 CleanupDeletedAuras();
11584 Object::RemoveFromWorld();
11587 void Unit::CleanupsBeforeDelete()
11589 if(m_uint32Values
) // only for fully created object
11591 InterruptNonMeleeSpells(true);
11592 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
11594 ClearComboPointHolders();
11595 DeleteThreatList();
11596 getHostileRefManager().setOnlineOfflineState(false);
11597 RemoveAllAuras(AURA_REMOVE_BY_DELETE
);
11598 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
11600 WorldObject::CleanupsBeforeDelete();
11603 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
11606 m_charmInfo
= new CharmInfo(charm
);
11607 return m_charmInfo
;
11610 CharmInfo::CharmInfo(Unit
* unit
)
11611 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
11613 for(int i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
11614 m_charmspells
[i
].SetActionAndType(0,ACT_DISABLED
);
11617 void CharmInfo::InitPetActionBar()
11619 // the first 3 SpellOrActions are attack, follow and stay
11620 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_START
- ACTION_BAR_INDEX_START
; ++i
)
11621 SetActionBar(ACTION_BAR_INDEX_START
+ i
,COMMAND_ATTACK
- i
,ACT_COMMAND
);
11623 // middle 4 SpellOrActions are spells/special attacks/abilities
11624 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_PET_SPELL_END
-ACTION_BAR_INDEX_PET_SPELL_START
; ++i
)
11625 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_START
+ i
,0,ACT_DISABLED
);
11627 // last 3 SpellOrActions are reactions
11628 for(uint32 i
= 0; i
< ACTION_BAR_INDEX_END
- ACTION_BAR_INDEX_PET_SPELL_END
; ++i
)
11629 SetActionBar(ACTION_BAR_INDEX_PET_SPELL_END
+ i
,COMMAND_ATTACK
- i
,ACT_REACTION
);
11632 void CharmInfo::InitEmptyActionBar()
11634 SetActionBar(ACTION_BAR_INDEX_START
,COMMAND_ATTACK
,ACT_COMMAND
);
11635 for(uint32 x
= ACTION_BAR_INDEX_START
+1; x
< ACTION_BAR_INDEX_END
; ++x
)
11636 SetActionBar(x
,0,ACT_PASSIVE
);
11639 void CharmInfo::InitPossessCreateSpells()
11641 InitEmptyActionBar(); //charm action bar
11643 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //possessed players don't have spells, keep the action bar empty
11646 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11648 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
11649 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
11651 AddSpellToActionBar(((Creature
*)m_unit
)->m_spells
[x
], ACT_PASSIVE
);
11655 void CharmInfo::InitCharmCreateSpells()
11657 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
11659 InitEmptyActionBar();
11663 InitPetActionBar();
11665 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11667 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
11671 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
11675 if (IsPassiveSpell(spellId
))
11677 m_unit
->CastSpell(m_unit
, spellId
, true);
11678 m_charmspells
[x
].SetActionAndType(spellId
,ACT_PASSIVE
);
11682 m_charmspells
[x
].SetActionAndType(spellId
,ACT_DISABLED
);
11684 ActiveStates newstate
;
11685 bool onlyselfcast
= true;
11686 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
11688 if(!spellInfo
) onlyselfcast
= false;
11689 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
11691 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
11692 onlyselfcast
= false;
11695 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
11696 newstate
= ACT_DISABLED
;
11698 newstate
= ACT_PASSIVE
;
11700 AddSpellToActionBar(spellId
, newstate
);
11705 bool CharmInfo::AddSpellToActionBar(uint32 spell_id
, ActiveStates newstate
)
11707 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
11709 // new spell rank can be already listed
11710 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11712 if (uint32 action
= PetActionBar
[i
].GetAction())
11714 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
11716 PetActionBar
[i
].SetAction(spell_id
);
11722 // or use empty slot in other case
11723 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11725 if (!PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
11727 SetActionBar(i
,spell_id
,newstate
== ACT_DECIDE
? ACT_DISABLED
: newstate
);
11734 bool CharmInfo::RemoveSpellFromActionBar(uint32 spell_id
)
11736 uint32 first_id
= sSpellMgr
.GetFirstSpellInChain(spell_id
);
11738 for(uint8 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11740 if (uint32 action
= PetActionBar
[i
].GetAction())
11742 if (PetActionBar
[i
].IsActionBarForSpell() && sSpellMgr
.GetFirstSpellInChain(action
) == first_id
)
11744 SetActionBar(i
,0,ACT_DISABLED
);
11753 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
11755 if(IsPassiveSpell(spellid
))
11758 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11759 if(spellid
== m_charmspells
[x
].GetAction())
11760 m_charmspells
[x
].SetType(apply
? ACT_ENABLED
: ACT_DISABLED
);
11763 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
11765 m_petnumber
= petnumber
;
11767 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
11769 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
11772 void CharmInfo::LoadPetActionBar(const std::string
& data
)
11774 InitPetActionBar();
11776 Tokens tokens
= StrSplit(data
, " ");
11778 if (tokens
.size() != (ACTION_BAR_INDEX_END
-ACTION_BAR_INDEX_START
)*2)
11779 return; // non critical, will reset to default
11782 Tokens::iterator iter
;
11783 for(iter
= tokens
.begin(), index
= ACTION_BAR_INDEX_START
; index
< ACTION_BAR_INDEX_END
; ++iter
, ++index
)
11785 // use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
11786 uint8 type
= atol((*iter
).c_str());
11788 uint32 action
= atol((*iter
).c_str());
11790 PetActionBar
[index
].SetActionAndType(action
,ActiveStates(type
));
11792 // check correctness
11793 if(PetActionBar
[index
].IsActionBarForSpell() && !sSpellStore
.LookupEntry(PetActionBar
[index
].GetAction()))
11794 SetActionBar(index
,0,ACT_DISABLED
);
11798 void CharmInfo::BuildActionBar( WorldPacket
* data
)
11800 for(uint32 i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11801 *data
<< uint32(PetActionBar
[i
].packedData
);
11804 void CharmInfo::SetSpellAutocast( uint32 spell_id
, bool state
)
11806 for(int i
= 0; i
< MAX_UNIT_ACTION_BAR_INDEX
; ++i
)
11808 if(spell_id
== PetActionBar
[i
].GetAction() && PetActionBar
[i
].IsActionBarForSpell())
11810 PetActionBar
[i
].SetType(state
? ACT_ENABLED
: ACT_DISABLED
);
11816 bool Unit::isFrozen() const
11818 return HasAuraState(AURA_STATE_FROZEN
);
11821 struct ProcTriggeredData
11823 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
11824 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
11825 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
11827 SpellProcEventEntry
const *spellProcEvent
;
11828 Aura
* triggeredByAura
;
11829 Unit::spellEffectPair triggeredByAura_SpellPair
;
11832 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
11833 typedef std::list
< uint32
> RemoveSpellList
;
11835 // List of auras that CAN be trigger but may not exist in spell_proc_event
11836 // in most case need for drop charges
11837 // in some types of aura need do additional check
11838 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
11839 bool InitTriggerAuraData()
11841 for (int i
=0;i
<TOTAL_AURAS
;++i
)
11843 isTriggerAura
[i
]=false;
11844 isNonTriggerAura
[i
] = false;
11846 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
11847 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
11848 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
11849 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
11850 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
11851 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
11852 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
11853 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
11854 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
11855 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
11856 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
11857 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
11858 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
] = true;
11859 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
11860 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
11861 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
11862 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
11863 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
11864 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
11865 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
11866 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
11867 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
11868 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
11869 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
11870 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
11871 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
11872 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
11873 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
] = true;
11874 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_FROM_CASTER
] = true;
11875 isTriggerAura
[SPELL_AURA_MOD_SPELL_CRIT_CHANCE
] = true;
11876 isTriggerAura
[SPELL_AURA_MAELSTROM_WEAPON
] = true;
11878 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
11879 isNonTriggerAura
[SPELL_AURA_REDUCE_PUSHBACK
]=true;
11884 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
11886 uint32 procEx
= PROC_EX_NONE
;
11887 // Check victim state
11888 if (missCondition
!=SPELL_MISS_NONE
)
11889 switch (missCondition
)
11891 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
11892 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
11893 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
11894 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
11895 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
11896 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
11897 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
11898 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
11899 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
11900 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
11901 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
11908 if (damageInfo
->blocked
)
11909 procEx
|=PROC_EX_BLOCK
;
11911 if (damageInfo
->absorb
)
11912 procEx
|=PROC_EX_ABSORB
;
11914 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
11915 procEx
|=PROC_EX_CRITICAL_HIT
;
11917 procEx
|=PROC_EX_NORMAL_HIT
;
11922 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
11924 // For melee/ranged based attack need update skills and set some Aura states
11925 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
11927 // Update skills here for players
11928 if (GetTypeId() == TYPEID_PLAYER
)
11930 // On melee based hit/miss/resist need update skill (for victim and attacker)
11931 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
11933 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
11934 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, isVictim
);
11936 // Update defence if player is victim and parry/dodge/block
11937 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
11938 ((Player
*)this)->UpdateDefense();
11940 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
11941 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
11946 // if victim and dodge attack
11947 if (procExtra
&PROC_EX_DODGE
)
11949 //Update AURA_STATE on dodge
11950 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
11952 ModifyAuraState(AURA_STATE_DEFENSE
, true);
11953 StartReactiveTimer( REACTIVE_DEFENSE
);
11956 // if victim and parry attack
11957 if (procExtra
& PROC_EX_PARRY
)
11959 // For Hunters only Counterattack (skip Mongoose bite)
11960 if (getClass() == CLASS_HUNTER
)
11962 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
11963 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
11967 ModifyAuraState(AURA_STATE_DEFENSE
, true);
11968 StartReactiveTimer( REACTIVE_DEFENSE
);
11971 // if and victim block attack
11972 if (procExtra
& PROC_EX_BLOCK
)
11974 ModifyAuraState(AURA_STATE_DEFENSE
,true);
11975 StartReactiveTimer( REACTIVE_DEFENSE
);
11978 else //For attacker
11980 // Overpower on victim dodge
11981 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
11983 ((Player
*)this)->AddComboPoints(pTarget
, 1);
11984 StartReactiveTimer( REACTIVE_OVERPOWER
);
11990 RemoveSpellList removedSpells
;
11991 ProcTriggeredList procTriggered
;
11992 // Fill procTriggered list
11993 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
11995 // skip deleted auras (possible at recursive triggered call
11996 if(itr
->second
->IsDeleted())
11999 SpellProcEventEntry
const* spellProcEvent
= NULL
;
12000 if(!IsTriggeredAtSpellProcEvent(pTarget
, itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
12003 itr
->second
->SetInUse(true); // prevent aura deletion
12004 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
12008 if (procTriggered
.empty())
12011 // Handle effects proceed this time
12012 for(ProcTriggeredList::const_iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
12014 // Some auras can be deleted in function called in this loop (except first, ofc)
12015 Aura
*triggeredByAura
= i
->triggeredByAura
;
12016 if(triggeredByAura
->IsDeleted())
12019 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
12020 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
12021 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
12022 bool useCharges
= triggeredByAura
->GetAuraCharges() > 0;
12023 // For players set spell cooldown if need
12024 uint32 cooldown
= 0;
12025 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
12026 cooldown
= spellProcEvent
->cooldown
;
12028 switch(auraModifier
->m_auraname
)
12030 case SPELL_AURA_PROC_TRIGGER_SPELL
:
12032 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12033 // Don`t drop charge or add cooldown for not started trigger
12034 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12036 triggeredByAura
->SetInUse(false);
12041 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
12043 sLog
.outDebug("ProcDamageAndSpell: doing %u damage from spell id %u (triggered by %s aura of spell %u)", auraModifier
->m_amount
, spellInfo
->Id
, (isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12044 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, spellInfo
->SchoolMask
);
12045 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
12046 DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
12047 SendSpellNonMeleeDamageLog(&damageInfo
);
12048 DealSpellDamage(&damageInfo
, true);
12051 case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
:
12052 case SPELL_AURA_MANA_SHIELD
:
12053 case SPELL_AURA_OBS_MOD_MANA
:
12054 case SPELL_AURA_ADD_PCT_MODIFIER
:
12055 case SPELL_AURA_DUMMY
:
12057 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12058 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12060 triggeredByAura
->SetInUse(false);
12065 case SPELL_AURA_MOD_HASTE
:
12067 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12068 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12070 triggeredByAura
->SetInUse(false);
12075 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
12077 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12078 if (!HandleOverrideClassScriptAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, cooldown
))
12080 triggeredByAura
->SetInUse(false);
12085 case SPELL_AURA_PRAYER_OF_MENDING
:
12087 sLog
.outDebug("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
12088 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
12090 HandleMendingAuraProc(triggeredByAura
);
12093 case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
:
12095 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered with value by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12097 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12099 triggeredByAura
->SetInUse(false);
12104 case SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
:
12105 // Skip melee hits or instant cast spells
12106 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
12108 triggeredByAura
->SetInUse(false);
12112 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
12113 // Skip Melee hits and spells ws wrong school
12114 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
12116 triggeredByAura
->SetInUse(false);
12120 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
12121 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
12122 // Skip melee hits and spells ws wrong school or zero cost
12123 if (procSpell
== NULL
||
12124 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
12125 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
12127 triggeredByAura
->SetInUse(false);
12131 case SPELL_AURA_MECHANIC_IMMUNITY
:
12132 // Compare mechanic
12133 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12135 triggeredByAura
->SetInUse(false);
12139 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
12140 // Compare mechanic
12141 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
12143 triggeredByAura
->SetInUse(false);
12147 case SPELL_AURA_MOD_DAMAGE_FROM_CASTER
:
12149 if (triggeredByAura
->GetCasterGUID() != pTarget
->GetGUID())
12151 triggeredByAura
->SetInUse(false);
12155 case SPELL_AURA_MOD_SPELL_CRIT_CHANCE
:
12158 triggeredByAura
->SetInUse(false);
12161 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s spell crit chance aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12162 if (!HandleSpellCritChanceAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
12164 triggeredByAura
->SetInUse(false);
12168 case SPELL_AURA_MAELSTROM_WEAPON
:
12169 sLog
.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s maelstrom aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
12171 // remove all stack;
12172 RemoveSpellsCausingAura(SPELL_AURA_MAELSTROM_WEAPON
);
12173 triggeredByAura
->SetInUse(false); // this safe, aura locked
12174 continue; // avoid re-remove attempts
12176 // nothing do, just charges counter
12180 // Remove charge (aura can be removed by triggers)
12181 if(useCharges
&& !triggeredByAura
->IsDeleted())
12183 // If last charge dropped add spell to remove list
12184 if(triggeredByAura
->DropAuraCharge())
12185 removedSpells
.push_back(triggeredByAura
->GetId());
12188 triggeredByAura
->SetInUse(false);
12190 if (!removedSpells
.empty())
12192 // Sort spells and remove dublicates
12193 removedSpells
.sort();
12194 removedSpells
.unique();
12195 // Remove auras from removedAuras
12196 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();++i
)
12197 RemoveSingleSpellAurasFromStack(*i
);
12201 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
12203 return SPELL_SCHOOL_MASK_NORMAL
;
12206 Player
* Unit::GetSpellModOwner()
12208 if(GetTypeId()==TYPEID_PLAYER
)
12209 return (Player
*)this;
12210 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
12212 Unit
* owner
= GetOwner();
12213 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
12214 return (Player
*)owner
;
12219 ///----------Pet responses methods-----------------
12220 void Unit::SendPetCastFail(uint32 spellid
, SpellCastResult msg
)
12222 if(msg
== SPELL_CAST_OK
)
12225 Unit
*owner
= GetCharmerOrOwner();
12226 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12229 WorldPacket
data(SMSG_PET_CAST_FAILED
, 1 + 4 + 1);
12230 data
<< uint8(0); // cast count?
12231 data
<< uint32(spellid
);
12232 data
<< uint8(msg
);
12233 // uint32 for some reason
12234 // uint32 for some reason
12235 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12238 void Unit::SendPetActionFeedback (uint8 msg
)
12240 Unit
* owner
= GetOwner();
12241 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12244 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
12245 data
<< uint8(msg
);
12246 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12249 void Unit::SendPetTalk (uint32 pettalk
)
12251 Unit
* owner
= GetOwner();
12252 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12255 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8 + 4);
12256 data
<< uint64(GetGUID());
12257 data
<< uint32(pettalk
);
12258 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12261 void Unit::SendPetAIReaction(uint64 guid
)
12263 Unit
* owner
= GetOwner();
12264 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
12267 WorldPacket
data(SMSG_AI_REACTION
, 8 + 4);
12268 data
<< uint64(guid
);
12269 data
<< uint32(AI_REACTION_AGGRO
);
12270 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
12273 ///----------End of Pet responses methods----------
12275 void Unit::StopMoving()
12277 clearUnitState(UNIT_STAT_MOVING
);
12279 // send explicit stop packet
12280 // player expected for correct work MONSTER_MOVE_WALK
12281 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, GetTypeId()==TYPEID_PLAYER
? MONSTER_MOVE_WALK
: MONSTER_MOVE_NONE
, 0);
12283 // update position and orientation for near players
12285 BuildHeartBeatMsg(&data
);
12286 SendMessageToSet(&data
,false);
12289 void Unit::SetFeared(bool apply
, uint64
const& casterGUID
, uint32 spellID
, uint32 time
)
12293 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
12296 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12298 GetMotionMaster()->MovementExpired(false);
12299 CastStop(GetGUID()==casterGUID
? spellID
: 0);
12301 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
12303 GetMotionMaster()->MoveFleeing(caster
, time
); // caster==NULL processed in MoveFleeing
12307 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
12309 GetMotionMaster()->MovementExpired(false);
12311 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
12313 // restore appropriate movement generator
12315 GetMotionMaster()->MoveChase(getVictim());
12317 GetMotionMaster()->Initialize();
12319 // attack caster if can
12320 Unit
* caster
= Unit::GetUnit(*this, casterGUID
);
12321 if(caster
&& ((Creature
*)this)->AI())
12322 ((Creature
*)this)->AI()->AttackedBy(caster
);
12326 if (GetTypeId() == TYPEID_PLAYER
)
12327 ((Player
*)this)->SetClientControl(this, !apply
);
12330 void Unit::SetConfused(bool apply
, uint64
const& casterGUID
, uint32 spellID
)
12334 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12336 CastStop(GetGUID()==casterGUID
? spellID
: 0);
12338 GetMotionMaster()->MoveConfused();
12342 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
12344 GetMotionMaster()->MovementExpired(false);
12346 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12348 // restore appropriate movement generator
12350 GetMotionMaster()->MoveChase(getVictim());
12352 GetMotionMaster()->Initialize();
12356 if(GetTypeId() == TYPEID_PLAYER
)
12357 ((Player
*)this)->SetClientControl(this, !apply
);
12360 void Unit::SetFeignDeath(bool apply
, uint64
const& casterGUID
, uint32 spellID
)
12365 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12368 SendMessageToSet(&data,true);
12371 if(GetTypeId() != TYPEID_PLAYER
)
12374 ((Player
*)this)->m_movementInfo
.SetMovementFlags(MOVEMENTFLAG_NONE
);
12376 // blizz like 2.0.x
12377 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12378 // blizz like 2.0.x
12379 SetFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12380 // blizz like 2.0.x
12381 SetFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12383 addUnitState(UNIT_STAT_DIED
);
12385 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION
);
12387 // prevent interrupt message
12388 if (casterGUID
== GetGUID())
12389 FinishSpell(CURRENT_GENERIC_SPELL
,false);
12390 InterruptNonMeleeSpells(true);
12391 getHostileRefManager().deleteReferences();
12396 WorldPacket data(SMSG_FEIGN_DEATH_RESISTED, 9);
12399 SendMessageToSet(&data,true);
12401 // blizz like 2.0.x
12402 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_29
);
12403 // blizz like 2.0.x
12404 RemoveFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_FEIGN_DEATH
);
12405 // blizz like 2.0.x
12406 RemoveFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_DEAD
);
12408 clearUnitState(UNIT_STAT_DIED
);
12410 if (GetTypeId() != TYPEID_PLAYER
&& isAlive())
12412 // restore appropriate movement generator
12414 GetMotionMaster()->MoveChase(getVictim());
12416 GetMotionMaster()->Initialize();
12422 bool Unit::IsSitState() const
12424 uint8 s
= getStandState();
12426 s
== UNIT_STAND_STATE_SIT_CHAIR
|| s
== UNIT_STAND_STATE_SIT_LOW_CHAIR
||
12427 s
== UNIT_STAND_STATE_SIT_MEDIUM_CHAIR
|| s
== UNIT_STAND_STATE_SIT_HIGH_CHAIR
||
12428 s
== UNIT_STAND_STATE_SIT
;
12431 bool Unit::IsStandState() const
12433 uint8 s
= getStandState();
12434 return !IsSitState() && s
!= UNIT_STAND_STATE_SLEEP
&& s
!= UNIT_STAND_STATE_KNEEL
;
12437 void Unit::SetStandState(uint8 state
)
12439 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
12441 if (IsStandState())
12442 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
12444 if(GetTypeId()==TYPEID_PLAYER
)
12446 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
12447 data
<< (uint8
)state
;
12448 ((Player
*)this)->GetSession()->SendPacket(&data
);
12452 bool Unit::IsPolymorphed() const
12454 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
12457 void Unit::SetDisplayId(uint32 modelId
)
12459 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
12461 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
12463 Pet
*pet
= ((Pet
*)this);
12464 if(!pet
->isControlled())
12466 Unit
*owner
= GetOwner();
12467 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12468 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
12472 void Unit::ClearComboPointHolders()
12474 while(!m_ComboPointHolders
.empty())
12476 uint32 lowguid
= *m_ComboPointHolders
.begin();
12478 Player
* plr
= sObjectMgr
.GetPlayer(MAKE_NEW_GUID(lowguid
, 0, HIGHGUID_PLAYER
));
12479 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
12480 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
12482 m_ComboPointHolders
.erase(lowguid
); // or remove manually
12486 void Unit::ClearAllReactives()
12488 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
12489 m_reactiveTimer
[i
] = 0;
12491 if (HasAuraState( AURA_STATE_DEFENSE
))
12492 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12493 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
12494 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12495 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12496 ((Player
*)this)->ClearComboPoints();
12499 void Unit::UpdateReactives( uint32 p_time
)
12501 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
12503 ReactiveType reactive
= ReactiveType(i
);
12505 if(!m_reactiveTimer
[reactive
])
12508 if ( m_reactiveTimer
[reactive
] <= p_time
)
12510 m_reactiveTimer
[reactive
] = 0;
12512 switch ( reactive
)
12514 case REACTIVE_DEFENSE
:
12515 if (HasAuraState(AURA_STATE_DEFENSE
))
12516 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12518 case REACTIVE_HUNTER_PARRY
:
12519 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
12520 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12522 case REACTIVE_OVERPOWER
:
12523 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12524 ((Player
*)this)->ClearComboPoints();
12532 m_reactiveTimer
[reactive
] -= p_time
;
12537 Unit
* Unit::SelectNearbyTarget(Unit
* except
/*= NULL*/) const
12539 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
12541 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
12542 cell
.SetNoCreate();
12544 std::list
<Unit
*> targets
;
12547 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, ATTACK_DISTANCE
);
12548 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
12550 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
12551 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
12553 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
12554 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *GetMap(), *this, ATTACK_DISTANCE
);
12555 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *GetMap(), *this, ATTACK_DISTANCE
);
12558 // remove current target
12560 targets
.remove(except
);
12562 // remove not LoS targets
12563 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
12565 if(!IsWithinLOSInMap(*tIter
))
12567 std::list
<Unit
*>::iterator tIter2
= tIter
;
12569 targets
.erase(tIter2
);
12575 // no appropriate targets
12576 if(targets
.empty())
12580 uint32 rIdx
= urand(0,targets
.size()-1);
12581 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
12582 for(uint32 i
= 0; i
< rIdx
; ++i
)
12588 bool Unit::hasNegativeAuraWithInterruptFlag(uint32 flag
)
12590 for (AuraMap::const_iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); ++iter
)
12592 if (!iter
->second
->IsPositive() && iter
->second
->GetSpellProto()->AuraInterruptFlags
& flag
)
12598 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
12602 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
12603 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
12607 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
12608 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
12612 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
12615 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
12617 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
12620 uint32
Unit::GetCastingTimeForBonus( SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 CastingTime
)
12622 // Not apply this to creature casted spells with casttime==0
12623 if(CastingTime
==0 && GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
12626 if (CastingTime
> 7000) CastingTime
= 7000;
12627 if (CastingTime
< 1500) CastingTime
= 1500;
12629 if(damagetype
== DOT
&& !IsChanneledSpell(spellProto
))
12630 CastingTime
= 3500;
12632 int32 overTime
= 0;
12634 bool DirectDamage
= false;
12635 bool AreaEffect
= false;
12637 for ( uint32 i
=0; i
<3;++i
)
12639 switch ( spellProto
->Effect
[i
] )
12641 case SPELL_EFFECT_SCHOOL_DAMAGE
:
12642 case SPELL_EFFECT_POWER_DRAIN
:
12643 case SPELL_EFFECT_HEALTH_LEECH
:
12644 case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
:
12645 case SPELL_EFFECT_POWER_BURN
:
12646 case SPELL_EFFECT_HEAL
:
12647 DirectDamage
= true;
12649 case SPELL_EFFECT_APPLY_AURA
:
12650 switch ( spellProto
->EffectApplyAuraName
[i
] )
12652 case SPELL_AURA_PERIODIC_DAMAGE
:
12653 case SPELL_AURA_PERIODIC_HEAL
:
12654 case SPELL_AURA_PERIODIC_LEECH
:
12655 if ( GetSpellDuration(spellProto
) )
12656 overTime
= GetSpellDuration(spellProto
);
12659 // -5% per additional effect
12667 if(IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetA
[i
])) || IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetB
[i
])))
12671 // Combined Spells with Both Over Time and Direct Damage
12672 if ( overTime
> 0 && CastingTime
> 0 && DirectDamage
)
12674 // mainly for DoTs which are 3500 here otherwise
12675 uint32 OriginalCastTime
= GetSpellCastTime(spellProto
);
12676 if (OriginalCastTime
> 7000) OriginalCastTime
= 7000;
12677 if (OriginalCastTime
< 1500) OriginalCastTime
= 1500;
12678 // Portion to Over Time
12679 float PtOT
= (overTime
/ 15000.0f
) / ((overTime
/ 15000.0f
) + (OriginalCastTime
/ 3500.0f
));
12681 if ( damagetype
== DOT
)
12682 CastingTime
= uint32(CastingTime
* PtOT
);
12683 else if ( PtOT
< 1.0f
)
12684 CastingTime
= uint32(CastingTime
* (1 - PtOT
));
12689 // Area Effect Spells receive only half of bonus
12693 // -5% of total per any additional effect
12694 for ( uint8 i
=0; i
<effects
; ++i
)
12696 if ( CastingTime
> 175 )
12698 CastingTime
-= 175;
12707 return CastingTime
;
12710 void Unit::UpdateAuraForGroup(uint8 slot
)
12712 if(GetTypeId() == TYPEID_PLAYER
)
12714 Player
* player
= (Player
*)this;
12715 if(player
->GetGroup())
12717 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
12718 player
->SetAuraUpdateMask(slot
);
12721 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
12723 Pet
*pet
= ((Pet
*)this);
12724 if(pet
->isControlled())
12726 Unit
*owner
= GetOwner();
12727 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12729 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
12730 pet
->SetAuraUpdateMask(slot
);
12736 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
12738 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
12739 return float(GetAttackTime(attType
))/1000.0f
;
12741 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
, true, false);
12743 return 2.4; // fist attack
12745 switch (Weapon
->GetProto()->InventoryType
)
12747 case INVTYPE_2HWEAPON
:
12749 case INVTYPE_RANGED
:
12750 case INVTYPE_RANGEDRIGHT
:
12751 case INVTYPE_THROWN
:
12753 case INVTYPE_WEAPON
:
12754 case INVTYPE_WEAPONMAINHAND
:
12755 case INVTYPE_WEAPONOFFHAND
:
12757 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7 : 2.4;
12761 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
12763 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
12764 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
12765 if ((*itr
)->GetId() == spell_id
)
12771 void Unit::SetContestedPvP(Player
*attackedPlayer
)
12773 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
12775 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
12778 player
->SetContestedPvPTimer(30000);
12779 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
12781 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
12782 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
12783 // call MoveInLineOfSight for nearby contested guards
12784 SetVisibility(GetVisibility());
12786 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
12788 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
12789 // call MoveInLineOfSight for nearby contested guards
12790 SetVisibility(GetVisibility());
12794 void Unit::AddPetAura(PetAura
const* petSpell
)
12796 m_petAuras
.insert(petSpell
);
12797 if(Pet
* pet
= GetPet())
12798 pet
->CastPetAura(petSpell
);
12801 void Unit::RemovePetAura(PetAura
const* petSpell
)
12803 m_petAuras
.erase(petSpell
);
12804 if(Pet
* pet
= GetPet())
12805 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
12808 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
12810 Pet
* pet
= new Pet(HUNTER_PET
);
12812 if(!pet
->CreateBaseAtCreature(creatureTarget
))
12818 pet
->SetOwnerGUID(GetGUID());
12819 pet
->SetCreatorGUID(GetGUID());
12820 pet
->setFaction(getFaction());
12821 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
12823 if(GetTypeId()==TYPEID_PLAYER
)
12824 pet
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
12830 pet
->SetFFAPvP(true);
12832 uint32 level
= (creatureTarget
->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget
->getLevel();
12834 if(!pet
->InitStatsForLevel(level
))
12836 sLog
.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
12841 pet
->GetCharmInfo()->SetPetNumber(sObjectMgr
.GeneratePetNumber(), true);
12842 // this enables pet details window (Shift+P)
12843 pet
->AIM_Initialize();
12844 pet
->InitPetCreateSpells();
12845 pet
->InitLevelupSpellsForLevel();
12846 pet
->InitTalentForLevel();
12847 pet
->SetHealth(pet
->GetMaxHealth());
12852 bool Unit::IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
12854 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
12856 // Get proc Event Entry
12857 spellProcEvent
= sSpellMgr
.GetSpellProcEvent(spellProto
->Id
);
12859 // Aura info stored here
12860 Modifier
*mod
= aura
->GetModifier();
12862 if (isNonTriggerAura
[mod
->m_auraname
])
12864 // If not trigger by default and spellProcEvent==NULL - skip
12865 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
12868 // Get EventProcFlag
12869 uint32 EventProcFlag
;
12870 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
12871 EventProcFlag
= spellProcEvent
->procFlags
;
12873 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
12874 // Continue if no trigger exist
12875 if (!EventProcFlag
)
12878 // Check spellProcEvent data requirements
12879 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
12882 // In most cases req get honor or XP from kill
12883 if (EventProcFlag
& PROC_FLAG_KILL
&& GetTypeId() == TYPEID_PLAYER
)
12885 bool allow
= ((Player
*)this)->isHonorOrXPTarget(pVictim
);
12886 // Shadow Word: Death - can trigger from every kill
12887 if (aura
->GetId() == 32409)
12892 // Aura added by spell can`t trogger from self (prevent drop charges/do triggers)
12893 // But except periodic triggers (can triggered from self)
12894 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
& PROC_FLAG_ON_TAKE_PERIODIC
))
12897 // Check if current equipment allows aura to proc
12898 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
12900 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
12903 if(attType
== BASE_ATTACK
)
12904 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
12905 else if (attType
== OFF_ATTACK
)
12906 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
12908 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
12910 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
12913 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
12915 // Check if player is wearing shield
12916 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
12917 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
12921 // Get chance from spell
12922 float chance
= (float)spellProto
->procChance
;
12923 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
12924 if(spellProcEvent
&& spellProcEvent
->customChance
)
12925 chance
= spellProcEvent
->customChance
;
12926 // If PPM exist calculate chance from PPM
12927 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
12929 uint32 WeaponSpeed
= GetAttackTime(attType
);
12930 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
12932 // Apply chance modifer aura
12933 if(Player
* modOwner
= GetSpellModOwner())
12935 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
12936 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_FREQUENCY_OF_SUCCESS
,chance
);
12939 return roll_chance_f(chance
);
12942 bool Unit::HandleMendingAuraProc( Aura
* triggeredByAura
)
12944 // aura can be deleted at casts
12945 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
12946 uint32 effIdx
= triggeredByAura
->GetEffIndex();
12947 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
12948 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
12951 int32 jumps
= triggeredByAura
->GetAuraCharges()-1;
12953 // current aura expire
12954 triggeredByAura
->SetAuraCharges(1); // will removed at next charges decrease
12956 // next target selection
12957 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
12960 if (spellProto
->EffectRadiusIndex
[effIdx
])
12961 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
12963 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
12965 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
12967 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
12969 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
12971 // aura will applied from caster, but spell casted from current aura holder
12972 SpellModifier
*mod
= new SpellModifier(SPELLMOD_CHARGES
,SPELLMOD_FLAT
,jumps
-5,spellProto
->Id
,spellProto
->SpellFamilyFlags
,spellProto
->SpellFamilyFlags2
);
12974 // remove before apply next (locked against deleted)
12975 triggeredByAura
->SetInUse(true);
12976 RemoveAurasByCasterSpell(spellProto
->Id
,caster
->GetGUID());
12978 caster
->AddSpellMod(mod
, true);
12979 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
12980 caster
->AddSpellMod(mod
, false);
12981 triggeredByAura
->SetInUse(false);
12987 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
12991 void Unit::RemoveAurasAtMechanicImmunity(uint32 mechMask
, uint32 exceptSpellId
, bool non_positive
/*= false*/)
12993 Unit::AuraMap
& auras
= GetAuras();
12994 for(Unit::AuraMap::iterator iter
= auras
.begin(); iter
!= auras
.end();)
12996 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
12997 if (spell
->Id
== exceptSpellId
)
12999 else if (non_positive
&& iter
->second
->IsPositive())
13001 else if (spell
->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
)
13003 else if (GetSpellMechanicMask(spell
, iter
->second
->GetEffIndex()) & mechMask
)
13005 RemoveAurasDueToSpell(spell
->Id
);
13009 iter
= auras
.begin();
13016 void Unit::SetPhaseMask(uint32 newPhaseMask
, bool update
)
13018 if(newPhaseMask
==GetPhaseMask())
13022 RemoveNotOwnSingleTargetAuras(newPhaseMask
); // we can lost access to caster or target
13024 WorldObject::SetPhaseMask(newPhaseMask
,update
);
13027 if(Pet
* pet
= GetPet())
13028 pet
->SetPhaseMask(newPhaseMask
,true);
13031 void Unit::NearTeleportTo( float x
, float y
, float z
, float orientation
, bool casting
/*= false*/ )
13033 if(GetTypeId() == TYPEID_PLAYER
)
13034 ((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));
13037 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, orientation
);
13040 BuildHeartBeatMsg(&data
);
13041 SendMessageToSet(&data
, false);
13045 struct SetPvPHelper
13047 explicit SetPvPHelper(bool _state
) : state(_state
) {}
13048 void operator()(Unit
* unit
) const { unit
->SetPvP(state
); }
13052 void Unit::SetPvP( bool state
)
13055 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13057 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
13059 CallForAllControlledUnits(SetPvPHelper(state
),true,true,true);
13062 struct SetFFAPvPHelper
13064 explicit SetFFAPvPHelper(bool _state
) : state(_state
) {}
13065 void operator()(Unit
* unit
) const { unit
->SetFFAPvP(state
); }
13069 void Unit::SetFFAPvP( bool state
)
13072 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13074 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
13076 CallForAllControlledUnits(SetFFAPvPHelper(state
),true,true,true);
13079 void Unit::KnockBackFrom(Unit
* target
, float horizintalSpeed
, float verticalSpeed
)
13081 float angle
= this == target
? GetOrientation() + M_PI
: target
->GetAngle(this);
13082 float vsin
= sin(angle
);
13083 float vcos
= cos(angle
);
13085 // Effect propertly implemented only for players
13086 if(GetTypeId()==TYPEID_PLAYER
)
13088 WorldPacket
data(SMSG_MOVE_KNOCK_BACK
, 8+4+4+4+4+4);
13089 data
.append(GetPackGUID());
13090 data
<< uint32(0); // Sequence
13091 data
<< float(vcos
); // x direction
13092 data
<< float(vsin
); // y direction
13093 data
<< float(horizintalSpeed
); // Horizontal speed
13094 data
<< float(-verticalSpeed
); // Z Movement speed (vertical)
13095 ((Player
*)this)->GetSession()->SendPacket(&data
);
13099 float dis
= horizintalSpeed
;
13102 GetPosition(ox
, oy
, oz
);
13104 float fx
= ox
+ dis
* vcos
;
13105 float fy
= oy
+ dis
* vsin
;
13108 float fx2
, fy2
, fz2
; // getObjectHitPos overwrite last args in any result case
13109 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), ox
,oy
,oz
+0.5, fx
,fy
,oz
+0.5,fx2
,fy2
,fz2
, -0.5))
13114 UpdateGroundPositionZ(fx
, fy
, fz
);
13117 //FIXME: this mostly hack, must exist some packet for proper creature move at client side
13118 // with CreatureRelocation at server side
13119 NearTeleportTo(fx
, fy
, fz
, GetOrientation(), this == target
);
13123 float Unit::GetCombatRatingReduction(CombatRating cr
) const
13125 if (GetTypeId() == TYPEID_PLAYER
)
13126 return ((Player
const*)this)->GetRatingBonusValue(cr
);
13127 else if (((Creature
const*)this)->isPet())
13129 // Player's pet have 0.4 resilience from owner
13130 if (Unit
* owner
= GetOwner())
13131 if(owner
->GetTypeId() == TYPEID_PLAYER
)
13132 return ((Player
*)owner
)->GetRatingBonusValue(cr
) * 0.4f
;
13138 uint32
Unit::GetCombatRatingDamageReduction(CombatRating cr
, float rate
, float cap
, uint32 damage
) const
13140 float percent
= GetCombatRatingReduction(cr
) * rate
;
13143 return uint32 (percent
* damage
/ 100.0f
);
13146 void Unit::SendThreatUpdate()
13148 ThreatList
const& tlist
= getThreatManager().getThreatList();
13149 if (uint32 count
= tlist
.size())
13151 sLog
.outDebug( "WORLD: Send SMSG_THREAT_UPDATE Message" );
13152 WorldPacket
data(SMSG_THREAT_UPDATE
, 8 + count
* 8);
13153 data
.append(GetPackGUID());
13154 data
<< uint32(count
);
13155 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13157 data
.appendPackGUID((*itr
)->getUnitGuid());
13158 data
<< uint32((*itr
)->getThreat());
13160 SendMessageToSet(&data
, false);
13164 void Unit::SendHighestThreatUpdate(HostileReference
* pHostilReference
)
13166 ThreatList
const& tlist
= getThreatManager().getThreatList();
13167 if (uint32 count
= tlist
.size())
13169 sLog
.outDebug( "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message" );
13170 WorldPacket
data(SMSG_HIGHEST_THREAT_UPDATE
, 8 + 8 + count
* 8);
13171 data
.append(GetPackGUID());
13172 data
.appendPackGUID(pHostilReference
->getUnitGuid());
13173 data
<< uint32(count
);
13174 for (ThreatList::const_iterator itr
= tlist
.begin(); itr
!= tlist
.end(); ++itr
)
13176 data
.appendPackGUID((*itr
)->getUnitGuid());
13177 data
<< uint32((*itr
)->getThreat());
13179 SendMessageToSet(&data
, false);
13183 void Unit::SendThreatClear()
13185 sLog
.outDebug( "WORLD: Send SMSG_THREAT_CLEAR Message" );
13186 WorldPacket
data(SMSG_THREAT_CLEAR
, 8);
13187 data
.append(GetPackGUID());
13188 SendMessageToSet(&data
, false);
13191 void Unit::SendThreatRemove(HostileReference
* pHostileReference
)
13193 sLog
.outDebug( "WORLD: Send SMSG_THREAT_REMOVE Message" );
13194 WorldPacket
data(SMSG_THREAT_REMOVE
, 8 + 8);
13195 data
.append(GetPackGUID());
13196 data
.appendPackGUID(pHostileReference
->getUnitGuid());
13197 SendMessageToSet(&data
, false);
13200 struct StopAttackFactionHelper
13202 explicit StopAttackFactionHelper(uint32 _faction_id
) : faction_id(_faction_id
) {}
13203 void operator()(Unit
* unit
) const { unit
->StopAttackFaction(faction_id
); }
13207 void Unit::StopAttackFaction(uint32 faction_id
)
13209 if (Unit
* victim
= getVictim())
13211 if (victim
->getFactionTemplateEntry()->faction
==faction_id
)
13214 if (IsNonMeleeSpellCasted(false))
13215 InterruptNonMeleeSpells(false);
13217 // melee and ranged forced attack cancel
13218 if (GetTypeId() == TYPEID_PLAYER
)
13219 ((Player
*)this)->SendAttackSwingCancelAttack();
13223 AttackerSet
const& attackers
= getAttackers();
13224 for(AttackerSet::const_iterator itr
= attackers
.begin(); itr
!= attackers
.end();)
13226 if ((*itr
)->getFactionTemplateEntry()->faction
==faction_id
)
13228 (*itr
)->AttackStop();
13229 itr
= attackers
.begin();
13235 getHostileRefManager().deleteReferencesForFaction(faction_id
);
13237 CallForAllControlledUnits(StopAttackFactionHelper(faction_id
),false,true,true);
13240 void Unit::CleanupDeletedAuras()
13242 // really delete auras "deleted" while processing its ApplyModify code
13243 for(AuraList::const_iterator itr
= m_deletedAuras
.begin(); itr
!= m_deletedAuras
.end(); ++itr
)
13245 m_deletedAuras
.clear();