2 * Copyright (C) 2005-2009 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_RUN_BACK
54 4.722222f
, // MOVE_SWIM
55 4.5f
, // MOVE_SWIM_BACK
56 3.141594f
, // MOVE_TURN_RATE
58 4.5f
, // MOVE_FLIGHT_BACK
59 3.14f
// MOVE_PITCH_RATE
62 // Used for prepare can/can`t triggr aura
63 static bool InitTriggerAuraData();
64 // Define can trigger auras
65 static bool isTriggerAura
[TOTAL_AURAS
];
66 // Define can`t trigger auras (need for disable second trigger)
67 static bool isNonTriggerAura
[TOTAL_AURAS
];
69 static bool procPrepared
= InitTriggerAuraData();
72 : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this)
74 m_objectType
|= TYPEMASK_UNIT
;
75 m_objectTypeId
= TYPEID_UNIT
;
77 m_updateFlag
= (UPDATEFLAG_LOWGUID
| UPDATEFLAG_HIGHGUID
| UPDATEFLAG_LIVING
| UPDATEFLAG_HAS_POSITION
);
79 m_attackTimer
[BASE_ATTACK
] = 0;
80 m_attackTimer
[OFF_ATTACK
] = 0;
81 m_attackTimer
[RANGED_ATTACK
] = 0;
82 m_modAttackSpeedPct
[BASE_ATTACK
] = 1.0f
;
83 m_modAttackSpeedPct
[OFF_ATTACK
] = 1.0f
;
84 m_modAttackSpeedPct
[RANGED_ATTACK
] = 1.0f
;
92 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
93 m_currentSpells
[i
] = NULL
;
97 for(int i
= 0; i
< MAX_TOTEM
; ++i
)
100 m_ObjectSlot
[0] = m_ObjectSlot
[1] = m_ObjectSlot
[2] = m_ObjectSlot
[3] = 0;
102 //m_AurasCheck = 2000;
103 //m_removeAuraTimer = 4;
106 m_Visibility
= VISIBILITY_ON
;
108 m_detectInvisibilityMask
= 0;
109 m_invisibilityMask
= 0;
111 m_ShapeShiftFormSpellId
= 0;
112 m_canModifyStats
= false;
114 for (int i
= 0; i
< MAX_SPELL_IMMUNITY
; i
++)
115 m_spellImmune
[i
].clear();
116 for (int i
= 0; i
< UNIT_MOD_END
; i
++)
118 m_auraModifiersGroup
[i
][BASE_VALUE
] = 0.0f
;
119 m_auraModifiersGroup
[i
][BASE_PCT
] = 1.0f
;
120 m_auraModifiersGroup
[i
][TOTAL_VALUE
] = 0.0f
;
121 m_auraModifiersGroup
[i
][TOTAL_PCT
] = 1.0f
;
123 // implement 50% base damage from offhand
124 m_auraModifiersGroup
[UNIT_MOD_DAMAGE_OFFHAND
][TOTAL_PCT
] = 0.5f
;
126 for (int i
= 0; i
< 3; i
++)
128 m_weaponDamage
[i
][MINDAMAGE
] = BASE_MINDAMAGE
;
129 m_weaponDamage
[i
][MAXDAMAGE
] = BASE_MAXDAMAGE
;
131 for (int i
= 0; i
< MAX_STATS
; i
++)
132 m_createStats
[i
] = 0.0f
;
135 m_modMeleeHitChance
= 0.0f
;
136 m_modRangedHitChance
= 0.0f
;
137 m_modSpellHitChance
= 0.0f
;
138 m_baseSpellCritChance
= 5;
143 //m_victimThreat = 0.0f;
144 for (int i
= 0; i
< MAX_SPELL_SCHOOL
; ++i
)
145 m_threatModifier
[i
] = 1.0f
;
147 for (int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
148 m_speed_rate
[i
] = 1.0f
;
152 m_unit_movement_flags
= 0;
154 // remove aurastates allowing special moves
155 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
156 m_reactiveTimer
[i
] = 0;
161 // set current spells as deletable
162 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
164 if (m_currentSpells
[i
])
166 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
167 m_currentSpells
[i
] = NULL
;
171 RemoveAllGameObjects();
172 RemoveAllDynObjects();
174 if(m_charmInfo
) delete m_charmInfo
;
177 void Unit::Update( uint32 p_time
)
179 /*if(p_time > m_AurasCheck)
184 m_AurasCheck -= p_time;*/
186 // WARNING! Order of execution here is important, do not change.
187 // Spells must be processed with event system BEFORE they go to _UpdateSpells.
188 // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
189 m_Events
.Update( p_time
);
190 _UpdateSpells( p_time
);
192 // update combat timer only for players and pets
193 if (isInCombat() && (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet() || ((Creature
*)this)->isCharmed()))
195 // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away
196 // targets without stopping half way there and running off.
197 // These flags are reset after target dies or another command is given.
198 if( m_HostilRefManager
.isEmpty() )
200 // m_CombatTimer set at aura start and it will be freeze until aura removing
201 if ( m_CombatTimer
<= p_time
)
204 m_CombatTimer
-= p_time
;
208 if(uint32 base_att
= getAttackTimer(BASE_ATTACK
))
210 setAttackTimer(BASE_ATTACK
, (p_time
>= base_att
? 0 : base_att
- p_time
) );
213 // update abilities available only for fraction of time
214 UpdateReactives( p_time
);
216 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, GetHealth() < GetMaxHealth()*0.20f
);
217 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, GetHealth() < GetMaxHealth()*0.35f
);
218 ModifyAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT
, GetHealth() > GetMaxHealth()*0.75f
);
220 i_motionMaster
.UpdateMotion(p_time
);
223 bool Unit::haveOffhandWeapon() const
225 if(GetTypeId() == TYPEID_PLAYER
)
226 return ((Player
*)this)->GetWeaponForAttack(OFF_ATTACK
,true);
231 void Unit::SendMonsterMoveWithSpeedToCurrentDestination(Player
* player
)
234 if(GetMotionMaster()->GetDestination(x
, y
, z
))
235 SendMonsterMoveWithSpeed(x
, y
, z
, GetUnitMovementFlags(), 0, player
);
238 void Unit::SendMonsterMoveWithSpeed(float x
, float y
, float z
, uint32 MovementFlags
, uint32 transitTime
, Player
* player
)
242 float dx
= x
- GetPositionX();
243 float dy
= y
- GetPositionY();
244 float dz
= z
- GetPositionZ();
246 float dist
= ((dx
*dx
) + (dy
*dy
) + (dz
*dz
));
252 double speed
= GetSpeed((MovementFlags
& MOVEMENTFLAG_WALK_MODE
) ? MOVE_WALK
: MOVE_RUN
);
256 transitTime
= static_cast<uint32
>(dist
/ speed
+ 0.5);
258 //float orientation = (float)atan2((double)dy, (double)dx);
259 SendMonsterMove(x
, y
, z
, 0, MovementFlags
, transitTime
, player
);
262 void Unit::SendMonsterMove(float NewPosX
, float NewPosY
, float NewPosZ
, uint8 type
, uint32 MovementFlags
, uint32 Time
, Player
* player
)
264 WorldPacket
data( SMSG_MONSTER_MOVE
, (41 + GetPackGUID().size()) );
265 data
.append(GetPackGUID());
267 // Point A, starting location
268 data
<< GetPositionX() << GetPositionY() << GetPositionZ();
269 // unknown field - unrelated to orientation
270 // seems to increment about 1000 for every 1.7 seconds
271 // for now, we'll just use mstime
274 data
<< uint8(type
); // unknown
277 case 0: // normal packet
279 case 1: // stop packet
280 SendMessageToSet( &data
, true );
282 case 2: // not used currently
287 case 3: // not used currently
288 data
<< uint64(0); // probably target guid
290 case 4: // not used currently
291 data
<< float(0); // probably orientation
295 //Movement Flags (0x0 = walk, 0x100 = run, 0x200 = fly/swim)
296 data
<< uint32(MovementFlags
);
298 data
<< Time
; // Time in between points
299 data
<< uint32(1); // 1 single waypoint
300 data
<< NewPosX
<< NewPosY
<< NewPosZ
; // the single waypoint Point B
303 player
->GetSession()->SendPacket(&data
);
305 SendMessageToSet( &data
, true );
308 void Unit::SendMonsterMoveByPath(Path
const& path
, uint32 start
, uint32 end
, uint32 MovementFlags
)
310 uint32 traveltime
= uint32(path
.GetTotalLength(start
, end
) * 32);
312 uint32 pathSize
= end
-start
;
314 WorldPacket
data( SMSG_MONSTER_MOVE
, (GetPackGUID().size()+4+4+4+4+1+4+4+4+pathSize
*4*3) );
315 data
.append(GetPackGUID());
316 data
<< GetPositionX();
317 data
<< GetPositionY();
318 data
<< GetPositionZ();
320 // unknown field - unrelated to orientation
321 // seems to increment about 1000 for every 1.7 seconds
322 // for now, we'll just use mstime
326 data
<< uint32( MovementFlags
);
327 data
<< uint32( traveltime
);
328 data
<< uint32( pathSize
);
329 data
.append( (char*)path
.GetNodes(start
), pathSize
* 4 * 3 );
331 //WPAssert( data.size() == 37 + pathnodes.Size( ) * 4 * 3 );
332 SendMessageToSet(&data
, true);
335 void Unit::resetAttackTimer(WeaponAttackType type
)
337 m_attackTimer
[type
] = uint32(GetAttackTime(type
) * m_modAttackSpeedPct
[type
]);
340 bool Unit::canReachWithAttack(Unit
*pVictim
) const
343 float reach
= GetFloatValue(UNIT_FIELD_COMBATREACH
);
346 return IsWithinDistInMap(pVictim
, reach
);
349 void Unit::RemoveSpellsCausingAura(AuraType auraType
)
351 if (auraType
>= TOTAL_AURAS
) return;
352 AuraList::iterator iter
, next
;
353 for (iter
= m_modAuras
[auraType
].begin(); iter
!= m_modAuras
[auraType
].end(); iter
= next
)
360 RemoveAurasDueToSpell((*iter
)->GetId());
361 if (!m_modAuras
[auraType
].empty())
362 next
= m_modAuras
[auraType
].begin();
369 bool Unit::HasAuraType(AuraType auraType
) const
371 return (!m_modAuras
[auraType
].empty());
374 /* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */
375 void Unit::RemoveSpellbyDamageTaken(AuraType auraType
, uint32 damage
)
377 if(!HasAuraType(auraType
))
380 // The chance to dispel an aura depends on the damage taken with respect to the casters level.
381 uint32 max_dmg
= getLevel() > 8 ? 25 * getLevel() - 150 : 50;
382 float chance
= float(damage
) / max_dmg
* 100.0f
;
383 if (roll_chance_f(chance
))
384 RemoveSpellsCausingAura(auraType
);
387 uint32
Unit::DealDamage(Unit
*pVictim
, uint32 damage
, CleanDamage
const* cleanDamage
, DamageEffectType damagetype
, SpellSchoolMask damageSchoolMask
, SpellEntry
const *spellProto
, bool durabilityLoss
)
389 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
392 //You don't lose health from damage taken from another player while in a sanctuary
393 //You still see it in the combat log though
394 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
396 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
397 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) //sanctuary
401 // remove affects from victim (including from 0 damage and DoTs)
403 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
405 // remove affects from attacker at any non-DoT damage (including 0 damage)
406 if( damagetype
!= DOT
)
408 RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
409 RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
412 RemoveSpellsCausingAura(SPELL_AURA_MOD_INVISIBILITY
);
414 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->IsStandState() && !pVictim
->hasUnitState(UNIT_STAT_STUNNED
))
415 pVictim
->SetStandState(PLAYER_STATE_NONE
);
418 //Script Event damage Deal
419 if( GetTypeId()== TYPEID_UNIT
&& ((Creature
*)this)->AI())
420 ((Creature
*)this)->AI()->DamageDeal(pVictim
, damage
);
421 //Script Event damage taken
422 if( pVictim
->GetTypeId()== TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI() )
423 ((Creature
*)pVictim
)->AI()->DamageTaken(this, damage
);
427 // Rage from physical damage received .
428 if(cleanDamage
&& cleanDamage
->damage
&& (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
) && pVictim
->GetTypeId() == TYPEID_PLAYER
&& (pVictim
->getPowerType() == POWER_RAGE
))
429 ((Player
*)pVictim
)->RewardRage(cleanDamage
->damage
, 0, false);
433 if (!spellProto
|| !IsAuraAddedBySpell(SPELL_AURA_MOD_FEAR
, spellProto
->Id
))
434 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_FEAR
, damage
);
435 // root type spells do not dispel the root effect
436 if (!spellProto
|| !(spellProto
->Mechanic
== MECHANIC_ROOT
|| IsAuraAddedBySpell(SPELL_AURA_MOD_ROOT
, spellProto
->Id
)))
437 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_ROOT
, damage
);
439 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
441 // no xp,health if type 8 /critters/
442 if ( pVictim
->GetCreatureType() == CREATURE_TYPE_CRITTER
)
444 pVictim
->setDeathState(JUST_DIED
);
445 pVictim
->SetHealth(0);
447 // allow loot only if has loot_id in creature_template
448 CreatureInfo
const* cInfo
= ((Creature
*)pVictim
)->GetCreatureInfo();
449 if(cInfo
&& cInfo
->lootid
)
450 pVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
452 // some critters required for quests
453 if(GetTypeId() == TYPEID_PLAYER
)
454 ((Player
*)this)->KilledMonster(pVictim
->GetEntry(),pVictim
->GetGUID());
459 if(!pVictim
->isInCombat() && ((Creature
*)pVictim
)->AI())
460 ((Creature
*)pVictim
)->AI()->AttackStart(this);
463 DEBUG_LOG("DealDamageStart");
465 uint32 health
= pVictim
->GetHealth();
466 sLog
.outDetail("deal dmg:%d to health:%d ",damage
,health
);
468 // duel ends when player has 1 or less hp
469 bool duel_hasEnded
= false;
470 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->duel
&& damage
>= (health
-1))
472 // prevent kill only if killed in duel and killed by opponent or opponent controlled creature
473 if(((Player
*)pVictim
)->duel
->opponent
==this || ((Player
*)pVictim
)->duel
->opponent
->GetGUID() == GetOwnerGUID())
476 duel_hasEnded
= true;
479 if(pVictim
!= this && damagetype
!= DOT
)
481 SetInCombatWith(pVictim
);
482 pVictim
->SetInCombatWith(this);
484 if(Player
* attackedPlayer
= pVictim
->GetCharmerOrOwnerPlayerOrPlayerItself())
485 SetContestedPvP(attackedPlayer
);
488 // Rage from Damage made (only from direct weapon damage)
489 if( cleanDamage
&& damagetype
==DIRECT_DAMAGE
&& this != pVictim
&& GetTypeId() == TYPEID_PLAYER
&& (getPowerType() == POWER_RAGE
))
491 uint32 weaponSpeedHitFactor
;
493 switch(cleanDamage
->attackType
)
497 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
498 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 7);
500 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
502 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
508 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
509 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
511 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 1.75f
);
513 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
522 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& GetTypeId() == TYPEID_PLAYER
)
524 if(((Player
*)pVictim
)->InBattleGround())
526 Player
*killer
= ((Player
*)this);
527 if(killer
!= ((Player
*)pVictim
))
528 if(BattleGround
*bg
= killer
->GetBattleGround())
529 bg
->UpdatePlayerScore(killer
, SCORE_DAMAGE_DONE
, damage
);
533 if (pVictim
->GetTypeId() == TYPEID_UNIT
&& !((Creature
*)pVictim
)->isPet() && !((Creature
*)pVictim
)->hasLootRecipient())
534 ((Creature
*)pVictim
)->SetLootRecipient(this);
535 if (health
<= damage
)
537 DEBUG_LOG("DealDamage: victim just died");
539 // find player: owner of controlled `this` or `this` itself maybe
540 Player
*player
= GetCharmerOrOwnerPlayerOrPlayerItself();
542 if(pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->GetLootRecipient())
543 player
= ((Creature
*)pVictim
)->GetLootRecipient();
544 // Reward player, his pets, and group/raid members
545 // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop)
546 if(player
&& player
!=pVictim
)
548 player
->RewardPlayerAndGroupAtKill(pVictim
);
549 player
->ProcDamageAndSpell(pVictim
, PROC_FLAG_KILL
, PROC_FLAG_KILLED
, PROC_EX_NONE
, 0);
552 DEBUG_LOG("DealDamageAttackStop");
555 pVictim
->CombatStop();
556 pVictim
->getHostilRefManager().deleteReferences();
558 bool damageFromSpiritOfRedemtionTalent
= spellProto
&& spellProto
->Id
== 27795;
560 // if talent known but not triggered (check priest class for speedup check)
561 Aura
* spiritOfRedemtionTalentReady
= NULL
;
562 if( !damageFromSpiritOfRedemtionTalent
&& // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION
563 pVictim
->GetTypeId()==TYPEID_PLAYER
&& pVictim
->getClass()==CLASS_PRIEST
)
565 AuraList
const& vDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
566 for(AuraList::const_iterator itr
= vDummyAuras
.begin(); itr
!= vDummyAuras
.end(); ++itr
)
568 if((*itr
)->GetSpellProto()->SpellIconID
==1654)
570 spiritOfRedemtionTalentReady
= *itr
;
576 DEBUG_LOG("SET JUST_DIED");
577 if(!spiritOfRedemtionTalentReady
)
578 pVictim
->setDeathState(JUST_DIED
);
580 DEBUG_LOG("DealDamageHealth1");
582 if(spiritOfRedemtionTalentReady
)
584 // save value before aura remove
585 uint32 ressSpellId
= pVictim
->GetUInt32Value(PLAYER_SELF_RES_SPELL
);
587 ressSpellId
= ((Player
*)pVictim
)->GetResurrectionSpellId();
589 //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers)
590 pVictim
->RemoveAllAurasOnDeath();
592 // restore for use at real death
593 pVictim
->SetUInt32Value(PLAYER_SELF_RES_SPELL
,ressSpellId
);
595 // FORM_SPIRITOFREDEMPTION and related auras
596 pVictim
->CastSpell(pVictim
,27827,true,NULL
,spiritOfRedemtionTalentReady
);
599 pVictim
->SetHealth(0);
601 // remember victim PvP death for corpse type and corpse reclaim delay
602 // at original death (not at SpiritOfRedemtionTalent timeout)
603 if( pVictim
->GetTypeId()==TYPEID_PLAYER
&& !damageFromSpiritOfRedemtionTalent
)
604 ((Player
*)pVictim
)->SetPvPDeath(player
!=NULL
);
606 // Call KilledUnit for creatures
607 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->AI())
608 ((Creature
*)this)->AI()->KilledUnit(pVictim
);
611 if ( pVictim
->GetTypeId() == TYPEID_PLAYER
)
613 if(GetTypeId() == TYPEID_UNIT
)
614 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE
, GetEntry());
615 else if(GetTypeId() == TYPEID_PLAYER
)
616 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER
, 1);
619 // 10% durability loss on death
620 // clean InHateListOf
621 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
623 // only if not player and not controlled by player pet. And not at BG
624 if (durabilityLoss
&& !player
&& !((Player
*)pVictim
)->InBattleGround())
626 DEBUG_LOG("We are dead, loosing 10 percents durability");
627 ((Player
*)pVictim
)->DurabilityLossAll(0.10f
,false);
628 // durability lost message
629 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
630 ((Player
*)pVictim
)->GetSession()->SendPacket(&data
);
633 else // creature died
635 DEBUG_LOG("DealDamageNotPlayer");
636 Creature
*cVictim
= (Creature
*)pVictim
;
638 if(!cVictim
->isPet())
640 cVictim
->DeleteThreatList();
641 cVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
643 // Call creature just died function
645 cVictim
->AI()->JustDied(this);
647 // Dungeon specific stuff, only applies to players killing creatures
648 if(cVictim
->GetInstanceId())
650 Map
*m
= cVictim
->GetMap();
651 Player
*creditedPlayer
= GetCharmerOrOwnerPlayerOrPlayerItself();
652 // TODO: do instance binding anyway if the charmer/owner is offline
654 if(m
->IsDungeon() && creditedPlayer
)
656 if(m
->IsRaid() || m
->IsHeroic())
658 if(cVictim
->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
659 ((InstanceMap
*)m
)->PermBindAllPlayers(creditedPlayer
);
663 // the reset time is set but not added to the scheduler
664 // until the players leave the instance
665 time_t resettime
= cVictim
->GetRespawnTimeEx() + 2 * HOUR
;
666 if(InstanceSave
*save
= sInstanceSaveManager
.GetInstanceSave(cVictim
->GetInstanceId()))
667 if(save
->GetResetTime() < resettime
) save
->SetResetTime(resettime
);
673 // last damage from non duel opponent or opponent controlled creature
676 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
677 Player
*he
= (Player
*)pVictim
;
681 he
->duel
->opponent
->CombatStopWithPets(true);
682 he
->CombatStopWithPets(true);
684 he
->DuelComplete(DUEL_INTERUPTED
);
687 // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill)
688 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->InBattleGround())
690 Player
*killed
= ((Player
*)pVictim
);
691 if(BattleGround
*bg
= killed
->GetBattleGround())
693 bg
->HandleKillPlayer(killed
, player
);
694 //later we can add support for creature->player kills here i'm
695 //not sure, but i guess those kills also get counted in av
696 //else if(GetTypeId() == TYPEID_UNIT)
697 // bg->HandleKillPlayer(killed,(Creature*)this);
700 else // if (health <= damage)
702 DEBUG_LOG("DealDamageAlive");
704 pVictim
->ModifyHealth(- (int32
)damage
);
706 if(damagetype
!= DOT
)
710 // if have target and damage pVictim just call AI reaction
711 if(pVictim
!= getVictim() && pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
712 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
716 // if not have main target then attack state with target (including AI call)
717 //start melee attacks only after melee hit
718 Attack(pVictim
,(damagetype
== DIRECT_DAMAGE
));
722 // polymorphed and other negative transformed cases
723 if(pVictim
->getTransForm() && pVictim
->hasUnitState(UNIT_STAT_CONFUSED
))
724 pVictim
->RemoveAurasDueToSpell(pVictim
->getTransForm());
726 if(damagetype
== DIRECT_DAMAGE
|| damagetype
== SPELL_DIRECT_DAMAGE
)
728 if (!spellProto
|| !(spellProto
->AuraInterruptFlags
&AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
))
729 pVictim
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
);
731 if (pVictim
->GetTypeId() != TYPEID_PLAYER
)
733 if(spellProto
&& IsDamageToThreatSpell(spellProto
))
734 pVictim
->AddThreat(this, damage
*2, damageSchoolMask
, spellProto
);
736 pVictim
->AddThreat(this, damage
, damageSchoolMask
, spellProto
);
738 else // victim is a player
740 // Rage from damage received
741 if(this != pVictim
&& pVictim
->getPowerType() == POWER_RAGE
)
743 uint32 rage_damage
= damage
+ (cleanDamage
? cleanDamage
->damage
: 0);
744 ((Player
*)pVictim
)->RewardRage(rage_damage
, 0, false);
747 // random durability for items (HIT TAKEN)
748 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
750 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
751 ((Player
*)pVictim
)->DurabilityPointLossForEquipSlot(slot
);
755 if(GetTypeId()==TYPEID_PLAYER
)
757 // random durability for items (HIT DONE)
758 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
760 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
761 ((Player
*)this)->DurabilityPointLossForEquipSlot(slot
);
765 // TODO: Store auras by interrupt flag to speed this up.
766 AuraMap
& vAuras
= pVictim
->GetAuras();
767 for (AuraMap::iterator i
= vAuras
.begin(), next
; i
!= vAuras
.end(); i
= next
)
769 const SpellEntry
*se
= i
->second
->GetSpellProto();
771 if (spellProto
&& spellProto
->Id
== se
->Id
) // Not drop auras added by self
773 if( se
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_DAMAGE
)
776 if (se
->procFlags
& (1<<3))
778 if (!roll_chance_i(se
->procChance
))
783 pVictim
->RemoveAurasDueToSpell(i
->second
->GetId());
784 // FIXME: this may cause the auras with proc chance to be rerolled several times
785 next
= vAuras
.begin();
790 if (damagetype
!= NODAMAGE
&& damage
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
792 if( damagetype
!= DOT
)
794 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
796 // skip channeled spell (processed differently below)
797 if (i
== CURRENT_CHANNELED_SPELL
)
800 if(Spell
* spell
= pVictim
->m_currentSpells
[i
])
801 if(spell
->getState() == SPELL_STATE_PREPARING
)
803 if(spell
->m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_ABORT_ON_DMG
)
804 pVictim
->InterruptSpell(i
);
811 if(Spell
* spell
= pVictim
->m_currentSpells
[CURRENT_CHANNELED_SPELL
])
813 if (spell
->getState() == SPELL_STATE_CASTING
)
815 uint32 channelInterruptFlags
= spell
->m_spellInfo
->ChannelInterruptFlags
;
816 if( channelInterruptFlags
& CHANNEL_FLAG_DELAY
)
818 if(pVictim
!=this) //don't shorten the duration of channeling if you damage yourself
819 spell
->DelayedChannel();
821 else if( (channelInterruptFlags
& (CHANNEL_FLAG_DAMAGE
| CHANNEL_FLAG_DAMAGE2
)) )
823 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
824 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
827 else if (spell
->getState() == SPELL_STATE_DELAYED
)
828 // break channeled spell in delayed state on damage
830 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
831 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
836 // last damage from duel opponent
839 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
840 Player
*he
= (Player
*)pVictim
;
846 he
->duel
->opponent
->CombatStopWithPets(true);
847 he
->CombatStopWithPets(true);
849 he
->CastSpell(he
, 7267, true); // beg
850 he
->DuelComplete(DUEL_WON
);
854 DEBUG_LOG("DealDamageEnd returned %d damage", damage
);
859 void Unit::CastStop(uint32 except_spellid
)
861 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
862 if (m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
!=except_spellid
)
863 InterruptSpell(i
,false);
866 void Unit::CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
868 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
872 sLog
.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId
,(GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
876 CastSpell(Victim
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
879 void Unit::CastSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
883 sLog
.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
888 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
890 if(!originalCaster
&& triggeredByAura
)
891 originalCaster
= triggeredByAura
->GetCasterGUID();
893 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
895 SpellCastTargets targets
;
896 targets
.setUnitTarget( Victim
);
897 spell
->m_CastItem
= castItem
;
898 spell
->prepare(&targets
, triggeredByAura
);
901 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
903 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
907 sLog
.outError("CastCustomSpell: unknown spell id %i\n", spellId
);
911 CastCustomSpell(Victim
,spellInfo
,bp0
,bp1
,bp2
,triggered
,castItem
,triggeredByAura
, originalCaster
);
914 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
)
918 sLog
.outError("CastCustomSpell: unknown spell");
923 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
925 if(!originalCaster
&& triggeredByAura
)
926 originalCaster
= triggeredByAura
->GetCasterGUID();
928 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
931 spell
->m_currentBasePoints
[0] = *bp0
-int32(spellInfo
->EffectBaseDice
[0]);
934 spell
->m_currentBasePoints
[1] = *bp1
-int32(spellInfo
->EffectBaseDice
[1]);
937 spell
->m_currentBasePoints
[2] = *bp2
-int32(spellInfo
->EffectBaseDice
[2]);
939 SpellCastTargets targets
;
940 targets
.setUnitTarget( Victim
);
941 spell
->m_CastItem
= castItem
;
942 spell
->prepare(&targets
, triggeredByAura
);
945 // used for scripting
946 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
948 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
952 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()));
956 CastSpell(x
, y
, z
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
959 // used for scripting
960 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
964 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
969 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
971 if(!originalCaster
&& triggeredByAura
)
972 originalCaster
= triggeredByAura
->GetCasterGUID();
974 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
976 SpellCastTargets targets
;
977 targets
.setDestination(x
, y
, z
);
978 spell
->m_CastItem
= castItem
;
979 spell
->prepare(&targets
, triggeredByAura
);
982 // Obsolete func need remove, here only for comotability vs another patches
983 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
, bool isTriggeredSpell
, bool useSpellDamage
)
985 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
986 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, spellInfo
->SchoolMask
);
987 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
988 SendSpellNonMeleeDamageLog(&damageInfo
);
989 DealSpellDamage(&damageInfo
, true);
990 return damageInfo
.damage
;
993 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
995 SpellSchoolMask damageSchoolMask
= SpellSchoolMask(damageInfo
->schoolMask
);
996 Unit
*pVictim
= damageInfo
->target
;
1001 if(!this || !pVictim
)
1003 if(!this->isAlive() || !pVictim
->isAlive())
1006 uint32 crTypeMask
= pVictim
->GetCreatureTypeMask();
1007 // Check spell crit chance
1008 bool crit
= isSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
1009 bool blocked
= false;
1011 switch (spellInfo
->DmgClass
)
1013 // Melee and Ranged Spells
1014 case SPELL_DAMAGE_CLASS_RANGED
:
1015 case SPELL_DAMAGE_CLASS_MELEE
:
1018 if ( damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
1020 //Calculate armor mitigation
1021 damage
= CalcArmorReducedDamage(pVictim
, damage
);
1022 // Get blocked status
1023 blocked
= isSpellBlocked(pVictim
, spellInfo
, attackType
);
1028 // Calculate damage bonus
1029 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1033 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1035 // Calculate crit bonus
1036 uint32 crit_bonus
= damage
;
1037 // Apply crit_damage bonus for melee spells
1038 if(Player
* modOwner
= GetSpellModOwner())
1039 modOwner
->ApplySpellMod(spellInfo
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
1040 damage
+= crit_bonus
;
1042 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1043 int32 critPctDamageMod
=0;
1044 if(attackType
== RANGED_ATTACK
)
1045 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1048 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1049 critPctDamageMod
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
);
1051 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1052 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1054 if (critPctDamageMod
!=0)
1055 damage
= int32((damage
) * float((100.0f
+ critPctDamageMod
)/100.0f
));
1057 // Resilience - reduce crit damage
1058 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1059 damage
-= ((Player
*)pVictim
)->GetMeleeCritDamageReduction(damage
);
1061 // Spell weapon based damage CAN BE crit & blocked at same time
1064 damageInfo
->blocked
= uint32(pVictim
->GetShieldBlockValue());
1065 if (damage
< damageInfo
->blocked
)
1066 damageInfo
->blocked
= damage
;
1067 damage
-=damageInfo
->blocked
;
1072 case SPELL_DAMAGE_CLASS_NONE
:
1073 case SPELL_DAMAGE_CLASS_MAGIC
:
1075 // Calculate damage bonus
1076 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1077 // If crit add critical bonus
1080 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1081 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1082 // Resilience - reduce crit damage
1083 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1084 damage
-= ((Player
*)pVictim
)->GetSpellCritDamageReduction(damage
);
1090 // Calculate absorb resist
1093 // lookup absorb/resist ignore auras on caster for spell
1094 bool ignore
= false;
1095 Unit::AuraList
const& ignoreAbsorb
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL
);
1096 for(Unit::AuraList::const_iterator i
= ignoreAbsorb
.begin(); i
!= ignoreAbsorb
.end(); ++i
)
1097 if ((*i
)->isAffectedOnSpell(spellInfo
))
1105 CalcAbsorbResist(pVictim
, damageSchoolMask
, SPELL_DIRECT_DAMAGE
, damage
, &damageInfo
->absorb
, &damageInfo
->resist
);
1106 damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
1111 damageInfo
->damage
= damage
;
1114 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1119 Unit
*pVictim
= damageInfo
->target
;
1121 if(!this || !pVictim
)
1124 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1127 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1128 if (spellProto
== NULL
)
1130 sLog
.outDebug("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1134 //You don't lose health from damage taken from another player while in a sanctuary
1135 //You still see it in the combat log though
1136 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1138 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1139 if(area
&& area
->flags
& 0x800) //sanctuary
1143 // Call default DealDamage
1144 CleanDamage
cleanDamage(damageInfo
->cleanDamage
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
1145 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->schoolMask
), spellProto
, durabilityLoss
);
1148 //TODO for melee need create structure as in
1149 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1151 damageInfo
->attacker
= this;
1152 damageInfo
->target
= pVictim
;
1153 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1154 damageInfo
->attackType
= attackType
;
1155 damageInfo
->damage
= 0;
1156 damageInfo
->cleanDamage
= 0;
1157 damageInfo
->absorb
= 0;
1158 damageInfo
->resist
= 0;
1159 damageInfo
->blocked_amount
= 0;
1161 damageInfo
->TargetState
= 0;
1162 damageInfo
->HitInfo
= 0;
1163 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1164 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1165 damageInfo
->procEx
= PROC_EX_NONE
;
1166 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1168 if(!this || !pVictim
)
1170 if(!this->isAlive() || !pVictim
->isAlive())
1173 // Select HitInfo/procAttacker/procVictim flag based on attack type
1177 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MILEE_HIT
;
1178 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1179 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1182 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MILEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1183 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1184 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1187 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1188 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1189 damageInfo
->HitInfo
= 0x08;// test
1195 // Physical Immune check
1196 if(damageInfo
->target
->IsImmunedToDamage(SpellSchoolMask(damageInfo
->damageSchoolMask
)))
1198 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1199 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1201 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1202 damageInfo
->damage
= 0;
1203 damageInfo
->cleanDamage
= 0;
1206 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1207 // Add melee damage bonus
1208 MeleeDamageBonus(damageInfo
->target
, &damage
, damageInfo
->attackType
);
1209 // Calculate armor reduction
1210 damageInfo
->damage
= CalcArmorReducedDamage(damageInfo
->target
, damage
);
1211 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1213 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1215 // Disable parry or dodge for ranged attack
1216 if(damageInfo
->attackType
== RANGED_ATTACK
)
1218 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1219 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1222 switch(damageInfo
->hitOutCome
)
1224 case MELEE_HIT_EVADE
:
1226 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1227 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1229 damageInfo
->procEx
|=PROC_EX_EVADE
;
1230 damageInfo
->damage
= 0;
1231 damageInfo
->cleanDamage
= 0;
1234 case MELEE_HIT_MISS
:
1236 damageInfo
->HitInfo
|= HITINFO_MISS
;
1237 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1239 damageInfo
->procEx
|=PROC_EX_MISS
;
1240 damageInfo
->damage
= 0;
1241 damageInfo
->cleanDamage
= 0;
1244 case MELEE_HIT_NORMAL
:
1245 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1246 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1248 case MELEE_HIT_CRIT
:
1250 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1251 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1253 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1255 damageInfo
->damage
+= damageInfo
->damage
;
1257 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1258 if(damageInfo
->attackType
== RANGED_ATTACK
)
1259 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1262 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1263 mod
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
);
1266 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1268 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1269 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1271 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1273 // Resilience - reduce crit damage
1274 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1276 uint32 resilienceReduction
= ((Player
*)pVictim
)->GetMeleeCritDamageReduction(damageInfo
->damage
);
1277 damageInfo
->damage
-= resilienceReduction
;
1278 damageInfo
->cleanDamage
+= resilienceReduction
;
1282 case MELEE_HIT_PARRY
:
1283 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1284 damageInfo
->procEx
|=PROC_EX_PARRY
;
1285 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1286 damageInfo
->damage
= 0;
1289 case MELEE_HIT_DODGE
:
1290 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1291 damageInfo
->procEx
|=PROC_EX_DODGE
;
1292 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1293 damageInfo
->damage
= 0;
1295 case MELEE_HIT_BLOCK
:
1297 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1298 damageInfo
->HitInfo
|= HITINFO_BLOCK
;
1299 damageInfo
->procEx
|=PROC_EX_BLOCK
;
1300 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1301 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1303 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1304 damageInfo
->blocked_amount
= damageInfo
->damage
;
1306 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1307 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1310 case MELEE_HIT_GLANCING
:
1312 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1313 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1314 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1315 float reducePercent
= 1.0f
; //damage factor
1316 // calculate base values and mods
1317 float baseLowEnd
= 1.3;
1318 float baseHighEnd
= 1.2;
1319 switch(getClass()) // lowering base values for casters
1331 float maxLowEnd
= 0.6;
1332 switch(getClass()) // upper for melee classes
1336 maxLowEnd
= 0.91; //If the attacker is a melee class then instead the lower value of 0.91
1340 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1341 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1342 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1344 // apply max/min bounds
1345 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1347 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1350 if ( highEnd
< 0.2f
) //high end limits
1352 if ( highEnd
> 0.99f
)
1355 if(lowEnd
> highEnd
) // prevent negative range size
1358 reducePercent
= lowEnd
+ rand_norm() * ( highEnd
- lowEnd
);
1360 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1361 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1364 case MELEE_HIT_CRUSHING
:
1366 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1367 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1368 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1369 // 150% normal damage
1370 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1378 // Calculate absorb resist
1379 if(int32(damageInfo
->damage
) > 0)
1381 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1382 // Calculate absorb & resists
1383 CalcAbsorbResist(damageInfo
->target
, SpellSchoolMask(damageInfo
->damageSchoolMask
), DIRECT_DAMAGE
, damageInfo
->damage
, &damageInfo
->absorb
, &damageInfo
->resist
);
1384 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1385 if (damageInfo
->absorb
)
1387 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1388 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1390 if (damageInfo
->resist
)
1391 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1394 else // Umpossible get negative result but....
1395 damageInfo
->damage
= 0;
1398 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1400 if (damageInfo
==0) return;
1401 Unit
*pVictim
= damageInfo
->target
;
1403 if(!this || !pVictim
)
1406 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1409 //You don't lose health from damage taken from another player while in a sanctuary
1410 //You still see it in the combat log though
1411 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1413 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1414 if(area
&& area
->flags
& 0x800) //sanctuary
1418 // Hmmmm dont like this emotes cloent must by self do all animations
1419 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1420 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1421 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1422 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1424 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1426 // Get attack timers
1427 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1428 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1429 // Reduce attack time
1430 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1432 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20;
1433 float percent60
= 3 * percent20
;
1434 if(offtime
> percent20
&& offtime
<= percent60
)
1436 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1438 else if(offtime
> percent60
)
1440 offtime
-= 2 * percent20
;
1441 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1446 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20;
1447 float percent60
= 3 * percent20
;
1448 if(basetime
> percent20
&& basetime
<= percent60
)
1450 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1452 else if(basetime
> percent60
)
1454 basetime
-= 2 * percent20
;
1455 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1460 // Call default DealDamage
1461 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1462 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->damageSchoolMask
), NULL
, durabilityLoss
);
1464 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1465 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1466 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI
, this) )
1468 // -probability is between 0% and 40%
1470 float Probability
= 20;
1472 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1473 if( pVictim
->getLevel() < 30 )
1474 Probability
= 0.65f
*pVictim
->getLevel()+0.5;
1476 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1477 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1479 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1481 if(Probability
> 40)
1484 if(roll_chance_f(Probability
))
1485 CastSpell(pVictim
, 1604, true);
1489 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1491 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1493 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
1494 ((Player
*)this)->CastItemCombatSpell(((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
,i
), pVictim
, damageInfo
->attackType
);
1497 // victim's damage shield
1498 std::set
<Aura
*> alreadyDone
;
1499 uint32 removedAuras
= pVictim
->m_removedAuras
;
1500 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1501 for(AuraList::const_iterator i
= vDamageShields
.begin(), next
= vDamageShields
.begin(); i
!= vDamageShields
.end(); i
= next
)
1504 if (alreadyDone
.find(*i
) == alreadyDone
.end())
1506 alreadyDone
.insert(*i
);
1507 uint32 damage
=(*i
)->GetModifier()->m_amount
;
1508 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry((*i
)->GetId());
1511 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
1514 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1515 //damage-=absorb + resist;
1517 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4+4+4));
1518 data
<< uint64(pVictim
->GetGUID());
1519 data
<< uint64(GetGUID());
1520 data
<< uint32(spellProto
->Id
);
1521 data
<< uint32(damage
); // Damage
1522 data
<< uint32(0); // Overkill
1523 data
<< uint32(spellProto
->SchoolMask
);
1524 pVictim
->SendMessageToSet(&data
, true );
1526 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(spellProto
), spellProto
, true);
1528 if (pVictim
->m_removedAuras
> removedAuras
)
1530 removedAuras
= pVictim
->m_removedAuras
;
1531 next
= vDamageShields
.begin();
1539 void Unit::HandleEmoteCommand(uint32 anim_id
)
1541 WorldPacket
data( SMSG_EMOTE
, 12 );
1542 data
<< uint32(anim_id
);
1543 data
<< uint64(GetGUID());
1544 SendMessageToSet(&data
, true);
1547 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
1549 uint32 newdamage
= 0;
1550 float armor
= pVictim
->GetArmor();
1551 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
1552 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
1554 // Apply Player CR_ARMOR_PENETRATION rating
1555 if (GetTypeId()==TYPEID_PLAYER
)
1556 armor
*= 1.0f
- ((Player
*)this)->GetRatingBonusValue(CR_ARMOR_PENETRATION
) / 100.0f
;
1558 if (armor
< 0.0f
) armor
=0.0f
;
1560 float levelModifier
= getLevel();
1561 if ( levelModifier
> 59 )
1562 levelModifier
= levelModifier
+ (4.5f
* (levelModifier
-59));
1564 float tmpvalue
= 0.1f
* armor
/ (8.5f
* levelModifier
+ 40);
1565 tmpvalue
= tmpvalue
/(1.0f
+ tmpvalue
);
1569 if(tmpvalue
> 0.75f
)
1571 newdamage
= uint32(damage
- (damage
* tmpvalue
));
1573 return (newdamage
> 1) ? newdamage
: 1;
1576 void Unit::CalcAbsorbResist(Unit
*pVictim
,SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
)
1578 if(!pVictim
|| !pVictim
->isAlive() || !damage
)
1581 // Magic damage, check for resists
1582 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
1584 // Get base victim resistance for school
1585 float tmpvalue2
= (float)pVictim
->GetResistance(GetFirstSchoolInMask(schoolMask
));
1586 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
1587 tmpvalue2
+= (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
1589 tmpvalue2
*= (float)(0.15f
/ getLevel());
1590 if (tmpvalue2
< 0.0f
)
1592 if (tmpvalue2
> 0.75f
)
1594 uint32 ran
= urand(0, 100);
1595 uint32 faq
[4] = {24,6,4,6};
1598 for (uint8 i
= 0; i
< 4; i
++)
1600 Binom
+= 2400 *( powf(tmpvalue2
, i
) * powf( (1-tmpvalue2
), (4-i
)))/faq
[i
];
1606 if (damagetype
== DOT
&& m
== 4)
1607 *resist
+= uint32(damage
- 1);
1609 *resist
+= uint32(damage
* m
/ 4);
1610 if(*resist
> damage
)
1616 int32 RemainingDamage
= damage
- *resist
;
1618 // Get unit state (need for some absorb check)
1619 uint32 unitflag
= pVictim
->GetUInt32Value(UNIT_FIELD_FLAGS
);
1620 // Need remove expired auras after
1621 bool existExpired
= false;
1622 // absorb without mana cost
1623 AuraList
const& vSchoolAbsorb
= pVictim
->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1624 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; ++i
)
1626 Modifier
* mod
= (*i
)->GetModifier();
1627 if (!(mod
->m_miscvalue
& schoolMask
))
1630 SpellEntry
const* spellProto
= (*i
)->GetSpellProto();
1632 // Max Amount can be absorbed by this aura
1633 int32 currentAbsorb
= mod
->m_amount
;
1635 // Found empty aura (umpossible but..)
1636 if (currentAbsorb
<=0)
1638 existExpired
= true;
1641 // Handle custom absorb auras
1642 // TODO: try find better way
1643 switch(spellProto
->SpellFamilyName
)
1645 case SPELLFAMILY_GENERIC
:
1648 if (spellProto
->SpellIconID
== 3066)
1650 //reduces all damage taken while stun, fear or silence
1651 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1652 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1656 if (spellProto
->SpellIconID
== 2115)
1658 // while affected by Stun and Fear
1659 if (unitflag
&(UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
))
1660 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1664 if (spellProto
->SpellIconID
== 3006)
1666 // You have a chance equal to your Parry chance
1667 if (damagetype
== DIRECT_DAMAGE
&& // Only for direct damage
1668 roll_chance_f(pVictim
->GetUnitParryChance())) // Roll chance
1669 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1672 // Reflective Shield (Lady Malande boss)
1673 if (spellProto
->Id
== 41475)
1675 int32 reflectDamage
= 0;
1676 if(RemainingDamage
< currentAbsorb
)
1677 reflectDamage
= RemainingDamage
/ 2;
1679 reflectDamage
= currentAbsorb
/ 2;
1680 pVictim
->CastCustomSpell(this, 33619, &reflectDamage
, NULL
, NULL
, true, NULL
, *i
);
1683 if (spellProto
->Id
== 39228 || // Argussian Compass
1684 spellProto
->Id
== 60218) // Essence of Gossamer
1686 // Max absorb stored in 1 dummy effect
1687 if (spellProto
->EffectBasePoints
[1] < currentAbsorb
)
1688 currentAbsorb
= spellProto
->EffectBasePoints
[1];
1693 case SPELLFAMILY_DRUID
:
1696 if (spellProto
->SpellIconID
== 2253)
1698 //reduces all damage taken while Stunned
1699 if (unitflag
& UNIT_FLAG_STUNNED
)
1700 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1705 case SPELLFAMILY_ROGUE
:
1708 if(spellProto
->SpellIconID
== 2109)
1710 if (pVictim
->GetTypeId()==TYPEID_PLAYER
&& // Only players
1711 pVictim
->GetHealth() <= RemainingDamage
&& // Only if damage kill
1712 !((Player
*)pVictim
)->HasSpellCooldown(31231) && // Only if no cooldown
1713 roll_chance_i(currentAbsorb
)) // Only if roll
1715 pVictim
->CastSpell(pVictim
,31231,true);
1716 ((Player
*)pVictim
)->AddSpellCooldown(31231,0,time(NULL
)+60);
1717 // with health > 10% lost health until health==10%, in other case no losses
1718 uint32 health10
= pVictim
->GetMaxHealth()/10;
1719 RemainingDamage
= pVictim
->GetHealth() > health10
? pVictim
->GetHealth() - health10
: 0;
1725 case SPELLFAMILY_PRIEST
:
1727 // Reflective Shield
1728 if (spellProto
->SpellFamilyFlags
== 0x1)
1730 if (pVictim
== this)
1732 Unit
* caster
= (*i
)->GetCaster();
1735 int32 reflectDamage
= 0;
1736 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
1737 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
1739 switch((*k
)->GetModifier()->m_miscvalue
)
1741 case 5065: // Rank 1
1742 case 5064: // Rank 2
1743 case 5063: // Rank 3
1745 if(RemainingDamage
>= currentAbsorb
)
1746 reflectDamage
= (*k
)->GetModifier()->m_amount
* currentAbsorb
/100;
1748 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
1754 pVictim
->CastCustomSpell(this, 33619, &reflectDamage
, NULL
, NULL
, true, NULL
, *i
);
1762 case SPELLFAMILY_SHAMAN
:
1765 if (spellProto
->SpellIconID
== 3066)
1767 //reduces all damage taken while stun, fear or silence
1768 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1769 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1774 case SPELLFAMILY_DEATHKNIGHT
:
1777 if (spellProto
->SpellIconID
== 1958)
1779 // TODO: absorb only while transform
1782 // Anti-Magic Shell (on self)
1783 if (spellProto
->Id
== 48707)
1785 // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power.
1786 // This, if I'm not mistaken, shows that we get back ~2% of the absorbed damage as runic power.
1787 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
1788 int32 regen
= absorbed
* 2 / 10;
1789 pVictim
->CastCustomSpell(pVictim
, 49088, ®en
, 0, 0, true, 0, *i
);
1790 RemainingDamage
-= absorbed
;
1793 // Anti-Magic Shell (on single party/raid member)
1794 if (spellProto
->Id
== 50462)
1796 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1800 if (spellProto
->Id
== 50461)
1802 Unit
* caster
= (*i
)->GetCaster();
1805 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
1806 int32 canabsorb
= caster
->GetHealth();
1807 if (canabsorb
< absorbed
)
1808 absorbed
= canabsorb
;
1809 DealDamage(caster
, absorbed
, NULL
, damagetype
, schoolMask
, 0, false);
1810 RemainingDamage
-= absorbed
;
1819 // currentAbsorb - damage can be absorbed by shield
1820 // If need absorb less damage
1821 if (RemainingDamage
< currentAbsorb
)
1822 currentAbsorb
= RemainingDamage
;
1824 RemainingDamage
-= currentAbsorb
;
1826 // Reduce shield amount
1827 mod
->m_amount
-=currentAbsorb
;
1828 // Need remove it later
1829 if (mod
->m_amount
<=0)
1830 existExpired
= true;
1833 // Remove all expired absorb auras
1836 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end();)
1838 if ((*i
)->GetModifier()->m_amount
<=0)
1840 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
1841 i
= vSchoolAbsorb
.begin();
1848 // absorb by mana cost
1849 AuraList
const& vManaShield
= pVictim
->GetAurasByType(SPELL_AURA_MANA_SHIELD
);
1850 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
1854 // check damage school mask
1855 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1858 int32 currentAbsorb
;
1859 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
1860 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
1862 currentAbsorb
= RemainingDamage
;
1864 float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()];
1865 if(Player
*modOwner
= GetSpellModOwner())
1866 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
1868 int32 maxAbsorb
= int32(pVictim
->GetPower(POWER_MANA
) / manaMultiplier
);
1869 if (currentAbsorb
> maxAbsorb
)
1870 currentAbsorb
= maxAbsorb
;
1872 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
1873 if((*i
)->GetModifier()->m_amount
<= 0)
1875 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
1876 next
= vManaShield
.begin();
1879 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
1880 pVictim
->ApplyPowerMod(POWER_MANA
, manaReduction
, false);
1882 RemainingDamage
-= currentAbsorb
;
1885 // only split damage if not damaging yourself
1888 AuraList
const& vSplitDamageFlat
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
1889 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
1893 // check damage school mask
1894 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1897 // Damage can be splitted only if aura has an alive caster
1898 Unit
*caster
= (*i
)->GetCaster();
1899 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
1902 int32 currentAbsorb
;
1903 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
1904 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
1906 currentAbsorb
= RemainingDamage
;
1908 RemainingDamage
-= currentAbsorb
;
1910 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, currentAbsorb
, schoolMask
, 0, 0, false, 0, false);
1912 CleanDamage cleanDamage
= CleanDamage(currentAbsorb
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
1913 DealDamage(caster
, currentAbsorb
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
1916 AuraList
const& vSplitDamagePct
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
1917 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
1921 // check damage school mask
1922 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1925 // Damage can be splitted only if aura has an alive caster
1926 Unit
*caster
= (*i
)->GetCaster();
1927 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
1930 int32 splitted
= int32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
1932 RemainingDamage
-= splitted
;
1934 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, 0, 0, false, 0, false);
1936 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
1937 DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
1941 *absorb
= damage
- RemainingDamage
- *resist
;
1944 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
1946 if(hasUnitState(UNIT_STAT_CONFUSED
| UNIT_STAT_STUNNED
| UNIT_STAT_FLEEING
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
1949 if (!pVictim
->isAlive())
1952 if(IsNonMeleeSpellCasted(false))
1956 if (attType
== BASE_ATTACK
)
1957 hitInfo
= HITINFO_NORMALSWING2
;
1958 else if (attType
== OFF_ATTACK
)
1959 hitInfo
= HITINFO_LEFTSWING
;
1961 return; // ignore ranged case
1963 uint32 extraAttacks
= m_extraAttacks
;
1965 // melee attack spell casted at main hand attack only
1966 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
1968 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
1970 // not recent extra attack only at any non extra attack (melee spell case)
1971 if(!extra
&& extraAttacks
)
1973 while(m_extraAttacks
)
1975 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
1976 if(m_extraAttacks
> 0)
1984 CalcDamageInfo damageInfo
;
1985 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
1986 // Send log damage message to client
1987 SendAttackStateUpdate(&damageInfo
);
1988 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
1989 DealMeleeDamage(&damageInfo
,true);
1991 if (GetTypeId() == TYPEID_PLAYER
)
1992 DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
1993 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
1995 DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
1996 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
1998 // extra attack only at any non extra attack (normal case)
1999 if(!extra
&& extraAttacks
)
2001 while(m_extraAttacks
)
2003 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
2004 if(m_extraAttacks
> 0)
2010 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
2012 // This is only wrapper
2014 // Miss chance based on melee
2015 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
2017 // Critical hit chance
2018 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
2020 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
2021 float dodge_chance
= pVictim
->GetUnitDodgeChance();
2022 float block_chance
= pVictim
->GetUnitBlockChance();
2023 float parry_chance
= pVictim
->GetUnitParryChance();
2025 // Useful if want to specify crit & miss chances for melee, else it could be removed
2026 DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance
,crit_chance
,dodge_chance
,parry_chance
,block_chance
);
2028 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100));
2031 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const
2033 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2034 return MELEE_HIT_EVADE
;
2036 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
2037 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
2039 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
2040 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
2042 // bonus from skills is 0.04%
2043 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
2044 int32 sum
= 0, tmp
= 0;
2045 int32 roll
= urand (0, 10000);
2047 DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
2048 DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
2049 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
2053 if (tmp
> 0 && roll
< (sum
+= tmp
))
2055 DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS");
2056 return MELEE_HIT_MISS
;
2059 // always crit against a sitting target (except 0 crit chance)
2060 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
2062 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)");
2063 return MELEE_HIT_CRIT
;
2068 // only players can't dodge if attacker is behind
2069 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI
,this))
2071 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
2075 // Reduce dodge chance by attacker expertise rating
2076 if (GetTypeId() == TYPEID_PLAYER
)
2077 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2079 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2080 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2083 if ( (tmp
> 0) // check if unit _can_ dodge
2084 && ((tmp
-= skillBonus
) > 0)
2085 && roll
< (sum
+= tmp
))
2087 DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
2088 return MELEE_HIT_DODGE
;
2092 // parry & block chances
2094 // check if attack comes from behind, nobody can parry or block if attacker is behind
2095 if (!pVictim
->HasInArc(M_PI
,this))
2097 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind.");
2101 // Reduce parry chance by attacker expertise rating
2102 if (GetTypeId() == TYPEID_PLAYER
)
2103 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2105 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
2107 int32 tmp
= int32(parry_chance
);
2108 if ( (tmp
> 0) // check if unit _can_ parry
2109 && ((tmp
-= skillBonus
) > 0)
2110 && (roll
< (sum
+= tmp
)))
2112 DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp
, sum
);
2113 return MELEE_HIT_PARRY
;
2117 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
2120 if ( (tmp
> 0) // check if unit _can_ block
2121 && ((tmp
-= skillBonus
) > 0)
2122 && (roll
< (sum
+= tmp
)))
2124 DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
2125 return MELEE_HIT_BLOCK
;
2133 if (tmp
> 0 && roll
< (sum
+= tmp
))
2135 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
2136 return MELEE_HIT_CRIT
;
2139 // 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)
2140 if( attType
!= RANGED_ATTACK
&&
2141 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
2142 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
2143 getLevel() < pVictim
->getLevelForTarget(this) )
2145 // cap possible value (with bonuses > max skill)
2146 int32 skill
= attackerWeaponSkill
;
2147 int32 maxskill
= attackerMaxSkillValueForLevel
;
2148 skill
= (skill
> maxskill
) ? maxskill
: skill
;
2150 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
2151 tmp
= tmp
> 4000 ? 4000 : tmp
;
2152 if (roll
< (sum
+= tmp
))
2154 DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
2155 return MELEE_HIT_GLANCING
;
2159 // mobs can score crushing blows if they're 4 or more levels above victim
2160 if (getLevelForTarget(pVictim
) >= pVictim
->getLevelForTarget(this) + 4 &&
2161 // can be from by creature (if can) or from controlled player that considered as creature
2162 (GetTypeId()!=TYPEID_PLAYER
&& !((Creature
*)this)->isPet() &&
2163 !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) ||
2164 GetTypeId()==TYPEID_PLAYER
&& GetCharmerOrOwnerGUID()))
2166 // when their weapon skill is 15 or more above victim's defense skill
2167 tmp
= victimDefenseSkill
;
2168 int32 tmpmax
= victimMaxSkillValueForLevel
;
2169 // having defense above your maximum (from items, talents etc.) has no effect
2170 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
2171 // tmp = mob's level * 5 - player's current defense skill
2172 tmp
= attackerMaxSkillValueForLevel
- tmp
;
2175 // add 2% chance per lacking skill point, min. is 15%
2176 tmp
= tmp
* 200 - 1500;
2177 if (roll
< (sum
+= tmp
))
2179 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
2180 return MELEE_HIT_CRUSHING
;
2185 DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL");
2186 return MELEE_HIT_NORMAL
;
2189 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
2191 float min_damage
, max_damage
;
2193 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
2194 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
2200 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
2201 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
2204 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
2205 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
2208 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
2209 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
2211 // Just for good manner
2219 if (min_damage
> max_damage
)
2221 std::swap(min_damage
,max_damage
);
2224 if(max_damage
== 0.0f
)
2227 return urand((uint32
)min_damage
, (uint32
)max_damage
);
2230 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
2232 if(spellProto
->spellLevel
<= 0)
2235 float LvlPenalty
= 0.0f
;
2237 if(spellProto
->spellLevel
< 20)
2238 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
2239 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
2240 if(LvlFactor
> 1.0f
)
2243 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
2246 void Unit::SendAttackStart(Unit
* pVictim
)
2248 WorldPacket
data( SMSG_ATTACKSTART
, 16 );
2249 data
<< uint64(GetGUID());
2250 data
<< uint64(pVictim
->GetGUID());
2252 SendMessageToSet(&data
, true);
2253 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
2256 void Unit::SendAttackStop(Unit
* victim
)
2261 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
2262 data
.append(GetPackGUID());
2263 data
.append(victim
->GetPackGUID()); // can be 0x00...
2264 data
<< uint32(0); // can be 0x1
2265 SendMessageToSet(&data
, true);
2266 sLog
.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER
? "player" : "creature"), GetGUIDLow(), (victim
->GetTypeId()==TYPEID_PLAYER
? "player" : "creature"),victim
->GetGUIDLow());
2268 /*if(victim->GetTypeId() == TYPEID_UNIT)
2269 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
2272 bool Unit::isSpellBlocked(Unit
*pVictim
, SpellEntry
const *spellProto
, WeaponAttackType attackType
)
2274 if (pVictim
->HasInArc(M_PI
,this))
2276 /* Currently not exist spells with ignore block
2277 // Ignore combat result aura (parry/dodge check on prepare)
2278 AuraList const& ignore = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2279 for(AuraList::const_iterator i = ignore.begin(); i != ignore.end(); ++i)
2281 if (!(*i)->isAffectedOnSpell(spellProto))
2283 if ((*i)->GetModifier()->m_miscvalue == )
2288 // Check creatures flags_extra for disable block
2289 if(pVictim
->GetTypeId()==TYPEID_UNIT
&&
2290 ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
)
2293 float blockChance
= GetUnitBlockChance();
2294 blockChance
+= (GetWeaponSkillValue(attackType
) - pVictim
->GetMaxSkillValueForLevel() )*0.04;
2295 if (roll_chance_f(blockChance
))
2301 // Melee based spells can be miss, parry or dodge on this step
2302 // Crit or block - determined on damage calculation phase! (and can be both in some time)
2303 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
2305 // Calculate hit chance (more correct for chance mod)
2308 // PvP - PvE melee chances
2309 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2310 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
2312 HitChance
= 95 - leveldif
;
2314 HitChance
= 93 - (leveldif
- 2) * lchance
;
2316 // Hit chance depends from victim auras
2317 if(attType
== RANGED_ATTACK
)
2318 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2320 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2322 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2323 if(Player
*modOwner
= GetSpellModOwner())
2324 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
2327 float miss_chance
= 100.0f
- HitChance
;
2329 // Bonuses from attacker aura and ratings
2330 if (attType
== RANGED_ATTACK
)
2331 miss_chance
-= m_modRangedHitChance
;
2333 miss_chance
-= m_modMeleeHitChance
;
2335 // bonus from skills is 0.04%
2336 miss_chance
-= skillDiff
* 0.04f
;
2338 // Limit miss chance from 0 to 60%
2339 if (miss_chance
< 0.0f
)
2341 if (miss_chance
> 60.0f
)
2346 // Melee based spells hit result calculations
2347 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2349 WeaponAttackType attType
= BASE_ATTACK
;
2351 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
2352 attType
= RANGED_ATTACK
;
2354 // bonus from skills is 0.04% per skill Diff
2355 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
2356 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
2357 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
2359 uint32 roll
= urand (0, 10000);
2361 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
2363 uint32 tmp
= missChance
;
2365 return SPELL_MISS_MISS
;
2367 // Chance resist mechanic (select max value from every mechanic spell effect)
2368 int32 resist_mech
= 0;
2369 // Get effects mechanic and chance
2370 for(int eff
= 0; eff
< 3; ++eff
)
2372 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2375 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2376 if (resist_mech
< temp
*100)
2377 resist_mech
= temp
*100;
2383 return SPELL_MISS_RESIST
;
2385 bool canDodge
= true;
2386 bool canParry
= true;
2388 // Same spells cannot be parry/dodge
2389 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
2390 return SPELL_MISS_NONE
;
2392 // Ranged attack cannot be parry/dodge
2393 if (attType
== RANGED_ATTACK
)
2394 return SPELL_MISS_NONE
;
2396 // Check for attack from behind
2397 if (!pVictim
->HasInArc(M_PI
,this))
2399 // Can`t dodge from behind in PvP (but its possible in PvE)
2400 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
2405 // Check creatures flags_extra for disable parry
2406 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
2408 uint32 flagEx
= ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
;
2409 if( flagEx
& CREATURE_FLAG_EXTRA_NO_PARRY
)
2412 // Ignore combat result aura
2413 AuraList
const& ignore
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
2414 for(AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
2416 if (!(*i
)->isAffectedOnSpell(spell
))
2418 switch((*i
)->GetModifier()->m_miscvalue
)
2420 case MELEE_HIT_DODGE
: canDodge
= false; break;
2421 case MELEE_HIT_BLOCK
: break; // Block check in hit step
2422 case MELEE_HIT_PARRY
: canParry
= false; break;
2424 DEBUG_LOG("Spell %u SPELL_AURA_IGNORE_COMBAT_RESULT have unhandled state %d", (*i
)->GetId(), (*i
)->GetModifier()->m_miscvalue
);
2432 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
2433 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2434 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2435 // Reduce dodge chance by attacker expertise rating
2436 if (GetTypeId() == TYPEID_PLAYER
)
2437 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2438 if (dodgeChance
< 0)
2443 return SPELL_MISS_DODGE
;
2449 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
2450 // Reduce parry chance by attacker expertise rating
2451 if (GetTypeId() == TYPEID_PLAYER
)
2452 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2453 if (parryChance
< 0)
2458 return SPELL_MISS_PARRY
;
2461 return SPELL_MISS_NONE
;
2464 // TODO need use unit spell resistances in calculations
2465 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2467 // Can`t miss on dead target (on skinning for example)
2468 if (!pVictim
->isAlive())
2469 return SPELL_MISS_NONE
;
2471 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
2472 // PvP - PvE spell misschances per leveldif > 2
2473 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
2474 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2476 // Base hit chance from attacker and victim levels
2479 modHitChance
= 96 - leveldif
;
2481 modHitChance
= 94 - (leveldif
- 2) * lchance
;
2483 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2484 if(Player
*modOwner
= GetSpellModOwner())
2485 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
2486 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
2487 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
2488 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
2489 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
2490 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
2491 if (IsAreaOfEffectSpell(spell
))
2492 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
2493 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
2494 if (IsDispelSpell(spell
))
2495 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
2496 // Chance resist mechanic (select max value from every mechanic spell effect)
2497 int32 resist_mech
= 0;
2498 // Get effects mechanic and chance
2499 for(int eff
= 0; eff
< 3; ++eff
)
2501 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2504 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2505 if (resist_mech
< temp
)
2510 modHitChance
-=resist_mech
;
2512 // Chance resist debuff
2513 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
2515 int32 HitChance
= modHitChance
* 100;
2516 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
2517 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
2519 // Decrease hit chance from victim rating bonus
2520 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2521 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
2523 if (HitChance
< 100) HitChance
= 100;
2524 if (HitChance
> 9900) HitChance
= 9900;
2526 uint32 rand
= urand(0,10000);
2527 if (rand
> HitChance
)
2528 return SPELL_MISS_RESIST
;
2529 return SPELL_MISS_NONE
;
2532 // Calculate spell hit result can be:
2533 // Every spell can: Evade/Immune/Reflect/Sucesful hit
2534 // For melee based spells:
2540 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
2542 // Return evade for units in evade mode
2543 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2544 return SPELL_MISS_EVADE
;
2547 if (pVictim
->IsImmunedToSpell(spell
))
2548 return SPELL_MISS_IMMUNE
;
2550 // All positive spells can`t miss
2551 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
2552 if (IsPositiveSpell(spell
->Id
))
2553 return SPELL_MISS_NONE
;
2556 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
)))
2557 return SPELL_MISS_IMMUNE
;
2559 // Try victim reflect spell
2562 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
2563 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
2564 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
2565 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
2566 reflectchance
+= (*i
)->GetModifier()->m_amount
;
2567 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
2569 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
2570 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
2571 return SPELL_MISS_REFLECT
;
2575 switch (spell
->DmgClass
)
2577 case SPELL_DAMAGE_CLASS_RANGED
:
2578 case SPELL_DAMAGE_CLASS_MELEE
:
2579 return MeleeSpellHitResult(pVictim
, spell
);
2580 case SPELL_DAMAGE_CLASS_NONE
:
2581 case SPELL_DAMAGE_CLASS_MAGIC
:
2582 return MagicSpellHitResult(pVictim
, spell
);
2584 return SPELL_MISS_NONE
;
2587 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
2592 // Base misschance 5%
2593 float misschance
= 5.0f
;
2595 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
2596 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
2598 bool isNormal
= false;
2599 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
2601 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
2607 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
2617 // PvP : PvE melee misschances per leveldif > 2
2618 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2620 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2624 // Hit chance from attacker based on ratings and auras
2625 float m_modHitChance
;
2626 if (attType
== RANGED_ATTACK
)
2627 m_modHitChance
= m_modRangedHitChance
;
2629 m_modHitChance
= m_modMeleeHitChance
;
2632 misschance
+= (leveldif
- m_modHitChance
);
2634 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
2636 // Hit chance for victim based on ratings
2637 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2639 if (attType
== RANGED_ATTACK
)
2640 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
2642 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
2645 // Modify miss chance by victim auras
2646 if(attType
== RANGED_ATTACK
)
2647 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2649 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2651 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
2652 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
2653 misschance
-= skillBonus
* 0.04f
;
2655 // Limit miss chance from 0 to 60%
2656 if ( misschance
< 0.0f
)
2658 if ( misschance
> 60.0f
)
2664 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
2666 if(GetTypeId() == TYPEID_PLAYER
)
2668 // in PvP use full skill instead current skill value
2669 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
2670 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
2671 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
2672 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
2676 return GetUnitMeleeSkill(target
);
2679 float Unit::GetUnitDodgeChance() const
2681 if(hasUnitState(UNIT_STAT_STUNNED
))
2683 if( GetTypeId() == TYPEID_PLAYER
)
2684 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
2687 if(((Creature
const*)this)->isTotem())
2692 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
2693 return dodge
> 0.0f
? dodge
: 0.0f
;
2698 float Unit::GetUnitParryChance() const
2700 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
2703 float chance
= 0.0f
;
2705 if(GetTypeId() == TYPEID_PLAYER
)
2707 Player
const* player
= (Player
const*)this;
2708 if(player
->CanParry() )
2710 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true);
2712 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true);
2715 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
2718 else if(GetTypeId() == TYPEID_UNIT
)
2720 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
2723 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
2727 return chance
> 0.0f
? chance
: 0.0f
;
2730 float Unit::GetUnitBlockChance() const
2732 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
2735 if(GetTypeId() == TYPEID_PLAYER
)
2737 Player
const* player
= (Player
const*)this;
2738 if(player
->CanBlock() )
2740 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
2741 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
2742 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
2744 // is player but has no block ability or no not broken shield equipped
2749 if(((Creature
const*)this)->isTotem())
2754 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
2755 return block
> 0.0f
? block
: 0.0f
;
2760 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
2764 if(GetTypeId() == TYPEID_PLAYER
)
2769 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
2772 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
2775 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
2777 // Just for good manner
2786 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
2790 if(attackType
== RANGED_ATTACK
)
2791 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
2793 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
2795 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
2797 // reduce crit chance from Rating for players
2798 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2800 if (attackType
==RANGED_ATTACK
)
2801 crit
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_RANGED
);
2803 crit
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
);
2806 // Apply crit chance from defence skill
2807 crit
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
2814 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
2817 if(GetTypeId() == TYPEID_PLAYER
)
2819 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true);
2821 // feral or unarmed skill only for base attack
2822 if(attType
!= BASE_ATTACK
&& !item
)
2825 if(((Player
*)this)->IsInFeralForm())
2826 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
2828 // weapon skill or (unarmed for base attack)
2829 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
2831 // in PvP use full skill instead current skill value
2832 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
2833 ? ((Player
*)this)->GetMaxSkillValue(skill
)
2834 : ((Player
*)this)->GetSkillValue(skill
);
2835 // Modify value from ratings
2836 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
2839 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
2840 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
2841 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
2845 value
= GetUnitMeleeSkill(target
);
2849 void Unit::_UpdateSpells( uint32 time
)
2851 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
2852 _UpdateAutoRepeatSpell();
2854 // remove finished spells from current pointers
2855 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
2857 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
2859 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
2860 m_currentSpells
[i
] = NULL
; // remove pointer
2864 // TODO: Find a better way to prevent crash when multiple auras are removed.
2866 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
2868 (*i
).second
->SetUpdated(false);
2870 for (AuraMap::iterator i
= m_Auras
.begin(), next
; i
!= m_Auras
.end(); i
= next
)
2876 // prevent double update
2877 if ((*i
).second
->IsUpdated())
2879 (*i
).second
->SetUpdated(true);
2880 (*i
).second
->Update( time
);
2881 // several auras can be deleted due to update
2884 if (m_Auras
.empty()) break;
2885 next
= m_Auras
.begin();
2891 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
2895 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
2910 if(!m_gameObj
.empty())
2912 std::list
<GameObject
*>::iterator ite1
, dnext1
;
2913 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
2916 //(*i)->Update( difftime );
2917 if( !(*ite1
)->isSpawned() )
2919 (*ite1
)->SetOwnerGUID(0);
2920 (*ite1
)->SetRespawnTime(0);
2922 dnext1
= m_gameObj
.erase(ite1
);
2930 void Unit::_UpdateAutoRepeatSpell()
2932 //check "realtime" interrupts
2933 if ( (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) )
2935 // cancel wand shoot
2936 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
2937 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
2938 m_AutoRepeatFirstCast
= true;
2943 if ( m_AutoRepeatFirstCast
&& getAttackTimer(RANGED_ATTACK
) < 500 )
2944 setAttackTimer(RANGED_ATTACK
,500);
2945 m_AutoRepeatFirstCast
= false;
2948 if (isAttackReady(RANGED_ATTACK
))
2950 // Check if able to cast
2951 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CanCast(true))
2953 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
2958 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
2959 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
2961 // all went good, reset attack
2962 resetAttackTimer(RANGED_ATTACK
);
2966 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
2968 assert(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
2970 uint32 CSpellType
= pSpell
->GetCurrentContainer();
2972 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
2974 // break same type spell if it is not delayed
2975 InterruptSpell(CSpellType
,false);
2977 // special breakage effects:
2980 case CURRENT_GENERIC_SPELL
:
2982 // generic spells always break channeled not delayed spells
2983 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
2985 // autorepeat breaking
2986 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
2988 // break autorepeat if not Auto Shot
2989 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
2990 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
2991 m_AutoRepeatFirstCast
= true;
2995 case CURRENT_CHANNELED_SPELL
:
2997 // channel spells always break generic non-delayed and any channeled spells
2998 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
2999 InterruptSpell(CURRENT_CHANNELED_SPELL
);
3001 // it also does break autorepeat if not Auto Shot
3002 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
3003 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3004 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3007 case CURRENT_AUTOREPEAT_SPELL
:
3009 // only Auto Shoot does not break anything
3010 if (pSpell
->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3012 // generic autorepeats break generic non-delayed and channeled non-delayed spells
3013 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3014 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3016 // special action: set first cast flag
3017 m_AutoRepeatFirstCast
= true;
3022 // other spell types don't break anything now
3026 // current spell (if it is still here) may be safely deleted now
3027 if (m_currentSpells
[CSpellType
])
3028 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
3030 // set new current spell
3031 m_currentSpells
[CSpellType
] = pSpell
;
3032 pSpell
->SetReferencedFromCurrent(true);
3035 void Unit::InterruptSpell(uint32 spellType
, bool withDelayed
)
3037 assert(spellType
< CURRENT_MAX_SPELL
);
3039 if(m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
3041 // send autorepeat cancel message for autorepeat spells
3042 if (spellType
== CURRENT_AUTOREPEAT_SPELL
)
3044 if(GetTypeId()==TYPEID_PLAYER
)
3045 ((Player
*)this)->SendAutoRepeatCancel();
3048 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
3049 m_currentSpells
[spellType
]->cancel();
3050 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
3051 m_currentSpells
[spellType
] = NULL
;
3055 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
3057 // We don't do loop here to explicitly show that melee spell is excluded.
3058 // Maybe later some special spells will be excluded too.
3060 // generic spells are casted when they are not finished and not delayed
3061 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
3062 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3063 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3066 // channeled spells may be delayed, but they are still considered casted
3067 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
3068 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
3071 // autorepeat spells may be finished or delayed, but they are still considered casted
3072 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3078 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
3080 // generic spells are interrupted if they are not finished or delayed
3081 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
3083 if ( (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3084 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3085 m_currentSpells
[CURRENT_GENERIC_SPELL
]->cancel();
3086 m_currentSpells
[CURRENT_GENERIC_SPELL
]->SetReferencedFromCurrent(false);
3087 m_currentSpells
[CURRENT_GENERIC_SPELL
] = NULL
;
3090 // autorepeat spells are interrupted if they are not finished or delayed
3091 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
3093 // send disable autorepeat packet in any case
3094 if(GetTypeId()==TYPEID_PLAYER
)
3095 ((Player
*)this)->SendAutoRepeatCancel();
3097 if ( (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3098 (withDelayed
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3099 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->cancel();
3100 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->SetReferencedFromCurrent(false);
3101 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] = NULL
;
3104 // channeled spells are interrupted if they are not finished, even if they are delayed
3105 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
3107 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
)
3108 m_currentSpells
[CURRENT_CHANNELED_SPELL
]->cancel();
3109 m_currentSpells
[CURRENT_CHANNELED_SPELL
]->SetReferencedFromCurrent(false);
3110 m_currentSpells
[CURRENT_CHANNELED_SPELL
] = NULL
;
3114 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
3116 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
3117 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
3118 return m_currentSpells
[i
];
3122 bool Unit::isInFront(Unit
const* target
, float distance
, float arc
) const
3124 return IsWithinDistInMap(target
, distance
) && HasInArc( arc
, target
);
3127 void Unit::SetInFront(Unit
const* target
)
3129 SetOrientation(GetAngle(target
));
3132 bool Unit::isInBack(Unit
const* target
, float distance
, float arc
) const
3134 return IsWithinDistInMap(target
, distance
) && !HasInArc( 2 * M_PI
- arc
, target
);
3137 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
3140 return c
->canSwim();
3142 return c
->canWalk() || c
->canFly();
3145 bool Unit::IsInWater() const
3147 return MapManager::Instance().GetBaseMap(GetMapId())->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
3150 bool Unit::IsUnderWater() const
3152 return MapManager::Instance().GetBaseMap(GetMapId())->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3155 void Unit::DeMorph()
3157 SetDisplayId(GetNativeDisplayId());
3160 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3164 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3165 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3166 modifier
+= (*i
)->GetModifier()->m_amount
;
3171 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3173 float multiplier
= 1.0f
;
3175 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3176 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3177 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3182 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3186 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3187 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3188 if ((*i
)->GetModifier()->m_amount
> modifier
)
3189 modifier
= (*i
)->GetModifier()->m_amount
;
3194 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
3198 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3199 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3200 if ((*i
)->GetModifier()->m_amount
< modifier
)
3201 modifier
= (*i
)->GetModifier()->m_amount
;
3206 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3210 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3211 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3213 Modifier
* mod
= (*i
)->GetModifier();
3214 if (mod
->m_miscvalue
& misc_mask
)
3215 modifier
+= mod
->m_amount
;
3220 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3222 float multiplier
= 1.0f
;
3224 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3225 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3227 Modifier
* mod
= (*i
)->GetModifier();
3228 if (mod
->m_miscvalue
& misc_mask
)
3229 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3234 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3238 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3239 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3241 Modifier
* mod
= (*i
)->GetModifier();
3242 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
> modifier
)
3243 modifier
= mod
->m_amount
;
3249 int32
Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3253 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3254 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3256 Modifier
* mod
= (*i
)->GetModifier();
3257 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
< modifier
)
3258 modifier
= mod
->m_amount
;
3264 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3268 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3269 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3271 Modifier
* mod
= (*i
)->GetModifier();
3272 if (mod
->m_miscvalue
== misc_value
)
3273 modifier
+= mod
->m_amount
;
3278 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
3280 float multiplier
= 1.0f
;
3282 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3283 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3285 Modifier
* mod
= (*i
)->GetModifier();
3286 if (mod
->m_miscvalue
== misc_value
)
3287 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3292 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3296 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3297 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3299 Modifier
* mod
= (*i
)->GetModifier();
3300 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
3301 modifier
= mod
->m_amount
;
3307 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3311 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3312 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3314 Modifier
* mod
= (*i
)->GetModifier();
3315 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
< modifier
)
3316 modifier
= mod
->m_amount
;
3322 bool Unit::AddAura(Aura
*Aur
)
3324 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
3325 if( !isAlive() && Aur
->GetId() != 20584 && Aur
->GetId() != 8326 && Aur
->GetId() != 2584 &&
3326 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
3332 if(Aur
->GetTarget() != this)
3334 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
3335 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
3336 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
3341 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
3343 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
3344 AuraMap::iterator i
= m_Auras
.find( spair
);
3346 // take out same spell
3347 if (i
!= m_Auras
.end())
3349 // passive and persistent auras can stack with themselves any number of times
3350 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
3352 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
3354 if(i2
->second
->GetCasterGUID()==Aur
->GetCasterGUID())
3356 // Aura can stack on self -> Stack it;
3357 if(aurSpellInfo
->StackAmount
)
3359 i2
->second
->modStackAmount(1);
3363 // can be only single (this check done at _each_ aura add
3364 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3369 switch(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()])
3372 case SPELL_AURA_PERIODIC_DAMAGE
: // allow stack
3373 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
3374 case SPELL_AURA_PERIODIC_LEECH
:
3375 case SPELL_AURA_PERIODIC_HEAL
:
3376 case SPELL_AURA_OBS_MOD_HEALTH
:
3377 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3378 case SPELL_AURA_PERIODIC_ENERGIZE
:
3379 case SPELL_AURA_OBS_MOD_MANA
:
3380 case SPELL_AURA_POWER_BURN_MANA
:
3382 default: // not allow
3383 // can be only single (this check done at _each_ aura add
3384 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3395 // passive auras not stacable with other ranks
3396 if (!IsPassiveSpellStackableWithRanks(aurSpellInfo
))
3398 if (!RemoveNoStackAurasDueToAura(Aur
))
3401 return false; // couldn't remove conflicting aura with higher rank
3405 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
3406 if (IsSingleTargetSpell(aurSpellInfo
) && Aur
->GetTarget())
3408 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
3411 Unit
* caster
= Aur
->GetCaster();
3412 if(!caster
) // caster deleted and not required adding scAura
3415 bool restart
= false;
3416 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3417 for(AuraList::iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
3419 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
3420 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
3422 if ((*itr
)->IsInUse())
3424 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());
3427 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
3436 scAuras
.push_back(Aur
);
3442 // add aura, register in lists and arrays
3444 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
3445 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
3447 m_modAuras
[Aur
->GetModifier()->m_auraname
].push_back(Aur
);
3450 Aur
->ApplyModifier(true,true);
3451 sLog
.outDebug("Aura %u now is in use", Aur
->GetModifier()->m_auraname
);
3455 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
3457 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3460 AuraMap::iterator i
,next
;
3461 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3465 uint32 i_spellId
= (*i
).second
->GetId();
3466 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
3468 if(spellmgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
3470 RemoveAurasDueToSpell(i_spellId
);
3472 if( m_Auras
.empty() )
3475 next
= m_Auras
.begin();
3481 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
3486 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
3490 uint32 spellId
= Aur
->GetId();
3492 // passive spell special case (only non stackable with ranks)
3493 if(IsPassiveSpell(spellId
))
3495 if(IsPassiveSpellStackableWithRanks(spellProto
))
3499 uint32 effIndex
= Aur
->GetEffIndex();
3501 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
3503 AuraMap::iterator i
,next
;
3504 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3508 if (!(*i
).second
) continue;
3510 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
3515 uint32 i_spellId
= i_spellProto
->Id
;
3517 // early checks that spellId is passive non stackable spell
3518 if(IsPassiveSpell(i_spellId
))
3520 // passive non-stackable spells not stackable only for same caster
3521 if(Aur
->GetCasterGUID()!=i
->second
->GetCasterGUID())
3524 // passive non-stackable spells not stackable only with another rank of same spell
3525 if (!spellmgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3529 uint32 i_effIndex
= (*i
).second
->GetEffIndex();
3531 if(i_spellId
== spellId
) continue;
3533 bool is_triggered_by_spell
= false;
3534 // prevent triggered aura of removing aura that triggered it
3535 for(int j
= 0; j
< 3; ++j
)
3536 if (i_spellProto
->EffectTriggerSpell
[j
] == spellProto
->Id
)
3537 is_triggered_by_spell
= true;
3539 if (is_triggered_by_spell
)
3542 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
3544 bool is_sspc
= IsSingleFromSpellSpecificPerCaster(spellId_spec
,i_spellId_spec
);
3546 if( is_sspc
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
3548 // cannot remove higher rank
3549 if (spellmgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3550 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3553 // Its a parent aura (create this aura in ApplyModifier)
3554 if ((*i
).second
->IsInUse())
3556 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());
3559 RemoveAurasDueToSpell(i_spellId
);
3561 if( m_Auras
.empty() )
3564 next
= m_Auras
.begin();
3566 else if( !is_sspc
&& spellmgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
3568 // Its a parent aura (create this aura in ApplyModifier)
3569 if ((*i
).second
->IsInUse())
3571 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());
3574 RemoveAurasDueToSpell(i_spellId
);
3576 if( m_Auras
.empty() )
3579 next
= m_Auras
.begin();
3581 // Potions stack aura by aura (elixirs/flask already checked)
3582 else if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
3584 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
3586 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3587 return false; // cannot remove higher rank
3589 // Its a parent aura (create this aura in ApplyModifier)
3590 if ((*i
).second
->IsInUse())
3592 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());
3603 void Unit::RemoveAura(uint32 spellId
, uint32 effindex
, Aura
* except
)
3605 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
3606 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
3608 if(iter
->second
!=except
)
3611 iter
= m_Auras
.lower_bound(spair
);
3618 void Unit::RemoveAurasDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
3620 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3622 Aura
*aur
= iter
->second
;
3623 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3625 // Custom dispel case
3626 // Unstable Affliction
3627 if (aur
->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (aur
->GetSpellProto()->SpellFamilyFlags
& 0x010000000000LL
))
3629 int32 damage
= aur
->GetModifier()->m_amount
*9;
3630 uint64 caster_guid
= aur
->GetCasterGUID();
3633 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
3635 // backfire damage and silence
3636 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,caster_guid
);
3638 iter
= m_Auras
.begin(); // iterator can be invalidate at cast if self-dispel
3641 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
3648 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
3650 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3652 Aura
*aur
= iter
->second
;
3653 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3655 int32 basePoints
= aur
->GetBasePoints();
3656 // construct the new aura for the attacker
3657 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
);
3661 // set its duration and maximum duration
3662 // max duration 2 minutes (in msecs)
3663 int32 dur
= aur
->GetAuraDuration();
3664 const int32 max_dur
= 2*MINUTE
*1000;
3665 new_aur
->SetAuraMaxDuration( max_dur
> dur
? dur
: max_dur
);
3666 new_aur
->SetAuraDuration( max_dur
> dur
? dur
: max_dur
);
3668 // add the new aura to stealer
3669 stealer
->AddAura(new_aur
);
3671 // Remove aura as dispel
3672 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
3679 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
3681 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3683 if (iter
->second
->GetId() == spellId
)
3684 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
3690 void Unit::RemoveAurasWithDispelType( DispelType type
)
3692 // Create dispel mask by dispel type
3693 uint32 dispelMask
= GetDispellMask(type
);
3694 // Dispel all existing auras vs current dispel type
3695 AuraMap
& auras
= GetAuras();
3696 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
3698 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
3699 if( (1<<spell
->Dispel
) & dispelMask
)
3702 RemoveAurasDueToSpell(spell
->Id
);
3703 itr
= auras
.begin();
3710 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, uint32 effindex
)
3712 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
3713 if(iter
!= m_Auras
.end())
3715 if (iter
->second
->modStackAmount(-1))
3720 void Unit::RemoveSingleSpellAurasFromStack(uint32 spellId
)
3722 for (int i
=0; i
<3; ++i
)
3723 RemoveSingleAuraFromStack(spellId
, i
);
3726 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
)
3728 for (int i
= 0; i
< 3; ++i
)
3729 RemoveAura(spellId
,i
,except
);
3732 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
3734 for (int k
=0; k
< 3; ++k
)
3736 spellEffectPair spair
= spellEffectPair(spellId
, k
);
3737 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
3739 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
3742 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
3750 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
3752 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3754 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
3761 void Unit::RemoveNotOwnSingleTargetAuras()
3763 // single target auras from other casters
3764 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3766 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
3772 // single target auras at other targets
3773 AuraList
& scAuras
= GetSingleCastAuras();
3774 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
3777 if (aura
->GetTarget()!=this)
3779 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
3780 aura
->GetTarget()->RemoveAura(aura
->GetId(),aura
->GetEffIndex());
3781 iter
= scAuras
.begin();
3789 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
3791 Aura
* Aur
= i
->second
;
3792 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
3794 Unit
* caster
= NULL
;
3795 if (IsSingleTargetSpell(AurSpellInfo
))
3797 caster
= Aur
->GetCaster();
3800 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3801 scAuras
.remove(Aur
);
3805 sLog
.outError("Couldn't find the caster of the single target aura, may crash later!");
3810 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
3811 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
3813 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
3817 Aur
->SetRemoveMode(mode
);
3818 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
3819 // remove aura from list before to prevent deleting it before
3821 ++m_removedAuras
; // internal count used by unit update
3823 // Statue unsummoned at aura remove
3824 Totem
* statue
= NULL
;
3825 bool caster_channeled
= false;
3826 if(IsChanneledSpell(AurSpellInfo
))
3828 if(!caster
) // can be already located for IsSingleTargetSpell case
3829 caster
= Aur
->GetCaster();
3833 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
3834 statue
= ((Totem
*)caster
);
3836 caster_channeled
= caster
==this;
3840 sLog
.outDebug("Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
3841 Aur
->ApplyModifier(false,true);
3845 if(caster_channeled
)
3846 RemoveAurasAtChanneledTarget (AurSpellInfo
);
3851 // only way correctly remove all auras from list
3852 if( m_Auras
.empty() )
3855 i
= m_Auras
.begin();
3858 void Unit::RemoveAllAuras()
3860 while (!m_Auras
.empty())
3862 AuraMap::iterator iter
= m_Auras
.begin();
3867 void Unit::RemoveArenaAuras(bool onleave
)
3869 // in join, remove positive buffs, on end, remove negative
3870 // used to remove positive visible auras in arenas
3871 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
3873 if ( !(iter
->second
->GetSpellProto()->AttributesEx4
& (1<<21)) // don't remove stances, shadowform, pally/hunter auras
3874 && !iter
->second
->IsPassive() // don't remove passive auras
3875 && (!(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY
) || !(iter
->second
->GetSpellProto()->Attributes
& SPELL_ATTR_UNK8
)) // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable)
3876 && (iter
->second
->IsPositive() ^ onleave
)) // remove positive buffs on enter, negative buffs on leave
3883 void Unit::RemoveAllAurasOnDeath()
3885 // used just after dieing to remove all visible auras
3886 // and disable the mods for the passive ones
3887 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
3889 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
3890 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
3896 void Unit::DelayAura(uint32 spellId
, uint32 effindex
, int32 delaytime
)
3898 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
3899 if (iter
!= m_Auras
.end())
3901 if (iter
->second
->GetAuraDuration() < delaytime
)
3902 iter
->second
->SetAuraDuration(0);
3904 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
3905 iter
->second
->SendAuraUpdate(false);
3906 sLog
.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter
->second
->GetModifier()->m_auraname
, GetGUIDLow(), iter
->second
->GetAuraDuration());
3910 void Unit::_RemoveAllAuraMods()
3912 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
3914 (*i
).second
->ApplyModifier(false);
3918 void Unit::_ApplyAllAuraMods()
3920 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
3922 (*i
).second
->ApplyModifier(true);
3926 Aura
* Unit::GetAura(uint32 spellId
, uint32 effindex
)
3928 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
3929 if (iter
!= m_Auras
.end())
3930 return iter
->second
;
3934 bool Unit::HasAura(uint32 spellId
) const
3936 for (int i
= 0; i
< 3 ; ++i
)
3938 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, i
));
3939 if (iter
!= m_Auras
.end())
3945 void Unit::AddDynObject(DynamicObject
* dynObj
)
3947 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
3950 void Unit::RemoveDynObject(uint32 spellid
)
3952 if(m_dynObjGUIDs
.empty())
3954 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
3956 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
3959 i
= m_dynObjGUIDs
.erase(i
);
3961 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
3964 i
= m_dynObjGUIDs
.erase(i
);
3971 void Unit::RemoveAllDynObjects()
3973 while(!m_dynObjGUIDs
.empty())
3975 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
3978 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
3982 DynamicObject
* Unit::GetDynObject(uint32 spellId
, uint32 effIndex
)
3984 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
3986 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
3989 i
= m_dynObjGUIDs
.erase(i
);
3993 if (dynObj
->GetSpellId() == spellId
&& dynObj
->GetEffIndex() == effIndex
)
4000 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
4002 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4004 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
4007 i
= m_dynObjGUIDs
.erase(i
);
4011 if (dynObj
->GetSpellId() == spellId
)
4018 void Unit::AddGameObject(GameObject
* gameObj
)
4020 assert(gameObj
&& gameObj
->GetOwnerGUID()==0);
4021 m_gameObj
.push_back(gameObj
);
4022 gameObj
->SetOwnerGUID(GetGUID());
4025 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
4027 assert(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
4029 // GO created by some spell
4030 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
4032 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
4033 // Need activate spell use for owner
4034 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4035 ((Player
*)this)->SendCooldownEvent(createBySpell
);
4037 gameObj
->SetOwnerGUID(0);
4038 m_gameObj
.remove(gameObj
);
4041 gameObj
->SetRespawnTime(0);
4046 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
4048 if(m_gameObj
.empty())
4050 std::list
<GameObject
*>::iterator i
, next
;
4051 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
4054 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
4056 (*i
)->SetOwnerGUID(0);
4059 (*i
)->SetRespawnTime(0);
4063 next
= m_gameObj
.erase(i
);
4070 void Unit::RemoveAllGameObjects()
4072 // remove references to unit
4073 for(std::list
<GameObject
*>::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4075 (*i
)->SetOwnerGUID(0);
4076 (*i
)->SetRespawnTime(0);
4078 i
= m_gameObj
.erase(i
);
4082 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
4084 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size
4085 data
.append(log
->target
->GetPackGUID());
4086 data
.append(log
->attacker
->GetPackGUID());
4087 data
<< uint32(log
->SpellID
);
4088 data
<< uint32(log
->damage
); //damage amount
4090 data
<< uint8 (log
->schoolMask
); //damage school
4091 data
<< uint32(log
->absorb
); //AbsorbedDamage
4092 data
<< uint32(log
->resist
); //resist
4093 data
<< uint8 (log
->phusicalLog
); // damsge type? flag
4094 data
<< uint8 (log
->unused
); //unused
4095 data
<< uint32(log
->blocked
); //blocked
4096 data
<< uint32(log
->HitInfo
);
4097 data
<< uint8 (0); // flag to use extend data
4098 SendMessageToSet( &data
, true );
4101 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
,uint32 SpellID
,uint32 Damage
, SpellSchoolMask damageSchoolMask
,uint32 AbsorbedDamage
, uint32 Resist
,bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
4103 sLog
.outDebug("Sending: SMSG_SPELLNONMELEEDAMAGELOG");
4104 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size
4105 data
.append(target
->GetPackGUID());
4106 data
.append(GetPackGUID());
4107 data
<< uint32(SpellID
);
4108 data
<< uint32(Damage
-AbsorbedDamage
-Resist
-Blocked
);
4109 data
<< uint32(0); // wotlk
4110 data
<< uint8(damageSchoolMask
); // spell school
4111 data
<< uint32(AbsorbedDamage
); // AbsorbedDamage
4112 data
<< uint32(Resist
); // resist
4113 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
4114 data
<< uint8(0); // unk isFromAura
4115 data
<< uint32(Blocked
); // blocked
4116 data
<< uint32(CriticalHit
? 0x27 : 0x25); // hitType, flags: 0x2 - SPELL_HIT_TYPE_CRIT, 0x10 - replace caster?
4117 data
<< uint8(0); // isDebug?
4118 SendMessageToSet( &data
, true );
4121 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
4123 // Not much to do if no flags are set.
4125 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
4126 // Now go on with a victim's events'n'auras
4127 // Not much to do if no flags are set or there is no victim
4128 if(pVictim
&& pVictim
->isAlive() && procVictim
)
4129 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4132 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4134 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4135 data
<< uint32(spellID
);
4136 data
<< uint64(GetGUID());
4137 data
<< uint8(0); // can be 0 or 1
4138 data
<< uint32(1); // target count
4139 // for(i = 0; i < target count; ++i)
4140 data
<< uint64(target
->GetGUID()); // target GUID
4141 data
<< uint8(missInfo
);
4143 SendMessageToSet(&data
, true);
4146 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4149 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, (16+45)); // we guess size
4150 data
<< (uint32
)damageInfo
->HitInfo
;
4151 data
.append(GetPackGUID());
4152 data
.append(damageInfo
->target
->GetPackGUID());
4153 data
<< (uint32
)(damageInfo
->damage
); // Full damage
4154 data
<< uint32(0); // overkill value
4156 data
<< (uint8
)count
; // Sub damage count
4158 for(int i
= 0; i
< count
; ++i
)
4160 data
<< (uint32
)(damageInfo
->damageSchoolMask
); // School of sub damage
4161 data
<< (float)damageInfo
->damage
; // sub damage
4162 data
<< (uint32
)damageInfo
->damage
; // Sub Damage
4165 if(damageInfo
->HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4167 for(int i
= 0; i
< count
; ++i
)
4168 data
<< (uint32
)damageInfo
->absorb
; // Absorb
4171 if(damageInfo
->HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4173 for(int i
= 0; i
< count
; ++i
)
4174 data
<< (uint32
)damageInfo
->resist
; // Resist
4177 data
<< (uint8
)damageInfo
->TargetState
;
4181 if(damageInfo
->HitInfo
& HITINFO_BLOCK
)
4182 data
<< (uint32
)damageInfo
->blocked_amount
;
4184 if(damageInfo
->HitInfo
& HITINFO_UNK3
)
4187 if(damageInfo
->HitInfo
& HITINFO_UNK1
)
4198 for(uint8 i
= 0; i
< 5; ++i
)
4206 SendMessageToSet( &data
, true );
4209 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8 SwingType
, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4211 sLog
.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4213 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, (16+45)); // we guess size
4214 data
<< uint32(HitInfo
); // flags
4215 data
.append(GetPackGUID());
4216 data
.append(target
->GetPackGUID());
4217 data
<< uint32(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);// damage
4218 data
<< uint32(0); // overkill value
4220 data
<< (uint8
)SwingType
; // count?
4222 // for(i = 0; i < SwingType; ++i)
4223 data
<< (uint32
)damageSchoolMask
;
4224 data
<< (float)(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);
4225 data
<< (uint32
)(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);
4228 if(HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4230 // for(i = 0; i < SwingType; ++i)
4231 data
<< uint32(AbsorbDamage
);
4235 if(HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4237 // for(i = 0; i < SwingType; ++i)
4238 data
<< uint32(Resist
);
4242 data
<< (uint8
)TargetState
;
4246 if(HitInfo
& HITINFO_BLOCK
)
4248 data
<< uint32(BlockedAmount
);
4251 if(HitInfo
& HITINFO_UNK3
)
4256 if(HitInfo
& HITINFO_UNK1
)
4267 for(uint8 i
= 0; i
< 5; ++i
)
4275 SendMessageToSet( &data
, true );
4278 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4280 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
4282 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4283 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4285 uint32 triggered_spell_id
= 0;
4286 Unit
* target
= pVictim
;
4287 int32 basepoints0
= 0;
4289 switch(hasteSpell
->SpellFamilyName
)
4291 case SPELLFAMILY_ROGUE
:
4293 switch(hasteSpell
->Id
)
4299 target
= SelectNearbyTarget();
4302 basepoints0
= damage
;
4303 triggered_spell_id
= 22482;
4311 // processed charge only counting case
4312 if(!triggered_spell_id
)
4315 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
4319 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
4324 if(!target
|| target
!=this && !target
->isAlive())
4327 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
4331 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4333 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
4335 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
4336 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
4341 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
4343 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
4344 uint32 effIndex
= triggeredByAura
->GetEffIndex();
4345 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
4347 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4348 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4350 uint32 triggered_spell_id
= 0;
4351 Unit
* target
= pVictim
;
4352 int32 basepoints0
= 0;
4354 switch(dummySpell
->SpellFamilyName
)
4356 case SPELLFAMILY_GENERIC
:
4358 switch (dummySpell
->Id
)
4364 // prevent damage back from weapon special attacks
4365 if (!procSpell
|| procSpell
->DmgClass
!= SPELL_DAMAGE_CLASS_MAGIC
)
4368 // return damage % to attacker but < 50% own total health
4369 basepoints0
= triggerAmount
*int32(damage
)/100;
4370 if(basepoints0
> GetMaxHealth()/2)
4371 basepoints0
= GetMaxHealth()/2;
4373 triggered_spell_id
= 25997;
4381 // prevent chain of triggered spell from same triggered spell
4382 if(procSpell
&& procSpell
->Id
==26654)
4385 target
= SelectNearbyTarget();
4389 triggered_spell_id
= 26654;
4395 if (!procSpell
|| procSpell
->Id
== 24659)
4397 // Need remove one 24659 aura
4398 RemoveSingleSpellAurasFromStack(24659);
4401 // Restless Strength
4404 // Need remove one 24662 aura
4405 RemoveSingleSpellAurasFromStack(24662);
4408 // Adaptive Warding (Frostfire Regalia set)
4416 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
4417 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
4419 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
4421 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& 0x10000000))
4431 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
4433 case SPELL_SCHOOL_NORMAL
:
4434 case SPELL_SCHOOL_HOLY
:
4435 return false; // ignored
4436 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
4437 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
4438 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
4439 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
4440 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
4448 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
4454 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
4456 case SPELL_SCHOOL_NORMAL
:
4457 return false; // ignore
4458 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
4459 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
4460 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
4461 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
4462 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
4463 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
4471 // Mana Leech (Passive) (Priest Pet Aura)
4475 target
= GetOwner();
4479 basepoints0
= int32(damage
* 2.5f
); // manaregen
4480 triggered_spell_id
= 34650;
4486 // Cast finish spell at last charge
4487 if (triggeredByAura
->GetAuraCharges() > 1)
4491 triggered_spell_id
= 33494;
4494 // Twisted Reflection (boss spell)
4496 triggered_spell_id
= 21064;
4498 // Vampiric Aura (boss spell)
4501 basepoints0
= 3 * damage
; // 300%
4502 if (basepoints0
< 0)
4505 triggered_spell_id
= 31285;
4509 // Aura of Madness (Darkmoon Card: Madness trinket)
4510 //=====================================================
4511 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
4512 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
4513 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
4514 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
4515 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
4516 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
4517 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
4518 // 41011 Martyr Complex: +35 stamina (All classes)
4519 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
4520 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
4523 if(GetTypeId() != TYPEID_PLAYER
)
4526 // Select class defined buff
4529 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
4530 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
4532 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
4533 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4536 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
4537 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
4539 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
4540 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4543 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
4544 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
4545 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
4546 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
4548 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
4549 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4552 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
4554 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
4555 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4563 if (roll_chance_i(10))
4564 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
4568 // TODO: need find item for aura and triggered spells
4569 // Sunwell Exalted Caster Neck (??? neck)
4570 // cast ??? Light's Wrath if Exalted by Aldor
4571 // cast ??? Arcane Bolt if Exalted by Scryers*/
4573 return false; // disable for while
4576 if(GetTypeId() != TYPEID_PLAYER)
4579 // Get Aldor reputation rank
4580 if (((Player *)this)->GetReputationRank(932) == REP_EXALTED)
4583 triggered_spell_id = ???
4586 // Get Scryers reputation rank
4587 if (((Player *)this)->GetReputationRank(934) == REP_EXALTED)
4589 triggered_spell_id = ???
4594 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
4595 // cast 45479 Light's Wrath if Exalted by Aldor
4596 // cast 45429 Arcane Bolt if Exalted by Scryers
4599 if(GetTypeId() != TYPEID_PLAYER
)
4602 // Get Aldor reputation rank
4603 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4606 triggered_spell_id
= 45479;
4609 // Get Scryers reputation rank
4610 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4612 triggered_spell_id
= 45429;
4617 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
4618 // cast 45480 Light's Strength if Exalted by Aldor
4619 // cast 45428 Arcane Strike if Exalted by Scryers
4622 if(GetTypeId() != TYPEID_PLAYER
)
4625 // Get Aldor reputation rank
4626 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4629 triggered_spell_id
= 45480;
4632 // Get Scryers reputation rank
4633 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4635 triggered_spell_id
= 45428;
4640 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
4641 // cast 45431 Arcane Insight if Exalted by Aldor
4642 // cast 45432 Light's Ward if Exalted by Scryers
4645 if(GetTypeId() != TYPEID_PLAYER
)
4648 // Get Aldor reputation rank
4649 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4652 triggered_spell_id
= 45432;
4655 // Get Scryers reputation rank
4656 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4659 triggered_spell_id
= 45431;
4664 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
4665 // cast 45478 Light's Salvation if Exalted by Aldor
4666 // cast 45430 Arcane Surge if Exalted by Scryers
4669 if(GetTypeId() != TYPEID_PLAYER
)
4672 // Get Aldor reputation rank
4673 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4676 triggered_spell_id
= 45478;
4679 // Get Scryers reputation rank
4680 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4682 triggered_spell_id
= 45430;
4690 triggered_spell_id
= 48503;
4691 basepoints0
= triggerAmount
;
4695 // Vampiric Touch (generic, used by some boss)
4699 triggered_spell_id
= 52724;
4700 basepoints0
= damage
/ 2;
4709 if (!roll_chance_i(triggerAmount
))
4712 // Remove any stun effect on target
4713 AuraMap
& Auras
= pVictim
->GetAuras();
4714 for(AuraMap::iterator iter
= Auras
.begin(); iter
!= Auras
.end();)
4716 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
4717 if( spell
->Mechanic
== MECHANIC_STUN
||
4718 spell
->EffectMechanic
[iter
->second
->GetEffIndex()] == MECHANIC_STUN
)
4720 pVictim
->RemoveAurasDueToSpell(spell
->Id
);
4721 iter
= Auras
.begin();
4731 case SPELLFAMILY_MAGE
:
4734 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
4736 if (getPowerType() != POWER_MANA
)
4740 basepoints0
= (triggerAmount
* GetMaxPower(POWER_MANA
) / 100);
4742 triggered_spell_id
= 29442;
4745 // Master of Elements
4746 if (dummySpell
->SpellIconID
== 1920)
4752 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
4753 basepoints0
= cost
* triggerAmount
/100;
4754 if( basepoints0
<=0 )
4758 triggered_spell_id
= 29077;
4762 if (dummySpell
->SpellIconID
== 2999)
4766 Aura
*counter
= GetAura(triggeredByAura
->GetId(), 1);
4770 // Count spell criticals in a row in second aura
4771 Modifier
*mod
= counter
->GetModifier();
4772 if (procEx
& PROC_EX_CRITICAL_HIT
)
4775 if (mod
->m_amount
< 100) // not enough
4777 // Crititcal counted -> roll chance
4778 if (roll_chance_i(triggerAmount
))
4779 CastSpell(this, 48108, true, castItem
, triggeredByAura
);
4785 if (dummySpell
->SpellIconID
== 2998)
4790 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
4791 basepoints0
= cost
* triggerAmount
/100;
4792 if( basepoints0
<=0 )
4794 triggered_spell_id
= 44450;
4798 // Incanter's Regalia set (add trigger chance to Mana Shield)
4799 if (dummySpell
->SpellFamilyFlags
& 0x0000000000008000LL
)
4801 if(GetTypeId() != TYPEID_PLAYER
)
4805 triggered_spell_id
= 37436;
4808 switch(dummySpell
->Id
)
4817 switch (dummySpell
->Id
)
4819 case 11119: basepoints0
= int32(0.04f
*damage
); break;
4820 case 11120: basepoints0
= int32(0.08f
*damage
); break;
4821 case 12846: basepoints0
= int32(0.12f
*damage
); break;
4822 case 12847: basepoints0
= int32(0.16f
*damage
); break;
4823 case 12848: basepoints0
= int32(0.20f
*damage
); break;
4825 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
4829 triggered_spell_id
= 12654;
4835 //last charge and crit
4836 if (triggeredByAura
->GetAuraCharges() <= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
4838 RemoveAurasDueToSpell(28682); //-> remove Combustion auras
4839 return true; // charge counting (will removed)
4842 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
4843 return (procEx
& PROC_EX_CRITICAL_HIT
);// charge update only at crit hits, no hidden cooldowns
4848 case SPELLFAMILY_WARRIOR
:
4851 if(dummySpell
->SpellFamilyFlags
==0x0000000800000000LL
)
4853 // check attack comes not from behind
4854 if (!HasInArc(M_PI
, pVictim
))
4857 triggered_spell_id
= 22858;
4861 if (dummySpell
->SpellIconID
== 1697)
4863 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
4864 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
4866 // Need stun or root mechanic
4867 if (!(GetAllSpellMechanicMask(procSpell
) & ((1<<MECHANIC_ROOT
)|(1<<MECHANIC_STUN
))))
4870 switch (dummySpell
->Id
)
4872 case 29838: triggered_spell_id
=29842; break;
4873 case 29834: triggered_spell_id
=29841; break;
4874 case 42770: triggered_spell_id
=42771; break;
4876 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
4884 if (dummySpell
->SpellIconID
== 3214)
4886 triggered_spell_id
= 59653;
4887 basepoints0
= GetShieldBlockValue() * triggerAmount
/ 100;
4892 case SPELLFAMILY_WARLOCK
:
4894 // Seed of Corruption
4895 if (dummySpell
->SpellFamilyFlags
& 0x0000001000000000LL
)
4897 Modifier
* mod
= triggeredByAura
->GetModifier();
4898 // if damage is more than need or target die from damage deal finish spell
4899 if( mod
->m_amount
<= damage
|| GetHealth() <= damage
)
4901 // remember guid before aura delete
4902 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
4904 // Remove aura (before cast for prevent infinite loop handlers)
4905 RemoveAurasDueToSpell(triggeredByAura
->GetId());
4907 // Cast finish spell (triggeredByAura already not exist!)
4908 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
4909 return true; // no hidden cooldown
4913 mod
->m_amount
-=damage
;
4916 // Seed of Corruption (Mobs cast) - no die req
4917 if (dummySpell
->SpellFamilyFlags
== 0x00LL
&& dummySpell
->SpellIconID
== 1932)
4919 Modifier
* mod
= triggeredByAura
->GetModifier();
4920 // if damage is more than need deal finish spell
4921 if( mod
->m_amount
<= damage
)
4923 // remember guid before aura delete
4924 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
4926 // Remove aura (before cast for prevent infinite loop handlers)
4927 RemoveAurasDueToSpell(triggeredByAura
->GetId());
4929 // Cast finish spell (triggeredByAura already not exist!)
4930 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
4931 return true; // no hidden cooldown
4934 mod
->m_amount
-=damage
;
4938 if (dummySpell
->SpellIconID
== 3222)
4943 triggered_spell_id
= 54181;
4944 basepoints0
= damage
* triggerAmount
/ 100;
4947 switch(dummySpell
->Id
)
4954 triggered_spell_id
= 17941;
4963 basepoints0
= int32(damage
*triggerAmount
/100);
4965 triggered_spell_id
= 30294;
4968 // Shadowflame (Voidheart Raiment set bonus)
4971 triggered_spell_id
= 37379;
4974 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
4982 basepoints0
= damage
* triggerAmount
/100;
4983 triggered_spell_id
= 37382;
4986 // Shadowflame Hellfire (Voidheart Raiment set bonus)
4989 triggered_spell_id
= 37378;
4995 case SPELLFAMILY_PRIEST
:
4998 if( dummySpell
->SpellFamilyFlags
& 0x0000040000000000LL
)
5000 if(!pVictim
|| !pVictim
->isAlive())
5003 // pVictim is caster of aura
5004 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5008 basepoints0
= triggerAmount
*damage
/100;
5009 pVictim
->CastCustomSpell(pVictim
,34919,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5010 return true; // no hidden cooldown
5013 if (dummySpell
->SpellIconID
== 2820)
5015 basepoints0
= damage
* triggerAmount
/100;
5016 triggered_spell_id
= 47753;
5019 switch(dummySpell
->Id
)
5024 if(!pVictim
|| !pVictim
->isAlive())
5027 // pVictim is caster of aura
5028 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5032 int32 team
= triggerAmount
*damage
/500;
5033 int32 self
= triggerAmount
*damage
/100 - team
;
5034 pVictim
->CastCustomSpell(pVictim
,15290,&team
,&self
,NULL
,true,castItem
,triggeredByAura
);
5035 return true; // no hidden cooldown
5037 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
5040 // Shadow Word: Pain
5041 if( procSpell
->SpellFamilyFlags
& 0x0000000000008000LL
)
5042 triggered_spell_id
= 40441;
5044 else if( procSpell
->SpellFamilyFlags
& 0x0000000000000010LL
)
5045 triggered_spell_id
= 40440;
5052 // Oracle Healing Bonus ("Garments of the Oracle" set)
5056 basepoints0
= int32(damage
* 10/100);
5058 triggered_spell_id
= 26170;
5061 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
5064 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
5068 basepoints0
= damage
* triggerAmount
/100;
5070 triggered_spell_id
= 39373;
5073 // Greater Heal (Vestments of Faith (Priest Tier 3) - 4 pieces bonus)
5076 triggered_spell_id
= 28810;
5082 case SPELLFAMILY_DRUID
:
5084 switch(dummySpell
->Id
)
5086 // Healing Touch (Dreamwalker Raiment set)
5090 basepoints0
= int32(procSpell
->manaCost
* 30 / 100);
5092 triggered_spell_id
= 28742;
5095 // Healing Touch Refund (Idol of Longevity trinket)
5099 triggered_spell_id
= 28848;
5102 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
5107 triggered_spell_id
= 37238;
5110 // Druid Tier 6 Trinket
5116 if( procSpell
->SpellFamilyFlags
& 0x0000000000000004LL
)
5118 triggered_spell_id
= 40445;
5122 else if( procSpell
->SpellFamilyFlags
& 0x0000000000000010LL
)
5124 triggered_spell_id
= 40446;
5127 // Mangle (cat/bear)
5128 else if( procSpell
->SpellFamilyFlags
& 0x0000044000000000LL
)
5130 triggered_spell_id
= 40452;
5136 if (!roll_chance_f(chance
))
5145 // Deadly Interrupt Effect
5146 triggered_spell_id
= 32747;
5151 if (dummySpell
->SpellIconID
== 2856)
5155 // Only 0 aura can proc
5159 if (procSpell
->SpellFamilyFlags
& 0x0000000000000001LL
)
5161 if (!roll_chance_i(60))
5163 triggered_spell_id
= 48518;
5168 if (procSpell
->SpellFamilyFlags
& 0x0000000000000004LL
)
5170 triggered_spell_id
= 48517;
5177 else if (dummySpell
->SpellIconID
== 2860)
5179 triggered_spell_id
= 48504;
5180 basepoints0
= triggerAmount
* damage
/ 100;
5185 case SPELLFAMILY_ROGUE
:
5187 switch(dummySpell
->Id
)
5189 // Deadly Throw Interrupt
5192 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
5196 triggered_spell_id
= 32747;
5201 if( dummySpell
->SpellIconID
== 2909 )
5203 // "refresh your Slice and Dice duration to its 5 combo point maximum"
5204 // lookup Slice and Dice
5205 AuraList
const& sd
= GetAurasByType(SPELL_AURA_MOD_HASTE
);
5206 for(AuraList::const_iterator itr
= sd
.begin(); itr
!= sd
.end(); ++itr
)
5208 SpellEntry
const *spellProto
= (*itr
)->GetSpellProto();
5209 if( spellProto
->SpellFamilyName
== SPELLFAMILY_ROGUE
&&
5210 spellProto
->SpellFamilyFlags
& 0x0000000000040000LL
)
5212 (*itr
)->SetAuraMaxDuration(GetSpellMaxDuration(spellProto
));
5213 (*itr
)->RefreshAura();
5220 if( dummySpell
->SpellIconID
== 2963 )
5222 triggered_spell_id
= 25809;
5226 if( dummySpell
->SpellIconID
== 2116 )
5232 basepoints0
= procSpell
->manaCost
* triggerAmount
/100;
5233 if(basepoints0
<= 0)
5237 triggered_spell_id
= 31663;
5242 case SPELLFAMILY_HUNTER
:
5244 // Thrill of the Hunt
5245 if ( dummySpell
->SpellIconID
== 2236 )
5251 int32 mana
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5252 basepoints0
= mana
* 40/100;
5253 if(basepoints0
<= 0)
5257 triggered_spell_id
= 34720;
5261 if ( dummySpell
->SpellIconID
== 3406 )
5263 triggered_spell_id
= 57669;
5268 if ( dummySpell
->SpellIconID
== 3579 )
5270 // Proc only from periodic (from trap activation proc another aura of this spell)
5271 if (!(procFlag
& PROC_FLAG_ON_DO_PERIODIC
) || !roll_chance_i(triggerAmount
))
5273 triggered_spell_id
= 56453;
5277 // Rapid Recuperation
5278 if ( dummySpell
->SpellIconID
== 3560 )
5280 // This effect only from Rapid Killing (mana regen)
5281 if (!(procSpell
->SpellFamilyFlags
& 0x0100000000000000LL
))
5283 triggered_spell_id
= 56654;
5289 case SPELLFAMILY_PALADIN
:
5291 // Seal of Righteousness - melee proc dummy (addition ${$MWS*(0.022*$AP+0.044*$SPH)} damage)
5292 if (dummySpell
->SpellFamilyFlags
&0x000000008000000LL
&& effIndex
==0)
5294 triggered_spell_id
= 25742;
5295 float ap
= GetTotalAttackPowerValue(BASE_ATTACK
);
5296 int32 holy
= SpellBaseDamageBonus(SPELL_SCHOOL_MASK_HOLY
) +
5297 SpellBaseDamageBonusForVictim(SPELL_SCHOOL_MASK_HOLY
, pVictim
);
5298 basepoints0
= GetAttackTime(BASE_ATTACK
) * int32(ap
*0.022f
+ 0.044f
* holy
) / 1000;
5302 if (dummySpell
->SpellFamilyFlags
&0x0008000000000000LL
)
5304 triggered_spell_id
= 58597;
5308 // Righteous Vengeance
5309 if (dummySpell
->SpellIconID
== 3025)
5312 basepoints0
= triggerAmount
*damage
/400;
5313 triggered_spell_id
= 61840;
5317 if (dummySpell
->SpellIconID
== 3030)
5320 basepoints0
= triggerAmount
*damage
/400;
5321 triggered_spell_id
= 54203;
5324 switch(dummySpell
->Id
)
5326 // Judgement of Light
5329 // Get judgement caster
5330 Unit
*caster
= triggeredByAura
->GetCaster();
5333 float ap
= caster
->GetTotalAttackPowerValue(BASE_ATTACK
);
5334 int32 holy
= caster
->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_HOLY
) +
5335 caster
->SpellBaseDamageBonusForVictim(SPELL_SCHOOL_MASK_HOLY
, this);
5336 basepoints0
= int32(ap
*0.10f
+ 0.10f
*holy
);
5337 pVictim
->CastCustomSpell(pVictim
, 20267, &basepoints0
, 0, 0, true, 0, triggeredByAura
);
5340 // Judgement of Wisdom
5343 if (pVictim
->getPowerType() == POWER_MANA
)
5344 pVictim
->CastSpell(pVictim
, 20268, true, 0, triggeredByAura
);
5347 // Holy Power (Redemption Armor set)
5353 // Set class defined buff
5354 switch (pVictim
->getClass())
5360 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
5364 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
5368 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
5371 triggered_spell_id
= 28790; // Increases the friendly target's armor
5378 // Seal of Vengeance (damage calc on apply aura)
5381 if(effIndex
!= 0) // effect 1,2 used by seal unleashing code
5384 triggered_spell_id
= 31803;
5387 // Spiritual Attunement
5391 // if healed by another unit (pVictim)
5396 basepoints0
= triggerAmount
*damage
/100;
5398 triggered_spell_id
= 31786;
5401 // Seal of Blood do damage trigger
5404 if (effIndex
== 0) // 0 effect - is proc on enemy
5405 triggered_spell_id
= 31893;
5406 else if (effIndex
== 1) // 1 effect - is proc on self
5408 // add spell damage from prev effect (27%)
5409 damage
+= CalculateDamage(BASE_ATTACK
, false) * 27 / 100;
5410 basepoints0
= triggerAmount
* damage
/ 100;
5412 triggered_spell_id
= 32221;
5418 // Seal of the Martyr do damage trigger
5421 if (effIndex
== 0) // 0 effect - is proc on enemy
5422 triggered_spell_id
= 53719;
5423 else if (effIndex
== 1) // 1 effect - is proc on self
5425 // add spell damage from prev effect (27%)
5426 damage
+= CalculateDamage(BASE_ATTACK
, false) * 27 / 100;
5427 basepoints0
= triggerAmount
* damage
/ 100;
5429 triggered_spell_id
= 53718;
5435 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
5443 // Flash of light/Holy light
5444 if( procSpell
->SpellFamilyFlags
& 0x00000000C0000000LL
)
5446 triggered_spell_id
= 40471;
5450 else if( procSpell
->SpellFamilyFlags
& 0x0000000000800000LL
)
5452 triggered_spell_id
= 40472;
5458 if (!roll_chance_f(chance
))
5463 // Glyph of Divinity
5466 // Lookup base amount mana restore
5467 for (int i
=0; i
<3;i
++)
5468 if (procSpell
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
5470 int32 mana
= procSpell
->EffectBasePoints
[i
];
5471 CastCustomSpell(this, 54986, 0, &mana
, 0, true, castItem
, triggeredByAura
);
5476 // Glyph of Flash of Light
5479 triggered_spell_id
= 54957;
5480 basepoints0
= triggerAmount
*damage
/100;
5483 // Glyph of Holy Light
5486 triggered_spell_id
= 54968;
5487 basepoints0
= triggerAmount
*damage
/100;
5493 case SPELLFAMILY_SHAMAN
:
5495 switch(dummySpell
->Id
)
5497 // Totemic Power (The Earthshatterer set)
5503 // Set class defined buff
5504 switch (pVictim
->getClass())
5510 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
5514 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
5518 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
5521 triggered_spell_id
= 28827; // Increases the friendly target's armor
5528 // Lesser Healing Wave (Totem of Flowing Water Relic)
5532 triggered_spell_id
= 28850;
5535 // Windfury Weapon (Passive) 1-5 Ranks
5538 if(GetTypeId()!=TYPEID_PLAYER
)
5541 if(!castItem
|| !castItem
->IsEquipped())
5544 // custom cooldown processing case
5545 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
5548 // Now amount of extra power stored in 1 effect of Enchant spell
5549 // Get it by item enchant id
5551 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
5553 case 283: spellId
= 8232; break; // 1 Rank
5554 case 284: spellId
= 8235; break; // 2 Rank
5555 case 525: spellId
= 10486; break; // 3 Rank
5556 case 1669:spellId
= 16362; break; // 4 Rank
5557 case 2636:spellId
= 25505; break; // 5 Rank
5558 case 3785:spellId
= 58801; break; // 6 Rank
5559 case 3786:spellId
= 58803; break; // 7 Rank
5560 case 3787:spellId
= 58804; break; // 8 Rank
5563 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
5564 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
5569 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
5570 if(!windfurySpellEntry
)
5572 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
5576 int32 extra_attack_power
= CalculateSpellDamage(windfurySpellEntry
, 1, windfurySpellEntry
->EffectBasePoints
[1], pVictim
);
5579 if ( castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
5581 // Value gained from additional AP
5582 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
5583 triggered_spell_id
= 33750;
5588 // Value gained from additional AP
5589 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
5590 triggered_spell_id
= 25504;
5593 // apply cooldown before cast to prevent processing itself
5595 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
5598 for ( uint32 i
= 0; i
<2; ++i
)
5599 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5603 // Shaman Tier 6 Trinket
5610 if (procSpell
->SpellFamilyFlags
& 0x0000000000000001LL
)
5612 triggered_spell_id
= 40465; // Lightning Bolt
5615 else if (procSpell
->SpellFamilyFlags
& 0x0000000000000080LL
)
5617 triggered_spell_id
= 40465; // Lesser Healing Wave
5620 else if (procSpell
->SpellFamilyFlags
& 0x0000001000000000LL
)
5622 triggered_spell_id
= 40466; // Stormstrike
5628 if (!roll_chance_f(chance
))
5634 // Glyph of Healing Wave
5637 // Not proc from self heals
5640 basepoints0
= triggerAmount
* damage
/ 100;
5642 triggered_spell_id
= 55533;
5649 target
= GetOwner();
5652 basepoints0
= triggerAmount
* damage
/ 100;
5653 triggered_spell_id
= 58879;
5657 // Ancestral Awakening
5658 if (dummySpell
->SpellIconID
== 2018)
5660 // TODO: frite dummy fot triggered spell
5661 triggered_spell_id
= 52759;
5662 basepoints0
= triggerAmount
* damage
/ 100;
5667 if(dummySpell
->SpellFamilyFlags
& 0x0000040000000000LL
)
5669 basepoints0
= triggerAmount
;
5671 triggered_spell_id
= 379;
5674 // Improved Water Shield
5675 if (dummySpell
->SpellIconID
== 2287)
5677 // lookup water shield
5678 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
5679 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
5681 if( (*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
5682 (*itr
)->GetSpellProto()->SpellFamilyFlags
& 0x0000002000000000LL
)
5684 uint32 spell
= (*itr
)->GetSpellProto()->EffectTriggerSpell
[(*itr
)->GetEffIndex()];
5685 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
5686 if ((*itr
)->DropAuraCharge())
5687 RemoveAurasDueToSpell((*itr
)->GetId());
5694 // Lightning Overload
5695 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
5697 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
5700 // custom cooldown processing case
5701 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
5705 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
5706 switch (procSpell
->Id
)
5709 case 403: spellId
= 45284; break; // Rank 1
5710 case 529: spellId
= 45286; break; // Rank 2
5711 case 548: spellId
= 45287; break; // Rank 3
5712 case 915: spellId
= 45288; break; // Rank 4
5713 case 943: spellId
= 45289; break; // Rank 5
5714 case 6041: spellId
= 45290; break; // Rank 6
5715 case 10391: spellId
= 45291; break; // Rank 7
5716 case 10392: spellId
= 45292; break; // Rank 8
5717 case 15207: spellId
= 45293; break; // Rank 9
5718 case 15208: spellId
= 45294; break; // Rank 10
5719 case 25448: spellId
= 45295; break; // Rank 11
5720 case 25449: spellId
= 45296; break; // Rank 12
5721 case 49237: spellId
= 49239; break; // Rank 13
5722 case 49238: spellId
= 49240; break; // Rank 14
5724 case 421: spellId
= 45297; break; // Rank 1
5725 case 930: spellId
= 45298; break; // Rank 2
5726 case 2860: spellId
= 45299; break; // Rank 3
5727 case 10605: spellId
= 45300; break; // Rank 4
5728 case 25439: spellId
= 45301; break; // Rank 5
5729 case 25442: spellId
= 45302; break; // Rank 6
5730 case 49268: spellId
= 49270; break; // Rank 7
5731 case 49269: spellId
= 49271; break; // Rank 8
5733 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
5736 // No thread generated mod
5737 // TODO: exist special flag in spell attributes for this, need found and use!
5738 SpellModifier
*mod
= new SpellModifier
;
5739 mod
->op
= SPELLMOD_THREAT
;
5741 mod
->type
= SPELLMOD_PCT
;
5742 mod
->spellId
= dummySpell
->Id
;
5743 mod
->mask
= 0x0000000000000003LL
;
5745 ((Player
*)this)->AddSpellMod(mod
, true);
5747 // Remove cooldown (Chain Lightning - have Category Recovery time)
5748 if (procSpell
->SpellFamilyFlags
& 0x0000000000000002LL
)
5749 ((Player
*)this)->RemoveSpellCooldown(spellId
);
5751 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
5753 ((Player
*)this)->AddSpellMod(mod
, false);
5755 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5756 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
5761 if(dummySpell
->SpellIconID
== 3059)
5763 // lookup Lightning Shield
5764 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
5765 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
5767 if( (*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
5768 (*itr
)->GetSpellProto()->SpellFamilyFlags
& 0x0000000000000400LL
)
5771 switch ((*itr
)->GetId())
5773 case 324: spell
= 26364; break;
5774 case 325: spell
= 26365; break;
5775 case 905: spell
= 26366; break;
5776 case 945: spell
= 26367; break;
5777 case 8134: spell
= 26369; break;
5778 case 10431: spell
= 26370; break;
5779 case 10432: spell
= 26363; break;
5780 case 25469: spell
= 26371; break;
5781 case 25472: spell
= 26372; break;
5785 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
5786 if ((*itr
)->DropAuraCharge())
5787 RemoveAurasDueToSpell((*itr
)->GetId());
5796 case SPELLFAMILY_DEATHKNIGHT
:
5799 if (dummySpell
->SpellIconID
== 2636)
5801 if (GetTypeId() != TYPEID_PLAYER
|| !((Player
*)this)->isHonorOrXPTarget(pVictim
))
5803 basepoints0
= triggerAmount
* damage
/ 100;
5804 triggered_spell_id
= 53168;
5808 if (dummySpell
->SpellIconID
== 2664)
5810 basepoints0
= triggerAmount
;
5811 triggered_spell_id
= 50163;
5815 // Dancing Rune Weapon
5816 if (dummySpell
->Id
== 49028)
5818 // 1 dummy aura for dismiss rune blade
5821 // TODO: wite script for this "fights on its own, doing the same attacks"
5822 // NOTE: Trigger here on every attack and spell cast
5826 if (dummySpell
->Id
== 49005)
5828 // TODO: need more info (cooldowns/PPM)
5829 triggered_spell_id
= 50424;
5833 if (dummySpell
->SpellFamilyFlags
& 0x0000000000010000LL
)
5835 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
5836 triggered_spell_id
= 50181;
5841 if (dummySpell
->SpellIconID
== 2709)
5843 basepoints0
= triggerAmount
* damage
/ 100;
5844 triggered_spell_id
= 51460;
5847 // Runic Power Back on Snare/Root
5848 if (dummySpell
->Id
== 61257)
5850 // only for spells and hit/crit (trigger start always) and not start from self casted spells
5851 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
5853 // Need snare or root mechanic
5854 if (!(GetAllSpellMechanicMask(procSpell
) & ((1<<MECHANIC_ROOT
)|(1<<MECHANIC_SNARE
))))
5856 triggered_spell_id
= 61258;
5861 if (dummySpell
->SpellIconID
== 1614)
5863 if (!roll_chance_f(GetUnitCriticalChance(BASE_ATTACK
, pVictim
)))
5865 basepoints0
= triggerAmount
* damage
/ 100;
5866 triggered_spell_id
= 50526;
5875 // processed charge only counting case
5876 if(!triggered_spell_id
)
5879 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5883 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
5888 if(!target
|| target
!=this && !target
->isAlive())
5891 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5895 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5897 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5899 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5900 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5905 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
5907 // Get triggered aura spell info
5908 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
5910 // Basepoints of trigger aura
5911 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
5913 // Set trigger spell id, target, custom basepoints
5914 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
5915 Unit
* target
= NULL
;
5916 int32 basepoints0
= 0;
5918 if(triggeredByAura
->GetModifier()->m_auraname
== SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
)
5919 basepoints0
= triggerAmount
;
5921 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5922 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5924 // Try handle uncnown trigger spells
5925 if (sSpellStore
.LookupEntry(trigger_spell_id
)==NULL
)
5927 switch (auraSpellInfo
->SpellFamilyName
)
5929 case SPELLFAMILY_GENERIC
:
5930 //if (auraSpellInfo->Id==59532) // Abandon Passengers on Poly
5931 //if (auraSpellInfo->Id==54775) // Abandon Vehicle on Poly
5932 //if (auraSpellInfo->Id==34082) // Advantaged State (DND)
5933 if (auraSpellInfo
->Id
== 23780) // Aegis of Preservation (Aegis of Preservation trinket)
5934 trigger_spell_id
= 23781;
5935 //else if (auraSpellInfo->Id==43504) // Alterac Valley OnKill Proc Aura
5936 //else if (auraSpellInfo->Id == 48876) // Beast's Mark
5938 // trigger_spell_id = 48877;
5940 //else if (auraSpellInfo->Id == 59237) // Beast's Mark
5942 // trigger_spell_id = 59233;
5944 //else if (auraSpellInfo->Id==46939) // Black Bow of the Betrayer
5946 // trigger_spell_id = 29471; // gain mana
5947 // 27526; // drain mana if possible
5949 //else if (auraSpellInfo->Id==50844) // Blood Mirror
5950 //else if (auraSpellInfo->Id==54476) // Blood Presence
5951 //else if (auraSpellInfo->Id==50689) // Blood Presence (Rank 1)
5952 //else if (auraSpellInfo->Id==37030) // Chaotic Temperament
5953 //else if (auraSpellInfo->Id==52856) // Charge
5954 else if (auraSpellInfo
->Id
==43820) // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
5956 // Pct value stored in dummy
5957 basepoints0
= pVictim
->GetCreateHealth() * auraSpellInfo
->EffectBasePoints
[1] / 100;
5961 //else if (auraSpellInfo->Id==41248) // Consuming Strikes
5962 // trigger_spell_id = 41249;
5963 //else if (auraSpellInfo->Id==45205) // Copy Offhand Weapon
5964 //else if (auraSpellInfo->Id==57594) // Copy Ranged Weapon
5965 //else if (auraSpellInfo->Id==41054) // Copy Weapon
5966 // trigger_spell_id = 41055;
5967 //else if (auraSpellInfo->Id==45343) // Dark Flame Aura
5968 //else if (auraSpellInfo->Id==47300) // Dark Flame Aura
5969 else if (auraSpellInfo
->Id
==57345) // Darkmoon Card: Greatness
5973 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 60229;stat
= GetStat(STAT_STRENGTH
); }
5975 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 60233;stat
= GetStat(STAT_AGILITY
); }
5977 if (GetStat(STAT_INTELLECT
)> stat
) { trigger_spell_id
= 60234;stat
= GetStat(STAT_INTELLECT
);}
5979 if (GetStat(STAT_SPIRIT
) > stat
) { trigger_spell_id
= 60235;stat
= GetStat(STAT_SPIRIT
); }
5981 //else if (auraSpellInfo->Id==31255) // Deadly Swiftness (Rank 1)
5982 //else if (auraSpellInfo->Id==5301) // Defensive State (DND)
5983 //else if (auraSpellInfo->Id==13358) // Defensive State (DND)
5984 //else if (auraSpellInfo->Id==16092) // Defensive State (DND)
5985 //else if (auraSpellInfo->Id==24949) // Defensive State 2 (DND)
5986 //else if (auraSpellInfo->Id==40329) // Demo Shout Sensor
5987 else if (auraSpellInfo
->Id
== 33896) // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
5988 trigger_spell_id
= 33898;
5989 //else if (auraSpellInfo->Id==18943) // Double Attack
5990 //else if (auraSpellInfo->Id==19194) // Double Attack
5991 //else if (auraSpellInfo->Id==19817) // Double Attack
5992 //else if (auraSpellInfo->Id==19818) // Double Attack
5993 //else if (auraSpellInfo->Id==22835) // Drunken Rage
5994 // trigger_spell_id = 14822;
5996 else if (auraSpellInfo->SpellIconID==191) // Elemental Response
5998 switch (auraSpellInfo->Id && auraSpellInfo->AttributesEx==0)
6007 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Elemental Response",auraSpellInfo->Id);
6010 //This generic aura self-triggers a different spell for each school of magic that lands on the wearer:
6011 switch (procSpell->School)
6013 case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192; break;
6014 case SPELL_SCHOOL_FROST: trigger_spell_id = 34193; break;
6015 case SPELL_SCHOOL_ARCANE:trigger_spell_id = 34194; break;
6016 case SPELL_SCHOOL_NATURE:trigger_spell_id = 34195; break;
6017 case SPELL_SCHOOL_SHADOW:trigger_spell_id = 34196; break;
6018 case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197; break;
6019 case SPELL_SCHOOL_NORMAL:trigger_spell_id = 34198; break;
6021 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u Elemental Response wrong school",auraSpellInfo->Id);
6026 //else if (auraSpellInfo->Id==40364) // Entangling Roots Sensor
6027 //else if (auraSpellInfo->Id==33207) // Gossip NPC Periodic - Fidget
6028 //else if (auraSpellInfo->Id==50051) // Ethereal Pet Aura
6029 //else if (auraSpellInfo->Id==35321) // Gushing Wound
6030 //else if (auraSpellInfo->Id==38363) // Gushing Wound
6031 //else if (auraSpellInfo->Id==39215) // Gushing Wound
6032 //else if (auraSpellInfo->Id==44527) // Hate Monster (Spar Buddy) (30 sec)
6033 //else if (auraSpellInfo->Id==44819) // Hate Monster (Spar Buddy) (>30% Health)
6034 //else if (auraSpellInfo->Id==44526) // Hate Monster (Spar) (30 sec)
6035 //else if (auraSpellInfo->Id==44820) // Hate Monster (Spar) (<30%)
6036 //else if (auraSpellInfo->Id==49059) // Horde, Hate Monster (Spar Buddy) (>30% Health)
6037 //else if (auraSpellInfo->Id==40250) // Improved Duration
6038 //else if (auraSpellInfo->Id==59288) // Infra-Green Shield
6039 //else if (auraSpellInfo->Id==54072) // Knockback Ball Passive
6040 else if (auraSpellInfo
->Id
==27522 || auraSpellInfo
->Id
==40336)
6041 // Mana Drain Trigger
6043 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
6044 if (this && this->isAlive())
6045 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
6046 if (pVictim
&& pVictim
->isAlive())
6047 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
6050 //else if (auraSpellInfo->Id==55580) // Mana Link
6051 //else if (auraSpellInfo->Id==45903) // Offensive State
6052 //else if (auraSpellInfo->Id==44326) // Pure Energy Passive
6053 //else if (auraSpellInfo->Id==43453) // Rune Ward
6054 //else if (auraSpellInfo->Id== 7137) // Shadow Charge (Rank 1)
6055 //else if (auraSpellInfo->Id==36576) // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
6056 //else if (auraSpellInfo->Id==34783) // Spell Reflection
6057 //else if (auraSpellInfo->Id==36096) // Spell Reflection
6058 //else if (auraSpellInfo->Id==57587) // Steal Ranged ()
6059 //else if (auraSpellInfo->Id==36207) // Steal Weapon
6060 //else if (auraSpellInfo->Id== 7377) // Take Immune Periodic Damage <Not Working>
6061 //else if (auraSpellInfo->Id==35205) // Vanish
6062 //else if (auraSpellInfo->Id==42730) // Woe Strike
6063 //else if (auraSpellInfo->Id==59735) // Woe Strike
6064 //else if (auraSpellInfo->Id==46146) // [PH] Ahune Spanky Hands
6066 case SPELLFAMILY_MAGE
:
6067 if (auraSpellInfo
->SpellIconID
== 2127) // Blazing Speed
6069 switch (auraSpellInfo
->Id
)
6071 case 31641: // Rank 1
6072 case 31642: // Rank 2
6073 trigger_spell_id
= 31643;
6076 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
6081 case SPELLFAMILY_WARRIOR
:
6082 if (auraSpellInfo
->Id
== 50421) // Scent of Blood
6083 trigger_spell_id
= 50422;
6085 case SPELLFAMILY_WARLOCK
:
6088 if (auraSpellInfo
->SpellIconID
== 1137)
6090 if(!pVictim
|| !pVictim
->isAlive() || pVictim
== this || procSpell
== NULL
)
6092 // Calculate spell tick count for spells
6093 uint32 tick
= 1; // Default tick = 1
6095 // Hellfire have 15 tick
6096 if (procSpell
->SpellFamilyFlags
&0x0000000000000040LL
)
6098 // Rain of Fire have 4 tick
6099 else if (procSpell
->SpellFamilyFlags
&0x0000000000000020LL
)
6104 // Calculate chance = baseChance / tick
6106 switch (auraSpellInfo
->Id
)
6108 case 18096: chance
= 13.0f
/ tick
; break;
6109 case 18073: chance
= 26.0f
/ tick
; break;
6112 if (!roll_chance_f(chance
))
6115 trigger_spell_id
= 18093;
6118 else if (auraSpellInfo
->SpellFamilyFlags
& 0x0000000000004000LL
)
6120 Unit::AuraList
const& mAddFlatModifier
= GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER
);
6121 for(Unit::AuraList::const_iterator i
= mAddFlatModifier
.begin(); i
!= mAddFlatModifier
.end(); ++i
)
6123 if ((*i
)->GetModifier()->m_miscvalue
== SPELLMOD_CHANCE_OF_SUCCESS
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
6125 int32 value2
= CalculateSpellDamage((*i
)->GetSpellProto(),2,(*i
)->GetSpellProto()->EffectBasePoints
[2],this);
6127 CastCustomSpell(this, 18371, &basepoints0
, NULL
, NULL
, true, castItem
, triggeredByAura
);
6131 // Not remove charge (aura removed on death in any cases)
6132 // Need for correct work Drain Soul SPELL_AURA_CHANNEL_DEATH_ITEM aura
6135 // Nether Protection
6136 else if (auraSpellInfo
->SpellIconID
== 1985)
6140 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
6142 case SPELL_SCHOOL_NORMAL
:
6143 case SPELL_SCHOOL_HOLY
:
6144 return false; // ignore
6145 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 54371; break;
6146 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 54375; break;
6147 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 54372; break;
6148 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 54374; break;
6149 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
6156 case SPELLFAMILY_PRIEST
:
6158 // Greater Heal Refund
6159 if (auraSpellInfo
->Id
==37594)
6160 trigger_spell_id
= 37595;
6162 else if (auraSpellInfo
->SpellIconID
== 1875)
6164 switch (auraSpellInfo
->Id
)
6166 case 27811: trigger_spell_id
= 27813; break;
6167 case 27815: trigger_spell_id
= 27817; break;
6168 case 27816: trigger_spell_id
= 27818; break;
6170 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
6173 basepoints0
= damage
* triggerAmount
/ 100 / 3;
6178 case SPELLFAMILY_DRUID
:
6180 // Druid Forms Trinket
6181 if (auraSpellInfo
->Id
==37336)
6185 case FORM_NONE
: trigger_spell_id
= 37344;break;
6186 case FORM_CAT
: trigger_spell_id
= 37341;break;
6188 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
6189 case FORM_TREE
: trigger_spell_id
= 37342;break;
6190 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
6195 //else if (auraSpellInfo->Id==40363)// Entangling Roots ()
6196 // trigger_spell_id = ????;
6197 // Leader of the Pack
6198 else if (auraSpellInfo
->Id
== 24932)
6200 if (triggerAmount
== 0)
6202 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
6203 trigger_spell_id
= 34299;
6207 case SPELLFAMILY_HUNTER
:
6209 case SPELLFAMILY_PALADIN
:
6213 if (auraSpellInfo->SpellIconID == 2137)
6215 switch (auraSpellInfo->Id)
6217 case 31828: // Rank 1
6218 case 31829: // Rank 2
6219 case 31830: // Rank 3
6222 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
6228 if (auraSpellInfo
->Id
==37705)
6230 trigger_spell_id
= 37706;
6234 if (auraSpellInfo
->Id
==60510)
6236 trigger_spell_id
= 60515;
6240 else if (auraSpellInfo
->SpellIconID
==241)
6244 // procspell is triggered spell but we need mana cost of original casted spell
6245 uint32 originalSpellId
= procSpell
->Id
;
6247 if(procSpell
->SpellFamilyFlags
& 0x0001000000000000LL
)
6249 switch(procSpell
->Id
)
6251 case 25914: originalSpellId
= 20473; break;
6252 case 25913: originalSpellId
= 20929; break;
6253 case 25903: originalSpellId
= 20930; break;
6254 case 27175: originalSpellId
= 27174; break;
6255 case 33074: originalSpellId
= 33072; break;
6256 case 48820: originalSpellId
= 48824; break;
6257 case 48821: originalSpellId
= 48825; break;
6259 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
6263 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
6266 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
6269 // percent stored in effect 1 (class scripts) base points
6270 int32 cost
= originalSpell
->manaCost
+ originalSpell
->ManaCostPercentage
* GetCreateMana() / 100;
6271 basepoints0
= cost
*(auraSpellInfo
->EffectBasePoints
[1]+1)/100;
6272 trigger_spell_id
= 20272;
6275 // Lightning Capacitor
6276 else if (auraSpellInfo
->Id
==37657)
6278 if(!pVictim
|| !pVictim
->isAlive())
6281 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
6283 Aura
* dummy
= GetDummyAura(37658);
6284 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
6285 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
6288 RemoveAurasDueToSpell(37658);
6289 trigger_spell_id
= 37661;
6292 // Thunder Capacitor
6293 else if (auraSpellInfo
->Id
== 54841)
6295 if(!pVictim
|| !pVictim
->isAlive())
6298 CastSpell(this, 54842, true, NULL
, triggeredByAura
);
6301 Aura
* dummy
= GetDummyAura(54842);
6302 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
6303 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
6306 RemoveAurasDueToSpell(54842);
6307 trigger_spell_id
= 54843;
6312 case SPELLFAMILY_SHAMAN
:
6314 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc
6315 if(auraSpellInfo
->SpellFamilyFlags
& 0x0000000000000400)
6317 switch(auraSpellInfo
->Id
)
6320 trigger_spell_id
= 26364; break;
6322 trigger_spell_id
= 26365; break;
6324 trigger_spell_id
= 26366; break;
6326 trigger_spell_id
= 26367; break;
6327 case 8134: // Rank 5
6328 trigger_spell_id
= 26369; break;
6329 case 10431: // Rank 6
6330 trigger_spell_id
= 26370; break;
6331 case 10432: // Rank 7
6332 trigger_spell_id
= 26363; break;
6333 case 25469: // Rank 8
6334 trigger_spell_id
= 26371; break;
6335 case 25472: // Rank 9
6336 trigger_spell_id
= 26372; break;
6338 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
6342 // Lightning Shield (The Ten Storms set)
6343 else if (auraSpellInfo
->Id
== 23551)
6345 trigger_spell_id
= 23552;
6348 // Damage from Lightning Shield (The Ten Storms set)
6349 else if (auraSpellInfo
->Id
== 23552)
6350 trigger_spell_id
= 27635;
6351 // Mana Surge (The Earthfury set)
6352 else if (auraSpellInfo
->Id
== 23572)
6356 basepoints0
= procSpell
->manaCost
* 35 / 100;
6357 trigger_spell_id
= 23571;
6360 // Nature's Guardian
6361 else if (auraSpellInfo
->SpellIconID
== 2013)
6363 // Check health condition - should drop to less 30% (damage deal after this!)
6364 if (!(10*(int32(GetHealth() - damage
)) < 3 * GetMaxHealth()))
6367 if(pVictim
&& pVictim
->isAlive())
6368 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
6370 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
6371 trigger_spell_id
= 31616;
6376 case SPELLFAMILY_DEATHKNIGHT
:
6379 if (auraSpellInfo
->SpellIconID
== 1930)
6383 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
6385 case SPELL_SCHOOL_NORMAL
:
6386 return false; // ignore
6387 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 50490; break;
6388 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 50362; break;
6389 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 50488; break;
6390 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 50485; break;
6391 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 50489; break;
6392 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
6398 else if (auraSpellInfo
->Id
== 48266)
6400 if (GetTypeId() != TYPEID_PLAYER
)
6402 if (!((Player
*)this)->isHonorOrXPTarget(pVictim
))
6404 trigger_spell_id
= 50475;
6405 basepoints0
= damage
* triggerAmount
/ 100;
6414 // All ok. Check current trigger spell
6415 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
6416 if ( triggerEntry
== NULL
)
6418 // Not cast unknown spell
6419 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
6423 // not allow proc extra attack spell at extra attack
6424 if( m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
) )
6427 // Costum requirements (not listed in procEx) Warning! damage dealing after this
6428 // Custom triggered spells
6429 switch (auraSpellInfo
->Id
)
6431 // Persistent Shield (Scarab Brooch trinket)
6432 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
6435 basepoints0
= damage
* 15 / 100;
6437 trigger_spell_id
= 26470;
6443 // When your health drops below 20% ....
6444 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
6448 // Deadly Swiftness (Rank 1)
6451 // whenever you deal damage to a target who is below 20% health.
6452 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
6456 trigger_spell_id
= 22588;
6458 // Greater Heal Refund (Avatar Raiment set)
6461 // Not give if target alredy have full health
6462 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
6464 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
6465 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
6469 // Bonus Healing (Crystal Spire of Karabor mace)
6472 // If your target is below $s1% health
6473 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
6477 // Evasive Maneuvers (Commendation of Kael`thas trinket)
6480 // reduce you below $s1% health
6481 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
6485 // Rapid Recuperation
6489 // This effect only from Rapid Fire (ability cast)
6490 if (!(procSpell
->SpellFamilyFlags
& 0x0000000000000020LL
))
6496 // Costum basepoints/target for exist spell
6497 // dummy basepoints or other customs
6498 switch(trigger_spell_id
)
6500 // Cast positive spell on enemy target
6501 case 7099: // Curse of Mending
6502 case 39647: // Curse of Mending
6503 case 29494: // Temptation
6504 case 20233: // Improved Lay on Hands (cast on target)
6509 // Combo points add triggers (need add combopoint only for main tatget, and after possible combopoints reset)
6510 case 15250: // Rogue Setup
6512 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
6514 break; // continue normal case
6516 // Finish movies that add combo
6517 case 14189: // Seal Fate (Netherblade set)
6518 case 14157: // Ruthlessness
6520 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
6523 // Bloodthirst (($m/100)% of max health)
6526 basepoints0
= int32(GetMaxHealth() * triggerAmount
/ 10000);
6529 // Shamanistic Rage triggered spell
6532 basepoints0
= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
6535 // Enlightenment (trigger only from mana cost spells)
6538 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
6547 // For trigger from Blizzard need exist Improved Blizzard
6548 if (procSpell
->SpellFamilyName
==SPELLFAMILY_MAGE
&& procSpell
->SpellFamilyFlags
& 0x0000000000000080LL
)
6551 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
6552 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
6554 int32 script
= (*i
)->GetModifier()->m_miscvalue
;
6555 if(script
==836 || script
==988 || script
==989)
6569 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
6572 // Need stun, fear or silence mechanic
6573 if (!(GetAllSpellMechanicMask(procSpell
) & ((1<<MECHANIC_SILENCE
)|(1<<MECHANIC_STUN
)|(1<<MECHANIC_FEAR
))))
6577 // Burning Determination
6582 // Need Interrupt or Silenced mechanic
6583 if (!(GetAllSpellMechanicMask(procSpell
) & ((1<<MECHANIC_INTERRUPT
)|(1<<MECHANIC_SILENCE
))))
6590 // Proc only from trap activation (from periodic proc another aura of this spell)
6591 if (!(procFlags
& PROC_FLAG_ON_TRAP_ACTIVATION
) || !roll_chance_i(triggerAmount
))
6597 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
6600 // try detect target manually if not set
6601 if ( target
== NULL
)
6602 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
6605 if(!target
|| target
!=this && !target
->isAlive())
6609 CastCustomSpell(target
,trigger_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6611 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
6613 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6614 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
6619 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32 damage
, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
6621 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
6623 if(!pVictim
|| !pVictim
->isAlive())
6626 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
6627 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
6629 uint32 triggered_spell_id
= 0;
6633 case 836: // Improved Blizzard (Rank 1)
6635 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
6637 triggered_spell_id
= 12484;
6640 case 988: // Improved Blizzard (Rank 2)
6642 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
6644 triggered_spell_id
= 12485;
6647 case 989: // Improved Blizzard (Rank 3)
6649 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
6651 triggered_spell_id
= 12486;
6654 case 4086: // Improved Mend Pet (Rank 1)
6655 case 4087: // Improved Mend Pet (Rank 2)
6657 int32 chance
= triggeredByAura
->GetSpellProto()->EffectBasePoints
[triggeredByAura
->GetEffIndex()];
6658 if(!roll_chance_i(chance
))
6661 triggered_spell_id
= 24406;
6664 case 4533: // Dreamwalker Raiment 2 pieces bonus
6667 if (!roll_chance_i(50))
6670 switch (pVictim
->getPowerType())
6672 case POWER_MANA
: triggered_spell_id
= 28722; break;
6673 case POWER_RAGE
: triggered_spell_id
= 28723; break;
6674 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
6680 case 4537: // Dreamwalker Raiment 6 pieces bonus
6681 triggered_spell_id
= 28750; // Blessing of the Claw
6683 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
6684 triggered_spell_id
= 37445; // Mana Surge
6686 case 8152: // Serendipity
6688 // if heal your target over maximum health
6689 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
6691 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
6692 int32 basepoints0
= cost
* triggeredByAura
->GetModifier()->m_amount
/100;
6693 CastCustomSpell(this, 47762, &basepoints0
, 0, 0, true, 0, triggeredByAura
);
6699 if(!triggered_spell_id
)
6702 // standard non-dummy case
6703 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6707 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
6711 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
6714 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
6716 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6717 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
6722 void Unit::setPowerType(Powers new_powertype
)
6724 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
6726 if(GetTypeId() == TYPEID_PLAYER
)
6728 if(((Player
*)this)->GetGroup())
6729 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
6731 else if(((Creature
*)this)->isPet())
6733 Pet
*pet
= ((Pet
*)this);
6734 if(pet
->isControlled())
6736 Unit
*owner
= GetOwner();
6737 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
6738 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
6742 switch(new_powertype
)
6748 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
6749 SetPower( POWER_RAGE
,0);
6752 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
6753 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
6756 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
6757 SetPower( POWER_ENERGY
,0);
6759 case POWER_HAPPINESS
:
6760 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
6761 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
6766 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
6768 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
6771 static uint64 guid
= 0; // prevent repeating spam same faction problem
6773 if(GetGUID() != guid
)
6775 if(GetTypeId() == TYPEID_PLAYER
)
6776 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
6778 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
6785 bool Unit::IsHostileTo(Unit
const* unit
) const
6787 // always non-hostile to self
6791 // always non-hostile to GM in GM mode
6792 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
6795 // always hostile to enemy
6796 if(getVictim()==unit
|| unit
->getVictim()==this)
6799 // test pet/charm masters instead pers/charmeds
6800 Unit
const* testerOwner
= GetCharmerOrOwner();
6801 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
6803 // always hostile to owner's enemy
6804 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
6807 // always hostile to enemy owner
6808 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
6811 // always hostile to owner of owner's enemy
6812 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
6815 Unit
const* tester
= testerOwner
? testerOwner
: this;
6816 Unit
const* target
= targetOwner
? targetOwner
: unit
;
6818 // always non-hostile to target with common owner, or to owner/pet
6822 // special cases (Duel, etc)
6823 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
6825 Player
const* pTester
= (Player
const*)tester
;
6826 Player
const* pTarget
= (Player
const*)target
;
6829 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
6833 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
6837 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
6841 if(pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
) && pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
))
6845 // Green/Blue (can't attack)
6846 if(pTester
->GetTeam()==pTarget
->GetTeam())
6849 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
6850 return pTester
->IsPvP() && pTarget
->IsPvP();
6853 // faction base cases
6854 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
6855 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
6856 if(!tester_faction
|| !target_faction
)
6859 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
6862 // PvC forced reaction and reputation case
6863 if(tester
->GetTypeId()==TYPEID_PLAYER
)
6866 ForcedReactions::const_iterator forceItr
= ((Player
*)tester
)->m_forcedReactions
.find(target_faction
->faction
);
6867 if(forceItr
!=((Player
*)tester
)->m_forcedReactions
.end())
6868 return forceItr
->second
<= REP_HOSTILE
;
6870 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
6871 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
6872 if(raw_target_faction
->reputationListID
>=0)
6873 if(FactionState
const* factionState
= ((Player
*)tester
)->GetFactionState(raw_target_faction
))
6874 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
6876 // CvP forced reaction and reputation case
6877 else if(target
->GetTypeId()==TYPEID_PLAYER
)
6880 ForcedReactions::const_iterator forceItr
= ((Player
const*)target
)->m_forcedReactions
.find(tester_faction
->faction
);
6881 if(forceItr
!=((Player
const*)target
)->m_forcedReactions
.end())
6882 return forceItr
->second
<= REP_HOSTILE
;
6884 // apply reputation state
6885 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
6886 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
6887 return ((Player
const*)target
)->GetReputationRank(raw_tester_faction
) <= REP_HOSTILE
;
6890 // common faction based case (CvC,PvC,CvP)
6891 return tester_faction
->IsHostileTo(*target_faction
);
6894 bool Unit::IsFriendlyTo(Unit
const* unit
) const
6896 // always friendly to self
6900 // always friendly to GM in GM mode
6901 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
6904 // always non-friendly to enemy
6905 if(getVictim()==unit
|| unit
->getVictim()==this)
6908 // test pet/charm masters instead pers/charmeds
6909 Unit
const* testerOwner
= GetCharmerOrOwner();
6910 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
6912 // always non-friendly to owner's enemy
6913 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
6916 // always non-friendly to enemy owner
6917 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
6920 // always non-friendly to owner of owner's enemy
6921 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
6924 Unit
const* tester
= testerOwner
? testerOwner
: this;
6925 Unit
const* target
= targetOwner
? targetOwner
: unit
;
6927 // always friendly to target with common owner, or to owner/pet
6931 // special cases (Duel)
6932 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
6934 Player
const* pTester
= (Player
const*)tester
;
6935 Player
const* pTarget
= (Player
const*)target
;
6938 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
6942 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
6946 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
6950 if(pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
) && pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
))
6954 // Green/Blue (non-attackable)
6955 if(pTester
->GetTeam()==pTarget
->GetTeam())
6958 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
6959 return !pTarget
->IsPvP();
6962 // faction base cases
6963 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
6964 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
6965 if(!tester_faction
|| !target_faction
)
6968 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
6971 // PvC forced reaction and reputation case
6972 if(tester
->GetTypeId()==TYPEID_PLAYER
)
6975 ForcedReactions::const_iterator forceItr
= ((Player
const*)tester
)->m_forcedReactions
.find(target_faction
->faction
);
6976 if(forceItr
!=((Player
const*)tester
)->m_forcedReactions
.end())
6977 return forceItr
->second
>= REP_FRIENDLY
;
6979 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
6980 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
6981 if(raw_target_faction
->reputationListID
>=0)
6982 if(FactionState
const* FactionState
= ((Player
*)tester
)->GetFactionState(raw_target_faction
))
6983 return !(FactionState
->Flags
& FACTION_FLAG_AT_WAR
);
6985 // CvP forced reaction and reputation case
6986 else if(target
->GetTypeId()==TYPEID_PLAYER
)
6989 ForcedReactions::const_iterator forceItr
= ((Player
const*)target
)->m_forcedReactions
.find(tester_faction
->faction
);
6990 if(forceItr
!=((Player
const*)target
)->m_forcedReactions
.end())
6991 return forceItr
->second
>= REP_FRIENDLY
;
6993 // apply reputation state
6994 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
6995 if(raw_tester_faction
->reputationListID
>=0 )
6996 return ((Player
const*)target
)->GetReputationRank(raw_tester_faction
) >= REP_FRIENDLY
;
6999 // common faction based case (CvC,PvC,CvP)
7000 return tester_faction
->IsFriendlyTo(*target_faction
);
7003 bool Unit::IsHostileToPlayers() const
7005 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
7009 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
7010 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
7013 return my_faction
->IsHostileToPlayers();
7016 bool Unit::IsNeutralToAll() const
7018 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
7022 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
7023 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
7026 return my_faction
->IsNeutralToAll();
7029 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
7031 if(!victim
|| victim
== this)
7034 // dead units can neither attack nor be attacked
7035 if(!isAlive() || !victim
->isAlive())
7038 // player cannot attack in mount state
7039 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
7042 // nobody can attack GM in GM-mode
7043 if(victim
->GetTypeId()==TYPEID_PLAYER
)
7045 if(((Player
*)victim
)->isGameMaster())
7050 if(((Creature
*)victim
)->IsInEvadeMode())
7054 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
7055 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
7056 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
7060 if (m_attacking
== victim
)
7062 // switch to melee attack from ranged/magic
7063 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
7065 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
7066 SendAttackStart(victim
);
7075 SetUInt64Value(UNIT_FIELD_TARGET
, victim
->GetGUID());
7078 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
7079 m_attacking
= victim
;
7080 m_attacking
->_addAttacker(this);
7082 if(m_attacking
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)m_attacking
)->AI())
7083 ((Creature
*)m_attacking
)->AI()->AttackedBy(this);
7085 if(GetTypeId()==TYPEID_UNIT
)
7087 WorldPacket
data(SMSG_AI_REACTION
, 12);
7088 data
<< uint64(GetGUID());
7089 data
<< uint32(AI_REACTION_AGGRO
); // Aggro sound
7090 ((WorldObject
*)this)->SendMessageToSet(&data
, true);
7092 ((Creature
*)this)->CallAssistance();
7093 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
7096 // delay offhand weapon attack to next attack time
7097 if(haveOffhandWeapon())
7098 resetAttackTimer(OFF_ATTACK
);
7101 SendAttackStart(victim
);
7106 bool Unit::AttackStop()
7111 Unit
* victim
= m_attacking
;
7113 m_attacking
->_removeAttacker(this);
7117 SetUInt64Value(UNIT_FIELD_TARGET
, 0);
7119 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
7121 InterruptSpell(CURRENT_MELEE_SPELL
);
7123 if( GetTypeId()==TYPEID_UNIT
)
7125 // reset call assistance
7126 ((Creature
*)this)->SetNoCallAssistance(false);
7129 SendAttackStop(victim
);
7134 void Unit::CombatStop(bool cast
)
7136 if(cast
& IsNonMeleeSpellCasted(false))
7137 InterruptNonMeleeSpells(false);
7140 RemoveAllAttackers();
7141 if( GetTypeId()==TYPEID_PLAYER
)
7142 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
7146 void Unit::CombatStopWithPets(bool cast
)
7149 if(Pet
* pet
= GetPet())
7150 pet
->CombatStop(cast
);
7151 if(Unit
* charm
= GetCharm())
7152 charm
->CombatStop(cast
);
7153 if(GetTypeId()==TYPEID_PLAYER
)
7155 GuardianPetList
const& guardians
= ((Player
*)this)->GetGuardians();
7156 for(GuardianPetList::const_iterator itr
= guardians
.begin(); itr
!= guardians
.end(); ++itr
)
7157 if(Unit
* guardian
= Unit::GetUnit(*this,*itr
))
7158 guardian
->CombatStop(cast
);
7162 bool Unit::isAttackingPlayer() const
7164 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
7167 Pet
* pet
= GetPet();
7168 if(pet
&& pet
->isAttackingPlayer())
7171 Unit
* charmed
= GetCharm();
7172 if(charmed
&& charmed
->isAttackingPlayer())
7175 for (int8 i
= 0; i
< MAX_TOTEM
; i
++)
7179 Creature
*totem
= ObjectAccessor::GetCreature(*this, m_TotemSlot
[i
]);
7180 if(totem
&& totem
->isAttackingPlayer())
7188 void Unit::RemoveAllAttackers()
7190 while (!m_attackers
.empty())
7192 AttackerSet::iterator iter
= m_attackers
.begin();
7193 if(!(*iter
)->AttackStop())
7195 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
7196 m_attackers
.erase(iter
);
7201 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
7205 if (!HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)))
7207 SetFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
7208 if(GetTypeId() == TYPEID_PLAYER
)
7210 const PlayerSpellMap
& sp_list
= ((Player
*)this)->GetSpellMap();
7211 for (PlayerSpellMap::const_iterator itr
= sp_list
.begin(); itr
!= sp_list
.end(); ++itr
)
7213 if(itr
->second
->state
== PLAYERSPELL_REMOVED
) continue;
7214 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
7215 if (!spellInfo
|| !IsPassiveSpell(itr
->first
)) continue;
7216 if (spellInfo
->CasterAuraState
== flag
)
7217 CastSpell(this, itr
->first
, true, NULL
);
7224 if (HasFlag(UNIT_FIELD_AURASTATE
,1<<(flag
-1)))
7226 RemoveFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
7227 Unit::AuraMap
& tAuras
= GetAuras();
7228 for (Unit::AuraMap::iterator itr
= tAuras
.begin(); itr
!= tAuras
.end();)
7230 SpellEntry
const* spellProto
= (*itr
).second
->GetSpellProto();
7231 if (spellProto
->CasterAuraState
== flag
)
7233 // exceptions (applied at state but not removed at state change)
7235 if(spellProto
->SpellIconID
==2006 && spellProto
->SpellFamilyName
==SPELLFAMILY_WARRIOR
&& spellProto
->SpellFamilyFlags
==0x100000)
7250 Unit
*Unit::GetOwner() const
7252 uint64 ownerid
= GetOwnerGUID();
7255 return ObjectAccessor::GetUnit(*this, ownerid
);
7258 Unit
*Unit::GetCharmer() const
7260 if(uint64 charmerid
= GetCharmerGUID())
7261 return ObjectAccessor::GetUnit(*this, charmerid
);
7265 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
7267 uint64 guid
= GetCharmerOrOwnerGUID();
7268 if(IS_PLAYER_GUID(guid
))
7269 return ObjectAccessor::GetPlayer(*this, guid
);
7271 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
7274 Pet
* Unit::GetPet() const
7276 if(uint64 pet_guid
= GetPetGUID())
7278 if(Pet
* pet
= ObjectAccessor::GetPet(pet_guid
))
7281 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
7282 const_cast<Unit
*>(this)->SetPet(0);
7288 Unit
* Unit::GetCharm() const
7290 if(uint64 charm_guid
= GetCharmGUID())
7292 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
7295 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
7296 const_cast<Unit
*>(this)->SetCharm(0);
7302 void Unit::SetPet(Pet
* pet
)
7304 SetUInt64Value(UNIT_FIELD_SUMMON
, pet
? pet
->GetGUID() : 0);
7306 // FIXME: hack, speed must be set only at follow
7308 for(int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
7309 pet
->SetSpeed(UnitMoveType(i
), m_speed_rate
[i
], true);
7312 void Unit::SetCharm(Unit
* pet
)
7314 SetUInt64Value(UNIT_FIELD_CHARM
, pet
? pet
->GetGUID() : 0);
7316 if(GetTypeId() == TYPEID_PLAYER
)
7317 ((Player
*)this)->m_mover
= pet
? pet
: this;
7320 void Unit::UnsummonAllTotems()
7322 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
7327 Creature
*OldTotem
= ObjectAccessor::GetCreature(*this, m_TotemSlot
[i
]);
7328 if (OldTotem
&& OldTotem
->isTotem())
7329 ((Totem
*)OldTotem
)->UnSummon();
7333 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, bool critical
)
7336 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
7337 data
.append(pVictim
->GetPackGUID());
7338 data
.append(GetPackGUID());
7339 data
<< uint32(SpellID
);
7340 data
<< uint32(Damage
);
7341 data
<< uint32(0); // over healing?
7342 data
<< uint8(critical
? 1 : 0);
7343 data
<< uint8(0); // unused in client?
7344 SendMessageToSet(&data
, true);
7347 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
7349 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
7350 data
.append(pVictim
->GetPackGUID());
7351 data
.append(GetPackGUID());
7352 data
<< uint32(SpellID
);
7353 data
<< uint32(powertype
);
7354 data
<< uint32(Damage
);
7355 SendMessageToSet(&data
, true);
7358 uint32
Unit::SpellDamageBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
)
7360 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
7363 // For totems get damage bonus from owner (statue isn't totem in fact)
7364 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
7366 if(Unit
* owner
= GetOwner())
7367 return owner
->SpellDamageBonus(pVictim
, spellProto
, pdamage
, damagetype
);
7370 // Taken/Done total percent damage auras
7371 float DoneTotalMod
= 1.0f
;
7372 float TakenTotalMod
= 1.0f
;
7373 uint32 DoneTotal
= 0;
7374 uint32 TakenTotal
= 0;
7378 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
7379 DoneTotalMod
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
7381 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
7382 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
7384 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
7385 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
7386 // -1 == any item class (not wand then)
7387 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
7388 // 0 == any inventory type (not wand then)
7390 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7394 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
7395 // Add flat bonus from spell damage versus
7396 DoneTotal
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
7397 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
7398 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
7399 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
7400 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7402 // done scripted mod (take it from owner)
7403 Unit
*owner
= GetOwner();
7404 if (!owner
) owner
= this;
7405 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7406 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7408 if (!(*i
)->isAffectedOnSpell(spellProto
))
7410 switch((*i
)->GetModifier()->m_miscvalue
)
7412 case 4920: // Molten Fury
7414 case 6917: // Death's Embrace
7418 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
7419 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
7426 // effect 1 m_amount
7427 int32 maxPercent
= (*i
)->GetModifier()->m_amount
;
7428 // effect 0 m_amount
7429 int32 stepPercent
= CalculateSpellDamage((*i
)->GetSpellProto(), 0, (*i
)->GetSpellProto()->EffectBasePoints
[0], this);
7430 // count affliction effects and calc additional damage in percentage
7431 int32 modPercent
= 0;
7432 AuraMap
const& victimAuras
= pVictim
->GetAuras();
7433 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
7435 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
7436 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_WARLOCK
|| !(m_spell
->SpellFamilyFlags
& 0x0004071B8044C402LL
))
7438 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
7439 if (modPercent
>= maxPercent
)
7441 modPercent
= maxPercent
;
7445 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
7448 case 6916: // Death's Embrace
7451 if (HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
))
7452 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
7454 case 5481: // Starfire Bonus
7456 AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
7457 for(AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
7459 SpellEntry
const* m_spell
= (*itr
)->GetSpellProto();
7460 if (m_spell
->SpellFamilyName
== SPELLFAMILY_DRUID
&&
7461 m_spell
->SpellFamilyFlags
& 0x0000000000200002LL
)
7463 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7469 case 4418: // Increased Shock Damage
7470 case 4554: // Increased Lightning Damage
7471 case 4555: // Improved Moonfire
7472 case 5142: // Increased Lightning Damage
7473 case 5147: // Improved Consecration / Libram of Resurgence
7474 case 5148: // Idol of the Shooting Star
7475 case 6008: // Increased Lightning Damage / Totem of Hex
7477 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
7485 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
7487 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
7488 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
7490 else // Tundra Stalker
7492 AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
7493 for(AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
7495 SpellEntry
const* m_spell
= (*itr
)->GetSpellProto();
7496 if (m_spell
->SpellFamilyName
== SPELLFAMILY_DEATHKNIGHT
&&
7497 m_spell
->SpellFamilyFlags
& 0x0400000000000000LL
)
7499 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7506 case 7293: // Rage of Rivendare
7508 AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
7509 for(AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
7511 SpellEntry
const* m_spell
= (*itr
)->GetSpellProto();
7512 if (m_spell
->SpellFamilyName
== SPELLFAMILY_DEATHKNIGHT
&&
7513 m_spell
->SpellFamilyFlags
& 0x0200000000000000LL
)
7515 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7524 AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
7525 for(AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
7527 SpellEntry
const* m_spell
= (*itr
)->GetSpellProto();
7528 if (m_spell
->SpellFamilyName
== SPELLFAMILY_PRIEST
&&
7529 m_spell
->SpellFamilyFlags
& 0x0000000000008000LL
&&
7530 (*itr
)->GetCasterGUID()==GetGUID())
7532 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7545 AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_MOD_STALKED
);
7546 for(AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
7548 SpellEntry
const* m_spell
= (*itr
)->GetSpellProto();
7549 if (m_spell
->SpellFamilyName
== SPELLFAMILY_HUNTER
&&
7550 m_spell
->SpellFamilyFlags
& 0x0000000000000400LL
)
7552 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7562 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
7563 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
7564 if( (*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
) )
7565 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7567 // .. taken pct: dummy auras
7568 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
7569 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
7571 switch((*i
)->GetSpellProto()->SpellIconID
)
7575 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) )
7577 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
7579 float mod
= -((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
7580 if (mod
< (*i
)->GetModifier()->m_amount
)
7581 mod
= (*i
)->GetModifier()->m_amount
;
7582 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
7588 // From caster spells
7589 AuraList
const& mOwnerTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_FROM_CASTER
);
7590 for(AuraList::const_iterator i
= mOwnerTaken
.begin(); i
!= mOwnerTaken
.end(); ++i
)
7591 if( (*i
)->GetCasterGUID() == GetGUID() && (*i
)->isAffectedOnSpell(spellProto
))
7592 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7594 // Mod damage from spell mechanic
7595 uint32 mechanicMask
= GetAllSpellMechanicMask(spellProto
);
7598 AuraList
const& mDamageDoneMechanic
= pVictim
->GetAurasByType(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
);
7599 for(AuraList::const_iterator i
= mDamageDoneMechanic
.begin();i
!= mDamageDoneMechanic
.end(); ++i
)
7600 if(mechanicMask
& uint32(1<<((*i
)->GetModifier()->m_miscvalue
)))
7601 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7604 // Damage Done from spell damage bonus
7605 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
7607 // Taken/Done fixed damage bonus auras
7608 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonus(GetSpellSchoolMask(spellProto
));
7609 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
7611 // Pets just add their bonus damage to their spell damage
7612 // note that their spell damage is just gain of their own auras
7613 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
7614 DoneAdvertisedBenefit
+= ((Pet
*)this)->GetBonusDamage();
7616 // Damage over Time spells bonus calculation
7617 float DotFactor
= 1.0f
;
7618 if(damagetype
== DOT
)
7620 int32 DotDuration
= GetSpellDuration(spellProto
);
7624 if(DotDuration
> 30000) DotDuration
= 30000;
7625 if(!IsChanneledSpell(spellProto
)) DotFactor
= DotDuration
/ 15000.0f
;
7627 for(int j
= 0; j
< 3; j
++)
7629 if( spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& (
7630 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_DAMAGE
||
7631 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
) )
7638 if(spellProto
->EffectAmplitude
[x
] != 0)
7639 DotTicks
= DotDuration
/ spellProto
->EffectAmplitude
[x
];
7642 DoneAdvertisedBenefit
/= DotTicks
;
7643 TakenAdvertisedBenefit
/= DotTicks
;
7647 // Distribute Damage over multiple effects, reduce by AoE
7648 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
7650 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
7651 for(int j
= 0; j
< 3; ++j
)
7653 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
7654 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
7661 switch(spellProto
->SpellFamilyName
)
7663 case SPELLFAMILY_MAGE
:
7664 // Ignite - do not modify, it is (8*Rank)% damage of procing Spell
7665 if(spellProto
->Id
==12654)
7670 else if((spellProto
->SpellFamilyFlags
& 0x20000LL
) && spellProto
->SpellIconID
== 186)
7672 CastingTime
/= 3; // applied 1/3 bonuses in case generic target
7673 if(pVictim
->isFrozen()) // and compensate this for frozen target.
7674 TakenTotalMod
*= 3.0f
;
7676 // Pyroblast - 115% of Fire Damage, DoT - 20% of Fire Damage
7677 else if((spellProto
->SpellFamilyFlags
& 0x400000LL
) && spellProto
->SpellIconID
== 184 )
7679 DotFactor
= damagetype
== DOT
? 0.2f
: 1.0f
;
7680 CastingTime
= damagetype
== DOT
? 3500 : 4025;
7682 // Fireball - 100% of Fire Damage, DoT - 0% of Fire Damage
7683 else if((spellProto
->SpellFamilyFlags
& 0x1LL
) && spellProto
->SpellIconID
== 185)
7686 DotFactor
= damagetype
== DOT
? 0.0f
: 1.0f
;
7689 else if (spellProto
->SpellFamilyFlags
& 0x0000000800000000LL
)
7693 // Arcane Missiles triggered spell
7694 else if ((spellProto
->SpellFamilyFlags
& 0x200000LL
) && spellProto
->SpellIconID
== 225)
7698 // Blizzard triggered spell
7699 else if ((spellProto
->SpellFamilyFlags
& 0x80080LL
) && spellProto
->SpellIconID
== 285)
7704 case SPELLFAMILY_WARLOCK
:
7706 if((spellProto
->SpellFamilyFlags
& 0x40000LL
) && spellProto
->SpellIconID
== 208)
7708 CastingTime
= 2800; // 80% from +shadow damage
7709 DoneTotalMod
= 1.0f
;
7710 TakenTotalMod
= 1.0f
;
7713 else if((spellProto
->SpellFamilyFlags
& 0x80000000LL
) && spellProto
->SpellIconID
== 154 && GetPetGUID())
7715 CastingTime
= 3360; // 96% from +shadow damage
7716 DoneTotalMod
= 1.0f
;
7717 TakenTotalMod
= 1.0f
;
7719 // Soul Fire - 115% of Fire Damage
7720 else if((spellProto
->SpellFamilyFlags
& 0x8000000000LL
) && spellProto
->SpellIconID
== 184)
7724 // Curse of Agony - 120% of Shadow Damage
7725 else if((spellProto
->SpellFamilyFlags
& 0x0000000400LL
) && spellProto
->SpellIconID
== 544)
7729 // Drain Mana - 0% of Shadow Damage
7730 else if((spellProto
->SpellFamilyFlags
& 0x10LL
) && spellProto
->SpellIconID
== 548)
7734 // Drain Soul 214.3%
7735 else if ((spellProto
->SpellFamilyFlags
& 0x4000LL
) && spellProto
->SpellIconID
== 113 )
7740 else if ((spellProto
->SpellFamilyFlags
& 0x40LL
) && spellProto
->SpellIconID
== 937)
7742 CastingTime
= damagetype
== DOT
? 5000 : 500; // self damage seems to be so
7744 // Unstable Affliction - 180%
7745 else if (spellProto
->Id
== 31117 && spellProto
->SpellIconID
== 232)
7750 else if ((spellProto
->SpellFamilyFlags
& 0x2LL
) && spellProto
->SpellIconID
== 313)
7755 case SPELLFAMILY_PALADIN
:
7756 // Consecration - 95% of Holy Damage
7757 if((spellProto
->SpellFamilyFlags
& 0x20LL
) && spellProto
->SpellIconID
== 51)
7762 // Judgement of Righteousness - 32%
7763 else if (spellProto
->SpellFamilyFlags
& 0x0000000000000400LL
)
7767 // Seal of Vengeance - 17% per Fully Stacked Tick - 5 Applications
7768 else if ((spellProto
->SpellFamilyFlags
& 0x80000000000LL
) && spellProto
->SpellIconID
== 2292)
7773 // Holy shield - 5% of Holy Damage
7774 else if ((spellProto
->SpellFamilyFlags
& 0x4000000000LL
) && spellProto
->SpellIconID
== 453)
7778 // Blessing of Sanctuary - 0%
7779 else if ((spellProto
->SpellFamilyFlags
& 0x10000000LL
) && spellProto
->SpellIconID
== 29)
7784 case SPELLFAMILY_SHAMAN
:
7786 if (spellProto
->SpellFamilyFlags
& 0x000040000000LL
)
7788 if (spellProto
->SpellIconID
== 33) // Fire Nova totem attack must be 21.4%(untested)
7789 CastingTime
= 749; // ignore CastingTime and use as modifier
7790 else if (spellProto
->SpellIconID
== 680) // Searing Totem attack 8%
7791 CastingTime
= 280; // ignore CastingTime and use as modifier
7792 else if (spellProto
->SpellIconID
== 37) // Magma totem attack must be 6.67%(untested)
7793 CastingTime
= 234; // ignore CastingTimePenalty and use as modifier
7795 // Lightning Shield (and proc shield from T2 8 pieces bonus ) 33% per charge
7796 else if( (spellProto
->SpellFamilyFlags
& 0x00000000400LL
) || spellProto
->Id
== 23552)
7797 CastingTime
= 1155; // ignore CastingTimePenalty and use as modifier
7799 case SPELLFAMILY_PRIEST
:
7800 // Mana Burn - 0% of Shadow Damage
7801 if((spellProto
->SpellFamilyFlags
& 0x10LL
) && spellProto
->SpellIconID
== 212)
7805 // Mind Flay - 59% of Shadow Damage
7806 else if((spellProto
->SpellFamilyFlags
& 0x800000LL
) && spellProto
->SpellIconID
== 548)
7810 // Holy Fire - 86.71%, DoT - 16.5%
7811 else if ((spellProto
->SpellFamilyFlags
& 0x100000LL
) && spellProto
->SpellIconID
== 156)
7813 DotFactor
= damagetype
== DOT
? 0.165f
: 1.0f
;
7814 CastingTime
= damagetype
== DOT
? 3500 : 3035;
7816 // Shadowguard - 28% per charge
7817 else if ((spellProto
->SpellFamilyFlags
& 0x2000000LL
) && spellProto
->SpellIconID
== 19)
7821 // Touch of Weakeness - 10%
7822 else if ((spellProto
->SpellFamilyFlags
& 0x80000LL
) && spellProto
->SpellIconID
== 1591)
7826 // Reflective Shield (back damage) - 0% (other spells fit to check not have damage effects/auras)
7827 else if (spellProto
->SpellFamilyFlags
== 0 && spellProto
->SpellIconID
== 566)
7832 else if ((spellProto
->SpellFamilyFlags
& 0x400000LL
) && spellProto
->SpellIconID
== 1874)
7837 case SPELLFAMILY_DRUID
:
7838 // Hurricane triggered spell
7839 if((spellProto
->SpellFamilyFlags
& 0x400000LL
) && spellProto
->SpellIconID
== 220)
7844 case SPELLFAMILY_WARRIOR
:
7845 case SPELLFAMILY_HUNTER
:
7846 case SPELLFAMILY_ROGUE
:
7853 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
7855 // Spellmod SpellDamage
7856 float SpellModSpellDamage
= 100.0f
;
7858 if(Player
* modOwner
= GetSpellModOwner())
7859 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
7861 SpellModSpellDamage
/= 100.0f
;
7863 float DoneActualBenefit
= DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* SpellModSpellDamage
* LvlPenalty
;
7864 float TakenActualBenefit
= TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
;
7866 float tmpDamage
= (float(pdamage
)+DoneActualBenefit
+ DoneTotal
)*DoneTotalMod
;
7867 // apply spellmod to Done damage (flat and pct)
7868 if(Player
* modOwner
= GetSpellModOwner())
7869 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
7871 tmpDamage
= (tmpDamage
+ TakenActualBenefit
+ TakenTotal
)*TakenTotalMod
;
7873 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
7876 int32
Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask
)
7878 int32 DoneAdvertisedBenefit
= 0;
7881 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
7882 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
7883 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
7884 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
7885 // -1 == any item class (not wand then)
7886 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
7887 // 0 == any inventory type (not wand then)
7888 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7890 if (GetTypeId() == TYPEID_PLAYER
)
7893 DoneAdvertisedBenefit
+=((Player
*)this)->GetBaseSpellDamageBonus();
7895 // Damage bonus from stats
7896 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
7897 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
7899 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
7901 // stat used stored in miscValueB for this aura
7902 Stats usedStat
= Stats((*i
)->GetMiscBValue());
7903 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
7906 // ... and attack power
7907 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
7908 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
7909 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
7910 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
7913 return DoneAdvertisedBenefit
;
7916 int32
Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
7918 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
7920 int32 TakenAdvertisedBenefit
= 0;
7921 // ..done (for creature type by mask) in taken
7922 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
7923 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
7924 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
7925 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7928 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
7929 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
7930 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
7931 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7933 return TakenAdvertisedBenefit
;
7936 bool Unit::isSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
7938 // not critting spell
7939 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
7942 float crit_chance
= 0.0f
;
7943 switch(spellProto
->DmgClass
)
7945 case SPELL_DAMAGE_CLASS_NONE
:
7947 case SPELL_DAMAGE_CLASS_MAGIC
:
7949 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
7951 // For other schools
7952 else if (GetTypeId() == TYPEID_PLAYER
)
7953 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
7956 crit_chance
= m_baseSpellCritChance
;
7957 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
7960 if (pVictim
&& !IsPositiveSpell(spellProto
->Id
))
7962 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
7963 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
7964 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
7965 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
7966 // Modify by player victim resilience
7967 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
7968 crit_chance
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
);
7970 // scripted (increase crit chance ... against ... target by x%
7971 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7972 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7974 if (!((*i
)->isAffectedOnSpell(spellProto
)))
7976 switch((*i
)->GetModifier()->m_miscvalue
)
7978 case 849: if (pVictim
->isFrozen()) crit_chance
+= 17.0f
; break; //Shatter Rank 1
7979 case 910: if (pVictim
->isFrozen()) crit_chance
+= 34.0f
; break; //Shatter Rank 2
7980 case 911: if (pVictim
->isFrozen()) crit_chance
+= 50.0f
; break; //Shatter Rank 3
7981 case 7917: // Glyph of Shadowburn
7982 if (pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
7983 crit_chance
+=(*i
)->GetModifier()->m_amount
;
7985 case 7997: // Renewed Hope
7987 if (pVictim
->HasAura(6788))
7988 crit_chance
+=(*i
)->GetModifier()->m_amount
;
7990 case 21: // Test of Faith
7993 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
7994 crit_chance
+=(*i
)->GetModifier()->m_amount
;
8002 if (spellProto
->SpellFamilyName
== SPELLFAMILY_PALADIN
&&
8003 spellProto
->SpellFamilyFlags
& 0x0000000040000000LL
)
8005 Aura
*aura
= pVictim
->GetDummyAura(58597);
8006 if (aura
&& aura
->GetCasterGUID() == GetGUID())
8007 crit_chance
+=aura
->GetModifier()->m_amount
;
8012 case SPELL_DAMAGE_CLASS_MELEE
:
8013 case SPELL_DAMAGE_CLASS_RANGED
:
8017 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
8018 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
8026 // only players use intelligence for critical chance computations
8027 if(Player
* modOwner
= GetSpellModOwner())
8028 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
8030 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
8031 if (roll_chance_f(crit_chance
))
8036 uint32
Unit::SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
8038 // Calculate critical bonus
8040 switch(spellProto
->DmgClass
)
8042 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
8043 case SPELL_DAMAGE_CLASS_RANGED
:
8044 // TODO: write here full calculation for melee/ranged spells
8045 crit_bonus
= damage
;
8048 crit_bonus
= damage
/ 2; // for spells is 50%
8052 // adds additional damage to crit_bonus (from talents)
8053 if(Player
* modOwner
= GetSpellModOwner())
8054 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
8058 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8059 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
8063 damage
+= crit_bonus
;
8068 uint32
Unit::SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
8070 // Calculate critical bonus
8072 switch(spellProto
->DmgClass
)
8074 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
8075 case SPELL_DAMAGE_CLASS_RANGED
:
8076 // TODO: write here full calculation for melee/ranged spells
8077 crit_bonus
= damage
;
8080 crit_bonus
= damage
/ 2; // for spells is 50%
8084 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplier(SPELL_AURA_MOD_CRITICAL_HEALING_BONUS
));
8088 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8089 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
8093 damage
+= crit_bonus
;
8098 uint32
Unit::SpellHealingBonus(SpellEntry
const *spellProto
, uint32 healamount
, DamageEffectType damagetype
, Unit
*pVictim
)
8100 // For totems get healing bonus from owner (statue isn't totem in fact)
8101 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
8102 if(Unit
* owner
= GetOwner())
8103 return owner
->SpellHealingBonus(spellProto
, healamount
, damagetype
, pVictim
);
8107 // These Spells are doing fixed amount of healing (TODO found less hack-like check)
8108 if (spellProto
->Id
== 15290 || spellProto
->Id
== 39373 ||
8109 spellProto
->Id
== 33778 || spellProto
->Id
== 379 ||
8110 spellProto
->Id
== 38395 || spellProto
->Id
== 40972)
8113 // Taken/Done total percent damage auras
8114 float DoneTotalMod
= 1.0f
;
8115 float TakenTotalMod
= 1.0f
;
8116 uint32 DoneTotal
= 0;
8117 uint32 TakenTotal
= 0;
8119 // Healing done percent
8120 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
8121 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
8122 DoneTotalMod
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
8124 // done scripted mod (take it from owner)
8125 Unit
*owner
= GetOwner();
8126 if (!owner
) owner
= this;
8127 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8128 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
8130 if (!(*i
)->isAffectedOnSpell(spellProto
))
8132 switch((*i
)->GetModifier()->m_miscvalue
)
8134 case 4415: // Increased Rejuvenation Healing
8136 case 3736: // Hateful Totem of the Third Wind / Increased Lesser Healing Wave / LK Arena (4/5/6) Totem of the Third Wind / Savage Totem of the Third Wind
8137 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
8139 case 7997: // Renewed Hope
8141 if (pVictim
->HasAura(6788))
8142 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
8144 case 21: // Test of Faith
8147 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
8148 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
8150 case 7798: // Glyph of Regrowth
8152 AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_PERIODIC_HEAL
);
8153 for(AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
8155 SpellEntry
const* m_spell
= (*itr
)->GetSpellProto();
8156 if (m_spell
->SpellFamilyName
== SPELLFAMILY_DRUID
&&
8157 m_spell
->SpellFamilyFlags
& 0x0000000000000040LL
)
8159 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8165 case 8477: // Nourish Heal Boost
8167 int32 stepPercent
= (*i
)->GetModifier()->m_amount
;
8168 int32 modPercent
= 0;
8169 AuraMap
const& victimAuras
= pVictim
->GetAuras();
8170 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
8172 if (itr
->second
->GetCasterGUID()!=GetGUID())
8174 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
8175 if ( m_spell
->SpellFamilyName
!= SPELLFAMILY_DRUID
||
8176 !(m_spell
->SpellFamilyFlags
& 0x0000001000000050LL
))
8178 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
8180 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
8183 case 7871: // Glyph of Lesser Healing Wave
8185 AuraList
const& auras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
8186 for(AuraList::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
8188 if ((*itr
)->GetCasterGUID()!=GetGUID())
8190 SpellEntry
const* m_spell
= (*itr
)->GetSpellProto();
8191 if (m_spell
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
8192 m_spell
->SpellFamilyFlags
& 0x0000040000000000LL
)
8194 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8205 int32 DoneAdvertisedBenefit
= SpellBaseHealingBonus(GetSpellSchoolMask(spellProto
));
8206 int32 TakenAdvertisedBenefit
= SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
8207 if (DoneAdvertisedBenefit
!= 0 && TakenAdvertisedBenefit
!=0)
8209 // Healing over Time spells
8210 float DotFactor
= 1.0f
;
8211 if(damagetype
== DOT
)
8213 int32 DotDuration
= GetSpellDuration(spellProto
);
8217 if(DotDuration
> 30000) DotDuration
= 30000;
8218 if(!IsChanneledSpell(spellProto
)) DotFactor
= DotDuration
/ 15000.0f
;
8220 for(int j
= 0; j
< 3; j
++)
8222 if( spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& (
8223 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_HEAL
||
8224 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
) )
8231 if(spellProto
->EffectAmplitude
[x
] != 0)
8232 DotTicks
= DotDuration
/ spellProto
->EffectAmplitude
[x
];
8235 DoneAdvertisedBenefit
/= DotTicks
;
8236 TakenAdvertisedBenefit
/= DotTicks
;
8240 uint32 CastingTime
= GetSpellCastTime(spellProto
);
8242 // distribute healing to all effects, reduce AoE damage
8243 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
8245 // 0% bonus for damage and healing spells for leech spells from healing bonus
8246 for(int j
= 0; j
< 3; ++j
)
8248 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
8249 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
8257 switch (spellProto
->SpellFamilyName
)
8259 case SPELLFAMILY_GENERIC
:
8260 // Healing stream from totem (add 6% per tick from hill bonus owner)
8261 // Possibly need do it on apply dummy aura
8262 if (spellProto
->Id
== 52042)
8265 case SPELLFAMILY_SHAMAN
:
8266 // Earth Shield 30% per charge
8267 if (spellProto
->SpellFamilyFlags
& 0x40000000000LL
)
8270 case SPELLFAMILY_DRUID
:
8272 if (spellProto
->SpellFamilyFlags
& 0x1000000000LL
)
8274 CastingTime
= damagetype
== DOT
? 3500 : 1200;
8275 DotFactor
= damagetype
== DOT
? 0.519f
: 1.0f
;
8277 // Tranquility triggered spell
8278 else if (spellProto
->SpellFamilyFlags
& 0x80LL
)
8281 else if (spellProto
->SpellFamilyFlags
& 0x10LL
)
8284 else if (spellProto
->SpellFamilyFlags
& 0x40LL
)
8286 DotFactor
= damagetype
== DOT
? 0.705f
: 1.0f
;
8287 CastingTime
= damagetype
== DOT
? 3500 : 1010;
8290 case SPELLFAMILY_PRIEST
:
8292 if ((spellProto
->SpellFamilyFlags
& 0x8000000LL
) && spellProto
->SpellIconID
== 1874)
8295 case SPELLFAMILY_PALADIN
:
8296 // Seal and Judgement of Light
8297 if ( spellProto
->SpellFamilyFlags
& 0x100040000LL
)
8300 case SPELLFAMILY_WARRIOR
:
8301 case SPELLFAMILY_ROGUE
:
8302 case SPELLFAMILY_HUNTER
:
8307 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
8309 // Spellmod SpellDamage
8310 float SpellModSpellDamage
= 100.0f
;
8312 if(Player
* modOwner
= GetSpellModOwner())
8313 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
8315 SpellModSpellDamage
/= 100.0f
;
8317 DoneTotal
+= (float)DoneAdvertisedBenefit
* ((float)CastingTime
/ 3500.0f
) * DotFactor
* SpellModSpellDamage
* LvlPenalty
;
8318 TakenTotal
+= (float)TakenAdvertisedBenefit
* ((float)CastingTime
/ 3500.0f
) * DotFactor
* SpellModSpellDamage
* LvlPenalty
;
8321 // use float as more appropriate for negative values and percent applying
8322 float heal
= (healamount
+ DoneTotal
)*DoneTotalMod
;
8323 // apply spellmod to Done amount
8324 if(Player
* modOwner
= GetSpellModOwner())
8325 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
8328 // Healing Wave cast
8329 if (spellProto
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& spellProto
->SpellFamilyFlags
& 0x0000000000000040LL
)
8331 // Search for Healing Way on Victim
8332 Unit::AuraList
const& auraDummy
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
8333 for(Unit::AuraList::const_iterator itr
= auraDummy
.begin(); itr
!=auraDummy
.end(); ++itr
)
8334 if((*itr
)->GetId() == 29203)
8335 TakenTotalMod
*= (*itr
)->GetModifier()->m_amount
;
8338 // Healing taken percent
8339 float minval
= pVictim
->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
8341 TakenTotalMod
*= (100.0f
+ minval
) / 100.0f
;
8343 float maxval
= pVictim
->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
8345 TakenTotalMod
*= (100.0f
+ maxval
) / 100.0f
;
8347 AuraList
const& mHealingGet
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING_RECEIVED
);
8348 for(AuraList::const_iterator i
= mHealingGet
.begin(); i
!= mHealingGet
.end(); ++i
)
8349 if ((*i
)->isAffectedOnSpell(spellProto
))
8350 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
8352 heal
= (heal
+ TakenTotal
) * TakenTotalMod
;
8354 return heal
< 0 ? 0 : uint32(heal
);
8357 int32
Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask
)
8359 int32 AdvertisedBenefit
= 0;
8361 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
8362 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
8363 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
8364 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8366 // Healing bonus of spirit, intellect and strength
8367 if (GetTypeId() == TYPEID_PLAYER
)
8370 AdvertisedBenefit
+=((Player
*)this)->GetBaseSpellHealingBonus();
8372 // Healing bonus from stats
8373 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
8374 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
8376 // stat used dependent from misc value (stat index)
8377 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
8378 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
8381 // ... and attack power
8382 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
8383 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
8384 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
8385 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
8387 return AdvertisedBenefit
;
8390 int32
Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
8392 int32 AdvertisedBenefit
= 0;
8393 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING
);
8394 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
8395 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
8396 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8397 return AdvertisedBenefit
;
8400 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
)
8402 //If m_immuneToSchool type contain this school type, IMMUNE damage.
8403 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
8404 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
8405 if(itr
->type
& shoolMask
)
8408 //If m_immuneToDamage type contain magic, IMMUNE damage.
8409 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
8410 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
8411 if(itr
->type
& shoolMask
)
8417 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
)
8422 //FIX ME this hack: don't get feared if stunned
8423 if (spellInfo
->Mechanic
== MECHANIC_FEAR
)
8425 if ( hasUnitState(UNIT_STAT_STUNNED
) )
8429 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
8430 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
8431 if(itr
->type
== spellInfo
->Dispel
)
8434 if( !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
) && // unaffected by school immunity
8435 !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)) // can remove immune (by dispell or immune it)
8437 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
8438 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
8439 if( !(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
8440 (itr
->type
& GetSpellSchoolMask(spellInfo
)) )
8444 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
8445 for(SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
8447 if(itr
->type
== spellInfo
->Mechanic
)
8456 bool Unit::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, uint32 index
) const
8458 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
8459 uint32 effect
= spellInfo
->Effect
[index
];
8460 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
8461 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
8462 if(itr
->type
== effect
)
8465 if(uint32 mechanic
= spellInfo
->EffectMechanic
[index
])
8467 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
8468 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
8469 if(itr
->type
== mechanic
)
8473 if(uint32 aura
= spellInfo
->EffectApplyAuraName
[index
])
8475 SpellImmuneList
const& list
= m_spellImmune
[IMMUNITY_STATE
];
8476 for(SpellImmuneList::const_iterator itr
= list
.begin(); itr
!= list
.end(); ++itr
)
8477 if(itr
->type
== aura
)
8479 // Check for immune to application of harmful magical effects
8480 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL
);
8481 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
8482 if (spellInfo
->Dispel
== DISPEL_MAGIC
&& // Magic debuff
8483 ((*iter
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellInfo
)) && // Check school
8484 !IsPositiveEffect(spellInfo
->Id
, index
)) // Harmful
8491 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
8496 uint32 family
= spellInfo
->SpellFamilyName
;
8497 uint64 flags
= spellInfo
->SpellFamilyFlags
;
8499 if((family
== 5 && flags
== 256) || //Searing Pain
8500 (family
== 6 && flags
== 8192) || //Mind Blast
8501 (family
== 11 && flags
== 1048576)) //Earth Shock
8507 void Unit::MeleeDamageBonus(Unit
*pVictim
, uint32
*pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
)
8515 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8517 // Taken/Done fixed damage bonus auras
8518 int32 DoneFlatBenefit
= 0;
8519 int32 TakenFlatBenefit
= 0;
8521 // ..done (for creature type by mask) in taken
8522 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
8523 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
8524 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8525 DoneFlatBenefit
+= (*i
)->GetModifier()->m_amount
;
8528 // SPELL_AURA_MOD_DAMAGE_DONE included in weapon damage
8530 // ..done (base at attack power for marked target and base at attack power for creature type)
8532 if(attType
== RANGED_ATTACK
)
8534 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
8536 // ..done (base at attack power and creature type)
8537 AuraList
const& mCreatureAttackPower
= GetAurasByType(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
);
8538 for(AuraList::const_iterator i
= mCreatureAttackPower
.begin();i
!= mCreatureAttackPower
.end(); ++i
)
8539 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8540 APbonus
+= (*i
)->GetModifier()->m_amount
;
8544 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
8546 // ..done (base at attack power and creature type)
8547 AuraList
const& mCreatureAttackPower
= GetAurasByType(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
);
8548 for(AuraList::const_iterator i
= mCreatureAttackPower
.begin();i
!= mCreatureAttackPower
.end(); ++i
)
8549 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8550 APbonus
+= (*i
)->GetModifier()->m_amount
;
8553 if (APbonus
!=0) // Can be negative
8555 bool normalized
= false;
8558 for (uint8 i
= 0; i
<3;i
++)
8560 if (spellProto
->Effect
[i
] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG
)
8568 DoneFlatBenefit
+= int32(APbonus
/14.0f
* GetAPMultiplier(attType
,normalized
));
8572 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
8573 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
8574 if((*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask())
8575 TakenFlatBenefit
+= (*i
)->GetModifier()->m_amount
;
8577 if(attType
!=RANGED_ATTACK
)
8578 TakenFlatBenefit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
8580 TakenFlatBenefit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
8582 // Done/Taken total percent damage auras
8583 float DoneTotalMod
= 1;
8584 float TakenTotalMod
= 1;
8587 // SPELL_AURA_MOD_DAMAGE_PERCENT_DONE included in weapon damage
8588 // SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT included in weapon damage
8590 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
8591 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
8592 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8593 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8596 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
8597 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
8598 if((*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask())
8599 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8601 // .. taken pct: dummy auras
8602 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
8603 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
8605 switch((*i
)->GetSpellProto()->SpellIconID
)
8609 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
8611 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
8613 float mod
= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
8614 if (mod
< (*i
)->GetModifier()->m_amount
)
8615 mod
= (*i
)->GetModifier()->m_amount
;
8616 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
8621 if(spellProto
==NULL
)
8623 // Should increase Shred (initial Damage of Lacerate and Rake handled in Spell::EffectSchoolDMG)
8624 if(spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& (spellProto
->SpellFamilyFlags
==0x00008000LL
))
8625 TakenTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8630 // .. taken pct: class scripts
8631 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8632 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
8634 switch((*i
)->GetMiscValue())
8636 case 6427: case 6428: // Dirty Deeds
8637 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8639 Aura
* eff0
= GetAura((*i
)->GetId(),0);
8640 if(!eff0
|| (*i
)->GetEffIndex()!=1)
8642 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
8646 // effect 0 have expected value but in negative state
8647 TakenTotalMod
*= (-eff0
->GetModifier()->m_amount
+100.0f
)/100.0f
;
8653 if(attType
!= RANGED_ATTACK
)
8655 AuraList
const& mModMeleeDamageTakenPercent
= pVictim
->GetAurasByType(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
8656 for(AuraList::const_iterator i
= mModMeleeDamageTakenPercent
.begin(); i
!= mModMeleeDamageTakenPercent
.end(); ++i
)
8657 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8661 AuraList
const& mModRangedDamageTakenPercent
= pVictim
->GetAurasByType(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
8662 for(AuraList::const_iterator i
= mModRangedDamageTakenPercent
.begin(); i
!= mModRangedDamageTakenPercent
.end(); ++i
)
8663 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8666 float tmpDamage
= float(int32(*pdamage
) + DoneFlatBenefit
) * DoneTotalMod
;
8668 // apply spellmod to Done damage
8671 if(Player
* modOwner
= GetSpellModOwner())
8672 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_DAMAGE
, tmpDamage
);
8675 tmpDamage
= (tmpDamage
+ TakenFlatBenefit
)*TakenTotalMod
;
8677 // bonus result can be negative
8678 *pdamage
= tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
8681 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
8685 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
8688 if(itr
->type
== type
)
8690 m_spellImmune
[op
].erase(itr
);
8691 next
= m_spellImmune
[op
].begin();
8695 Immune
.spellId
= spellId
;
8697 m_spellImmune
[op
].push_back(Immune
);
8701 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
8703 if(itr
->spellId
== spellId
)
8705 m_spellImmune
[op
].erase(itr
);
8713 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
8715 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
8717 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
8718 RemoveAurasWithDispelType(type
);
8721 float Unit::GetWeaponProcChance() const
8723 // normalized proc chance for weapon attack speed
8725 if(isAttackReady(BASE_ATTACK
))
8726 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
8727 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
8728 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
8732 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
8734 // proc per minute chance calculation
8735 if (PPM
<= 0) return 0.0f
;
8736 uint32 result
= uint32((WeaponSpeed
* PPM
) / 600.0f
); // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
8740 void Unit::Mount(uint32 mount
)
8745 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
8747 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
8749 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
8752 if(GetTypeId() == TYPEID_PLAYER
)
8754 Pet
* pet
= GetPet();
8757 if(pet
->isControlled())
8759 ((Player
*)this)->SetTemporaryUnsummonedPetNumber(pet
->GetCharmInfo()->GetPetNumber());
8760 ((Player
*)this)->SetOldPetSpell(pet
->GetUInt32Value(UNIT_CREATED_BY_SPELL
));
8763 ((Player
*)this)->RemovePet(NULL
,PET_SAVE_NOT_IN_SLOT
);
8766 ((Player
*)this)->SetTemporaryUnsummonedPetNumber(0);
8770 void Unit::Unmount()
8775 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
8777 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
8778 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
8780 // only resummon old pet if the player is already added to a map
8781 // this prevents adding a pet to a not created map which would otherwise cause a crash
8782 // (it could probably happen when logging in after a previous crash)
8783 if(GetTypeId() == TYPEID_PLAYER
&& IsInWorld() && ((Player
*)this)->GetTemporaryUnsummonedPetNumber() && isAlive())
8785 Pet
* NewPet
= new Pet
;
8786 if(!NewPet
->LoadPetFromDB((Player
*)this, 0, ((Player
*)this)->GetTemporaryUnsummonedPetNumber(), true))
8789 ((Player
*)this)->SetTemporaryUnsummonedPetNumber(0);
8793 void Unit::SetInCombatWith(Unit
* enemy
)
8795 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
8798 SetInCombatState(true);
8803 if(eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
8805 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
8806 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
8808 SetInCombatState(true);
8812 SetInCombatState(false);
8815 void Unit::SetInCombatState(bool PvP
)
8817 // only alive units can be in combat
8822 m_CombatTimer
= 5000;
8823 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
8825 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
8826 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
8829 void Unit::ClearInCombat()
8832 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
8834 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
8835 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
8837 // Player's state will be cleared in Player::UpdateContestedPvP
8838 if(GetTypeId()!=TYPEID_PLAYER
)
8839 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
8842 bool Unit::isTargetableForAttack() const
8844 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
8847 if(HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
8850 return isAlive() && !hasUnitState(UNIT_STAT_DIED
)&& !isInFlight() /*&& !isStealth()*/;
8853 int32
Unit::ModifyHealth(int32 dVal
)
8860 int32 curHealth
= (int32
)GetHealth();
8862 int32 val
= dVal
+ curHealth
;
8869 int32 maxHealth
= (int32
)GetMaxHealth();
8874 gain
= val
- curHealth
;
8876 else if(curHealth
!= maxHealth
)
8878 SetHealth(maxHealth
);
8879 gain
= maxHealth
- curHealth
;
8885 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
8892 int32 curPower
= (int32
)GetPower(power
);
8894 int32 val
= dVal
+ curPower
;
8901 int32 maxPower
= (int32
)GetMaxPower(power
);
8905 SetPower(power
,val
);
8906 gain
= val
- curPower
;
8908 else if(curPower
!= maxPower
)
8910 SetPower(power
,maxPower
);
8911 gain
= maxPower
- curPower
;
8917 bool Unit::isVisibleForOrDetect(Unit
const* u
, bool detect
, bool inVisibleList
, bool is3dDistance
) const
8922 // Always can see self
8926 // player visible for other player if not logout and at same transport
8927 // including case when player is out of world
8928 bool at_same_transport
=
8929 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
8930 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
8931 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
8932 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
8935 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
8938 // forbidden to seen (at GM respawn command)
8939 if(m_Visibility
==VISIBILITY_RESPAWN
)
8942 // always seen by owner
8943 if(GetCharmerOrOwnerGUID()==u
->GetGUID())
8946 // Grid dead/alive checks
8947 if( u
->GetTypeId()==TYPEID_PLAYER
)
8949 // non visible at grid for any stealth state
8950 if(!IsVisibleInGridForPlayer((Player
*)u
))
8953 // if player is dead then he can't detect anyone in any cases
8959 // all dead creatures/players not visible for any creatures
8960 if(!u
->isAlive() || !isAlive())
8964 // different visible distance checks
8965 if(u
->isInFlight()) // what see player in flight
8967 // use object grey distance for all (only see objects any way)
8968 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
8971 else if(!isAlive()) // distance for show body
8973 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
8976 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
8978 if(u
->GetTypeId()==TYPEID_PLAYER
)
8980 // Players far than max visible distance for player or not in our map are not visible too
8981 if (!at_same_transport
&& !IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForPlayer()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8986 // Units far than max visible distance for creature or not in our map are not visible too
8987 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForCreature()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8991 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
8993 // Pet/charmed far than max visible distance for player or not in our map are not visible too
8994 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForPlayer()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8997 else // distance for show creature
8999 // Units far than max visible distance for creature or not in our map are not visible too
9000 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForCreature()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
9004 // Visible units, always are visible for all units, except for units under invisibility
9005 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0)
9008 // GMs see any players, not higher GMs and all units
9009 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
9011 if(GetTypeId() == TYPEID_PLAYER
)
9012 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
9017 // non faction visibility non-breakable for non-GMs
9018 if (m_Visibility
== VISIBILITY_OFF
)
9022 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
9024 // detectable invisibility case
9026 // Invisible units, always are visible for units under same invisibility type
9027 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
9028 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
9029 u
->canDetectInvisibilityOf(this) ||
9030 // Units that can detect invisibility always are visible for units that can be detected
9031 canDetectInvisibilityOf(u
) ))
9036 // special cases for always overwrite invisibility/stealth
9037 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
9040 if (!u
->IsHostileTo(this))
9042 // 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)
9043 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
9045 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
9048 // else apply same rules as for hostile case (detecting check for stealth)
9054 // Hunter mark functionality
9055 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
9056 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
9057 if((*iter
)->GetCasterGUID()==u
->GetGUID())
9060 // else apply detecting check for stealth
9063 // none other cases for detect invisibility, so invisible
9067 // else apply stealth detecting check
9070 // unit got in stealth in this moment and must ignore old detected state
9071 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
9074 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
9075 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
9078 // NOW ONLY STEALTH CASE
9080 // stealth and detected and visible for some seconds
9081 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->m_DetectInvTimer
> 300 && ((Player
*)u
)->HaveAtClient(this))
9084 //if in non-detect mode then invisible for unit
9090 // If is attacked then stealth is lost, some creature can use stealth too
9091 if( !getAttackers().empty() )
9094 // If there is collision rogue is seen regardless of level difference
9095 // TODO: check sizes in DB
9096 float distance
= GetDistance(u
);
9097 if (distance
< 0.24f
)
9100 //If a mob or player is stunned he will not be able to detect stealth
9101 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
9104 // Creature can detect target only in aggro radius
9105 if(u
->GetTypeId() != TYPEID_PLAYER
)
9107 //Always invisible from back and out of aggro range
9108 bool isInFront
= u
->isInFront(this,((Creature
const*)u
)->GetAttackDistance(this));
9114 //Always invisible from back
9115 bool isInFront
= u
->isInFront(this,(GetTypeId()==TYPEID_PLAYER
|| GetCharmerOrOwnerGUID()) ? World::GetMaxVisibleDistanceForPlayer() : World::GetMaxVisibleDistanceForCreature());
9120 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
9121 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
9123 //Calculation if target is in front
9125 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
9126 float visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
9128 //Visible distance is modified by
9129 //-Level Diff (every level diff = 1.0f in visible distance)
9130 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
9132 //This allows to check talent tree and will add addition stealth dependent on used points)
9133 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
9137 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
9138 //based on wowwiki every 5 mod we have 1 more level diff in calculation
9139 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_DETECT
)) - stealthMod
)/5.0f
;
9141 if(distance
> visibleDistance
)
9145 // Now check is target visible with LoS
9147 u
->GetPosition(ox
,oy
,oz
);
9148 return IsWithinLOS(ox
,oy
,oz
);
9151 void Unit::SetVisibility(UnitVisibility x
)
9159 if(GetTypeId()==TYPEID_PLAYER
)
9160 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
9162 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
9166 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
9168 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
9170 for(uint32 i
= 0; i
< 10; ++i
)
9172 if(((1 << i
) & mask
)==0)
9175 // find invisibility level
9176 uint32 invLevel
= 0;
9177 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
9178 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
9179 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
9180 invLevel
= (*itr
)->GetModifier()->m_amount
;
9182 // find invisibility detect level
9183 uint32 detectLevel
= 0;
9184 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
9185 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
9186 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
9187 detectLevel
= (*itr
)->GetModifier()->m_amount
;
9189 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
9191 detectLevel
= ((Player
*)this)->GetDrunkValue();
9194 if(invLevel
<= detectLevel
)
9202 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
)
9204 int32 main_speed_mod
= 0;
9205 float stack_bonus
= 1.0f
;
9206 float non_stack_bonus
= 1.0f
;
9214 if (IsMounted()) // Use on mount auras
9216 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
9217 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
9218 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
9222 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
9223 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
9224 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
9232 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
9235 case MOVE_SWIM_BACK
:
9239 if (IsMounted()) // Use on mount auras
9240 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
);
9241 else // Use not mount (shapeshift for example) auras (should stack)
9242 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT
);
9243 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS
);
9244 non_stack_bonus
= (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
))/100.0f
;
9247 case MOVE_FLIGHT_BACK
:
9250 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
9254 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
9255 // now we ready for speed calculation
9256 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
9264 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
9265 // TODO: possible affect only on MOVE_RUN
9266 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
9268 // Use speed from aura
9269 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
9270 if (speed
> max_speed
)
9279 // Apply strongest slow aura mod to speed
9280 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
9282 speed
*=(100.0f
+ slow
)/100.0f
;
9283 SetSpeed(mtype
, speed
, forced
);
9286 float Unit::GetSpeed( UnitMoveType mtype
) const
9288 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
9291 void Unit::SetSpeed(UnitMoveType mtype
, float rate
, bool forced
)
9296 // Update speed only on change
9297 if (m_speed_rate
[mtype
] == rate
)
9300 m_speed_rate
[mtype
] = rate
;
9302 propagateSpeedChange();
9310 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9313 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9316 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9319 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9321 case MOVE_SWIM_BACK
:
9322 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9324 case MOVE_TURN_RATE
:
9325 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+2+4+4+4+4+4+4+4);
9328 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9330 case MOVE_FLIGHT_BACK
:
9331 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9333 case MOVE_PITCH_RATE
:
9334 data
.Initialize(MSG_MOVE_SET_PITCH_RATE
, 8+4+2+4+4+4+4+4+4+4);
9337 sLog
.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype
);
9341 data
.append(GetPackGUID());
9342 data
<< uint32(0); // movement flags
9343 data
<< uint16(0); // unk flags
9344 data
<< uint32(getMSTime());
9345 data
<< float(GetPositionX());
9346 data
<< float(GetPositionY());
9347 data
<< float(GetPositionZ());
9348 data
<< float(GetOrientation());
9349 data
<< uint32(0); // fall time
9350 data
<< float(GetSpeed(mtype
));
9351 SendMessageToSet( &data
, true );
9355 if(GetTypeId() == TYPEID_PLAYER
)
9357 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
9358 // and do it only for real sent packets and use run for run/mounted as client expected
9359 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
9365 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
9368 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
9371 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
9374 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
9376 case MOVE_SWIM_BACK
:
9377 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
9379 case MOVE_TURN_RATE
:
9380 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
9383 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
9385 case MOVE_FLIGHT_BACK
:
9386 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
9388 case MOVE_PITCH_RATE
:
9389 data
.Initialize(SMSG_FORCE_PITCH_RATE_CHANGE
, 16);
9392 sLog
.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype
);
9395 data
.append(GetPackGUID());
9396 data
<< (uint32
)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
9397 if (mtype
== MOVE_RUN
)
9398 data
<< uint8(0); // new 2.1.0
9399 data
<< float(GetSpeed(mtype
));
9400 SendMessageToSet( &data
, true );
9402 if(Pet
* pet
= GetPet())
9403 pet
->SetSpeed(MOVE_RUN
, m_speed_rate
[mtype
],forced
);
9406 void Unit::SetHover(bool on
)
9409 CastSpell(this,11010,true);
9411 RemoveAurasDueToSpell(11010);
9414 void Unit::setDeathState(DeathState s
)
9416 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
9420 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
9422 if(IsNonMeleeSpellCasted(false))
9423 InterruptNonMeleeSpells(false);
9428 RemoveAllAurasOnDeath();
9429 UnsummonAllTotems();
9431 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
9432 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
9433 // remove aurastates allowing special moves
9434 ClearAllReactives();
9435 ClearDiminishings();
9437 else if(s
== JUST_ALIVED
)
9439 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
9442 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
9444 //_ApplyAllAuraMods();
9449 /*########################################
9451 ######## AGGRO SYSTEM ########
9453 ########################################*/
9454 bool Unit::CanHaveThreatList() const
9456 // only creatures can have threat list
9457 if( GetTypeId() != TYPEID_UNIT
)
9460 // only alive units can have threat list
9464 // totems can not have threat list
9465 if( ((Creature
*)this)->isTotem() )
9468 // vehicles can not have threat list
9469 if( ((Creature
*)this)->isVehicle() )
9472 // pets can not have a threat list, unless they are controlled by a creature
9473 if( ((Creature
*)this)->isPet() && IS_PLAYER_GUID(((Pet
*)this)->GetOwnerGUID()) )
9479 //======================================================================
9481 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
9483 if(!HasAuraType(SPELL_AURA_MOD_THREAT
))
9486 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
9488 return threat
* m_threatModifier
[school
];
9491 //======================================================================
9493 void Unit::AddThreat(Unit
* pVictim
, float threat
, SpellSchoolMask schoolMask
, SpellEntry
const *threatSpell
)
9495 // Only mobs can manage threat lists
9496 if(CanHaveThreatList())
9497 m_ThreatManager
.addThreat(pVictim
, threat
, schoolMask
, threatSpell
);
9500 //======================================================================
9502 void Unit::DeleteThreatList()
9504 m_ThreatManager
.clearReferences();
9507 //======================================================================
9509 void Unit::TauntApply(Unit
* taunter
)
9511 assert(GetTypeId()== TYPEID_UNIT
);
9513 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
9516 if(!CanHaveThreatList())
9519 Unit
*target
= getVictim();
9520 if(target
&& target
== taunter
)
9523 SetInFront(taunter
);
9524 if (((Creature
*)this)->AI())
9525 ((Creature
*)this)->AI()->AttackStart(taunter
);
9527 m_ThreatManager
.tauntApply(taunter
);
9530 //======================================================================
9532 void Unit::TauntFadeOut(Unit
*taunter
)
9534 assert(GetTypeId()== TYPEID_UNIT
);
9536 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
9539 if(!CanHaveThreatList())
9542 Unit
*target
= getVictim();
9543 if(!target
|| target
!= taunter
)
9546 if(m_ThreatManager
.isThreatListEmpty())
9548 if(((Creature
*)this)->AI())
9549 ((Creature
*)this)->AI()->EnterEvadeMode();
9553 m_ThreatManager
.tauntFadeOut(taunter
);
9554 target
= m_ThreatManager
.getHostilTarget();
9556 if (target
&& target
!= taunter
)
9559 if (((Creature
*)this)->AI())
9560 ((Creature
*)this)->AI()->AttackStart(target
);
9564 //======================================================================
9566 bool Unit::SelectHostilTarget()
9568 //function provides main threat functionality
9569 //next-victim-selection algorithm and evade mode are called
9570 //threat list sorting etc.
9572 assert(GetTypeId()== TYPEID_UNIT
);
9574 if (!this->isAlive())
9576 //This function only useful once AI has been initialized
9577 if (!((Creature
*)this)->AI())
9580 Unit
* target
= NULL
;
9582 // First checking if we have some taunt on us
9583 const AuraList
& tauntAuras
= GetAurasByType(SPELL_AURA_MOD_TAUNT
);
9584 if ( !tauntAuras
.empty() )
9588 // The last taunt aura caster is alive an we are happy to attack him
9589 if ( (caster
= tauntAuras
.back()->GetCaster()) && caster
->isAlive() )
9591 else if (tauntAuras
.size() > 1)
9593 // We do not have last taunt aura caster but we have more taunt auras,
9594 // so find first available target
9596 // Auras are pushed_back, last caster will be on the end
9597 AuraList::const_iterator aura
= --tauntAuras
.end();
9601 if ( (caster
= (*aura
)->GetCaster()) &&
9602 caster
->IsInMap(this) && caster
->isTargetableForAttack() && caster
->isInAccessablePlaceFor((Creature
*)this) )
9607 }while (aura
!= tauntAuras
.begin());
9611 if ( !target
&& !m_ThreatManager
.isThreatListEmpty() )
9612 // No taunt aura or taunt aura caster is dead standart target selection
9613 target
= m_ThreatManager
.getHostilTarget();
9617 if(!hasUnitState(UNIT_STAT_STUNNED
))
9619 ((Creature
*)this)->AI()->AttackStart(target
);
9623 // no target but something prevent go to evade mode
9624 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
9627 // last case when creature don't must go to evade mode:
9628 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
9629 // for example at owner command to pet attack some far away creature
9630 // Note: creature not have targeted movement generator but have attacker in this case
9631 if( GetMotionMaster()->GetCurrentMovementGeneratorType() != TARGETED_MOTION_TYPE
)
9633 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
9635 if( (*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this) )
9640 // enter in evade mode in other case
9641 ((Creature
*)this)->AI()->EnterEvadeMode();
9646 //======================================================================
9647 //======================================================================
9648 //======================================================================
9650 int32
Unit::CalculateSpellDamage(SpellEntry
const* spellProto
, uint8 effect_index
, int32 effBasePoints
, Unit
const* target
)
9652 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
9654 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
9656 int32 level
= int32(getLevel());
9657 if (level
> (int32
)spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
9658 level
= (int32
)spellProto
->maxLevel
;
9659 else if (level
< (int32
)spellProto
->baseLevel
)
9660 level
= (int32
)spellProto
->baseLevel
;
9661 level
-= (int32
)spellProto
->spellLevel
;
9663 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
9664 float randomPointsPerLevel
= spellProto
->EffectDicePerLevel
[effect_index
];
9665 int32 basePoints
= int32(effBasePoints
+ level
* basePointsPerLevel
);
9666 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
] + level
* randomPointsPerLevel
);
9667 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
9669 // range can have possitive and negative values, so order its for irand
9670 int32 randvalue
= int32(spellProto
->EffectBaseDice
[effect_index
]) >= randomPoints
9671 ? irand(randomPoints
, int32(spellProto
->EffectBaseDice
[effect_index
]))
9672 : irand(int32(spellProto
->EffectBaseDice
[effect_index
]), randomPoints
);
9674 int32 value
= basePoints
+ randvalue
;
9676 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
9677 value
+= (int32
)(comboDamage
* comboPoints
);
9679 if(Player
* modOwner
= GetSpellModOwner())
9681 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_ALL_EFFECTS
, value
);
9682 switch(effect_index
)
9685 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT1
, value
);
9688 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT2
, value
);
9691 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT3
, value
);
9696 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
9697 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
9698 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
)
9699 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
9704 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, uint8 effect_index
, Unit
const* target
)
9706 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
9708 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
9710 int32 minduration
= GetSpellDuration(spellProto
);
9711 int32 maxduration
= GetSpellMaxDuration(spellProto
);
9715 if( minduration
!= -1 && minduration
!= maxduration
)
9716 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
9718 duration
= minduration
;
9722 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
9723 // Find total mod value (negative bonus)
9724 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
9725 // Modify from SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL aura (stack always ?)
9726 durationMod_always
+=target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
, spellProto
->Dispel
);
9727 // Find max mod (negative bonus)
9728 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
9730 int32 durationMod
= 0;
9731 // Select strongest negative mod
9732 if (durationMod_always
> durationMod_not_stack
)
9733 durationMod
= durationMod_not_stack
;
9735 durationMod
= durationMod_always
;
9737 if (durationMod
!= 0)
9738 duration
= int32(int64(duration
) * (100+durationMod
) /100);
9740 if (duration
< 0) duration
= 0;
9746 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
9748 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
9750 if(i
->DRGroup
!= group
)
9754 return DIMINISHING_LEVEL_1
;
9757 return DIMINISHING_LEVEL_1
;
9759 // If last spell was casted more than 15 seconds ago - reset the count.
9760 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
9762 i
->hitCount
= DIMINISHING_LEVEL_1
;
9763 return DIMINISHING_LEVEL_1
;
9765 // or else increase the count.
9768 return DiminishingLevels(i
->hitCount
);
9771 return DIMINISHING_LEVEL_1
;
9774 void Unit::IncrDiminishing(DiminishingGroup group
)
9776 // Checking for existing in the table
9777 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
9779 if(i
->DRGroup
!= group
)
9781 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
9785 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
9788 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
)
9790 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
9793 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
9794 if(duration
> 10000 && IsDiminishingReturnsGroupDurationLimited(group
))
9796 // test pet/charm masters instead pets/charmeds
9797 Unit
const* targetOwner
= GetCharmerOrOwner();
9798 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
9800 Unit
const* target
= targetOwner
? targetOwner
: this;
9801 Unit
const* source
= casterOwner
? casterOwner
: caster
;
9803 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
9809 // Some diminishings applies to mobs too (for example, Stun)
9810 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
9812 DiminishingLevels diminish
= Level
;
9815 case DIMINISHING_LEVEL_1
: break;
9816 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
9817 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
9818 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
9823 duration
= int32(duration
* mod
);
9826 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
9828 // Checking for existing in the table
9829 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
9831 if(i
->DRGroup
!= group
)
9839 // Remember time after last aura from group removed
9841 i
->hitTime
= getMSTime();
9847 Unit
* Unit::GetUnit(WorldObject
& object
, uint64 guid
)
9849 return ObjectAccessor::GetUnit(object
,guid
);
9852 bool Unit::isVisibleForInState( Player
const* u
, bool inVisibleList
) const
9854 return isVisibleForOrDetect(u
, false, inVisibleList
, false);
9857 uint32
Unit::GetCreatureType() const
9859 if(GetTypeId() == TYPEID_PLAYER
)
9861 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(((Player
*)this)->m_form
);
9862 if(ssEntry
&& ssEntry
->creatureType
> 0)
9863 return ssEntry
->creatureType
;
9865 return CREATURE_TYPE_HUMANOID
;
9868 return ((Creature
*)this)->GetCreatureInfo()->type
;
9871 /*#######################################
9873 ######## STAT SYSTEM ########
9875 #######################################*/
9877 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
9879 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
9881 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
9887 switch(modifierType
)
9891 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
9895 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
9898 val
= (100.0f
+ amount
) / 100.0f
;
9899 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
9906 if(!CanModifyStats())
9911 case UNIT_MOD_STAT_STRENGTH
:
9912 case UNIT_MOD_STAT_AGILITY
:
9913 case UNIT_MOD_STAT_STAMINA
:
9914 case UNIT_MOD_STAT_INTELLECT
:
9915 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
9917 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
9918 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
9922 case UNIT_MOD_FOCUS
:
9923 case UNIT_MOD_ENERGY
:
9924 case UNIT_MOD_HAPPINESS
:
9926 case UNIT_MOD_RUNIC_POWER
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
9928 case UNIT_MOD_RESISTANCE_HOLY
:
9929 case UNIT_MOD_RESISTANCE_FIRE
:
9930 case UNIT_MOD_RESISTANCE_NATURE
:
9931 case UNIT_MOD_RESISTANCE_FROST
:
9932 case UNIT_MOD_RESISTANCE_SHADOW
:
9933 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
9935 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
9936 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
9938 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
9939 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
9940 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
9949 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
9951 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
9953 sLog
.outError("ERROR: trial to access non existed modifier value from UnitMods!");
9957 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
9960 return m_auraModifiersGroup
[unitMod
][modifierType
];
9963 float Unit::GetTotalStatValue(Stats stat
) const
9965 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
9967 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
9970 // value = ((base_value * base_pct) + total_value) * total_pct
9971 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
9972 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
9973 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
9974 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
9979 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
9981 if(unitMod
>= UNIT_MOD_END
)
9983 sLog
.outError("ERROR: trial to access non existed UnitMods in GetTotalAuraModValue()!");
9987 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
9990 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
9991 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
9992 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
9993 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
9998 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
10000 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
10004 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
10005 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
10006 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
10007 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
10008 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
10009 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
10018 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
10020 Stats stat
= STAT_STRENGTH
;
10024 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
10025 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
10026 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
10027 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
10028 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
10037 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
10041 case UNIT_MOD_MANA
: return POWER_MANA
;
10042 case UNIT_MOD_RAGE
: return POWER_RAGE
;
10043 case UNIT_MOD_FOCUS
: return POWER_FOCUS
;
10044 case UNIT_MOD_ENERGY
: return POWER_ENERGY
;
10045 case UNIT_MOD_HAPPINESS
: return POWER_HAPPINESS
;
10046 case UNIT_MOD_RUNE
: return POWER_RUNE
;
10047 case UNIT_MOD_RUNIC_POWER
:return POWER_RUNIC_POWER
;
10053 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
10055 UnitMods unitMod
= (attType
== RANGED_ATTACK
) ? UNIT_MOD_ATTACK_POWER_RANGED
: UNIT_MOD_ATTACK_POWER
;
10057 float val
= GetTotalAuraModValue(unitMod
);
10064 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
10066 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
10069 return m_weaponDamage
[attType
][type
];
10072 void Unit::SetLevel(uint32 lvl
)
10074 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
10077 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
10078 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
10081 void Unit::SetHealth(uint32 val
)
10083 uint32 maxHealth
= GetMaxHealth();
10084 if(maxHealth
< val
)
10087 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
10090 if(GetTypeId() == TYPEID_PLAYER
)
10092 if(((Player
*)this)->GetGroup())
10093 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
10095 else if(((Creature
*)this)->isPet())
10097 Pet
*pet
= ((Pet
*)this);
10098 if(pet
->isControlled())
10100 Unit
*owner
= GetOwner();
10101 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10102 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
10107 void Unit::SetMaxHealth(uint32 val
)
10109 uint32 health
= GetHealth();
10110 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
10113 if(GetTypeId() == TYPEID_PLAYER
)
10115 if(((Player
*)this)->GetGroup())
10116 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
10118 else if(((Creature
*)this)->isPet())
10120 Pet
*pet
= ((Pet
*)this);
10121 if(pet
->isControlled())
10123 Unit
*owner
= GetOwner();
10124 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10125 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP
);
10133 void Unit::SetPower(Powers power
, uint32 val
)
10135 if(GetPower(power
) == val
)
10138 uint32 maxPower
= GetMaxPower(power
);
10142 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
10144 WorldPacket
data(SMSG_POWER_UPDATE
);
10145 data
.append(GetPackGUID());
10146 data
<< uint8(power
);
10147 data
<< uint32(val
);
10148 SendMessageToSet(&data
, GetTypeId() == TYPEID_PLAYER
? true : false);
10151 if(GetTypeId() == TYPEID_PLAYER
)
10153 if(((Player
*)this)->GetGroup())
10154 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
10156 else if(((Creature
*)this)->isPet())
10158 Pet
*pet
= ((Pet
*)this);
10159 if(pet
->isControlled())
10161 Unit
*owner
= GetOwner();
10162 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10163 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
10166 // Update the pet's character sheet with happiness damage bonus
10167 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
10169 pet
->UpdateDamagePhysical(BASE_ATTACK
);
10174 void Unit::SetMaxPower(Powers power
, uint32 val
)
10176 uint32 cur_power
= GetPower(power
);
10177 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
10180 if(GetTypeId() == TYPEID_PLAYER
)
10182 if(((Player
*)this)->GetGroup())
10183 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
10185 else if(((Creature
*)this)->isPet())
10187 Pet
*pet
= ((Pet
*)this);
10188 if(pet
->isControlled())
10190 Unit
*owner
= GetOwner();
10191 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10192 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
10196 if(val
< cur_power
)
10197 SetPower(power
, val
);
10200 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
10202 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
10205 if(GetTypeId() == TYPEID_PLAYER
)
10207 if(((Player
*)this)->GetGroup())
10208 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
10210 else if(((Creature
*)this)->isPet())
10212 Pet
*pet
= ((Pet
*)this);
10213 if(pet
->isControlled())
10215 Unit
*owner
= GetOwner();
10216 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10217 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
10222 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
10224 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
10227 if(GetTypeId() == TYPEID_PLAYER
)
10229 if(((Player
*)this)->GetGroup())
10230 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
10232 else if(((Creature
*)this)->isPet())
10234 Pet
*pet
= ((Pet
*)this);
10235 if(pet
->isControlled())
10237 Unit
*owner
= GetOwner();
10238 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10239 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
10244 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
10246 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
10248 tAuraProcTriggerDamage
.push_back(aura
);
10250 tAuraProcTriggerDamage
.remove(aura
);
10253 uint32
Unit::GetCreatePowers( Powers power
) const
10255 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
10258 case POWER_MANA
: return GetCreateMana();
10259 case POWER_RAGE
: return 1000;
10260 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
10261 case POWER_ENERGY
: return 100;
10262 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
10263 case POWER_RUNIC_POWER
: return 1000;
10269 void Unit::AddToWorld()
10271 Object::AddToWorld();
10274 void Unit::RemoveFromWorld()
10279 RemoveNotOwnSingleTargetAuras();
10282 Object::RemoveFromWorld();
10285 void Unit::CleanupsBeforeDelete()
10287 if(m_uint32Values
) // only for fully created object
10289 InterruptNonMeleeSpells(true);
10290 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
10292 ClearComboPointHolders();
10293 DeleteThreatList();
10294 getHostilRefManager().setOnlineOfflineState(false);
10296 RemoveAllGameObjects();
10297 RemoveAllDynObjects();
10298 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
10303 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
10306 m_charmInfo
= new CharmInfo(charm
);
10307 return m_charmInfo
;
10310 CharmInfo::CharmInfo(Unit
* unit
)
10311 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
10313 for(int i
=0; i
<4; ++i
)
10315 m_charmspells
[i
].spellId
= 0;
10316 m_charmspells
[i
].active
= ACT_DISABLED
;
10320 void CharmInfo::InitPetActionBar()
10322 // the first 3 SpellOrActions are attack, follow and stay
10323 for(uint32 i
= 0; i
< 3; i
++)
10325 PetActionBar
[i
].Type
= ACT_COMMAND
;
10326 PetActionBar
[i
].SpellOrAction
= COMMAND_ATTACK
- i
;
10328 PetActionBar
[i
+ 7].Type
= ACT_REACTION
;
10329 PetActionBar
[i
+ 7].SpellOrAction
= COMMAND_ATTACK
- i
;
10331 for(uint32 i
=0; i
< 4; i
++)
10333 PetActionBar
[i
+ 3].Type
= ACT_DISABLED
;
10334 PetActionBar
[i
+ 3].SpellOrAction
= 0;
10338 void CharmInfo::InitEmptyActionBar()
10340 for(uint32 x
= 1; x
< 10; ++x
)
10342 PetActionBar
[x
].Type
= ACT_PASSIVE
;
10343 PetActionBar
[x
].SpellOrAction
= 0;
10345 PetActionBar
[0].Type
= ACT_COMMAND
;
10346 PetActionBar
[0].SpellOrAction
= COMMAND_ATTACK
;
10349 void CharmInfo::InitPossessCreateSpells()
10351 if(m_unit
->GetTypeId() == TYPEID_PLAYER
)
10354 InitEmptyActionBar(); //charm action bar
10356 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
10358 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
10359 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
10361 AddSpellToAB(0, ((Creature
*)m_unit
)->m_spells
[x
], ACT_PASSIVE
);
10365 void CharmInfo::InitCharmCreateSpells()
10367 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
10369 InitEmptyActionBar();
10373 InitPetActionBar();
10375 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
10377 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
10378 m_charmspells
[x
].spellId
= spellId
;
10383 if (IsPassiveSpell(spellId
))
10385 m_unit
->CastSpell(m_unit
, spellId
, true);
10386 m_charmspells
[x
].active
= ACT_PASSIVE
;
10390 ActiveStates newstate
;
10391 bool onlyselfcast
= true;
10392 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
10394 if(!spellInfo
) onlyselfcast
= false;
10395 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
10397 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
10398 onlyselfcast
= false;
10401 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
10402 newstate
= ACT_DISABLED
;
10404 newstate
= ACT_PASSIVE
;
10406 AddSpellToAB(0, spellId
, newstate
);
10411 bool CharmInfo::AddSpellToAB(uint32 oldid
, uint32 newid
, ActiveStates newstate
)
10413 for(uint8 i
= 0; i
< 10; i
++)
10415 if((PetActionBar
[i
].Type
== ACT_DISABLED
|| PetActionBar
[i
].Type
== ACT_ENABLED
|| PetActionBar
[i
].Type
== ACT_PASSIVE
) && PetActionBar
[i
].SpellOrAction
== oldid
)
10417 PetActionBar
[i
].SpellOrAction
= newid
;
10420 if(newstate
== ACT_DECIDE
)
10421 PetActionBar
[i
].Type
= ACT_DISABLED
;
10423 PetActionBar
[i
].Type
= newstate
;
10432 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
10434 if(IsPassiveSpell(spellid
))
10437 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
10439 if(spellid
== m_charmspells
[x
].spellId
)
10441 m_charmspells
[x
].active
= apply
? ACT_ENABLED
: ACT_DISABLED
;
10446 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
10448 m_petnumber
= petnumber
;
10450 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
10452 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
10455 bool Unit::isFrozen() const
10457 return HasAuraState(AURA_STATE_FROZEN
);
10460 struct ProcTriggeredData
10462 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
10463 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
10464 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
10466 SpellProcEventEntry
const *spellProcEvent
;
10467 Aura
* triggeredByAura
;
10468 Unit::spellEffectPair triggeredByAura_SpellPair
;
10471 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
10472 typedef std::list
< uint32
> RemoveSpellList
;
10474 // List of auras that CAN be trigger but may not exist in spell_proc_event
10475 // in most case need for drop charges
10476 // in some types of aura need do additional check
10477 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
10478 bool InitTriggerAuraData()
10480 for (int i
=0;i
<TOTAL_AURAS
;i
++)
10482 isTriggerAura
[i
]=false;
10483 isNonTriggerAura
[i
] = false;
10485 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
10486 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
10487 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
10488 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
10489 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
10490 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
10491 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
10492 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
10493 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
10494 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
10495 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
10496 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
10497 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED
] = true;
10498 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
10499 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
10500 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
10501 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
10502 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
10503 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
10504 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
10505 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
10506 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
10507 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
10508 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
10509 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
10510 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
10511 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
10512 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
] = true;
10513 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_FROM_CASTER
] = true;
10515 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
10516 isNonTriggerAura
[SPELL_AURA_REDUCE_PUSHBACK
]=true;
10521 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
10523 uint32 procEx
= PROC_EX_NONE
;
10524 // Check victim state
10525 if (missCondition
!=SPELL_MISS_NONE
)
10526 switch (missCondition
)
10528 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
10529 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
10530 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
10531 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
10532 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
10533 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
10534 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
10535 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
10536 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
10537 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
10538 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
10545 if (damageInfo
->blocked
)
10546 procEx
|=PROC_EX_BLOCK
;
10548 if (damageInfo
->absorb
)
10549 procEx
|=PROC_EX_ABSORB
;
10551 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
10552 procEx
|=PROC_EX_CRITICAL_HIT
;
10554 procEx
|=PROC_EX_NORMAL_HIT
;
10559 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
10561 // For melee/ranged based attack need update skills and set some Aura states
10562 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
10564 // Update skills here for players
10565 if (GetTypeId() == TYPEID_PLAYER
)
10567 // On melee based hit/miss/resist need update skill (for victim and attacker)
10568 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
10570 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
10571 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, isVictim
);
10573 // Update defence if player is victim and parry/dodge/block
10574 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
10575 ((Player
*)this)->UpdateDefense();
10577 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
10578 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
10583 // if victim and dodge attack
10584 if (procExtra
&PROC_EX_DODGE
)
10586 //Update AURA_STATE on dodge
10587 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
10589 ModifyAuraState(AURA_STATE_DEFENSE
, true);
10590 StartReactiveTimer( REACTIVE_DEFENSE
);
10593 // if victim and parry attack
10594 if (procExtra
& PROC_EX_PARRY
)
10596 // For Hunters only Counterattack (skip Mongoose bite)
10597 if (getClass() == CLASS_HUNTER
)
10599 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
10600 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
10604 ModifyAuraState(AURA_STATE_DEFENSE
, true);
10605 StartReactiveTimer( REACTIVE_DEFENSE
);
10608 // if and victim block attack
10609 if (procExtra
& PROC_EX_BLOCK
)
10611 ModifyAuraState(AURA_STATE_DEFENSE
,true);
10612 StartReactiveTimer( REACTIVE_DEFENSE
);
10615 else //For attacker
10617 // Overpower on victim dodge
10618 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
10620 ((Player
*)this)->AddComboPoints(pTarget
, 1);
10621 StartReactiveTimer( REACTIVE_OVERPOWER
);
10627 RemoveSpellList removedSpells
;
10628 ProcTriggeredList procTriggered
;
10629 // Fill procTriggered list
10630 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
10632 SpellProcEventEntry
const* spellProcEvent
= NULL
;
10633 if(!IsTriggeredAtSpellProcEvent(pTarget
, itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
10636 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
10640 if (procTriggered
.empty())
10643 // Handle effects proceed this time
10644 for(ProcTriggeredList::iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
10646 // Some auras can be deleted in function called in this loop (except first, ofc)
10647 // Until storing auars in std::multimap to hard check deleting by another way
10648 if(i
!= procTriggered
.begin())
10650 bool found
= false;
10651 AuraMap::const_iterator lower
= GetAuras().lower_bound(i
->triggeredByAura_SpellPair
);
10652 AuraMap::const_iterator upper
= GetAuras().upper_bound(i
->triggeredByAura_SpellPair
);
10653 for(AuraMap::const_iterator itr
= lower
; itr
!= upper
; ++itr
)
10655 if(itr
->second
==i
->triggeredByAura
)
10663 // 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);
10664 // sLog.outDebug("It can be deleted one from early proccesed auras:");
10665 // for(ProcTriggeredList::iterator i2 = procTriggered.begin(); i != i2; ++i2)
10666 // sLog.outDebug(" Spell aura %u (id:%u effect:%u)", i->triggeredByAura->GetModifier()->m_auraname,i2->triggeredByAura_SpellPair.first,i2->triggeredByAura_SpellPair.second);
10667 // sLog.outDebug(" <end of list>");
10672 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
10673 Aura
*triggeredByAura
= i
->triggeredByAura
;
10674 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
10675 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
10676 uint32 effIndex
= triggeredByAura
->GetEffIndex();
10677 bool useCharges
= triggeredByAura
->GetAuraCharges() > 0;
10678 // For players set spell cooldown if need
10679 uint32 cooldown
= 0;
10680 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
10681 cooldown
= spellProcEvent
->cooldown
;
10683 switch(auraModifier
->m_auraname
)
10685 case SPELL_AURA_PROC_TRIGGER_SPELL
:
10687 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
10688 // Don`t drop charge or add cooldown for not started trigger
10689 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
10693 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
10695 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());
10696 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, spellInfo
->SchoolMask
);
10697 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
10698 SendSpellNonMeleeDamageLog(&damageInfo
);
10699 DealSpellDamage(&damageInfo
, true);
10702 case SPELL_AURA_MANA_SHIELD
:
10703 case SPELL_AURA_DUMMY
:
10705 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());
10706 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
10710 case SPELL_AURA_MOD_HASTE
:
10712 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());
10713 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
10717 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
10719 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());
10720 if (!HandleOverrideClassScriptAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, cooldown
))
10724 case SPELL_AURA_PRAYER_OF_MENDING
:
10726 sLog
.outDebug("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
10727 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
10729 HandleMeandingAuraProc(triggeredByAura
);
10732 case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
:
10734 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered with value by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
10736 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
10740 case SPELL_AURA_MOD_CASTING_SPEED
:
10741 // Skip melee hits or instant cast spells
10742 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
10745 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
10746 // Skip Melee hits and spells ws wrong school
10747 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
10750 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
10751 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
10752 // Skip melee hits and spells ws wrong school or zero cost
10753 if (procSpell
== NULL
||
10754 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
10755 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
10758 case SPELL_AURA_MECHANIC_IMMUNITY
:
10759 // Compare mechanic
10760 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
10763 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
10764 // Compare mechanic
10765 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
10768 case SPELL_AURA_MOD_DAMAGE_FROM_CASTER
:
10770 if (triggeredByAura
->GetCasterGUID() != pTarget
->GetGUID())
10774 // nothing do, just charges counter
10777 // Remove charge (aura can be removed by triggers)
10780 // need found aura on drop (can be dropped by triggers)
10781 AuraMap::const_iterator lower
= GetAuras().lower_bound(i
->triggeredByAura_SpellPair
);
10782 AuraMap::const_iterator upper
= GetAuras().upper_bound(i
->triggeredByAura_SpellPair
);
10783 for(AuraMap::const_iterator itr
= lower
; itr
!= upper
; ++itr
)
10785 // If last charge dropped add spell to remove list
10786 if(itr
->second
== i
->triggeredByAura
&& triggeredByAura
->DropAuraCharge())
10788 removedSpells
.push_back(triggeredByAura
->GetId());
10794 if (!removedSpells
.empty())
10796 // Sort spells and remove dublicates
10797 removedSpells
.sort();
10798 removedSpells
.unique();
10799 // Remove auras from removedAuras
10800 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();i
++)
10801 RemoveAurasDueToSpell(*i
);
10805 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
10807 return SPELL_SCHOOL_MASK_NORMAL
;
10810 Player
* Unit::GetSpellModOwner()
10812 if(GetTypeId()==TYPEID_PLAYER
)
10813 return (Player
*)this;
10814 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
10816 Unit
* owner
= GetOwner();
10817 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
10818 return (Player
*)owner
;
10823 ///----------Pet responses methods-----------------
10824 void Unit::SendPetCastFail(uint32 spellid
, uint8 msg
)
10826 Unit
*owner
= GetCharmerOrOwner();
10827 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10830 WorldPacket
data(SMSG_PET_CAST_FAILED
, (4+1));
10831 data
<< uint8(0); // cast count?
10832 data
<< uint32(spellid
);
10833 data
<< uint8(msg
);
10834 // uint32 for some reason
10835 // uint32 for some reason
10836 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10839 void Unit::SendPetActionFeedback (uint8 msg
)
10841 Unit
* owner
= GetOwner();
10842 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10845 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
10846 data
<< uint8(msg
);
10847 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10850 void Unit::SendPetTalk (uint32 pettalk
)
10852 Unit
* owner
= GetOwner();
10853 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10856 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8+4);
10857 data
<< uint64(GetGUID());
10858 data
<< uint32(pettalk
);
10859 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10862 void Unit::SendPetSpellCooldown (uint32 spellid
, time_t cooltime
)
10864 Unit
* owner
= GetOwner();
10865 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10868 WorldPacket
data(SMSG_SPELL_COOLDOWN
, 8+1+4+4);
10869 data
<< uint64(GetGUID());
10870 data
<< uint8(0x0); // flags (0x1, 0x2)
10871 data
<< uint32(spellid
);
10872 data
<< uint32(cooltime
);
10874 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10877 void Unit::SendPetClearCooldown (uint32 spellid
)
10879 Unit
* owner
= GetOwner();
10880 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10883 WorldPacket
data(SMSG_CLEAR_COOLDOWN
, (4+8));
10884 data
<< uint32(spellid
);
10885 data
<< uint64(GetGUID());
10886 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10889 void Unit::SendPetAIReaction(uint64 guid
)
10891 Unit
* owner
= GetOwner();
10892 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10895 WorldPacket
data(SMSG_AI_REACTION
, 12);
10896 data
<< uint64(guid
) << uint32(00000002);
10897 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10900 ///----------End of Pet responses methods----------
10902 void Unit::StopMoving()
10904 clearUnitState(UNIT_STAT_MOVING
);
10906 // send explicit stop packet
10907 // rely on vmaps here because for example stormwind is in air
10908 //float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true);
10909 //if (fabs(GetPositionZ() - z) < 2.0f)
10910 // Relocate(GetPositionX(), GetPositionY(), z);
10911 Relocate(GetPositionX(), GetPositionY(),GetPositionZ());
10913 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, 0);
10915 // update position and orientation;
10917 BuildHeartBeatMsg(&data
);
10918 SendMessageToSet(&data
,false);
10921 void Unit::SetFeared(bool apply
, uint64 casterGUID
, uint32 spellID
)
10925 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
10928 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
10930 GetMotionMaster()->MovementExpired(false);
10931 CastStop(GetGUID()==casterGUID
? spellID
: 0);
10933 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
10935 GetMotionMaster()->MoveFleeing(caster
); // caster==NULL processed in MoveFleeing
10939 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
10941 GetMotionMaster()->MovementExpired(false);
10943 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
10945 // restore appropriate movement generator
10947 GetMotionMaster()->MoveChase(getVictim());
10949 GetMotionMaster()->Initialize();
10951 // attack caster if can
10952 Unit
* caster
= ObjectAccessor::GetObjectInWorld(casterGUID
, (Unit
*)NULL
);
10953 if(caster
&& caster
!= getVictim() && ((Creature
*)this)->AI())
10954 ((Creature
*)this)->AI()->AttackStart(caster
);
10958 if (GetTypeId() == TYPEID_PLAYER
)
10959 ((Player
*)this)->SetClientControl(this, !apply
);
10962 void Unit::SetConfused(bool apply
, uint64 casterGUID
, uint32 spellID
)
10966 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
10968 CastStop(GetGUID()==casterGUID
? spellID
: 0);
10970 GetMotionMaster()->MoveConfused();
10974 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
10976 GetMotionMaster()->MovementExpired(false);
10978 if (GetTypeId() == TYPEID_UNIT
)
10980 // if in combat restore movement generator
10982 GetMotionMaster()->MoveChase(getVictim());
10986 if(GetTypeId() == TYPEID_PLAYER
)
10987 ((Player
*)this)->SetClientControl(this, !apply
);
10990 bool Unit::IsSitState() const
10992 uint8 s
= getStandState();
10993 return s
== PLAYER_STATE_SIT_CHAIR
|| s
== PLAYER_STATE_SIT_LOW_CHAIR
||
10994 s
== PLAYER_STATE_SIT_MEDIUM_CHAIR
|| s
== PLAYER_STATE_SIT_HIGH_CHAIR
||
10995 s
== PLAYER_STATE_SIT
;
10998 bool Unit::IsStandState() const
11000 uint8 s
= getStandState();
11001 return !IsSitState() && s
!= PLAYER_STATE_SLEEP
&& s
!= PLAYER_STATE_KNEEL
;
11004 void Unit::SetStandState(uint8 state
)
11006 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
11008 if (IsStandState())
11009 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
11011 if(GetTypeId()==TYPEID_PLAYER
)
11013 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
11014 data
<< (uint8
)state
;
11015 ((Player
*)this)->GetSession()->SendPacket(&data
);
11019 bool Unit::IsPolymorphed() const
11021 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
11024 void Unit::SetDisplayId(uint32 modelId
)
11026 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
11028 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
11030 Pet
*pet
= ((Pet
*)this);
11031 if(!pet
->isControlled())
11033 Unit
*owner
= GetOwner();
11034 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11035 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
11039 void Unit::ClearComboPointHolders()
11041 while(!m_ComboPointHolders
.empty())
11043 uint32 lowguid
= *m_ComboPointHolders
.begin();
11045 Player
* plr
= objmgr
.GetPlayer(MAKE_NEW_GUID(lowguid
, 0, HIGHGUID_PLAYER
));
11046 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
11047 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
11049 m_ComboPointHolders
.erase(lowguid
); // or remove manually
11053 void Unit::ClearAllReactives()
11055 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
11056 m_reactiveTimer
[i
] = 0;
11058 if (HasAuraState( AURA_STATE_DEFENSE
))
11059 ModifyAuraState(AURA_STATE_DEFENSE
, false);
11060 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
11061 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
11062 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
11063 ((Player
*)this)->ClearComboPoints();
11066 void Unit::UpdateReactives( uint32 p_time
)
11068 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
11070 ReactiveType reactive
= ReactiveType(i
);
11072 if(!m_reactiveTimer
[reactive
])
11075 if ( m_reactiveTimer
[reactive
] <= p_time
)
11077 m_reactiveTimer
[reactive
] = 0;
11079 switch ( reactive
)
11081 case REACTIVE_DEFENSE
:
11082 if (HasAuraState(AURA_STATE_DEFENSE
))
11083 ModifyAuraState(AURA_STATE_DEFENSE
, false);
11085 case REACTIVE_HUNTER_PARRY
:
11086 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
11087 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
11089 case REACTIVE_OVERPOWER
:
11090 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
11091 ((Player
*)this)->ClearComboPoints();
11099 m_reactiveTimer
[reactive
] -= p_time
;
11104 Unit
* Unit::SelectNearbyTarget() const
11106 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
11108 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
11109 cell
.SetNoCreate();
11111 std::list
<Unit
*> targets
;
11114 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, ATTACK_DISTANCE
);
11115 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(targets
, u_check
);
11117 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
11118 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
11120 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
11121 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *GetMap());
11122 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *GetMap());
11125 // remove current target
11127 targets
.remove(getVictim());
11129 // remove not LoS targets
11130 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
11132 if(!IsWithinLOSInMap(*tIter
))
11134 std::list
<Unit
*>::iterator tIter2
= tIter
;
11136 targets
.erase(tIter2
);
11142 // no appropriate targets
11143 if(targets
.empty())
11147 uint32 rIdx
= urand(0,targets
.size()-1);
11148 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
11149 for(uint32 i
= 0; i
< rIdx
; ++i
)
11155 bool Unit::hasNegativeAuraWithInterruptFlag(uint32 flag
)
11157 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); ++iter
)
11159 if (!iter
->second
->IsPositive() && iter
->second
->GetSpellProto()->AuraInterruptFlags
& flag
)
11165 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
11169 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
11170 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
11174 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
11175 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
11179 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
11182 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
11184 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
11187 uint32
Unit::GetCastingTimeForBonus( SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 CastingTime
)
11189 // Not apply this to creature casted spells with casttime==0
11190 if(CastingTime
==0 && GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
11193 if (CastingTime
> 7000) CastingTime
= 7000;
11194 if (CastingTime
< 1500) CastingTime
= 1500;
11196 if(damagetype
== DOT
&& !IsChanneledSpell(spellProto
))
11197 CastingTime
= 3500;
11199 int32 overTime
= 0;
11201 bool DirectDamage
= false;
11202 bool AreaEffect
= false;
11204 for ( uint32 i
=0; i
<3;i
++)
11206 switch ( spellProto
->Effect
[i
] )
11208 case SPELL_EFFECT_SCHOOL_DAMAGE
:
11209 case SPELL_EFFECT_POWER_DRAIN
:
11210 case SPELL_EFFECT_HEALTH_LEECH
:
11211 case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
:
11212 case SPELL_EFFECT_POWER_BURN
:
11213 case SPELL_EFFECT_HEAL
:
11214 DirectDamage
= true;
11216 case SPELL_EFFECT_APPLY_AURA
:
11217 switch ( spellProto
->EffectApplyAuraName
[i
] )
11219 case SPELL_AURA_PERIODIC_DAMAGE
:
11220 case SPELL_AURA_PERIODIC_HEAL
:
11221 case SPELL_AURA_PERIODIC_LEECH
:
11222 if ( GetSpellDuration(spellProto
) )
11223 overTime
= GetSpellDuration(spellProto
);
11226 // -5% per additional effect
11234 if(IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetA
[i
])) || IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetB
[i
])))
11238 // Combined Spells with Both Over Time and Direct Damage
11239 if ( overTime
> 0 && CastingTime
> 0 && DirectDamage
)
11241 // mainly for DoTs which are 3500 here otherwise
11242 uint32 OriginalCastTime
= GetSpellCastTime(spellProto
);
11243 if (OriginalCastTime
> 7000) OriginalCastTime
= 7000;
11244 if (OriginalCastTime
< 1500) OriginalCastTime
= 1500;
11245 // Portion to Over Time
11246 float PtOT
= (overTime
/ 15000.f
) / ((overTime
/ 15000.f
) + (OriginalCastTime
/ 3500.f
));
11248 if ( damagetype
== DOT
)
11249 CastingTime
= uint32(CastingTime
* PtOT
);
11250 else if ( PtOT
< 1.0f
)
11251 CastingTime
= uint32(CastingTime
* (1 - PtOT
));
11256 // Area Effect Spells receive only half of bonus
11260 // -5% of total per any additional effect
11261 for ( uint8 i
=0; i
<effects
; ++i
)
11263 if ( CastingTime
> 175 )
11265 CastingTime
-= 175;
11274 return CastingTime
;
11277 void Unit::UpdateAuraForGroup(uint8 slot
)
11279 if(GetTypeId() == TYPEID_PLAYER
)
11281 Player
* player
= (Player
*)this;
11282 if(player
->GetGroup())
11284 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
11285 player
->SetAuraUpdateMask(slot
);
11288 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
11290 Pet
*pet
= ((Pet
*)this);
11291 if(pet
->isControlled())
11293 Unit
*owner
= GetOwner();
11294 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11296 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
11297 pet
->SetAuraUpdateMask(slot
);
11303 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
11305 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
11306 return float(GetAttackTime(attType
))/1000.0f
;
11308 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
);
11310 return 2.4; // fist attack
11312 switch (Weapon
->GetProto()->InventoryType
)
11314 case INVTYPE_2HWEAPON
:
11316 case INVTYPE_RANGED
:
11317 case INVTYPE_RANGEDRIGHT
:
11318 case INVTYPE_THROWN
:
11320 case INVTYPE_WEAPON
:
11321 case INVTYPE_WEAPONMAINHAND
:
11322 case INVTYPE_WEAPONOFFHAND
:
11324 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7 : 2.4;
11328 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
11330 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
11331 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
11332 if ((*itr
)->GetId() == spell_id
)
11338 bool Unit::IsUnderLastManaUseEffect() const
11340 return getMSTimeDiff(m_lastManaUse
,getMSTime()) < 5000;
11343 void Unit::SetContestedPvP(Player
*attackedPlayer
)
11345 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
11347 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
11350 player
->SetContestedPvPTimer(30000);
11351 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
11353 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
11354 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
11355 // call MoveInLineOfSight for nearby contested guards
11356 SetVisibility(GetVisibility());
11358 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
11360 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
11361 // call MoveInLineOfSight for nearby contested guards
11362 SetVisibility(GetVisibility());
11366 void Unit::AddPetAura(PetAura
const* petSpell
)
11368 m_petAuras
.insert(petSpell
);
11369 if(Pet
* pet
= GetPet())
11370 pet
->CastPetAura(petSpell
);
11373 void Unit::RemovePetAura(PetAura
const* petSpell
)
11375 m_petAuras
.erase(petSpell
);
11376 if(Pet
* pet
= GetPet())
11377 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
11380 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
11382 Pet
* pet
= new Pet(HUNTER_PET
);
11384 if(!pet
->CreateBaseAtCreature(creatureTarget
))
11390 pet
->SetOwnerGUID(GetGUID());
11391 pet
->SetCreatorGUID(GetGUID());
11392 pet
->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE
, getFaction());
11393 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
11395 if(GetTypeId()==TYPEID_PLAYER
)
11396 pet
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
11398 uint32 level
= (creatureTarget
->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget
->getLevel();
11400 if(!pet
->InitStatsForLevel(level
))
11402 sLog
.outError("ERROR: Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
11407 pet
->GetCharmInfo()->SetPetNumber(objmgr
.GeneratePetNumber(), true);
11408 // this enables pet details window (Shift+P)
11409 pet
->AIM_Initialize();
11410 pet
->InitPetCreateSpells();
11411 pet
->InitTalentForLevel();
11412 pet
->SetHealth(pet
->GetMaxHealth());
11417 bool Unit::IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
11419 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
11421 // Get proc Event Entry
11422 spellProcEvent
= spellmgr
.GetSpellProcEvent(spellProto
->Id
);
11424 // Aura info stored here
11425 Modifier
*mod
= aura
->GetModifier();
11427 if (isNonTriggerAura
[mod
->m_auraname
])
11429 // If not trigger by default and spellProcEvent==NULL - skip
11430 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
11433 // Get EventProcFlag
11434 uint32 EventProcFlag
;
11435 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
11436 EventProcFlag
= spellProcEvent
->procFlags
;
11438 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
11439 // Continue if no trigger exist
11440 if (!EventProcFlag
)
11443 // Check spellProcEvent data requirements
11444 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
11447 // In most cases req get honor or XP from kill
11448 if (EventProcFlag
& PROC_FLAG_KILL
&& GetTypeId() == TYPEID_PLAYER
)
11450 bool allow
= ((Player
*)this)->isHonorOrXPTarget(pVictim
);
11451 // Shadow Word: Death - can trigger from every kill
11452 if (aura
->GetId() == 32409)
11457 // Aura added by spell can`t trogger from self (prevent drop charges/do triggers)
11458 // But except periodic triggers (can triggered from self)
11459 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
&PROC_FLAG_ON_TAKE_PERIODIC
))
11462 // Check if current equipment allows aura to proc
11463 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
11465 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
11468 if(attType
== BASE_ATTACK
)
11469 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
11470 else if (attType
== OFF_ATTACK
)
11471 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
11473 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
11475 if (!((Player
*)this)->IsUseEquipedWeapon(attType
==BASE_ATTACK
))
11478 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
11481 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
11483 // Check if player is wearing shield
11484 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
11485 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
11489 // Get chance from spell
11490 float chance
= (float)spellProto
->procChance
;
11491 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
11492 if(spellProcEvent
&& spellProcEvent
->customChance
)
11493 chance
= spellProcEvent
->customChance
;
11494 // If PPM exist calculate chance from PPM
11495 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
11497 uint32 WeaponSpeed
= GetAttackTime(attType
);
11498 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
11500 // Apply chance modifer aura
11501 if(Player
* modOwner
= GetSpellModOwner())
11502 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
11504 return roll_chance_f(chance
);
11507 bool Unit::HandleMeandingAuraProc( Aura
* triggeredByAura
)
11509 // aura can be deleted at casts
11510 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
11511 uint32 effIdx
= triggeredByAura
->GetEffIndex();
11512 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
11513 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
11516 int32 jumps
= triggeredByAura
->GetAuraCharges()-1;
11518 // current aura expire
11519 triggeredByAura
->SetAuraCharges(1); // will removed at next charges decrease
11521 // next target selection
11522 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
11525 if (spellProto
->EffectRadiusIndex
[effIdx
])
11526 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
11528 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
11530 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
11532 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
11534 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
11536 // aura will applied from caster, but spell casted from current aura holder
11537 SpellModifier
*mod
= new SpellModifier
;
11538 mod
->op
= SPELLMOD_CHARGES
;
11539 mod
->value
= jumps
-5; // negative
11540 mod
->type
= SPELLMOD_FLAT
;
11541 mod
->spellId
= spellProto
->Id
;
11542 mod
->mask
= spellProto
->SpellFamilyFlags
;
11543 mod
->mask2
= spellProto
->SpellFamilyFlags2
;
11545 caster
->AddSpellMod(mod
, true);
11546 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
11547 caster
->AddSpellMod(mod
, false);
11553 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
11557 void Unit::RemoveAurasAtChanneledTarget(SpellEntry
const* spellInfo
)
11559 uint64 target_guid
= GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
);
11561 if(!IS_UNIT_GUID(target_guid
))
11564 Unit
* target
= ObjectAccessor::GetUnit(*this, target_guid
);
11568 for (AuraMap::iterator iter
= target
->GetAuras().begin(); iter
!= target
->GetAuras().end(); )
11570 if (iter
->second
->GetId() == spellInfo
->Id
&& iter
->second
->GetCasterGUID()==GetGUID())
11571 target
->RemoveAura(iter
);