2 * Copyright (C) 2005-2008 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"
33 #include "SpellAuras.h"
34 #include "MapManager.h"
35 #include "ObjectAccessor.h"
36 #include "CreatureAI.h"
41 #include "BattleGround.h"
42 #include "InstanceSaveMgr.h"
43 #include "GridNotifiersImpl.h"
49 float baseMoveSpeed
[MAX_MOVE_TYPE
] =
53 1.25f
, // MOVE_WALKBACK
54 4.722222f
, // MOVE_SWIM
55 4.5f
, // MOVE_SWIMBACK
56 3.141594f
, // MOVE_TURN
61 void InitTriggerAuraData();
63 // auraTypes contains attacker auras capable of proc'ing cast auras
64 static Unit::AuraTypeSet
GenerateAttakerProcCastAuraTypes()
66 static Unit::AuraTypeSet auraTypes
;
67 auraTypes
.insert(SPELL_AURA_DUMMY
);
68 auraTypes
.insert(SPELL_AURA_PROC_TRIGGER_SPELL
);
69 auraTypes
.insert(SPELL_AURA_MOD_HASTE
);
70 auraTypes
.insert(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
74 // auraTypes contains victim auras capable of proc'ing cast auras
75 static Unit::AuraTypeSet
GenerateVictimProcCastAuraTypes()
77 static Unit::AuraTypeSet auraTypes
;
78 auraTypes
.insert(SPELL_AURA_DUMMY
);
79 auraTypes
.insert(SPELL_AURA_PRAYER_OF_MENDING
);
80 auraTypes
.insert(SPELL_AURA_PROC_TRIGGER_SPELL
);
84 // auraTypes contains auras capable of proc effect/damage (but not cast) for attacker
85 static Unit::AuraTypeSet
GenerateAttakerProcEffectAuraTypes()
87 static Unit::AuraTypeSet auraTypes
;
88 auraTypes
.insert(SPELL_AURA_MOD_DAMAGE_DONE
);
89 auraTypes
.insert(SPELL_AURA_PROC_TRIGGER_DAMAGE
);
90 auraTypes
.insert(SPELL_AURA_MOD_CASTING_SPEED
);
91 auraTypes
.insert(SPELL_AURA_MOD_RATING
);
95 // auraTypes contains auras capable of proc effect/damage (but not cast) for victim
96 static Unit::AuraTypeSet
GenerateVictimProcEffectAuraTypes()
98 static Unit::AuraTypeSet auraTypes
;
99 auraTypes
.insert(SPELL_AURA_MOD_RESISTANCE
);
100 auraTypes
.insert(SPELL_AURA_PROC_TRIGGER_DAMAGE
);
101 auraTypes
.insert(SPELL_AURA_MOD_PARRY_PERCENT
);
102 auraTypes
.insert(SPELL_AURA_MOD_BLOCK_PERCENT
);
103 auraTypes
.insert(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
107 static Unit::AuraTypeSet attackerProcCastAuraTypes
= GenerateAttakerProcCastAuraTypes();
108 static Unit::AuraTypeSet attackerProcEffectAuraTypes
= GenerateAttakerProcEffectAuraTypes();
110 static Unit::AuraTypeSet victimProcCastAuraTypes
= GenerateVictimProcCastAuraTypes();
111 static Unit::AuraTypeSet victimProcEffectAuraTypes
= GenerateVictimProcEffectAuraTypes();
113 // auraTypes contains auras capable of proc'ing for attacker and victim
114 static Unit::AuraTypeSet
GenerateProcAuraTypes()
116 InitTriggerAuraData();
118 Unit::AuraTypeSet auraTypes
;
119 auraTypes
.insert(attackerProcCastAuraTypes
.begin(),attackerProcCastAuraTypes
.end());
120 auraTypes
.insert(attackerProcEffectAuraTypes
.begin(),attackerProcEffectAuraTypes
.end());
121 auraTypes
.insert(victimProcCastAuraTypes
.begin(),victimProcCastAuraTypes
.end());
122 auraTypes
.insert(victimProcEffectAuraTypes
.begin(),victimProcEffectAuraTypes
.end());
126 static Unit::AuraTypeSet procAuraTypes
= GenerateProcAuraTypes();
128 bool IsPassiveStackableSpell( uint32 spellId
)
130 if(!IsPassiveSpell(spellId
))
133 SpellEntry
const* spellProto
= sSpellStore
.LookupEntry(spellId
);
137 for(int j
= 0; j
< 3; ++j
)
139 if(std::find(procAuraTypes
.begin(),procAuraTypes
.end(),spellProto
->EffectApplyAuraName
[j
])!=procAuraTypes
.end())
147 : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this)
149 m_objectType
|= TYPEMASK_UNIT
;
150 m_objectTypeId
= TYPEID_UNIT
;
152 m_updateFlag
= (UPDATEFLAG_HIGHGUID
| UPDATEFLAG_LIVING
| UPDATEFLAG_HASPOSITION
);
154 m_attackTimer
[BASE_ATTACK
] = 0;
155 m_attackTimer
[OFF_ATTACK
] = 0;
156 m_attackTimer
[RANGED_ATTACK
] = 0;
157 m_modAttackSpeedPct
[BASE_ATTACK
] = 1.0f
;
158 m_modAttackSpeedPct
[OFF_ATTACK
] = 1.0f
;
159 m_modAttackSpeedPct
[RANGED_ATTACK
] = 1.0f
;
165 m_deathState
= ALIVE
;
167 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
168 m_currentSpells
[i
] = NULL
;
172 for(int i
= 0; i
< MAX_TOTEM
; ++i
)
175 m_ObjectSlot
[0] = m_ObjectSlot
[1] = m_ObjectSlot
[2] = m_ObjectSlot
[3] = 0;
177 //m_AurasCheck = 2000;
178 //m_removeAuraTimer = 4;
182 m_Visibility
= VISIBILITY_ON
;
184 m_detectInvisibilityMask
= 0;
185 m_invisibilityMask
= 0;
187 m_ShapeShiftFormSpellId
= 0;
188 m_canModifyStats
= false;
190 for (int i
= 0; i
< MAX_SPELL_IMMUNITY
; i
++)
191 m_spellImmune
[i
].clear();
192 for (int i
= 0; i
< UNIT_MOD_END
; i
++)
194 m_auraModifiersGroup
[i
][BASE_VALUE
] = 0.0f
;
195 m_auraModifiersGroup
[i
][BASE_PCT
] = 1.0f
;
196 m_auraModifiersGroup
[i
][TOTAL_VALUE
] = 0.0f
;
197 m_auraModifiersGroup
[i
][TOTAL_PCT
] = 1.0f
;
199 // implement 50% base damage from offhand
200 m_auraModifiersGroup
[UNIT_MOD_DAMAGE_OFFHAND
][TOTAL_PCT
] = 0.5f
;
202 for (int i
= 0; i
< 3; i
++)
204 m_weaponDamage
[i
][MINDAMAGE
] = BASE_MINDAMAGE
;
205 m_weaponDamage
[i
][MAXDAMAGE
] = BASE_MAXDAMAGE
;
207 for (int i
= 0; i
< MAX_STATS
; i
++)
208 m_createStats
[i
] = 0.0f
;
211 m_modMeleeHitChance
= 0.0f
;
212 m_modRangedHitChance
= 0.0f
;
213 m_modSpellHitChance
= 0.0f
;
214 m_baseSpellCritChance
= 5;
219 //m_victimThreat = 0.0f;
220 for (int i
= 0; i
< MAX_SPELL_SCHOOL
; ++i
)
221 m_threatModifier
[i
] = 1.0f
;
223 for (int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
224 m_speed_rate
[i
] = 1.0f
;
228 m_unit_movement_flags
= 0;
230 // remove aurastates allowing special moves
231 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
232 m_reactiveTimer
[i
] = 0;
237 // set current spells as deletable
238 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
240 if (m_currentSpells
[i
])
242 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
243 m_currentSpells
[i
] = NULL
;
247 RemoveAllGameObjects();
248 RemoveAllDynObjects();
250 if(m_charmInfo
) delete m_charmInfo
;
253 void Unit::Update( uint32 p_time
)
255 /*if(p_time > m_AurasCheck)
260 m_AurasCheck -= p_time;*/
262 // WARNING! Order of execution here is important, do not change.
263 // Spells must be processed with event system BEFORE they go to _UpdateSpells.
264 // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
265 m_Events
.Update( p_time
);
266 _UpdateSpells( p_time
);
268 // update combat timer only for players and pets
269 if (isInCombat() && (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet() || ((Creature
*)this)->isCharmed()))
271 // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away
272 // targets without stopping half way there and running off.
273 // These flags are reset after target dies or another command is given.
274 if( m_HostilRefManager
.isEmpty() )
276 // m_CombatTimer set at aura start and it will be freeze until aura removing
277 if ( m_CombatTimer
<= p_time
)
280 m_CombatTimer
-= p_time
;
284 if(uint32 base_att
= getAttackTimer(BASE_ATTACK
))
286 setAttackTimer(BASE_ATTACK
, (p_time
>= base_att
? 0 : base_att
- p_time
) );
289 // update abilities available only for fraction of time
290 UpdateReactives( p_time
);
292 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, GetHealth() < GetMaxHealth()*0.20f
);
293 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, GetHealth() < GetMaxHealth()*0.35f
);
295 i_motionMaster
.UpdateMotion(p_time
);
298 bool Unit::haveOffhandWeapon() const
300 if(GetTypeId() == TYPEID_PLAYER
)
301 return ((Player
*)this)->GetWeaponForAttack(OFF_ATTACK
,true);
306 void Unit::SendMonsterMoveWithSpeedToCurrentDestination(Player
* player
)
309 if(GetMotionMaster()->GetDestination(x
, y
, z
))
310 SendMonsterMoveWithSpeed(x
, y
, z
, GetUnitMovementFlags(), 0, player
);
313 void Unit::SendMonsterMoveWithSpeed(float x
, float y
, float z
, uint32 MovementFlags
, uint32 transitTime
, Player
* player
)
317 float dx
= x
- GetPositionX();
318 float dy
= y
- GetPositionY();
319 float dz
= z
- GetPositionZ();
321 float dist
= ((dx
*dx
) + (dy
*dy
) + (dz
*dz
));
327 double speed
= GetSpeed((MovementFlags
& MOVEMENTFLAG_WALK_MODE
) ? MOVE_WALK
: MOVE_RUN
);
331 transitTime
= static_cast<uint32
>(dist
/ speed
+ 0.5);
333 //float orientation = (float)atan2((double)dy, (double)dx);
334 SendMonsterMove(x
, y
, z
, 0, MovementFlags
, transitTime
, player
);
337 void Unit::SendMonsterMove(float NewPosX
, float NewPosY
, float NewPosZ
, uint8 type
, uint32 MovementFlags
, uint32 Time
, Player
* player
)
339 WorldPacket
data( SMSG_MONSTER_MOVE
, (41 + GetPackGUID().size()) );
340 data
.append(GetPackGUID());
342 // Point A, starting location
343 data
<< GetPositionX() << GetPositionY() << GetPositionZ();
344 // unknown field - unrelated to orientation
345 // seems to increment about 1000 for every 1.7 seconds
346 // for now, we'll just use mstime
349 data
<< uint8(type
); // unknown
352 case 0: // normal packet
354 case 1: // stop packet
355 SendMessageToSet( &data
, true );
357 case 2: // not used currently
362 case 3: // not used currently
363 data
<< uint64(0); // probably target guid
365 case 4: // not used currently
366 data
<< float(0); // probably orientation
370 //Movement Flags (0x0 = walk, 0x100 = run, 0x200 = fly/swim)
371 data
<< uint32(MovementFlags
);
373 data
<< Time
; // Time in between points
374 data
<< uint32(1); // 1 single waypoint
375 data
<< NewPosX
<< NewPosY
<< NewPosZ
; // the single waypoint Point B
378 player
->GetSession()->SendPacket(&data
);
380 SendMessageToSet( &data
, true );
383 void Unit::SendMonsterMoveByPath(Path
const& path
, uint32 start
, uint32 end
, uint32 MovementFlags
)
385 uint32 traveltime
= uint32(path
.GetTotalLength(start
, end
) * 32);
387 uint32 pathSize
= end
-start
;
389 WorldPacket
data( SMSG_MONSTER_MOVE
, (GetPackGUID().size()+4+4+4+4+1+4+4+4+pathSize
*4*3) );
390 data
.append(GetPackGUID());
391 data
<< GetPositionX();
392 data
<< GetPositionY();
393 data
<< GetPositionZ();
395 // unknown field - unrelated to orientation
396 // seems to increment about 1000 for every 1.7 seconds
397 // for now, we'll just use mstime
401 data
<< uint32( MovementFlags
);
402 data
<< uint32( traveltime
);
403 data
<< uint32( pathSize
);
404 data
.append( (char*)path
.GetNodes(start
), pathSize
* 4 * 3 );
406 //WPAssert( data.size() == 37 + pathnodes.Size( ) * 4 * 3 );
407 SendMessageToSet(&data
, true);
410 void Unit::resetAttackTimer(WeaponAttackType type
)
412 m_attackTimer
[type
] = uint32(GetAttackTime(type
) * m_modAttackSpeedPct
[type
]);
415 bool Unit::canReachWithAttack(Unit
*pVictim
) const
418 float reach
= GetFloatValue(UNIT_FIELD_COMBATREACH
);
421 return IsWithinDistInMap(pVictim
, reach
);
424 void Unit::RemoveSpellsCausingAura(AuraType auraType
)
426 if (auraType
>= TOTAL_AURAS
) return;
427 AuraList::iterator iter
, next
;
428 for (iter
= m_modAuras
[auraType
].begin(); iter
!= m_modAuras
[auraType
].end(); iter
= next
)
435 RemoveAurasDueToSpell((*iter
)->GetId());
436 if (!m_modAuras
[auraType
].empty())
437 next
= m_modAuras
[auraType
].begin();
444 bool Unit::HasAuraType(AuraType auraType
) const
446 return (!m_modAuras
[auraType
].empty());
449 /* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */
450 void Unit::RemoveSpellbyDamageTaken(AuraType auraType
, uint32 damage
)
452 if(!HasAuraType(auraType
))
455 // The chance to dispel an aura depends on the damage taken with respect to the casters level.
456 uint32 max_dmg
= getLevel() > 8 ? 25 * getLevel() - 150 : 50;
457 float chance
= float(damage
) / max_dmg
* 100.0f
;
458 if (roll_chance_f(chance
))
459 RemoveSpellsCausingAura(auraType
);
462 uint32
Unit::DealDamage(Unit
*pVictim
, uint32 damage
, CleanDamage
const* cleanDamage
, DamageEffectType damagetype
, SpellSchoolMask damageSchoolMask
, SpellEntry
const *spellProto
, bool durabilityLoss
)
464 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
467 //You don't lose health from damage taken from another player while in a sanctuary
468 //You still see it in the combat log though
469 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
471 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
472 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) //sanctuary
476 // remove affects from victim (including from 0 damage and DoTs)
478 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
480 // remove affects from attacker at any non-DoT damage (including 0 damage)
481 if( damagetype
!= DOT
)
483 RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
484 RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
487 RemoveSpellsCausingAura(SPELL_AURA_MOD_INVISIBILITY
);
489 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->IsStandState() && !pVictim
->hasUnitState(UNIT_STAT_STUNNED
))
490 pVictim
->SetStandState(PLAYER_STATE_NONE
);
493 //Script Event damage Deal
494 if( GetTypeId()== TYPEID_UNIT
&& ((Creature
*)this)->AI())
495 ((Creature
*)this)->AI()->DamageDeal(pVictim
, damage
);
496 //Script Event damage taken
497 if( pVictim
->GetTypeId()== TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI() )
498 ((Creature
*)pVictim
)->AI()->DamageTaken(this, damage
);
502 // Rage from physical damage received .
503 if(cleanDamage
&& cleanDamage
->damage
&& (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
) && pVictim
->GetTypeId() == TYPEID_PLAYER
&& (pVictim
->getPowerType() == POWER_RAGE
))
504 ((Player
*)pVictim
)->RewardRage(cleanDamage
->damage
, 0, false);
508 if (!spellProto
|| !IsAuraAddedBySpell(SPELL_AURA_MOD_FEAR
, spellProto
->Id
))
509 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_FEAR
, damage
);
510 // root type spells do not dispel the root effect
511 if (!spellProto
|| !(spellProto
->Mechanic
== MECHANIC_ROOT
|| IsAuraAddedBySpell(SPELL_AURA_MOD_ROOT
, spellProto
->Id
)))
512 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_ROOT
, damage
);
514 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
516 // no xp,health if type 8 /critters/
517 if ( pVictim
->GetCreatureType() == CREATURE_TYPE_CRITTER
)
519 pVictim
->setDeathState(JUST_DIED
);
520 pVictim
->SetHealth(0);
522 // allow loot only if has loot_id in creature_template
523 CreatureInfo
const* cInfo
= ((Creature
*)pVictim
)->GetCreatureInfo();
524 if(cInfo
&& cInfo
->lootid
)
525 pVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
527 // some critters required for quests
528 if(GetTypeId() == TYPEID_PLAYER
)
529 ((Player
*)this)->KilledMonster(pVictim
->GetEntry(),pVictim
->GetGUID());
534 if(!pVictim
->isInCombat() && ((Creature
*)pVictim
)->AI())
535 ((Creature
*)pVictim
)->AI()->AttackStart(this);
538 DEBUG_LOG("DealDamageStart");
540 uint32 health
= pVictim
->GetHealth();
541 sLog
.outDetail("deal dmg:%d to health:%d ",damage
,health
);
543 // duel ends when player has 1 or less hp
544 bool duel_hasEnded
= false;
545 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->duel
&& damage
>= (health
-1))
547 // prevent kill only if killed in duel and killed by opponent or opponent controlled creature
548 if(((Player
*)pVictim
)->duel
->opponent
==this || ((Player
*)pVictim
)->duel
->opponent
->GetGUID() == GetOwnerGUID())
551 duel_hasEnded
= true;
554 if(pVictim
!= this && damagetype
!= DOT
)
556 SetInCombatWith(pVictim
);
557 pVictim
->SetInCombatWith(this);
559 if(Player
* attackedPlayer
= pVictim
->GetCharmerOrOwnerPlayerOrPlayerItself())
560 SetContestedPvP(attackedPlayer
);
563 // Rage from Damage made (only from direct weapon damage)
564 if( cleanDamage
&& damagetype
==DIRECT_DAMAGE
&& this != pVictim
&& GetTypeId() == TYPEID_PLAYER
&& (getPowerType() == POWER_RAGE
))
566 uint32 weaponSpeedHitFactor
;
568 switch(cleanDamage
->attackType
)
572 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
573 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 7);
575 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
577 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
583 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
584 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
586 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 1.75f
);
588 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
597 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& GetTypeId() == TYPEID_PLAYER
)
599 if(((Player
*)pVictim
)->InBattleGround())
601 Player
*killer
= ((Player
*)this);
602 if(killer
!= ((Player
*)pVictim
))
603 if(BattleGround
*bg
= killer
->GetBattleGround())
604 bg
->UpdatePlayerScore(killer
, SCORE_DAMAGE_DONE
, damage
);
608 if (pVictim
->GetTypeId() == TYPEID_UNIT
&& !((Creature
*)pVictim
)->isPet() && !((Creature
*)pVictim
)->hasLootRecipient())
609 ((Creature
*)pVictim
)->SetLootRecipient(this);
610 if (health
<= damage
)
612 // battleground things
613 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& (((Player
*)pVictim
)->InBattleGround()))
615 Player
*killed
= ((Player
*)pVictim
);
616 Player
*killer
= NULL
;
617 if(GetTypeId() == TYPEID_PLAYER
)
618 killer
= ((Player
*)this);
619 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
621 Unit
*owner
= GetOwner();
622 if(owner
&& owner
->GetTypeId() == TYPEID_PLAYER
)
623 killer
= ((Player
*)owner
);
627 if(BattleGround
*bg
= killed
->GetBattleGround())
628 bg
->HandleKillPlayer(killed
, killer
); // drop flags and etc
631 DEBUG_LOG("DealDamage: victim just died");
633 // find player: owner of controlled `this` or `this` itself maybe
634 Player
*player
= GetCharmerOrOwnerPlayerOrPlayerItself();
636 if(pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->GetLootRecipient())
637 player
= ((Creature
*)pVictim
)->GetLootRecipient();
638 // Reward player, his pets, and group/raid members
639 // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop)
640 if(player
&& player
!=pVictim
)
642 if(player
->RewardPlayerAndGroupAtKill(pVictim
))
643 player
->ProcDamageAndSpell(pVictim
, PROC_FLAG_KILL_AND_GET_XP
, PROC_FLAG_KILLED
, PROC_EX_NONE
, 0);
645 player
->ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_KILLED
,PROC_EX_NONE
, 0);
648 DEBUG_LOG("DealDamageAttackStop");
651 pVictim
->CombatStop();
652 pVictim
->getHostilRefManager().deleteReferences();
654 bool damageFromSpiritOfRedemtionTalent
= spellProto
&& spellProto
->Id
== 27795;
656 // if talent known but not triggered (check priest class for speedup check)
657 Aura
* spiritOfRedemtionTalentReady
= NULL
;
658 if( !damageFromSpiritOfRedemtionTalent
&& // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION
659 pVictim
->GetTypeId()==TYPEID_PLAYER
&& pVictim
->getClass()==CLASS_PRIEST
)
661 AuraList
const& vDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
662 for(AuraList::const_iterator itr
= vDummyAuras
.begin(); itr
!= vDummyAuras
.end(); ++itr
)
664 if((*itr
)->GetSpellProto()->SpellIconID
==1654)
666 spiritOfRedemtionTalentReady
= *itr
;
672 DEBUG_LOG("SET JUST_DIED");
673 if(!spiritOfRedemtionTalentReady
)
674 pVictim
->setDeathState(JUST_DIED
);
676 DEBUG_LOG("DealDamageHealth1");
678 if(spiritOfRedemtionTalentReady
)
680 // save value before aura remove
681 uint32 ressSpellId
= pVictim
->GetUInt32Value(PLAYER_SELF_RES_SPELL
);
683 ressSpellId
= ((Player
*)pVictim
)->GetResurrectionSpellId();
685 //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers)
686 pVictim
->RemoveAllAurasOnDeath();
688 // restore for use at real death
689 pVictim
->SetUInt32Value(PLAYER_SELF_RES_SPELL
,ressSpellId
);
691 // FORM_SPIRITOFREDEMPTION and related auras
692 pVictim
->CastSpell(pVictim
,27827,true,NULL
,spiritOfRedemtionTalentReady
);
695 pVictim
->SetHealth(0);
697 // remember victim PvP death for corpse type and corpse reclaim delay
698 // at original death (not at SpiritOfRedemtionTalent timeout)
699 if( pVictim
->GetTypeId()==TYPEID_PLAYER
&& !damageFromSpiritOfRedemtionTalent
)
700 ((Player
*)pVictim
)->SetPvPDeath(player
!=NULL
);
702 // Call KilledUnit for creatures
703 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->AI())
704 ((Creature
*)this)->AI()->KilledUnit(pVictim
);
706 // 10% durability loss on death
707 // clean InHateListOf
708 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
710 // only if not player and not controlled by player pet. And not at BG
711 if (durabilityLoss
&& !player
&& !((Player
*)pVictim
)->InBattleGround())
713 DEBUG_LOG("We are dead, loosing 10 percents durability");
714 ((Player
*)pVictim
)->DurabilityLossAll(0.10f
,false);
715 // durability lost message
716 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
717 ((Player
*)pVictim
)->GetSession()->SendPacket(&data
);
720 else // creature died
722 DEBUG_LOG("DealDamageNotPlayer");
723 Creature
*cVictim
= (Creature
*)pVictim
;
725 if(!cVictim
->isPet())
727 cVictim
->DeleteThreatList();
728 cVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
730 // Call creature just died function
732 cVictim
->AI()->JustDied(this);
734 // Dungeon specific stuff, only applies to players killing creatures
735 if(cVictim
->GetInstanceId())
737 Map
*m
= cVictim
->GetMap();
738 Player
*creditedPlayer
= GetCharmerOrOwnerPlayerOrPlayerItself();
739 // TODO: do instance binding anyway if the charmer/owner is offline
741 if(m
->IsDungeon() && creditedPlayer
)
743 if(m
->IsRaid() || m
->IsHeroic())
745 if(cVictim
->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
746 ((InstanceMap
*)m
)->PermBindAllPlayers(creditedPlayer
);
750 // the reset time is set but not added to the scheduler
751 // until the players leave the instance
752 time_t resettime
= cVictim
->GetRespawnTimeEx() + 2 * HOUR
;
753 if(InstanceSave
*save
= sInstanceSaveManager
.GetInstanceSave(cVictim
->GetInstanceId()))
754 if(save
->GetResetTime() < resettime
) save
->SetResetTime(resettime
);
760 // last damage from non duel opponent or opponent controlled creature
763 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
764 Player
*he
= (Player
*)pVictim
;
768 he
->duel
->opponent
->CombatStopWithPets(true);
769 he
->CombatStopWithPets(true);
771 he
->DuelComplete(DUEL_INTERUPTED
);
774 else // if (health <= damage)
776 DEBUG_LOG("DealDamageAlive");
778 pVictim
->ModifyHealth(- (int32
)damage
);
780 if(damagetype
!= DOT
)
784 // if have target and damage pVictim just call AI reaction
785 if(pVictim
!= getVictim() && pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
786 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
790 // if not have main target then attack state with target (including AI call)
791 //start melee attacks only after melee hit
792 Attack(pVictim
,(damagetype
== DIRECT_DAMAGE
));
796 // polymorphed and other negative transformed cases
797 if(pVictim
->getTransForm() && pVictim
->hasUnitState(UNIT_STAT_CONFUSED
))
798 pVictim
->RemoveAurasDueToSpell(pVictim
->getTransForm());
800 if(damagetype
== DIRECT_DAMAGE
|| damagetype
== SPELL_DIRECT_DAMAGE
)
802 if (!spellProto
|| !(spellProto
->AuraInterruptFlags
&AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
))
803 pVictim
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
);
805 if (pVictim
->GetTypeId() != TYPEID_PLAYER
)
807 if(spellProto
&& IsDamageToThreatSpell(spellProto
))
808 pVictim
->AddThreat(this, damage
*2, damageSchoolMask
, spellProto
);
810 pVictim
->AddThreat(this, damage
, damageSchoolMask
, spellProto
);
812 else // victim is a player
814 // Rage from damage received
815 if(this != pVictim
&& pVictim
->getPowerType() == POWER_RAGE
)
817 uint32 rage_damage
= damage
+ (cleanDamage
? cleanDamage
->damage
: 0);
818 ((Player
*)pVictim
)->RewardRage(rage_damage
, 0, false);
821 // random durability for items (HIT TAKEN)
822 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
824 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
825 ((Player
*)pVictim
)->DurabilityPointLossForEquipSlot(slot
);
829 if(GetTypeId()==TYPEID_PLAYER
)
831 // random durability for items (HIT DONE)
832 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
834 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
835 ((Player
*)this)->DurabilityPointLossForEquipSlot(slot
);
839 // TODO: Store auras by interrupt flag to speed this up.
840 AuraMap
& vAuras
= pVictim
->GetAuras();
841 for (AuraMap::iterator i
= vAuras
.begin(), next
; i
!= vAuras
.end(); i
= next
)
843 const SpellEntry
*se
= i
->second
->GetSpellProto();
845 if (spellProto
&& spellProto
->Id
== se
->Id
) // Not drop auras added by self
847 if( se
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_DAMAGE
)
850 if (se
->procFlags
& (1<<3))
852 if (!roll_chance_i(se
->procChance
))
857 pVictim
->RemoveAurasDueToSpell(i
->second
->GetId());
858 // FIXME: this may cause the auras with proc chance to be rerolled several times
859 next
= vAuras
.begin();
864 if (damagetype
!= NODAMAGE
&& damage
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
866 if( damagetype
!= DOT
)
868 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
870 // skip channeled spell (processed differently below)
871 if (i
== CURRENT_CHANNELED_SPELL
)
874 if(Spell
* spell
= pVictim
->m_currentSpells
[i
])
875 if(spell
->getState() == SPELL_STATE_PREPARING
)
880 if(Spell
* spell
= pVictim
->m_currentSpells
[CURRENT_CHANNELED_SPELL
])
882 if (spell
->getState() == SPELL_STATE_CASTING
)
884 uint32 channelInterruptFlags
= spell
->m_spellInfo
->ChannelInterruptFlags
;
885 if( channelInterruptFlags
& CHANNEL_FLAG_DELAY
)
887 if(pVictim
!=this) //don't shorten the duration of channeling if you damage yourself
888 spell
->DelayedChannel();
890 else if( (channelInterruptFlags
& (CHANNEL_FLAG_DAMAGE
| CHANNEL_FLAG_DAMAGE2
)) )
892 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
893 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
896 else if (spell
->getState() == SPELL_STATE_DELAYED
)
897 // break channeled spell in delayed state on damage
899 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
900 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
905 // last damage from duel opponent
908 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
909 Player
*he
= (Player
*)pVictim
;
915 he
->duel
->opponent
->CombatStopWithPets(true);
916 he
->CombatStopWithPets(true);
918 he
->CastSpell(he
, 7267, true); // beg
919 he
->DuelComplete(DUEL_WON
);
923 DEBUG_LOG("DealDamageEnd returned %d damage", damage
);
928 void Unit::CastStop(uint32 except_spellid
)
930 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
931 if (m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
!=except_spellid
)
932 InterruptSpell(i
,false);
935 void Unit::CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
937 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
941 sLog
.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId
,(GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
945 CastSpell(Victim
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
948 void Unit::CastSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
952 sLog
.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
957 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
959 if(!originalCaster
&& triggeredByAura
)
960 originalCaster
= triggeredByAura
->GetCasterGUID();
962 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
964 SpellCastTargets targets
;
965 targets
.setUnitTarget( Victim
);
966 spell
->m_CastItem
= castItem
;
967 spell
->prepare(&targets
, triggeredByAura
);
970 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
972 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
976 sLog
.outError("CastCustomSpell: unknown spell id %i\n", spellId
);
980 CastCustomSpell(Victim
,spellInfo
,bp0
,bp1
,bp2
,triggered
,castItem
,triggeredByAura
, originalCaster
);
983 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
)
987 sLog
.outError("CastCustomSpell: unknown spell");
992 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
994 if(!originalCaster
&& triggeredByAura
)
995 originalCaster
= triggeredByAura
->GetCasterGUID();
997 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1000 spell
->m_currentBasePoints
[0] = *bp0
-int32(spellInfo
->EffectBaseDice
[0]);
1003 spell
->m_currentBasePoints
[1] = *bp1
-int32(spellInfo
->EffectBaseDice
[1]);
1006 spell
->m_currentBasePoints
[2] = *bp2
-int32(spellInfo
->EffectBaseDice
[2]);
1008 SpellCastTargets targets
;
1009 targets
.setUnitTarget( Victim
);
1010 spell
->m_CastItem
= castItem
;
1011 spell
->prepare(&targets
, triggeredByAura
);
1014 // used for scripting
1015 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1017 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
1021 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()));
1025 CastSpell(x
, y
, z
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
1028 // used for scripting
1029 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
1033 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
1038 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
1040 if(!originalCaster
&& triggeredByAura
)
1041 originalCaster
= triggeredByAura
->GetCasterGUID();
1043 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
1045 SpellCastTargets targets
;
1046 targets
.setDestination(x
, y
, z
);
1047 spell
->m_CastItem
= castItem
;
1048 spell
->prepare(&targets
, triggeredByAura
);
1052 void Unit::DealFlatDamage(Unit *pVictim, SpellEntry const *spellInfo, uint32 *damage, CleanDamage *cleanDamage, bool *crit, bool isTriggeredSpell)
1054 // TODO this in only generic way, check for exceptions
1055 DEBUG_LOG("DealFlatDamage (BEFORE) >> DMG:%u", *damage);
1057 // Per-damage class calculation
1058 switch (spellInfo->DmgClass)
1060 // Melee and Ranged Spells
1061 case SPELL_DAMAGE_CLASS_RANGED:
1062 case SPELL_DAMAGE_CLASS_MELEE:
1064 // Calculate physical outcome
1065 MeleeHitOutcome outcome = RollPhysicalOutcomeAgainst(pVictim, BASE_ATTACK, spellInfo);
1067 //Used to store the Hit Outcome
1068 cleanDamage->hitOutCome = outcome;
1070 // Return miss/evade first (sends miss message)
1073 case MELEE_HIT_EVADE:
1075 SendAttackStateUpdate(HITINFO_MISS, pVictim, 1, GetSpellSchoolMask(spellInfo), 0, 0,0,VICTIMSTATE_EVADES,0);
1079 case MELEE_HIT_MISS:
1081 SendAttackStateUpdate(HITINFO_MISS, pVictim, 1, GetSpellSchoolMask(spellInfo), 0, 0,0,VICTIMSTATE_NORMAL,0);
1084 if(GetTypeId()== TYPEID_PLAYER)
1085 ((Player*)this)->UpdateWeaponSkill(BASE_ATTACK);
1087 CastMeleeProcDamageAndSpell(pVictim,0,GetSpellSchoolMask(spellInfo),BASE_ATTACK,MELEE_HIT_MISS,spellInfo,isTriggeredSpell);
1092 // Hitinfo, Victimstate
1093 uint32 hitInfo = HITINFO_NORMALSWING;
1094 VictimState victimState = VICTIMSTATE_NORMAL;
1097 if ( GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NORMAL )
1099 // apply spellmod to Done damage
1100 if(Player* modOwner = GetSpellModOwner())
1101 modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_DAMAGE, *damage);
1103 //Calculate armor mitigation
1104 uint32 damageAfterArmor = CalcArmorReducedDamage(pVictim, *damage);
1106 // random durability for main hand weapon (ABSORB)
1107 if(damageAfterArmor < *damage)
1108 if(pVictim->GetTypeId() == TYPEID_PLAYER)
1109 if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_ABSORB)))
1110 ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EquipmentSlots(urand(EQUIPMENT_SLOT_START,EQUIPMENT_SLOT_BACK)));
1112 cleanDamage->damage += *damage - damageAfterArmor;
1113 *damage = damageAfterArmor;
1118 // Calculate damage bonus
1119 *damage = SpellDamageBonus(pVictim, spellInfo, *damage, SPELL_DIRECT_DAMAGE);
1125 case MELEE_HIT_BLOCK_CRIT:
1126 case MELEE_HIT_CRIT:
1128 uint32 bonusDmg = *damage;
1130 // Apply crit_damage bonus
1131 if(Player* modOwner = GetSpellModOwner())
1132 modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CRIT_DAMAGE_BONUS, bonusDmg);
1134 uint32 creatureTypeMask = pVictim->GetCreatureTypeMask();
1135 AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS);
1136 for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i)
1137 if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue))
1138 bonusDmg = uint32(bonusDmg * ((*i)->GetModifier()->m_amount+100.0f)/100.0f);
1140 *damage += bonusDmg;
1142 // Resilience - reduce crit damage
1143 if (pVictim->GetTypeId()==TYPEID_PLAYER)
1145 uint32 resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(*damage);
1146 cleanDamage->damage += resilienceReduction;
1147 *damage -= resilienceReduction;
1151 hitInfo |= HITINFO_CRITICALHIT;
1153 ModifyAuraState(AURA_STATE_CRIT, true);
1154 StartReactiveTimer( REACTIVE_CRIT );
1156 if(getClass()==CLASS_HUNTER)
1158 ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, true);
1159 StartReactiveTimer( REACTIVE_HUNTER_CRIT );
1162 if ( outcome == MELEE_HIT_BLOCK_CRIT )
1164 uint32 blocked_amount = uint32(pVictim->GetShieldBlockValue());
1165 if (blocked_amount >= *damage)
1167 hitInfo |= HITINFO_SWINGNOHITSOUND;
1168 victimState = VICTIMSTATE_BLOCKS;
1169 cleanDamage->damage += *damage; // To Help Calculate Rage
1174 // To Help Calculate Rage
1175 cleanDamage->damage += blocked_amount;
1176 *damage = *damage - blocked_amount;
1179 pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true);
1180 pVictim->StartReactiveTimer( REACTIVE_DEFENSE );
1182 if(pVictim->GetTypeId() == TYPEID_PLAYER)
1185 ((Player*)pVictim)->UpdateDefense();
1187 // random durability for main hand weapon (BLOCK)
1188 if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK)))
1189 ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND);
1194 case MELEE_HIT_PARRY:
1196 cleanDamage->damage += *damage; // To Help Calculate Rage
1198 victimState = VICTIMSTATE_PARRY;
1200 // Counter-attack ( explained in Unit::DoAttackDamage() )
1201 if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN) )
1203 // Get attack timers
1204 float offtime = float(pVictim->getAttackTimer(OFF_ATTACK));
1205 float basetime = float(pVictim->getAttackTimer(BASE_ATTACK));
1207 // Reduce attack time
1208 if (pVictim->haveOffhandWeapon() && offtime < basetime)
1210 float percent20 = pVictim->GetAttackTime(OFF_ATTACK) * 0.20;
1211 float percent60 = 3 * percent20;
1212 if(offtime > percent20 && offtime <= percent60)
1214 pVictim->setAttackTimer(OFF_ATTACK, uint32(percent20));
1216 else if(offtime > percent60)
1218 offtime -= 2 * percent20;
1219 pVictim->setAttackTimer(OFF_ATTACK, uint32(offtime));
1224 float percent20 = pVictim->GetAttackTime(BASE_ATTACK) * 0.20;
1225 float percent60 = 3 * percent20;
1226 if(basetime > percent20 && basetime <= percent60)
1228 pVictim->setAttackTimer(BASE_ATTACK, uint32(percent20));
1230 else if(basetime > percent60)
1232 basetime -= 2 * percent20;
1233 pVictim->setAttackTimer(BASE_ATTACK, uint32(basetime));
1238 if(pVictim->GetTypeId() == TYPEID_PLAYER)
1240 // Update victim defense ?
1241 ((Player*)pVictim)->UpdateDefense();
1243 // random durability for main hand weapon (PARRY)
1244 if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_PARRY)))
1245 ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_MAINHAND);
1249 pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED);
1251 // Mongoose bite - set only Counterattack here
1252 if (pVictim->getClass() == CLASS_HUNTER)
1254 pVictim->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true);
1255 pVictim->StartReactiveTimer( REACTIVE_HUNTER_PARRY );
1259 pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true);
1260 pVictim->StartReactiveTimer( REACTIVE_DEFENSE );
1264 case MELEE_HIT_DODGE:
1266 if(pVictim->GetTypeId() == TYPEID_PLAYER)
1267 ((Player*)pVictim)->UpdateDefense();
1269 cleanDamage->damage += *damage; // To Help Calculate Rage
1271 hitInfo |= HITINFO_SWINGNOHITSOUND;
1272 victimState = VICTIMSTATE_DODGE;
1275 pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED);
1278 if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR)
1280 ((Player*)this)->AddComboPoints(pVictim, 1);
1281 StartReactiveTimer( REACTIVE_OVERPOWER );
1285 if (pVictim->getClass() != CLASS_ROGUE)
1287 pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true);
1288 pVictim->StartReactiveTimer( REACTIVE_DEFENSE );
1292 case MELEE_HIT_BLOCK:
1294 uint32 blocked_amount = uint32(pVictim->GetShieldBlockValue());
1295 if (blocked_amount >= *damage)
1297 hitInfo |= HITINFO_SWINGNOHITSOUND;
1298 victimState = VICTIMSTATE_BLOCKS;
1299 cleanDamage->damage += *damage; // To Help Calculate Rage
1304 // To Help Calculate Rage
1305 cleanDamage->damage += blocked_amount;
1306 *damage = *damage - blocked_amount;
1309 pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true);
1310 pVictim->StartReactiveTimer( REACTIVE_DEFENSE );
1312 if(pVictim->GetTypeId() == TYPEID_PLAYER)
1315 ((Player*)pVictim)->UpdateDefense();
1317 // random durability for main hand weapon (BLOCK)
1318 if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK)))
1319 ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND);
1323 case MELEE_HIT_EVADE: // already processed early
1324 case MELEE_HIT_MISS: // already processed early
1325 case MELEE_HIT_GLANCING:
1326 case MELEE_HIT_CRUSHING:
1327 case MELEE_HIT_NORMAL:
1331 // do all damage=0 cases here
1333 CastMeleeProcDamageAndSpell(pVictim,0,GetSpellSchoolMask(spellInfo),BASE_ATTACK,outcome,spellInfo,isTriggeredSpell);
1338 case SPELL_DAMAGE_CLASS_NONE:
1339 case SPELL_DAMAGE_CLASS_MAGIC:
1341 // Calculate damage bonus
1342 *damage = SpellDamageBonus(pVictim, spellInfo, *damage, SPELL_DIRECT_DAMAGE);
1344 *crit = isSpellCrit(pVictim, spellInfo, GetSpellSchoolMask(spellInfo), BASE_ATTACK);
1347 *damage = SpellCriticalBonus(spellInfo, *damage, pVictim);
1349 // Resilience - reduce crit damage
1350 if (pVictim && pVictim->GetTypeId()==TYPEID_PLAYER)
1352 uint32 damage_reduction = ((Player *)pVictim)->GetSpellCritDamageReduction(*damage);
1353 if(*damage > damage_reduction)
1354 *damage -= damage_reduction;
1359 cleanDamage->hitOutCome = MELEE_HIT_CRIT;
1361 // spell proc all magic damage==0 case in this function
1365 uint32 procAttacker = PROC_FLAG_HIT_SPELL;
1366 uint32 procVictim = (PROC_FLAG_STRUCK_SPELL|PROC_FLAG_TAKE_DAMAGE);
1368 ProcDamageAndSpell(pVictim, procAttacker, procVictim, 0, GetSpellSchoolMask(spellInfo), spellInfo, isTriggeredSpell);
1375 // TODO this in only generic way, check for exceptions
1376 DEBUG_LOG("DealFlatDamage (AFTER) >> DMG:%u", *damage);
1379 uint32 Unit::SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage, bool isTriggeredSpell, bool useSpellDamage)
1381 if(!this || !pVictim)
1383 if(!isAlive() || !pVictim->isAlive())
1386 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellID);
1390 CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL);
1394 DealFlatDamage(pVictim, spellInfo, &damage, &cleanDamage, &crit, isTriggeredSpell);
1396 // If we actually dealt some damage (spell proc's for 0 damage (normal and magic) called in DealFlatDamage)
1399 // Calculate absorb & resists
1403 CalcAbsorbResist(pVictim,GetSpellSchoolMask(spellInfo), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1405 //No more damage left, target absorbed and/or resisted all damage
1406 if (damage > absorb + resist)
1407 damage -= absorb + resist; //Remove Absorbed and Resisted from damage actually dealt
1410 uint32 HitInfo = HITINFO_SWINGNOHITSOUND;
1413 HitInfo |= HITINFO_ABSORB;
1416 HitInfo |= HITINFO_RESIST;
1417 ProcDamageAndSpell(pVictim, PROC_FLAG_TARGET_RESISTS, PROC_FLAG_RESIST_SPELL, 0, GetSpellSchoolMask(spellInfo), spellInfo,isTriggeredSpell);
1421 SendAttackStateUpdate(HitInfo, pVictim, 1, GetSpellSchoolMask(spellInfo), damage, absorb,resist,VICTIMSTATE_NORMAL,0);
1426 damage = DealDamage(pVictim, damage, &cleanDamage, SPELL_DIRECT_DAMAGE, GetSpellSchoolMask(spellInfo), spellInfo, true);
1429 sLog.outDetail("SpellNonMeleeDamageLog: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u,absorb is %u,resist is %u",
1430 GetGUIDLow(), GetTypeId(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, spellID, absorb,resist);
1432 // Actual log sent to client
1433 SendSpellNonMeleeDamageLog(pVictim, spellID, damage, GetSpellSchoolMask(spellInfo), absorb, resist, false, 0, crit);
1436 uint32 procAttacker = PROC_FLAG_HIT_SPELL;
1437 uint32 procVictim = (PROC_FLAG_STRUCK_SPELL|PROC_FLAG_TAKE_DAMAGE);
1441 procAttacker |= PROC_FLAG_CRIT_SPELL;
1442 procVictim |= PROC_FLAG_STRUCK_CRIT_SPELL;
1445 ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, GetSpellSchoolMask(spellInfo), spellInfo, isTriggeredSpell);
1451 // all spell proc for 0 normal and magic damage called in DealFlatDamage
1454 if(cleanDamage.damage)
1455 // Rage from damage received.
1456 if(pVictim->GetTypeId() == TYPEID_PLAYER && (pVictim->getPowerType() == POWER_RAGE))
1457 ((Player*)pVictim)->RewardRage(cleanDamage.damage, 0, false);
1464 // Obsolete func need remove, here only for comotability vs another patches
1465 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
, bool isTriggeredSpell
, bool useSpellDamage
)
1467 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
1468 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, spellInfo
->SchoolMask
);
1469 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
1470 SendSpellNonMeleeDamageLog(&damageInfo
);
1471 DealSpellDamage(&damageInfo
, true);
1472 return damageInfo
.damage
;
1475 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
1477 SpellSchoolMask damageSchoolMask
= SpellSchoolMask(damageInfo
->schoolMask
);
1478 Unit
*pVictim
= damageInfo
->target
;
1483 if(!this || !pVictim
)
1485 if(!this->isAlive() || !pVictim
->isAlive())
1488 uint32 crTypeMask
= pVictim
->GetCreatureTypeMask();
1489 // Check spell crit chance
1490 bool crit
= isSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
1491 bool blocked
= false;
1493 switch (spellInfo
->DmgClass
)
1495 // Melee and Ranged Spells
1496 case SPELL_DAMAGE_CLASS_RANGED
:
1497 case SPELL_DAMAGE_CLASS_MELEE
:
1500 if ( damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
1502 //Calculate armor mitigation
1503 damage
= CalcArmorReducedDamage(pVictim
, damage
);
1504 // Get blocked status
1505 blocked
= isSpellBlocked(pVictim
, spellInfo
, attackType
);
1510 // Calculate damage bonus
1511 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1515 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1517 // Calculate crit bonus
1518 uint32 crit_bonus
= damage
;
1519 // Apply crit_damage bonus for melee spells
1520 if(Player
* modOwner
= GetSpellModOwner())
1521 modOwner
->ApplySpellMod(spellInfo
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
1522 damage
+= crit_bonus
;
1524 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1525 int32 critPctDamageMod
=0;
1526 if(attackType
== RANGED_ATTACK
)
1527 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1530 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1531 critPctDamageMod
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
);
1533 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1534 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1536 if (critPctDamageMod
!=0)
1537 damage
= int32((damage
) * float((100.0f
+ critPctDamageMod
)/100.0f
));
1539 // Resilience - reduce crit damage
1540 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1541 damage
-= ((Player
*)pVictim
)->GetMeleeCritDamageReduction(damage
);
1543 // Spell weapon based damage CAN BE crit & blocked at same time
1546 damageInfo
->blocked
= uint32(pVictim
->GetShieldBlockValue());
1547 if (damage
< damageInfo
->blocked
)
1548 damageInfo
->blocked
= damage
;
1549 damage
-=damageInfo
->blocked
;
1554 case SPELL_DAMAGE_CLASS_NONE
:
1555 case SPELL_DAMAGE_CLASS_MAGIC
:
1557 // Calculate damage bonus
1558 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1559 // If crit add critical bonus
1562 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1563 damage
= SpellCriticalBonus(spellInfo
, damage
, pVictim
);
1564 // Resilience - reduce crit damage
1565 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1566 damage
-= ((Player
*)pVictim
)->GetSpellCritDamageReduction(damage
);
1572 // Calculate absorb resist
1575 CalcAbsorbResist(pVictim
, damageSchoolMask
, SPELL_DIRECT_DAMAGE
, damage
, &damageInfo
->absorb
, &damageInfo
->resist
);
1576 damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
1580 damageInfo
->damage
= damage
;
1583 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1588 Unit
*pVictim
= damageInfo
->target
;
1590 if(!this || !pVictim
)
1593 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1596 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1597 if (spellProto
== NULL
)
1599 sLog
.outDebug("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1603 //You don't lose health from damage taken from another player while in a sanctuary
1604 //You still see it in the combat log though
1605 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1607 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1608 if(area
&& area
->flags
& 0x800) //sanctuary
1612 // update at damage Judgement aura duration that applied by attacker at victim
1613 if(damageInfo
->damage
&& spellProto
->Id
== 35395)
1615 AuraMap
& vAuras
= pVictim
->GetAuras();
1616 for(AuraMap::iterator itr
= vAuras
.begin(); itr
!= vAuras
.end(); ++itr
)
1618 SpellEntry
const *spellInfo
= (*itr
).second
->GetSpellProto();
1619 if( spellInfo
->AttributesEx3
& 0x40000 && spellInfo
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& ((*itr
).second
->GetCasterGUID() == GetGUID()))
1621 (*itr
).second
->SetAuraDuration((*itr
).second
->GetAuraMaxDuration());
1622 (*itr
).second
->UpdateAuraDuration();
1626 // Call default DealDamage
1627 CleanDamage
cleanDamage(damageInfo
->cleanDamage
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
1628 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->schoolMask
), spellProto
, durabilityLoss
);
1631 //TODO for melee need create structure as in
1632 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1634 damageInfo
->attacker
= this;
1635 damageInfo
->target
= pVictim
;
1636 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1637 damageInfo
->attackType
= attackType
;
1638 damageInfo
->damage
= 0;
1639 damageInfo
->cleanDamage
= 0;
1640 damageInfo
->absorb
= 0;
1641 damageInfo
->resist
= 0;
1642 damageInfo
->blocked_amount
= 0;
1644 damageInfo
->TargetState
= 0;
1645 damageInfo
->HitInfo
= 0;
1646 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1647 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1648 damageInfo
->procEx
= PROC_EX_NONE
;
1649 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1651 if(!this || !pVictim
)
1653 if(!this->isAlive() || !pVictim
->isAlive())
1656 // Select HitInfo/procAttacker/procVictim flag based on attack type
1660 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MILEE_HIT
;
1661 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1662 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1665 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MILEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1666 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1667 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1670 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1671 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1672 damageInfo
->HitInfo
= 0x08;// test
1678 // Physical Immune check
1679 if(damageInfo
->target
->IsImmunedToDamage(SpellSchoolMask(damageInfo
->damageSchoolMask
),true))
1681 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1682 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1684 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1685 damageInfo
->damage
= 0;
1686 damageInfo
->cleanDamage
= 0;
1689 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1690 // Add melee damage bonus
1691 MeleeDamageBonus(damageInfo
->target
, &damage
, damageInfo
->attackType
);
1692 // Calculate armor reduction
1693 damageInfo
->damage
= CalcArmorReducedDamage(damageInfo
->target
, damage
);
1694 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1696 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1698 // Disable parry or dodge for ranged attack
1699 if(damageInfo
->attackType
== RANGED_ATTACK
)
1701 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1702 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1705 switch(damageInfo
->hitOutCome
)
1707 case MELEE_HIT_EVADE
:
1709 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1710 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1712 damageInfo
->procEx
|=PROC_EX_EVADE
;
1713 damageInfo
->damage
= 0;
1714 damageInfo
->cleanDamage
= 0;
1717 case MELEE_HIT_MISS
:
1719 damageInfo
->HitInfo
|= HITINFO_MISS
;
1720 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1722 damageInfo
->procEx
|=PROC_EX_MISS
;
1723 damageInfo
->damage
= 0;
1724 damageInfo
->cleanDamage
= 0;
1727 case MELEE_HIT_NORMAL
:
1728 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1729 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1731 case MELEE_HIT_CRIT
:
1733 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1734 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1736 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1738 damageInfo
->damage
+= damageInfo
->damage
;
1740 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1741 if(damageInfo
->attackType
== RANGED_ATTACK
)
1742 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1745 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1746 mod
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
);
1749 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1751 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1752 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1754 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1756 // Resilience - reduce crit damage
1757 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1759 uint32 resilienceReduction
= ((Player
*)pVictim
)->GetMeleeCritDamageReduction(damageInfo
->damage
);
1760 damageInfo
->damage
-= resilienceReduction
;
1761 damageInfo
->cleanDamage
+= resilienceReduction
;
1765 case MELEE_HIT_PARRY
:
1766 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1767 damageInfo
->procEx
|=PROC_EX_PARRY
;
1768 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1769 damageInfo
->damage
= 0;
1772 case MELEE_HIT_DODGE
:
1773 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1774 damageInfo
->procEx
|=PROC_EX_DODGE
;
1775 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1776 damageInfo
->damage
= 0;
1778 case MELEE_HIT_BLOCK
:
1780 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1781 damageInfo
->procEx
|=PROC_EX_BLOCK
;
1782 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1783 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1785 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1786 damageInfo
->blocked_amount
= damageInfo
->damage
;
1788 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1789 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1792 case MELEE_HIT_GLANCING
:
1794 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1795 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1796 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1797 float reducePercent
= 1.0f
; //damage factor
1798 // calculate base values and mods
1799 float baseLowEnd
= 1.3;
1800 float baseHighEnd
= 1.2;
1801 switch(getClass()) // lowering base values for casters
1813 float maxLowEnd
= 0.6;
1814 switch(getClass()) // upper for melee classes
1818 maxLowEnd
= 0.91; //If the attacker is a melee class then instead the lower value of 0.91
1822 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1823 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1824 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1826 // apply max/min bounds
1827 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1829 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1832 if ( highEnd
< 0.2f
) //high end limits
1834 if ( highEnd
> 0.99f
)
1837 if(lowEnd
> highEnd
) // prevent negative range size
1840 reducePercent
= lowEnd
+ rand_norm() * ( highEnd
- lowEnd
);
1842 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1843 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1846 case MELEE_HIT_CRUSHING
:
1848 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1849 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1850 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1851 // 150% normal damage
1852 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1860 // Calculate absorb resist
1861 if(int32(damageInfo
->damage
) > 0)
1863 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1864 // Calculate absorb & resists
1865 CalcAbsorbResist(damageInfo
->target
, SpellSchoolMask(damageInfo
->damageSchoolMask
), DIRECT_DAMAGE
, damageInfo
->damage
, &damageInfo
->absorb
, &damageInfo
->resist
);
1866 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1867 if (damageInfo
->absorb
)
1869 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1870 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1872 if (damageInfo
->resist
)
1873 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1876 else // Umpossible get negative result but....
1877 damageInfo
->damage
= 0;
1880 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1882 if (damageInfo
==0) return;
1883 Unit
*pVictim
= damageInfo
->target
;
1885 if(!this || !pVictim
)
1888 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1891 //You don't lose health from damage taken from another player while in a sanctuary
1892 //You still see it in the combat log though
1893 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1895 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1896 if(area
&& area
->flags
& 0x800) //sanctuary
1900 // Hmmmm dont like this emotes cloent must by self do all animations
1901 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1902 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1903 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1904 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1906 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1908 // Get attack timers
1909 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1910 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1911 // Reduce attack time
1912 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1914 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20;
1915 float percent60
= 3 * percent20
;
1916 if(offtime
> percent20
&& offtime
<= percent60
)
1918 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1920 else if(offtime
> percent60
)
1922 offtime
-= 2 * percent20
;
1923 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1928 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20;
1929 float percent60
= 3 * percent20
;
1930 if(basetime
> percent20
&& basetime
<= percent60
)
1932 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1934 else if(basetime
> percent60
)
1936 basetime
-= 2 * percent20
;
1937 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1942 // Call default DealDamage
1943 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1944 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->damageSchoolMask
), NULL
, durabilityLoss
);
1946 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1947 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1948 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI
, this) )
1950 // -probability is between 0% and 40%
1952 float Probability
= 20;
1954 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1955 if( pVictim
->getLevel() < 30 )
1956 Probability
= 0.65f
*pVictim
->getLevel()+0.5;
1958 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1959 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1961 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1963 if(Probability
> 40)
1966 if(roll_chance_f(Probability
))
1967 CastSpell(pVictim
, 1604, true);
1970 // update at damage Judgement aura duration that applied by attacker at victim
1971 if(damageInfo
->damage
)
1973 AuraMap
& vAuras
= pVictim
->GetAuras();
1974 for(AuraMap::iterator itr
= vAuras
.begin(); itr
!= vAuras
.end(); ++itr
)
1976 SpellEntry
const *spellInfo
= (*itr
).second
->GetSpellProto();
1977 if( spellInfo
->AttributesEx3
& 0x40000 && spellInfo
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& ((*itr
).second
->GetCasterGUID() == GetGUID()))
1979 (*itr
).second
->SetAuraDuration((*itr
).second
->GetAuraMaxDuration());
1980 (*itr
).second
->UpdateAuraDuration();
1986 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1988 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1990 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
1991 ((Player
*)this)->CastItemCombatSpell(((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
,i
), pVictim
, damageInfo
->attackType
);
1994 // victim's damage shield
1995 std::set
<Aura
*> alreadyDone
;
1996 uint32 removedAuras
= pVictim
->m_removedAuras
;
1997 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1998 for(AuraList::const_iterator i
= vDamageShields
.begin(), next
= vDamageShields
.begin(); i
!= vDamageShields
.end(); i
= next
)
2001 if (alreadyDone
.find(*i
) == alreadyDone
.end())
2003 alreadyDone
.insert(*i
);
2004 uint32 damage
=(*i
)->GetModifier()->m_amount
;
2005 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry((*i
)->GetId());
2008 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
2011 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
2012 //damage-=absorb + resist;
2014 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4));
2015 data
<< uint64(pVictim
->GetGUID());
2016 data
<< uint64(GetGUID());
2017 data
<< uint32(spellProto
->SchoolMask
);
2018 data
<< uint32(damage
);
2019 pVictim
->SendMessageToSet(&data
, true );
2021 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(spellProto
), spellProto
, true);
2023 if (pVictim
->m_removedAuras
> removedAuras
)
2025 removedAuras
= pVictim
->m_removedAuras
;
2026 next
= vDamageShields
.begin();
2034 void Unit::HandleEmoteCommand(uint32 anim_id
)
2036 WorldPacket
data( SMSG_EMOTE
, 12 );
2037 data
<< anim_id
<< GetGUID();
2038 WPAssert(data
.size() == 12);
2040 SendMessageToSet(&data
, true);
2043 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
2045 uint32 newdamage
= 0;
2046 float armor
= pVictim
->GetArmor();
2047 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
2048 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
2050 if (armor
<0.0f
) armor
=0.0f
;
2052 float tmpvalue
= 0.0f
;
2053 if(getLevel() <= 59) //Level 1-59
2054 tmpvalue
= armor
/ (armor
+ 400.0f
+ 85.0f
* getLevel());
2055 else if(getLevel() < 70) //Level 60-69
2056 tmpvalue
= armor
/ (armor
- 22167.5f
+ 467.5f
* getLevel());
2058 tmpvalue
= armor
/ (armor
+ 10557.5f
);
2062 if(tmpvalue
> 0.75f
)
2064 newdamage
= uint32(damage
- (damage
* tmpvalue
));
2066 return (newdamage
> 1) ? newdamage
: 1;
2069 void Unit::CalcAbsorbResist(Unit
*pVictim
,SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
)
2071 if(!pVictim
|| !pVictim
->isAlive() || !damage
)
2074 // Magic damage, check for resists
2075 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
2077 // Get base victim resistance for school
2078 float tmpvalue2
= (float)pVictim
->GetResistance(GetFirstSchoolInMask(schoolMask
));
2079 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
2080 tmpvalue2
+= (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
2082 tmpvalue2
*= (float)(0.15f
/ getLevel());
2083 if (tmpvalue2
< 0.0f
)
2085 if (tmpvalue2
> 0.75f
)
2087 uint32 ran
= urand(0, 100);
2088 uint32 faq
[4] = {24,6,4,6};
2091 for (uint8 i
= 0; i
< 4; i
++)
2093 Binom
+= 2400 *( powf(tmpvalue2
, i
) * powf( (1-tmpvalue2
), (4-i
)))/faq
[i
];
2099 if (damagetype
== DOT
&& m
== 4)
2100 *resist
+= uint32(damage
- 1);
2102 *resist
+= uint32(damage
* m
/ 4);
2103 if(*resist
> damage
)
2109 int32 RemainingDamage
= damage
- *resist
;
2111 // absorb without mana cost
2112 int32 reflectDamage
= 0;
2113 Aura
* reflectAura
= NULL
;
2114 AuraList
const& vSchoolAbsorb
= pVictim
->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
2115 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(), next
; i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; i
= next
)
2119 if (((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2123 if((*i
)->GetSpellProto()->SpellFamilyName
==SPELLFAMILY_ROGUE
&& (*i
)->GetSpellProto()->SpellIconID
== 2109)
2125 if (((Player
*)pVictim
)->HasSpellCooldown(31231))
2127 if (pVictim
->GetHealth() <= RemainingDamage
)
2129 int32 chance
= (*i
)->GetModifier()->m_amount
;
2130 if (roll_chance_i(chance
))
2132 pVictim
->CastSpell(pVictim
,31231,true);
2133 ((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;
2143 int32 currentAbsorb
;
2146 if ((pVictim
!= this) && (*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_PRIEST
&& (*i
)->GetSpellProto()->SpellFamilyFlags
== 0x1)
2148 if(Unit
* caster
= (*i
)->GetCaster())
2150 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
2151 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
2153 switch((*k
)->GetModifier()->m_miscvalue
)
2155 case 5065: // Rank 1
2156 case 5064: // Rank 2
2157 case 5063: // Rank 3
2158 case 5062: // Rank 4
2159 case 5061: // Rank 5
2161 if(RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2162 reflectDamage
= (*i
)->GetModifier()->m_amount
* (*k
)->GetModifier()->m_amount
/100;
2164 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
2177 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2179 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2180 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
2181 next
= vSchoolAbsorb
.begin();
2185 currentAbsorb
= RemainingDamage
;
2186 (*i
)->GetModifier()->m_amount
-= RemainingDamage
;
2189 RemainingDamage
-= currentAbsorb
;
2191 // do not cast spells while looping auras; auras can get invalid otherwise
2193 pVictim
->CastCustomSpell(this, 33619, &reflectDamage
, NULL
, NULL
, true, NULL
, reflectAura
);
2195 // absorb by mana cost
2196 AuraList
const& vManaShield
= pVictim
->GetAurasByType(SPELL_AURA_MANA_SHIELD
);
2197 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
2201 // check damage school mask
2202 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2205 int32 currentAbsorb
;
2206 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2207 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2209 currentAbsorb
= RemainingDamage
;
2211 float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()];
2212 if(Player
*modOwner
= GetSpellModOwner())
2213 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
2215 int32 maxAbsorb
= int32(pVictim
->GetPower(POWER_MANA
) / manaMultiplier
);
2216 if (currentAbsorb
> maxAbsorb
)
2217 currentAbsorb
= maxAbsorb
;
2219 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
2220 if((*i
)->GetModifier()->m_amount
<= 0)
2222 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
2223 next
= vManaShield
.begin();
2226 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
2227 pVictim
->ApplyPowerMod(POWER_MANA
, manaReduction
, false);
2229 RemainingDamage
-= currentAbsorb
;
2232 // only split damage if not damaging yourself
2235 AuraList
const& vSplitDamageFlat
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
2236 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
2240 // check damage school mask
2241 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2244 // Damage can be splitted only if aura has an alive caster
2245 Unit
*caster
= (*i
)->GetCaster();
2246 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
2249 int32 currentAbsorb
;
2250 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
2251 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
2253 currentAbsorb
= RemainingDamage
;
2255 RemainingDamage
-= currentAbsorb
;
2257 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, currentAbsorb
, schoolMask
, 0, 0, false, 0, false);
2259 CleanDamage cleanDamage
= CleanDamage(currentAbsorb
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2260 DealDamage(caster
, currentAbsorb
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2263 AuraList
const& vSplitDamagePct
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
2264 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
2268 // check damage school mask
2269 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
2272 // Damage can be splitted only if aura has an alive caster
2273 Unit
*caster
= (*i
)->GetCaster();
2274 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
2277 int32 splitted
= int32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
2279 RemainingDamage
-= splitted
;
2281 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, 0, 0, false, 0, false);
2283 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
2284 DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
2288 *absorb
= damage
- RemainingDamage
- *resist
;
2292 void Unit::DoAttackDamage (Unit *pVictim, uint32 *damage, CleanDamage *cleanDamage, uint32 *blocked_amount, SpellSchoolMask damageSchoolMask, uint32 *hitInfo, VictimState *victimState, uint32 *absorbDamage, uint32 *resistDamage, WeaponAttackType attType, SpellEntry const *spellCasted, bool isTriggeredSpell)
2294 MeleeHitOutcome outcome;
2296 // If is casted Melee spell, calculate like physical
2298 outcome = RollMeleeOutcomeAgainst (pVictim, attType);
2300 outcome = RollPhysicalOutcomeAgainst (pVictim, attType, spellCasted);
2302 if(outcome == MELEE_HIT_MISS ||outcome == MELEE_HIT_DODGE ||outcome == MELEE_HIT_BLOCK ||outcome == MELEE_HIT_PARRY)
2303 pVictim->AddThreat(this, 0.0f);
2306 case MELEE_HIT_EVADE:
2308 *hitInfo |= HITINFO_MISS;
2310 cleanDamage->damage = 0;
2313 case MELEE_HIT_MISS:
2315 *hitInfo |= HITINFO_MISS;
2317 cleanDamage->damage = 0;
2318 if(GetTypeId()== TYPEID_PLAYER)
2319 ((Player*)this)->UpdateWeaponSkill(attType);
2324 /// If this is a creature and it attacks from behind it has a probability to daze it's victim
2325 if( (outcome==MELEE_HIT_CRIT || outcome==MELEE_HIT_CRUSHING || outcome==MELEE_HIT_NORMAL || outcome==MELEE_HIT_GLANCING) &&
2326 GetTypeId() != TYPEID_PLAYER && !((Creature*)this)->GetCharmerOrOwnerGUID() && !pVictim->HasInArc(M_PI, this) )
2328 // -probability is between 0% and 40%
2330 float Probability = 20;
2332 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
2333 if( pVictim->getLevel() < 30 )
2334 Probability = 0.65f*pVictim->getLevel()+0.5;
2336 uint32 VictimDefense=pVictim->GetDefenseSkillValue(this);
2337 uint32 AttackerMeleeSkill=GetUnitMeleeSkill(pVictim);
2339 Probability *= AttackerMeleeSkill/(float)VictimDefense;
2341 if(Probability > 40.0f)
2342 Probability = 40.0f;
2344 if(roll_chance_f(Probability))
2345 CastSpell(pVictim, 1604, true);
2348 //Calculate the damage after armor mitigation if SPELL_SCHOOL_NORMAL
2349 if (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL)
2351 uint32 damageAfterArmor = CalcArmorReducedDamage(pVictim, *damage);
2353 // random durability for main hand weapon (ABSORB)
2354 if(damageAfterArmor < *damage)
2355 if(pVictim->GetTypeId() == TYPEID_PLAYER)
2356 if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_ABSORB)))
2357 ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EquipmentSlots(urand(EQUIPMENT_SLOT_START,EQUIPMENT_SLOT_BACK)));
2359 cleanDamage->damage += *damage - damageAfterArmor;
2360 *damage = damageAfterArmor;
2363 if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && pVictim->GetCreatureType() != CREATURE_TYPE_CRITTER )
2364 ((Player*)this)->UpdateCombatSkills(pVictim, attType, outcome, false);
2366 if(GetTypeId() != TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER)
2367 ((Player*)pVictim)->UpdateCombatSkills(this, attType, outcome, true);
2371 case MELEE_HIT_BLOCK_CRIT:
2372 case MELEE_HIT_CRIT:
2376 *hitInfo = HITINFO_CRITICALHIT | HITINFO_NORMALSWING2 | 0x8;
2380 crit_bonus = *damage;
2382 // Apply crit_damage bonus for melee spells
2385 if(Player* modOwner = GetSpellModOwner())
2386 modOwner->ApplySpellMod(spellCasted->Id, SPELLMOD_CRIT_DAMAGE_BONUS, crit_bonus);
2388 uint32 creatureTypeMask = pVictim->GetCreatureTypeMask();
2389 AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS);
2390 for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i)
2391 if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue))
2392 crit_bonus = uint32(crit_bonus * ((*i)->GetModifier()->m_amount+100.0f)/100.0f);
2395 *damage += crit_bonus;
2397 uint32 resilienceReduction = 0;
2399 if(attType == RANGED_ATTACK)
2401 int32 mod = pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE);
2402 *damage = int32((*damage) * float((100.0f + mod)/100.0f));
2403 // Resilience - reduce crit damage
2404 if (pVictim->GetTypeId()==TYPEID_PLAYER)
2405 resilienceReduction = ((Player*)pVictim)->GetRangedCritDamageReduction(*damage);
2409 int32 mod = pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE);
2410 mod += GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE);
2411 *damage = int32((*damage) * float((100.0f + mod)/100.0f));
2412 // Resilience - reduce crit damage
2413 if (pVictim->GetTypeId()==TYPEID_PLAYER)
2414 resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(*damage);
2417 *damage -= resilienceReduction;
2418 cleanDamage->damage += resilienceReduction;
2420 if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && pVictim->GetCreatureType() != CREATURE_TYPE_CRITTER )
2421 ((Player*)this)->UpdateWeaponSkill(attType);
2423 ModifyAuraState(AURA_STATE_CRIT, true);
2424 StartReactiveTimer( REACTIVE_CRIT );
2426 if(getClass()==CLASS_HUNTER)
2428 ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, true);
2429 StartReactiveTimer( REACTIVE_HUNTER_CRIT );
2432 if ( outcome == MELEE_HIT_BLOCK_CRIT )
2434 *blocked_amount = pVictim->GetShieldBlockValue();
2436 if (pVictim->GetUnitBlockChance())
2437 pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD);
2439 pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED);
2441 //Only set VICTIMSTATE_BLOCK on a full block
2442 if (*blocked_amount >= uint32(*damage))
2444 *victimState = VICTIMSTATE_BLOCKS;
2445 *blocked_amount = uint32(*damage);
2448 if(pVictim->GetTypeId() == TYPEID_PLAYER)
2451 ((Player*)pVictim)->UpdateDefense();
2453 // random durability for main hand weapon (BLOCK)
2454 if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK)))
2455 ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND);
2458 pVictim->ModifyAuraState(AURA_STATE_DEFENSE,true);
2459 pVictim->StartReactiveTimer( REACTIVE_DEFENSE );
2463 pVictim->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL);
2466 case MELEE_HIT_PARRY:
2468 if(attType == RANGED_ATTACK) //range attack - no parry
2470 outcome = MELEE_HIT_NORMAL;
2474 cleanDamage->damage += *damage;
2476 *victimState = VICTIMSTATE_PARRY;
2478 // instant (maybe with small delay) counter attack
2480 float offtime = float(pVictim->getAttackTimer(OFF_ATTACK));
2481 float basetime = float(pVictim->getAttackTimer(BASE_ATTACK));
2483 // after parry nearest next attack time will reduced at %40 from full attack time.
2484 // The delay cannot be reduced to less than 20% of your weapon base swing delay.
2485 if (pVictim->haveOffhandWeapon() && offtime < basetime)
2487 float percent20 = pVictim->GetAttackTime(OFF_ATTACK)*0.20;
2488 float percent60 = 3*percent20;
2489 // set to 20% if in range 20%...20+40% of full time
2490 if(offtime > percent20 && offtime <= percent60)
2492 pVictim->setAttackTimer(OFF_ATTACK,uint32(percent20));
2494 // decrease at %40 from full time
2495 else if(offtime > percent60)
2497 offtime -= 2*percent20;
2498 pVictim->setAttackTimer(OFF_ATTACK,uint32(offtime));
2504 float percent20 = pVictim->GetAttackTime(BASE_ATTACK)*0.20;
2505 float percent60 = 3*percent20;
2506 // set to 20% if in range 20%...20+40% of full time
2507 if(basetime > percent20 && basetime <= percent60)
2509 pVictim->setAttackTimer(BASE_ATTACK,uint32(percent20));
2511 // decrease at %40 from full time
2512 else if(basetime > percent60)
2514 basetime -= 2*percent20;
2515 pVictim->setAttackTimer(BASE_ATTACK,uint32(basetime));
2521 if(pVictim->GetTypeId() == TYPEID_PLAYER)
2523 // Update victim defense ?
2524 ((Player*)pVictim)->UpdateDefense();
2526 // random durability for main hand weapon (PARRY)
2527 if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_PARRY)))
2528 ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_MAINHAND);
2531 pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED);
2533 if (pVictim->getClass() == CLASS_HUNTER)
2535 pVictim->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true);
2536 pVictim->StartReactiveTimer( REACTIVE_HUNTER_PARRY );
2540 pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true);
2541 pVictim->StartReactiveTimer( REACTIVE_DEFENSE );
2544 CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell);
2547 case MELEE_HIT_DODGE:
2549 if(attType == RANGED_ATTACK) //range attack - no dodge
2551 outcome = MELEE_HIT_NORMAL;
2555 cleanDamage->damage += *damage;
2557 *victimState = VICTIMSTATE_DODGE;
2559 if(pVictim->GetTypeId() == TYPEID_PLAYER)
2560 ((Player*)pVictim)->UpdateDefense();
2562 pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED);
2564 if (pVictim->getClass() != CLASS_ROGUE) // Riposte
2566 pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true);
2567 pVictim->StartReactiveTimer( REACTIVE_DEFENSE );
2571 if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR)
2573 ((Player*)this)->AddComboPoints(pVictim, 1);
2574 StartReactiveTimer( REACTIVE_OVERPOWER );
2577 CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell);
2580 case MELEE_HIT_BLOCK:
2582 *blocked_amount = pVictim->GetShieldBlockValue();
2584 if (pVictim->GetUnitBlockChance())
2585 pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD);
2587 pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED);
2589 //Only set VICTIMSTATE_BLOCK on a full block
2590 if (*blocked_amount >= uint32(*damage))
2592 *victimState = VICTIMSTATE_BLOCKS;
2593 *blocked_amount = uint32(*damage);
2596 if(pVictim->GetTypeId() == TYPEID_PLAYER)
2599 ((Player*)pVictim)->UpdateDefense();
2601 // random durability for main hand weapon (BLOCK)
2602 if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK)))
2603 ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND);
2606 pVictim->ModifyAuraState(AURA_STATE_DEFENSE,true);
2607 pVictim->StartReactiveTimer( REACTIVE_DEFENSE );
2611 case MELEE_HIT_GLANCING:
2613 float reducePercent = 1.0f; //damage factor
2615 // calculate base values and mods
2616 float baseLowEnd = 1.3;
2617 float baseHighEnd = 1.2;
2618 switch(getClass()) // lowering base values for casters
2630 float maxLowEnd = 0.6;
2631 switch(getClass()) // upper for melee classes
2635 maxLowEnd = 0.91; //If the attacker is a melee class then instead the lower value of 0.91
2639 int32 diff = int32(pVictim->GetDefenseSkillValue(this)) - int32(GetWeaponSkillValue(attType,pVictim));
2640 float lowEnd = baseLowEnd - ( 0.05f * diff );
2641 float highEnd = baseHighEnd - ( 0.03f * diff );
2643 // apply max/min bounds
2644 if ( lowEnd < 0.01f ) //the low end must not go bellow 0.01f
2646 else if ( lowEnd > maxLowEnd ) //the smaller value of this and 0.6 is kept as the low end
2649 if ( highEnd < 0.2f ) //high end limits
2651 if ( highEnd > 0.99f )
2654 if(lowEnd > highEnd) // prevent negative range size
2657 reducePercent = lowEnd + rand_norm() * ( highEnd - lowEnd );
2659 *damage = uint32(reducePercent * *damage);
2660 cleanDamage->damage += *damage;
2661 *hitInfo |= HITINFO_GLANCING;
2664 case MELEE_HIT_CRUSHING:
2666 // 150% normal damage
2667 *damage += (*damage / 2);
2668 cleanDamage->damage = *damage;
2669 *hitInfo |= HITINFO_CRUSHING;
2670 // TODO: victimState, victim animation?
2677 // apply melee damage bonus and absorb only if base damage not fully blocked to prevent negative damage or damage with full block
2678 if(*victimState != VICTIMSTATE_BLOCKS)
2680 MeleeDamageBonus(pVictim, damage,attType,spellCasted);
2681 CalcAbsorbResist(pVictim, damageSchoolMask, DIRECT_DAMAGE, *damage-*blocked_amount, absorbDamage, resistDamage);
2684 if (*absorbDamage) *hitInfo |= HITINFO_ABSORB;
2685 if (*resistDamage) *hitInfo |= HITINFO_RESIST;
2687 cleanDamage->damage += *blocked_amount;
2689 if (*damage <= *absorbDamage + *resistDamage + *blocked_amount)
2691 //*hitInfo = 0x00010020;
2692 //*hitInfo |= HITINFO_SWINGNOHITSOUND;
2694 CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell);
2698 // update at damage Judgement aura duration that applied by attacker at victim
2701 AuraMap const& vAuras = pVictim->GetAuras();
2702 for(AuraMap::const_iterator itr = vAuras.begin(); itr != vAuras.end(); ++itr)
2704 SpellEntry const *spellInfo = (*itr).second->GetSpellProto();
2705 if( (spellInfo->AttributesEx3 & 0x40000) && spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN &&
2706 ((*itr).second->GetCasterGUID() == GetGUID() && (!spellCasted || spellCasted->Id == 35395)) )
2708 (*itr).second->SetAuraDuration((*itr).second->GetAuraMaxDuration());
2709 (*itr).second->UpdateAuraDuration();
2714 CastMeleeProcDamageAndSpell(pVictim, (*damage - *absorbDamage - *resistDamage - *blocked_amount), damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell);
2716 // victim's damage shield
2717 // yet another hack to fix crashes related to the aura getting removed during iteration
2718 std::set<Aura*> alreadyDone;
2719 uint32 removedAuras = pVictim->m_removedAuras;
2720 AuraList const& vDamageShields = pVictim->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD);
2721 for(AuraList::const_iterator i = vDamageShields.begin(), next = vDamageShields.begin(); i != vDamageShields.end(); i = next)
2724 if (alreadyDone.find(*i) == alreadyDone.end())
2726 alreadyDone.insert(*i);
2727 pVictim->SpellNonMeleeDamageLog(this, (*i)->GetId(), (*i)->GetModifier()->m_amount, false, false);
2728 if (pVictim->m_removedAuras > removedAuras)
2730 removedAuras = pVictim->m_removedAuras;
2731 next = vDamageShields.begin();
2737 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
2739 if(hasUnitState(UNIT_STAT_CONFUSED
| UNIT_STAT_STUNNED
| UNIT_STAT_FLEEING
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
2742 if (!pVictim
->isAlive())
2745 if(IsNonMeleeSpellCasted(false))
2749 if (attType
== BASE_ATTACK
)
2750 hitInfo
= HITINFO_NORMALSWING2
;
2751 else if (attType
== OFF_ATTACK
)
2752 hitInfo
= HITINFO_LEFTSWING
;
2754 return; // ignore ranged case
2756 uint32 extraAttacks
= m_extraAttacks
;
2758 // melee attack spell casted at main hand attack only
2759 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
2761 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
2763 // not recent extra attack only at any non extra attack (melee spell case)
2764 if(!extra
&& extraAttacks
)
2766 while(m_extraAttacks
)
2768 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2769 if(m_extraAttacks
> 0)
2777 CalcDamageInfo damageInfo
;
2778 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
2779 // Send log damage message to client
2780 SendAttackStateUpdate(&damageInfo
);
2781 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
2782 DealMeleeDamage(&damageInfo
,true);
2784 if (GetTypeId() == TYPEID_PLAYER
)
2785 DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2786 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2788 DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
2789 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
2791 // extra attack only at any non extra attack (normal case)
2792 if(!extra
&& extraAttacks
)
2794 while(m_extraAttacks
)
2796 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2797 if(m_extraAttacks
> 0)
2804 MeleeHitOutcome Unit::RollPhysicalOutcomeAgainst (Unit const *pVictim, WeaponAttackType attType, SpellEntry const *spellInfo)
2806 // Miss chance based on melee
2807 float miss_chance = MeleeMissChanceCalc(pVictim, attType);
2809 // Critical hit chance
2810 float crit_chance = GetUnitCriticalChance(attType, pVictim);
2811 // this is to avoid compiler issue when declaring variables inside if
2812 float block_chance, parry_chance, dodge_chance;
2814 // cannot be dodged/parried/blocked
2815 if(spellInfo->Attributes & SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK)
2817 block_chance = 0.0f;
2818 parry_chance = 0.0f;
2819 dodge_chance = 0.0f;
2823 // parry can be avoided only by some abilities
2824 parry_chance = pVictim->GetUnitParryChance();
2825 // block might be bypassed by it as well
2826 block_chance = pVictim->GetUnitBlockChance();
2827 // stunned target cannot dodge and this is check in GetUnitDodgeChance()
2828 dodge_chance = pVictim->GetUnitDodgeChance();
2831 // Only players can have Talent&Spell bonuses
2832 if (GetTypeId() == TYPEID_PLAYER)
2834 // Increase from SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL aura
2835 crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, spellInfo->SchoolMask);
2837 if( dodge_chance != 0.0f ) // if dodge chance is already 0, ignore talents for speed
2839 AuraList const& mCanNotBeDodge = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2840 for(AuraList::const_iterator i = mCanNotBeDodge.begin(); i != mCanNotBeDodge.end(); ++i)
2842 // can't be dodged rogue finishing move
2843 if((*i)->GetModifier()->m_miscvalue == VICTIMSTATE_DODGE)
2845 if(spellInfo->SpellFamilyName==SPELLFAMILY_ROGUE && (spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE))
2847 dodge_chance = 0.0f;
2856 if(Player* modOwner = GetSpellModOwner())
2857 modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance);
2859 DEBUG_LOG("PHYSICAL OUTCOME: miss %f crit %f dodge %f parry %f block %f",miss_chance,crit_chance,dodge_chance,parry_chance, block_chance);
2861 return RollMeleeOutcomeAgainst(pVictim, attType, int32(crit_chance*100), int32(miss_chance*100),int32(dodge_chance*100),int32(parry_chance*100),int32(block_chance*100), true);
2864 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
2866 // This is only wrapper
2868 // Miss chance based on melee
2869 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
2871 // Critical hit chance
2872 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
2874 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
2875 float dodge_chance
= pVictim
->GetUnitDodgeChance();
2876 float block_chance
= pVictim
->GetUnitBlockChance();
2877 float parry_chance
= pVictim
->GetUnitParryChance();
2879 // Useful if want to specify crit & miss chances for melee, else it could be removed
2880 DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance
,crit_chance
,dodge_chance
,parry_chance
,block_chance
);
2882 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100), false);
2885 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
, bool SpellCasted
) const
2887 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2888 return MELEE_HIT_EVADE
;
2890 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
2891 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
2893 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
2894 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
2896 // bonus from skills is 0.04%
2897 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
2898 int32 skillBonus2
= 4 * ( attackerMaxSkillValueForLevel
- victimDefenseSkill
);
2899 int32 sum
= 0, tmp
= 0;
2900 int32 roll
= urand (0, 10000);
2902 DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
2903 DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
2904 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
2908 if (tmp
> 0 && roll
< (sum
+= tmp
))
2910 DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS");
2911 return MELEE_HIT_MISS
;
2914 // always crit against a sitting target (except 0 crit chance)
2915 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
2917 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)");
2918 return MELEE_HIT_CRIT
;
2923 // only players can't dodge if attacker is behind
2924 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI
,this))
2926 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
2930 // Reduce dodge chance by attacker expertise rating
2931 if (GetTypeId() == TYPEID_PLAYER
)
2932 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2934 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2935 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2938 if ( (tmp
> 0) // check if unit _can_ dodge
2939 && ((tmp
-= skillBonus
) > 0)
2940 && roll
< (sum
+= tmp
))
2942 DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
2943 return MELEE_HIT_DODGE
;
2947 // parry & block chances
2949 // check if attack comes from behind, nobody can parry or block if attacker is behind
2950 if (!pVictim
->HasInArc(M_PI
,this))
2952 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind.");
2956 // Reduce parry chance by attacker expertise rating
2957 if (GetTypeId() == TYPEID_PLAYER
)
2958 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2960 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
2962 int32 tmp
= int32(parry_chance
);
2963 if ( (tmp
> 0) // check if unit _can_ parry
2964 && ((tmp
-= skillBonus
) > 0)
2965 && (roll
< (sum
+= tmp
)))
2967 DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp
, sum
);
2968 return MELEE_HIT_PARRY
;
2972 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
2975 if ( (tmp
> 0) // check if unit _can_ block
2976 && ((tmp
-= skillBonus
) > 0)
2977 && (roll
< (sum
+= tmp
)))
2980 tmp
= crit_chance
+ skillBonus2
;
2981 if ( GetTypeId() == TYPEID_PLAYER
&& SpellCasted
&& tmp
> 0 )
2983 if ( roll_chance_i(tmp
/100))
2985 DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCKED CRIT");
2986 return MELEE_HIT_BLOCK_CRIT
;
2989 DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
2990 return MELEE_HIT_BLOCK
;
2996 tmp
= crit_chance
+ skillBonus2
;
2998 if (tmp
> 0 && roll
< (sum
+= tmp
))
3000 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
3001 return MELEE_HIT_CRIT
;
3004 // 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)
3005 if( attType
!= RANGED_ATTACK
&& !SpellCasted
&&
3006 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
3007 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
3008 getLevel() < pVictim
->getLevelForTarget(this) )
3010 // cap possible value (with bonuses > max skill)
3011 int32 skill
= attackerWeaponSkill
;
3012 int32 maxskill
= attackerMaxSkillValueForLevel
;
3013 skill
= (skill
> maxskill
) ? maxskill
: skill
;
3015 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
3016 tmp
= tmp
> 4000 ? 4000 : tmp
;
3017 if (roll
< (sum
+= tmp
))
3019 DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
3020 return MELEE_HIT_GLANCING
;
3024 if(GetTypeId()!=TYPEID_PLAYER
&& !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) && !((Creature
*)this)->isPet() )
3026 // mobs can score crushing blows if they're 3 or more levels above victim
3027 // or when their weapon skill is 15 or more above victim's defense skill
3028 tmp
= victimDefenseSkill
;
3029 int32 tmpmax
= victimMaxSkillValueForLevel
;
3030 // having defense above your maximum (from items, talents etc.) has no effect
3031 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
3032 // tmp = mob's level * 5 - player's current defense skill
3033 tmp
= attackerMaxSkillValueForLevel
- tmp
;
3036 // add 2% chance per lacking skill point, min. is 15%
3037 tmp
= tmp
* 200 - 1500;
3038 if (roll
< (sum
+= tmp
))
3040 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
3041 return MELEE_HIT_CRUSHING
;
3046 DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL");
3047 return MELEE_HIT_NORMAL
;
3050 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
3052 float min_damage
, max_damage
;
3054 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
3055 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
3061 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
3062 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
3065 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
3066 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
3069 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
3070 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
3072 // Just for good manner
3080 if (min_damage
> max_damage
)
3082 std::swap(min_damage
,max_damage
);
3085 if(max_damage
== 0.0f
)
3088 return urand((uint32
)min_damage
, (uint32
)max_damage
);
3091 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
3093 if(spellProto
->spellLevel
<= 0)
3096 float LvlPenalty
= 0.0f
;
3098 if(spellProto
->spellLevel
< 20)
3099 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
3100 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
3101 if(LvlFactor
> 1.0f
)
3104 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
3107 void Unit::SendAttackStart(Unit
* pVictim
)
3109 WorldPacket
data( SMSG_ATTACKSTART
, 16 );
3111 data
<< pVictim
->GetGUID();
3113 SendMessageToSet(&data
, true);
3114 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
3117 void Unit::SendAttackStop(Unit
* victim
)
3122 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
3123 data
.append(GetPackGUID());
3124 data
.append(victim
->GetPackGUID()); // can be 0x00...
3125 data
<< uint32(0); // can be 0x1
3126 SendMessageToSet(&data
, true);
3127 sLog
.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER
? "player" : "creature"), GetGUIDLow(), (victim
->GetTypeId()==TYPEID_PLAYER
? "player" : "creature"),victim
->GetGUIDLow());
3129 /*if(victim->GetTypeId() == TYPEID_UNIT)
3130 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
3133 bool Unit::isSpellBlocked(Unit
*pVictim
, SpellEntry
const *spellProto
, WeaponAttackType attackType
)
3135 if (pVictim
->HasInArc(M_PI
,this))
3137 float blockChance
= GetUnitBlockChance();
3138 blockChance
+= (GetWeaponSkillValue(attackType
) - pVictim
->GetMaxSkillValueForLevel() )*0.04;
3139 if (roll_chance_f(blockChance
))
3145 // Melee based spells can be miss, parry or dodge on this step
3146 // Crit or block - determined on damage calculation phase! (and can be both in some time)
3147 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
3149 // Calculate hit chance (more correct for chance mod)
3152 // PvP - PvE melee chances
3153 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
3154 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
3156 HitChance
= 95 - leveldif
;
3158 HitChance
= 93 - (leveldif
- 2) * lchance
;
3160 // Hit chance depends from victim auras
3161 if(attType
== RANGED_ATTACK
)
3162 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
3164 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
3166 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
3167 if(Player
*modOwner
= GetSpellModOwner())
3168 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
3171 float miss_chance
= 100.0f
- HitChance
;
3173 // Bonuses from attacker aura and ratings
3174 if (attType
== RANGED_ATTACK
)
3175 miss_chance
-= m_modRangedHitChance
;
3177 miss_chance
-= m_modMeleeHitChance
;
3179 // bonus from skills is 0.04%
3180 miss_chance
-= skillDiff
* 0.04f
;
3182 // Limit miss chance from 0 to 60%
3183 if (miss_chance
< 0.0f
)
3185 if (miss_chance
> 60.0f
)
3190 // Melee based spells hit result calculations
3191 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
3193 WeaponAttackType attType
= BASE_ATTACK
;
3195 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
3196 attType
= RANGED_ATTACK
;
3198 // bonus from skills is 0.04% per skill Diff
3199 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
3200 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
3201 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
3203 uint32 roll
= urand (0, 10000);
3204 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
3207 uint32 tmp
= missChance
;
3209 return SPELL_MISS_MISS
;
3211 // Same spells cannot be parry/dodge
3212 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
3213 return SPELL_MISS_NONE
;
3215 // Ranged attack can`t miss too
3216 if (attType
== RANGED_ATTACK
)
3217 return SPELL_MISS_NONE
;
3219 bool attackFromBehind
= !pVictim
->HasInArc(M_PI
,this);
3222 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
3223 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
3224 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
3226 // Reduce dodge chance by attacker expertise rating
3227 if (GetTypeId() == TYPEID_PLAYER
)
3228 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
3229 if (dodgeChance
< 0)
3232 // Can`t dodge from behind in PvP (but its possible in PvE)
3233 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
&& attackFromBehind
)
3236 // Rogue talent`s cant be dodged
3237 AuraList
const& mCanNotBeDodge
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
3238 for(AuraList::const_iterator i
= mCanNotBeDodge
.begin(); i
!= mCanNotBeDodge
.end(); ++i
)
3240 if((*i
)->GetModifier()->m_miscvalue
== VICTIMSTATE_DODGE
) // can't be dodged rogue finishing move
3242 if(spell
->SpellFamilyName
==SPELLFAMILY_ROGUE
&& (spell
->SpellFamilyFlags
& SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE
))
3252 return SPELL_MISS_DODGE
;
3255 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
3256 // Reduce parry chance by attacker expertise rating
3257 if (GetTypeId() == TYPEID_PLAYER
)
3258 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
3259 // Can`t parry from behind
3260 if (parryChance
< 0 || attackFromBehind
)
3265 return SPELL_MISS_PARRY
;
3267 return SPELL_MISS_NONE
;
3270 // TODO need use unit spell resistances in calculations
3271 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
3273 // Can`t miss on dead target (on skinning for example)
3274 if (!pVictim
->isAlive())
3275 return SPELL_MISS_NONE
;
3277 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
3278 // PvP - PvE spell misschances per leveldif > 2
3279 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
3280 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
3282 // Base hit chance from attacker and victim levels
3285 modHitChance
= 96 - leveldif
;
3287 modHitChance
= 94 - (leveldif
- 2) * lchance
;
3289 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
3290 if(Player
*modOwner
= GetSpellModOwner())
3291 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
3292 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
3293 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
3294 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
3295 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
3296 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
3297 if (IsAreaOfEffectSpell(spell
))
3298 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
3299 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
3300 if (IsDispelSpell(spell
))
3301 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
3302 // Chance resist mechanic (select max value from every mechanic spell effect)
3303 int32 resist_mech
= 0;
3304 // Get effects mechanic and chance
3305 for(int eff
= 0; eff
< 3; ++eff
)
3307 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
3310 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
3311 if (resist_mech
< temp
)
3316 modHitChance
-=resist_mech
;
3318 // Chance resist debuff
3319 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
3321 int32 HitChance
= modHitChance
* 100;
3322 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
3323 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
3325 // Decrease hit chance from victim rating bonus
3326 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
3327 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
3329 if (HitChance
< 100) HitChance
= 100;
3330 if (HitChance
> 9900) HitChance
= 9900;
3332 uint32 rand
= urand(0,10000);
3333 if (rand
> HitChance
)
3334 return SPELL_MISS_RESIST
;
3335 return SPELL_MISS_NONE
;
3338 // Calculate spell hit result can be:
3339 // Every spell can: Evade/Immune/Reflect/Sucesful hit
3340 // For melee based spells:
3346 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
3348 // Return evade for units in evade mode
3349 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
3350 return SPELL_MISS_EVADE
;
3352 // Check for immune (use charges)
3353 if (pVictim
->IsImmunedToSpell(spell
,true))
3354 return SPELL_MISS_IMMUNE
;
3356 // All positive spells can`t miss
3357 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
3358 if (IsPositiveSpell(spell
->Id
))
3359 return SPELL_MISS_NONE
;
3361 // Check for immune (use charges)
3362 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
),true))
3363 return SPELL_MISS_IMMUNE
;
3365 // Try victim reflect spell
3368 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
3369 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
3370 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
3371 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
3372 reflectchance
+= (*i
)->GetModifier()->m_amount
;
3373 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
3375 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
3376 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
3377 return SPELL_MISS_REFLECT
;
3381 switch (spell
->DmgClass
)
3383 case SPELL_DAMAGE_CLASS_RANGED
:
3384 case SPELL_DAMAGE_CLASS_MELEE
:
3385 return MeleeSpellHitResult(pVictim
, spell
);
3386 case SPELL_DAMAGE_CLASS_NONE
:
3387 case SPELL_DAMAGE_CLASS_MAGIC
:
3388 return MagicSpellHitResult(pVictim
, spell
);
3390 return SPELL_MISS_NONE
;
3393 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
3398 // Base misschance 5%
3399 float misschance
= 5.0f
;
3401 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
3402 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
3404 bool isNormal
= false;
3405 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
3407 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
3413 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
3423 // PvP : PvE melee misschances per leveldif > 2
3424 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
3426 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
3430 // Hit chance from attacker based on ratings and auras
3431 float m_modHitChance
;
3432 if (attType
== RANGED_ATTACK
)
3433 m_modHitChance
= m_modRangedHitChance
;
3435 m_modHitChance
= m_modMeleeHitChance
;
3438 misschance
+= (leveldif
- m_modHitChance
);
3440 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
3442 // Hit chance for victim based on ratings
3443 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
3445 if (attType
== RANGED_ATTACK
)
3446 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
3448 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
3451 // Modify miss chance by victim auras
3452 if(attType
== RANGED_ATTACK
)
3453 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
3455 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
3457 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
3458 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
3459 misschance
-= skillBonus
* 0.04f
;
3461 // Limit miss chance from 0 to 60%
3462 if ( misschance
< 0.0f
)
3464 if ( misschance
> 60.0f
)
3470 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
3472 if(GetTypeId() == TYPEID_PLAYER
)
3474 // in PvP use full skill instead current skill value
3475 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3476 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
3477 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
3478 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
3482 return GetUnitMeleeSkill(target
);
3485 float Unit::GetUnitDodgeChance() const
3487 if(hasUnitState(UNIT_STAT_STUNNED
))
3489 if( GetTypeId() == TYPEID_PLAYER
)
3490 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
3493 if(((Creature
const*)this)->isTotem())
3498 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
3499 return dodge
> 0.0f
? dodge
: 0.0f
;
3504 float Unit::GetUnitParryChance() const
3506 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3509 float chance
= 0.0f
;
3511 if(GetTypeId() == TYPEID_PLAYER
)
3513 Player
const* player
= (Player
const*)this;
3514 if(player
->CanParry() )
3516 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true);
3518 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true);
3521 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
3524 else if(GetTypeId() == TYPEID_UNIT
)
3526 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
3529 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
3533 return chance
> 0.0f
? chance
: 0.0f
;
3536 float Unit::GetUnitBlockChance() const
3538 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
3541 if(GetTypeId() == TYPEID_PLAYER
)
3543 Player
const* player
= (Player
const*)this;
3544 if(player
->CanBlock() )
3546 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
3547 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
3548 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
3550 // is player but has no block ability or no not broken shield equipped
3555 if(((Creature
const*)this)->isTotem())
3560 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
3561 return block
> 0.0f
? block
: 0.0f
;
3566 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
3570 if(GetTypeId() == TYPEID_PLAYER
)
3575 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
3578 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
3581 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
3583 // Just for good manner
3592 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
3596 if(attackType
== RANGED_ATTACK
)
3597 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
3599 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
3601 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
3603 // reduce crit chance from Rating for players
3604 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
3606 if (attackType
==RANGED_ATTACK
)
3607 crit
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_RANGED
);
3609 crit
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
);
3617 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
3620 if(GetTypeId() == TYPEID_PLAYER
)
3622 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true);
3624 // feral or unarmed skill only for base attack
3625 if(attType
!= BASE_ATTACK
&& !item
)
3628 if(((Player
*)this)->IsInFeralForm())
3629 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
3631 // weapon skill or (unarmed for base attack)
3632 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
3634 // in PvP use full skill instead current skill value
3635 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
3636 ? ((Player
*)this)->GetMaxSkillValue(skill
)
3637 : ((Player
*)this)->GetSkillValue(skill
);
3638 // Modify value from ratings
3639 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
3642 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
3643 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
3644 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
3648 value
= GetUnitMeleeSkill(target
);
3652 void Unit::_UpdateSpells( uint32 time
)
3654 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
3655 _UpdateAutoRepeatSpell();
3657 // remove finished spells from current pointers
3658 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
3660 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
3662 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
3663 m_currentSpells
[i
] = NULL
; // remove pointer
3667 // TODO: Find a better way to prevent crash when multiple auras are removed.
3669 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
3671 (*i
).second
->SetUpdated(false);
3673 for (AuraMap::iterator i
= m_Auras
.begin(), next
; i
!= m_Auras
.end(); i
= next
)
3679 // prevent double update
3680 if ((*i
).second
->IsUpdated())
3682 (*i
).second
->SetUpdated(true);
3683 (*i
).second
->Update( time
);
3684 // several auras can be deleted due to update
3687 if (m_Auras
.empty()) break;
3688 next
= m_Auras
.begin();
3694 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
3698 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
3713 if(!m_gameObj
.empty())
3715 std::list
<GameObject
*>::iterator ite1
, dnext1
;
3716 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
3719 //(*i)->Update( difftime );
3720 if( !(*ite1
)->isSpawned() )
3722 (*ite1
)->SetOwnerGUID(0);
3723 (*ite1
)->SetRespawnTime(0);
3725 dnext1
= m_gameObj
.erase(ite1
);
3733 void Unit::_UpdateAutoRepeatSpell()
3735 //check "realtime" interrupts
3736 if ( (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) )
3738 // cancel wand shoot
3739 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Category
== 351)
3740 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3741 m_AutoRepeatFirstCast
= true;
3746 if ( m_AutoRepeatFirstCast
&& getAttackTimer(RANGED_ATTACK
) < 500 )
3747 setAttackTimer(RANGED_ATTACK
,500);
3748 m_AutoRepeatFirstCast
= false;
3751 if (isAttackReady(RANGED_ATTACK
))
3753 // Check if able to cast
3754 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CanCast(true))
3756 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3761 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
3762 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
3764 // all went good, reset attack
3765 resetAttackTimer(RANGED_ATTACK
);
3769 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
3771 assert(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
3773 uint32 CSpellType
= pSpell
->GetCurrentContainer();
3775 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
3777 // break same type spell if it is not delayed
3778 InterruptSpell(CSpellType
,false);
3780 // special breakage effects:
3783 case CURRENT_GENERIC_SPELL
:
3785 // generic spells always break channeled not delayed spells
3786 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3788 // autorepeat breaking
3789 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3791 // break autorepeat if not Auto Shot
3792 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Category
== 351)
3793 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3794 m_AutoRepeatFirstCast
= true;
3798 case CURRENT_CHANNELED_SPELL
:
3800 // channel spells always break generic non-delayed and any channeled spells
3801 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3802 InterruptSpell(CURRENT_CHANNELED_SPELL
);
3804 // it also does break autorepeat if not Auto Shot
3805 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
3806 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Category
== 351 )
3807 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3810 case CURRENT_AUTOREPEAT_SPELL
:
3812 // only Auto Shoot does not break anything
3813 if (pSpell
->m_spellInfo
->Category
== 351)
3815 // generic autorepeats break generic non-delayed and channeled non-delayed spells
3816 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3817 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3819 // special action: set first cast flag
3820 m_AutoRepeatFirstCast
= true;
3825 // other spell types don't break anything now
3829 // current spell (if it is still here) may be safely deleted now
3830 if (m_currentSpells
[CSpellType
])
3831 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
3833 // set new current spell
3834 m_currentSpells
[CSpellType
] = pSpell
;
3835 pSpell
->SetReferencedFromCurrent(true);
3838 void Unit::InterruptSpell(uint32 spellType
, bool withDelayed
)
3840 assert(spellType
< CURRENT_MAX_SPELL
);
3842 if(m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
3844 // send autorepeat cancel message for autorepeat spells
3845 if (spellType
== CURRENT_AUTOREPEAT_SPELL
)
3847 if(GetTypeId()==TYPEID_PLAYER
)
3848 ((Player
*)this)->SendAutoRepeatCancel();
3851 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
3852 m_currentSpells
[spellType
]->cancel();
3853 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
3854 m_currentSpells
[spellType
] = NULL
;
3858 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
3860 // We don't do loop here to explicitly show that melee spell is excluded.
3861 // Maybe later some special spells will be excluded too.
3863 // generic spells are casted when they are not finished and not delayed
3864 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
3865 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3866 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3869 // channeled spells may be delayed, but they are still considered casted
3870 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
3871 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
3874 // autorepeat spells may be finished or delayed, but they are still considered casted
3875 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3881 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
3883 // generic spells are interrupted if they are not finished or delayed
3884 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
3886 if ( (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3887 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3888 m_currentSpells
[CURRENT_GENERIC_SPELL
]->cancel();
3889 m_currentSpells
[CURRENT_GENERIC_SPELL
]->SetReferencedFromCurrent(false);
3890 m_currentSpells
[CURRENT_GENERIC_SPELL
] = NULL
;
3893 // autorepeat spells are interrupted if they are not finished or delayed
3894 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
3896 // send disable autorepeat packet in any case
3897 if(GetTypeId()==TYPEID_PLAYER
)
3898 ((Player
*)this)->SendAutoRepeatCancel();
3900 if ( (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3901 (withDelayed
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3902 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->cancel();
3903 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->SetReferencedFromCurrent(false);
3904 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] = NULL
;
3907 // channeled spells are interrupted if they are not finished, even if they are delayed
3908 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
3910 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
)
3911 m_currentSpells
[CURRENT_CHANNELED_SPELL
]->cancel();
3912 m_currentSpells
[CURRENT_CHANNELED_SPELL
]->SetReferencedFromCurrent(false);
3913 m_currentSpells
[CURRENT_CHANNELED_SPELL
] = NULL
;
3917 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
3919 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
3920 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
3921 return m_currentSpells
[i
];
3925 bool Unit::isInFront(Unit
const* target
, float distance
, float arc
) const
3927 return IsWithinDistInMap(target
, distance
) && HasInArc( arc
, target
);
3930 void Unit::SetInFront(Unit
const* target
)
3932 SetOrientation(GetAngle(target
));
3935 bool Unit::isInBack(Unit
const* target
, float distance
, float arc
) const
3937 return IsWithinDistInMap(target
, distance
) && !HasInArc( 2 * M_PI
- arc
, target
);
3940 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
3943 return c
->canSwim();
3945 return c
->canWalk() || c
->canFly();
3948 bool Unit::IsInWater() const
3950 return MapManager::Instance().GetBaseMap(GetMapId())->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
3953 bool Unit::IsUnderWater() const
3955 return MapManager::Instance().GetBaseMap(GetMapId())->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3958 void Unit::DeMorph()
3960 SetDisplayId(GetNativeDisplayId());
3963 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3967 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3968 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3969 modifier
+= (*i
)->GetModifier()->m_amount
;
3974 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3976 float multiplier
= 1.0f
;
3978 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3979 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3980 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3985 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3989 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3990 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3991 if ((*i
)->GetModifier()->m_amount
> modifier
)
3992 modifier
= (*i
)->GetModifier()->m_amount
;
3997 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
4001 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
4002 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
4003 if ((*i
)->GetModifier()->m_amount
< modifier
)
4004 modifier
= (*i
)->GetModifier()->m_amount
;
4009 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
4013 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
4014 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
4016 Modifier
* mod
= (*i
)->GetModifier();
4017 if (mod
->m_miscvalue
& misc_mask
)
4018 modifier
+= mod
->m_amount
;
4023 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
4025 float multiplier
= 1.0f
;
4027 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
4028 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
4030 Modifier
* mod
= (*i
)->GetModifier();
4031 if (mod
->m_miscvalue
& misc_mask
)
4032 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
4037 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
4041 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
4042 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
4044 Modifier
* mod
= (*i
)->GetModifier();
4045 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
> modifier
)
4046 modifier
= mod
->m_amount
;
4052 int32
Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
4056 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
4057 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
4059 Modifier
* mod
= (*i
)->GetModifier();
4060 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
< modifier
)
4061 modifier
= mod
->m_amount
;
4067 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
4071 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
4072 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
4074 Modifier
* mod
= (*i
)->GetModifier();
4075 if (mod
->m_miscvalue
== misc_value
)
4076 modifier
+= mod
->m_amount
;
4081 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
4083 float multiplier
= 1.0f
;
4085 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
4086 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
4088 Modifier
* mod
= (*i
)->GetModifier();
4089 if (mod
->m_miscvalue
== misc_value
)
4090 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
4095 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
4099 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
4100 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
4102 Modifier
* mod
= (*i
)->GetModifier();
4103 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
4104 modifier
= mod
->m_amount
;
4110 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
4114 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
4115 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
4117 Modifier
* mod
= (*i
)->GetModifier();
4118 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
< modifier
)
4119 modifier
= mod
->m_amount
;
4125 bool Unit::AddAura(Aura
*Aur
)
4127 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
4128 if( !isAlive() && Aur
->GetId() != 20584 && Aur
->GetId() != 8326 && Aur
->GetId() != 2584 &&
4129 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
4135 if(Aur
->GetTarget() != this)
4137 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
4138 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
4139 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
4144 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
4146 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
4147 AuraMap::iterator i
= m_Auras
.find( spair
);
4149 // take out same spell
4150 if (i
!= m_Auras
.end())
4152 // passive and persistent auras can stack with themselves any number of times
4153 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
4155 // replace aura if next will > spell StackAmount
4156 if(aurSpellInfo
->StackAmount
)
4158 if(m_Auras
.count(spair
) >= aurSpellInfo
->StackAmount
)
4159 RemoveAura(i
,AURA_REMOVE_BY_STACK
);
4161 // if StackAmount==0 not allow auras from same caster
4164 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
4166 if(i2
->second
->GetCasterGUID()==Aur
->GetCasterGUID())
4168 // can be only single (this check done at _each_ aura add
4169 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
4174 switch(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()])
4177 case SPELL_AURA_PERIODIC_DAMAGE
: // allow stack
4178 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
4179 case SPELL_AURA_PERIODIC_LEECH
:
4180 case SPELL_AURA_PERIODIC_HEAL
:
4181 case SPELL_AURA_OBS_MOD_HEALTH
:
4182 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4183 case SPELL_AURA_PERIODIC_ENERGIZE
:
4184 case SPELL_AURA_OBS_MOD_MANA
:
4185 case SPELL_AURA_POWER_BURN_MANA
:
4187 default: // not allow
4188 // can be only single (this check done at _each_ aura add
4189 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
4201 // passive auras stack with all (except passive spell proc auras)
4202 if ((!Aur
->IsPassive() || !IsPassiveStackableSpell(Aur
->GetId())) &&
4203 !(Aur
->GetId() == 20584 || Aur
->GetId() == 8326))
4205 if (!RemoveNoStackAurasDueToAura(Aur
))
4208 return false; // couldn't remove conflicting aura with higher rank
4212 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
4213 if (IsSingleTargetSpell(aurSpellInfo
) && Aur
->GetTarget())
4215 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
4218 Unit
* caster
= Aur
->GetCaster();
4219 if(!caster
) // caster deleted and not required adding scAura
4222 bool restart
= false;
4223 AuraList
& scAuras
= caster
->GetSingleCastAuras();
4224 for(AuraList::iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
4226 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
4227 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
4229 if ((*itr
)->IsInUse())
4231 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());
4234 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
4243 scAuras
.push_back(Aur
);
4249 // add aura, register in lists and arrays
4251 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
4252 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
4254 m_modAuras
[Aur
->GetModifier()->m_auraname
].push_back(Aur
);
4257 Aur
->ApplyModifier(true,true);
4258 sLog
.outDebug("Aura %u now is in use", Aur
->GetModifier()->m_auraname
);
4262 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
4264 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
4267 AuraMap::iterator i
,next
;
4268 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
4272 uint32 i_spellId
= (*i
).second
->GetId();
4273 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
4275 if(spellmgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
4277 RemoveAurasDueToSpell(i_spellId
);
4279 if( m_Auras
.empty() )
4282 next
= m_Auras
.begin();
4288 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
4293 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
4297 uint32 spellId
= Aur
->GetId();
4298 uint32 effIndex
= Aur
->GetEffIndex();
4300 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
4302 AuraMap::iterator i
,next
;
4303 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
4307 if (!(*i
).second
) continue;
4309 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
4314 uint32 i_spellId
= i_spellProto
->Id
;
4316 if(IsPassiveSpell(i_spellId
))
4318 if(IsPassiveStackableSpell(i_spellId
))
4321 // passive non-stackable spells not stackable only with another rank of same spell
4322 if (!spellmgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4326 uint32 i_effIndex
= (*i
).second
->GetEffIndex();
4328 if(i_spellId
== spellId
) continue;
4330 bool is_triggered_by_spell
= false;
4331 // prevent triggered aura of removing aura that triggered it
4332 for(int j
= 0; j
< 3; ++j
)
4333 if (i_spellProto
->EffectTriggerSpell
[j
] == spellProto
->Id
)
4334 is_triggered_by_spell
= true;
4335 if (is_triggered_by_spell
) continue;
4337 for(int j
= 0; j
< 3; ++j
)
4339 // prevent remove dummy triggered spells at next effect aura add
4340 switch(spellProto
->Effect
[j
]) // main spell auras added added after triggered spell
4342 case SPELL_EFFECT_DUMMY
:
4345 case 5420: if(i_spellId
==34123) is_triggered_by_spell
= true; break;
4350 if(is_triggered_by_spell
)
4353 // prevent remove form main spell by triggered passive spells
4354 switch(i_spellProto
->EffectApplyAuraName
[j
]) // main aura added before triggered spell
4356 case SPELL_AURA_MOD_SHAPESHIFT
:
4359 case 24858: if(spellId
==24905) is_triggered_by_spell
= true; break;
4360 case 33891: if(spellId
==5420 || spellId
==34123) is_triggered_by_spell
= true; break;
4361 case 34551: if(spellId
==22688) is_triggered_by_spell
= true; break;
4367 if(!is_triggered_by_spell
)
4369 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
4371 bool is_sspc
= IsSingleFromSpellSpecificPerCaster(spellId_spec
,i_spellId_spec
);
4373 if( is_sspc
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
4375 // cannot remove higher rank
4376 if (spellmgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
4377 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4380 // Its a parent aura (create this aura in ApplyModifier)
4381 if ((*i
).second
->IsInUse())
4383 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());
4386 RemoveAurasDueToSpell(i_spellId
);
4388 if( m_Auras
.empty() )
4391 next
= m_Auras
.begin();
4393 else if( !is_sspc
&& spellmgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
4395 // Its a parent aura (create this aura in ApplyModifier)
4396 if ((*i
).second
->IsInUse())
4398 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());
4401 RemoveAurasDueToSpell(i_spellId
);
4403 if( m_Auras
.empty() )
4406 next
= m_Auras
.begin();
4408 // Potions stack aura by aura (elixirs/flask already checked)
4409 else if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
4411 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
4413 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
4414 return false; // cannot remove higher rank
4416 // Its a parent aura (create this aura in ApplyModifier)
4417 if ((*i
).second
->IsInUse())
4419 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());
4431 void Unit::RemoveAura(uint32 spellId
, uint32 effindex
, Aura
* except
)
4433 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
4434 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4436 if(iter
->second
!=except
)
4439 iter
= m_Auras
.lower_bound(spair
);
4446 void Unit::RemoveAurasDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
4448 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4450 Aura
*aur
= iter
->second
;
4451 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4453 // Custom dispel case
4454 // Unstable Affliction
4455 if (aur
->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (aur
->GetSpellProto()->SpellFamilyFlags
& 0x010000000000LL
))
4457 int32 damage
= aur
->GetModifier()->m_amount
*9;
4458 uint64 caster_guid
= aur
->GetCasterGUID();
4461 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
4463 // backfire damage and silence
4464 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,caster_guid
);
4466 iter
= m_Auras
.begin(); // iterator can be invalidate at cast if self-dispel
4469 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
4476 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
4478 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4480 Aura
*aur
= iter
->second
;
4481 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
4483 int32 basePoints
= aur
->GetBasePoints();
4484 // construct the new aura for the attacker
4485 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
);
4489 // set its duration and maximum duration
4490 // max duration 2 minutes (in msecs)
4491 int32 dur
= aur
->GetAuraDuration();
4492 const int32 max_dur
= 2*MINUTE
*1000;
4493 new_aur
->SetAuraMaxDuration( max_dur
> dur
? dur
: max_dur
);
4494 new_aur
->SetAuraDuration( max_dur
> dur
? dur
: max_dur
);
4496 // add the new aura to stealer
4497 stealer
->AddAura(new_aur
);
4499 // Remove aura as dispel
4500 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
4507 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
4509 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4511 if (iter
->second
->GetId() == spellId
)
4512 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
4518 void Unit::RemoveAurasWithDispelType( DispelType type
)
4520 // Create dispel mask by dispel type
4521 uint32 dispelMask
= GetDispellMask(type
);
4522 // Dispel all existing auras vs current dispel type
4523 AuraMap
& auras
= GetAuras();
4524 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
4526 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
4527 if( (1<<spell
->Dispel
) & dispelMask
)
4530 RemoveAurasDueToSpell(spell
->Id
);
4531 itr
= auras
.begin();
4538 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, uint32 effindex
)
4540 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4541 if(iter
!= m_Auras
.end())
4545 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
)
4547 for (int i
= 0; i
< 3; ++i
)
4548 RemoveAura(spellId
,i
,except
);
4551 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
4553 for (int k
=0; k
< 3; ++k
)
4555 spellEffectPair spair
= spellEffectPair(spellId
, k
);
4556 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
4558 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
4561 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
4569 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
4571 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4573 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
4580 void Unit::RemoveNotOwnSingleTargetAuras()
4582 // single target auras from other casters
4583 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
4585 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
4591 // single target auras at other targets
4592 AuraList
& scAuras
= GetSingleCastAuras();
4593 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
4596 if (aura
->GetTarget()!=this)
4598 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
4599 aura
->GetTarget()->RemoveAura(aura
->GetId(),aura
->GetEffIndex());
4600 iter
= scAuras
.begin();
4608 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
4610 Aura
* Aur
= i
->second
;
4611 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
4613 Unit
* caster
= NULL
;
4614 if (IsSingleTargetSpell(AurSpellInfo
))
4616 caster
= Aur
->GetCaster();
4619 AuraList
& scAuras
= caster
->GetSingleCastAuras();
4620 scAuras
.remove(Aur
);
4624 sLog
.outError("Couldn't find the caster of the single target aura, may crash later!");
4629 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
4630 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
4632 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
4636 Aur
->SetRemoveMode(mode
);
4637 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
4638 // remove aura from list before to prevent deleting it before
4640 ++m_removedAuras
; // internal count used by unit update
4642 // Statue unsummoned at aura remove
4643 Totem
* statue
= NULL
;
4644 bool caster_channeled
= false;
4645 if(IsChanneledSpell(AurSpellInfo
))
4647 if(!caster
) // can be already located for IsSingleTargetSpell case
4648 caster
= Aur
->GetCaster();
4652 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
4653 statue
= ((Totem
*)caster
);
4655 caster_channeled
= caster
==this;
4659 sLog
.outDebug("Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
4660 Aur
->ApplyModifier(false,true);
4664 if(caster_channeled
)
4665 RemoveAurasAtChanneledTarget (AurSpellInfo
);
4670 // only way correctly remove all auras from list
4671 if( m_Auras
.empty() )
4674 i
= m_Auras
.begin();
4677 void Unit::RemoveAllAuras()
4679 while (!m_Auras
.empty())
4681 AuraMap::iterator iter
= m_Auras
.begin();
4686 void Unit::RemoveAllAurasOnDeath()
4688 // used just after dieing to remove all visible auras
4689 // and disable the mods for the passive ones
4690 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
4692 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
4693 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
4699 void Unit::DelayAura(uint32 spellId
, uint32 effindex
, int32 delaytime
)
4701 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4702 if (iter
!= m_Auras
.end())
4704 if (iter
->second
->GetAuraDuration() < delaytime
)
4705 iter
->second
->SetAuraDuration(0);
4707 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
4708 iter
->second
->UpdateAuraDuration();
4709 sLog
.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter
->second
->GetModifier()->m_auraname
, GetGUIDLow(), iter
->second
->GetAuraDuration());
4713 void Unit::_RemoveAllAuraMods()
4715 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4717 (*i
).second
->ApplyModifier(false);
4721 void Unit::_ApplyAllAuraMods()
4723 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
4725 (*i
).second
->ApplyModifier(true);
4729 Aura
* Unit::GetAura(uint32 spellId
, uint32 effindex
)
4731 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
4732 if (iter
!= m_Auras
.end())
4733 return iter
->second
;
4737 void Unit::AddDynObject(DynamicObject
* dynObj
)
4739 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
4742 void Unit::RemoveDynObject(uint32 spellid
)
4744 if(m_dynObjGUIDs
.empty())
4746 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4748 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
4751 i
= m_dynObjGUIDs
.erase(i
);
4753 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
4756 i
= m_dynObjGUIDs
.erase(i
);
4763 void Unit::RemoveAllDynObjects()
4765 while(!m_dynObjGUIDs
.empty())
4767 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
4770 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
4774 DynamicObject
* Unit::GetDynObject(uint32 spellId
, uint32 effIndex
)
4776 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4778 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
4781 i
= m_dynObjGUIDs
.erase(i
);
4785 if (dynObj
->GetSpellId() == spellId
&& dynObj
->GetEffIndex() == effIndex
)
4792 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
4794 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4796 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
4799 i
= m_dynObjGUIDs
.erase(i
);
4803 if (dynObj
->GetSpellId() == spellId
)
4810 void Unit::AddGameObject(GameObject
* gameObj
)
4812 assert(gameObj
&& gameObj
->GetOwnerGUID()==0);
4813 m_gameObj
.push_back(gameObj
);
4814 gameObj
->SetOwnerGUID(GetGUID());
4817 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
4819 assert(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
4821 // GO created by some spell
4822 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
4824 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
4825 // Need activate spell use for owner
4826 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4827 ((Player
*)this)->SendCooldownEvent(createBySpell
);
4829 gameObj
->SetOwnerGUID(0);
4830 m_gameObj
.remove(gameObj
);
4833 gameObj
->SetRespawnTime(0);
4838 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
4840 if(m_gameObj
.empty())
4842 std::list
<GameObject
*>::iterator i
, next
;
4843 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
4846 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
4848 (*i
)->SetOwnerGUID(0);
4851 (*i
)->SetRespawnTime(0);
4855 next
= m_gameObj
.erase(i
);
4862 void Unit::RemoveAllGameObjects()
4864 // remove references to unit
4865 for(std::list
<GameObject
*>::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4867 (*i
)->SetOwnerGUID(0);
4868 (*i
)->SetRespawnTime(0);
4870 i
= m_gameObj
.erase(i
);
4874 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
4876 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size
4877 data
.append(log
->target
->GetPackGUID());
4878 data
.append(log
->attacker
->GetPackGUID());
4879 data
<< uint32(log
->SpellID
);
4880 data
<< uint32(log
->damage
); //damage amount
4881 data
<< uint8 (log
->schoolMask
); //damage school
4882 data
<< uint32(log
->absorb
); //AbsorbedDamage
4883 data
<< uint32(log
->resist
); //resist
4884 data
<< uint8 (log
->phusicalLog
); // damsge type? flag
4885 data
<< uint8 (log
->unused
); //unused
4886 data
<< uint32(log
->blocked
); //blocked
4887 data
<< uint32(log
->HitInfo
);
4888 data
<< uint8 (0); // flag to use extend data
4889 SendMessageToSet( &data
, true );
4892 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
,uint32 SpellID
,uint32 Damage
, SpellSchoolMask damageSchoolMask
,uint32 AbsorbedDamage
, uint32 Resist
,bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
4894 sLog
.outDebug("Sending: SMSG_SPELLNONMELEEDAMAGELOG");
4895 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size
4896 data
.append(target
->GetPackGUID());
4897 data
.append(GetPackGUID());
4898 data
<< uint32(SpellID
);
4899 data
<< uint32(Damage
-AbsorbedDamage
-Resist
-Blocked
);
4900 data
<< uint8(damageSchoolMask
); // spell school
4901 data
<< uint32(AbsorbedDamage
); // AbsorbedDamage
4902 data
<< uint32(Resist
); // resist
4903 data
<< uint8(PhysicalDamage
); // 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
4904 data
<< uint8(0); // unk isFromAura
4905 data
<< uint32(Blocked
); // blocked
4906 data
<< uint32(CriticalHit
? 0x27 : 0x25); // hitType, flags: 0x2 - SPELL_HIT_TYPE_CRIT, 0x10 - replace caster?
4907 data
<< uint8(0); // isDebug?
4908 SendMessageToSet( &data
, true );
4911 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
4913 // Not much to do if no flags are set.
4915 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
4916 // Now go on with a victim's events'n'auras
4917 // Not much to do if no flags are set or there is no victim
4918 if(pVictim
&& pVictim
->isAlive() && procVictim
)
4919 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4922 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4924 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4925 data
<< uint32(spellID
);
4926 data
<< uint64(GetGUID());
4927 data
<< uint8(0); // can be 0 or 1
4928 data
<< uint32(1); // target count
4929 // for(i = 0; i < target count; ++i)
4930 data
<< uint64(target
->GetGUID()); // target GUID
4931 data
<< uint8(missInfo
);
4933 SendMessageToSet(&data
, true);
4936 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4938 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, (16+84)); // we guess size
4939 data
<< (uint32
)damageInfo
->HitInfo
;
4940 data
.append(GetPackGUID());
4941 data
.append(damageInfo
->target
->GetPackGUID());
4942 data
<< (uint32
)(damageInfo
->damage
); // Full damage
4944 data
<< (uint8
)1; // Sub damage count
4945 //=== Sub damage description
4946 data
<< (uint32
)(damageInfo
->damageSchoolMask
); // School of sub damage
4947 data
<< (float)damageInfo
->damage
; // sub damage
4948 data
<< (uint32
)damageInfo
->damage
; // Sub Damage
4949 data
<< (uint32
)damageInfo
->absorb
; // Absorb
4950 data
<< (uint32
)damageInfo
->resist
; // Resist
4951 //=================================================
4952 data
<< (uint32
)damageInfo
->TargetState
;
4955 data
<< (uint32
)damageInfo
->blocked_amount
;
4956 SendMessageToSet( &data
, true );/**/
4959 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8 SwingType
, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4961 sLog
.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4963 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, (16+45)); // we guess size
4964 data
<< (uint32
)HitInfo
;
4965 data
.append(GetPackGUID());
4966 data
.append(target
->GetPackGUID());
4967 data
<< (uint32
)(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);
4969 data
<< (uint8
)SwingType
; // count?
4971 // for(i = 0; i < SwingType; ++i)
4972 data
<< (uint32
)damageSchoolMask
;
4973 data
<< (float)(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);
4974 // still need to double check damage
4975 data
<< (uint32
)(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);
4976 data
<< (uint32
)AbsorbDamage
;
4977 data
<< (uint32
)Resist
;
4980 data
<< (uint32
)TargetState
;
4982 if( AbsorbDamage
== 0 ) //also 0x3E8 = 0x3E8, check when that happens
4988 data
<< (uint32
)BlockedAmount
;
4990 SendMessageToSet( &data
, true );
4993 void Unit::ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 damage, SpellSchoolMask damageSchoolMask, SpellEntry const *procSpell, bool isTriggeredSpell, WeaponAttackType attType)
4995 sLog.outDebug("ProcDamageAndSpell: attacker flags are 0x%x, victim flags 0x%x", procAttacker, procVictim);
4997 sLog.outDebug("ProcDamageAndSpell: invoked due to spell id %u %s", procSpell->Id, (isTriggeredSpell?"(triggered)":""));
4999 // Assign melee/ranged proc flags for magic attacks, that are actually melee/ranged abilities
5000 // not assign for spell proc triggered spell to prevent infinity (or unexpected 2-3 times) melee damage spell proc call with melee damage effect
5001 // That is the question though if it's fully correct
5002 if(procSpell && !isTriggeredSpell)
5004 if(procSpell->DmgClass == SPELL_DAMAGE_CLASS_MELEE)
5006 if(procAttacker & PROC_FLAG_HIT_SPELL) procAttacker |= PROC_FLAG_HIT_MELEE;
5007 if(procAttacker & PROC_FLAG_CRIT_SPELL) procAttacker |= PROC_FLAG_CRIT_MELEE;
5008 if(procVictim & PROC_FLAG_STRUCK_SPELL) procVictim |= PROC_FLAG_STRUCK_MELEE;
5009 if(procVictim & PROC_FLAG_STRUCK_CRIT_SPELL) procVictim |= PROC_FLAG_STRUCK_CRIT_MELEE;
5010 attType = BASE_ATTACK; // Melee abilities are assumed to be dealt with mainhand weapon
5012 else if (procSpell->DmgClass == SPELL_DAMAGE_CLASS_RANGED)
5014 if(procAttacker & PROC_FLAG_HIT_SPELL) procAttacker |= PROC_FLAG_HIT_RANGED;
5015 if(procAttacker & PROC_FLAG_CRIT_SPELL) procAttacker |= PROC_FLAG_CRIT_RANGED;
5016 if(procVictim & PROC_FLAG_STRUCK_SPELL) procVictim |= PROC_FLAG_STRUCK_RANGED;
5017 if(procVictim & PROC_FLAG_STRUCK_CRIT_SPELL) procVictim |= PROC_FLAG_STRUCK_CRIT_RANGED;
5018 attType = RANGED_ATTACK;
5021 if(damage && (procVictim & (PROC_FLAG_STRUCK_MELEE|PROC_FLAG_STRUCK_RANGED|PROC_FLAG_STRUCK_SPELL)))
5022 procVictim |= (PROC_FLAG_TAKE_DAMAGE|PROC_FLAG_TOUCH);
5024 // Not much to do if no flags are set.
5027 // processing auras that not generate casts at proc event before auras that generate casts to prevent proc aura added at prev. proc aura execute in set
5028 ProcDamageAndSpellFor(false,pVictim,procAttacker,attackerProcEffectAuraTypes,attType, procSpell, damage, damageSchoolMask);
5029 ProcDamageAndSpellFor(false,pVictim,procAttacker,attackerProcCastAuraTypes,attType, procSpell, damage, damageSchoolMask);
5032 // Now go on with a victim's events'n'auras
5033 // Not much to do if no flags are set or there is no victim
5034 if(pVictim && pVictim->isAlive() && procVictim)
5036 // processing auras that not generate casts at proc event before auras that generate casts to prevent proc aura added at prev. proc aura execute in set
5037 pVictim->ProcDamageAndSpellFor(true,this,procVictim,victimProcEffectAuraTypes,attType,procSpell, damage, damageSchoolMask);
5038 pVictim->ProcDamageAndSpellFor(true,this,procVictim,victimProcCastAuraTypes,attType,procSpell, damage, damageSchoolMask);
5042 void Unit::CastMeleeProcDamageAndSpell(Unit* pVictim, uint32 damage, SpellSchoolMask damageSchoolMask, WeaponAttackType attType, MeleeHitOutcome outcome, SpellEntry const *spellCasted, bool isTriggeredSpell)
5047 uint32 procAttacker = PROC_FLAG_NONE;
5048 uint32 procVictim = PROC_FLAG_NONE;
5052 case MELEE_HIT_EVADE:
5054 case MELEE_HIT_MISS:
5055 if(attType == BASE_ATTACK || attType == OFF_ATTACK)
5057 procAttacker = PROC_FLAG_MISS;
5060 case MELEE_HIT_BLOCK_CRIT:
5061 case MELEE_HIT_CRIT:
5062 if(spellCasted && attType == BASE_ATTACK)
5064 procAttacker |= PROC_FLAG_CRIT_SPELL;
5065 procVictim |= PROC_FLAG_STRUCK_CRIT_SPELL;
5066 if ( outcome == MELEE_HIT_BLOCK_CRIT )
5068 procVictim |= PROC_FLAG_BLOCK;
5069 procAttacker |= PROC_FLAG_TARGET_BLOCK;
5072 else if(attType == BASE_ATTACK || attType == OFF_ATTACK)
5074 procAttacker = PROC_FLAG_HIT_MELEE | PROC_FLAG_CRIT_MELEE;
5075 procVictim = PROC_FLAG_STRUCK_MELEE | PROC_FLAG_STRUCK_CRIT_MELEE;
5079 procAttacker = PROC_FLAG_HIT_RANGED | PROC_FLAG_CRIT_RANGED;
5080 procVictim = PROC_FLAG_STRUCK_RANGED | PROC_FLAG_STRUCK_CRIT_RANGED;
5083 case MELEE_HIT_PARRY:
5084 procAttacker = PROC_FLAG_TARGET_DODGE_OR_PARRY;
5085 procVictim = PROC_FLAG_PARRY;
5087 case MELEE_HIT_BLOCK:
5088 procAttacker = PROC_FLAG_TARGET_BLOCK;
5089 procVictim = PROC_FLAG_BLOCK;
5091 case MELEE_HIT_DODGE:
5092 procAttacker = PROC_FLAG_TARGET_DODGE_OR_PARRY;
5093 procVictim = PROC_FLAG_DODGE;
5095 case MELEE_HIT_CRUSHING:
5096 if(attType == BASE_ATTACK || attType == OFF_ATTACK)
5098 procAttacker = PROC_FLAG_HIT_MELEE | PROC_FLAG_CRIT_MELEE;
5099 procVictim = PROC_FLAG_STRUCK_MELEE | PROC_FLAG_STRUCK_CRIT_MELEE;
5103 procAttacker = PROC_FLAG_HIT_RANGED | PROC_FLAG_CRIT_RANGED;
5104 procVictim = PROC_FLAG_STRUCK_RANGED | PROC_FLAG_STRUCK_CRIT_RANGED;
5108 if(attType == BASE_ATTACK || attType == OFF_ATTACK)
5110 procAttacker = PROC_FLAG_HIT_MELEE;
5111 procVictim = PROC_FLAG_STRUCK_MELEE;
5115 procAttacker = PROC_FLAG_HIT_RANGED;
5116 procVictim = PROC_FLAG_STRUCK_RANGED;
5122 procVictim |= PROC_FLAG_TAKE_DAMAGE;
5124 if(procAttacker != PROC_FLAG_NONE || procVictim != PROC_FLAG_NONE)
5125 ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, damageSchoolMask, spellCasted, isTriggeredSpell, attType);
5128 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
5130 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
5132 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5133 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5135 uint32 triggered_spell_id
= 0;
5136 Unit
* target
= pVictim
;
5137 int32 basepoints0
= 0;
5139 switch(hasteSpell
->SpellFamilyName
)
5141 case SPELLFAMILY_ROGUE
:
5143 switch(hasteSpell
->Id
)
5149 target
= SelectNearbyTarget();
5152 basepoints0
= damage
;
5153 triggered_spell_id
= 22482;
5161 // processed charge only counting case
5162 if(!triggered_spell_id
)
5165 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5169 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
5174 if(!target
|| target
!=this && !target
->isAlive())
5177 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5181 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5183 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5185 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5186 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5191 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
5193 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
5194 uint32 effIndex
= triggeredByAura
->GetEffIndex ();
5196 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5197 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5199 uint32 triggered_spell_id
= 0;
5200 Unit
* target
= pVictim
;
5201 int32 basepoints0
= 0;
5203 switch(dummySpell
->SpellFamilyName
)
5205 case SPELLFAMILY_GENERIC
:
5207 switch (dummySpell
->Id
)
5213 // prevent damage back from weapon special attacks
5214 if (!procSpell
|| procSpell
->DmgClass
!= SPELL_DAMAGE_CLASS_MAGIC
)
5217 // return damage % to attacker but < 50% own total health
5218 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*int32(damage
)/100;
5219 if(basepoints0
> GetMaxHealth()/2)
5220 basepoints0
= GetMaxHealth()/2;
5222 triggered_spell_id
= 25997;
5230 // prevent chain of triggered spell from same triggered spell
5231 if(procSpell
&& procSpell
->Id
==26654)
5234 target
= SelectNearbyTarget();
5238 triggered_spell_id
= 26654;
5244 if (!procSpell
|| procSpell
->Id
== 24659)
5246 // Need remove one 24659 aura
5247 RemoveSingleAuraFromStack(24659, 0);
5248 RemoveSingleAuraFromStack(24659, 1);
5251 // Restless Strength
5254 // Need remove one 24662 aura
5255 RemoveSingleAuraFromStack(24662, 0);
5258 // Adaptive Warding (Frostfire Regalia set)
5266 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
5267 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
5269 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
5271 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& 0x10000000))
5281 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5283 case SPELL_SCHOOL_NORMAL
:
5284 case SPELL_SCHOOL_HOLY
:
5285 return false; // ignored
5286 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
5287 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
5288 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
5289 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
5290 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
5298 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
5304 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5306 case SPELL_SCHOOL_NORMAL
:
5307 return false; // ignore
5308 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
5309 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
5310 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
5311 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
5312 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
5313 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
5321 // Mana Leech (Passive) (Priest Pet Aura)
5325 target
= GetOwner();
5329 basepoints0
= int32(damage
* 2.5f
); // manaregen
5330 triggered_spell_id
= 34650;
5336 // Cast finish spell at last charge
5337 if (triggeredByAura
->m_procCharges
> 1)
5341 triggered_spell_id
= 33494;
5344 // Twisted Reflection (boss spell)
5346 triggered_spell_id
= 21064;
5348 // Vampiric Aura (boss spell)
5351 basepoints0
= 3 * damage
; // 300%
5352 if (basepoints0
< 0)
5355 triggered_spell_id
= 31285;
5359 // Aura of Madness (Darkmoon Card: Madness trinket)
5360 //=====================================================
5361 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
5362 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
5363 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
5364 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5365 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
5366 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
5367 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
5368 // 41011 Martyr Complex: +35 stamina (All classes)
5369 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5370 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
5373 if(GetTypeId() != TYPEID_PLAYER
)
5376 // Select class defined buff
5379 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5380 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
5382 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
5383 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5386 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
5387 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
5389 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
5390 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5393 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
5394 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
5395 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
5396 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
5398 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
5399 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5402 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
5404 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
5405 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
5413 if (roll_chance_i(10))
5414 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
5418 // TODO: need find item for aura and triggered spells
5419 // Sunwell Exalted Caster Neck (??? neck)
5420 // cast ??? Light's Wrath if Exalted by Aldor
5421 // cast ??? Arcane Bolt if Exalted by Scryers*/
5423 return false; // disable for while
5426 if(GetTypeId() != TYPEID_PLAYER)
5429 // Get Aldor reputation rank
5430 if (((Player *)this)->GetReputationRank(932) == REP_EXALTED)
5433 triggered_spell_id = ???
5436 // Get Scryers reputation rank
5437 if (((Player *)this)->GetReputationRank(934) == REP_EXALTED)
5439 triggered_spell_id = ???
5444 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
5445 // cast 45479 Light's Wrath if Exalted by Aldor
5446 // cast 45429 Arcane Bolt if Exalted by Scryers
5449 if(GetTypeId() != TYPEID_PLAYER
)
5452 // Get Aldor reputation rank
5453 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5456 triggered_spell_id
= 45479;
5459 // Get Scryers reputation rank
5460 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5462 triggered_spell_id
= 45429;
5467 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
5468 // cast 45480 Light's Strength if Exalted by Aldor
5469 // cast 45428 Arcane Strike if Exalted by Scryers
5472 if(GetTypeId() != TYPEID_PLAYER
)
5475 // Get Aldor reputation rank
5476 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5479 triggered_spell_id
= 45480;
5482 // Get Scryers reputation rank
5483 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5485 triggered_spell_id
= 45428;
5490 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
5491 // cast 45431 Arcane Insight if Exalted by Aldor
5492 // cast 45432 Light's Ward if Exalted by Scryers
5495 if(GetTypeId() != TYPEID_PLAYER
)
5498 // Get Aldor reputation rank
5499 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5502 triggered_spell_id
= 45432;
5505 // Get Scryers reputation rank
5506 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5509 triggered_spell_id
= 45431;
5514 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
5515 // cast 45478 Light's Salvation if Exalted by Aldor
5516 // cast 45430 Arcane Surge if Exalted by Scryers
5519 if(GetTypeId() != TYPEID_PLAYER
)
5522 // Get Aldor reputation rank
5523 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
5526 triggered_spell_id
= 45478;
5529 // Get Scryers reputation rank
5530 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
5532 triggered_spell_id
= 45430;
5540 case SPELLFAMILY_MAGE
:
5543 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
5545 if (getPowerType() != POWER_MANA
)
5549 basepoints0
= (triggeredByAura
->GetModifier()->m_amount
* GetMaxPower(POWER_MANA
) / 100);
5551 triggered_spell_id
= 29442;
5554 // Master of Elements
5555 if (dummySpell
->SpellIconID
== 1920)
5561 basepoints0
= procSpell
->manaCost
* triggeredByAura
->GetModifier()->m_amount
/100;
5562 if( basepoints0
<=0 )
5566 triggered_spell_id
= 29077;
5569 // Incanter's Regalia set (add trigger chance to Mana Shield)
5570 if (dummySpell
->SpellFamilyFlags
& 0x0000000000008000LL
)
5572 if(GetTypeId() != TYPEID_PLAYER
)
5576 triggered_spell_id
= 37436;
5579 switch(dummySpell
->Id
)
5588 switch (dummySpell
->Id
)
5590 case 11119: basepoints0
= int32(0.04f
*damage
); break;
5591 case 11120: basepoints0
= int32(0.08f
*damage
); break;
5592 case 12846: basepoints0
= int32(0.12f
*damage
); break;
5593 case 12847: basepoints0
= int32(0.16f
*damage
); break;
5594 case 12848: basepoints0
= int32(0.20f
*damage
); break;
5596 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
5600 triggered_spell_id
= 12654;
5606 //last charge and crit
5607 if (triggeredByAura
->m_procCharges
<= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
5609 RemoveAurasDueToSpell(28682); //-> remove Combustion auras
5610 return true; // charge counting (will removed)
5613 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
5614 return (procEx
& PROC_EX_CRITICAL_HIT
);// charge update only at crit hits, no hidden cooldowns
5619 case SPELLFAMILY_WARRIOR
:
5622 if(dummySpell
->SpellFamilyFlags
==0x0000000800000000LL
)
5624 // check attack comes not from behind
5625 if (!HasInArc(M_PI
, pVictim
))
5628 triggered_spell_id
= 22858;
5631 else if (dummySpell
->SpellIconID
== 1697) // Second Wind
5633 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
5634 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
5636 // Need stun or root mechanic
5637 if (procSpell
->Mechanic
!= MECHANIC_ROOT
&& procSpell
->Mechanic
!= MECHANIC_STUN
)
5641 if (procSpell
->EffectMechanic
[i
] == MECHANIC_ROOT
|| procSpell
->EffectMechanic
[i
] == MECHANIC_STUN
)
5647 switch (dummySpell
->Id
)
5649 case 29838: triggered_spell_id
=29842; break;
5650 case 29834: triggered_spell_id
=29841; break;
5652 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
5661 case SPELLFAMILY_WARLOCK
:
5663 // Seed of Corruption
5664 if (dummySpell
->SpellFamilyFlags
& 0x0000001000000000LL
)
5666 Modifier
* mod
= triggeredByAura
->GetModifier();
5667 // if damage is more than need or target die from damage deal finish spell
5668 if( mod
->m_amount
<= damage
|| GetHealth() <= damage
)
5670 // remember guid before aura delete
5671 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5673 // Remove aura (before cast for prevent infinite loop handlers)
5674 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5676 // Cast finish spell (triggeredByAura already not exist!)
5677 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
5678 return true; // no hidden cooldown
5682 mod
->m_amount
-=damage
;
5685 // Seed of Corruption (Mobs cast) - no die req
5686 if (dummySpell
->SpellFamilyFlags
== 0x00LL
&& dummySpell
->SpellIconID
== 1932)
5688 Modifier
* mod
= triggeredByAura
->GetModifier();
5689 // if damage is more than need deal finish spell
5690 if( mod
->m_amount
<= damage
)
5692 // remember guid before aura delete
5693 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
5695 // Remove aura (before cast for prevent infinite loop handlers)
5696 RemoveAurasDueToSpell(triggeredByAura
->GetId());
5698 // Cast finish spell (triggeredByAura already not exist!)
5699 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
5700 return true; // no hidden cooldown
5703 mod
->m_amount
-=damage
;
5706 switch(dummySpell
->Id
)
5713 triggered_spell_id
= 17941;
5722 basepoints0
= int32(damage
*triggeredByAura
->GetModifier()->m_amount
/100);
5724 triggered_spell_id
= 30294;
5727 // Shadowflame (Voidheart Raiment set bonus)
5730 triggered_spell_id
= 37379;
5733 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
5741 basepoints0
= damage
* triggeredByAura
->GetModifier()->m_amount
/100;
5742 triggered_spell_id
= 37382;
5745 // Shadowflame Hellfire (Voidheart Raiment set bonus)
5748 triggered_spell_id
= 37378;
5754 case SPELLFAMILY_PRIEST
:
5757 if( dummySpell
->SpellFamilyFlags
& 0x0000040000000000LL
)
5759 if(!pVictim
|| !pVictim
->isAlive())
5762 // pVictim is caster of aura
5763 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5767 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*damage
/100;
5768 pVictim
->CastCustomSpell(pVictim
,34919,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5769 return true; // no hidden cooldown
5771 switch(dummySpell
->Id
)
5776 if(!pVictim
|| !pVictim
->isAlive())
5779 // pVictim is caster of aura
5780 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5784 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*damage
/100;
5785 pVictim
->CastCustomSpell(pVictim
,15290,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5786 return true; // no hidden cooldown
5788 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
5791 // Shadow Word: Pain
5792 if( procSpell
->SpellFamilyFlags
& 0x0000000000008000LL
)
5793 triggered_spell_id
= 40441;
5795 else if( procSpell
->SpellFamilyFlags
& 0x0000000000000010LL
)
5796 triggered_spell_id
= 40440;
5803 // Oracle Healing Bonus ("Garments of the Oracle" set)
5807 basepoints0
= int32(damage
* 10/100);
5809 triggered_spell_id
= 26170;
5812 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
5815 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
5819 basepoints0
= int32(damage
* 2 / 100);
5821 triggered_spell_id
= 39373;
5824 // Vestments of Faith (Priest Tier 3) - 4 pieces bonus
5827 triggered_spell_id
= 28810;
5833 case SPELLFAMILY_DRUID
:
5835 switch(dummySpell
->Id
)
5837 // Healing Touch (Dreamwalker Raiment set)
5841 basepoints0
= int32(procSpell
->manaCost
* 30 / 100);
5843 triggered_spell_id
= 28742;
5846 // Healing Touch Refund (Idol of Longevity trinket)
5850 triggered_spell_id
= 28848;
5853 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
5858 triggered_spell_id
= 37238;
5861 // Druid Tier 6 Trinket
5867 if( procSpell
->SpellFamilyFlags
& 0x0000000000000004LL
)
5869 triggered_spell_id
= 40445;
5873 else if( procSpell
->SpellFamilyFlags
& 0x0000000000000010LL
)
5875 triggered_spell_id
= 40446;
5878 // Mangle (cat/bear)
5879 else if( procSpell
->SpellFamilyFlags
& 0x0000044000000000LL
)
5881 triggered_spell_id
= 40452;
5887 if (!roll_chance_f(chance
))
5896 // Deadly Interrupt Effect
5897 triggered_spell_id
= 32747;
5903 case SPELLFAMILY_ROGUE
:
5905 switch(dummySpell
->Id
)
5907 // Deadly Throw Interrupt
5910 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
5914 triggered_spell_id
= 32747;
5919 if( dummySpell
->SpellIconID
== 2116 )
5924 // only rogue's finishing moves (maybe need additional checks)
5925 if( procSpell
->SpellFamilyName
!=SPELLFAMILY_ROGUE
||
5926 (procSpell
->SpellFamilyFlags
& SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE
) == 0)
5930 basepoints0
= procSpell
->manaCost
* triggeredByAura
->GetModifier()->m_amount
/100;
5931 if(basepoints0
<= 0)
5935 triggered_spell_id
= 31663;
5940 case SPELLFAMILY_HUNTER
:
5942 // Thrill of the Hunt
5943 if ( dummySpell
->SpellIconID
== 2236 )
5949 basepoints0
= procSpell
->manaCost
* 40/100;
5950 if(basepoints0
<= 0)
5954 triggered_spell_id
= 34720;
5959 case SPELLFAMILY_PALADIN
:
5961 // Seal of Righteousness - melee proc dummy
5962 if (dummySpell
->SpellFamilyFlags
&0x000000008000000LL
&& triggeredByAura
->GetEffIndex()==0)
5964 if(GetTypeId() != TYPEID_PLAYER
)
5968 switch (triggeredByAura
->GetId())
5970 case 21084: spellId
= 25742; break; // Rank 1
5971 case 20287: spellId
= 25740; break; // Rank 2
5972 case 20288: spellId
= 25739; break; // Rank 3
5973 case 20289: spellId
= 25738; break; // Rank 4
5974 case 20290: spellId
= 25737; break; // Rank 5
5975 case 20291: spellId
= 25736; break; // Rank 6
5976 case 20292: spellId
= 25735; break; // Rank 7
5977 case 20293: spellId
= 25713; break; // Rank 8
5978 case 27155: spellId
= 27156; break; // Rank 9
5980 sLog
.outError("Unit::HandleDummyAuraProc: non handled possibly SoR (Id = %u)", triggeredByAura
->GetId());
5983 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
5984 float speed
= (item
? item
->GetProto()->Delay
: BASE_ATTACK_TIME
)/1000.0f
;
5986 float damageBasePoints
;
5987 if(item
&& item
->GetProto()->InventoryType
== INVTYPE_2HWEAPON
)
5989 damageBasePoints
=1.20f
*triggeredByAura
->GetModifier()->m_amount
* 1.2f
* 1.03f
* speed
/100.0f
+ 1;
5991 // one hand weapon/no weapon
5992 damageBasePoints
=0.85f
*ceil(triggeredByAura
->GetModifier()->m_amount
* 1.2f
* 1.03f
* speed
/100.0f
) - 1;
5994 int32 damagePoint
= int32(damageBasePoints
+ 0.03f
* (GetWeaponDamageRange(BASE_ATTACK
,MINDAMAGE
)+GetWeaponDamageRange(BASE_ATTACK
,MAXDAMAGE
))/2.0f
) + 1;
5996 // apply damage bonuses manually
5997 if(damagePoint
>= 0)
5998 damagePoint
= SpellDamageBonus(pVictim
, dummySpell
, damagePoint
, SPELL_DIRECT_DAMAGE
);
6000 CastCustomSpell(pVictim
,spellId
,&damagePoint
,NULL
,NULL
,true,NULL
, triggeredByAura
);
6001 return true; // no hidden cooldown
6003 // Seal of Blood do damage trigger
6004 if(dummySpell
->SpellFamilyFlags
& 0x0000040000000000LL
)
6006 switch(triggeredByAura
->GetEffIndex())
6009 triggered_spell_id
= 31893;
6014 damage
+= CalculateDamage(BASE_ATTACK
, false) * 35 / 100; // add spell damage from prev effect (35%)
6015 basepoints0
= triggeredByAura
->GetModifier()->m_amount
* damage
/ 100;
6018 triggered_spell_id
= 32221;
6024 switch(dummySpell
->Id
)
6026 // Holy Power (Redemption Armor set)
6032 // Set class defined buff
6033 switch (pVictim
->getClass())
6039 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6043 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6047 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
6050 triggered_spell_id
= 28790; // Increases the friendly target's armor
6060 if(effIndex
!= 0) // effect 1,2 used by seal unleashing code
6063 triggered_spell_id
= 31803;
6070 // if healed by another unit (pVictim)
6075 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*damage
/100;
6077 triggered_spell_id
= 31786;
6080 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
6088 // Flash of light/Holy light
6089 if( procSpell
->SpellFamilyFlags
& 0x00000000C0000000LL
)
6091 triggered_spell_id
= 40471;
6095 else if( procSpell
->SpellFamilyFlags
& 0x0000000000800000LL
)
6097 triggered_spell_id
= 40472;
6103 if (!roll_chance_f(chance
))
6111 case SPELLFAMILY_SHAMAN
:
6113 switch(dummySpell
->Id
)
6115 // Totemic Power (The Earthshatterer set)
6121 // Set class defined buff
6122 switch (pVictim
->getClass())
6128 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
6132 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
6136 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
6139 triggered_spell_id
= 28827; // Increases the friendly target's armor
6146 // Lesser Healing Wave (Totem of Flowing Water Relic)
6150 triggered_spell_id
= 28850;
6153 // Windfury Weapon (Passive) 1-5 Ranks
6156 if(GetTypeId()!=TYPEID_PLAYER
)
6159 if(!castItem
|| !castItem
->IsEquipped())
6162 // custom cooldown processing case
6163 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6167 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
6169 case 283: spellId
= 33757; break; //1 Rank
6170 case 284: spellId
= 33756; break; //2 Rank
6171 case 525: spellId
= 33755; break; //3 Rank
6172 case 1669:spellId
= 33754; break; //4 Rank
6173 case 2636:spellId
= 33727; break; //5 Rank
6176 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
6177 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
6182 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
6183 if(!windfurySpellEntry
)
6185 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
6189 int32 extra_attack_power
= CalculateSpellDamage(windfurySpellEntry
,0,windfurySpellEntry
->EffectBasePoints
[0],pVictim
);
6192 if ( castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
6194 // Value gained from additional AP
6195 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
6196 triggered_spell_id
= 33750;
6201 // Value gained from additional AP
6202 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
6203 triggered_spell_id
= 25504;
6206 // apply cooldown before cast to prevent processing itself
6208 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6211 for ( uint32 i
= 0; i
<2; ++i
)
6212 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6216 // Shaman Tier 6 Trinket
6223 if (procSpell
->SpellFamilyFlags
& 0x0000000000000001LL
)
6225 triggered_spell_id
= 40465; // Lightning Bolt
6228 else if (procSpell
->SpellFamilyFlags
& 0x0000000000000080LL
)
6230 triggered_spell_id
= 40465; // Lesser Healing Wave
6233 else if (procSpell
->SpellFamilyFlags
& 0x0000001000000000LL
)
6235 triggered_spell_id
= 40466; // Stormstrike
6241 if (!roll_chance_f(chance
))
6250 if(dummySpell
->SpellFamilyFlags
==0x40000000000LL
)
6252 if(GetTypeId() != TYPEID_PLAYER
)
6256 basepoints0
= triggeredByAura
->GetModifier()->m_amount
;
6258 triggered_spell_id
= 379;
6261 // Lightning Overload
6262 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
6264 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
6267 // custom cooldown processing case
6268 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
6272 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
6273 switch (procSpell
->Id
)
6276 case 403: spellId
= 45284; break; // Rank 1
6277 case 529: spellId
= 45286; break; // Rank 2
6278 case 548: spellId
= 45287; break; // Rank 3
6279 case 915: spellId
= 45288; break; // Rank 4
6280 case 943: spellId
= 45289; break; // Rank 5
6281 case 6041: spellId
= 45290; break; // Rank 6
6282 case 10391: spellId
= 45291; break; // Rank 7
6283 case 10392: spellId
= 45292; break; // Rank 8
6284 case 15207: spellId
= 45293; break; // Rank 9
6285 case 15208: spellId
= 45294; break; // Rank 10
6286 case 25448: spellId
= 45295; break; // Rank 11
6287 case 25449: spellId
= 45296; break; // Rank 12
6289 case 421: spellId
= 45297; break; // Rank 1
6290 case 930: spellId
= 45298; break; // Rank 2
6291 case 2860: spellId
= 45299; break; // Rank 3
6292 case 10605: spellId
= 45300; break; // Rank 4
6293 case 25439: spellId
= 45301; break; // Rank 5
6294 case 25442: spellId
= 45302; break; // Rank 6
6296 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
6299 // No thread generated mod
6300 SpellModifier
*mod
= new SpellModifier
;
6301 mod
->op
= SPELLMOD_THREAT
;
6303 mod
->type
= SPELLMOD_PCT
;
6304 mod
->spellId
= dummySpell
->Id
;
6306 mod
->lastAffected
= NULL
;
6307 mod
->mask
= 0x0000000000000003LL
;
6309 ((Player
*)this)->AddSpellMod(mod
, true);
6311 // Remove cooldown (Chain Lightning - have Category Recovery time)
6312 if (procSpell
->SpellFamilyFlags
& 0x0000000000000002LL
)
6313 ((Player
*)this)->RemoveSpellCooldown(spellId
);
6315 // Hmmm.. in most case spells already set half basepoints but...
6316 // Lightning Bolt (2-10 rank) have full basepoint and half bonus from level
6318 // BUG: Rank 2 to 10 (and maybe 11) of Lightning Bolt will proc another Bolt with FULL damage (not halved). This bug is known and will probably be fixed soon.
6319 // So - no add changes :)
6320 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
6322 ((Player
*)this)->AddSpellMod(mod
, false);
6324 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6325 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
6335 // processed charge only counting case
6336 if(!triggered_spell_id
)
6339 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6343 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
6348 if(!target
|| target
!=this && !target
->isAlive())
6351 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
6355 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6357 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
6359 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6360 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
6365 bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const *procSpell, uint32 procFlags,WeaponAttackType attackType, uint32 cooldown)
6367 SpellEntry const* auraSpellInfo = triggeredByAura->GetSpellProto();
6369 Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
6370 ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL;
6372 uint32 triggered_spell_id = auraSpellInfo->EffectTriggerSpell[triggeredByAura->GetEffIndex()];
6373 Unit* target = !(procFlags & PROC_FLAG_HEAL) && IsPositiveSpell(triggered_spell_id) ? this : pVictim;
6374 int32 basepoints0 = 0;
6376 switch(auraSpellInfo->SpellFamilyName)
6378 case SPELLFAMILY_GENERIC:
6380 switch(auraSpellInfo->Id)
6382 // Aegis of Preservation
6384 //Aegis Heal (instead non-existed triggered spell)
6385 triggered_spell_id = 23781;
6388 // Elune's Touch (moonkin mana restore)
6391 // Elune's Touch (instead non-existed triggered spell)
6392 triggered_spell_id = 33926;
6393 basepoints0 = int32(0.3f * GetTotalAttackPowerValue(BASE_ATTACK));
6400 // only for cast with mana price
6401 if(!procSpell || procSpell->powerType!=POWER_MANA || procSpell->manaCost==0 && procSpell->ManaCostPercentage==0 && procSpell->manaCostPerlevel==0)
6403 break; // fall through to normal cast
6408 // at melee hit call std triggered spell
6409 if(procFlags & PROC_FLAG_HIT_MELEE)
6410 break; // fall through to normal cast
6412 // Mark of Conquest - else (at range hit) called custom case
6413 triggered_spell_id = 39557;
6419 return true; // nothing to do
6420 // Forgotten Knowledge (Blade of Wizardry)
6422 // only for harmful enemy targeted spell
6423 if(!pVictim || pVictim==this || !procSpell || IsPositiveSpell(procSpell->Id))
6425 break; // fall through to normal cast
6426 // Aura of Wrath (Darkmoon Card: Wrath trinket bonus)
6429 // proc only at non-crit hits
6430 if(procFlags & (PROC_FLAG_CRIT_MELEE|PROC_FLAG_CRIT_RANGED|PROC_FLAG_CRIT_SPELL))
6432 break; // fall through to normal cast
6434 // Augment Pain (Timbal's Focusing Crystal trinket bonus)
6440 //only periodic damage can trigger spell
6442 for(int j = 0; j < 3; ++j)
6444 if( procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE ||
6445 procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE_PERCENT ||
6446 procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_LEECH )
6455 break; // fall through to normal cast
6457 // Evasive Maneuvers (Commendation of Kael'thas)
6460 // damage taken that reduces below 35% health
6461 // does NOT mean you must have been >= 35% before
6462 if (int32(GetHealth())-int32(damage) >= int32(GetMaxHealth()*0.35f))
6464 break; // fall through to normal cast
6468 switch(triggered_spell_id)
6473 // applied only for main target
6474 if(!pVictim || pVictim != getVictim())
6477 // continue normal case
6480 // Shamanistic Rage triggered spell
6482 basepoints0 = int32(GetTotalAttackPowerValue(BASE_ATTACK)*triggeredByAura->GetModifier()->m_amount/100);
6487 case SPELLFAMILY_MAGE:
6489 switch(auraSpellInfo->SpellIconID)
6493 //Blazing Speed (instead non-existed triggered spell)
6494 triggered_spell_id = 31643;
6498 switch(auraSpellInfo->Id)
6500 // Persistent Shield (Scarab Brooch)
6502 basepoints0 = int32(damage * 0.15f);
6507 case SPELLFAMILY_WARRIOR:
6510 if((auraSpellInfo->SpellFamilyFlags & 0x100000) && auraSpellInfo->SpellIconID==2006)
6512 //all ranks have effect[0]==AURA (Proc Trigger Spell, non-existed)
6513 //and effect[1]==TriggerSpell
6514 if(auraSpellInfo->Effect[1]!=SPELL_EFFECT_TRIGGER_SPELL)
6516 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have wrong effect in RM",triggeredByAura->GetSpellProto()->Id);
6519 triggered_spell_id = auraSpellInfo->EffectTriggerSpell[1];
6520 break; // fall through to normal cast
6524 case SPELLFAMILY_WARLOCK:
6527 if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000 && auraSpellInfo->SpellIconID==1137)
6529 // last case for Hellfire that damage caster also but don't must stun caster
6530 if( pVictim == this )
6535 switch (triggeredByAura->GetId())
6537 case 18096: chance = 13.0f; break;
6538 case 18073: chance = 26.0f; break;
6540 if (!roll_chance_f(chance))
6543 // Pyroclasm (instead non-existed triggered spell)
6544 triggered_spell_id = 18093;
6549 if(auraSpellInfo->SpellFamilyFlags & 0x0000000000004000)
6552 Unit::AuraList const& mAddFlatModifier = GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER);
6553 for(Unit::AuraList::const_iterator i = mAddFlatModifier.begin(); i != mAddFlatModifier.end(); ++i)
6555 //Improved Drain Soul
6556 if ((*i)->GetModifier()->m_miscvalue == SPELLMOD_CHANCE_OF_SUCCESS && (*i)->GetSpellProto()->SpellIconID == 113)
6558 int32 value2 = CalculateSpellDamage((*i)->GetSpellProto(),2,(*i)->GetSpellProto()->EffectBasePoints[2],this);
6559 basepoints0 = value2 * GetMaxPower(POWER_MANA) / 100;
6562 triggered_spell_id = 18371;
6570 break; // fall through to normal cast
6574 case SPELLFAMILY_PRIEST:
6577 if(auraSpellInfo->SpellFamilyFlags == 0x00000000LL && auraSpellInfo->SpellIconID==1875)
6579 switch (triggeredByAura->GetSpellProto()->Id)
6581 case 27811: triggered_spell_id = 27813; break;
6582 case 27815: triggered_spell_id = 27817; break;
6583 case 27816: triggered_spell_id = 27818; break;
6585 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR",triggeredByAura->GetSpellProto()->Id);
6589 int32 heal_amount = damage * triggeredByAura->GetModifier()->m_amount / 100;
6590 basepoints0 = heal_amount/3;
6595 if((auraSpellInfo->SpellFamilyFlags & 0x80000000LL) && auraSpellInfo->SpellVisual==7958)
6597 switch(triggeredByAura->GetSpellProto()->Id)
6600 triggered_spell_id = 28377; break; // Rank 1
6602 triggered_spell_id = 28378; break; // Rank 2
6604 triggered_spell_id = 28379; break; // Rank 3
6606 triggered_spell_id = 28380; break; // Rank 4
6608 triggered_spell_id = 28381; break; // Rank 5
6610 triggered_spell_id = 28382; break; // Rank 6
6612 triggered_spell_id = 28385; break; // Rank 7
6614 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in SG",triggeredByAura->GetSpellProto()->Id);
6622 case SPELLFAMILY_DRUID:
6624 switch(auraSpellInfo->Id)
6626 // Leader of the Pack (triggering Improved Leader of the Pack heal)
6629 if (triggeredByAura->GetModifier()->m_amount == 0)
6631 basepoints0 = triggeredByAura->GetModifier()->m_amount * GetMaxHealth() / 100;
6632 triggered_spell_id = 34299;
6635 // Druid Forms Trinket (Druid Tier5 Trinket, triggers different spells per Form)
6642 triggered_spell_id=37340; break;// Ursine Blessing
6644 triggered_spell_id=37341; break;// Feline Blessing
6646 triggered_spell_id=37342; break;// Slyvan Blessing
6648 triggered_spell_id=37343; break;// Lunar Blessing
6650 triggered_spell_id=37344; break;// Cenarion Blessing (for caster form, except FORM_MOONKIN)
6661 case SPELLFAMILY_ROGUE:
6663 if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000LL)
6665 switch(auraSpellInfo->SpellIconID)
6670 // skip non offhand attacks
6671 if(attackType!=OFF_ATTACK)
6673 break; // fall through to normal cast
6679 case SPELLFAMILY_PALADIN:
6681 if(auraSpellInfo->SpellFamilyFlags == 0x00000000LL)
6683 switch(auraSpellInfo->Id)
6685 // Lightning Capacitor
6688 // trinket ProcTriggerSpell but for safe checks for player
6689 if(!castItem || !pVictim || !pVictim->isAlive() || GetTypeId()!=TYPEID_PLAYER)
6692 if(((Player*)this)->HasSpellCooldown(37657))
6696 CastSpell(this, 37658, true, castItem, triggeredByAura);
6697 // 2.5s cooldown before it can stack again, current system allow 1 sec step in cooldown
6698 ((Player*)this)->AddSpellCooldown(37657,0,time(NULL)+(roll_chance_i(50) ? 2 : 3));
6702 AuraList const& dummyAura = GetAurasByType(SPELL_AURA_DUMMY);
6703 for(AuraList::const_iterator itr = dummyAura.begin(); itr != dummyAura.end(); ++itr)
6704 if((*itr)->GetId()==37658)
6707 // release at 3 aura in stack
6709 return true; // main triggered spell casted anyway
6711 RemoveAurasDueToSpell(37658);
6712 CastSpell(pVictim, 37661, true, castItem, triggeredByAura);
6717 // Healing Trance (instead non-existed triggered spell)
6718 triggered_spell_id = 37706;
6721 // HoTs on Heals (Fel Reaver's Piston trinket)
6724 // at direct heal effect
6725 if(!procSpell || !IsSpellHaveEffect(procSpell,SPELL_EFFECT_HEAL))
6728 // single proc at time
6729 AuraList const& scAuras = GetSingleCastAuras();
6730 for(AuraList::const_iterator itr = scAuras.begin(); itr != scAuras.end(); ++itr)
6731 if((*itr)->GetId()==triggered_spell_id)
6734 // positive cast at victim instead self
6739 switch(auraSpellInfo->SpellIconID)
6743 switch(auraSpellInfo->EffectTriggerSpell[0])
6751 // procspell is triggered spell but we need mana cost of original casted spell
6752 uint32 originalSpellId = procSpell->Id;
6755 if(procSpell->SpellFamilyName == SPELLFAMILY_PALADIN)
6757 if(procSpell->SpellFamilyFlags & 0x0001000000000000LL)
6759 switch(procSpell->Id)
6761 case 25914: originalSpellId = 20473; break;
6762 case 25913: originalSpellId = 20929; break;
6763 case 25903: originalSpellId = 20930; break;
6764 case 27175: originalSpellId = 27174; break;
6765 case 33074: originalSpellId = 33072; break;
6767 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell->Id);
6773 SpellEntry const *originalSpell = sSpellStore.LookupEntry(originalSpellId);
6776 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId);
6780 // percent stored in effect 1 (class scripts) base points
6781 int32 percent = auraSpellInfo->EffectBasePoints[1]+1;
6783 basepoints0 = originalSpell->manaCost*percent/100;
6784 triggered_spell_id = 20272;
6793 if(auraSpellInfo->SpellFamilyFlags & 0x00080000)
6795 switch(auraSpellInfo->SpellIconID)
6797 //Judgement of Wisdom (overwrite non existing triggered spell call in spell.dbc
6800 if(!pVictim || !pVictim->isAlive())
6803 switch(triggeredByAura->GetSpellProto()->Id)
6806 triggered_spell_id = 20268; // Rank 1
6809 triggered_spell_id = 20352; // Rank 2
6812 triggered_spell_id = 20353; // Rank 3
6815 triggered_spell_id = 27165; // Rank 4
6818 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in JoW",triggeredByAura->GetSpellProto()->Id);
6822 pVictim->CastSpell(pVictim,triggered_spell_id,true,castItem,triggeredByAura,GetGUID());
6823 return true; // no hidden cooldown
6825 //Judgement of Light
6828 if(!pVictim || !pVictim->isAlive())
6831 // overwrite non existing triggered spell call in spell.dbc
6832 switch(triggeredByAura->GetSpellProto()->Id)
6835 triggered_spell_id = 20267; // Rank 1
6838 triggered_spell_id = 20341; // Rank 2
6841 triggered_spell_id = 20342; // Rank 3
6844 triggered_spell_id = 20343; // Rank 4
6847 triggered_spell_id = 27163; // Rank 5
6850 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in JoL",triggeredByAura->GetSpellProto()->Id);
6853 pVictim->CastSpell(pVictim,triggered_spell_id,true,castItem,triggeredByAura,GetGUID());
6854 return true; // no hidden cooldown
6858 // custom check for proc spell
6859 switch(auraSpellInfo->Id)
6861 // Bonus Healing (item spell)
6864 if(!pVictim || !pVictim->isAlive())
6867 // bonus if health < 50%
6868 if(pVictim->GetHealth() >= pVictim->GetMaxHealth()*triggeredByAura->GetModifier()->m_amount/100)
6871 // cast at target positive spell
6876 switch(triggered_spell_id)
6880 // prevent chain of triggered spell from same triggered spell
6881 if(procSpell && procSpell->Id==20424)
6887 case SPELLFAMILY_SHAMAN:
6889 if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000)
6891 switch(auraSpellInfo->SpellIconID)
6895 switch(auraSpellInfo->Id)
6897 case 23551: // Lightning Shield - Tier2: 8 pieces proc shield
6899 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc)
6900 triggered_spell_id = 23552;
6904 case 23552: // Lightning Shield - trigger shield damage
6906 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc)
6907 triggered_spell_id = 27635;
6914 // Mana Surge (Shaman T1 bonus)
6920 basepoints0 = procSpell->manaCost * 35/100;
6921 triggered_spell_id = 23571;
6928 if(GetTypeId()!=TYPEID_PLAYER)
6931 // damage taken that reduces below 30% health
6932 // does NOT mean you must have been >= 30% before
6933 if (10*(int32(GetHealth())-int32(damage)) >= 3*GetMaxHealth())
6936 triggered_spell_id = 31616;
6938 // need check cooldown now
6939 if( cooldown && ((Player*)this)->HasSpellCooldown(triggered_spell_id))
6942 basepoints0 = triggeredByAura->GetModifier()->m_amount * GetMaxHealth() / 100;
6944 if(pVictim && pVictim->isAlive())
6945 pVictim->getThreatManager().modifyThreatPercent(this,-10);
6951 // Water Shield (we can't set cooldown for main spell - it's player casted spell
6952 if((auraSpellInfo->SpellFamilyFlags & 0x0000002000000000LL) && auraSpellInfo->SpellVisual==7358)
6959 if((auraSpellInfo->SpellFamilyFlags & 0x00000400) && auraSpellInfo->SpellVisual==37)
6961 // overwrite non existing triggered spell call in spell.dbc
6962 switch(triggeredByAura->GetSpellProto()->Id)
6965 triggered_spell_id = 26364; break; // Rank 1
6967 triggered_spell_id = 26365; break; // Rank 2
6969 triggered_spell_id = 26366; break; // Rank 3
6971 triggered_spell_id = 26367; break; // Rank 4
6973 triggered_spell_id = 26369; break; // Rank 5
6975 triggered_spell_id = 26370; break; // Rank 6
6977 triggered_spell_id = 26363; break; // Rank 7
6979 triggered_spell_id = 26371; break; // Rank 8
6981 triggered_spell_id = 26372; break; // Rank 9
6983 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield",triggeredByAura->GetSpellProto()->Id);
6994 // standard non-dummy case
6995 if(!triggered_spell_id)
6997 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
7001 SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id);
7005 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have not existed EffectTriggered[%d]=%u, not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex(),triggered_spell_id);
7009 // not allow proc extra attack spell at extra attack
7010 if( m_extraAttacks && IsSpellHaveEffect(triggerEntry,SPELL_EFFECT_ADD_EXTRA_ATTACKS) )
7013 if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id))
7017 if(!target || target!=this && !target->isAlive())
7021 CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura);
7023 CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura);
7025 if( cooldown && GetTypeId()==TYPEID_PLAYER )
7026 ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown);
7032 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
7034 // Get triggered aura spell info
7035 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
7037 // Basepoints of trigger aura
7038 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
7040 // Set trigger spell id, target, custom basepoints
7041 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
7042 Unit
* target
= NULL
;
7043 int32 basepoints0
= 0;
7045 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7046 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7048 // Try handle uncnown trigger spells
7049 if (sSpellStore
.LookupEntry(trigger_spell_id
)==NULL
)
7050 switch (auraSpellInfo
->SpellFamilyName
)
7052 //=====================================================================
7054 // ====================================================================
7056 //=====================================================================
7057 case SPELLFAMILY_GENERIC
:
7058 // if (auraSpellInfo->Id==34082) // Advantaged State (DND)
7059 // trigger_spell_id = ???;
7060 if (auraSpellInfo
->Id
== 23780) // Aegis of Preservation (Aegis of Preservation trinket)
7061 trigger_spell_id
= 23781;
7062 // else if (auraSpellInfo->Id==43504) // Alterac Valley OnKill Proc Aura
7063 // trigger_spell_id = ;
7064 // else if (auraSpellInfo->Id==37030) // Chaotic Temperament
7065 // trigger_spell_id = ;
7066 else if (auraSpellInfo
->Id
==43820) // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
7068 // Pct value stored in dummy
7069 basepoints0
= pVictim
->GetCreateHealth() * auraSpellInfo
->EffectBasePoints
[1] / 100;
7073 // else if (auraSpellInfo->Id==41248) // Consuming Strikes
7074 // trigger_spell_id = 41249;
7075 // else if (auraSpellInfo->Id==41054) // Copy Weapon
7076 // trigger_spell_id = 41055;
7077 // else if (auraSpellInfo->Id==31255) // Deadly Swiftness (Rank 1)
7078 // trigger_spell_id = ;
7079 // else if (auraSpellInfo->Id==5301) // Defensive State (DND)
7080 // trigger_spell_id = ;
7081 // else if (auraSpellInfo->Id==13358) // Defensive State (DND)
7082 // trigger_spell_id = ;
7083 // else if (auraSpellInfo->Id==16092) // Defensive State (DND)
7084 // trigger_spell_id = ;
7085 // else if (auraSpellInfo->Id==24949) // Defensive State 2 (DND)
7086 // trigger_spell_id = ;
7087 // else if (auraSpellInfo->Id==40329) // Demo Shout Sensor
7088 // trigger_spell_id = ;
7089 // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
7090 else if (auraSpellInfo
->Id
== 33896)
7091 trigger_spell_id
= 33898;
7092 // else if (auraSpellInfo->Id==18943) // Double Attack
7093 // trigger_spell_id = ;
7094 // else if (auraSpellInfo->Id==19194) // Double Attack
7095 // trigger_spell_id = ;
7096 // else if (auraSpellInfo->Id==19817) // Double Attack
7097 // trigger_spell_id = ;
7098 // else if (auraSpellInfo->Id==19818) // Double Attack
7099 // trigger_spell_id = ;
7100 // else if (auraSpellInfo->Id==22835) // Drunken Rage
7101 // trigger_spell_id = 14822;
7103 else if (auraSpellInfo->SpellIconID==191) // Elemental Response
7105 switch (auraSpellInfo->Id && auraSpellInfo->AttributesEx==0)
7113 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Elemental Response",auraSpellInfo->Id);
7116 //This generic aura self-triggers a different spell for each school of magic that lands on the wearer:
7117 switch (procSpell->School)
7119 case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192;break;//Fire: 34192
7120 case SPELL_SCHOOL_FROST: trigger_spell_id = 34193;break;//Frost: 34193
7121 case SPELL_SCHOOL_ARCANE: trigger_spell_id = 34194;break;//Arcane: 34194
7122 case SPELL_SCHOOL_NATURE: trigger_spell_id = 34195;break;//Nature: 34195
7123 case SPELL_SCHOOL_SHADOW: trigger_spell_id = 34196;break;//Shadow: 34196
7124 case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197;break;//Holy: 34197
7125 case SPELL_SCHOOL_NORMAL: trigger_spell_id = 34198;break;//Physical: 34198
7127 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u Elemental Response wrong school",auraSpellInfo->Id);
7131 // else if (auraSpellInfo->Id==6542) // Enraged Defense
7132 // trigger_spell_id = ;
7133 // else if (auraSpellInfo->Id==40364) // Entangling Roots Sensor
7134 // trigger_spell_id = ;
7135 // else if (auraSpellInfo->Id==33207) // Gossip NPC Periodic - Fidget
7136 // trigger_spell_id = ;
7137 // else if (auraSpellInfo->Id==35321) // Gushing Wound
7138 // trigger_spell_id = ;
7139 // else if (auraSpellInfo->Id==38363) // Gushing Wound
7140 // trigger_spell_id = ;
7141 // else if (auraSpellInfo->Id==39215) // Gushing Wound
7142 // trigger_spell_id = ;
7143 // else if (auraSpellInfo->Id==40250) // Improved Duration
7144 // trigger_spell_id = ;
7145 else if (auraSpellInfo
->Id
==27522) // Mana Drain Trigger
7147 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
7148 if (this && this->isAlive())
7149 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
7150 if (pVictim
&& pVictim
->isAlive())
7151 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
7154 else if (auraSpellInfo
->Id
==24905) // Moonkin Form (Passive)
7156 // Elune's Touch (instead non-existed triggered spell) 30% from AP
7157 trigger_spell_id
= 33926;
7158 basepoints0
= GetTotalAttackPowerValue(BASE_ATTACK
) * 30 / 100;
7161 // else if (auraSpellInfo->Id==43453) // Rune Ward
7162 // trigger_spell_id = ;
7163 // else if (auraSpellInfo->Id==7137) // Shadow Charge (Rank 1)
7164 // trigger_spell_id = ;
7165 // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
7166 // else if (auraSpellInfo->Id==36576)
7167 // trigger_spell_id = ;
7168 // else if (auraSpellInfo->Id==34783) // Spell Reflection
7169 // trigger_spell_id = ;
7170 // else if (auraSpellInfo->Id==36096) // Spell Reflection
7171 // trigger_spell_id = ;
7172 // else if (auraSpellInfo->Id==36207) // Steal Weapon
7173 // trigger_spell_id = ;
7174 // else if (auraSpellInfo->Id==35205) // Vanish
7176 //=====================================================================
7178 //=====================================================================
7179 // Blazing Speed (Rank 1,2) trigger = 18350
7180 //=====================================================================
7181 case SPELLFAMILY_MAGE
:
7183 if (auraSpellInfo
->SpellIconID
== 2127)
7185 switch (auraSpellInfo
->Id
)
7187 case 31641: // Rank 1
7188 case 31642: // Rank 2
7189 trigger_spell_id
= 31643;
7192 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
7197 //=====================================================================
7199 //=====================================================================
7200 // Rampage (Rank 1-3) trigger = 18350
7201 //=====================================================================
7202 case SPELLFAMILY_WARRIOR
:
7204 if (auraSpellInfo
->SpellIconID
== 2006 && auraSpellInfo
->SpellFamilyFlags
==0x100000)
7206 switch(auraSpellInfo
->Id
)
7208 case 29801: trigger_spell_id
= 30029; break; // Rank 1
7209 case 30030: trigger_spell_id
= 30031; break; // Rank 2
7210 case 30033: trigger_spell_id
= 30032; break; // Rank 3
7212 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in Rampage",auraSpellInfo
->Id
);
7217 //=====================================================================
7219 //=====================================================================
7220 // Pyroclasm trigger = 18350
7221 // Drain Soul (Rank 1-5) trigger = 0
7222 //=====================================================================
7223 case SPELLFAMILY_WARLOCK
:
7226 if (auraSpellInfo
->SpellIconID
== 1137)
7228 if(!pVictim
|| !pVictim
->isAlive() || pVictim
== this || procSpell
== NULL
)
7230 // Calculate spell tick count for spells
7231 uint32 tick
= 1; // Default tick = 1
7233 // Hellfire have 15 tick
7234 if (procSpell
->SpellFamilyFlags
&0x0000000000000040LL
)
7236 // Rain of Fire have 4 tick
7237 else if (procSpell
->SpellFamilyFlags
&0x0000000000000020LL
)
7242 // Calculate chance = baseChance / tick
7244 switch (auraSpellInfo
->Id
)
7246 case 18096: chance
= 13.0f
/ tick
; break;
7247 case 18073: chance
= 26.0f
/ tick
; break;
7250 if (!roll_chance_f(chance
))
7253 trigger_spell_id
= 18093;
7256 else if (auraSpellInfo
->SpellFamilyFlags
& 0x0000000000004000LL
)
7258 Unit::AuraList
const& mAddFlatModifier
= GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER
);
7259 for(Unit::AuraList::const_iterator i
= mAddFlatModifier
.begin(); i
!= mAddFlatModifier
.end(); ++i
)
7261 if ((*i
)->GetModifier()->m_miscvalue
== SPELLMOD_CHANCE_OF_SUCCESS
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
7263 int32 value2
= CalculateSpellDamage((*i
)->GetSpellProto(),2,(*i
)->GetSpellProto()->EffectBasePoints
[2],this);
7264 basepoints0
= value2
* GetMaxPower(POWER_MANA
) / 100;
7267 if ( basepoints0
== 0 )
7269 trigger_spell_id
= 18371;
7273 //=====================================================================
7275 //=====================================================================
7276 // Greater Heal Refund trigger = 18350
7277 // Blessed Recovery (Rank 1-3) trigger = 18350
7278 // Shadowguard (1-7) trigger = 28376
7279 //=====================================================================
7280 case SPELLFAMILY_PRIEST
:
7282 // Greater Heal Refund
7283 if (auraSpellInfo
->Id
==37594)
7284 trigger_spell_id
= 37595;
7286 else if(auraSpellInfo
->SpellFamilyFlags
==0x100080000000LL
&& auraSpellInfo
->SpellVisual
==7958)
7288 switch(auraSpellInfo
->Id
)
7290 case 18137: trigger_spell_id
= 28377; break; // Rank 1
7291 case 19308: trigger_spell_id
= 28378; break; // Rank 2
7292 case 19309: trigger_spell_id
= 28379; break; // Rank 3
7293 case 19310: trigger_spell_id
= 28380; break; // Rank 4
7294 case 19311: trigger_spell_id
= 28381; break; // Rank 5
7295 case 19312: trigger_spell_id
= 28382; break; // Rank 6
7296 case 25477: trigger_spell_id
= 28385; break; // Rank 7
7298 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in SG", auraSpellInfo
->Id
);
7303 else if (auraSpellInfo
->SpellIconID
== 1875)
7305 switch (auraSpellInfo
->Id
)
7307 case 27811: trigger_spell_id
= 27813; break;
7308 case 27815: trigger_spell_id
= 27817; break;
7309 case 27816: trigger_spell_id
= 27818; break;
7311 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
7314 basepoints0
= damage
* triggerAmount
/ 100 / 3;
7319 //=====================================================================
7321 // ====================================================================
7322 // Druid Forms Trinket trigger = 18350
7323 // Entangling Roots trigger = 30023
7324 // Leader of the Pack trigger = 18350
7325 //=====================================================================
7326 case SPELLFAMILY_DRUID
:
7328 // Druid Forms Trinket
7329 if (auraSpellInfo
->Id
==37336)
7333 case 0: trigger_spell_id
= 37344;break;
7334 case FORM_CAT
: trigger_spell_id
= 37341;break;
7336 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
7337 case FORM_TREE
: trigger_spell_id
= 37342;break;
7338 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
7343 // else if (auraSpellInfo->Id==40363)// Entangling Roots ()
7344 // trigger_spell_id = ????;
7345 // Leader of the Pack
7346 else if (auraSpellInfo
->Id
== 24932)
7348 if (triggerAmount
== 0)
7350 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
7351 trigger_spell_id
= 34299;
7355 //=====================================================================
7357 // ====================================================================
7359 //=====================================================================
7360 case SPELLFAMILY_HUNTER
:
7362 //=====================================================================
7364 // ====================================================================
7365 // Blessed Life trigger = 31934
7366 // Healing Discount trigger = 18350
7367 // Illumination (Rank 1-5) trigger = 18350
7368 // Judgement of Light (Rank 1-5) trigger = 5373
7369 // Judgement of Wisdom (Rank 1-4) trigger = 1826
7370 // Lightning Capacitor trigger = 18350
7371 //=====================================================================
7372 case SPELLFAMILY_PALADIN
:
7375 if (auraSpellInfo->SpellIconID == 2137)
7377 switch (auraSpellInfo->Id)
7379 case 31828: // Rank 1
7380 case 31829: // Rank 2
7381 case 31830: // Rank 3
7384 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
7389 if (auraSpellInfo
->Id
==37705)
7391 trigger_spell_id
= 37706;
7394 // Judgement of Light and Judgement of Wisdom
7395 else if (auraSpellInfo
->SpellFamilyFlags
& 0x0000000000080000LL
)
7397 switch (auraSpellInfo
->Id
)
7399 // Judgement of Light
7400 case 20185: trigger_spell_id
= 20267;break; // Rank 1
7401 case 20344: trigger_spell_id
= 20341;break; // Rank 2
7402 case 20345: trigger_spell_id
= 20342;break; // Rank 3
7403 case 20346: trigger_spell_id
= 20343;break; // Rank 4
7404 case 27162: trigger_spell_id
= 27163;break; // Rank 5
7405 // Judgement of Wisdom
7406 case 20186: trigger_spell_id
= 20268;break; // Rank 1
7407 case 20354: trigger_spell_id
= 20352;break; // Rank 2
7408 case 20355: trigger_spell_id
= 20353;break; // Rank 3
7409 case 27164: trigger_spell_id
= 27165;break; // Rank 4
7411 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Judgement of Light/Wisdom", auraSpellInfo
->Id
);
7414 pVictim
->CastSpell(pVictim
, trigger_spell_id
, true, castItem
, triggeredByAura
);
7415 return true; // no hidden cooldown
7418 else if (auraSpellInfo
->SpellIconID
==241)
7422 // procspell is triggered spell but we need mana cost of original casted spell
7423 uint32 originalSpellId
= procSpell
->Id
;
7425 if(procSpell
->SpellFamilyFlags
& 0x00200000)
7427 switch(procSpell
->Id
)
7429 case 25914: originalSpellId
= 20473; break;
7430 case 25913: originalSpellId
= 20929; break;
7431 case 25903: originalSpellId
= 20930; break;
7432 case 27175: originalSpellId
= 27174; break;
7433 case 33074: originalSpellId
= 33072; break;
7435 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
7439 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
7442 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
7445 // percent stored in effect 1 (class scripts) base points
7446 basepoints0
= originalSpell
->manaCost
*(auraSpellInfo
->EffectBasePoints
[1]+1)/100;
7447 trigger_spell_id
= 20272;
7450 // Lightning Capacitor
7451 else if (auraSpellInfo
->Id
==37657)
7453 if(!pVictim
|| !pVictim
->isAlive())
7456 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
7459 AuraList
const& dummyAura
= GetAurasByType(SPELL_AURA_DUMMY
);
7460 for(AuraList::const_iterator itr
= dummyAura
.begin(); itr
!= dummyAura
.end(); ++itr
)
7461 if((*itr
)->GetId()==37658)
7463 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
7464 if(count
< triggerAmount
)
7467 RemoveAurasDueToSpell(37658);
7468 trigger_spell_id
= 37661;
7473 //=====================================================================
7475 //====================================================================
7476 // Lightning Shield trigger = 18350
7477 // Mana Surge trigger = 18350
7478 // Nature's Guardian (Rank 1-5) trigger = 18350
7479 //=====================================================================
7480 case SPELLFAMILY_SHAMAN
:
7482 //Lightning Shield (overwrite non existing triggered spell call in spell.dbc
7483 if(auraSpellInfo
->SpellFamilyFlags
==0x00000400 && auraSpellInfo
->SpellVisual
==37)
7485 switch(auraSpellInfo
->Id
)
7487 case 324: trigger_spell_id
= 26364; break; // Rank 1
7488 case 325: trigger_spell_id
= 26365; break; // Rank 2
7489 case 905: trigger_spell_id
= 26366; break; // Rank 3
7490 case 945: trigger_spell_id
= 26367; break; // Rank 4
7491 case 8134: trigger_spell_id
= 26369; break; // Rank 5
7492 case 10431: trigger_spell_id
= 26370; break; // Rank 6
7493 case 10432: trigger_spell_id
= 26363; break; // Rank 7
7494 case 25469: trigger_spell_id
= 26371; break; // Rank 8
7495 case 25472: trigger_spell_id
= 26372; break; // Rank 9
7497 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
7501 // Lightning Shield (The Ten Storms set)
7502 else if (auraSpellInfo
->Id
== 23551)
7504 trigger_spell_id
= 23552;
7507 // Damage from Lightning Shield (The Ten Storms set)
7508 else if (auraSpellInfo
->Id
== 23552)
7509 trigger_spell_id
= 27635;
7510 // Mana Surge (The Earthfury set)
7511 else if (auraSpellInfo
->Id
== 23572)
7515 basepoints0
= procSpell
->manaCost
* 35 / 100;
7516 trigger_spell_id
= 23571;
7519 else if (auraSpellInfo
->SpellIconID
== 2013) //Nature's Guardian
7521 // Check health condition - should drop to less 30% (damage deal after this!)
7522 if (!(10*(int32(GetHealth() - damage
)) < 3 * GetMaxHealth()))
7525 if(pVictim
&& pVictim
->isAlive())
7526 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
7528 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
7529 trigger_spell_id
= 31616;
7539 // All ok. Check current trigger spell
7540 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
7541 if ( triggerEntry
== NULL
)
7543 // Not cast unknown spell
7544 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
7548 // not allow proc extra attack spell at extra attack
7549 if( m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
) )
7552 // Costum requirements (not listed in procEx) Warning! damage dealing after this
7553 // Custom triggered spells
7554 switch (auraSpellInfo
->Id
)
7556 // Persistent Shield (Scarab Brooch trinket)
7557 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
7560 basepoints0
= damage
* 15 / 100;
7562 trigger_spell_id
= 26470;
7568 // When your health drops below 20% ....
7569 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
7573 // Deadly Swiftness (Rank 1)
7576 // whenever you deal damage to a target who is below 20% health.
7577 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
7581 trigger_spell_id
= 22588;
7583 // Greater Heal Refund (Avatar Raiment set)
7586 // Not give if target alredy have full health
7587 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
7589 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
7590 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
7594 // Bonus Healing (Crystal Spire of Karabor mace)
7597 // If your target is below $s1% health
7598 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
7602 // Evasive Maneuvers (Commendation of Kael`thas trinket)
7605 // reduce you below $s1% health
7606 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
7612 // Costum basepoints/target for exist spell
7613 // dummy basepoints or other customs
7614 switch(trigger_spell_id
)
7616 // Cast positive spell on enemy target
7617 case 7099: // Curse of Mending
7618 case 39647: // Curse of Mending
7619 case 29494: // Temptation
7620 case 20233: // Improved Lay on Hands (cast on target)
7625 // Combo points add triggers (need add combopoint only for main tatget, and after possible combopoints reset)
7626 case 15250: // Rogue Setup
7628 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
7630 break; // continue normal case
7632 // Finish movies that add combo
7633 case 14189: // Seal Fate (Netherblade set)
7634 case 14157: // Ruthlessness
7636 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
7639 // Shamanistic Rage triggered spell
7642 basepoints0
= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
7643 trigger_spell_id
= 30824;
7646 // Enlightenment (trigger only from mana cost spells)
7649 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
7655 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
7658 // try detect target manually if not set
7659 if ( target
== NULL
)
7660 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
7663 if(!target
|| target
!=this && !target
->isAlive())
7667 CastCustomSpell(target
,trigger_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
7669 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
7671 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7672 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
7677 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
7679 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
7681 if(!pVictim
|| !pVictim
->isAlive())
7684 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
7685 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
7687 uint32 triggered_spell_id
= 0;
7691 case 836: // Improved Blizzard (Rank 1)
7693 if (!procSpell
|| procSpell
->SpellVisual
!=9487)
7695 triggered_spell_id
= 12484;
7698 case 988: // Improved Blizzard (Rank 2)
7700 if (!procSpell
|| procSpell
->SpellVisual
!=9487)
7702 triggered_spell_id
= 12485;
7705 case 989: // Improved Blizzard (Rank 3)
7707 if (!procSpell
|| procSpell
->SpellVisual
!=9487)
7709 triggered_spell_id
= 12486;
7712 case 4086: // Improved Mend Pet (Rank 1)
7713 case 4087: // Improved Mend Pet (Rank 2)
7715 int32 chance
= triggeredByAura
->GetSpellProto()->EffectBasePoints
[triggeredByAura
->GetEffIndex()];
7716 if(!roll_chance_i(chance
))
7719 triggered_spell_id
= 24406;
7722 case 4533: // Dreamwalker Raiment 2 pieces bonus
7725 if (!roll_chance_i(50))
7728 switch (pVictim
->getPowerType())
7730 case POWER_MANA
: triggered_spell_id
= 28722; break;
7731 case POWER_RAGE
: triggered_spell_id
= 28723; break;
7732 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
7738 case 4537: // Dreamwalker Raiment 6 pieces bonus
7739 triggered_spell_id
= 28750; // Blessing of the Claw
7741 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
7742 triggered_spell_id
= 37445; // Mana Surge
7747 if(!triggered_spell_id
)
7750 // standard non-dummy case
7751 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
7755 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
7759 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
7762 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
7764 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
7765 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
7770 void Unit::setPowerType(Powers new_powertype
)
7772 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
7774 if(GetTypeId() == TYPEID_PLAYER
)
7776 if(((Player
*)this)->GetGroup())
7777 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
7779 else if(((Creature
*)this)->isPet())
7781 Pet
*pet
= ((Pet
*)this);
7782 if(pet
->isControlled())
7784 Unit
*owner
= GetOwner();
7785 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
7786 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
7790 switch(new_powertype
)
7796 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
7797 SetPower( POWER_RAGE
,0);
7800 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
7801 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
7804 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
7805 SetPower( POWER_ENERGY
,0);
7807 case POWER_HAPPINESS
:
7808 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
7809 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
7814 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
7816 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
7819 static uint64 guid
= 0; // prevent repeating spam same faction problem
7821 if(GetGUID() != guid
)
7823 if(GetTypeId() == TYPEID_PLAYER
)
7824 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
7826 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
7833 bool Unit::IsHostileTo(Unit
const* unit
) const
7835 // always non-hostile to self
7839 // always non-hostile to GM in GM mode
7840 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
7843 // always hostile to enemy
7844 if(getVictim()==unit
|| unit
->getVictim()==this)
7847 // test pet/charm masters instead pers/charmeds
7848 Unit
const* testerOwner
= GetCharmerOrOwner();
7849 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
7851 // always hostile to owner's enemy
7852 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
7855 // always hostile to enemy owner
7856 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
7859 // always hostile to owner of owner's enemy
7860 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
7863 Unit
const* tester
= testerOwner
? testerOwner
: this;
7864 Unit
const* target
= targetOwner
? targetOwner
: unit
;
7866 // always non-hostile to target with common owner, or to owner/pet
7870 // special cases (Duel, etc)
7871 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
7873 Player
const* pTester
= (Player
const*)tester
;
7874 Player
const* pTarget
= (Player
const*)target
;
7877 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
7881 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
7885 if(pTarget
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_SANCTUARY
) && pTester
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_SANCTUARY
))
7889 if(pTester
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_FFA_PVP
) && pTarget
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_FFA_PVP
))
7893 // Green/Blue (can't attack)
7894 if(pTester
->GetTeam()==pTarget
->GetTeam())
7897 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
7898 return pTester
->IsPvP() && pTarget
->IsPvP();
7901 // faction base cases
7902 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
7903 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
7904 if(!tester_faction
|| !target_faction
)
7907 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
7910 // PvC forced reaction and reputation case
7911 if(tester
->GetTypeId()==TYPEID_PLAYER
)
7914 ForcedReactions::const_iterator forceItr
= ((Player
*)tester
)->m_forcedReactions
.find(target_faction
->faction
);
7915 if(forceItr
!=((Player
*)tester
)->m_forcedReactions
.end())
7916 return forceItr
->second
<= REP_HOSTILE
;
7918 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
7919 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
7920 if(raw_target_faction
->reputationListID
>=0)
7921 if(FactionState
const* factionState
= ((Player
*)tester
)->GetFactionState(raw_target_faction
))
7922 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
7924 // CvP forced reaction and reputation case
7925 else if(target
->GetTypeId()==TYPEID_PLAYER
)
7928 ForcedReactions::const_iterator forceItr
= ((Player
const*)target
)->m_forcedReactions
.find(tester_faction
->faction
);
7929 if(forceItr
!=((Player
const*)target
)->m_forcedReactions
.end())
7930 return forceItr
->second
<= REP_HOSTILE
;
7932 // apply reputation state
7933 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
7934 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
7935 return ((Player
const*)target
)->GetReputationRank(raw_tester_faction
) <= REP_HOSTILE
;
7938 // common faction based case (CvC,PvC,CvP)
7939 return tester_faction
->IsHostileTo(*target_faction
);
7942 bool Unit::IsFriendlyTo(Unit
const* unit
) const
7944 // always friendly to self
7948 // always friendly to GM in GM mode
7949 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
7952 // always non-friendly to enemy
7953 if(getVictim()==unit
|| unit
->getVictim()==this)
7956 // test pet/charm masters instead pers/charmeds
7957 Unit
const* testerOwner
= GetCharmerOrOwner();
7958 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
7960 // always non-friendly to owner's enemy
7961 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
7964 // always non-friendly to enemy owner
7965 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
7968 // always non-friendly to owner of owner's enemy
7969 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
7972 Unit
const* tester
= testerOwner
? testerOwner
: this;
7973 Unit
const* target
= targetOwner
? targetOwner
: unit
;
7975 // always friendly to target with common owner, or to owner/pet
7979 // special cases (Duel)
7980 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
7982 Player
const* pTester
= (Player
const*)tester
;
7983 Player
const* pTarget
= (Player
const*)target
;
7986 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
7990 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
7994 if(pTarget
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_SANCTUARY
) && pTester
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_SANCTUARY
))
7998 if(pTester
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_FFA_PVP
) && pTarget
->HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_FFA_PVP
))
8002 // Green/Blue (non-attackable)
8003 if(pTester
->GetTeam()==pTarget
->GetTeam())
8006 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
8007 return !pTarget
->IsPvP();
8010 // faction base cases
8011 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
8012 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
8013 if(!tester_faction
|| !target_faction
)
8016 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
8019 // PvC forced reaction and reputation case
8020 if(tester
->GetTypeId()==TYPEID_PLAYER
)
8023 ForcedReactions::const_iterator forceItr
= ((Player
const*)tester
)->m_forcedReactions
.find(target_faction
->faction
);
8024 if(forceItr
!=((Player
const*)tester
)->m_forcedReactions
.end())
8025 return forceItr
->second
>= REP_FRIENDLY
;
8027 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
8028 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
8029 if(raw_target_faction
->reputationListID
>=0)
8030 if(FactionState
const* FactionState
= ((Player
*)tester
)->GetFactionState(raw_target_faction
))
8031 return !(FactionState
->Flags
& FACTION_FLAG_AT_WAR
);
8033 // CvP forced reaction and reputation case
8034 else if(target
->GetTypeId()==TYPEID_PLAYER
)
8037 ForcedReactions::const_iterator forceItr
= ((Player
const*)target
)->m_forcedReactions
.find(tester_faction
->faction
);
8038 if(forceItr
!=((Player
const*)target
)->m_forcedReactions
.end())
8039 return forceItr
->second
>= REP_FRIENDLY
;
8041 // apply reputation state
8042 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
8043 if(raw_tester_faction
->reputationListID
>=0 )
8044 return ((Player
const*)target
)->GetReputationRank(raw_tester_faction
) >= REP_FRIENDLY
;
8047 // common faction based case (CvC,PvC,CvP)
8048 return tester_faction
->IsFriendlyTo(*target_faction
);
8051 bool Unit::IsHostileToPlayers() const
8053 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8057 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8058 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8061 return my_faction
->IsHostileToPlayers();
8064 bool Unit::IsNeutralToAll() const
8066 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
8070 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
8071 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
8074 return my_faction
->IsNeutralToAll();
8077 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
8079 if(!victim
|| victim
== this)
8082 // dead units can neither attack nor be attacked
8083 if(!isAlive() || !victim
->isAlive())
8086 // player cannot attack in mount state
8087 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
8090 // nobody can attack GM in GM-mode
8091 if(victim
->GetTypeId()==TYPEID_PLAYER
)
8093 if(((Player
*)victim
)->isGameMaster())
8098 if(((Creature
*)victim
)->IsInEvadeMode())
8102 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
8103 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
8104 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
8108 if (m_attacking
== victim
)
8110 // switch to melee attack from ranged/magic
8111 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
8113 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8114 SendAttackStart(victim
);
8123 SetUInt64Value(UNIT_FIELD_TARGET
, victim
->GetGUID());
8126 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
8127 m_attacking
= victim
;
8128 m_attacking
->_addAttacker(this);
8130 if(m_attacking
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)m_attacking
)->AI())
8131 ((Creature
*)m_attacking
)->AI()->AttackedBy(this);
8133 if(GetTypeId()==TYPEID_UNIT
)
8135 WorldPacket
data(SMSG_AI_REACTION
, 12);
8137 data
<< uint32(AI_REACTION_AGGRO
); // Aggro sound
8138 ((WorldObject
*)this)->SendMessageToSet(&data
, true);
8140 ((Creature
*)this)->CallAssistance();
8141 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
8144 // delay offhand weapon attack to next attack time
8145 if(haveOffhandWeapon())
8146 resetAttackTimer(OFF_ATTACK
);
8149 SendAttackStart(victim
);
8154 bool Unit::AttackStop()
8159 Unit
* victim
= m_attacking
;
8161 m_attacking
->_removeAttacker(this);
8165 SetUInt64Value(UNIT_FIELD_TARGET
, 0);
8167 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
8169 InterruptSpell(CURRENT_MELEE_SPELL
);
8171 if( GetTypeId()==TYPEID_UNIT
)
8173 // reset call assistance
8174 ((Creature
*)this)->SetNoCallAssistance(false);
8177 SendAttackStop(victim
);
8182 void Unit::CombatStop(bool cast
)
8184 if(cast
& IsNonMeleeSpellCasted(false))
8185 InterruptNonMeleeSpells(false);
8188 RemoveAllAttackers();
8189 if( GetTypeId()==TYPEID_PLAYER
)
8190 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
8194 void Unit::CombatStopWithPets(bool cast
)
8197 if(Pet
* pet
= GetPet())
8198 pet
->CombatStop(cast
);
8199 if(Unit
* charm
= GetCharm())
8200 charm
->CombatStop(cast
);
8201 if(GetTypeId()==TYPEID_PLAYER
)
8203 GuardianPetList
const& guardians
= ((Player
*)this)->GetGuardians();
8204 for(GuardianPetList::const_iterator itr
= guardians
.begin(); itr
!= guardians
.end(); ++itr
)
8205 if(Unit
* guardian
= Unit::GetUnit(*this,*itr
))
8206 guardian
->CombatStop(cast
);
8210 bool Unit::isAttackingPlayer() const
8212 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
8215 Pet
* pet
= GetPet();
8216 if(pet
&& pet
->isAttackingPlayer())
8219 Unit
* charmed
= GetCharm();
8220 if(charmed
&& charmed
->isAttackingPlayer())
8223 for (int8 i
= 0; i
< MAX_TOTEM
; i
++)
8227 Creature
*totem
= ObjectAccessor::GetCreature(*this, m_TotemSlot
[i
]);
8228 if(totem
&& totem
->isAttackingPlayer())
8236 void Unit::RemoveAllAttackers()
8238 while (!m_attackers
.empty())
8240 AttackerSet::iterator iter
= m_attackers
.begin();
8241 if(!(*iter
)->AttackStop())
8243 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
8244 m_attackers
.erase(iter
);
8249 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
8253 if (!HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)))
8255 SetFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8256 if(GetTypeId() == TYPEID_PLAYER
)
8258 const PlayerSpellMap
& sp_list
= ((Player
*)this)->GetSpellMap();
8259 for (PlayerSpellMap::const_iterator itr
= sp_list
.begin(); itr
!= sp_list
.end(); ++itr
)
8261 if(itr
->second
->state
== PLAYERSPELL_REMOVED
) continue;
8262 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
8263 if (!spellInfo
|| !IsPassiveSpell(itr
->first
)) continue;
8264 if (spellInfo
->CasterAuraState
== flag
)
8265 CastSpell(this, itr
->first
, true, NULL
);
8272 if (HasFlag(UNIT_FIELD_AURASTATE
,1<<(flag
-1)))
8274 RemoveFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
8275 Unit::AuraMap
& tAuras
= GetAuras();
8276 for (Unit::AuraMap::iterator itr
= tAuras
.begin(); itr
!= tAuras
.end();)
8278 SpellEntry
const* spellProto
= (*itr
).second
->GetSpellProto();
8279 if (spellProto
->CasterAuraState
== flag
)
8281 // exceptions (applied at state but not removed at state change)
8283 if(spellProto
->SpellIconID
==2006 && spellProto
->SpellFamilyName
==SPELLFAMILY_WARRIOR
&& spellProto
->SpellFamilyFlags
==0x100000)
8298 Unit
*Unit::GetOwner() const
8300 uint64 ownerid
= GetOwnerGUID();
8303 return ObjectAccessor::GetUnit(*this, ownerid
);
8306 Unit
*Unit::GetCharmer() const
8308 if(uint64 charmerid
= GetCharmerGUID())
8309 return ObjectAccessor::GetUnit(*this, charmerid
);
8313 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
8315 uint64 guid
= GetCharmerOrOwnerGUID();
8316 if(IS_PLAYER_GUID(guid
))
8317 return ObjectAccessor::GetPlayer(*this, guid
);
8319 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
8322 Pet
* Unit::GetPet() const
8324 if(uint64 pet_guid
= GetPetGUID())
8326 if(Pet
* pet
= ObjectAccessor::GetPet(pet_guid
))
8329 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
8330 const_cast<Unit
*>(this)->SetPet(0);
8336 Unit
* Unit::GetCharm() const
8338 if(uint64 charm_guid
= GetCharmGUID())
8340 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
8343 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
8344 const_cast<Unit
*>(this)->SetCharm(0);
8350 void Unit::SetPet(Pet
* pet
)
8352 SetUInt64Value(UNIT_FIELD_SUMMON
,pet
? pet
->GetGUID() : 0);
8354 // FIXME: hack, speed must be set only at follow
8356 for(int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
8357 pet
->SetSpeed(UnitMoveType(i
),m_speed_rate
[i
],true);
8360 void Unit::SetCharm(Unit
* charmed
)
8362 SetUInt64Value(UNIT_FIELD_CHARM
,charmed
? charmed
->GetGUID() : 0);
8365 void Unit::UnsummonAllTotems()
8367 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
8372 Creature
*OldTotem
= ObjectAccessor::GetCreature(*this, m_TotemSlot
[i
]);
8373 if (OldTotem
&& OldTotem
->isTotem())
8374 ((Totem
*)OldTotem
)->UnSummon();
8378 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, bool critical
)
8381 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
8382 data
.append(pVictim
->GetPackGUID());
8383 data
.append(GetPackGUID());
8384 data
<< uint32(SpellID
);
8385 data
<< uint32(Damage
);
8386 data
<< uint8(critical
? 1 : 0);
8387 data
<< uint8(0); // unused in client?
8388 SendMessageToSet(&data
, true);
8391 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
8393 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
8394 data
.append(pVictim
->GetPackGUID());
8395 data
.append(GetPackGUID());
8396 data
<< uint32(SpellID
);
8397 data
<< uint32(powertype
);
8398 data
<< uint32(Damage
);
8399 //data << uint8(critical ? 1 : 0); // removed in 2.4.0
8400 SendMessageToSet(&data
, true);
8403 uint32
Unit::SpellDamageBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
)
8405 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
8408 int32 BonusDamage
= 0;
8409 if( GetTypeId()==TYPEID_UNIT
)
8411 // Pets just add their bonus damage to their spell damage
8412 // note that their spell damage is just gain of their own auras
8413 if (((Creature
*)this)->isPet())
8415 BonusDamage
= ((Pet
*)this)->GetBonusDamage();
8417 // For totems get damage bonus from owner (statue isn't totem in fact)
8418 else if (((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8420 if(Unit
* owner
= GetOwner())
8421 return owner
->SpellDamageBonus(pVictim
, spellProto
, pdamage
, damagetype
);
8426 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
8428 // Taken/Done fixed damage bonus auras
8429 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonus(GetSpellSchoolMask(spellProto
))+BonusDamage
;
8430 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
8432 // Damage over Time spells bonus calculation
8433 float DotFactor
= 1.0f
;
8434 if(damagetype
== DOT
)
8436 int32 DotDuration
= GetSpellDuration(spellProto
);
8440 if(DotDuration
> 30000) DotDuration
= 30000;
8441 if(!IsChanneledSpell(spellProto
)) DotFactor
= DotDuration
/ 15000.0f
;
8443 for(int j
= 0; j
< 3; j
++)
8445 if( spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& (
8446 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_DAMAGE
||
8447 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
) )
8454 if(spellProto
->EffectAmplitude
[x
] != 0)
8455 DotTicks
= DotDuration
/ spellProto
->EffectAmplitude
[x
];
8458 DoneAdvertisedBenefit
/= DotTicks
;
8459 TakenAdvertisedBenefit
/= DotTicks
;
8464 // Taken/Done total percent damage auras
8465 float DoneTotalMod
= 1.0f
;
8466 float TakenTotalMod
= 1.0f
;
8469 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
8470 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
8472 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
8473 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
8474 // -1 == any item class (not wand then)
8475 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
8476 // 0 == any inventory type (not wand then)
8478 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8482 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8483 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
8484 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
8485 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8486 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8489 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
8490 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
8491 if( (*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
) )
8492 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8494 // .. taken pct: scripted (increases damage of * against targets *)
8495 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8496 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
8498 switch((*i
)->GetModifier()->m_miscvalue
)
8501 case 4920: case 4919:
8502 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
))
8503 TakenTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
; break;
8507 // .. taken pct: dummy auras
8508 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
8509 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
8511 switch((*i
)->GetSpellProto()->SpellIconID
)
8515 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) )
8517 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
8519 float mod
= -((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
8520 if (mod
< (*i
)->GetModifier()->m_amount
)
8521 mod
= (*i
)->GetModifier()->m_amount
;
8522 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
8527 for(int j
=0;j
<3;j
++)
8529 if(GetEffectMechanic(spellProto
, j
)==MECHANIC_BLEED
)
8531 TakenTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8539 // Distribute Damage over multiple effects, reduce by AoE
8540 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
8542 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
8543 for(int j
= 0; j
< 3; ++j
)
8545 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
8546 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
8553 switch(spellProto
->SpellFamilyName
)
8555 case SPELLFAMILY_MAGE
:
8556 // Ignite - do not modify, it is (8*Rank)% damage of procing Spell
8557 if(spellProto
->Id
==12654)
8562 else if((spellProto
->SpellFamilyFlags
& 0x20000LL
) && spellProto
->SpellIconID
== 186)
8564 CastingTime
/= 3; // applied 1/3 bonuses in case generic target
8565 if(pVictim
->isFrozen()) // and compensate this for frozen target.
8566 TakenTotalMod
*= 3.0f
;
8568 // Pyroblast - 115% of Fire Damage, DoT - 20% of Fire Damage
8569 else if((spellProto
->SpellFamilyFlags
& 0x400000LL
) && spellProto
->SpellIconID
== 184 )
8571 DotFactor
= damagetype
== DOT
? 0.2f
: 1.0f
;
8572 CastingTime
= damagetype
== DOT
? 3500 : 4025;
8574 // Fireball - 100% of Fire Damage, DoT - 0% of Fire Damage
8575 else if((spellProto
->SpellFamilyFlags
& 0x1LL
) && spellProto
->SpellIconID
== 185)
8578 DotFactor
= damagetype
== DOT
? 0.0f
: 1.0f
;
8581 else if (spellProto
->SpellFamilyFlags
& 0x0000000800000000LL
)
8585 // Arcane Missiles triggered spell
8586 else if ((spellProto
->SpellFamilyFlags
& 0x200000LL
) && spellProto
->SpellIconID
== 225)
8590 // Blizzard triggered spell
8591 else if ((spellProto
->SpellFamilyFlags
& 0x80080LL
) && spellProto
->SpellIconID
== 285)
8596 case SPELLFAMILY_WARLOCK
:
8598 if((spellProto
->SpellFamilyFlags
& 0x40000LL
) && spellProto
->SpellIconID
== 208)
8600 CastingTime
= 2800; // 80% from +shadow damage
8601 DoneTotalMod
= 1.0f
;
8602 TakenTotalMod
= 1.0f
;
8605 else if((spellProto
->SpellFamilyFlags
& 0x80000000LL
) && spellProto
->SpellIconID
== 154 && GetPetGUID())
8607 CastingTime
= 3360; // 96% from +shadow damage
8608 DoneTotalMod
= 1.0f
;
8609 TakenTotalMod
= 1.0f
;
8611 // Soul Fire - 115% of Fire Damage
8612 else if((spellProto
->SpellFamilyFlags
& 0x8000000000LL
) && spellProto
->SpellIconID
== 184)
8616 // Curse of Agony - 120% of Shadow Damage
8617 else if((spellProto
->SpellFamilyFlags
& 0x0000000400LL
) && spellProto
->SpellIconID
== 544)
8621 // Drain Mana - 0% of Shadow Damage
8622 else if((spellProto
->SpellFamilyFlags
& 0x10LL
) && spellProto
->SpellIconID
== 548)
8626 // Drain Soul 214.3%
8627 else if ((spellProto
->SpellFamilyFlags
& 0x4000LL
) && spellProto
->SpellIconID
== 113 )
8632 else if ((spellProto
->SpellFamilyFlags
& 0x40LL
) && spellProto
->SpellIconID
== 937)
8634 CastingTime
= damagetype
== DOT
? 5000 : 500; // self damage seems to be so
8636 // Unstable Affliction - 180%
8637 else if (spellProto
->Id
== 31117 && spellProto
->SpellIconID
== 232)
8642 else if ((spellProto
->SpellFamilyFlags
& 0x2LL
) && spellProto
->SpellIconID
== 313)
8647 case SPELLFAMILY_PALADIN
:
8648 // Consecration - 95% of Holy Damage
8649 if((spellProto
->SpellFamilyFlags
& 0x20LL
) && spellProto
->SpellIconID
== 51)
8654 // Seal of Righteousness - 10.2%/9.8% ( based on weapon type ) of Holy Damage, multiplied by weapon speed
8655 else if((spellProto
->SpellFamilyFlags
& 0x8000000LL
) && spellProto
->SpellIconID
== 25)
8657 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
8658 float wspeed
= GetAttackTime(BASE_ATTACK
)/1000.0f
;
8660 if( item
&& item
->GetProto()->InventoryType
== INVTYPE_2HWEAPON
)
8661 CastingTime
= uint32(wspeed
*3500*0.102f
);
8663 CastingTime
= uint32(wspeed
*3500*0.098f
);
8665 // Judgement of Righteousness - 73%
8666 else if ((spellProto
->SpellFamilyFlags
& 1024) && spellProto
->SpellIconID
== 25)
8670 // Seal of Vengeance - 17% per Fully Stacked Tick - 5 Applications
8671 else if ((spellProto
->SpellFamilyFlags
& 0x80000000000LL
) && spellProto
->SpellIconID
== 2292)
8676 // Holy shield - 5% of Holy Damage
8677 else if ((spellProto
->SpellFamilyFlags
& 0x4000000000LL
) && spellProto
->SpellIconID
== 453)
8681 // Blessing of Sanctuary - 0%
8682 else if ((spellProto
->SpellFamilyFlags
& 0x10000000LL
) && spellProto
->SpellIconID
== 29)
8686 // Seal of Righteousness trigger - already computed for parent spell
8687 else if ( spellProto
->SpellFamilyName
==SPELLFAMILY_PALADIN
&& spellProto
->SpellIconID
==25 && spellProto
->AttributesEx4
& 0x00800000LL
)
8692 case SPELLFAMILY_SHAMAN
:
8694 if (spellProto
->SpellFamilyFlags
& 0x000040000000LL
)
8696 if (spellProto
->SpellIconID
== 33) // Fire Nova totem attack must be 21.4%(untested)
8697 CastingTime
= 749; // ignore CastingTime and use as modifier
8698 else if (spellProto
->SpellIconID
== 680) // Searing Totem attack 8%
8699 CastingTime
= 280; // ignore CastingTime and use as modifier
8700 else if (spellProto
->SpellIconID
== 37) // Magma totem attack must be 6.67%(untested)
8701 CastingTime
= 234; // ignore CastingTimePenalty and use as modifier
8703 // Lightning Shield (and proc shield from T2 8 pieces bonus ) 33% per charge
8704 else if( (spellProto
->SpellFamilyFlags
& 0x00000000400LL
) || spellProto
->Id
== 23552)
8705 CastingTime
= 1155; // ignore CastingTimePenalty and use as modifier
8707 case SPELLFAMILY_PRIEST
:
8708 // Mana Burn - 0% of Shadow Damage
8709 if((spellProto
->SpellFamilyFlags
& 0x10LL
) && spellProto
->SpellIconID
== 212)
8713 // Mind Flay - 59% of Shadow Damage
8714 else if((spellProto
->SpellFamilyFlags
& 0x800000LL
) && spellProto
->SpellIconID
== 548)
8718 // Holy Fire - 86.71%, DoT - 16.5%
8719 else if ((spellProto
->SpellFamilyFlags
& 0x100000LL
) && spellProto
->SpellIconID
== 156)
8721 DotFactor
= damagetype
== DOT
? 0.165f
: 1.0f
;
8722 CastingTime
= damagetype
== DOT
? 3500 : 3035;
8724 // Shadowguard - 28% per charge
8725 else if ((spellProto
->SpellFamilyFlags
& 0x2000000LL
) && spellProto
->SpellIconID
== 19)
8729 // Touch of Weakeness - 10%
8730 else if ((spellProto
->SpellFamilyFlags
& 0x80000LL
) && spellProto
->SpellIconID
== 1591)
8734 // Reflective Shield (back damage) - 0% (other spells fit to check not have damage effects/auras)
8735 else if (spellProto
->SpellFamilyFlags
== 0 && spellProto
->SpellIconID
== 566)
8740 else if ((spellProto
->SpellFamilyFlags
& 0x400000LL
) && spellProto
->SpellIconID
== 1874)
8745 case SPELLFAMILY_DRUID
:
8746 // Hurricane triggered spell
8747 if((spellProto
->SpellFamilyFlags
& 0x400000LL
) && spellProto
->SpellIconID
== 220)
8752 case SPELLFAMILY_WARRIOR
:
8753 case SPELLFAMILY_HUNTER
:
8754 case SPELLFAMILY_ROGUE
:
8761 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
8763 // Spellmod SpellDamage
8764 float SpellModSpellDamage
= 100.0f
;
8766 if(Player
* modOwner
= GetSpellModOwner())
8767 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
8769 SpellModSpellDamage
/= 100.0f
;
8771 float DoneActualBenefit
= DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* SpellModSpellDamage
* LvlPenalty
;
8772 float TakenActualBenefit
= TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
;
8774 float tmpDamage
= (float(pdamage
)+DoneActualBenefit
)*DoneTotalMod
;
8776 // Add flat bonus from spell damage versus
8777 tmpDamage
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
8779 // apply spellmod to Done damage
8780 if(Player
* modOwner
= GetSpellModOwner())
8781 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
8783 tmpDamage
= (tmpDamage
+TakenActualBenefit
)*TakenTotalMod
;
8785 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
8786 tmpDamage
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
8788 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
8791 int32
Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask
)
8793 int32 DoneAdvertisedBenefit
= 0;
8796 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
8797 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
8798 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
8799 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
8800 // -1 == any item class (not wand then)
8801 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
8802 // 0 == any inventory type (not wand then)
8803 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8805 if (GetTypeId() == TYPEID_PLAYER
)
8807 // Damage bonus from stats
8808 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
8809 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
8811 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
8813 SpellEntry
const* iSpellProto
= (*i
)->GetSpellProto();
8814 uint8 eff
= (*i
)->GetEffIndex();
8816 // stat used dependent from next effect aura SPELL_AURA_MOD_SPELL_HEALING presence and misc value (stat index)
8817 Stats usedStat
= STAT_INTELLECT
;
8818 if(eff
< 2 && iSpellProto
->EffectApplyAuraName
[eff
+1]==SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
)
8819 usedStat
= Stats(iSpellProto
->EffectMiscValue
[eff
+1]);
8821 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
8824 // ... and attack power
8825 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
8826 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
8827 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
8828 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
8831 return DoneAdvertisedBenefit
;
8834 int32
Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
8836 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8838 int32 TakenAdvertisedBenefit
= 0;
8839 // ..done (for creature type by mask) in taken
8840 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
8841 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
8842 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8843 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8846 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
8847 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
8848 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
8849 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8851 return TakenAdvertisedBenefit
;
8854 bool Unit::isSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
8856 // not criting spell
8857 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
8860 float crit_chance
= 0.0f
;
8861 switch(spellProto
->DmgClass
)
8863 case SPELL_DAMAGE_CLASS_NONE
:
8865 case SPELL_DAMAGE_CLASS_MAGIC
:
8867 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
8869 // For other schools
8870 else if (GetTypeId() == TYPEID_PLAYER
)
8871 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
8874 crit_chance
= m_baseSpellCritChance
;
8875 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
8878 if (pVictim
&& !IsPositiveSpell(spellProto
->Id
))
8880 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
8881 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
8882 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
8883 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
8884 // Modify by player victim resilience
8885 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
8886 crit_chance
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
);
8887 // scripted (increase crit chance ... against ... target by x%
8888 if(pVictim
->isFrozen()) // Shatter
8890 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8891 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
8893 switch((*i
)->GetModifier()->m_miscvalue
)
8895 case 849: crit_chance
+= 10.0f
; break; //Shatter Rank 1
8896 case 910: crit_chance
+= 20.0f
; break; //Shatter Rank 2
8897 case 911: crit_chance
+= 30.0f
; break; //Shatter Rank 3
8898 case 912: crit_chance
+= 40.0f
; break; //Shatter Rank 4
8899 case 913: crit_chance
+= 50.0f
; break; //Shatter Rank 5
8906 case SPELL_DAMAGE_CLASS_MELEE
:
8907 case SPELL_DAMAGE_CLASS_RANGED
:
8911 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
8912 crit_chance
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
8913 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
8921 // only players use intelligence for critical chance computations
8922 if(Player
* modOwner
= GetSpellModOwner())
8923 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
8925 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
8926 if (roll_chance_f(crit_chance
))
8931 uint32
Unit::SpellCriticalBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
8933 // Calculate critical bonus
8935 switch(spellProto
->DmgClass
)
8937 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
8938 case SPELL_DAMAGE_CLASS_RANGED
:
8939 // TODO: write here full calculation for melee/ranged spells
8940 crit_bonus
= damage
;
8943 crit_bonus
= damage
/ 2; // for spells is 50%
8947 // adds additional damage to crit_bonus (from talents)
8948 if(Player
* modOwner
= GetSpellModOwner())
8949 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
8953 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8954 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
8958 damage
+= crit_bonus
;
8963 uint32
Unit::SpellHealingBonus(SpellEntry
const *spellProto
, uint32 healamount
, DamageEffectType damagetype
, Unit
*pVictim
)
8965 // For totems get healing bonus from owner (statue isn't totem in fact)
8966 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8967 if(Unit
* owner
= GetOwner())
8968 return owner
->SpellHealingBonus(spellProto
, healamount
, damagetype
, pVictim
);
8972 // These Spells are doing fixed amount of healing (TODO found less hack-like check)
8973 if (spellProto
->Id
== 15290 || spellProto
->Id
== 39373 ||
8974 spellProto
->Id
== 33778 || spellProto
->Id
== 379 ||
8975 spellProto
->Id
== 38395 || spellProto
->Id
== 40972)
8978 int32 AdvertisedBenefit
= SpellBaseHealingBonus(GetSpellSchoolMask(spellProto
));
8979 uint32 CastingTime
= GetSpellCastTime(spellProto
);
8982 AdvertisedBenefit
+= SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
8984 // Blessing of Light dummy effects healing taken from Holy Light and Flash of Light
8985 if (spellProto
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& (spellProto
->SpellFamilyFlags
& 0x00000000C0000000LL
))
8987 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
8988 for(AuraList::const_iterator i
= mDummyAuras
.begin();i
!= mDummyAuras
.end(); ++i
)
8990 if((*i
)->GetSpellProto()->SpellVisual
== 9180)
8993 if ((spellProto
->SpellFamilyFlags
& 0x0000000040000000LL
) && (*i
)->GetEffIndex() == 1)
8994 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8996 else if ((spellProto
->SpellFamilyFlags
& 0x0000000080000000LL
) && (*i
)->GetEffIndex() == 0)
8997 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9002 float ActualBenefit
= 0.0f
;
9004 if (AdvertisedBenefit
!= 0)
9006 // Healing over Time spells
9007 float DotFactor
= 1.0f
;
9008 if(damagetype
== DOT
)
9010 int32 DotDuration
= GetSpellDuration(spellProto
);
9014 if(DotDuration
> 30000) DotDuration
= 30000;
9015 if(!IsChanneledSpell(spellProto
)) DotFactor
= DotDuration
/ 15000.0f
;
9017 for(int j
= 0; j
< 3; j
++)
9019 if( spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& (
9020 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_HEAL
||
9021 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
) )
9028 if(spellProto
->EffectAmplitude
[x
] != 0)
9029 DotTicks
= DotDuration
/ spellProto
->EffectAmplitude
[x
];
9031 AdvertisedBenefit
/= DotTicks
;
9035 // distribute healing to all effects, reduce AoE damage
9036 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
9038 // 0% bonus for damage and healing spells for leech spells from healing bonus
9039 for(int j
= 0; j
< 3; ++j
)
9041 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
9042 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
9050 switch (spellProto
->SpellFamilyName
)
9052 case SPELLFAMILY_SHAMAN
:
9053 // Healing stream from totem (add 6% per tick from hill bonus owner)
9054 if (spellProto
->SpellFamilyFlags
& 0x000000002000LL
)
9056 // Earth Shield 30% per charge
9057 else if (spellProto
->SpellFamilyFlags
& 0x40000000000LL
)
9060 case SPELLFAMILY_DRUID
:
9062 if (spellProto
->SpellFamilyFlags
& 0x1000000000LL
)
9064 CastingTime
= damagetype
== DOT
? 3500 : 1200;
9065 DotFactor
= damagetype
== DOT
? 0.519f
: 1.0f
;
9067 // Tranquility triggered spell
9068 else if (spellProto
->SpellFamilyFlags
& 0x80LL
)
9071 else if (spellProto
->SpellFamilyFlags
& 0x10LL
)
9074 else if (spellProto
->SpellFamilyFlags
& 0x40LL
)
9076 DotFactor
= damagetype
== DOT
? 0.705f
: 1.0f
;
9077 CastingTime
= damagetype
== DOT
? 3500 : 1010;
9080 case SPELLFAMILY_PRIEST
:
9082 if ((spellProto
->SpellFamilyFlags
& 0x8000000LL
) && spellProto
->SpellIconID
== 1874)
9085 case SPELLFAMILY_PALADIN
:
9086 // Seal and Judgement of Light
9087 if ( spellProto
->SpellFamilyFlags
& 0x100040000LL
)
9090 case SPELLFAMILY_WARRIOR
:
9091 case SPELLFAMILY_ROGUE
:
9092 case SPELLFAMILY_HUNTER
:
9097 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
9099 // Spellmod SpellDamage
9100 float SpellModSpellDamage
= 100.0f
;
9102 if(Player
* modOwner
= GetSpellModOwner())
9103 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
9105 SpellModSpellDamage
/= 100.0f
;
9107 ActualBenefit
= (float)AdvertisedBenefit
* ((float)CastingTime
/ 3500.0f
) * DotFactor
* SpellModSpellDamage
* LvlPenalty
;
9110 // use float as more appropriate for negative values and percent applying
9111 float heal
= healamount
+ ActualBenefit
;
9113 // TODO: check for ALL/SPELLS type
9114 // Healing done percent
9115 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
9116 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
9117 heal
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
9119 // apply spellmod to Done amount
9120 if(Player
* modOwner
= GetSpellModOwner())
9121 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
9123 // Healing Wave cast
9124 if (spellProto
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& spellProto
->SpellFamilyFlags
& 0x0000000000000040LL
)
9126 // Search for Healing Way on Victim (stack up to 3 time)
9128 Unit::AuraList
const& auraDummy
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
9129 for(Unit::AuraList::const_iterator itr
= auraDummy
.begin(); itr
!=auraDummy
.end(); ++itr
)
9130 if((*itr
)->GetId() == 29203)
9131 pctMod
+= (*itr
)->GetModifier()->m_amount
;
9134 heal
= heal
* (100 + pctMod
) / 100;
9137 // Healing taken percent
9138 float minval
= pVictim
->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
9140 heal
*= (100.0f
+ minval
) / 100.0f
;
9142 float maxval
= pVictim
->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
9144 heal
*= (100.0f
+ maxval
) / 100.0f
;
9146 if (heal
< 0) heal
= 0;
9148 return uint32(heal
);
9151 int32
Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask
)
9153 int32 AdvertisedBenefit
= 0;
9155 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
9156 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
9157 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9158 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9160 // Healing bonus of spirit, intellect and strength
9161 if (GetTypeId() == TYPEID_PLAYER
)
9163 // Healing bonus from stats
9164 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
9165 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
9167 // stat used dependent from misc value (stat index)
9168 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
9169 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9172 // ... and attack power
9173 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
9174 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
9175 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
9176 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
9178 return AdvertisedBenefit
;
9181 int32
Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
9183 int32 AdvertisedBenefit
= 0;
9184 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING
);
9185 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9186 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
9187 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
9188 return AdvertisedBenefit
;
9191 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
, bool useCharges
)
9193 //If m_immuneToSchool type contain this school type, IMMUNE damage.
9194 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9195 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9196 if(itr
->type
& shoolMask
)
9199 //If m_immuneToDamage type contain magic, IMMUNE damage.
9200 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
9201 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
9202 if(itr
->type
& shoolMask
)
9208 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
, bool useCharges
)
9213 //FIX ME this hack: don't get feared if stunned
9214 if (spellInfo
->Mechanic
== MECHANIC_FEAR
)
9216 if ( hasUnitState(UNIT_STAT_STUNNED
) )
9220 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
9221 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
9222 if(itr
->type
== spellInfo
->Dispel
)
9225 if( !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
)) // unaffected by school immunity
9227 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
9228 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
9229 if( !(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
9230 (itr
->type
& GetSpellSchoolMask(spellInfo
)) )
9234 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9235 for(SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9237 if(itr
->type
== spellInfo
->Mechanic
)
9246 bool Unit::IsImmunedToSpellEffect(uint32 effect
, uint32 mechanic
) const
9248 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
9249 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
9250 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
9251 if(itr
->type
== effect
)
9254 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
9255 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
9256 if(itr
->type
== mechanic
)
9262 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
9267 uint32 family
= spellInfo
->SpellFamilyName
;
9268 uint64 flags
= spellInfo
->SpellFamilyFlags
;
9270 if((family
== 5 && flags
== 256) || //Searing Pain
9271 (family
== 6 && flags
== 8192) || //Mind Blast
9272 (family
== 11 && flags
== 1048576)) //Earth Shock
9278 void Unit::MeleeDamageBonus(Unit
*pVictim
, uint32
*pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
)
9286 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
9288 // Taken/Done fixed damage bonus auras
9289 int32 DoneFlatBenefit
= 0;
9290 int32 TakenFlatBenefit
= 0;
9292 // ..done (for creature type by mask) in taken
9293 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
9294 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
9295 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
9296 DoneFlatBenefit
+= (*i
)->GetModifier()->m_amount
;
9299 // SPELL_AURA_MOD_DAMAGE_DONE included in weapon damage
9301 // ..done (base at attack power for marked target and base at attack power for creature type)
9303 if(attType
== RANGED_ATTACK
)
9305 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
9307 // ..done (base at attack power and creature type)
9308 AuraList
const& mCreatureAttackPower
= GetAurasByType(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
);
9309 for(AuraList::const_iterator i
= mCreatureAttackPower
.begin();i
!= mCreatureAttackPower
.end(); ++i
)
9310 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
9311 APbonus
+= (*i
)->GetModifier()->m_amount
;
9315 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
9317 // ..done (base at attack power and creature type)
9318 AuraList
const& mCreatureAttackPower
= GetAurasByType(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
);
9319 for(AuraList::const_iterator i
= mCreatureAttackPower
.begin();i
!= mCreatureAttackPower
.end(); ++i
)
9320 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
9321 APbonus
+= (*i
)->GetModifier()->m_amount
;
9324 if (APbonus
!=0) // Can be negative
9326 bool normalized
= false;
9329 for (uint8 i
= 0; i
<3;i
++)
9331 if (spellProto
->Effect
[i
] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG
)
9339 DoneFlatBenefit
+= int32(APbonus
/14.0f
* GetAPMultiplier(attType
,normalized
));
9343 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
9344 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
9345 if((*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask())
9346 TakenFlatBenefit
+= (*i
)->GetModifier()->m_amount
;
9348 if(attType
!=RANGED_ATTACK
)
9349 TakenFlatBenefit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
9351 TakenFlatBenefit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
9353 // Done/Taken total percent damage auras
9354 float DoneTotalMod
= 1;
9355 float TakenTotalMod
= 1;
9358 // SPELL_AURA_MOD_DAMAGE_PERCENT_DONE included in weapon damage
9359 // SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT included in weapon damage
9361 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
9362 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
9363 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
9364 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9367 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
9368 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
9369 if((*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask())
9370 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9372 // .. taken pct: dummy auras
9373 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
9374 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
9376 switch((*i
)->GetSpellProto()->SpellIconID
)
9380 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
9382 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
9384 float mod
= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
9385 if (mod
< (*i
)->GetModifier()->m_amount
)
9386 mod
= (*i
)->GetModifier()->m_amount
;
9387 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
9392 if(spellProto
==NULL
)
9394 // Should increase Shred (initial Damage of Lacerate and Rake handled in Spell::EffectSchoolDMG)
9395 if(spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& (spellProto
->SpellFamilyFlags
==0x00008000LL
))
9396 TakenTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
9401 // .. taken pct: class scripts
9402 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
9403 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
9405 switch((*i
)->GetMiscValue())
9407 case 6427: case 6428: // Dirty Deeds
9408 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
9410 Aura
* eff0
= GetAura((*i
)->GetId(),0);
9411 if(!eff0
|| (*i
)->GetEffIndex()!=1)
9413 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
9417 // effect 0 have expected value but in negative state
9418 TakenTotalMod
*= (-eff0
->GetModifier()->m_amount
+100.0f
)/100.0f
;
9424 if(attType
!= RANGED_ATTACK
)
9426 AuraList
const& mModMeleeDamageTakenPercent
= pVictim
->GetAurasByType(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
9427 for(AuraList::const_iterator i
= mModMeleeDamageTakenPercent
.begin(); i
!= mModMeleeDamageTakenPercent
.end(); ++i
)
9428 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9432 AuraList
const& mModRangedDamageTakenPercent
= pVictim
->GetAurasByType(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
9433 for(AuraList::const_iterator i
= mModRangedDamageTakenPercent
.begin(); i
!= mModRangedDamageTakenPercent
.end(); ++i
)
9434 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
9437 float tmpDamage
= float(int32(*pdamage
) + DoneFlatBenefit
) * DoneTotalMod
;
9439 // apply spellmod to Done damage
9442 if(Player
* modOwner
= GetSpellModOwner())
9443 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_DAMAGE
, tmpDamage
);
9446 tmpDamage
= (tmpDamage
+ TakenFlatBenefit
)*TakenTotalMod
;
9448 // bonus result can be negative
9449 *pdamage
= tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
9452 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
9456 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
9459 if(itr
->type
== type
)
9461 m_spellImmune
[op
].erase(itr
);
9462 next
= m_spellImmune
[op
].begin();
9466 Immune
.spellId
= spellId
;
9468 m_spellImmune
[op
].push_back(Immune
);
9472 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
9474 if(itr
->spellId
== spellId
)
9476 m_spellImmune
[op
].erase(itr
);
9484 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
9486 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
9488 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
9489 RemoveAurasWithDispelType(type
);
9492 float Unit::GetWeaponProcChance() const
9494 // normalized proc chance for weapon attack speed
9496 if(isAttackReady(BASE_ATTACK
))
9497 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
9498 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
9499 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
9503 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
9505 // proc per minute chance calculation
9506 if (PPM
<= 0) return 0.0f
;
9507 uint32 result
= uint32((WeaponSpeed
* PPM
) / 600.0f
); // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
9511 void Unit::Mount(uint32 mount
)
9516 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
9518 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
9520 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
9523 if(GetTypeId() == TYPEID_PLAYER
)
9525 Pet
* pet
= GetPet();
9528 if(pet
->isControlled())
9530 ((Player
*)this)->SetTemporaryUnsummonedPetNumber(pet
->GetCharmInfo()->GetPetNumber());
9531 ((Player
*)this)->SetOldPetSpell(pet
->GetUInt32Value(UNIT_CREATED_BY_SPELL
));
9534 ((Player
*)this)->RemovePet(NULL
,PET_SAVE_NOT_IN_SLOT
);
9537 ((Player
*)this)->SetTemporaryUnsummonedPetNumber(0);
9541 void Unit::Unmount()
9546 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
9548 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
9549 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
9551 // only resummon old pet if the player is already added to a map
9552 // this prevents adding a pet to a not created map which would otherwise cause a crash
9553 // (it could probably happen when logging in after a previous crash)
9554 if(GetTypeId() == TYPEID_PLAYER
&& IsInWorld() && ((Player
*)this)->GetTemporaryUnsummonedPetNumber() && isAlive())
9556 Pet
* NewPet
= new Pet
;
9557 if(!NewPet
->LoadPetFromDB(this, 0, ((Player
*)this)->GetTemporaryUnsummonedPetNumber(), true))
9560 ((Player
*)this)->SetTemporaryUnsummonedPetNumber(0);
9564 void Unit::SetInCombatWith(Unit
* enemy
)
9566 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
9569 SetInCombatState(true);
9574 if(eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
9576 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
9577 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
9579 SetInCombatState(true);
9583 SetInCombatState(false);
9586 void Unit::SetInCombatState(bool PvP
)
9588 // only alive units can be in combat
9593 m_CombatTimer
= 5000;
9594 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
9596 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
9597 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
9600 void Unit::ClearInCombat()
9603 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
9605 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
9606 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
9608 // Player's state will be cleared in Player::UpdateContestedPvP
9609 if(GetTypeId()!=TYPEID_PLAYER
)
9610 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
9613 bool Unit::isTargetableForAttack() const
9615 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
9618 if(HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
9621 return isAlive() && !hasUnitState(UNIT_STAT_DIED
)&& !isInFlight() /*&& !isStealth()*/;
9624 int32
Unit::ModifyHealth(int32 dVal
)
9631 int32 curHealth
= (int32
)GetHealth();
9633 int32 val
= dVal
+ curHealth
;
9640 int32 maxHealth
= (int32
)GetMaxHealth();
9645 gain
= val
- curHealth
;
9647 else if(curHealth
!= maxHealth
)
9649 SetHealth(maxHealth
);
9650 gain
= maxHealth
- curHealth
;
9656 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
9663 int32 curPower
= (int32
)GetPower(power
);
9665 int32 val
= dVal
+ curPower
;
9672 int32 maxPower
= (int32
)GetMaxPower(power
);
9676 SetPower(power
,val
);
9677 gain
= val
- curPower
;
9679 else if(curPower
!= maxPower
)
9681 SetPower(power
,maxPower
);
9682 gain
= maxPower
- curPower
;
9688 bool Unit::isVisibleForOrDetect(Unit
const* u
, bool detect
, bool inVisibleList
) const
9693 // Always can see self
9697 // player visible for other player if not logout and at same transport
9698 // including case when player is out of world
9699 bool at_same_transport
=
9700 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
9701 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
9702 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
9703 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
9706 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
9709 // forbidden to seen (at GM respawn command)
9710 if(m_Visibility
==VISIBILITY_RESPAWN
)
9713 // always seen by owner
9714 if(GetCharmerOrOwnerGUID()==u
->GetGUID())
9717 // Grid dead/alive checks
9718 if( u
->GetTypeId()==TYPEID_PLAYER
)
9720 // non visible at grid for any stealth state
9721 if(!IsVisibleInGridForPlayer((Player
*)u
))
9724 // if player is dead then he can't detect anyone in any cases
9730 // all dead creatures/players not visible for any creatures
9731 if(!u
->isAlive() || !isAlive())
9735 // different visible distance checks
9736 if(u
->isInFlight()) // what see player in flight
9738 // use object grey distance for all (only see objects any way)
9739 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
)))
9742 else if(!isAlive()) // distance for show body
9744 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
)))
9747 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
9749 if(u
->GetTypeId()==TYPEID_PLAYER
)
9751 // Players far than max visible distance for player or not in our map are not visible too
9752 if (!at_same_transport
&& !IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForPlayer()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
)))
9757 // Units far than max visible distance for creature or not in our map are not visible too
9758 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForCreature()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
)))
9762 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
9764 // Pet/charmed far than max visible distance for player or not in our map are not visible too
9765 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForPlayer()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
)))
9768 else // distance for show creature
9770 // Units far than max visible distance for creature or not in our map are not visible too
9771 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForCreature()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
)))
9775 // Visible units, always are visible for all units, except for units under invisibility
9776 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0)
9779 // GMs see any players, not higher GMs and all units
9780 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
9782 if(GetTypeId() == TYPEID_PLAYER
)
9783 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
9788 // non faction visibility non-breakable for non-GMs
9789 if (m_Visibility
== VISIBILITY_OFF
)
9793 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
9795 // detectable invisibility case
9797 // Invisible units, always are visible for units under same invisibility type
9798 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
9799 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
9800 u
->canDetectInvisibilityOf(this) ||
9801 // Units that can detect invisibility always are visible for units that can be detected
9802 canDetectInvisibilityOf(u
) ))
9807 // special cases for always overwrite invisibility/stealth
9808 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
9811 if (!u
->IsHostileTo(this))
9813 // 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)
9814 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
9816 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
9819 // else apply same rules as for hostile case (detecting check for stealth)
9825 // Hunter mark functionality
9826 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
9827 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
9828 if((*iter
)->GetCasterGUID()==u
->GetGUID())
9831 // else apply detecting check for stealth
9834 // none other cases for detect invisibility, so invisible
9838 // else apply stealth detecting check
9841 // unit got in stealth in this moment and must ignore old detected state
9842 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
9845 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
9846 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
9849 // NOW ONLY STEALTH CASE
9851 // stealth and detected and visible for some seconds
9852 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->m_DetectInvTimer
> 300 && ((Player
*)u
)->HaveAtClient(this))
9855 //if in non-detect mode then invisible for unit
9861 // If is attacked then stealth is lost, some creature can use stealth too
9862 if( !getAttackers().empty() )
9865 // If there is collision rogue is seen regardless of level difference
9866 // TODO: check sizes in DB
9867 float distance
= GetDistance(u
);
9868 if (distance
< 0.24f
)
9871 //If a mob or player is stunned he will not be able to detect stealth
9872 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
9875 // Creature can detect target only in aggro radius
9876 if(u
->GetTypeId() != TYPEID_PLAYER
)
9878 //Always invisible from back and out of aggro range
9879 bool isInFront
= u
->isInFront(this,((Creature
const*)u
)->GetAttackDistance(this));
9885 //Always invisible from back
9886 bool isInFront
= u
->isInFront(this,(GetTypeId()==TYPEID_PLAYER
|| GetCharmerOrOwnerGUID()) ? World::GetMaxVisibleDistanceForPlayer() : World::GetMaxVisibleDistanceForCreature());
9891 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
9892 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
9894 //Calculation if target is in front
9896 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
9897 float visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
9899 //Visible distance is modified by
9900 //-Level Diff (every level diff = 1.0f in visible distance)
9901 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
9903 //This allows to check talent tree and will add addition stealth dependent on used points)
9904 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
9908 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
9909 //based on wowwiki every 5 mod we have 1 more level diff in calculation
9910 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_DETECT
)) - stealthMod
)/5.0f
;
9912 if(distance
> visibleDistance
)
9916 // Now check is target visible with LoS
9918 u
->GetPosition(ox
,oy
,oz
);
9919 return IsWithinLOS(ox
,oy
,oz
);
9922 void Unit::SetVisibility(UnitVisibility x
)
9930 if(GetTypeId()==TYPEID_PLAYER
)
9931 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
9933 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
9937 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
9939 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
9941 for(uint32 i
= 0; i
< 10; ++i
)
9943 if(((1 << i
) & mask
)==0)
9946 // find invisibility level
9947 uint32 invLevel
= 0;
9948 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
9949 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
9950 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
9951 invLevel
= (*itr
)->GetModifier()->m_amount
;
9953 // find invisibility detect level
9954 uint32 detectLevel
= 0;
9955 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
9956 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
9957 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
9958 detectLevel
= (*itr
)->GetModifier()->m_amount
;
9960 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
9962 detectLevel
= ((Player
*)this)->GetDrunkValue();
9965 if(invLevel
<= detectLevel
)
9973 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
)
9975 int32 main_speed_mod
= 0;
9976 float stack_bonus
= 1.0f
;
9977 float non_stack_bonus
= 1.0f
;
9985 if (IsMounted()) // Use on mount auras
9987 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
9988 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
9989 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
9993 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
9994 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
9995 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
10003 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
10006 case MOVE_SWIMBACK
:
10010 if (IsMounted()) // Use on mount auras
10011 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
);
10012 else // Use not mount (shapeshift for example) auras (should stack)
10013 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT
);
10014 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS
);
10015 non_stack_bonus
= (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
))/100.0f
;
10021 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
10025 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
10026 // now we ready for speed calculation
10027 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
10035 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
10036 // TODO: possible affect only on MOVE_RUN
10037 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
10039 // Use speed from aura
10040 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
10041 if (speed
> max_speed
)
10050 // Apply strongest slow aura mod to speed
10051 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
10053 speed
*=(100.0f
+ slow
)/100.0f
;
10054 SetSpeed(mtype
, speed
, forced
);
10057 float Unit::GetSpeed( UnitMoveType mtype
) const
10059 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
10062 void Unit::SetSpeed(UnitMoveType mtype
, float rate
, bool forced
)
10067 // Update speed only on change
10068 if (m_speed_rate
[mtype
] == rate
)
10071 m_speed_rate
[mtype
] = rate
;
10073 propagateSpeedChange();
10075 // Send speed change packet only for player
10076 if (GetTypeId()!=TYPEID_PLAYER
)
10085 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+1+4+4+4+4+4+4+4);
10088 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+1+4+4+4+4+4+4+4);
10090 case MOVE_WALKBACK
:
10091 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+1+4+4+4+4+4+4+4);
10094 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+1+4+4+4+4+4+4+4);
10096 case MOVE_SWIMBACK
:
10097 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+1+4+4+4+4+4+4+4);
10100 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+1+4+4+4+4+4+4+4);
10103 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+1+4+4+4+4+4+4+4);
10106 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+1+4+4+4+4+4+4+4);
10109 sLog
.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype
);
10113 data
.append(GetPackGUID());
10114 data
<< uint32(0); //movement flags
10115 data
<< uint8(0); //unk
10116 data
<< uint32(getMSTime());
10117 data
<< float(GetPositionX());
10118 data
<< float(GetPositionY());
10119 data
<< float(GetPositionZ());
10120 data
<< float(GetOrientation());
10121 data
<< uint32(0); //flag unk
10122 data
<< float(GetSpeed(mtype
));
10123 SendMessageToSet( &data
, true );
10127 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
10128 // and do it only for real sent packets and use run for run/mounted as client expected
10129 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
10133 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
10136 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
10138 case MOVE_WALKBACK
:
10139 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
10142 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
10144 case MOVE_SWIMBACK
:
10145 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
10148 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
10151 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
10154 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
10157 sLog
.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype
);
10160 data
.append(GetPackGUID());
10162 if (mtype
== MOVE_RUN
)
10163 data
<< uint8(0); // new 2.1.0
10164 data
<< float(GetSpeed(mtype
));
10165 SendMessageToSet( &data
, true );
10167 if(Pet
* pet
= GetPet())
10168 pet
->SetSpeed(MOVE_RUN
, m_speed_rate
[mtype
],forced
);
10171 void Unit::SetHover(bool on
)
10174 CastSpell(this,11010,true);
10176 RemoveAurasDueToSpell(11010);
10179 void Unit::setDeathState(DeathState s
)
10181 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
10184 DeleteThreatList();
10185 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
10187 if(IsNonMeleeSpellCasted(false))
10188 InterruptNonMeleeSpells(false);
10191 if (s
== JUST_DIED
)
10193 RemoveAllAurasOnDeath();
10194 UnsummonAllTotems();
10196 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
10197 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
10198 // remove aurastates allowing special moves
10199 ClearAllReactives();
10200 ClearDiminishings();
10202 else if(s
== JUST_ALIVED
)
10204 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
10207 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
10209 //_ApplyAllAuraMods();
10214 /*########################################
10216 ######## AGGRO SYSTEM ########
10218 ########################################*/
10219 bool Unit::CanHaveThreatList() const
10221 // only creatures can have threat list
10222 if( GetTypeId() != TYPEID_UNIT
)
10225 // only alive units can have threat list
10229 // pets and totems can not have threat list
10230 if( ((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem() )
10236 //======================================================================
10238 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
10240 if(!HasAuraType(SPELL_AURA_MOD_THREAT
))
10243 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
10245 return threat
* m_threatModifier
[school
];
10248 //======================================================================
10250 void Unit::AddThreat(Unit
* pVictim
, float threat
, SpellSchoolMask schoolMask
, SpellEntry
const *threatSpell
)
10252 // Only mobs can manage threat lists
10253 if(CanHaveThreatList())
10254 m_ThreatManager
.addThreat(pVictim
, threat
, schoolMask
, threatSpell
);
10257 //======================================================================
10259 void Unit::DeleteThreatList()
10261 m_ThreatManager
.clearReferences();
10264 //======================================================================
10266 void Unit::TauntApply(Unit
* taunter
)
10268 assert(GetTypeId()== TYPEID_UNIT
);
10270 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
10273 if(!CanHaveThreatList())
10276 Unit
*target
= getVictim();
10277 if(target
&& target
== taunter
)
10280 SetInFront(taunter
);
10281 if (((Creature
*)this)->AI())
10282 ((Creature
*)this)->AI()->AttackStart(taunter
);
10284 m_ThreatManager
.tauntApply(taunter
);
10287 //======================================================================
10289 void Unit::TauntFadeOut(Unit
*taunter
)
10291 assert(GetTypeId()== TYPEID_UNIT
);
10293 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
10296 if(!CanHaveThreatList())
10299 Unit
*target
= getVictim();
10300 if(!target
|| target
!= taunter
)
10303 if(m_ThreatManager
.isThreatListEmpty())
10305 if(((Creature
*)this)->AI())
10306 ((Creature
*)this)->AI()->EnterEvadeMode();
10310 m_ThreatManager
.tauntFadeOut(taunter
);
10311 target
= m_ThreatManager
.getHostilTarget();
10313 if (target
&& target
!= taunter
)
10315 SetInFront(target
);
10316 if (((Creature
*)this)->AI())
10317 ((Creature
*)this)->AI()->AttackStart(target
);
10321 //======================================================================
10323 bool Unit::SelectHostilTarget()
10325 //function provides main threat functionality
10326 //next-victim-selection algorithm and evade mode are called
10327 //threat list sorting etc.
10329 assert(GetTypeId()== TYPEID_UNIT
);
10330 Unit
* target
= NULL
;
10332 //This function only useful once AI has been initialized
10333 if (!((Creature
*)this)->AI())
10336 if(!m_ThreatManager
.isThreatListEmpty())
10338 if(!HasAuraType(SPELL_AURA_MOD_TAUNT
))
10340 target
= m_ThreatManager
.getHostilTarget();
10346 if(!hasUnitState(UNIT_STAT_STUNNED
))
10347 SetInFront(target
);
10348 ((Creature
*)this)->AI()->AttackStart(target
);
10352 // no target but something prevent go to evade mode
10353 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
10356 // last case when creature don't must go to evade mode:
10357 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
10358 // for example at owner command to pet attack some far away creature
10359 // Note: creature not have targeted movement generator but have attacker in this case
10360 if( GetMotionMaster()->GetCurrentMovementGeneratorType() != TARGETED_MOTION_TYPE
)
10362 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
10364 if( (*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this) )
10369 // enter in evade mode in other case
10370 ((Creature
*)this)->AI()->EnterEvadeMode();
10375 //======================================================================
10376 //======================================================================
10377 //======================================================================
10379 int32
Unit::CalculateSpellDamage(SpellEntry
const* spellProto
, uint8 effect_index
, int32 effBasePoints
, Unit
const* target
)
10381 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
10383 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
10385 int32 level
= int32(getLevel()) - int32(spellProto
->spellLevel
);
10386 if (level
> spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
10387 level
= spellProto
->maxLevel
;
10389 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
10390 float randomPointsPerLevel
= spellProto
->EffectDicePerLevel
[effect_index
];
10391 int32 basePoints
= int32(effBasePoints
+ level
* basePointsPerLevel
);
10392 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
] + level
* randomPointsPerLevel
);
10393 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
10395 // prevent random generator from getting confused by spells casted with Unit::CastCustomSpell
10396 int32 randvalue
= spellProto
->EffectBaseDice
[effect_index
] >= randomPoints
? spellProto
->EffectBaseDice
[effect_index
]:irand(spellProto
->EffectBaseDice
[effect_index
], randomPoints
);
10397 int32 value
= basePoints
+ randvalue
;
10399 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
10400 value
+= (int32
)(comboDamage
* comboPoints
);
10402 if(Player
* modOwner
= GetSpellModOwner())
10404 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_ALL_EFFECTS
, value
);
10405 switch(effect_index
)
10408 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT1
, value
);
10411 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT2
, value
);
10414 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT3
, value
);
10419 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
10420 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
10421 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
)
10422 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
10427 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, uint8 effect_index
, Unit
const* target
)
10429 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
10431 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
10433 int32 minduration
= GetSpellDuration(spellProto
);
10434 int32 maxduration
= GetSpellMaxDuration(spellProto
);
10438 if( minduration
!= -1 && minduration
!= maxduration
)
10439 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
10441 duration
= minduration
;
10445 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
10446 // Find total mod value (negative bonus)
10447 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
10448 // Find max mod (negative bonus)
10449 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
10451 int32 durationMod
= 0;
10452 // Select strongest negative mod
10453 if (durationMod_always
> durationMod_not_stack
)
10454 durationMod
= durationMod_not_stack
;
10456 durationMod
= durationMod_always
;
10458 if (durationMod
!= 0)
10459 duration
= int32(int64(duration
) * (100+durationMod
) /100);
10461 if (duration
< 0) duration
= 0;
10467 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
10469 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
10471 if(i
->DRGroup
!= group
)
10475 return DIMINISHING_LEVEL_1
;
10478 return DIMINISHING_LEVEL_1
;
10480 // If last spell was casted more than 15 seconds ago - reset the count.
10481 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
10483 i
->hitCount
= DIMINISHING_LEVEL_1
;
10484 return DIMINISHING_LEVEL_1
;
10486 // or else increase the count.
10489 return DiminishingLevels(i
->hitCount
);
10492 return DIMINISHING_LEVEL_1
;
10495 void Unit::IncrDiminishing(DiminishingGroup group
)
10497 // Checking for existing in the table
10498 bool IsExist
= false;
10499 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
10501 if(i
->DRGroup
!= group
)
10505 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
10512 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
10515 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
)
10517 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
10520 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
10521 if(duration
> 10000 && IsDiminishingReturnsGroupDurationLimited(group
))
10523 // test pet/charm masters instead pets/charmeds
10524 Unit
const* targetOwner
= GetCharmerOrOwner();
10525 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
10527 Unit
const* target
= targetOwner
? targetOwner
: this;
10528 Unit
const* source
= casterOwner
? casterOwner
: caster
;
10530 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
10536 // Some diminishings applies to mobs too (for example, Stun)
10537 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
10539 DiminishingLevels diminish
= Level
;
10542 case DIMINISHING_LEVEL_1
: break;
10543 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
10544 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
10545 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
10550 duration
= int32(duration
* mod
);
10553 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
10555 // Checking for existing in the table
10556 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
10558 if(i
->DRGroup
!= group
)
10561 i
->hitTime
= getMSTime();
10572 Unit
* Unit::GetUnit(WorldObject
& object
, uint64 guid
)
10574 return ObjectAccessor::GetUnit(object
,guid
);
10577 bool Unit::isVisibleForInState( Player
const* u
, bool inVisibleList
) const
10579 return isVisibleForOrDetect(u
,false,inVisibleList
);
10582 uint32
Unit::GetCreatureType() const
10584 if(GetTypeId() == TYPEID_PLAYER
)
10586 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(((Player
*)this)->m_form
);
10587 if(ssEntry
&& ssEntry
->creatureType
> 0)
10588 return ssEntry
->creatureType
;
10590 return CREATURE_TYPE_HUMANOID
;
10593 return ((Creature
*)this)->GetCreatureInfo()->type
;
10596 /*#######################################
10598 ######## STAT SYSTEM ########
10600 #######################################*/
10602 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
10604 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
10606 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
10612 switch(modifierType
)
10616 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
10620 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
10623 val
= (100.0f
+ amount
) / 100.0f
;
10624 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
10631 if(!CanModifyStats())
10636 case UNIT_MOD_STAT_STRENGTH
:
10637 case UNIT_MOD_STAT_AGILITY
:
10638 case UNIT_MOD_STAT_STAMINA
:
10639 case UNIT_MOD_STAT_INTELLECT
:
10640 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
10642 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
10643 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
10645 case UNIT_MOD_MANA
:
10646 case UNIT_MOD_RAGE
:
10647 case UNIT_MOD_FOCUS
:
10648 case UNIT_MOD_ENERGY
:
10649 case UNIT_MOD_HAPPINESS
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
10651 case UNIT_MOD_RESISTANCE_HOLY
:
10652 case UNIT_MOD_RESISTANCE_FIRE
:
10653 case UNIT_MOD_RESISTANCE_NATURE
:
10654 case UNIT_MOD_RESISTANCE_FROST
:
10655 case UNIT_MOD_RESISTANCE_SHADOW
:
10656 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
10658 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
10659 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
10661 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
10662 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
10663 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
10672 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
10674 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
10676 sLog
.outError("ERROR: trial to access non existed modifier value from UnitMods!");
10680 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
10683 return m_auraModifiersGroup
[unitMod
][modifierType
];
10686 float Unit::GetTotalStatValue(Stats stat
) const
10688 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
10690 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
10693 // value = ((base_value * base_pct) + total_value) * total_pct
10694 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
10695 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
10696 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
10697 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
10702 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
10704 if(unitMod
>= UNIT_MOD_END
)
10706 sLog
.outError("ERROR: trial to access non existed UnitMods in GetTotalAuraModValue()!");
10710 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
10713 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
10714 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
10715 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
10716 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
10721 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
10723 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
10727 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
10728 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
10729 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
10730 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
10731 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
10732 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
10741 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
10743 Stats stat
= STAT_STRENGTH
;
10747 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
10748 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
10749 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
10750 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
10751 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
10760 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
10762 Powers power
= POWER_MANA
;
10766 case UNIT_MOD_MANA
: power
= POWER_MANA
; break;
10767 case UNIT_MOD_RAGE
: power
= POWER_RAGE
; break;
10768 case UNIT_MOD_FOCUS
: power
= POWER_FOCUS
; break;
10769 case UNIT_MOD_ENERGY
: power
= POWER_ENERGY
; break;
10770 case UNIT_MOD_HAPPINESS
: power
= POWER_HAPPINESS
; break;
10779 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
10781 UnitMods unitMod
= (attType
== RANGED_ATTACK
) ? UNIT_MOD_ATTACK_POWER_RANGED
: UNIT_MOD_ATTACK_POWER
;
10783 float val
= GetTotalAuraModValue(unitMod
);
10790 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
10792 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
10795 return m_weaponDamage
[attType
][type
];
10798 void Unit::SetLevel(uint32 lvl
)
10800 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
10803 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
10804 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
10807 void Unit::SetHealth(uint32 val
)
10809 uint32 maxHealth
= GetMaxHealth();
10810 if(maxHealth
< val
)
10813 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
10816 if(GetTypeId() == TYPEID_PLAYER
)
10818 if(((Player
*)this)->GetGroup())
10819 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
10821 else if(((Creature
*)this)->isPet())
10823 Pet
*pet
= ((Pet
*)this);
10824 if(pet
->isControlled())
10826 Unit
*owner
= GetOwner();
10827 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10828 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
10833 void Unit::SetMaxHealth(uint32 val
)
10835 uint32 health
= GetHealth();
10836 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
10839 if(GetTypeId() == TYPEID_PLAYER
)
10841 if(((Player
*)this)->GetGroup())
10842 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
10844 else if(((Creature
*)this)->isPet())
10846 Pet
*pet
= ((Pet
*)this);
10847 if(pet
->isControlled())
10849 Unit
*owner
= GetOwner();
10850 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10851 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP
);
10859 void Unit::SetPower(Powers power
, uint32 val
)
10861 if(GetPower(power
) == val
)
10864 uint32 maxPower
= GetMaxPower(power
);
10868 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
10871 if(GetTypeId() == TYPEID_PLAYER
)
10873 if(((Player
*)this)->GetGroup())
10874 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
10876 else if(((Creature
*)this)->isPet())
10878 Pet
*pet
= ((Pet
*)this);
10879 if(pet
->isControlled())
10881 Unit
*owner
= GetOwner();
10882 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10883 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
10886 // Update the pet's character sheet with happiness damage bonus
10887 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
10889 pet
->UpdateDamagePhysical(BASE_ATTACK
);
10894 void Unit::SetMaxPower(Powers power
, uint32 val
)
10896 uint32 cur_power
= GetPower(power
);
10897 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
10900 if(GetTypeId() == TYPEID_PLAYER
)
10902 if(((Player
*)this)->GetGroup())
10903 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
10905 else if(((Creature
*)this)->isPet())
10907 Pet
*pet
= ((Pet
*)this);
10908 if(pet
->isControlled())
10910 Unit
*owner
= GetOwner();
10911 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10912 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
10916 if(val
< cur_power
)
10917 SetPower(power
, val
);
10920 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
10922 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
10925 if(GetTypeId() == TYPEID_PLAYER
)
10927 if(((Player
*)this)->GetGroup())
10928 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
10930 else if(((Creature
*)this)->isPet())
10932 Pet
*pet
= ((Pet
*)this);
10933 if(pet
->isControlled())
10935 Unit
*owner
= GetOwner();
10936 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10937 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
10942 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
10944 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
10947 if(GetTypeId() == TYPEID_PLAYER
)
10949 if(((Player
*)this)->GetGroup())
10950 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
10952 else if(((Creature
*)this)->isPet())
10954 Pet
*pet
= ((Pet
*)this);
10955 if(pet
->isControlled())
10957 Unit
*owner
= GetOwner();
10958 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10959 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
10964 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
10966 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
10968 tAuraProcTriggerDamage
.push_back(aura
);
10970 tAuraProcTriggerDamage
.remove(aura
);
10973 uint32
Unit::GetCreatePowers( Powers power
) const
10975 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
10978 case POWER_MANA
: return GetCreateMana();
10979 case POWER_RAGE
: return 1000;
10980 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
10981 case POWER_ENERGY
: return 100;
10982 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
10988 void Unit::AddToWorld()
10990 Object::AddToWorld();
10993 void Unit::RemoveFromWorld()
10998 RemoveNotOwnSingleTargetAuras();
11001 Object::RemoveFromWorld();
11004 void Unit::CleanupsBeforeDelete()
11006 if(m_uint32Values
) // only for fully created object
11008 InterruptNonMeleeSpells(true);
11009 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
11011 ClearComboPointHolders();
11012 DeleteThreatList();
11013 getHostilRefManager().setOnlineOfflineState(false);
11015 RemoveAllGameObjects();
11016 RemoveAllDynObjects();
11017 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
11022 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
11025 m_charmInfo
= new CharmInfo(charm
);
11026 return m_charmInfo
;
11029 CharmInfo::CharmInfo(Unit
* unit
)
11030 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
11032 for(int i
=0; i
<4; ++i
)
11034 m_charmspells
[i
].spellId
= 0;
11035 m_charmspells
[i
].active
= ACT_DISABLED
;
11039 void CharmInfo::InitPetActionBar()
11041 // the first 3 SpellOrActions are attack, follow and stay
11042 for(uint32 i
= 0; i
< 3; i
++)
11044 PetActionBar
[i
].Type
= ACT_COMMAND
;
11045 PetActionBar
[i
].SpellOrAction
= COMMAND_ATTACK
- i
;
11047 PetActionBar
[i
+ 7].Type
= ACT_REACTION
;
11048 PetActionBar
[i
+ 7].SpellOrAction
= COMMAND_ATTACK
- i
;
11050 for(uint32 i
=0; i
< 4; i
++)
11052 PetActionBar
[i
+ 3].Type
= ACT_DISABLED
;
11053 PetActionBar
[i
+ 3].SpellOrAction
= 0;
11057 void CharmInfo::InitEmptyActionBar()
11059 for(uint32 x
= 1; x
< 10; ++x
)
11061 PetActionBar
[x
].Type
= ACT_CAST
;
11062 PetActionBar
[x
].SpellOrAction
= 0;
11064 PetActionBar
[0].Type
= ACT_COMMAND
;
11065 PetActionBar
[0].SpellOrAction
= COMMAND_ATTACK
;
11068 void CharmInfo::InitPossessCreateSpells()
11070 if(m_unit
->GetTypeId() == TYPEID_PLAYER
)
11073 InitEmptyActionBar(); //charm action bar
11075 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11077 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
11078 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
11080 AddSpellToAB(0, ((Creature
*)m_unit
)->m_spells
[x
], ACT_CAST
);
11084 void CharmInfo::InitCharmCreateSpells()
11086 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
11088 InitEmptyActionBar();
11092 InitPetActionBar();
11094 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11096 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
11097 m_charmspells
[x
].spellId
= spellId
;
11102 if (IsPassiveSpell(spellId
))
11104 m_unit
->CastSpell(m_unit
, spellId
, true);
11105 m_charmspells
[x
].active
= ACT_PASSIVE
;
11109 ActiveStates newstate
;
11110 bool onlyselfcast
= true;
11111 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
11113 if(!spellInfo
) onlyselfcast
= false;
11114 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
11116 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
11117 onlyselfcast
= false;
11120 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
11121 newstate
= ACT_DISABLED
;
11123 newstate
= ACT_CAST
;
11125 AddSpellToAB(0, spellId
, newstate
);
11130 bool CharmInfo::AddSpellToAB(uint32 oldid
, uint32 newid
, ActiveStates newstate
)
11132 for(uint8 i
= 0; i
< 10; i
++)
11134 if((PetActionBar
[i
].Type
== ACT_DISABLED
|| PetActionBar
[i
].Type
== ACT_ENABLED
|| PetActionBar
[i
].Type
== ACT_CAST
) && PetActionBar
[i
].SpellOrAction
== oldid
)
11136 PetActionBar
[i
].SpellOrAction
= newid
;
11139 if(newstate
== ACT_DECIDE
)
11140 PetActionBar
[i
].Type
= ACT_DISABLED
;
11142 PetActionBar
[i
].Type
= newstate
;
11151 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
11153 if(IsPassiveSpell(spellid
))
11156 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
11158 if(spellid
== m_charmspells
[x
].spellId
)
11160 m_charmspells
[x
].active
= apply
? ACT_ENABLED
: ACT_DISABLED
;
11165 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
11167 m_petnumber
= petnumber
;
11169 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
11171 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
11174 bool Unit::isFrozen() const
11176 AuraList
const& mRoot
= GetAurasByType(SPELL_AURA_MOD_ROOT
);
11177 for(AuraList::const_iterator i
= mRoot
.begin(); i
!= mRoot
.end(); ++i
)
11178 if( GetSpellSchoolMask((*i
)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST
)
11184 struct ProcTriggeredData
11186 ProcTriggeredData(Aura* _triggeredByAura, uint32 _cooldown)
11187 : triggeredByAura(_triggeredByAura),
11188 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura->GetId(),triggeredByAura->GetEffIndex())),
11189 cooldown(_cooldown)
11192 Aura* triggeredByAura; // triggred aura, can be invalidate at triggered aura proccessing
11193 Unit::spellEffectPair triggeredByAura_SpellPair; // spell pair, used for re-find aura (by pointer comparison in range)
11194 uint32 cooldown; // possible hidden cooldown
11197 typedef std::list< ProcTriggeredData > ProcTriggeredList;
11199 void Unit::ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, AuraTypeSet const& procAuraTypes, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage, SpellSchoolMask damageSchoolMask )
11201 for(AuraTypeSet::const_iterator aur = procAuraTypes.begin(); aur != procAuraTypes.end(); ++aur)
11203 // List of spells (effects) that proceed. Spell prototype and aura-specific value (damage for TRIGGER_DAMAGE)
11204 ProcTriggeredList procTriggered;
11206 AuraList const& auras = GetAurasByType(*aur);
11207 for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next)
11213 uint32 cooldown; // returned at next line
11214 if(!IsTriggeredAtSpellProcEvent(i_aura->GetSpellProto(), procSpell, procFlag,attType,isVictim,cooldown))
11217 procTriggered.push_back( ProcTriggeredData(i_aura, cooldown) );
11220 // Handle effects proceed this time
11221 for(ProcTriggeredList::iterator i = procTriggered.begin(); i != procTriggered.end(); ++i)
11223 // Some auras can be deleted in function called in this loop (except first, ofc)
11224 // Until storing auras in std::multimap to hard check deleting by another way
11225 if(i != procTriggered.begin())
11227 bool found = false;
11228 AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair);
11229 AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair);
11230 for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr)
11232 if(itr->second==i->triggeredByAura)
11241 sLog.outError("Spell aura %u (id:%u effect:%u) has been deleted before call spell proc event handler",*aur,i->triggeredByAura_SpellPair.first,i->triggeredByAura_SpellPair.second);
11242 sLog.outError("It can be deleted one from early processed auras:");
11243 for(ProcTriggeredList::iterator i2 = procTriggered.begin(); i != i2; ++i2)
11244 sLog.outError(" Spell aura %u (id:%u effect:%u)",*aur,i2->triggeredByAura_SpellPair.first,i2->triggeredByAura_SpellPair.second);
11245 sLog.outError(" <end of list>");
11250 /// this is aura triggering code call
11251 Aura* triggeredByAura = i->triggeredByAura;
11253 /// save charges existence before processing to prevent crash at access to deleted triggered aura after
11254 /// used in speedup code check before check aura existance.
11255 bool triggeredByAuraWithCharges = triggeredByAura->m_procCharges > 0;
11257 /// success in event proccesing
11258 /// used in speedup code check before check aura existance.
11259 bool casted = false;
11261 /// process triggered code
11264 case SPELL_AURA_PROC_TRIGGER_SPELL:
11266 sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s proc aura of spell %u)",
11267 (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId());
11268 casted = HandleProcTriggerSpell(pTarget, damage, triggeredByAura, procSpell, procFlag, attType, i->cooldown);
11271 case SPELL_AURA_PROC_TRIGGER_DAMAGE:
11273 uint32 triggered_damage = triggeredByAura->GetModifier()->m_amount;
11274 sLog.outDebug("ProcDamageAndSpell: doing %u damage (triggered by %s aura of spell %u)",
11275 triggered_damage, (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId());
11276 SpellNonMeleeDamageLog(pTarget, triggeredByAura->GetId(), triggered_damage, true, true);
11280 case SPELL_AURA_DUMMY:
11282 uint32 effect = triggeredByAura->GetEffIndex();
11283 sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s dummy aura of spell %u)",
11284 (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId());
11285 casted = HandleDummyAuraProc(pTarget, damage, triggeredByAura, procSpell, procFlag,i->cooldown);
11288 case SPELL_AURA_PRAYER_OF_MENDING:
11290 sLog.outDebug("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
11291 (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId());
11293 casted = HandleMeandingAuraProc(triggeredByAura);
11296 case SPELL_AURA_MOD_HASTE:
11298 sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s haste aura of spell %u)",
11299 (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId());
11300 casted = HandleHasteAuraProc(pTarget, damage, triggeredByAura, procSpell, procFlag,i->cooldown);
11303 case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN:
11305 // nothing do, just charges counter
11306 // but count only in case appropriate school damage
11307 casted = triggeredByAura->GetModifier()->m_miscvalue & damageSchoolMask;
11310 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS:
11312 sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s class script aura of spell %u)",
11313 (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId());
11314 casted = HandleOverrideClassScriptAuraProc(pTarget, triggeredByAura, procSpell,i->cooldown);
11319 // nothing do, just charges counter
11325 /// Update charge (aura can be removed by triggers)
11326 if(casted && triggeredByAuraWithCharges)
11328 /// need re-found aura (can be dropped by triggers)
11329 AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair);
11330 AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair);
11331 for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr)
11333 if(itr->second == triggeredByAura) // pointer still valid
11335 if(triggeredByAura->m_procCharges > 0)
11336 triggeredByAura->m_procCharges -= 1;
11338 triggeredByAura->UpdateAuraCharges();
11345 /// Safely remove auras with zero charges
11346 for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next)
11349 if((*i)->m_procCharges == 0)
11351 RemoveAurasDueToSpell((*i)->GetId());
11352 next = auras.begin();
11358 struct ProcTriggeredData
11360 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
11361 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
11362 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
11364 SpellProcEventEntry
const *spellProcEvent
;
11365 Aura
* triggeredByAura
;
11366 Unit::spellEffectPair triggeredByAura_SpellPair
;
11369 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
11370 typedef std::list
< uint32
> RemoveSpellList
;
11372 // List of auras that CAN be trigger but may not exist in spell_proc_event
11373 // in most case need for drop charges
11374 // in some types of aura need do additional check
11375 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
11376 static bool isTriggerAura
[TOTAL_AURAS
];
11377 static bool isNonTriggerAura
[TOTAL_AURAS
];
11378 void InitTriggerAuraData()
11380 for (int i
=0;i
<TOTAL_AURAS
;i
++)
11382 isTriggerAura
[i
]=false;
11383 isNonTriggerAura
[i
] = false;
11385 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
11386 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
11387 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
11388 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
11389 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
11390 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
11391 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
11392 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
11393 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
11394 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
11395 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
11396 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
11397 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED
] = true;
11398 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
11399 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
11400 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
11401 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
11402 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
11403 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
11404 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
11405 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
11406 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
11407 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
11408 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
11409 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
11410 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
11411 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
11413 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
11414 isNonTriggerAura
[SPELL_AURA_RESIST_PUSHBACK
]=true;
11417 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
11419 uint32 procEx
= PROC_EX_NONE
;
11420 // Check victim state
11421 if (missCondition
!=SPELL_MISS_NONE
)
11422 switch (missCondition
)
11424 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
11425 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
11426 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
11427 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
11428 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
11429 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
11430 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
11431 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
11432 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
11433 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
11434 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
11441 if (damageInfo
->blocked
)
11442 procEx
|=PROC_EX_BLOCK
;
11444 if (damageInfo
->absorb
)
11445 procEx
|=PROC_EX_ABSORB
;
11447 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
11448 procEx
|=PROC_EX_CRITICAL_HIT
;
11450 procEx
|=PROC_EX_NORMAL_HIT
;
11455 static int deep
= 0;
11456 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
11461 sLog
.outError("Prevent possible stack owerflow in Unit::ProcDamageAndSpellFor");
11463 sLog
.outError(" Spell %u", procSpell
->Id
);
11467 // For melee/ranged based attack need update skills and set some Aura states
11468 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
11470 // Update skills here for players
11471 if (GetTypeId() == TYPEID_PLAYER
)
11473 // On melee based hit/miss/resist need update skill (for victim and attacker)
11474 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
11476 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
11477 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, MELEE_HIT_MISS
, isVictim
);
11479 // Update defence if player is victim and parry/dodge/block
11480 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
11481 ((Player
*)this)->UpdateDefense();
11483 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
11484 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
11489 // if victim and dodge attack
11490 if (procExtra
&PROC_EX_DODGE
)
11492 //Update AURA_STATE on dodge
11493 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
11495 ModifyAuraState(AURA_STATE_DEFENSE
, true);
11496 StartReactiveTimer( REACTIVE_DEFENSE
);
11499 // if victim and parry attack
11500 if (procExtra
& PROC_EX_PARRY
)
11502 // For Hunters only Counterattack (skip Mongoose bite)
11503 if (getClass() == CLASS_HUNTER
)
11505 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
11506 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
11510 ModifyAuraState(AURA_STATE_DEFENSE
, true);
11511 StartReactiveTimer( REACTIVE_DEFENSE
);
11514 // if and victim block attack
11515 if (procExtra
& PROC_EX_BLOCK
)
11517 ModifyAuraState(AURA_STATE_DEFENSE
,true);
11518 StartReactiveTimer( REACTIVE_DEFENSE
);
11521 else //For attacker
11523 // Overpower on victim dodge
11524 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
11526 ((Player
*)this)->AddComboPoints(pTarget
, 1);
11527 StartReactiveTimer( REACTIVE_OVERPOWER
);
11529 // Enable AURA_STATE_CRIT on crit
11530 if (procExtra
& PROC_EX_CRITICAL_HIT
)
11532 ModifyAuraState(AURA_STATE_CRIT
, true);
11533 StartReactiveTimer( REACTIVE_CRIT
);
11534 if(getClass()==CLASS_HUNTER
)
11536 ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE
, true);
11537 StartReactiveTimer( REACTIVE_HUNTER_CRIT
);
11544 RemoveSpellList removedSpells
;
11545 ProcTriggeredList procTriggered
;
11546 // Fill procTriggered list
11547 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
11549 SpellProcEventEntry
const* spellProcEvent
= NULL
;
11550 if(!IsTriggeredAtSpellProcEvent(itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
11553 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
11555 // Handle effects proceed this time
11556 for(ProcTriggeredList::iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
11558 // Some auras can be deleted in function called in this loop (except first, ofc)
11559 // Until storing auars in std::multimap to hard check deleting by another way
11560 if(i
!= procTriggered
.begin())
11562 bool found
= false;
11563 AuraMap::const_iterator lower
= GetAuras().lower_bound(i
->triggeredByAura_SpellPair
);
11564 AuraMap::const_iterator upper
= GetAuras().upper_bound(i
->triggeredByAura_SpellPair
);
11565 for(AuraMap::const_iterator itr
= lower
; itr
!= upper
; ++itr
)
11567 if(itr
->second
==i
->triggeredByAura
)
11575 // sLog.outDebug("Spell aura %u (id:%u effect:%u) has been deleted before call spell proc event handler", i->triggeredByAura->GetModifier()->m_auraname, i->triggeredByAura_SpellPair.first, i->triggeredByAura_SpellPair.second);
11576 // sLog.outDebug("It can be deleted one from early proccesed auras:");
11577 // for(ProcTriggeredList::iterator i2 = procTriggered.begin(); i != i2; ++i2)
11578 // sLog.outDebug(" Spell aura %u (id:%u effect:%u)", i->triggeredByAura->GetModifier()->m_auraname,i2->triggeredByAura_SpellPair.first,i2->triggeredByAura_SpellPair.second);
11579 // sLog.outDebug(" <end of list>");
11584 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
11585 Aura
*triggeredByAura
= i
->triggeredByAura
;
11586 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
11587 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
11588 uint32 effIndex
= triggeredByAura
->GetEffIndex();
11589 bool useCharges
= triggeredByAura
->m_procCharges
> 0;
11590 // For players set spell cooldown if need
11591 uint32 cooldown
= 0;
11592 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
11593 cooldown
= spellProcEvent
->cooldown
;
11595 switch(auraModifier
->m_auraname
)
11597 case SPELL_AURA_PROC_TRIGGER_SPELL
:
11599 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
11600 // Don`t drop charge or add cooldown for not started trigger
11601 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
11605 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
11607 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());
11608 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, spellInfo
->SchoolMask
);
11609 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
11610 SendSpellNonMeleeDamageLog(&damageInfo
);
11611 DealSpellDamage(&damageInfo
, true);
11614 case SPELL_AURA_MANA_SHIELD
:
11615 case SPELL_AURA_DUMMY
:
11617 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());
11618 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
11622 case SPELL_AURA_MOD_HASTE
:
11624 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());
11625 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
11629 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
11631 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());
11632 if (!HandleOverrideClassScriptAuraProc(pTarget
, triggeredByAura
, procSpell
, cooldown
))
11636 case SPELL_AURA_PRAYER_OF_MENDING
:
11638 sLog
.outDebug("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
11639 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
11641 HandleMeandingAuraProc(triggeredByAura
);
11644 case SPELL_AURA_MOD_STUN
:
11645 // Remove by default, but if charge exist drop it
11646 if (triggeredByAura
->m_procCharges
== 0)
11647 removedSpells
.push_back(triggeredByAura
->GetId());
11649 case SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
:
11650 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
11651 // Hunter's Mark (1-4 Rangs)
11652 if (spellInfo
->SpellFamilyName
== SPELLFAMILY_HUNTER
&& (spellInfo
->SpellFamilyFlags
&0x0000000000000400LL
))
11654 uint32 basevalue
= triggeredByAura
->GetBasePoints();
11655 auraModifier
->m_amount
+= basevalue
/10;
11656 if (auraModifier
->m_amount
> basevalue
*4)
11657 auraModifier
->m_amount
= basevalue
*4;
11660 case SPELL_AURA_MOD_CASTING_SPEED
:
11661 // Skip melee hits or instant cast spells
11662 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
11665 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
11666 // Skip Melee hits and spells ws wrong school
11667 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
11670 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
11671 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
11672 // Skip melee hits and spells ws wrong school or zero cost
11673 if (procSpell
== NULL
||
11674 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
11675 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
11678 case SPELL_AURA_MECHANIC_IMMUNITY
:
11679 // Compare mechanic
11680 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
11683 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
11684 // Compare mechanic
11685 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
11689 // nothing do, just charges counter
11692 // Remove charge (aura can be removed by triggers)
11695 // need found aura on drop (can be dropped by triggers)
11696 AuraMap::const_iterator lower
= GetAuras().lower_bound(i
->triggeredByAura_SpellPair
);
11697 AuraMap::const_iterator upper
= GetAuras().upper_bound(i
->triggeredByAura_SpellPair
);
11698 for(AuraMap::const_iterator itr
= lower
; itr
!= upper
; ++itr
)
11700 if(itr
->second
== i
->triggeredByAura
)
11702 triggeredByAura
->m_procCharges
-=1;
11703 triggeredByAura
->UpdateAuraCharges();
11704 if (triggeredByAura
->m_procCharges
<= 0)
11705 removedSpells
.push_back(triggeredByAura
->GetId());
11711 if (removedSpells
.size())
11713 // Sort spells and remove dublicates
11714 removedSpells
.sort();
11715 removedSpells
.unique();
11716 // Remove auras from removedAuras
11717 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();i
++)
11718 RemoveAurasDueToSpell(*i
);
11723 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
11725 return SPELL_SCHOOL_MASK_NORMAL
;
11728 Player
* Unit::GetSpellModOwner()
11730 if(GetTypeId()==TYPEID_PLAYER
)
11731 return (Player
*)this;
11732 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
11734 Unit
* owner
= GetOwner();
11735 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
11736 return (Player
*)owner
;
11741 ///----------Pet responses methods-----------------
11742 void Unit::SendPetCastFail(uint32 spellid
, uint8 msg
)
11744 Unit
*owner
= GetCharmerOrOwner();
11745 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
11748 WorldPacket
data(SMSG_PET_CAST_FAILED
, (4+1));
11749 data
<< uint32(spellid
);
11750 data
<< uint8(msg
);
11751 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
11754 void Unit::SendPetActionFeedback (uint8 msg
)
11756 Unit
* owner
= GetOwner();
11757 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
11760 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
11761 data
<< uint8(msg
);
11762 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
11765 void Unit::SendPetTalk (uint32 pettalk
)
11767 Unit
* owner
= GetOwner();
11768 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
11771 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8+4);
11772 data
<< uint64(GetGUID());
11773 data
<< uint32(pettalk
);
11774 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
11777 void Unit::SendPetSpellCooldown (uint32 spellid
, time_t cooltime
)
11779 Unit
* owner
= GetOwner();
11780 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
11783 WorldPacket
data(SMSG_SPELL_COOLDOWN
, 8+1+4+4);
11784 data
<< uint64(GetGUID());
11785 data
<< uint8(0x0); // flags (0x1, 0x2)
11786 data
<< uint32(spellid
);
11787 data
<< uint32(cooltime
);
11789 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
11792 void Unit::SendPetClearCooldown (uint32 spellid
)
11794 Unit
* owner
= GetOwner();
11795 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
11798 WorldPacket
data(SMSG_CLEAR_COOLDOWN
, (4+8));
11799 data
<< uint32(spellid
);
11800 data
<< uint64(GetGUID());
11801 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
11804 void Unit::SendPetAIReaction(uint64 guid
)
11806 Unit
* owner
= GetOwner();
11807 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
11810 WorldPacket
data(SMSG_AI_REACTION
, 12);
11811 data
<< uint64(guid
) << uint32(00000002);
11812 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
11815 ///----------End of Pet responses methods----------
11817 void Unit::StopMoving()
11819 clearUnitState(UNIT_STAT_MOVING
);
11821 // send explicit stop packet
11822 // rely on vmaps here because for example stormwind is in air
11823 //float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true);
11824 //if (fabs(GetPositionZ() - z) < 2.0f)
11825 // Relocate(GetPositionX(), GetPositionY(), z);
11826 Relocate(GetPositionX(), GetPositionY(),GetPositionZ());
11828 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, 0);
11830 // update position and orientation;
11832 BuildHeartBeatMsg(&data
);
11833 SendMessageToSet(&data
,false);
11836 void Unit::SetFeared(bool apply
, uint64 casterGUID
, uint32 spellID
)
11840 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
11843 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
11845 GetMotionMaster()->MovementExpired(false);
11846 CastStop(GetGUID()==casterGUID
? spellID
: 0);
11848 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
11850 GetMotionMaster()->MoveFleeing(caster
); // caster==NULL processed in MoveFleeing
11854 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
11856 GetMotionMaster()->MovementExpired(false);
11858 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
11860 // restore appropriate movement generator
11862 GetMotionMaster()->MoveChase(getVictim());
11864 GetMotionMaster()->Initialize();
11866 // attack caster if can
11867 Unit
* caster
= ObjectAccessor::GetObjectInWorld(casterGUID
, (Unit
*)NULL
);
11868 if(caster
&& caster
!= getVictim() && ((Creature
*)this)->AI())
11869 ((Creature
*)this)->AI()->AttackStart(caster
);
11873 if (GetTypeId() == TYPEID_PLAYER
)
11874 ((Player
*)this)->SetClientControl(this, !apply
);
11877 void Unit::SetConfused(bool apply
, uint64 casterGUID
, uint32 spellID
)
11881 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
11883 CastStop(GetGUID()==casterGUID
? spellID
: 0);
11885 GetMotionMaster()->MoveConfused();
11889 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
11891 GetMotionMaster()->MovementExpired(false);
11893 if (GetTypeId() == TYPEID_UNIT
)
11895 // if in combat restore movement generator
11897 GetMotionMaster()->MoveChase(getVictim());
11901 if(GetTypeId() == TYPEID_PLAYER
)
11902 ((Player
*)this)->SetClientControl(this, !apply
);
11905 bool Unit::IsSitState() const
11907 uint8 s
= getStandState();
11908 return s
== PLAYER_STATE_SIT_CHAIR
|| s
== PLAYER_STATE_SIT_LOW_CHAIR
||
11909 s
== PLAYER_STATE_SIT_MEDIUM_CHAIR
|| s
== PLAYER_STATE_SIT_HIGH_CHAIR
||
11910 s
== PLAYER_STATE_SIT
;
11913 bool Unit::IsStandState() const
11915 uint8 s
= getStandState();
11916 return !IsSitState() && s
!= PLAYER_STATE_SLEEP
&& s
!= PLAYER_STATE_KNEEL
;
11919 void Unit::SetStandState(uint8 state
)
11921 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
11923 if (IsStandState())
11924 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
11926 if(GetTypeId()==TYPEID_PLAYER
)
11928 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
11929 data
<< (uint8
)state
;
11930 ((Player
*)this)->GetSession()->SendPacket(&data
);
11934 bool Unit::IsPolymorphed() const
11936 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
11939 void Unit::SetDisplayId(uint32 modelId
)
11941 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
11943 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
11945 Pet
*pet
= ((Pet
*)this);
11946 if(!pet
->isControlled())
11948 Unit
*owner
= GetOwner();
11949 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11950 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
11954 void Unit::ClearComboPointHolders()
11956 while(!m_ComboPointHolders
.empty())
11958 uint32 lowguid
= *m_ComboPointHolders
.begin();
11960 Player
* plr
= objmgr
.GetPlayer(MAKE_NEW_GUID(lowguid
, 0, HIGHGUID_PLAYER
));
11961 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
11962 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
11964 m_ComboPointHolders
.erase(lowguid
); // or remove manually
11968 void Unit::ClearAllReactives()
11971 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
11972 m_reactiveTimer
[i
] = 0;
11974 if (HasAuraState( AURA_STATE_DEFENSE
))
11975 ModifyAuraState(AURA_STATE_DEFENSE
, false);
11976 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
11977 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
11978 if (HasAuraState( AURA_STATE_CRIT
))
11979 ModifyAuraState(AURA_STATE_CRIT
, false);
11980 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_CRIT_STRIKE
) )
11981 ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE
, false);
11983 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
11984 ((Player
*)this)->ClearComboPoints();
11987 void Unit::UpdateReactives( uint32 p_time
)
11989 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
11991 ReactiveType reactive
= ReactiveType(i
);
11993 if(!m_reactiveTimer
[reactive
])
11996 if ( m_reactiveTimer
[reactive
] <= p_time
)
11998 m_reactiveTimer
[reactive
] = 0;
12000 switch ( reactive
)
12002 case REACTIVE_DEFENSE
:
12003 if (HasAuraState(AURA_STATE_DEFENSE
))
12004 ModifyAuraState(AURA_STATE_DEFENSE
, false);
12006 case REACTIVE_HUNTER_PARRY
:
12007 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
12008 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
12010 case REACTIVE_CRIT
:
12011 if (HasAuraState(AURA_STATE_CRIT
))
12012 ModifyAuraState(AURA_STATE_CRIT
, false);
12014 case REACTIVE_HUNTER_CRIT
:
12015 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_CRIT_STRIKE
) )
12016 ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE
, false);
12018 case REACTIVE_OVERPOWER
:
12019 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
12020 ((Player
*)this)->ClearComboPoints();
12028 m_reactiveTimer
[reactive
] -= p_time
;
12033 Unit
* Unit::SelectNearbyTarget() const
12035 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
12037 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
12038 cell
.SetNoCreate();
12040 std::list
<Unit
*> targets
;
12043 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, ATTACK_DISTANCE
);
12044 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(targets
, u_check
);
12046 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
12047 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
12049 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
12050 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *GetMap());
12051 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *GetMap());
12054 // remove current target
12056 targets
.remove(getVictim());
12058 // remove not LoS targets
12059 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
12061 if(!IsWithinLOSInMap(*tIter
))
12063 std::list
<Unit
*>::iterator tIter2
= tIter
;
12065 targets
.erase(tIter2
);
12071 // no appropriate targets
12072 if(targets
.empty())
12076 uint32 rIdx
= urand(0,targets
.size()-1);
12077 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
12078 for(uint32 i
= 0; i
< rIdx
; ++i
)
12084 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
12088 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
12089 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
12093 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
12094 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
12098 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
12101 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
12103 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
12106 uint32
Unit::GetCastingTimeForBonus( SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 CastingTime
)
12108 if (CastingTime
> 7000) CastingTime
= 7000;
12109 if (CastingTime
< 1500) CastingTime
= 1500;
12111 if(damagetype
== DOT
&& !IsChanneledSpell(spellProto
))
12112 CastingTime
= 3500;
12114 int32 overTime
= 0;
12116 bool DirectDamage
= false;
12117 bool AreaEffect
= false;
12119 for ( uint32 i
=0; i
<3;i
++)
12121 switch ( spellProto
->Effect
[i
] )
12123 case SPELL_EFFECT_SCHOOL_DAMAGE
:
12124 case SPELL_EFFECT_POWER_DRAIN
:
12125 case SPELL_EFFECT_HEALTH_LEECH
:
12126 case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
:
12127 case SPELL_EFFECT_POWER_BURN
:
12128 case SPELL_EFFECT_HEAL
:
12129 DirectDamage
= true;
12131 case SPELL_EFFECT_APPLY_AURA
:
12132 switch ( spellProto
->EffectApplyAuraName
[i
] )
12134 case SPELL_AURA_PERIODIC_DAMAGE
:
12135 case SPELL_AURA_PERIODIC_HEAL
:
12136 case SPELL_AURA_PERIODIC_LEECH
:
12137 if ( GetSpellDuration(spellProto
) )
12138 overTime
= GetSpellDuration(spellProto
);
12141 // -5% per additional effect
12149 if(IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetA
[i
])) || IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetB
[i
])))
12153 // Combined Spells with Both Over Time and Direct Damage
12154 if ( overTime
> 0 && CastingTime
> 0 && DirectDamage
)
12156 // mainly for DoTs which are 3500 here otherwise
12157 uint32 OriginalCastTime
= GetSpellCastTime(spellProto
);
12158 if (OriginalCastTime
> 7000) OriginalCastTime
= 7000;
12159 if (OriginalCastTime
< 1500) OriginalCastTime
= 1500;
12160 // Portion to Over Time
12161 float PtOT
= (overTime
/ 15000.f
) / ((overTime
/ 15000.f
) + (OriginalCastTime
/ 3500.f
));
12163 if ( damagetype
== DOT
)
12164 CastingTime
= uint32(CastingTime
* PtOT
);
12165 else if ( PtOT
< 1.0f
)
12166 CastingTime
= uint32(CastingTime
* (1 - PtOT
));
12171 // Area Effect Spells receive only half of bonus
12175 // -5% of total per any additional effect
12176 for ( uint8 i
=0; i
<effects
; ++i
)
12178 if ( CastingTime
> 175 )
12180 CastingTime
-= 175;
12189 return CastingTime
;
12192 void Unit::UpdateAuraForGroup(uint8 slot
)
12194 if(GetTypeId() == TYPEID_PLAYER
)
12196 Player
* player
= (Player
*)this;
12197 if(player
->GetGroup())
12199 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
12200 player
->SetAuraUpdateMask(slot
);
12203 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
12205 Pet
*pet
= ((Pet
*)this);
12206 if(pet
->isControlled())
12208 Unit
*owner
= GetOwner();
12209 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
12211 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
12212 pet
->SetAuraUpdateMask(slot
);
12218 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
12220 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
12221 return float(GetAttackTime(attType
))/1000.0f
;
12223 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
);
12225 return 2.4; // fist attack
12227 switch (Weapon
->GetProto()->InventoryType
)
12229 case INVTYPE_2HWEAPON
:
12231 case INVTYPE_RANGED
:
12232 case INVTYPE_RANGEDRIGHT
:
12233 case INVTYPE_THROWN
:
12235 case INVTYPE_WEAPON
:
12236 case INVTYPE_WEAPONMAINHAND
:
12237 case INVTYPE_WEAPONOFFHAND
:
12239 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7 : 2.4;
12243 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
12245 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
12246 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
12247 if ((*itr
)->GetId() == spell_id
)
12253 bool Unit::IsUnderLastManaUseEffect() const
12255 return getMSTimeDiff(m_lastManaUse
,getMSTime()) < 5000;
12258 void Unit::SetContestedPvP(Player
*attackedPlayer
)
12260 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
12262 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
12265 player
->SetContestedPvPTimer(30000);
12266 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
12268 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
12269 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
12270 // call MoveInLineOfSight for nearby contested guards
12271 SetVisibility(GetVisibility());
12273 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
12275 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
12276 // call MoveInLineOfSight for nearby contested guards
12277 SetVisibility(GetVisibility());
12281 void Unit::AddPetAura(PetAura
const* petSpell
)
12283 m_petAuras
.insert(petSpell
);
12284 if(Pet
* pet
= GetPet())
12285 pet
->CastPetAura(petSpell
);
12288 void Unit::RemovePetAura(PetAura
const* petSpell
)
12290 m_petAuras
.erase(petSpell
);
12291 if(Pet
* pet
= GetPet())
12292 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
12295 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
12297 Pet
* pet
= new Pet(HUNTER_PET
);
12299 if(!pet
->CreateBaseAtCreature(creatureTarget
))
12305 pet
->SetUInt64Value(UNIT_FIELD_SUMMONEDBY
, GetGUID());
12306 pet
->SetUInt64Value(UNIT_FIELD_CREATEDBY
, GetGUID());
12307 pet
->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE
,getFaction());
12308 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
12310 if(!pet
->InitStatsForLevel(creatureTarget
->getLevel()))
12312 sLog
.outError("ERROR: Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
12317 pet
->GetCharmInfo()->SetPetNumber(objmgr
.GeneratePetNumber(), true);
12318 // this enables pet details window (Shift+P)
12319 pet
->AIM_Initialize();
12320 pet
->InitPetCreateSpells();
12321 pet
->SetHealth(pet
->GetMaxHealth());
12326 bool Unit::IsTriggeredAtSpellProcEvent(Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
12328 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
12330 // Get proc Event Entry
12331 spellProcEvent
= spellmgr
.GetSpellProcEvent(spellProto
->Id
);
12333 // Aura info stored here
12334 Modifier
*mod
= aura
->GetModifier();
12336 if (isNonTriggerAura
[mod
->m_auraname
])
12338 // If not trigger by default and spellProcEvent==NULL - skip
12339 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
12342 // Get EventProcFlag
12343 uint32 EventProcFlag
;
12344 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
12345 EventProcFlag
= spellProcEvent
->procFlags
;
12347 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
12348 // Continue if no trigger exist
12349 if (!EventProcFlag
)
12352 // Check spellProcEvent data requirements
12353 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
12356 // Aura added by spell can`t trogger from self (prevent drop cahres/do triggers)
12357 // But except periodic triggers (can triggered from self)
12358 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
&PROC_FLAG_ON_TAKE_PERIODIC
))
12361 // Check if current equipment allows aura to proc
12362 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
12364 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
12367 if(attType
== BASE_ATTACK
)
12368 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
12369 else if (attType
== OFF_ATTACK
)
12370 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
12372 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
12374 if (!((Player
*)this)->IsUseEquipedWeapon(attType
==BASE_ATTACK
))
12377 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
12380 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
12382 // Check if player is wearing shield
12383 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
12384 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
12388 // Get chance from spell
12389 float chance
= (float)spellProto
->procChance
;
12390 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
12391 if(spellProcEvent
&& spellProcEvent
->customChance
)
12392 chance
= spellProcEvent
->customChance
;
12393 // If PPM exist calculate chance from PPM
12394 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
12396 uint32 WeaponSpeed
= GetAttackTime(attType
);
12397 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
12399 // Apply chance modifer aura
12400 if(Player
* modOwner
= GetSpellModOwner())
12401 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
12403 return roll_chance_f(chance
);
12406 bool Unit::HandleMeandingAuraProc( Aura
* triggeredByAura
)
12408 // aura can be deleted at casts
12409 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
12410 uint32 effIdx
= triggeredByAura
->GetEffIndex();
12411 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
12412 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
12415 int32 jumps
= triggeredByAura
->m_procCharges
-1;
12417 // current aura expire
12418 triggeredByAura
->m_procCharges
= 1; // will removed at next charges decrease
12420 // next target selection
12421 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
12424 if (spellProto
->EffectRadiusIndex
[effIdx
])
12425 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
12427 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
12429 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
12431 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
12433 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
12435 // aura will applied from caster, but spell casted from current aura holder
12436 SpellModifier
*mod
= new SpellModifier
;
12437 mod
->op
= SPELLMOD_CHARGES
;
12438 mod
->value
= jumps
-5; // negative
12439 mod
->type
= SPELLMOD_FLAT
;
12440 mod
->spellId
= spellProto
->Id
;
12441 mod
->effectId
= effIdx
;
12442 mod
->lastAffected
= NULL
;
12443 mod
->mask
= spellProto
->SpellFamilyFlags
;
12446 caster
->AddSpellMod(mod
, true);
12447 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
12448 caster
->AddSpellMod(mod
, false);
12454 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
12458 void Unit::RemoveAurasAtChanneledTarget(SpellEntry
const* spellInfo
)
12460 uint64 target_guid
= GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
);
12462 if(!IS_UNIT_GUID(target_guid
))
12465 Unit
* target
= ObjectAccessor::GetUnit(*this, target_guid
);
12469 for (AuraMap::iterator iter
= target
->GetAuras().begin(); iter
!= target
->GetAuras().end(); )
12471 if (iter
->second
->GetId() == spellInfo
->Id
&& iter
->second
->GetCasterGUID()==GetGUID())
12472 target
->RemoveAura(iter
);