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;
107 m_Visibility
= VISIBILITY_ON
;
109 m_detectInvisibilityMask
= 0;
110 m_invisibilityMask
= 0;
112 m_ShapeShiftFormSpellId
= 0;
113 m_canModifyStats
= false;
115 for (int i
= 0; i
< MAX_SPELL_IMMUNITY
; i
++)
116 m_spellImmune
[i
].clear();
117 for (int i
= 0; i
< UNIT_MOD_END
; i
++)
119 m_auraModifiersGroup
[i
][BASE_VALUE
] = 0.0f
;
120 m_auraModifiersGroup
[i
][BASE_PCT
] = 1.0f
;
121 m_auraModifiersGroup
[i
][TOTAL_VALUE
] = 0.0f
;
122 m_auraModifiersGroup
[i
][TOTAL_PCT
] = 1.0f
;
124 // implement 50% base damage from offhand
125 m_auraModifiersGroup
[UNIT_MOD_DAMAGE_OFFHAND
][TOTAL_PCT
] = 0.5f
;
127 for (int i
= 0; i
< 3; i
++)
129 m_weaponDamage
[i
][MINDAMAGE
] = BASE_MINDAMAGE
;
130 m_weaponDamage
[i
][MAXDAMAGE
] = BASE_MAXDAMAGE
;
132 for (int i
= 0; i
< MAX_STATS
; i
++)
133 m_createStats
[i
] = 0.0f
;
136 m_modMeleeHitChance
= 0.0f
;
137 m_modRangedHitChance
= 0.0f
;
138 m_modSpellHitChance
= 0.0f
;
139 m_baseSpellCritChance
= 5;
144 //m_victimThreat = 0.0f;
145 for (int i
= 0; i
< MAX_SPELL_SCHOOL
; ++i
)
146 m_threatModifier
[i
] = 1.0f
;
148 for (int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
149 m_speed_rate
[i
] = 1.0f
;
153 m_unit_movement_flags
= 0;
155 // remove aurastates allowing special moves
156 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
157 m_reactiveTimer
[i
] = 0;
162 // set current spells as deletable
163 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
165 if (m_currentSpells
[i
])
167 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
168 m_currentSpells
[i
] = NULL
;
172 RemoveAllGameObjects();
173 RemoveAllDynObjects();
175 if(m_charmInfo
) delete m_charmInfo
;
178 void Unit::Update( uint32 p_time
)
180 /*if(p_time > m_AurasCheck)
185 m_AurasCheck -= p_time;*/
187 // WARNING! Order of execution here is important, do not change.
188 // Spells must be processed with event system BEFORE they go to _UpdateSpells.
189 // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
190 m_Events
.Update( p_time
);
191 _UpdateSpells( p_time
);
193 // update combat timer only for players and pets
194 if (isInCombat() && (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet() || ((Creature
*)this)->isCharmed()))
196 // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away
197 // targets without stopping half way there and running off.
198 // These flags are reset after target dies or another command is given.
199 if( m_HostilRefManager
.isEmpty() )
201 // m_CombatTimer set at aura start and it will be freeze until aura removing
202 if ( m_CombatTimer
<= p_time
)
205 m_CombatTimer
-= p_time
;
209 if(uint32 base_att
= getAttackTimer(BASE_ATTACK
))
211 setAttackTimer(BASE_ATTACK
, (p_time
>= base_att
? 0 : base_att
- p_time
) );
214 // update abilities available only for fraction of time
215 UpdateReactives( p_time
);
217 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, GetHealth() < GetMaxHealth()*0.20f
);
218 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, GetHealth() < GetMaxHealth()*0.35f
);
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
)
806 if(Spell
* spell
= pVictim
->m_currentSpells
[CURRENT_CHANNELED_SPELL
])
808 if (spell
->getState() == SPELL_STATE_CASTING
)
810 uint32 channelInterruptFlags
= spell
->m_spellInfo
->ChannelInterruptFlags
;
811 if( channelInterruptFlags
& CHANNEL_FLAG_DELAY
)
813 if(pVictim
!=this) //don't shorten the duration of channeling if you damage yourself
814 spell
->DelayedChannel();
816 else if( (channelInterruptFlags
& (CHANNEL_FLAG_DAMAGE
| CHANNEL_FLAG_DAMAGE2
)) )
818 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
819 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
822 else if (spell
->getState() == SPELL_STATE_DELAYED
)
823 // break channeled spell in delayed state on damage
825 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
826 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
831 // last damage from duel opponent
834 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
835 Player
*he
= (Player
*)pVictim
;
841 he
->duel
->opponent
->CombatStopWithPets(true);
842 he
->CombatStopWithPets(true);
844 he
->CastSpell(he
, 7267, true); // beg
845 he
->DuelComplete(DUEL_WON
);
849 DEBUG_LOG("DealDamageEnd returned %d damage", damage
);
854 void Unit::CastStop(uint32 except_spellid
)
856 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
857 if (m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
!=except_spellid
)
858 InterruptSpell(i
,false);
861 void Unit::CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
863 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
867 sLog
.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId
,(GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
871 CastSpell(Victim
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
874 void Unit::CastSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
878 sLog
.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
883 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
885 if(!originalCaster
&& triggeredByAura
)
886 originalCaster
= triggeredByAura
->GetCasterGUID();
888 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
890 SpellCastTargets targets
;
891 targets
.setUnitTarget( Victim
);
892 spell
->m_CastItem
= castItem
;
893 spell
->prepare(&targets
, triggeredByAura
);
896 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
898 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
902 sLog
.outError("CastCustomSpell: unknown spell id %i\n", spellId
);
906 CastCustomSpell(Victim
,spellInfo
,bp0
,bp1
,bp2
,triggered
,castItem
,triggeredByAura
, originalCaster
);
909 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
)
913 sLog
.outError("CastCustomSpell: unknown spell");
918 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
920 if(!originalCaster
&& triggeredByAura
)
921 originalCaster
= triggeredByAura
->GetCasterGUID();
923 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
926 spell
->m_currentBasePoints
[0] = *bp0
-int32(spellInfo
->EffectBaseDice
[0]);
929 spell
->m_currentBasePoints
[1] = *bp1
-int32(spellInfo
->EffectBaseDice
[1]);
932 spell
->m_currentBasePoints
[2] = *bp2
-int32(spellInfo
->EffectBaseDice
[2]);
934 SpellCastTargets targets
;
935 targets
.setUnitTarget( Victim
);
936 spell
->m_CastItem
= castItem
;
937 spell
->prepare(&targets
, triggeredByAura
);
940 // used for scripting
941 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
943 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
947 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()));
951 CastSpell(x
, y
, z
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
954 // used for scripting
955 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
959 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
964 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
966 if(!originalCaster
&& triggeredByAura
)
967 originalCaster
= triggeredByAura
->GetCasterGUID();
969 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
971 SpellCastTargets targets
;
972 targets
.setDestination(x
, y
, z
);
973 spell
->m_CastItem
= castItem
;
974 spell
->prepare(&targets
, triggeredByAura
);
977 // Obsolete func need remove, here only for comotability vs another patches
978 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
, bool isTriggeredSpell
, bool useSpellDamage
)
980 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
981 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, spellInfo
->SchoolMask
);
982 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
983 SendSpellNonMeleeDamageLog(&damageInfo
);
984 DealSpellDamage(&damageInfo
, true);
985 return damageInfo
.damage
;
988 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
990 SpellSchoolMask damageSchoolMask
= SpellSchoolMask(damageInfo
->schoolMask
);
991 Unit
*pVictim
= damageInfo
->target
;
996 if(!this || !pVictim
)
998 if(!this->isAlive() || !pVictim
->isAlive())
1001 uint32 crTypeMask
= pVictim
->GetCreatureTypeMask();
1002 // Check spell crit chance
1003 bool crit
= isSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
1004 bool blocked
= false;
1006 switch (spellInfo
->DmgClass
)
1008 // Melee and Ranged Spells
1009 case SPELL_DAMAGE_CLASS_RANGED
:
1010 case SPELL_DAMAGE_CLASS_MELEE
:
1013 if ( damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
1015 //Calculate armor mitigation
1016 damage
= CalcArmorReducedDamage(pVictim
, damage
);
1017 // Get blocked status
1018 blocked
= isSpellBlocked(pVictim
, spellInfo
, attackType
);
1023 // Calculate damage bonus
1024 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1028 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1030 // Calculate crit bonus
1031 uint32 crit_bonus
= damage
;
1032 // Apply crit_damage bonus for melee spells
1033 if(Player
* modOwner
= GetSpellModOwner())
1034 modOwner
->ApplySpellMod(spellInfo
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
1035 damage
+= crit_bonus
;
1037 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1038 int32 critPctDamageMod
=0;
1039 if(attackType
== RANGED_ATTACK
)
1040 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1043 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1044 critPctDamageMod
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
);
1046 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1047 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1049 if (critPctDamageMod
!=0)
1050 damage
= int32((damage
) * float((100.0f
+ critPctDamageMod
)/100.0f
));
1052 // Resilience - reduce crit damage
1053 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1054 damage
-= ((Player
*)pVictim
)->GetMeleeCritDamageReduction(damage
);
1056 // Spell weapon based damage CAN BE crit & blocked at same time
1059 damageInfo
->blocked
= uint32(pVictim
->GetShieldBlockValue());
1060 if (damage
< damageInfo
->blocked
)
1061 damageInfo
->blocked
= damage
;
1062 damage
-=damageInfo
->blocked
;
1067 case SPELL_DAMAGE_CLASS_NONE
:
1068 case SPELL_DAMAGE_CLASS_MAGIC
:
1070 // Calculate damage bonus
1071 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1072 // If crit add critical bonus
1075 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1076 damage
= SpellCriticalBonus(spellInfo
, damage
, pVictim
);
1077 // Resilience - reduce crit damage
1078 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1079 damage
-= ((Player
*)pVictim
)->GetSpellCritDamageReduction(damage
);
1085 // Calculate absorb resist
1088 CalcAbsorbResist(pVictim
, damageSchoolMask
, SPELL_DIRECT_DAMAGE
, damage
, &damageInfo
->absorb
, &damageInfo
->resist
);
1089 damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
1093 damageInfo
->damage
= damage
;
1096 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1101 Unit
*pVictim
= damageInfo
->target
;
1103 if(!this || !pVictim
)
1106 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1109 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1110 if (spellProto
== NULL
)
1112 sLog
.outDebug("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1116 //You don't lose health from damage taken from another player while in a sanctuary
1117 //You still see it in the combat log though
1118 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1120 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1121 if(area
&& area
->flags
& 0x800) //sanctuary
1125 // update at damage Judgement aura duration that applied by attacker at victim
1126 if(damageInfo
->damage
&& spellProto
->Id
== 35395)
1128 AuraMap
& vAuras
= pVictim
->GetAuras();
1129 for(AuraMap::iterator itr
= vAuras
.begin(); itr
!= vAuras
.end(); ++itr
)
1131 SpellEntry
const *spellInfo
= (*itr
).second
->GetSpellProto();
1132 if( spellInfo
->AttributesEx3
& 0x40000 && spellInfo
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& ((*itr
).second
->GetCasterGUID() == GetGUID()))
1134 (*itr
).second
->SetAuraDuration((*itr
).second
->GetAuraMaxDuration());
1135 (*itr
).second
->SendAuraUpdate(false);
1139 // Call default DealDamage
1140 CleanDamage
cleanDamage(damageInfo
->cleanDamage
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
1141 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->schoolMask
), spellProto
, durabilityLoss
);
1144 //TODO for melee need create structure as in
1145 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1147 damageInfo
->attacker
= this;
1148 damageInfo
->target
= pVictim
;
1149 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1150 damageInfo
->attackType
= attackType
;
1151 damageInfo
->damage
= 0;
1152 damageInfo
->cleanDamage
= 0;
1153 damageInfo
->absorb
= 0;
1154 damageInfo
->resist
= 0;
1155 damageInfo
->blocked_amount
= 0;
1157 damageInfo
->TargetState
= 0;
1158 damageInfo
->HitInfo
= 0;
1159 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1160 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1161 damageInfo
->procEx
= PROC_EX_NONE
;
1162 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1164 if(!this || !pVictim
)
1166 if(!this->isAlive() || !pVictim
->isAlive())
1169 // Select HitInfo/procAttacker/procVictim flag based on attack type
1173 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MILEE_HIT
;
1174 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1175 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1178 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MILEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1179 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1180 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1183 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1184 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1185 damageInfo
->HitInfo
= 0x08;// test
1191 // Physical Immune check
1192 if(damageInfo
->target
->IsImmunedToDamage(SpellSchoolMask(damageInfo
->damageSchoolMask
)))
1194 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1195 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1197 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1198 damageInfo
->damage
= 0;
1199 damageInfo
->cleanDamage
= 0;
1202 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1203 // Add melee damage bonus
1204 MeleeDamageBonus(damageInfo
->target
, &damage
, damageInfo
->attackType
);
1205 // Calculate armor reduction
1206 damageInfo
->damage
= CalcArmorReducedDamage(damageInfo
->target
, damage
);
1207 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1209 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1211 // Disable parry or dodge for ranged attack
1212 if(damageInfo
->attackType
== RANGED_ATTACK
)
1214 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1215 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1218 switch(damageInfo
->hitOutCome
)
1220 case MELEE_HIT_EVADE
:
1222 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1223 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1225 damageInfo
->procEx
|=PROC_EX_EVADE
;
1226 damageInfo
->damage
= 0;
1227 damageInfo
->cleanDamage
= 0;
1230 case MELEE_HIT_MISS
:
1232 damageInfo
->HitInfo
|= HITINFO_MISS
;
1233 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1235 damageInfo
->procEx
|=PROC_EX_MISS
;
1236 damageInfo
->damage
= 0;
1237 damageInfo
->cleanDamage
= 0;
1240 case MELEE_HIT_NORMAL
:
1241 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1242 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1244 case MELEE_HIT_CRIT
:
1246 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1247 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1249 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1251 damageInfo
->damage
+= damageInfo
->damage
;
1253 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1254 if(damageInfo
->attackType
== RANGED_ATTACK
)
1255 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1258 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1259 mod
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
);
1262 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1264 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1265 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1267 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1269 // Resilience - reduce crit damage
1270 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1272 uint32 resilienceReduction
= ((Player
*)pVictim
)->GetMeleeCritDamageReduction(damageInfo
->damage
);
1273 damageInfo
->damage
-= resilienceReduction
;
1274 damageInfo
->cleanDamage
+= resilienceReduction
;
1278 case MELEE_HIT_PARRY
:
1279 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1280 damageInfo
->procEx
|=PROC_EX_PARRY
;
1281 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1282 damageInfo
->damage
= 0;
1285 case MELEE_HIT_DODGE
:
1286 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1287 damageInfo
->procEx
|=PROC_EX_DODGE
;
1288 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1289 damageInfo
->damage
= 0;
1291 case MELEE_HIT_BLOCK
:
1293 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1294 damageInfo
->HitInfo
|= HITINFO_BLOCK
;
1295 damageInfo
->procEx
|=PROC_EX_BLOCK
;
1296 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1297 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1299 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1300 damageInfo
->blocked_amount
= damageInfo
->damage
;
1302 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1303 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1306 case MELEE_HIT_GLANCING
:
1308 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1309 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1310 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1311 float reducePercent
= 1.0f
; //damage factor
1312 // calculate base values and mods
1313 float baseLowEnd
= 1.3;
1314 float baseHighEnd
= 1.2;
1315 switch(getClass()) // lowering base values for casters
1327 float maxLowEnd
= 0.6;
1328 switch(getClass()) // upper for melee classes
1332 maxLowEnd
= 0.91; //If the attacker is a melee class then instead the lower value of 0.91
1336 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1337 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1338 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1340 // apply max/min bounds
1341 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1343 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1346 if ( highEnd
< 0.2f
) //high end limits
1348 if ( highEnd
> 0.99f
)
1351 if(lowEnd
> highEnd
) // prevent negative range size
1354 reducePercent
= lowEnd
+ rand_norm() * ( highEnd
- lowEnd
);
1356 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1357 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1360 case MELEE_HIT_CRUSHING
:
1362 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1363 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1364 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1365 // 150% normal damage
1366 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1374 // Calculate absorb resist
1375 if(int32(damageInfo
->damage
) > 0)
1377 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1378 // Calculate absorb & resists
1379 CalcAbsorbResist(damageInfo
->target
, SpellSchoolMask(damageInfo
->damageSchoolMask
), DIRECT_DAMAGE
, damageInfo
->damage
, &damageInfo
->absorb
, &damageInfo
->resist
);
1380 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1381 if (damageInfo
->absorb
)
1383 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1384 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1386 if (damageInfo
->resist
)
1387 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1390 else // Umpossible get negative result but....
1391 damageInfo
->damage
= 0;
1394 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1396 if (damageInfo
==0) return;
1397 Unit
*pVictim
= damageInfo
->target
;
1399 if(!this || !pVictim
)
1402 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1405 //You don't lose health from damage taken from another player while in a sanctuary
1406 //You still see it in the combat log though
1407 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1409 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1410 if(area
&& area
->flags
& 0x800) //sanctuary
1414 // Hmmmm dont like this emotes cloent must by self do all animations
1415 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1416 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1417 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1418 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1420 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1422 // Get attack timers
1423 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1424 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1425 // Reduce attack time
1426 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1428 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20;
1429 float percent60
= 3 * percent20
;
1430 if(offtime
> percent20
&& offtime
<= percent60
)
1432 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1434 else if(offtime
> percent60
)
1436 offtime
-= 2 * percent20
;
1437 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1442 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20;
1443 float percent60
= 3 * percent20
;
1444 if(basetime
> percent20
&& basetime
<= percent60
)
1446 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1448 else if(basetime
> percent60
)
1450 basetime
-= 2 * percent20
;
1451 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1456 // Call default DealDamage
1457 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1458 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->damageSchoolMask
), NULL
, durabilityLoss
);
1460 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1461 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1462 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI
, this) )
1464 // -probability is between 0% and 40%
1466 float Probability
= 20;
1468 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1469 if( pVictim
->getLevel() < 30 )
1470 Probability
= 0.65f
*pVictim
->getLevel()+0.5;
1472 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1473 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1475 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1477 if(Probability
> 40)
1480 if(roll_chance_f(Probability
))
1481 CastSpell(pVictim
, 1604, true);
1484 // update at damage Judgement aura duration that applied by attacker at victim
1485 if(damageInfo
->damage
)
1487 AuraMap
& vAuras
= pVictim
->GetAuras();
1488 for(AuraMap::iterator itr
= vAuras
.begin(); itr
!= vAuras
.end(); ++itr
)
1490 SpellEntry
const *spellInfo
= (*itr
).second
->GetSpellProto();
1491 if( spellInfo
->AttributesEx3
& 0x40000 && spellInfo
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& ((*itr
).second
->GetCasterGUID() == GetGUID()))
1493 (*itr
).second
->SetAuraDuration((*itr
).second
->GetAuraMaxDuration());
1494 (*itr
).second
->SendAuraUpdate(false);
1500 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1502 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1504 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
1505 ((Player
*)this)->CastItemCombatSpell(((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
,i
), pVictim
, damageInfo
->attackType
);
1508 // victim's damage shield
1509 std::set
<Aura
*> alreadyDone
;
1510 uint32 removedAuras
= pVictim
->m_removedAuras
;
1511 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1512 for(AuraList::const_iterator i
= vDamageShields
.begin(), next
= vDamageShields
.begin(); i
!= vDamageShields
.end(); i
= next
)
1515 if (alreadyDone
.find(*i
) == alreadyDone
.end())
1517 alreadyDone
.insert(*i
);
1518 uint32 damage
=(*i
)->GetModifier()->m_amount
;
1519 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry((*i
)->GetId());
1522 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
1525 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1526 //damage-=absorb + resist;
1528 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4+4+4));
1529 data
<< uint64(pVictim
->GetGUID());
1530 data
<< uint64(GetGUID());
1531 data
<< uint32(spellProto
->Id
);
1532 data
<< uint32(damage
); // Damage
1533 data
<< uint32(0); // Overkill
1534 data
<< uint32(spellProto
->SchoolMask
);
1535 pVictim
->SendMessageToSet(&data
, true );
1537 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(spellProto
), spellProto
, true);
1539 if (pVictim
->m_removedAuras
> removedAuras
)
1541 removedAuras
= pVictim
->m_removedAuras
;
1542 next
= vDamageShields
.begin();
1550 void Unit::HandleEmoteCommand(uint32 anim_id
)
1552 WorldPacket
data( SMSG_EMOTE
, 12 );
1553 data
<< uint32(anim_id
);
1554 data
<< uint64(GetGUID());
1555 SendMessageToSet(&data
, true);
1558 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
1560 uint32 newdamage
= 0;
1561 float armor
= pVictim
->GetArmor();
1562 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
1563 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
1565 // Apply Player CR_ARMOR_PENETRATION rating
1566 if (GetTypeId()==TYPEID_PLAYER
)
1567 armor
*= 1.0f
- ((Player
*)this)->GetRatingBonusValue(CR_ARMOR_PENETRATION
) / 100.0f
;
1569 if (armor
< 0.0f
) armor
=0.0f
;
1571 float levelModifier
= getLevel();
1572 if ( levelModifier
> 59 )
1573 levelModifier
= levelModifier
+ (4.5f
* (levelModifier
-59));
1575 float tmpvalue
= 0.1f
* armor
/ (8.5f
* levelModifier
+ 40);
1576 tmpvalue
= tmpvalue
/(1.0f
+ tmpvalue
);
1580 if(tmpvalue
> 0.75f
)
1582 newdamage
= uint32(damage
- (damage
* tmpvalue
));
1584 return (newdamage
> 1) ? newdamage
: 1;
1587 void Unit::CalcAbsorbResist(Unit
*pVictim
,SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
)
1589 if(!pVictim
|| !pVictim
->isAlive() || !damage
)
1592 // Magic damage, check for resists
1593 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
1595 // Get base victim resistance for school
1596 float tmpvalue2
= (float)pVictim
->GetResistance(GetFirstSchoolInMask(schoolMask
));
1597 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
1598 tmpvalue2
+= (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
1600 tmpvalue2
*= (float)(0.15f
/ getLevel());
1601 if (tmpvalue2
< 0.0f
)
1603 if (tmpvalue2
> 0.75f
)
1605 uint32 ran
= urand(0, 100);
1606 uint32 faq
[4] = {24,6,4,6};
1609 for (uint8 i
= 0; i
< 4; i
++)
1611 Binom
+= 2400 *( powf(tmpvalue2
, i
) * powf( (1-tmpvalue2
), (4-i
)))/faq
[i
];
1617 if (damagetype
== DOT
&& m
== 4)
1618 *resist
+= uint32(damage
- 1);
1620 *resist
+= uint32(damage
* m
/ 4);
1621 if(*resist
> damage
)
1627 int32 RemainingDamage
= damage
- *resist
;
1629 // absorb without mana cost
1630 int32 reflectDamage
= 0;
1631 Aura
* reflectAura
= NULL
;
1632 AuraList
const& vSchoolAbsorb
= pVictim
->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1633 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(), next
; i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; i
= next
)
1637 if (((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1641 if((*i
)->GetSpellProto()->SpellFamilyName
==SPELLFAMILY_ROGUE
&& (*i
)->GetSpellProto()->SpellIconID
== 2109)
1643 if (((Player
*)pVictim
)->HasSpellCooldown(31231))
1645 if (pVictim
->GetHealth() <= RemainingDamage
)
1647 int32 chance
= (*i
)->GetModifier()->m_amount
;
1648 if (roll_chance_i(chance
))
1650 pVictim
->CastSpell(pVictim
,31231,true);
1651 ((Player
*)pVictim
)->AddSpellCooldown(31231,0,time(NULL
)+60);
1653 // with health > 10% lost health until health==10%, in other case no losses
1654 uint32 health10
= pVictim
->GetMaxHealth()/10;
1655 RemainingDamage
= pVictim
->GetHealth() > health10
? pVictim
->GetHealth() - health10
: 0;
1661 int32 currentAbsorb
;
1663 // Reflective Shield
1664 if ((pVictim
!= this) && (*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_PRIEST
&& (*i
)->GetSpellProto()->SpellFamilyFlags
== 0x1)
1666 if(Unit
* caster
= (*i
)->GetCaster())
1668 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
1669 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
1671 switch((*k
)->GetModifier()->m_miscvalue
)
1673 case 5065: // Rank 1
1674 case 5064: // Rank 2
1675 case 5063: // Rank 3
1677 if(RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
1678 reflectDamage
= (*i
)->GetModifier()->m_amount
* (*k
)->GetModifier()->m_amount
/100;
1680 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
1693 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
1695 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
1696 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
1697 next
= vSchoolAbsorb
.begin();
1701 currentAbsorb
= RemainingDamage
;
1702 (*i
)->GetModifier()->m_amount
-= RemainingDamage
;
1705 RemainingDamage
-= currentAbsorb
;
1707 // do not cast spells while looping auras; auras can get invalid otherwise
1709 pVictim
->CastCustomSpell(this, 33619, &reflectDamage
, NULL
, NULL
, true, NULL
, reflectAura
);
1711 // absorb by mana cost
1712 AuraList
const& vManaShield
= pVictim
->GetAurasByType(SPELL_AURA_MANA_SHIELD
);
1713 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
1717 // check damage school mask
1718 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1721 int32 currentAbsorb
;
1722 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
1723 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
1725 currentAbsorb
= RemainingDamage
;
1727 float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()];
1728 if(Player
*modOwner
= GetSpellModOwner())
1729 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
1731 int32 maxAbsorb
= int32(pVictim
->GetPower(POWER_MANA
) / manaMultiplier
);
1732 if (currentAbsorb
> maxAbsorb
)
1733 currentAbsorb
= maxAbsorb
;
1735 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
1736 if((*i
)->GetModifier()->m_amount
<= 0)
1738 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
1739 next
= vManaShield
.begin();
1742 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
1743 pVictim
->ApplyPowerMod(POWER_MANA
, manaReduction
, false);
1745 RemainingDamage
-= currentAbsorb
;
1748 // only split damage if not damaging yourself
1751 AuraList
const& vSplitDamageFlat
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
1752 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
1756 // check damage school mask
1757 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1760 // Damage can be splitted only if aura has an alive caster
1761 Unit
*caster
= (*i
)->GetCaster();
1762 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
1765 int32 currentAbsorb
;
1766 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
1767 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
1769 currentAbsorb
= RemainingDamage
;
1771 RemainingDamage
-= currentAbsorb
;
1773 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, currentAbsorb
, schoolMask
, 0, 0, false, 0, false);
1775 CleanDamage cleanDamage
= CleanDamage(currentAbsorb
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
1776 DealDamage(caster
, currentAbsorb
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
1779 AuraList
const& vSplitDamagePct
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
1780 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
1784 // check damage school mask
1785 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1788 // Damage can be splitted only if aura has an alive caster
1789 Unit
*caster
= (*i
)->GetCaster();
1790 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
1793 int32 splitted
= int32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
1795 RemainingDamage
-= splitted
;
1797 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, 0, 0, false, 0, false);
1799 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
1800 DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
1804 *absorb
= damage
- RemainingDamage
- *resist
;
1807 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
1809 if(hasUnitState(UNIT_STAT_CONFUSED
| UNIT_STAT_STUNNED
| UNIT_STAT_FLEEING
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
1812 if (!pVictim
->isAlive())
1815 if(IsNonMeleeSpellCasted(false))
1819 if (attType
== BASE_ATTACK
)
1820 hitInfo
= HITINFO_NORMALSWING2
;
1821 else if (attType
== OFF_ATTACK
)
1822 hitInfo
= HITINFO_LEFTSWING
;
1824 return; // ignore ranged case
1826 uint32 extraAttacks
= m_extraAttacks
;
1828 // melee attack spell casted at main hand attack only
1829 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
1831 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
1833 // not recent extra attack only at any non extra attack (melee spell case)
1834 if(!extra
&& extraAttacks
)
1836 while(m_extraAttacks
)
1838 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
1839 if(m_extraAttacks
> 0)
1847 CalcDamageInfo damageInfo
;
1848 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
1849 // Send log damage message to client
1850 SendAttackStateUpdate(&damageInfo
);
1851 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
1852 DealMeleeDamage(&damageInfo
,true);
1854 if (GetTypeId() == TYPEID_PLAYER
)
1855 DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
1856 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
1858 DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
1859 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
1861 // extra attack only at any non extra attack (normal case)
1862 if(!extra
&& extraAttacks
)
1864 while(m_extraAttacks
)
1866 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
1867 if(m_extraAttacks
> 0)
1873 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
1875 // This is only wrapper
1877 // Miss chance based on melee
1878 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
1880 // Critical hit chance
1881 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
1883 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
1884 float dodge_chance
= pVictim
->GetUnitDodgeChance();
1885 float block_chance
= pVictim
->GetUnitBlockChance();
1886 float parry_chance
= pVictim
->GetUnitParryChance();
1888 // Useful if want to specify crit & miss chances for melee, else it could be removed
1889 DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance
,crit_chance
,dodge_chance
,parry_chance
,block_chance
);
1891 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100));
1894 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const
1896 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1897 return MELEE_HIT_EVADE
;
1899 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
1900 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
1902 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
1903 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
1905 // bonus from skills is 0.04%
1906 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
1907 int32 sum
= 0, tmp
= 0;
1908 int32 roll
= urand (0, 10000);
1910 DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
1911 DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
1912 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
1916 if (tmp
> 0 && roll
< (sum
+= tmp
))
1918 DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS");
1919 return MELEE_HIT_MISS
;
1922 // always crit against a sitting target (except 0 crit chance)
1923 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
1925 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)");
1926 return MELEE_HIT_CRIT
;
1931 // only players can't dodge if attacker is behind
1932 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI
,this))
1934 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
1938 // Reduce dodge chance by attacker expertise rating
1939 if (GetTypeId() == TYPEID_PLAYER
)
1940 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
1942 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
1943 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
1946 if ( (tmp
> 0) // check if unit _can_ dodge
1947 && ((tmp
-= skillBonus
) > 0)
1948 && roll
< (sum
+= tmp
))
1950 DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
1951 return MELEE_HIT_DODGE
;
1955 // parry & block chances
1957 // check if attack comes from behind, nobody can parry or block if attacker is behind
1958 if (!pVictim
->HasInArc(M_PI
,this))
1960 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind.");
1964 // Reduce parry chance by attacker expertise rating
1965 if (GetTypeId() == TYPEID_PLAYER
)
1966 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
1968 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
1970 int32 tmp
= int32(parry_chance
);
1971 if ( (tmp
> 0) // check if unit _can_ parry
1972 && ((tmp
-= skillBonus
) > 0)
1973 && (roll
< (sum
+= tmp
)))
1975 DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp
, sum
);
1976 return MELEE_HIT_PARRY
;
1980 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
1983 if ( (tmp
> 0) // check if unit _can_ block
1984 && ((tmp
-= skillBonus
) > 0)
1985 && (roll
< (sum
+= tmp
)))
1987 DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
1988 return MELEE_HIT_BLOCK
;
1996 if (tmp
> 0 && roll
< (sum
+= tmp
))
1998 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
1999 return MELEE_HIT_CRIT
;
2002 // 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)
2003 if( attType
!= RANGED_ATTACK
&&
2004 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
2005 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
2006 getLevel() < pVictim
->getLevelForTarget(this) )
2008 // cap possible value (with bonuses > max skill)
2009 int32 skill
= attackerWeaponSkill
;
2010 int32 maxskill
= attackerMaxSkillValueForLevel
;
2011 skill
= (skill
> maxskill
) ? maxskill
: skill
;
2013 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
2014 tmp
= tmp
> 4000 ? 4000 : tmp
;
2015 if (roll
< (sum
+= tmp
))
2017 DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
2018 return MELEE_HIT_GLANCING
;
2022 // mobs can score crushing blows if they're 4 or more levels above victim
2023 if (getLevelForTarget(pVictim
) >= pVictim
->getLevelForTarget(this) + 4 &&
2024 // can be from by creature (if can) or from controlled player that considered as creature
2025 (GetTypeId()!=TYPEID_PLAYER
&& !((Creature
*)this)->isPet() &&
2026 !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) ||
2027 GetTypeId()==TYPEID_PLAYER
&& GetCharmerOrOwnerGUID()))
2029 // when their weapon skill is 15 or more above victim's defense skill
2030 tmp
= victimDefenseSkill
;
2031 int32 tmpmax
= victimMaxSkillValueForLevel
;
2032 // having defense above your maximum (from items, talents etc.) has no effect
2033 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
2034 // tmp = mob's level * 5 - player's current defense skill
2035 tmp
= attackerMaxSkillValueForLevel
- tmp
;
2038 // add 2% chance per lacking skill point, min. is 15%
2039 tmp
= tmp
* 200 - 1500;
2040 if (roll
< (sum
+= tmp
))
2042 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
2043 return MELEE_HIT_CRUSHING
;
2048 DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL");
2049 return MELEE_HIT_NORMAL
;
2052 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
2054 float min_damage
, max_damage
;
2056 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
2057 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
2063 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
2064 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
2067 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
2068 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
2071 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
2072 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
2074 // Just for good manner
2082 if (min_damage
> max_damage
)
2084 std::swap(min_damage
,max_damage
);
2087 if(max_damage
== 0.0f
)
2090 return urand((uint32
)min_damage
, (uint32
)max_damage
);
2093 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
2095 if(spellProto
->spellLevel
<= 0)
2098 float LvlPenalty
= 0.0f
;
2100 if(spellProto
->spellLevel
< 20)
2101 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
2102 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
2103 if(LvlFactor
> 1.0f
)
2106 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
2109 void Unit::SendAttackStart(Unit
* pVictim
)
2111 WorldPacket
data( SMSG_ATTACKSTART
, 16 );
2112 data
<< uint64(GetGUID());
2113 data
<< uint64(pVictim
->GetGUID());
2115 SendMessageToSet(&data
, true);
2116 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
2119 void Unit::SendAttackStop(Unit
* victim
)
2124 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
2125 data
.append(GetPackGUID());
2126 data
.append(victim
->GetPackGUID()); // can be 0x00...
2127 data
<< uint32(0); // can be 0x1
2128 SendMessageToSet(&data
, true);
2129 sLog
.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER
? "player" : "creature"), GetGUIDLow(), (victim
->GetTypeId()==TYPEID_PLAYER
? "player" : "creature"),victim
->GetGUIDLow());
2131 /*if(victim->GetTypeId() == TYPEID_UNIT)
2132 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
2135 bool Unit::isSpellBlocked(Unit
*pVictim
, SpellEntry
const *spellProto
, WeaponAttackType attackType
)
2137 if (pVictim
->HasInArc(M_PI
,this))
2139 /* Currently not exist spells with ignore block
2140 // Ignore combat result aura (parry/dodge check on prepare)
2141 AuraList const& ignore = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2142 for(AuraList::const_iterator i = ignore.begin(); i != ignore.end(); ++i)
2144 if (!(*i)->isAffectedOnSpell(spellProto))
2146 if ((*i)->GetModifier()->m_miscvalue == )
2151 // Check creatures flags_extra for disable block
2152 if(pVictim
->GetTypeId()==TYPEID_UNIT
&&
2153 ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
)
2156 float blockChance
= GetUnitBlockChance();
2157 blockChance
+= (GetWeaponSkillValue(attackType
) - pVictim
->GetMaxSkillValueForLevel() )*0.04;
2158 if (roll_chance_f(blockChance
))
2164 // Melee based spells can be miss, parry or dodge on this step
2165 // Crit or block - determined on damage calculation phase! (and can be both in some time)
2166 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
2168 // Calculate hit chance (more correct for chance mod)
2171 // PvP - PvE melee chances
2172 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2173 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
2175 HitChance
= 95 - leveldif
;
2177 HitChance
= 93 - (leveldif
- 2) * lchance
;
2179 // Hit chance depends from victim auras
2180 if(attType
== RANGED_ATTACK
)
2181 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2183 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2185 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2186 if(Player
*modOwner
= GetSpellModOwner())
2187 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
2190 float miss_chance
= 100.0f
- HitChance
;
2192 // Bonuses from attacker aura and ratings
2193 if (attType
== RANGED_ATTACK
)
2194 miss_chance
-= m_modRangedHitChance
;
2196 miss_chance
-= m_modMeleeHitChance
;
2198 // bonus from skills is 0.04%
2199 miss_chance
-= skillDiff
* 0.04f
;
2201 // Limit miss chance from 0 to 60%
2202 if (miss_chance
< 0.0f
)
2204 if (miss_chance
> 60.0f
)
2209 // Melee based spells hit result calculations
2210 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2212 WeaponAttackType attType
= BASE_ATTACK
;
2214 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
2215 attType
= RANGED_ATTACK
;
2217 // bonus from skills is 0.04% per skill Diff
2218 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
2219 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
2220 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
2222 uint32 roll
= urand (0, 10000);
2224 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
2226 uint32 tmp
= missChance
;
2228 return SPELL_MISS_MISS
;
2230 bool canDodge
= true;
2231 bool canParry
= true;
2233 // Same spells cannot be parry/dodge
2234 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
2235 return SPELL_MISS_NONE
;
2237 // Ranged attack cannot be parry/dodge
2238 if (attType
== RANGED_ATTACK
)
2239 return SPELL_MISS_NONE
;
2241 // Check for attack from behind
2242 if (!pVictim
->HasInArc(M_PI
,this))
2244 // Can`t dodge from behind in PvP (but its possible in PvE)
2245 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
2250 // Check creatures flags_extra for disable parry
2251 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
2253 uint32 flagEx
= ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
;
2254 if( flagEx
& CREATURE_FLAG_EXTRA_NO_PARRY
)
2257 // Ignore combat result aura
2258 AuraList
const& ignore
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
2259 for(AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
2261 if (!(*i
)->isAffectedOnSpell(spell
))
2263 switch((*i
)->GetModifier()->m_miscvalue
)
2265 case MELEE_HIT_DODGE
: canDodge
= false; break;
2266 case MELEE_HIT_BLOCK
: break; // Block check in hit step
2267 case MELEE_HIT_PARRY
: canParry
= false; break;
2269 DEBUG_LOG("Spell %u SPELL_AURA_IGNORE_COMBAT_RESULT have unhandled state %d", (*i
)->GetId(), (*i
)->GetModifier()->m_miscvalue
);
2277 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
2278 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2279 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2280 // Reduce dodge chance by attacker expertise rating
2281 if (GetTypeId() == TYPEID_PLAYER
)
2282 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2283 if (dodgeChance
< 0)
2288 return SPELL_MISS_DODGE
;
2294 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
2295 // Reduce parry chance by attacker expertise rating
2296 if (GetTypeId() == TYPEID_PLAYER
)
2297 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2298 if (parryChance
< 0)
2303 return SPELL_MISS_PARRY
;
2306 return SPELL_MISS_NONE
;
2309 // TODO need use unit spell resistances in calculations
2310 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2312 // Can`t miss on dead target (on skinning for example)
2313 if (!pVictim
->isAlive())
2314 return SPELL_MISS_NONE
;
2316 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
2317 // PvP - PvE spell misschances per leveldif > 2
2318 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
2319 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2321 // Base hit chance from attacker and victim levels
2324 modHitChance
= 96 - leveldif
;
2326 modHitChance
= 94 - (leveldif
- 2) * lchance
;
2328 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2329 if(Player
*modOwner
= GetSpellModOwner())
2330 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
2331 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
2332 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
2333 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
2334 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
2335 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
2336 if (IsAreaOfEffectSpell(spell
))
2337 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
2338 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
2339 if (IsDispelSpell(spell
))
2340 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
2341 // Chance resist mechanic (select max value from every mechanic spell effect)
2342 int32 resist_mech
= 0;
2343 // Get effects mechanic and chance
2344 for(int eff
= 0; eff
< 3; ++eff
)
2346 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2349 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2350 if (resist_mech
< temp
)
2355 modHitChance
-=resist_mech
;
2357 // Chance resist debuff
2358 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
2360 int32 HitChance
= modHitChance
* 100;
2361 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
2362 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
2364 // Decrease hit chance from victim rating bonus
2365 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2366 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
2368 if (HitChance
< 100) HitChance
= 100;
2369 if (HitChance
> 9900) HitChance
= 9900;
2371 uint32 rand
= urand(0,10000);
2372 if (rand
> HitChance
)
2373 return SPELL_MISS_RESIST
;
2374 return SPELL_MISS_NONE
;
2377 // Calculate spell hit result can be:
2378 // Every spell can: Evade/Immune/Reflect/Sucesful hit
2379 // For melee based spells:
2385 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
2387 // Return evade for units in evade mode
2388 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2389 return SPELL_MISS_EVADE
;
2392 if (pVictim
->IsImmunedToSpell(spell
))
2393 return SPELL_MISS_IMMUNE
;
2395 // All positive spells can`t miss
2396 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
2397 if (IsPositiveSpell(spell
->Id
))
2398 return SPELL_MISS_NONE
;
2401 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
)))
2402 return SPELL_MISS_IMMUNE
;
2404 // Try victim reflect spell
2407 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
2408 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
2409 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
2410 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
2411 reflectchance
+= (*i
)->GetModifier()->m_amount
;
2412 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
2414 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
2415 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
2416 return SPELL_MISS_REFLECT
;
2420 switch (spell
->DmgClass
)
2422 case SPELL_DAMAGE_CLASS_RANGED
:
2423 case SPELL_DAMAGE_CLASS_MELEE
:
2424 return MeleeSpellHitResult(pVictim
, spell
);
2425 case SPELL_DAMAGE_CLASS_NONE
:
2426 case SPELL_DAMAGE_CLASS_MAGIC
:
2427 return MagicSpellHitResult(pVictim
, spell
);
2429 return SPELL_MISS_NONE
;
2432 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
2437 // Base misschance 5%
2438 float misschance
= 5.0f
;
2440 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
2441 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
2443 bool isNormal
= false;
2444 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
2446 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
2452 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
2462 // PvP : PvE melee misschances per leveldif > 2
2463 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2465 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2469 // Hit chance from attacker based on ratings and auras
2470 float m_modHitChance
;
2471 if (attType
== RANGED_ATTACK
)
2472 m_modHitChance
= m_modRangedHitChance
;
2474 m_modHitChance
= m_modMeleeHitChance
;
2477 misschance
+= (leveldif
- m_modHitChance
);
2479 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
2481 // Hit chance for victim based on ratings
2482 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2484 if (attType
== RANGED_ATTACK
)
2485 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
2487 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
2490 // Modify miss chance by victim auras
2491 if(attType
== RANGED_ATTACK
)
2492 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2494 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2496 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
2497 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
2498 misschance
-= skillBonus
* 0.04f
;
2500 // Limit miss chance from 0 to 60%
2501 if ( misschance
< 0.0f
)
2503 if ( misschance
> 60.0f
)
2509 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
2511 if(GetTypeId() == TYPEID_PLAYER
)
2513 // in PvP use full skill instead current skill value
2514 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
2515 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
2516 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
2517 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
2521 return GetUnitMeleeSkill(target
);
2524 float Unit::GetUnitDodgeChance() const
2526 if(hasUnitState(UNIT_STAT_STUNNED
))
2528 if( GetTypeId() == TYPEID_PLAYER
)
2529 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
2532 if(((Creature
const*)this)->isTotem())
2537 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
2538 return dodge
> 0.0f
? dodge
: 0.0f
;
2543 float Unit::GetUnitParryChance() const
2545 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
2548 float chance
= 0.0f
;
2550 if(GetTypeId() == TYPEID_PLAYER
)
2552 Player
const* player
= (Player
const*)this;
2553 if(player
->CanParry() )
2555 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true);
2557 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true);
2560 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
2563 else if(GetTypeId() == TYPEID_UNIT
)
2565 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
2568 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
2572 return chance
> 0.0f
? chance
: 0.0f
;
2575 float Unit::GetUnitBlockChance() const
2577 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
2580 if(GetTypeId() == TYPEID_PLAYER
)
2582 Player
const* player
= (Player
const*)this;
2583 if(player
->CanBlock() )
2585 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
2586 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
2587 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
2589 // is player but has no block ability or no not broken shield equipped
2594 if(((Creature
const*)this)->isTotem())
2599 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
2600 return block
> 0.0f
? block
: 0.0f
;
2605 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
2609 if(GetTypeId() == TYPEID_PLAYER
)
2614 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
2617 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
2620 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
2622 // Just for good manner
2631 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
2635 if(attackType
== RANGED_ATTACK
)
2636 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
2638 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
2640 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
2642 // reduce crit chance from Rating for players
2643 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2645 if (attackType
==RANGED_ATTACK
)
2646 crit
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_RANGED
);
2648 crit
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
);
2651 // Apply crit chance from defence skill
2652 crit
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
2659 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
2662 if(GetTypeId() == TYPEID_PLAYER
)
2664 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true);
2666 // feral or unarmed skill only for base attack
2667 if(attType
!= BASE_ATTACK
&& !item
)
2670 if(((Player
*)this)->IsInFeralForm())
2671 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
2673 // weapon skill or (unarmed for base attack)
2674 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
2676 // in PvP use full skill instead current skill value
2677 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
2678 ? ((Player
*)this)->GetMaxSkillValue(skill
)
2679 : ((Player
*)this)->GetSkillValue(skill
);
2680 // Modify value from ratings
2681 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
2684 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
2685 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
2686 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
2690 value
= GetUnitMeleeSkill(target
);
2694 void Unit::_UpdateSpells( uint32 time
)
2696 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
2697 _UpdateAutoRepeatSpell();
2699 // remove finished spells from current pointers
2700 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
2702 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
2704 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
2705 m_currentSpells
[i
] = NULL
; // remove pointer
2709 // TODO: Find a better way to prevent crash when multiple auras are removed.
2711 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
2713 (*i
).second
->SetUpdated(false);
2715 for (AuraMap::iterator i
= m_Auras
.begin(), next
; i
!= m_Auras
.end(); i
= next
)
2721 // prevent double update
2722 if ((*i
).second
->IsUpdated())
2724 (*i
).second
->SetUpdated(true);
2725 (*i
).second
->Update( time
);
2726 // several auras can be deleted due to update
2729 if (m_Auras
.empty()) break;
2730 next
= m_Auras
.begin();
2736 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
2740 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
2755 if(!m_gameObj
.empty())
2757 std::list
<GameObject
*>::iterator ite1
, dnext1
;
2758 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
2761 //(*i)->Update( difftime );
2762 if( !(*ite1
)->isSpawned() )
2764 (*ite1
)->SetOwnerGUID(0);
2765 (*ite1
)->SetRespawnTime(0);
2767 dnext1
= m_gameObj
.erase(ite1
);
2775 void Unit::_UpdateAutoRepeatSpell()
2777 //check "realtime" interrupts
2778 if ( (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) )
2780 // cancel wand shoot
2781 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
2782 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
2783 m_AutoRepeatFirstCast
= true;
2788 if ( m_AutoRepeatFirstCast
&& getAttackTimer(RANGED_ATTACK
) < 500 )
2789 setAttackTimer(RANGED_ATTACK
,500);
2790 m_AutoRepeatFirstCast
= false;
2793 if (isAttackReady(RANGED_ATTACK
))
2795 // Check if able to cast
2796 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CanCast(true))
2798 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
2803 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
2804 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
2806 // all went good, reset attack
2807 resetAttackTimer(RANGED_ATTACK
);
2811 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
2813 assert(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
2815 uint32 CSpellType
= pSpell
->GetCurrentContainer();
2817 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
2819 // break same type spell if it is not delayed
2820 InterruptSpell(CSpellType
,false);
2822 // special breakage effects:
2825 case CURRENT_GENERIC_SPELL
:
2827 // generic spells always break channeled not delayed spells
2828 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
2830 // autorepeat breaking
2831 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
2833 // break autorepeat if not Auto Shot
2834 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
2835 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
2836 m_AutoRepeatFirstCast
= true;
2840 case CURRENT_CHANNELED_SPELL
:
2842 // channel spells always break generic non-delayed and any channeled spells
2843 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
2844 InterruptSpell(CURRENT_CHANNELED_SPELL
);
2846 // it also does break autorepeat if not Auto Shot
2847 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
2848 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
2849 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
2852 case CURRENT_AUTOREPEAT_SPELL
:
2854 // only Auto Shoot does not break anything
2855 if (pSpell
->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
2857 // generic autorepeats break generic non-delayed and channeled non-delayed spells
2858 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
2859 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
2861 // special action: set first cast flag
2862 m_AutoRepeatFirstCast
= true;
2867 // other spell types don't break anything now
2871 // current spell (if it is still here) may be safely deleted now
2872 if (m_currentSpells
[CSpellType
])
2873 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
2875 // set new current spell
2876 m_currentSpells
[CSpellType
] = pSpell
;
2877 pSpell
->SetReferencedFromCurrent(true);
2880 void Unit::InterruptSpell(uint32 spellType
, bool withDelayed
)
2882 assert(spellType
< CURRENT_MAX_SPELL
);
2884 if(m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
2886 // send autorepeat cancel message for autorepeat spells
2887 if (spellType
== CURRENT_AUTOREPEAT_SPELL
)
2889 if(GetTypeId()==TYPEID_PLAYER
)
2890 ((Player
*)this)->SendAutoRepeatCancel();
2893 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
2894 m_currentSpells
[spellType
]->cancel();
2895 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
2896 m_currentSpells
[spellType
] = NULL
;
2900 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
2902 // We don't do loop here to explicitly show that melee spell is excluded.
2903 // Maybe later some special spells will be excluded too.
2905 // generic spells are casted when they are not finished and not delayed
2906 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
2907 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
2908 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
2911 // channeled spells may be delayed, but they are still considered casted
2912 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
2913 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
2916 // autorepeat spells may be finished or delayed, but they are still considered casted
2917 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
2923 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
2925 // generic spells are interrupted if they are not finished or delayed
2926 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
2928 if ( (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
2929 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
2930 m_currentSpells
[CURRENT_GENERIC_SPELL
]->cancel();
2931 m_currentSpells
[CURRENT_GENERIC_SPELL
]->SetReferencedFromCurrent(false);
2932 m_currentSpells
[CURRENT_GENERIC_SPELL
] = NULL
;
2935 // autorepeat spells are interrupted if they are not finished or delayed
2936 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
2938 // send disable autorepeat packet in any case
2939 if(GetTypeId()==TYPEID_PLAYER
)
2940 ((Player
*)this)->SendAutoRepeatCancel();
2942 if ( (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
2943 (withDelayed
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
2944 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->cancel();
2945 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->SetReferencedFromCurrent(false);
2946 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] = NULL
;
2949 // channeled spells are interrupted if they are not finished, even if they are delayed
2950 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
2952 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
)
2953 m_currentSpells
[CURRENT_CHANNELED_SPELL
]->cancel();
2954 m_currentSpells
[CURRENT_CHANNELED_SPELL
]->SetReferencedFromCurrent(false);
2955 m_currentSpells
[CURRENT_CHANNELED_SPELL
] = NULL
;
2959 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
2961 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
2962 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
2963 return m_currentSpells
[i
];
2967 bool Unit::isInFront(Unit
const* target
, float distance
, float arc
) const
2969 return IsWithinDistInMap(target
, distance
) && HasInArc( arc
, target
);
2972 void Unit::SetInFront(Unit
const* target
)
2974 SetOrientation(GetAngle(target
));
2977 bool Unit::isInBack(Unit
const* target
, float distance
, float arc
) const
2979 return IsWithinDistInMap(target
, distance
) && !HasInArc( 2 * M_PI
- arc
, target
);
2982 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
2985 return c
->canSwim();
2987 return c
->canWalk() || c
->canFly();
2990 bool Unit::IsInWater() const
2992 return MapManager::Instance().GetBaseMap(GetMapId())->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
2995 bool Unit::IsUnderWater() const
2997 return MapManager::Instance().GetBaseMap(GetMapId())->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3000 void Unit::DeMorph()
3002 SetDisplayId(GetNativeDisplayId());
3005 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3009 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3010 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3011 modifier
+= (*i
)->GetModifier()->m_amount
;
3016 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3018 float multiplier
= 1.0f
;
3020 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3021 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3022 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3027 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3031 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3032 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3033 if ((*i
)->GetModifier()->m_amount
> modifier
)
3034 modifier
= (*i
)->GetModifier()->m_amount
;
3039 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
3043 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3044 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3045 if ((*i
)->GetModifier()->m_amount
< modifier
)
3046 modifier
= (*i
)->GetModifier()->m_amount
;
3051 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3055 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3056 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3058 Modifier
* mod
= (*i
)->GetModifier();
3059 if (mod
->m_miscvalue
& misc_mask
)
3060 modifier
+= mod
->m_amount
;
3065 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3067 float multiplier
= 1.0f
;
3069 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3070 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3072 Modifier
* mod
= (*i
)->GetModifier();
3073 if (mod
->m_miscvalue
& misc_mask
)
3074 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3079 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3083 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3084 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3086 Modifier
* mod
= (*i
)->GetModifier();
3087 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
> modifier
)
3088 modifier
= mod
->m_amount
;
3094 int32
Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3098 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3099 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3101 Modifier
* mod
= (*i
)->GetModifier();
3102 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
< modifier
)
3103 modifier
= mod
->m_amount
;
3109 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3113 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3114 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3116 Modifier
* mod
= (*i
)->GetModifier();
3117 if (mod
->m_miscvalue
== misc_value
)
3118 modifier
+= mod
->m_amount
;
3123 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
3125 float multiplier
= 1.0f
;
3127 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3128 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3130 Modifier
* mod
= (*i
)->GetModifier();
3131 if (mod
->m_miscvalue
== misc_value
)
3132 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3137 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3141 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3142 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3144 Modifier
* mod
= (*i
)->GetModifier();
3145 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
3146 modifier
= mod
->m_amount
;
3152 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3156 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3157 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3159 Modifier
* mod
= (*i
)->GetModifier();
3160 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
< modifier
)
3161 modifier
= mod
->m_amount
;
3167 bool Unit::AddAura(Aura
*Aur
)
3169 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
3170 if( !isAlive() && Aur
->GetId() != 20584 && Aur
->GetId() != 8326 && Aur
->GetId() != 2584 &&
3171 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
3177 if(Aur
->GetTarget() != this)
3179 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
3180 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
3181 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
3186 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
3188 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
3189 AuraMap::iterator i
= m_Auras
.find( spair
);
3191 // take out same spell
3192 if (i
!= m_Auras
.end())
3194 // passive and persistent auras can stack with themselves any number of times
3195 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
3197 // replace aura if next will > spell StackAmount
3198 if(aurSpellInfo
->StackAmount
)
3200 if(m_Auras
.count(spair
) >= aurSpellInfo
->StackAmount
)
3201 RemoveAura(i
,AURA_REMOVE_BY_STACK
);
3203 // if StackAmount==0 not allow auras from same caster
3206 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
3208 if(i2
->second
->GetCasterGUID()==Aur
->GetCasterGUID())
3210 // can be only single (this check done at _each_ aura add
3211 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3216 switch(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()])
3219 case SPELL_AURA_PERIODIC_DAMAGE
: // allow stack
3220 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
3221 case SPELL_AURA_PERIODIC_LEECH
:
3222 case SPELL_AURA_PERIODIC_HEAL
:
3223 case SPELL_AURA_OBS_MOD_HEALTH
:
3224 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3225 case SPELL_AURA_PERIODIC_ENERGIZE
:
3226 case SPELL_AURA_OBS_MOD_MANA
:
3227 case SPELL_AURA_POWER_BURN_MANA
:
3229 default: // not allow
3230 // can be only single (this check done at _each_ aura add
3231 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3243 // passive auras not stacable with other ranks
3244 if (!IsPassiveSpellStackableWithRanks(aurSpellInfo
))
3246 if (!RemoveNoStackAurasDueToAura(Aur
))
3249 return false; // couldn't remove conflicting aura with higher rank
3253 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
3254 if (IsSingleTargetSpell(aurSpellInfo
) && Aur
->GetTarget())
3256 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
3259 Unit
* caster
= Aur
->GetCaster();
3260 if(!caster
) // caster deleted and not required adding scAura
3263 bool restart
= false;
3264 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3265 for(AuraList::iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
3267 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
3268 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
3270 if ((*itr
)->IsInUse())
3272 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());
3275 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
3284 scAuras
.push_back(Aur
);
3290 // add aura, register in lists and arrays
3292 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
3293 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
3295 m_modAuras
[Aur
->GetModifier()->m_auraname
].push_back(Aur
);
3298 Aur
->ApplyModifier(true,true);
3299 sLog
.outDebug("Aura %u now is in use", Aur
->GetModifier()->m_auraname
);
3303 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
3305 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3308 AuraMap::iterator i
,next
;
3309 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3313 uint32 i_spellId
= (*i
).second
->GetId();
3314 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
3316 if(spellmgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
3318 RemoveAurasDueToSpell(i_spellId
);
3320 if( m_Auras
.empty() )
3323 next
= m_Auras
.begin();
3329 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
3334 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
3338 uint32 spellId
= Aur
->GetId();
3340 // passive spell special case (only non stackable with ranks)
3341 if(IsPassiveSpell(spellId
))
3343 if(IsPassiveSpellStackableWithRanks(spellProto
))
3347 uint32 effIndex
= Aur
->GetEffIndex();
3349 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
3351 AuraMap::iterator i
,next
;
3352 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3356 if (!(*i
).second
) continue;
3358 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
3363 uint32 i_spellId
= i_spellProto
->Id
;
3365 // early checks that spellId is passive non stackable spell
3366 if(IsPassiveSpell(i_spellId
))
3368 // passive non-stackable spells not stackable only for same caster
3369 if(Aur
->GetCasterGUID()!=i
->second
->GetCasterGUID())
3372 // passive non-stackable spells not stackable only with another rank of same spell
3373 if (!spellmgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3377 uint32 i_effIndex
= (*i
).second
->GetEffIndex();
3379 if(i_spellId
== spellId
) continue;
3381 bool is_triggered_by_spell
= false;
3382 // prevent triggered aura of removing aura that triggered it
3383 for(int j
= 0; j
< 3; ++j
)
3384 if (i_spellProto
->EffectTriggerSpell
[j
] == spellProto
->Id
)
3385 is_triggered_by_spell
= true;
3386 if (is_triggered_by_spell
) continue;
3388 for(int j
= 0; j
< 3; ++j
)
3390 // prevent remove dummy triggered spells at next effect aura add
3391 switch(spellProto
->Effect
[j
]) // main spell auras added added after triggered spell
3393 case SPELL_EFFECT_DUMMY
:
3396 case 5420: if(i_spellId
==34123) is_triggered_by_spell
= true; break;
3401 if(is_triggered_by_spell
)
3404 // prevent remove form main spell by triggered passive spells
3405 switch(i_spellProto
->EffectApplyAuraName
[j
]) // main aura added before triggered spell
3407 case SPELL_AURA_MOD_SHAPESHIFT
:
3410 case 24858: if(spellId
==24905) is_triggered_by_spell
= true; break;
3411 case 33891: if(spellId
==5420 || spellId
==34123) is_triggered_by_spell
= true; break;
3412 case 34551: if(spellId
==22688) is_triggered_by_spell
= true; break;
3418 if(!is_triggered_by_spell
)
3420 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
3422 bool is_sspc
= IsSingleFromSpellSpecificPerCaster(spellId_spec
,i_spellId_spec
);
3424 if( is_sspc
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
3426 // cannot remove higher rank
3427 if (spellmgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3428 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3431 // Its a parent aura (create this aura in ApplyModifier)
3432 if ((*i
).second
->IsInUse())
3434 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());
3437 RemoveAurasDueToSpell(i_spellId
);
3439 if( m_Auras
.empty() )
3442 next
= m_Auras
.begin();
3444 else if( !is_sspc
&& spellmgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
3446 // Its a parent aura (create this aura in ApplyModifier)
3447 if ((*i
).second
->IsInUse())
3449 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());
3452 RemoveAurasDueToSpell(i_spellId
);
3454 if( m_Auras
.empty() )
3457 next
= m_Auras
.begin();
3459 // Potions stack aura by aura (elixirs/flask already checked)
3460 else if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
3462 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
3464 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3465 return false; // cannot remove higher rank
3467 // Its a parent aura (create this aura in ApplyModifier)
3468 if ((*i
).second
->IsInUse())
3470 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());
3482 void Unit::RemoveAura(uint32 spellId
, uint32 effindex
, Aura
* except
)
3484 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
3485 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
3487 if(iter
->second
!=except
)
3490 iter
= m_Auras
.lower_bound(spair
);
3497 void Unit::RemoveAurasDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
3499 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3501 Aura
*aur
= iter
->second
;
3502 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3504 // Custom dispel case
3505 // Unstable Affliction
3506 if (aur
->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (aur
->GetSpellProto()->SpellFamilyFlags
& 0x010000000000LL
))
3508 int32 damage
= aur
->GetModifier()->m_amount
*9;
3509 uint64 caster_guid
= aur
->GetCasterGUID();
3512 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
3514 // backfire damage and silence
3515 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,caster_guid
);
3517 iter
= m_Auras
.begin(); // iterator can be invalidate at cast if self-dispel
3520 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
3527 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
3529 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3531 Aura
*aur
= iter
->second
;
3532 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3534 int32 basePoints
= aur
->GetBasePoints();
3535 // construct the new aura for the attacker
3536 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
);
3540 // set its duration and maximum duration
3541 // max duration 2 minutes (in msecs)
3542 int32 dur
= aur
->GetAuraDuration();
3543 const int32 max_dur
= 2*MINUTE
*1000;
3544 new_aur
->SetAuraMaxDuration( max_dur
> dur
? dur
: max_dur
);
3545 new_aur
->SetAuraDuration( max_dur
> dur
? dur
: max_dur
);
3547 // add the new aura to stealer
3548 stealer
->AddAura(new_aur
);
3550 // Remove aura as dispel
3551 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
3558 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
3560 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3562 if (iter
->second
->GetId() == spellId
)
3563 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
3569 void Unit::RemoveAurasWithDispelType( DispelType type
)
3571 // Create dispel mask by dispel type
3572 uint32 dispelMask
= GetDispellMask(type
);
3573 // Dispel all existing auras vs current dispel type
3574 AuraMap
& auras
= GetAuras();
3575 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
3577 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
3578 if( (1<<spell
->Dispel
) & dispelMask
)
3581 RemoveAurasDueToSpell(spell
->Id
);
3582 itr
= auras
.begin();
3589 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, uint32 effindex
)
3591 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
3592 if(iter
!= m_Auras
.end())
3596 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
)
3598 for (int i
= 0; i
< 3; ++i
)
3599 RemoveAura(spellId
,i
,except
);
3602 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
3604 for (int k
=0; k
< 3; ++k
)
3606 spellEffectPair spair
= spellEffectPair(spellId
, k
);
3607 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
3609 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
3612 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
3620 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
3622 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3624 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
3631 void Unit::RemoveNotOwnSingleTargetAuras()
3633 // single target auras from other casters
3634 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3636 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
3642 // single target auras at other targets
3643 AuraList
& scAuras
= GetSingleCastAuras();
3644 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
3647 if (aura
->GetTarget()!=this)
3649 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
3650 aura
->GetTarget()->RemoveAura(aura
->GetId(),aura
->GetEffIndex());
3651 iter
= scAuras
.begin();
3659 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
3661 Aura
* Aur
= i
->second
;
3662 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
3664 Unit
* caster
= NULL
;
3665 if (IsSingleTargetSpell(AurSpellInfo
))
3667 caster
= Aur
->GetCaster();
3670 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3671 scAuras
.remove(Aur
);
3675 sLog
.outError("Couldn't find the caster of the single target aura, may crash later!");
3680 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
3681 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
3683 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
3687 Aur
->SetRemoveMode(mode
);
3688 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
3689 // remove aura from list before to prevent deleting it before
3691 ++m_removedAuras
; // internal count used by unit update
3693 // Statue unsummoned at aura remove
3694 Totem
* statue
= NULL
;
3695 bool caster_channeled
= false;
3696 if(IsChanneledSpell(AurSpellInfo
))
3698 if(!caster
) // can be already located for IsSingleTargetSpell case
3699 caster
= Aur
->GetCaster();
3703 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
3704 statue
= ((Totem
*)caster
);
3706 caster_channeled
= caster
==this;
3710 sLog
.outDebug("Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
3711 Aur
->ApplyModifier(false,true);
3715 if(caster_channeled
)
3716 RemoveAurasAtChanneledTarget (AurSpellInfo
);
3721 // only way correctly remove all auras from list
3722 if( m_Auras
.empty() )
3725 i
= m_Auras
.begin();
3728 void Unit::RemoveAllAuras()
3730 while (!m_Auras
.empty())
3732 AuraMap::iterator iter
= m_Auras
.begin();
3737 void Unit::RemoveArenaAuras(bool onleave
)
3739 // in join, remove positive buffs, on end, remove negative
3740 // used to remove positive visible auras in arenas
3741 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
3743 if ( !(iter
->second
->GetSpellProto()->AttributesEx4
& (1<<21)) // don't remove stances, shadowform, pally/hunter auras
3744 && !iter
->second
->IsPassive() // don't remove passive auras
3745 && (!(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)
3746 && (iter
->second
->IsPositive() ^ onleave
)) // remove positive buffs on enter, negative buffs on leave
3753 void Unit::RemoveAllAurasOnDeath()
3755 // used just after dieing to remove all visible auras
3756 // and disable the mods for the passive ones
3757 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
3759 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
3760 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
3766 void Unit::DelayAura(uint32 spellId
, uint32 effindex
, int32 delaytime
)
3768 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
3769 if (iter
!= m_Auras
.end())
3771 if (iter
->second
->GetAuraDuration() < delaytime
)
3772 iter
->second
->SetAuraDuration(0);
3774 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
3775 iter
->second
->SendAuraUpdate(false);
3776 sLog
.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter
->second
->GetModifier()->m_auraname
, GetGUIDLow(), iter
->second
->GetAuraDuration());
3780 void Unit::_RemoveAllAuraMods()
3782 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
3784 (*i
).second
->ApplyModifier(false);
3788 void Unit::_ApplyAllAuraMods()
3790 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
3792 (*i
).second
->ApplyModifier(true);
3796 Aura
* Unit::GetAura(uint32 spellId
, uint32 effindex
)
3798 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
3799 if (iter
!= m_Auras
.end())
3800 return iter
->second
;
3804 bool Unit::HasAura(uint32 spellId
) const
3806 for (int i
= 0; i
< 3 ; ++i
)
3808 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, i
));
3809 if (iter
!= m_Auras
.end())
3815 void Unit::AddDynObject(DynamicObject
* dynObj
)
3817 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
3820 void Unit::RemoveDynObject(uint32 spellid
)
3822 if(m_dynObjGUIDs
.empty())
3824 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
3826 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
3829 i
= m_dynObjGUIDs
.erase(i
);
3831 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
3834 i
= m_dynObjGUIDs
.erase(i
);
3841 void Unit::RemoveAllDynObjects()
3843 while(!m_dynObjGUIDs
.empty())
3845 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
3848 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
3852 DynamicObject
* Unit::GetDynObject(uint32 spellId
, uint32 effIndex
)
3854 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
3856 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
3859 i
= m_dynObjGUIDs
.erase(i
);
3863 if (dynObj
->GetSpellId() == spellId
&& dynObj
->GetEffIndex() == effIndex
)
3870 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
3872 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
3874 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
3877 i
= m_dynObjGUIDs
.erase(i
);
3881 if (dynObj
->GetSpellId() == spellId
)
3888 void Unit::AddGameObject(GameObject
* gameObj
)
3890 assert(gameObj
&& gameObj
->GetOwnerGUID()==0);
3891 m_gameObj
.push_back(gameObj
);
3892 gameObj
->SetOwnerGUID(GetGUID());
3895 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
3897 assert(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
3899 // GO created by some spell
3900 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
3902 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
3903 // Need activate spell use for owner
3904 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
3905 ((Player
*)this)->SendCooldownEvent(createBySpell
);
3907 gameObj
->SetOwnerGUID(0);
3908 m_gameObj
.remove(gameObj
);
3911 gameObj
->SetRespawnTime(0);
3916 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
3918 if(m_gameObj
.empty())
3920 std::list
<GameObject
*>::iterator i
, next
;
3921 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
3924 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
3926 (*i
)->SetOwnerGUID(0);
3929 (*i
)->SetRespawnTime(0);
3933 next
= m_gameObj
.erase(i
);
3940 void Unit::RemoveAllGameObjects()
3942 // remove references to unit
3943 for(std::list
<GameObject
*>::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
3945 (*i
)->SetOwnerGUID(0);
3946 (*i
)->SetRespawnTime(0);
3948 i
= m_gameObj
.erase(i
);
3952 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
3954 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size
3955 data
.append(log
->target
->GetPackGUID());
3956 data
.append(log
->attacker
->GetPackGUID());
3957 data
<< uint32(log
->SpellID
);
3958 data
<< uint32(log
->damage
); //damage amount
3960 data
<< uint8 (log
->schoolMask
); //damage school
3961 data
<< uint32(log
->absorb
); //AbsorbedDamage
3962 data
<< uint32(log
->resist
); //resist
3963 data
<< uint8 (log
->phusicalLog
); // damsge type? flag
3964 data
<< uint8 (log
->unused
); //unused
3965 data
<< uint32(log
->blocked
); //blocked
3966 data
<< uint32(log
->HitInfo
);
3967 data
<< uint8 (0); // flag to use extend data
3968 SendMessageToSet( &data
, true );
3971 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
,uint32 SpellID
,uint32 Damage
, SpellSchoolMask damageSchoolMask
,uint32 AbsorbedDamage
, uint32 Resist
,bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
3973 sLog
.outDebug("Sending: SMSG_SPELLNONMELEEDAMAGELOG");
3974 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size
3975 data
.append(target
->GetPackGUID());
3976 data
.append(GetPackGUID());
3977 data
<< uint32(SpellID
);
3978 data
<< uint32(Damage
-AbsorbedDamage
-Resist
-Blocked
);
3979 data
<< uint32(0); // wotlk
3980 data
<< uint8(damageSchoolMask
); // spell school
3981 data
<< uint32(AbsorbedDamage
); // AbsorbedDamage
3982 data
<< uint32(Resist
); // resist
3983 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
3984 data
<< uint8(0); // unk isFromAura
3985 data
<< uint32(Blocked
); // blocked
3986 data
<< uint32(CriticalHit
? 0x27 : 0x25); // hitType, flags: 0x2 - SPELL_HIT_TYPE_CRIT, 0x10 - replace caster?
3987 data
<< uint8(0); // isDebug?
3988 SendMessageToSet( &data
, true );
3991 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
3993 // Not much to do if no flags are set.
3995 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
3996 // Now go on with a victim's events'n'auras
3997 // Not much to do if no flags are set or there is no victim
3998 if(pVictim
&& pVictim
->isAlive() && procVictim
)
3999 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4002 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4004 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4005 data
<< uint32(spellID
);
4006 data
<< uint64(GetGUID());
4007 data
<< uint8(0); // can be 0 or 1
4008 data
<< uint32(1); // target count
4009 // for(i = 0; i < target count; ++i)
4010 data
<< uint64(target
->GetGUID()); // target GUID
4011 data
<< uint8(missInfo
);
4013 SendMessageToSet(&data
, true);
4016 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4019 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, (16+45)); // we guess size
4020 data
<< (uint32
)damageInfo
->HitInfo
;
4021 data
.append(GetPackGUID());
4022 data
.append(damageInfo
->target
->GetPackGUID());
4023 data
<< (uint32
)(damageInfo
->damage
); // Full damage
4024 data
<< uint32(0); // overkill value
4026 data
<< (uint8
)count
; // Sub damage count
4028 for(int i
= 0; i
< count
; ++i
)
4030 data
<< (uint32
)(damageInfo
->damageSchoolMask
); // School of sub damage
4031 data
<< (float)damageInfo
->damage
; // sub damage
4032 data
<< (uint32
)damageInfo
->damage
; // Sub Damage
4035 if(damageInfo
->HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4037 for(int i
= 0; i
< count
; ++i
)
4038 data
<< (uint32
)damageInfo
->absorb
; // Absorb
4041 if(damageInfo
->HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4043 for(int i
= 0; i
< count
; ++i
)
4044 data
<< (uint32
)damageInfo
->resist
; // Resist
4047 data
<< (uint32
)damageInfo
->TargetState
;
4051 if(damageInfo
->HitInfo
& HITINFO_BLOCK
)
4052 data
<< (uint32
)damageInfo
->blocked_amount
;
4054 if(damageInfo
->HitInfo
& HITINFO_UNK3
)
4057 if(damageInfo
->HitInfo
& HITINFO_UNK1
)
4068 for(uint8 i
= 0; i
< 5; ++i
)
4076 SendMessageToSet( &data
, true );
4079 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8 SwingType
, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4081 sLog
.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4083 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, (16+45)); // we guess size
4084 data
<< uint32(HitInfo
); // flags
4085 data
.append(GetPackGUID());
4086 data
.append(target
->GetPackGUID());
4087 data
<< uint32(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);// damage
4088 data
<< uint32(0); // overkill value
4090 data
<< (uint8
)SwingType
; // count?
4092 // for(i = 0; i < SwingType; ++i)
4093 data
<< (uint32
)damageSchoolMask
;
4094 data
<< (float)(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);
4095 data
<< (uint32
)(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);
4098 if(HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4100 // for(i = 0; i < SwingType; ++i)
4101 data
<< uint32(AbsorbDamage
);
4105 if(HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4107 // for(i = 0; i < SwingType; ++i)
4108 data
<< uint32(Resist
);
4112 data
<< (uint8
)TargetState
;
4116 if(HitInfo
& HITINFO_BLOCK
)
4118 data
<< uint32(BlockedAmount
);
4121 if(HitInfo
& HITINFO_UNK3
)
4126 if(HitInfo
& HITINFO_UNK1
)
4137 for(uint8 i
= 0; i
< 5; ++i
)
4145 SendMessageToSet( &data
, true );
4148 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4150 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
4152 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4153 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4155 uint32 triggered_spell_id
= 0;
4156 Unit
* target
= pVictim
;
4157 int32 basepoints0
= 0;
4159 switch(hasteSpell
->SpellFamilyName
)
4161 case SPELLFAMILY_ROGUE
:
4163 switch(hasteSpell
->Id
)
4169 target
= SelectNearbyTarget();
4172 basepoints0
= damage
;
4173 triggered_spell_id
= 22482;
4181 // processed charge only counting case
4182 if(!triggered_spell_id
)
4185 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
4189 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
4194 if(!target
|| target
!=this && !target
->isAlive())
4197 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
4201 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4203 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
4205 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
4206 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
4211 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
4213 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
4214 uint32 effIndex
= triggeredByAura
->GetEffIndex ();
4216 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4217 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4219 uint32 triggered_spell_id
= 0;
4220 Unit
* target
= pVictim
;
4221 int32 basepoints0
= 0;
4223 switch(dummySpell
->SpellFamilyName
)
4225 case SPELLFAMILY_GENERIC
:
4227 switch (dummySpell
->Id
)
4233 // prevent damage back from weapon special attacks
4234 if (!procSpell
|| procSpell
->DmgClass
!= SPELL_DAMAGE_CLASS_MAGIC
)
4237 // return damage % to attacker but < 50% own total health
4238 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*int32(damage
)/100;
4239 if(basepoints0
> GetMaxHealth()/2)
4240 basepoints0
= GetMaxHealth()/2;
4242 triggered_spell_id
= 25997;
4250 // prevent chain of triggered spell from same triggered spell
4251 if(procSpell
&& procSpell
->Id
==26654)
4254 target
= SelectNearbyTarget();
4258 triggered_spell_id
= 26654;
4264 if (!procSpell
|| procSpell
->Id
== 24659)
4266 // Need remove one 24659 aura
4267 RemoveSingleAuraFromStack(24659, 0);
4268 RemoveSingleAuraFromStack(24659, 1);
4271 // Restless Strength
4274 // Need remove one 24662 aura
4275 RemoveSingleAuraFromStack(24662, 0);
4278 // Adaptive Warding (Frostfire Regalia set)
4286 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
4287 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
4289 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
4291 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& 0x10000000))
4301 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
4303 case SPELL_SCHOOL_NORMAL
:
4304 case SPELL_SCHOOL_HOLY
:
4305 return false; // ignored
4306 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
4307 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
4308 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
4309 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
4310 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
4318 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
4324 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
4326 case SPELL_SCHOOL_NORMAL
:
4327 return false; // ignore
4328 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
4329 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
4330 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
4331 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
4332 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
4333 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
4341 // Mana Leech (Passive) (Priest Pet Aura)
4345 target
= GetOwner();
4349 basepoints0
= int32(damage
* 2.5f
); // manaregen
4350 triggered_spell_id
= 34650;
4356 // Cast finish spell at last charge
4357 if (triggeredByAura
->m_procCharges
> 1)
4361 triggered_spell_id
= 33494;
4364 // Twisted Reflection (boss spell)
4366 triggered_spell_id
= 21064;
4368 // Vampiric Aura (boss spell)
4371 basepoints0
= 3 * damage
; // 300%
4372 if (basepoints0
< 0)
4375 triggered_spell_id
= 31285;
4379 // Aura of Madness (Darkmoon Card: Madness trinket)
4380 //=====================================================
4381 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
4382 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
4383 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
4384 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
4385 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
4386 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
4387 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
4388 // 41011 Martyr Complex: +35 stamina (All classes)
4389 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
4390 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
4393 if(GetTypeId() != TYPEID_PLAYER
)
4396 // Select class defined buff
4399 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
4400 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
4402 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
4403 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4406 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
4407 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
4409 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
4410 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4413 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
4414 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
4415 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
4416 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
4418 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
4419 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4422 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
4424 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
4425 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4433 if (roll_chance_i(10))
4434 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
4438 // TODO: need find item for aura and triggered spells
4439 // Sunwell Exalted Caster Neck (??? neck)
4440 // cast ??? Light's Wrath if Exalted by Aldor
4441 // cast ??? Arcane Bolt if Exalted by Scryers*/
4443 return false; // disable for while
4446 if(GetTypeId() != TYPEID_PLAYER)
4449 // Get Aldor reputation rank
4450 if (((Player *)this)->GetReputationRank(932) == REP_EXALTED)
4453 triggered_spell_id = ???
4456 // Get Scryers reputation rank
4457 if (((Player *)this)->GetReputationRank(934) == REP_EXALTED)
4459 triggered_spell_id = ???
4464 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
4465 // cast 45479 Light's Wrath if Exalted by Aldor
4466 // cast 45429 Arcane Bolt if Exalted by Scryers
4469 if(GetTypeId() != TYPEID_PLAYER
)
4472 // Get Aldor reputation rank
4473 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4476 triggered_spell_id
= 45479;
4479 // Get Scryers reputation rank
4480 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4482 triggered_spell_id
= 45429;
4487 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
4488 // cast 45480 Light's Strength if Exalted by Aldor
4489 // cast 45428 Arcane Strike if Exalted by Scryers
4492 if(GetTypeId() != TYPEID_PLAYER
)
4495 // Get Aldor reputation rank
4496 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4499 triggered_spell_id
= 45480;
4502 // Get Scryers reputation rank
4503 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4505 triggered_spell_id
= 45428;
4510 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
4511 // cast 45431 Arcane Insight if Exalted by Aldor
4512 // cast 45432 Light's Ward if Exalted by Scryers
4515 if(GetTypeId() != TYPEID_PLAYER
)
4518 // Get Aldor reputation rank
4519 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4522 triggered_spell_id
= 45432;
4525 // Get Scryers reputation rank
4526 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4529 triggered_spell_id
= 45431;
4534 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
4535 // cast 45478 Light's Salvation if Exalted by Aldor
4536 // cast 45430 Arcane Surge if Exalted by Scryers
4539 if(GetTypeId() != TYPEID_PLAYER
)
4542 // Get Aldor reputation rank
4543 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4546 triggered_spell_id
= 45478;
4549 // Get Scryers reputation rank
4550 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4552 triggered_spell_id
= 45430;
4560 case SPELLFAMILY_MAGE
:
4563 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
4565 if (getPowerType() != POWER_MANA
)
4569 basepoints0
= (triggeredByAura
->GetModifier()->m_amount
* GetMaxPower(POWER_MANA
) / 100);
4571 triggered_spell_id
= 29442;
4574 // Master of Elements
4575 if (dummySpell
->SpellIconID
== 1920)
4581 basepoints0
= procSpell
->manaCost
* triggeredByAura
->GetModifier()->m_amount
/100;
4582 if( basepoints0
<=0 )
4586 triggered_spell_id
= 29077;
4589 // Incanter's Regalia set (add trigger chance to Mana Shield)
4590 if (dummySpell
->SpellFamilyFlags
& 0x0000000000008000LL
)
4592 if(GetTypeId() != TYPEID_PLAYER
)
4596 triggered_spell_id
= 37436;
4599 switch(dummySpell
->Id
)
4608 switch (dummySpell
->Id
)
4610 case 11119: basepoints0
= int32(0.04f
*damage
); break;
4611 case 11120: basepoints0
= int32(0.08f
*damage
); break;
4612 case 12846: basepoints0
= int32(0.12f
*damage
); break;
4613 case 12847: basepoints0
= int32(0.16f
*damage
); break;
4614 case 12848: basepoints0
= int32(0.20f
*damage
); break;
4616 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
4620 triggered_spell_id
= 12654;
4626 //last charge and crit
4627 if (triggeredByAura
->m_procCharges
<= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
4629 RemoveAurasDueToSpell(28682); //-> remove Combustion auras
4630 return true; // charge counting (will removed)
4633 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
4634 return (procEx
& PROC_EX_CRITICAL_HIT
);// charge update only at crit hits, no hidden cooldowns
4639 case SPELLFAMILY_WARRIOR
:
4642 if(dummySpell
->SpellFamilyFlags
==0x0000000800000000LL
)
4644 // check attack comes not from behind
4645 if (!HasInArc(M_PI
, pVictim
))
4648 triggered_spell_id
= 22858;
4651 else if (dummySpell
->SpellIconID
== 1697) // Second Wind
4653 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
4654 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
4656 // Need stun or root mechanic
4657 if (procSpell
->Mechanic
!= MECHANIC_ROOT
&& procSpell
->Mechanic
!= MECHANIC_STUN
)
4661 if (procSpell
->EffectMechanic
[i
] == MECHANIC_ROOT
|| procSpell
->EffectMechanic
[i
] == MECHANIC_STUN
)
4667 switch (dummySpell
->Id
)
4669 case 29838: triggered_spell_id
=29842; break;
4670 case 29834: triggered_spell_id
=29841; break;
4672 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
4681 case SPELLFAMILY_WARLOCK
:
4683 // Seed of Corruption
4684 if (dummySpell
->SpellFamilyFlags
& 0x0000001000000000LL
)
4686 Modifier
* mod
= triggeredByAura
->GetModifier();
4687 // if damage is more than need or target die from damage deal finish spell
4688 if( mod
->m_amount
<= damage
|| GetHealth() <= damage
)
4690 // remember guid before aura delete
4691 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
4693 // Remove aura (before cast for prevent infinite loop handlers)
4694 RemoveAurasDueToSpell(triggeredByAura
->GetId());
4696 // Cast finish spell (triggeredByAura already not exist!)
4697 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
4698 return true; // no hidden cooldown
4702 mod
->m_amount
-=damage
;
4705 // Seed of Corruption (Mobs cast) - no die req
4706 if (dummySpell
->SpellFamilyFlags
== 0x00LL
&& dummySpell
->SpellIconID
== 1932)
4708 Modifier
* mod
= triggeredByAura
->GetModifier();
4709 // if damage is more than need deal finish spell
4710 if( mod
->m_amount
<= damage
)
4712 // remember guid before aura delete
4713 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
4715 // Remove aura (before cast for prevent infinite loop handlers)
4716 RemoveAurasDueToSpell(triggeredByAura
->GetId());
4718 // Cast finish spell (triggeredByAura already not exist!)
4719 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
4720 return true; // no hidden cooldown
4723 mod
->m_amount
-=damage
;
4726 switch(dummySpell
->Id
)
4733 triggered_spell_id
= 17941;
4742 basepoints0
= int32(damage
*triggeredByAura
->GetModifier()->m_amount
/100);
4744 triggered_spell_id
= 30294;
4747 // Shadowflame (Voidheart Raiment set bonus)
4750 triggered_spell_id
= 37379;
4753 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
4761 basepoints0
= damage
* triggeredByAura
->GetModifier()->m_amount
/100;
4762 triggered_spell_id
= 37382;
4765 // Shadowflame Hellfire (Voidheart Raiment set bonus)
4768 triggered_spell_id
= 37378;
4774 case SPELLFAMILY_PRIEST
:
4777 if( dummySpell
->SpellFamilyFlags
& 0x0000040000000000LL
)
4779 if(!pVictim
|| !pVictim
->isAlive())
4782 // pVictim is caster of aura
4783 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
4787 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*damage
/100;
4788 pVictim
->CastCustomSpell(pVictim
,34919,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4789 return true; // no hidden cooldown
4791 switch(dummySpell
->Id
)
4796 if(!pVictim
|| !pVictim
->isAlive())
4799 // pVictim is caster of aura
4800 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
4804 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*damage
/100;
4805 pVictim
->CastCustomSpell(pVictim
,15290,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4806 return true; // no hidden cooldown
4808 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
4811 // Shadow Word: Pain
4812 if( procSpell
->SpellFamilyFlags
& 0x0000000000008000LL
)
4813 triggered_spell_id
= 40441;
4815 else if( procSpell
->SpellFamilyFlags
& 0x0000000000000010LL
)
4816 triggered_spell_id
= 40440;
4823 // Oracle Healing Bonus ("Garments of the Oracle" set)
4827 basepoints0
= int32(damage
* 10/100);
4829 triggered_spell_id
= 26170;
4832 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
4835 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
4839 basepoints0
= int32(damage
* 2 / 100);
4841 triggered_spell_id
= 39373;
4844 // Greater Heal (Vestments of Faith (Priest Tier 3) - 4 pieces bonus)
4847 triggered_spell_id
= 28810;
4853 case SPELLFAMILY_DRUID
:
4855 switch(dummySpell
->Id
)
4857 // Healing Touch (Dreamwalker Raiment set)
4861 basepoints0
= int32(procSpell
->manaCost
* 30 / 100);
4863 triggered_spell_id
= 28742;
4866 // Healing Touch Refund (Idol of Longevity trinket)
4870 triggered_spell_id
= 28848;
4873 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
4878 triggered_spell_id
= 37238;
4881 // Druid Tier 6 Trinket
4887 if( procSpell
->SpellFamilyFlags
& 0x0000000000000004LL
)
4889 triggered_spell_id
= 40445;
4893 else if( procSpell
->SpellFamilyFlags
& 0x0000000000000010LL
)
4895 triggered_spell_id
= 40446;
4898 // Mangle (cat/bear)
4899 else if( procSpell
->SpellFamilyFlags
& 0x0000044000000000LL
)
4901 triggered_spell_id
= 40452;
4907 if (!roll_chance_f(chance
))
4916 // Deadly Interrupt Effect
4917 triggered_spell_id
= 32747;
4923 case SPELLFAMILY_ROGUE
:
4925 switch(dummySpell
->Id
)
4927 // Deadly Throw Interrupt
4930 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
4934 triggered_spell_id
= 32747;
4939 if( dummySpell
->SpellIconID
== 2116 )
4944 // only rogue's finishing moves (maybe need additional checks)
4945 if( procSpell
->SpellFamilyName
!=SPELLFAMILY_ROGUE
||
4946 (procSpell
->SpellFamilyFlags
& SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE
) == 0)
4950 basepoints0
= procSpell
->manaCost
* triggeredByAura
->GetModifier()->m_amount
/100;
4951 if(basepoints0
<= 0)
4955 triggered_spell_id
= 31663;
4960 case SPELLFAMILY_HUNTER
:
4962 // Thrill of the Hunt
4963 if ( dummySpell
->SpellIconID
== 2236 )
4969 basepoints0
= procSpell
->manaCost
* 40/100;
4970 if(basepoints0
<= 0)
4974 triggered_spell_id
= 34720;
4979 case SPELLFAMILY_PALADIN
:
4981 // TODO: spell list, formula change in 3.0.3
4982 // Seal of Righteousness - melee proc dummy
4983 if (dummySpell
->SpellFamilyFlags
&0x000000008000000LL
&& triggeredByAura
->GetEffIndex()==0)
4985 if(GetTypeId() != TYPEID_PLAYER
)
4989 switch (triggeredByAura
->GetId())
4991 case 21084: spellId
= 25742; break; // Rank 1
4992 case 20287: spellId
= 25740; break; // Rank 2
4993 case 20288: spellId
= 25739; break; // Rank 3
4994 case 20289: spellId
= 25738; break; // Rank 4
4995 case 20290: spellId
= 25737; break; // Rank 5
4996 case 20291: spellId
= 25736; break; // Rank 6
4997 case 20292: spellId
= 25735; break; // Rank 7
4998 case 20293: spellId
= 25713; break; // Rank 8
4999 case 27155: spellId
= 27156; break; // Rank 9
5001 sLog
.outError("Unit::HandleDummyAuraProc: non handled possibly SoR (Id = %u)", triggeredByAura
->GetId());
5004 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
5005 float speed
= (item
? item
->GetProto()->Delay
: BASE_ATTACK_TIME
)/1000.0f
;
5007 float damageBasePoints
;
5008 if(item
&& item
->GetProto()->InventoryType
== INVTYPE_2HWEAPON
)
5010 damageBasePoints
=1.20f
*triggeredByAura
->GetModifier()->m_amount
* 1.2f
* 1.03f
* speed
/100.0f
+ 1;
5012 // one hand weapon/no weapon
5013 damageBasePoints
=0.85f
*ceil(triggeredByAura
->GetModifier()->m_amount
* 1.2f
* 1.03f
* speed
/100.0f
) - 1;
5015 int32 damagePoint
= int32(damageBasePoints
+ 0.03f
* (GetWeaponDamageRange(BASE_ATTACK
,MINDAMAGE
)+GetWeaponDamageRange(BASE_ATTACK
,MAXDAMAGE
))/2.0f
) + 1;
5017 // apply damage bonuses manually
5018 if(damagePoint
>= 0)
5019 damagePoint
= SpellDamageBonus(pVictim
, dummySpell
, damagePoint
, SPELL_DIRECT_DAMAGE
);
5021 CastCustomSpell(pVictim
,spellId
,&damagePoint
,NULL
,NULL
,true,NULL
, triggeredByAura
);
5022 return true; // no hidden cooldown
5024 // Seal of Blood do damage trigger
5025 if(dummySpell
->SpellFamilyFlags
& 0x0000040000000000LL
)
5027 switch(triggeredByAura
->GetEffIndex())
5030 triggered_spell_id
= 31893;
5035 damage
+= CalculateDamage(BASE_ATTACK
, false) * 35 / 100; // add spell damage from prev effect (35%)
5036 basepoints0
= triggeredByAura
->GetModifier()->m_amount
* damage
/ 100;
5039 triggered_spell_id
= 32221;
5045 switch(dummySpell
->Id
)
5047 // Holy Power (Redemption Armor set)
5053 // Set class defined buff
5054 switch (pVictim
->getClass())
5060 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
5064 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
5068 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
5071 triggered_spell_id
= 28790; // Increases the friendly target's armor
5078 // TODO: fix basepoint calculation (changed in 3.0.3)
5079 // Seal of Vengeance
5082 if(effIndex
!= 0) // effect 1,2 used by seal unleashing code
5085 triggered_spell_id
= 31803;
5088 // Spiritual Attunement
5092 // if healed by another unit (pVictim)
5097 basepoints0
= triggeredByAura
->GetModifier()->m_amount
*damage
/100;
5099 triggered_spell_id
= 31786;
5102 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
5110 // Flash of light/Holy light
5111 if( procSpell
->SpellFamilyFlags
& 0x00000000C0000000LL
)
5113 triggered_spell_id
= 40471;
5117 else if( procSpell
->SpellFamilyFlags
& 0x0000000000800000LL
)
5119 triggered_spell_id
= 40472;
5125 if (!roll_chance_f(chance
))
5133 case SPELLFAMILY_SHAMAN
:
5135 switch(dummySpell
->Id
)
5137 // Totemic Power (The Earthshatterer set)
5143 // Set class defined buff
5144 switch (pVictim
->getClass())
5150 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
5154 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
5158 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
5161 triggered_spell_id
= 28827; // Increases the friendly target's armor
5168 // Lesser Healing Wave (Totem of Flowing Water Relic)
5172 triggered_spell_id
= 28850;
5175 // Windfury Weapon (Passive) 1-5 Ranks
5178 if(GetTypeId()!=TYPEID_PLAYER
)
5181 if(!castItem
|| !castItem
->IsEquipped())
5184 // custom cooldown processing case
5185 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
5189 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
5191 case 283: spellId
= 33757; break; //1 Rank
5192 case 284: spellId
= 33756; break; //2 Rank
5193 case 525: spellId
= 33755; break; //3 Rank
5194 case 1669:spellId
= 33754; break; //4 Rank
5195 case 2636:spellId
= 33727; break; //5 Rank
5198 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
5199 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
5204 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
5205 if(!windfurySpellEntry
)
5207 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
5211 int32 extra_attack_power
= CalculateSpellDamage(windfurySpellEntry
,0,windfurySpellEntry
->EffectBasePoints
[0],pVictim
);
5214 if ( castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
5216 // Value gained from additional AP
5217 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
5218 triggered_spell_id
= 33750;
5223 // Value gained from additional AP
5224 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
5225 triggered_spell_id
= 25504;
5228 // apply cooldown before cast to prevent processing itself
5230 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
5233 for ( uint32 i
= 0; i
<2; ++i
)
5234 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5238 // Shaman Tier 6 Trinket
5245 if (procSpell
->SpellFamilyFlags
& 0x0000000000000001LL
)
5247 triggered_spell_id
= 40465; // Lightning Bolt
5250 else if (procSpell
->SpellFamilyFlags
& 0x0000000000000080LL
)
5252 triggered_spell_id
= 40465; // Lesser Healing Wave
5255 else if (procSpell
->SpellFamilyFlags
& 0x0000001000000000LL
)
5257 triggered_spell_id
= 40466; // Stormstrike
5263 if (!roll_chance_f(chance
))
5272 if(dummySpell
->SpellFamilyFlags
& 0x0000040000000000LL
)
5274 if(GetTypeId() != TYPEID_PLAYER
)
5278 basepoints0
= triggeredByAura
->GetModifier()->m_amount
;
5280 triggered_spell_id
= 379;
5283 // Lightning Overload
5284 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
5286 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
5289 // custom cooldown processing case
5290 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
5294 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
5295 switch (procSpell
->Id
)
5298 case 403: spellId
= 45284; break; // Rank 1
5299 case 529: spellId
= 45286; break; // Rank 2
5300 case 548: spellId
= 45287; break; // Rank 3
5301 case 915: spellId
= 45288; break; // Rank 4
5302 case 943: spellId
= 45289; break; // Rank 5
5303 case 6041: spellId
= 45290; break; // Rank 6
5304 case 10391: spellId
= 45291; break; // Rank 7
5305 case 10392: spellId
= 45292; break; // Rank 8
5306 case 15207: spellId
= 45293; break; // Rank 9
5307 case 15208: spellId
= 45294; break; // Rank 10
5308 case 25448: spellId
= 45295; break; // Rank 11
5309 case 25449: spellId
= 45296; break; // Rank 12
5310 case 49237: spellId
= 49239; break; // Rank 13
5311 case 49238: spellId
= 49240; break; // Rank 14
5313 case 421: spellId
= 45297; break; // Rank 1
5314 case 930: spellId
= 45298; break; // Rank 2
5315 case 2860: spellId
= 45299; break; // Rank 3
5316 case 10605: spellId
= 45300; break; // Rank 4
5317 case 25439: spellId
= 45301; break; // Rank 5
5318 case 25442: spellId
= 45302; break; // Rank 6
5319 case 49268: spellId
= 49270; break; // Rank 7
5320 case 49269: spellId
= 49271; break; // Rank 8
5322 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
5325 // No thread generated mod
5326 SpellModifier
*mod
= new SpellModifier
;
5327 mod
->op
= SPELLMOD_THREAT
;
5329 mod
->type
= SPELLMOD_PCT
;
5330 mod
->spellId
= dummySpell
->Id
;
5331 mod
->mask
= 0x0000000000000003LL
;
5333 ((Player
*)this)->AddSpellMod(mod
, true);
5335 // Remove cooldown (Chain Lightning - have Category Recovery time)
5336 if (procSpell
->SpellFamilyFlags
& 0x0000000000000002LL
)
5337 ((Player
*)this)->RemoveSpellCooldown(spellId
);
5339 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
5341 ((Player
*)this)->AddSpellMod(mod
, false);
5343 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5344 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
5354 // processed charge only counting case
5355 if(!triggered_spell_id
)
5358 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5362 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
5367 if(!target
|| target
!=this && !target
->isAlive())
5370 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5374 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5376 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5378 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5379 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5384 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
5386 // Get triggered aura spell info
5387 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
5389 // Basepoints of trigger aura
5390 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
5392 // Set trigger spell id, target, custom basepoints
5393 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
5394 Unit
* target
= NULL
;
5395 int32 basepoints0
= 0;
5397 if(triggeredByAura
->GetModifier()->m_auraname
== SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
)
5398 basepoints0
= triggerAmount
;
5400 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5401 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5403 // Try handle uncnown trigger spells
5404 if (sSpellStore
.LookupEntry(trigger_spell_id
)==NULL
)
5406 switch (auraSpellInfo
->SpellFamilyName
)
5408 case SPELLFAMILY_GENERIC
:
5409 //if (auraSpellInfo->Id==59532) // Abandon Passengers on Poly
5410 //if (auraSpellInfo->Id==54775) // Abandon Vehicle on Poly
5411 //if (auraSpellInfo->Id==34082) // Advantaged State (DND)
5412 if (auraSpellInfo
->Id
== 23780) // Aegis of Preservation (Aegis of Preservation trinket)
5413 trigger_spell_id
= 23781;
5414 //else if (auraSpellInfo->Id==43504) // Alterac Valley OnKill Proc Aura
5415 //else if (auraSpellInfo->Id == 48876) // Beast's Mark
5417 // trigger_spell_id = 48877;
5419 //else if (auraSpellInfo->Id == 59237) // Beast's Mark
5421 // trigger_spell_id = 59233;
5423 //else if (auraSpellInfo->Id==46939) // Black Bow of the Betrayer
5425 // trigger_spell_id = 29471; // gain mana
5426 // 27526; // drain mana if possible
5428 //else if (auraSpellInfo->Id==50844) // Blood Mirror
5429 //else if (auraSpellInfo->Id==54476) // Blood Presence
5430 //else if (auraSpellInfo->Id==50689) // Blood Presence (Rank 1)
5431 //else if (auraSpellInfo->Id==37030) // Chaotic Temperament
5432 //else if (auraSpellInfo->Id==52856) // Charge
5433 else if (auraSpellInfo
->Id
==43820) // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
5435 // Pct value stored in dummy
5436 basepoints0
= pVictim
->GetCreateHealth() * auraSpellInfo
->EffectBasePoints
[1] / 100;
5440 //else if (auraSpellInfo->Id==41248) // Consuming Strikes
5441 // trigger_spell_id = 41249;
5442 //else if (auraSpellInfo->Id==45205) // Copy Offhand Weapon
5443 //else if (auraSpellInfo->Id==57594) // Copy Ranged Weapon
5444 //else if (auraSpellInfo->Id==41054) // Copy Weapon
5445 // trigger_spell_id = 41055;
5446 //else if (auraSpellInfo->Id==45343) // Dark Flame Aura
5447 //else if (auraSpellInfo->Id==47300) // Dark Flame Aura
5448 else if (auraSpellInfo
->Id
==57345) // Darkmoon Card: Greatness
5452 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 60229;stat
= GetStat(STAT_STRENGTH
); }
5454 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 60233;stat
= GetStat(STAT_AGILITY
); }
5456 if (GetStat(STAT_INTELLECT
)> stat
) { trigger_spell_id
= 60234;stat
= GetStat(STAT_INTELLECT
);}
5458 if (GetStat(STAT_SPIRIT
) > stat
) { trigger_spell_id
= 60235;stat
= GetStat(STAT_SPIRIT
); }
5460 //else if (auraSpellInfo->Id==31255) // Deadly Swiftness (Rank 1)
5461 //else if (auraSpellInfo->Id==5301) // Defensive State (DND)
5462 //else if (auraSpellInfo->Id==13358) // Defensive State (DND)
5463 //else if (auraSpellInfo->Id==16092) // Defensive State (DND)
5464 //else if (auraSpellInfo->Id==24949) // Defensive State 2 (DND)
5465 //else if (auraSpellInfo->Id==40329) // Demo Shout Sensor
5466 else if (auraSpellInfo
->Id
== 33896) // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
5467 trigger_spell_id
= 33898;
5468 //else if (auraSpellInfo->Id==18943) // Double Attack
5469 //else if (auraSpellInfo->Id==19194) // Double Attack
5470 //else if (auraSpellInfo->Id==19817) // Double Attack
5471 //else if (auraSpellInfo->Id==19818) // Double Attack
5472 //else if (auraSpellInfo->Id==22835) // Drunken Rage
5473 // trigger_spell_id = 14822;
5475 else if (auraSpellInfo->SpellIconID==191) // Elemental Response
5477 switch (auraSpellInfo->Id && auraSpellInfo->AttributesEx==0)
5486 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Elemental Response",auraSpellInfo->Id);
5489 //This generic aura self-triggers a different spell for each school of magic that lands on the wearer:
5490 switch (procSpell->School)
5492 case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192; break;
5493 case SPELL_SCHOOL_FROST: trigger_spell_id = 34193; break;
5494 case SPELL_SCHOOL_ARCANE:trigger_spell_id = 34194; break;
5495 case SPELL_SCHOOL_NATURE:trigger_spell_id = 34195; break;
5496 case SPELL_SCHOOL_SHADOW:trigger_spell_id = 34196; break;
5497 case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197; break;
5498 case SPELL_SCHOOL_NORMAL:trigger_spell_id = 34198; break;
5500 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u Elemental Response wrong school",auraSpellInfo->Id);
5505 //else if (auraSpellInfo->Id==40364) // Entangling Roots Sensor
5506 //else if (auraSpellInfo->Id==33207) // Gossip NPC Periodic - Fidget
5507 //else if (auraSpellInfo->Id==50051) // Ethereal Pet Aura
5508 //else if (auraSpellInfo->Id==35321) // Gushing Wound
5509 //else if (auraSpellInfo->Id==38363) // Gushing Wound
5510 //else if (auraSpellInfo->Id==39215) // Gushing Wound
5511 //else if (auraSpellInfo->Id==44527) // Hate Monster (Spar Buddy) (30 sec)
5512 //else if (auraSpellInfo->Id==44819) // Hate Monster (Spar Buddy) (>30% Health)
5513 //else if (auraSpellInfo->Id==44526) // Hate Monster (Spar) (30 sec)
5514 //else if (auraSpellInfo->Id==44820) // Hate Monster (Spar) (<30%)
5515 //else if (auraSpellInfo->Id==49059) // Horde, Hate Monster (Spar Buddy) (>30% Health)
5516 //else if (auraSpellInfo->Id==40250) // Improved Duration
5517 //else if (auraSpellInfo->Id==59288) // Infra-Green Shield
5518 //else if (auraSpellInfo->Id==54072) // Knockback Ball Passive
5519 else if (auraSpellInfo
->Id
==27522 || auraSpellInfo
->Id
==40336)
5520 // Mana Drain Trigger
5522 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
5523 if (this && this->isAlive())
5524 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
5525 if (pVictim
&& pVictim
->isAlive())
5526 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
5529 //else if (auraSpellInfo->Id==55580) // Mana Link
5530 //else if (auraSpellInfo->Id==45903) // Offensive State
5531 //else if (auraSpellInfo->Id==44326) // Pure Energy Passive
5532 //else if (auraSpellInfo->Id==43453) // Rune Ward
5533 //else if (auraSpellInfo->Id== 7137) // Shadow Charge (Rank 1)
5534 //else if (auraSpellInfo->Id==36576) // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
5535 //else if (auraSpellInfo->Id==34783) // Spell Reflection
5536 //else if (auraSpellInfo->Id==36096) // Spell Reflection
5537 //else if (auraSpellInfo->Id==57587) // Steal Ranged ()
5538 //else if (auraSpellInfo->Id==36207) // Steal Weapon
5539 //else if (auraSpellInfo->Id== 7377) // Take Immune Periodic Damage <Not Working>
5540 //else if (auraSpellInfo->Id==35205) // Vanish
5541 //else if (auraSpellInfo->Id==42730) // Woe Strike
5542 //else if (auraSpellInfo->Id==59735) // Woe Strike
5543 //else if (auraSpellInfo->Id==46146) // [PH] Ahune Spanky Hands
5545 case SPELLFAMILY_MAGE
:
5546 if (auraSpellInfo
->SpellIconID
== 2127) // Blazing Speed
5548 switch (auraSpellInfo
->Id
)
5550 case 31641: // Rank 1
5551 case 31642: // Rank 2
5552 trigger_spell_id
= 31643;
5555 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
5560 case SPELLFAMILY_WARRIOR
:
5561 if (auraSpellInfo
->Id
== 50421) // Scent of Blood
5562 trigger_spell_id
= 50422;
5564 case SPELLFAMILY_WARLOCK
:
5567 if (auraSpellInfo
->SpellIconID
== 1137)
5569 if(!pVictim
|| !pVictim
->isAlive() || pVictim
== this || procSpell
== NULL
)
5571 // Calculate spell tick count for spells
5572 uint32 tick
= 1; // Default tick = 1
5574 // Hellfire have 15 tick
5575 if (procSpell
->SpellFamilyFlags
&0x0000000000000040LL
)
5577 // Rain of Fire have 4 tick
5578 else if (procSpell
->SpellFamilyFlags
&0x0000000000000020LL
)
5583 // Calculate chance = baseChance / tick
5585 switch (auraSpellInfo
->Id
)
5587 case 18096: chance
= 13.0f
/ tick
; break;
5588 case 18073: chance
= 26.0f
/ tick
; break;
5591 if (!roll_chance_f(chance
))
5594 trigger_spell_id
= 18093;
5597 else if (auraSpellInfo
->SpellFamilyFlags
& 0x0000000000004000LL
)
5599 Unit::AuraList
const& mAddFlatModifier
= GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER
);
5600 for(Unit::AuraList::const_iterator i
= mAddFlatModifier
.begin(); i
!= mAddFlatModifier
.end(); ++i
)
5602 if ((*i
)->GetModifier()->m_miscvalue
== SPELLMOD_CHANCE_OF_SUCCESS
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
5604 int32 value2
= CalculateSpellDamage((*i
)->GetSpellProto(),2,(*i
)->GetSpellProto()->EffectBasePoints
[2],this);
5606 CastCustomSpell(this, 18371, &basepoints0
, NULL
, NULL
, true, castItem
, triggeredByAura
);
5610 // Not remove charge (aura removed on death in any cases)
5611 // Need for correct work Drain Soul SPELL_AURA_CHANNEL_DEATH_ITEM aura
5614 // Nether Protection
5615 else if (auraSpellInfo
->SpellIconID
== 1985)
5619 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5621 case SPELL_SCHOOL_NORMAL
:
5622 case SPELL_SCHOOL_HOLY
:
5623 return false; // ignore
5624 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 54371; break;
5625 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 54375; break;
5626 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 54372; break;
5627 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 54374; break;
5628 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
5635 case SPELLFAMILY_PRIEST
:
5637 // Greater Heal Refund
5638 if (auraSpellInfo
->Id
==37594)
5639 trigger_spell_id
= 37595;
5641 else if (auraSpellInfo
->SpellIconID
== 1875)
5643 switch (auraSpellInfo
->Id
)
5645 case 27811: trigger_spell_id
= 27813; break;
5646 case 27815: trigger_spell_id
= 27817; break;
5647 case 27816: trigger_spell_id
= 27818; break;
5649 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
5652 basepoints0
= damage
* triggerAmount
/ 100 / 3;
5657 case SPELLFAMILY_DRUID
:
5659 // Druid Forms Trinket
5660 if (auraSpellInfo
->Id
==37336)
5664 case FORM_NONE
: trigger_spell_id
= 37344;break;
5665 case FORM_CAT
: trigger_spell_id
= 37341;break;
5667 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
5668 case FORM_TREE
: trigger_spell_id
= 37342;break;
5669 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
5674 //else if (auraSpellInfo->Id==40363)// Entangling Roots ()
5675 // trigger_spell_id = ????;
5676 // Leader of the Pack
5677 else if (auraSpellInfo
->Id
== 24932)
5679 if (triggerAmount
== 0)
5681 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
5682 trigger_spell_id
= 34299;
5686 case SPELLFAMILY_HUNTER
:
5688 case SPELLFAMILY_PALADIN
:
5692 if (auraSpellInfo->SpellIconID == 2137)
5694 switch (auraSpellInfo->Id)
5696 case 31828: // Rank 1
5697 case 31829: // Rank 2
5698 case 31830: // Rank 3
5701 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
5707 if (auraSpellInfo
->Id
==37705)
5709 trigger_spell_id
= 37706;
5713 if (auraSpellInfo
->Id
==60510)
5715 trigger_spell_id
= 60515;
5719 else if (auraSpellInfo
->SpellIconID
==241)
5723 // procspell is triggered spell but we need mana cost of original casted spell
5724 uint32 originalSpellId
= procSpell
->Id
;
5726 if(procSpell
->SpellFamilyFlags
& 0x00200000)
5728 switch(procSpell
->Id
)
5730 case 25914: originalSpellId
= 20473; break;
5731 case 25913: originalSpellId
= 20929; break;
5732 case 25903: originalSpellId
= 20930; break;
5733 case 27175: originalSpellId
= 27174; break;
5734 case 33074: originalSpellId
= 33072; break;
5736 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
5740 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
5743 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
5746 // percent stored in effect 1 (class scripts) base points
5747 basepoints0
= originalSpell
->manaCost
*(auraSpellInfo
->EffectBasePoints
[1]+1)/100;
5748 trigger_spell_id
= 20272;
5751 // Lightning Capacitor
5752 else if (auraSpellInfo
->Id
==37657)
5754 if(!pVictim
|| !pVictim
->isAlive())
5757 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
5760 AuraList
const& dummyAura
= GetAurasByType(SPELL_AURA_DUMMY
);
5761 for(AuraList::const_iterator itr
= dummyAura
.begin(); itr
!= dummyAura
.end(); ++itr
)
5762 if((*itr
)->GetId()==37658)
5764 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
5765 if(count
< triggerAmount
)
5768 RemoveAurasDueToSpell(37658);
5769 trigger_spell_id
= 37661;
5772 // Thunder Capacitor
5773 else if (auraSpellInfo
->Id
== 54841)
5775 if(!pVictim
|| !pVictim
->isAlive())
5778 CastSpell(this, 54842, true, NULL
, triggeredByAura
);
5781 AuraList
const& dummyAura
= GetAurasByType(SPELL_AURA_DUMMY
);
5782 for(AuraList::const_iterator itr
= dummyAura
.begin(); itr
!= dummyAura
.end(); ++itr
)
5783 if((*itr
)->GetId()==54842)
5785 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
5786 if(count
< triggerAmount
)
5789 RemoveAurasDueToSpell(54842);
5790 trigger_spell_id
= 54843;
5795 case SPELLFAMILY_SHAMAN
:
5797 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc
5798 if(auraSpellInfo
->SpellFamilyFlags
& 0x0000000000000400)
5800 switch(auraSpellInfo
->Id
)
5803 trigger_spell_id
= 26364; break;
5805 trigger_spell_id
= 26365; break;
5807 trigger_spell_id
= 26366; break;
5809 trigger_spell_id
= 26367; break;
5810 case 8134: // Rank 5
5811 trigger_spell_id
= 26369; break;
5812 case 10431: // Rank 6
5813 trigger_spell_id
= 26370; break;
5814 case 10432: // Rank 7
5815 trigger_spell_id
= 26363; break;
5816 case 25469: // Rank 8
5817 trigger_spell_id
= 26371; break;
5818 case 25472: // Rank 9
5819 trigger_spell_id
= 26372; break;
5820 case 49280: // Rank 10
5821 trigger_spell_id
= 49278; break;
5822 case 49281: // Rank 11
5823 trigger_spell_id
= 49279; break;
5825 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
5829 // Lightning Shield (The Ten Storms set)
5830 else if (auraSpellInfo
->Id
== 23551)
5832 trigger_spell_id
= 23552;
5835 // Damage from Lightning Shield (The Ten Storms set)
5836 else if (auraSpellInfo
->Id
== 23552)
5837 trigger_spell_id
= 27635;
5838 // Mana Surge (The Earthfury set)
5839 else if (auraSpellInfo
->Id
== 23572)
5843 basepoints0
= procSpell
->manaCost
* 35 / 100;
5844 trigger_spell_id
= 23571;
5847 // Nature's Guardian
5848 else if (auraSpellInfo
->SpellIconID
== 2013)
5850 // Check health condition - should drop to less 30% (damage deal after this!)
5851 if (!(10*(int32(GetHealth() - damage
)) < 3 * GetMaxHealth()))
5854 if(pVictim
&& pVictim
->isAlive())
5855 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
5857 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
5858 trigger_spell_id
= 31616;
5863 case SPELLFAMILY_DEATHKNIGHT
:
5866 if (auraSpellInfo
->SpellIconID
== 1930)
5870 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
5872 case SPELL_SCHOOL_NORMAL
:
5873 return false; // ignore
5874 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 50490; break;
5875 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 50362; break;
5876 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 50488; break;
5877 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 50485; break;
5878 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 50489; break;
5879 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
5885 else if (auraSpellInfo
->Id
== 48266)
5887 if (GetTypeId() != TYPEID_PLAYER
)
5889 if (!((Player
*)this)->isHonorOrXPTarget(pVictim
))
5891 trigger_spell_id
= 50475;
5892 basepoints0
= damage
* triggerAmount
/ 100;
5901 // All ok. Check current trigger spell
5902 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
5903 if ( triggerEntry
== NULL
)
5905 // Not cast unknown spell
5906 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
5910 // not allow proc extra attack spell at extra attack
5911 if( m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
) )
5914 // Costum requirements (not listed in procEx) Warning! damage dealing after this
5915 // Custom triggered spells
5916 switch (auraSpellInfo
->Id
)
5918 // Persistent Shield (Scarab Brooch trinket)
5919 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
5922 basepoints0
= damage
* 15 / 100;
5924 trigger_spell_id
= 26470;
5930 // When your health drops below 20% ....
5931 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
5935 // Deadly Swiftness (Rank 1)
5938 // whenever you deal damage to a target who is below 20% health.
5939 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
5943 trigger_spell_id
= 22588;
5945 // Greater Heal Refund (Avatar Raiment set)
5948 // Not give if target alredy have full health
5949 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
5951 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
5952 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
5956 // Bonus Healing (Crystal Spire of Karabor mace)
5959 // If your target is below $s1% health
5960 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
5964 // Evasive Maneuvers (Commendation of Kael`thas trinket)
5967 // reduce you below $s1% health
5968 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
5974 // Costum basepoints/target for exist spell
5975 // dummy basepoints or other customs
5976 switch(trigger_spell_id
)
5978 // Cast positive spell on enemy target
5979 case 7099: // Curse of Mending
5980 case 39647: // Curse of Mending
5981 case 29494: // Temptation
5982 case 20233: // Improved Lay on Hands (cast on target)
5987 // Combo points add triggers (need add combopoint only for main tatget, and after possible combopoints reset)
5988 case 15250: // Rogue Setup
5990 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
5992 break; // continue normal case
5994 // Finish movies that add combo
5995 case 14189: // Seal Fate (Netherblade set)
5996 case 14157: // Ruthlessness
5998 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
6001 // Shamanistic Rage triggered spell
6004 basepoints0
= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
6005 trigger_spell_id
= 30824;
6008 // Enlightenment (trigger only from mana cost spells)
6011 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
6017 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
6020 // try detect target manually if not set
6021 if ( target
== NULL
)
6022 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
6025 if(!target
|| target
!=this && !target
->isAlive())
6029 CastCustomSpell(target
,trigger_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6031 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
6033 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6034 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
6039 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
6041 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
6043 if(!pVictim
|| !pVictim
->isAlive())
6046 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
6047 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
6049 uint32 triggered_spell_id
= 0;
6053 case 836: // Improved Blizzard (Rank 1)
6055 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
6057 triggered_spell_id
= 12484;
6060 case 988: // Improved Blizzard (Rank 2)
6062 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
6064 triggered_spell_id
= 12485;
6067 case 989: // Improved Blizzard (Rank 3)
6069 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
6071 triggered_spell_id
= 12486;
6074 case 4086: // Improved Mend Pet (Rank 1)
6075 case 4087: // Improved Mend Pet (Rank 2)
6077 int32 chance
= triggeredByAura
->GetSpellProto()->EffectBasePoints
[triggeredByAura
->GetEffIndex()];
6078 if(!roll_chance_i(chance
))
6081 triggered_spell_id
= 24406;
6084 case 4533: // Dreamwalker Raiment 2 pieces bonus
6087 if (!roll_chance_i(50))
6090 switch (pVictim
->getPowerType())
6092 case POWER_MANA
: triggered_spell_id
= 28722; break;
6093 case POWER_RAGE
: triggered_spell_id
= 28723; break;
6094 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
6100 case 4537: // Dreamwalker Raiment 6 pieces bonus
6101 triggered_spell_id
= 28750; // Blessing of the Claw
6103 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
6104 triggered_spell_id
= 37445; // Mana Surge
6109 if(!triggered_spell_id
)
6112 // standard non-dummy case
6113 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6117 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
6121 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
6124 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
6126 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6127 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
6132 void Unit::setPowerType(Powers new_powertype
)
6134 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
6136 if(GetTypeId() == TYPEID_PLAYER
)
6138 if(((Player
*)this)->GetGroup())
6139 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
6141 else if(((Creature
*)this)->isPet())
6143 Pet
*pet
= ((Pet
*)this);
6144 if(pet
->isControlled())
6146 Unit
*owner
= GetOwner();
6147 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
6148 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
6152 switch(new_powertype
)
6158 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
6159 SetPower( POWER_RAGE
,0);
6162 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
6163 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
6166 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
6167 SetPower( POWER_ENERGY
,0);
6169 case POWER_HAPPINESS
:
6170 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
6171 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
6176 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
6178 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
6181 static uint64 guid
= 0; // prevent repeating spam same faction problem
6183 if(GetGUID() != guid
)
6185 if(GetTypeId() == TYPEID_PLAYER
)
6186 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
6188 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
6195 bool Unit::IsHostileTo(Unit
const* unit
) const
6197 // always non-hostile to self
6201 // always non-hostile to GM in GM mode
6202 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
6205 // always hostile to enemy
6206 if(getVictim()==unit
|| unit
->getVictim()==this)
6209 // test pet/charm masters instead pers/charmeds
6210 Unit
const* testerOwner
= GetCharmerOrOwner();
6211 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
6213 // always hostile to owner's enemy
6214 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
6217 // always hostile to enemy owner
6218 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
6221 // always hostile to owner of owner's enemy
6222 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
6225 Unit
const* tester
= testerOwner
? testerOwner
: this;
6226 Unit
const* target
= targetOwner
? targetOwner
: unit
;
6228 // always non-hostile to target with common owner, or to owner/pet
6232 // special cases (Duel, etc)
6233 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
6235 Player
const* pTester
= (Player
const*)tester
;
6236 Player
const* pTarget
= (Player
const*)target
;
6239 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
6243 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
6247 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
6251 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
))
6255 // Green/Blue (can't attack)
6256 if(pTester
->GetTeam()==pTarget
->GetTeam())
6259 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
6260 return pTester
->IsPvP() && pTarget
->IsPvP();
6263 // faction base cases
6264 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
6265 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
6266 if(!tester_faction
|| !target_faction
)
6269 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
6272 // PvC forced reaction and reputation case
6273 if(tester
->GetTypeId()==TYPEID_PLAYER
)
6276 ForcedReactions::const_iterator forceItr
= ((Player
*)tester
)->m_forcedReactions
.find(target_faction
->faction
);
6277 if(forceItr
!=((Player
*)tester
)->m_forcedReactions
.end())
6278 return forceItr
->second
<= REP_HOSTILE
;
6280 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
6281 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
6282 if(raw_target_faction
->reputationListID
>=0)
6283 if(FactionState
const* factionState
= ((Player
*)tester
)->GetFactionState(raw_target_faction
))
6284 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
6286 // CvP forced reaction and reputation case
6287 else if(target
->GetTypeId()==TYPEID_PLAYER
)
6290 ForcedReactions::const_iterator forceItr
= ((Player
const*)target
)->m_forcedReactions
.find(tester_faction
->faction
);
6291 if(forceItr
!=((Player
const*)target
)->m_forcedReactions
.end())
6292 return forceItr
->second
<= REP_HOSTILE
;
6294 // apply reputation state
6295 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
6296 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
6297 return ((Player
const*)target
)->GetReputationRank(raw_tester_faction
) <= REP_HOSTILE
;
6300 // common faction based case (CvC,PvC,CvP)
6301 return tester_faction
->IsHostileTo(*target_faction
);
6304 bool Unit::IsFriendlyTo(Unit
const* unit
) const
6306 // always friendly to self
6310 // always friendly to GM in GM mode
6311 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
6314 // always non-friendly to enemy
6315 if(getVictim()==unit
|| unit
->getVictim()==this)
6318 // test pet/charm masters instead pers/charmeds
6319 Unit
const* testerOwner
= GetCharmerOrOwner();
6320 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
6322 // always non-friendly to owner's enemy
6323 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
6326 // always non-friendly to enemy owner
6327 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
6330 // always non-friendly to owner of owner's enemy
6331 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
6334 Unit
const* tester
= testerOwner
? testerOwner
: this;
6335 Unit
const* target
= targetOwner
? targetOwner
: unit
;
6337 // always friendly to target with common owner, or to owner/pet
6341 // special cases (Duel)
6342 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
6344 Player
const* pTester
= (Player
const*)tester
;
6345 Player
const* pTarget
= (Player
const*)target
;
6348 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
6352 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
6356 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
6360 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
))
6364 // Green/Blue (non-attackable)
6365 if(pTester
->GetTeam()==pTarget
->GetTeam())
6368 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
6369 return !pTarget
->IsPvP();
6372 // faction base cases
6373 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
6374 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
6375 if(!tester_faction
|| !target_faction
)
6378 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
6381 // PvC forced reaction and reputation case
6382 if(tester
->GetTypeId()==TYPEID_PLAYER
)
6385 ForcedReactions::const_iterator forceItr
= ((Player
const*)tester
)->m_forcedReactions
.find(target_faction
->faction
);
6386 if(forceItr
!=((Player
const*)tester
)->m_forcedReactions
.end())
6387 return forceItr
->second
>= REP_FRIENDLY
;
6389 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
6390 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
6391 if(raw_target_faction
->reputationListID
>=0)
6392 if(FactionState
const* FactionState
= ((Player
*)tester
)->GetFactionState(raw_target_faction
))
6393 return !(FactionState
->Flags
& FACTION_FLAG_AT_WAR
);
6395 // CvP forced reaction and reputation case
6396 else if(target
->GetTypeId()==TYPEID_PLAYER
)
6399 ForcedReactions::const_iterator forceItr
= ((Player
const*)target
)->m_forcedReactions
.find(tester_faction
->faction
);
6400 if(forceItr
!=((Player
const*)target
)->m_forcedReactions
.end())
6401 return forceItr
->second
>= REP_FRIENDLY
;
6403 // apply reputation state
6404 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
6405 if(raw_tester_faction
->reputationListID
>=0 )
6406 return ((Player
const*)target
)->GetReputationRank(raw_tester_faction
) >= REP_FRIENDLY
;
6409 // common faction based case (CvC,PvC,CvP)
6410 return tester_faction
->IsFriendlyTo(*target_faction
);
6413 bool Unit::IsHostileToPlayers() const
6415 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
6419 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
6420 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
6423 return my_faction
->IsHostileToPlayers();
6426 bool Unit::IsNeutralToAll() const
6428 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
6432 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
6433 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
6436 return my_faction
->IsNeutralToAll();
6439 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
6441 if(!victim
|| victim
== this)
6444 // dead units can neither attack nor be attacked
6445 if(!isAlive() || !victim
->isAlive())
6448 // player cannot attack in mount state
6449 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
6452 // nobody can attack GM in GM-mode
6453 if(victim
->GetTypeId()==TYPEID_PLAYER
)
6455 if(((Player
*)victim
)->isGameMaster())
6460 if(((Creature
*)victim
)->IsInEvadeMode())
6464 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
6465 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
6466 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
6470 if (m_attacking
== victim
)
6472 // switch to melee attack from ranged/magic
6473 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
6475 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
6476 SendAttackStart(victim
);
6485 SetUInt64Value(UNIT_FIELD_TARGET
, victim
->GetGUID());
6488 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
6489 m_attacking
= victim
;
6490 m_attacking
->_addAttacker(this);
6492 if(m_attacking
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)m_attacking
)->AI())
6493 ((Creature
*)m_attacking
)->AI()->AttackedBy(this);
6495 if(GetTypeId()==TYPEID_UNIT
)
6497 WorldPacket
data(SMSG_AI_REACTION
, 12);
6498 data
<< uint64(GetGUID());
6499 data
<< uint32(AI_REACTION_AGGRO
); // Aggro sound
6500 ((WorldObject
*)this)->SendMessageToSet(&data
, true);
6502 ((Creature
*)this)->CallAssistance();
6503 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
6506 // delay offhand weapon attack to next attack time
6507 if(haveOffhandWeapon())
6508 resetAttackTimer(OFF_ATTACK
);
6511 SendAttackStart(victim
);
6516 bool Unit::AttackStop()
6521 Unit
* victim
= m_attacking
;
6523 m_attacking
->_removeAttacker(this);
6527 SetUInt64Value(UNIT_FIELD_TARGET
, 0);
6529 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
6531 InterruptSpell(CURRENT_MELEE_SPELL
);
6533 if( GetTypeId()==TYPEID_UNIT
)
6535 // reset call assistance
6536 ((Creature
*)this)->SetNoCallAssistance(false);
6539 SendAttackStop(victim
);
6544 void Unit::CombatStop(bool cast
)
6546 if(cast
& IsNonMeleeSpellCasted(false))
6547 InterruptNonMeleeSpells(false);
6550 RemoveAllAttackers();
6551 if( GetTypeId()==TYPEID_PLAYER
)
6552 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
6556 void Unit::CombatStopWithPets(bool cast
)
6559 if(Pet
* pet
= GetPet())
6560 pet
->CombatStop(cast
);
6561 if(Unit
* charm
= GetCharm())
6562 charm
->CombatStop(cast
);
6563 if(GetTypeId()==TYPEID_PLAYER
)
6565 GuardianPetList
const& guardians
= ((Player
*)this)->GetGuardians();
6566 for(GuardianPetList::const_iterator itr
= guardians
.begin(); itr
!= guardians
.end(); ++itr
)
6567 if(Unit
* guardian
= Unit::GetUnit(*this,*itr
))
6568 guardian
->CombatStop(cast
);
6572 bool Unit::isAttackingPlayer() const
6574 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
6577 Pet
* pet
= GetPet();
6578 if(pet
&& pet
->isAttackingPlayer())
6581 Unit
* charmed
= GetCharm();
6582 if(charmed
&& charmed
->isAttackingPlayer())
6585 for (int8 i
= 0; i
< MAX_TOTEM
; i
++)
6589 Creature
*totem
= ObjectAccessor::GetCreature(*this, m_TotemSlot
[i
]);
6590 if(totem
&& totem
->isAttackingPlayer())
6598 void Unit::RemoveAllAttackers()
6600 while (!m_attackers
.empty())
6602 AttackerSet::iterator iter
= m_attackers
.begin();
6603 if(!(*iter
)->AttackStop())
6605 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
6606 m_attackers
.erase(iter
);
6611 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
6615 if (!HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)))
6617 SetFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
6618 if(GetTypeId() == TYPEID_PLAYER
)
6620 const PlayerSpellMap
& sp_list
= ((Player
*)this)->GetSpellMap();
6621 for (PlayerSpellMap::const_iterator itr
= sp_list
.begin(); itr
!= sp_list
.end(); ++itr
)
6623 if(itr
->second
->state
== PLAYERSPELL_REMOVED
) continue;
6624 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
6625 if (!spellInfo
|| !IsPassiveSpell(itr
->first
)) continue;
6626 if (spellInfo
->CasterAuraState
== flag
)
6627 CastSpell(this, itr
->first
, true, NULL
);
6634 if (HasFlag(UNIT_FIELD_AURASTATE
,1<<(flag
-1)))
6636 RemoveFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1));
6637 Unit::AuraMap
& tAuras
= GetAuras();
6638 for (Unit::AuraMap::iterator itr
= tAuras
.begin(); itr
!= tAuras
.end();)
6640 SpellEntry
const* spellProto
= (*itr
).second
->GetSpellProto();
6641 if (spellProto
->CasterAuraState
== flag
)
6643 // exceptions (applied at state but not removed at state change)
6645 if(spellProto
->SpellIconID
==2006 && spellProto
->SpellFamilyName
==SPELLFAMILY_WARRIOR
&& spellProto
->SpellFamilyFlags
==0x100000)
6660 Unit
*Unit::GetOwner() const
6662 uint64 ownerid
= GetOwnerGUID();
6665 return ObjectAccessor::GetUnit(*this, ownerid
);
6668 Unit
*Unit::GetCharmer() const
6670 if(uint64 charmerid
= GetCharmerGUID())
6671 return ObjectAccessor::GetUnit(*this, charmerid
);
6675 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
6677 uint64 guid
= GetCharmerOrOwnerGUID();
6678 if(IS_PLAYER_GUID(guid
))
6679 return ObjectAccessor::GetPlayer(*this, guid
);
6681 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
6684 Pet
* Unit::GetPet() const
6686 if(uint64 pet_guid
= GetPetGUID())
6688 if(Pet
* pet
= ObjectAccessor::GetPet(pet_guid
))
6691 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
6692 const_cast<Unit
*>(this)->SetPet(0);
6698 Unit
* Unit::GetCharm() const
6700 if(uint64 charm_guid
= GetCharmGUID())
6702 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
6705 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
6706 const_cast<Unit
*>(this)->SetCharm(0);
6712 void Unit::SetPet(Pet
* pet
)
6714 SetUInt64Value(UNIT_FIELD_SUMMON
, pet
? pet
->GetGUID() : 0);
6716 // FIXME: hack, speed must be set only at follow
6718 for(int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
6719 pet
->SetSpeed(UnitMoveType(i
), m_speed_rate
[i
], true);
6722 void Unit::SetCharm(Unit
* pet
)
6724 SetUInt64Value(UNIT_FIELD_CHARM
, pet
? pet
->GetGUID() : 0);
6726 if(GetTypeId() == TYPEID_PLAYER
)
6727 ((Player
*)this)->m_mover
= pet
? pet
: this;
6730 void Unit::UnsummonAllTotems()
6732 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
6737 Creature
*OldTotem
= ObjectAccessor::GetCreature(*this, m_TotemSlot
[i
]);
6738 if (OldTotem
&& OldTotem
->isTotem())
6739 ((Totem
*)OldTotem
)->UnSummon();
6743 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, bool critical
)
6746 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
6747 data
.append(pVictim
->GetPackGUID());
6748 data
.append(GetPackGUID());
6749 data
<< uint32(SpellID
);
6750 data
<< uint32(Damage
);
6751 data
<< uint32(0); // over healing?
6752 data
<< uint8(critical
? 1 : 0);
6753 data
<< uint8(0); // unused in client?
6754 SendMessageToSet(&data
, true);
6757 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
6759 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
6760 data
.append(pVictim
->GetPackGUID());
6761 data
.append(GetPackGUID());
6762 data
<< uint32(SpellID
);
6763 data
<< uint32(powertype
);
6764 data
<< uint32(Damage
);
6765 SendMessageToSet(&data
, true);
6768 uint32
Unit::SpellDamageBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
)
6770 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
6773 int32 BonusDamage
= 0;
6774 if( GetTypeId()==TYPEID_UNIT
)
6776 // Pets just add their bonus damage to their spell damage
6777 // note that their spell damage is just gain of their own auras
6778 if (((Creature
*)this)->isPet())
6780 BonusDamage
= ((Pet
*)this)->GetBonusDamage();
6782 // For totems get damage bonus from owner (statue isn't totem in fact)
6783 else if (((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
6785 if(Unit
* owner
= GetOwner())
6786 return owner
->SpellDamageBonus(pVictim
, spellProto
, pdamage
, damagetype
);
6791 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
6793 // Taken/Done fixed damage bonus auras
6794 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonus(GetSpellSchoolMask(spellProto
))+BonusDamage
;
6795 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
6797 // Damage over Time spells bonus calculation
6798 float DotFactor
= 1.0f
;
6799 if(damagetype
== DOT
)
6801 int32 DotDuration
= GetSpellDuration(spellProto
);
6805 if(DotDuration
> 30000) DotDuration
= 30000;
6806 if(!IsChanneledSpell(spellProto
)) DotFactor
= DotDuration
/ 15000.0f
;
6808 for(int j
= 0; j
< 3; j
++)
6810 if( spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& (
6811 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_DAMAGE
||
6812 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
) )
6819 if(spellProto
->EffectAmplitude
[x
] != 0)
6820 DotTicks
= DotDuration
/ spellProto
->EffectAmplitude
[x
];
6823 DoneAdvertisedBenefit
/= DotTicks
;
6824 TakenAdvertisedBenefit
/= DotTicks
;
6829 // Taken/Done total percent damage auras
6830 float DoneTotalMod
= 1.0f
;
6831 float TakenTotalMod
= 1.0f
;
6834 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
6835 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
6837 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
6838 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
6839 // -1 == any item class (not wand then)
6840 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
6841 // 0 == any inventory type (not wand then)
6843 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
6847 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
6848 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
6849 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
6850 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
6851 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
6854 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
6855 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
6856 if( (*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
) )
6857 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
6859 // .. taken pct: scripted (increases damage of * against targets *)
6860 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
6861 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
6863 switch((*i
)->GetModifier()->m_miscvalue
)
6866 case 4920: case 4919:
6867 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
6868 TakenTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
; break;
6872 // .. taken pct: dummy auras
6873 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
6874 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
6876 switch((*i
)->GetSpellProto()->SpellIconID
)
6880 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) )
6882 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
6884 float mod
= -((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
6885 if (mod
< (*i
)->GetModifier()->m_amount
)
6886 mod
= (*i
)->GetModifier()->m_amount
;
6887 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
6892 for(int j
=0;j
<3;j
++)
6894 if(GetEffectMechanic(spellProto
, j
)==MECHANIC_BLEED
)
6896 TakenTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
6904 // Distribute Damage over multiple effects, reduce by AoE
6905 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
6907 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
6908 for(int j
= 0; j
< 3; ++j
)
6910 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
6911 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
6918 switch(spellProto
->SpellFamilyName
)
6920 case SPELLFAMILY_MAGE
:
6921 // Ignite - do not modify, it is (8*Rank)% damage of procing Spell
6922 if(spellProto
->Id
==12654)
6927 else if((spellProto
->SpellFamilyFlags
& 0x20000LL
) && spellProto
->SpellIconID
== 186)
6929 CastingTime
/= 3; // applied 1/3 bonuses in case generic target
6930 if(pVictim
->isFrozen()) // and compensate this for frozen target.
6931 TakenTotalMod
*= 3.0f
;
6933 // Pyroblast - 115% of Fire Damage, DoT - 20% of Fire Damage
6934 else if((spellProto
->SpellFamilyFlags
& 0x400000LL
) && spellProto
->SpellIconID
== 184 )
6936 DotFactor
= damagetype
== DOT
? 0.2f
: 1.0f
;
6937 CastingTime
= damagetype
== DOT
? 3500 : 4025;
6939 // Fireball - 100% of Fire Damage, DoT - 0% of Fire Damage
6940 else if((spellProto
->SpellFamilyFlags
& 0x1LL
) && spellProto
->SpellIconID
== 185)
6943 DotFactor
= damagetype
== DOT
? 0.0f
: 1.0f
;
6946 else if (spellProto
->SpellFamilyFlags
& 0x0000000800000000LL
)
6950 // Arcane Missiles triggered spell
6951 else if ((spellProto
->SpellFamilyFlags
& 0x200000LL
) && spellProto
->SpellIconID
== 225)
6955 // Blizzard triggered spell
6956 else if ((spellProto
->SpellFamilyFlags
& 0x80080LL
) && spellProto
->SpellIconID
== 285)
6961 case SPELLFAMILY_WARLOCK
:
6963 if((spellProto
->SpellFamilyFlags
& 0x40000LL
) && spellProto
->SpellIconID
== 208)
6965 CastingTime
= 2800; // 80% from +shadow damage
6966 DoneTotalMod
= 1.0f
;
6967 TakenTotalMod
= 1.0f
;
6970 else if((spellProto
->SpellFamilyFlags
& 0x80000000LL
) && spellProto
->SpellIconID
== 154 && GetPetGUID())
6972 CastingTime
= 3360; // 96% from +shadow damage
6973 DoneTotalMod
= 1.0f
;
6974 TakenTotalMod
= 1.0f
;
6976 // Soul Fire - 115% of Fire Damage
6977 else if((spellProto
->SpellFamilyFlags
& 0x8000000000LL
) && spellProto
->SpellIconID
== 184)
6981 // Curse of Agony - 120% of Shadow Damage
6982 else if((spellProto
->SpellFamilyFlags
& 0x0000000400LL
) && spellProto
->SpellIconID
== 544)
6986 // Drain Mana - 0% of Shadow Damage
6987 else if((spellProto
->SpellFamilyFlags
& 0x10LL
) && spellProto
->SpellIconID
== 548)
6991 // Drain Soul 214.3%
6992 else if ((spellProto
->SpellFamilyFlags
& 0x4000LL
) && spellProto
->SpellIconID
== 113 )
6997 else if ((spellProto
->SpellFamilyFlags
& 0x40LL
) && spellProto
->SpellIconID
== 937)
6999 CastingTime
= damagetype
== DOT
? 5000 : 500; // self damage seems to be so
7001 // Unstable Affliction - 180%
7002 else if (spellProto
->Id
== 31117 && spellProto
->SpellIconID
== 232)
7007 else if ((spellProto
->SpellFamilyFlags
& 0x2LL
) && spellProto
->SpellIconID
== 313)
7012 case SPELLFAMILY_PALADIN
:
7013 // Consecration - 95% of Holy Damage
7014 if((spellProto
->SpellFamilyFlags
& 0x20LL
) && spellProto
->SpellIconID
== 51)
7019 // Seal of Righteousness - 10.2%/9.8% ( based on weapon type ) of Holy Damage, multiplied by weapon speed
7020 else if((spellProto
->SpellFamilyFlags
& 0x8000000LL
) && spellProto
->SpellIconID
== 25)
7022 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
7023 float wspeed
= GetAttackTime(BASE_ATTACK
)/1000.0f
;
7025 if( item
&& item
->GetProto()->InventoryType
== INVTYPE_2HWEAPON
)
7026 CastingTime
= uint32(wspeed
*3500*0.102f
);
7028 CastingTime
= uint32(wspeed
*3500*0.098f
);
7030 // Judgement of Righteousness - 73%
7031 else if ((spellProto
->SpellFamilyFlags
& 1024) && spellProto
->SpellIconID
== 25)
7035 // Seal of Vengeance - 17% per Fully Stacked Tick - 5 Applications
7036 else if ((spellProto
->SpellFamilyFlags
& 0x80000000000LL
) && spellProto
->SpellIconID
== 2292)
7041 // Holy shield - 5% of Holy Damage
7042 else if ((spellProto
->SpellFamilyFlags
& 0x4000000000LL
) && spellProto
->SpellIconID
== 453)
7046 // Blessing of Sanctuary - 0%
7047 else if ((spellProto
->SpellFamilyFlags
& 0x10000000LL
) && spellProto
->SpellIconID
== 29)
7051 // Seal of Righteousness trigger - already computed for parent spell
7052 else if ( spellProto
->SpellFamilyName
==SPELLFAMILY_PALADIN
&& spellProto
->SpellIconID
==25 && spellProto
->AttributesEx4
& 0x00800000LL
)
7057 case SPELLFAMILY_SHAMAN
:
7059 if (spellProto
->SpellFamilyFlags
& 0x000040000000LL
)
7061 if (spellProto
->SpellIconID
== 33) // Fire Nova totem attack must be 21.4%(untested)
7062 CastingTime
= 749; // ignore CastingTime and use as modifier
7063 else if (spellProto
->SpellIconID
== 680) // Searing Totem attack 8%
7064 CastingTime
= 280; // ignore CastingTime and use as modifier
7065 else if (spellProto
->SpellIconID
== 37) // Magma totem attack must be 6.67%(untested)
7066 CastingTime
= 234; // ignore CastingTimePenalty and use as modifier
7068 // Lightning Shield (and proc shield from T2 8 pieces bonus ) 33% per charge
7069 else if( (spellProto
->SpellFamilyFlags
& 0x00000000400LL
) || spellProto
->Id
== 23552)
7070 CastingTime
= 1155; // ignore CastingTimePenalty and use as modifier
7072 case SPELLFAMILY_PRIEST
:
7073 // Mana Burn - 0% of Shadow Damage
7074 if((spellProto
->SpellFamilyFlags
& 0x10LL
) && spellProto
->SpellIconID
== 212)
7078 // Mind Flay - 59% of Shadow Damage
7079 else if((spellProto
->SpellFamilyFlags
& 0x800000LL
) && spellProto
->SpellIconID
== 548)
7083 // Holy Fire - 86.71%, DoT - 16.5%
7084 else if ((spellProto
->SpellFamilyFlags
& 0x100000LL
) && spellProto
->SpellIconID
== 156)
7086 DotFactor
= damagetype
== DOT
? 0.165f
: 1.0f
;
7087 CastingTime
= damagetype
== DOT
? 3500 : 3035;
7089 // Shadowguard - 28% per charge
7090 else if ((spellProto
->SpellFamilyFlags
& 0x2000000LL
) && spellProto
->SpellIconID
== 19)
7094 // Touch of Weakeness - 10%
7095 else if ((spellProto
->SpellFamilyFlags
& 0x80000LL
) && spellProto
->SpellIconID
== 1591)
7099 // Reflective Shield (back damage) - 0% (other spells fit to check not have damage effects/auras)
7100 else if (spellProto
->SpellFamilyFlags
== 0 && spellProto
->SpellIconID
== 566)
7105 else if ((spellProto
->SpellFamilyFlags
& 0x400000LL
) && spellProto
->SpellIconID
== 1874)
7110 case SPELLFAMILY_DRUID
:
7111 // Hurricane triggered spell
7112 if((spellProto
->SpellFamilyFlags
& 0x400000LL
) && spellProto
->SpellIconID
== 220)
7117 case SPELLFAMILY_WARRIOR
:
7118 case SPELLFAMILY_HUNTER
:
7119 case SPELLFAMILY_ROGUE
:
7126 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
7128 // Spellmod SpellDamage
7129 float SpellModSpellDamage
= 100.0f
;
7131 if(Player
* modOwner
= GetSpellModOwner())
7132 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
7134 SpellModSpellDamage
/= 100.0f
;
7136 float DoneActualBenefit
= DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* SpellModSpellDamage
* LvlPenalty
;
7137 float TakenActualBenefit
= TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
;
7139 float tmpDamage
= (float(pdamage
)+DoneActualBenefit
)*DoneTotalMod
;
7141 // Add flat bonus from spell damage versus
7142 tmpDamage
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
7144 // apply spellmod to Done damage
7145 if(Player
* modOwner
= GetSpellModOwner())
7146 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
7148 tmpDamage
= (tmpDamage
+TakenActualBenefit
)*TakenTotalMod
;
7150 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
7151 tmpDamage
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
7153 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
7156 int32
Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask
)
7158 int32 DoneAdvertisedBenefit
= 0;
7161 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
7162 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
7163 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
7164 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
7165 // -1 == any item class (not wand then)
7166 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
7167 // 0 == any inventory type (not wand then)
7168 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7170 if (GetTypeId() == TYPEID_PLAYER
)
7172 // Damage bonus from stats
7173 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
7174 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
7176 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
7178 // stat used stored in miscValueB for this aura
7179 Stats usedStat
= Stats((*i
)->GetMiscBValue());
7180 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
7183 // ... and attack power
7184 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
7185 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
7186 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
7187 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
7190 return DoneAdvertisedBenefit
;
7193 int32
Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
7195 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
7197 int32 TakenAdvertisedBenefit
= 0;
7198 // ..done (for creature type by mask) in taken
7199 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
7200 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
7201 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
7202 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7205 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
7206 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
7207 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
7208 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7210 return TakenAdvertisedBenefit
;
7213 bool Unit::isSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
7215 // not critting spell
7216 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
7219 float crit_chance
= 0.0f
;
7220 switch(spellProto
->DmgClass
)
7222 case SPELL_DAMAGE_CLASS_NONE
:
7224 case SPELL_DAMAGE_CLASS_MAGIC
:
7226 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
7228 // For other schools
7229 else if (GetTypeId() == TYPEID_PLAYER
)
7230 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
7233 crit_chance
= m_baseSpellCritChance
;
7234 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
7237 if (pVictim
&& !IsPositiveSpell(spellProto
->Id
))
7239 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
7240 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
7241 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
7242 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
7243 // Modify by player victim resilience
7244 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
7245 crit_chance
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
);
7246 // scripted (increase crit chance ... against ... target by x%
7247 if(pVictim
->isFrozen()) // Shatter
7249 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7250 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7252 switch((*i
)->GetModifier()->m_miscvalue
)
7254 case 849: crit_chance
+= 17.0f
; break; //Shatter Rank 1
7255 case 910: crit_chance
+= 34.0f
; break; //Shatter Rank 2
7256 case 911: crit_chance
+= 50.0f
; break; //Shatter Rank 3
7263 case SPELL_DAMAGE_CLASS_MELEE
:
7264 case SPELL_DAMAGE_CLASS_RANGED
:
7268 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
7269 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
7277 // only players use intelligence for critical chance computations
7278 if(Player
* modOwner
= GetSpellModOwner())
7279 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
7281 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
7282 if (roll_chance_f(crit_chance
))
7287 uint32
Unit::SpellCriticalBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
7289 // Calculate critical bonus
7291 switch(spellProto
->DmgClass
)
7293 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
7294 case SPELL_DAMAGE_CLASS_RANGED
:
7295 // TODO: write here full calculation for melee/ranged spells
7296 crit_bonus
= damage
;
7299 crit_bonus
= damage
/ 2; // for spells is 50%
7303 // adds additional damage to crit_bonus (from talents)
7304 if(Player
* modOwner
= GetSpellModOwner())
7305 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
7309 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
7310 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
7314 damage
+= crit_bonus
;
7319 uint32
Unit::SpellHealingBonus(SpellEntry
const *spellProto
, uint32 healamount
, DamageEffectType damagetype
, Unit
*pVictim
)
7321 // For totems get healing bonus from owner (statue isn't totem in fact)
7322 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
7323 if(Unit
* owner
= GetOwner())
7324 return owner
->SpellHealingBonus(spellProto
, healamount
, damagetype
, pVictim
);
7328 // These Spells are doing fixed amount of healing (TODO found less hack-like check)
7329 if (spellProto
->Id
== 15290 || spellProto
->Id
== 39373 ||
7330 spellProto
->Id
== 33778 || spellProto
->Id
== 379 ||
7331 spellProto
->Id
== 38395 || spellProto
->Id
== 40972)
7334 int32 AdvertisedBenefit
= SpellBaseHealingBonus(GetSpellSchoolMask(spellProto
));
7335 uint32 CastingTime
= GetSpellCastTime(spellProto
);
7338 AdvertisedBenefit
+= SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
7340 // Blessing of Light dummy effects healing taken from Holy Light and Flash of Light
7341 if (spellProto
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& (spellProto
->SpellFamilyFlags
& 0x00000000C0000000LL
))
7343 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
7344 for(AuraList::const_iterator i
= mDummyAuras
.begin();i
!= mDummyAuras
.end(); ++i
)
7346 if((*i
)->GetSpellProto()->SpellVisual
[0] == 9180)
7349 if ((spellProto
->SpellFamilyFlags
& 0x0000000040000000LL
) && (*i
)->GetEffIndex() == 1)
7350 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7352 else if ((spellProto
->SpellFamilyFlags
& 0x0000000080000000LL
) && (*i
)->GetEffIndex() == 0)
7353 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7358 float ActualBenefit
= 0.0f
;
7360 if (AdvertisedBenefit
!= 0)
7362 // Healing over Time spells
7363 float DotFactor
= 1.0f
;
7364 if(damagetype
== DOT
)
7366 int32 DotDuration
= GetSpellDuration(spellProto
);
7370 if(DotDuration
> 30000) DotDuration
= 30000;
7371 if(!IsChanneledSpell(spellProto
)) DotFactor
= DotDuration
/ 15000.0f
;
7373 for(int j
= 0; j
< 3; j
++)
7375 if( spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& (
7376 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_HEAL
||
7377 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
) )
7384 if(spellProto
->EffectAmplitude
[x
] != 0)
7385 DotTicks
= DotDuration
/ spellProto
->EffectAmplitude
[x
];
7387 AdvertisedBenefit
/= DotTicks
;
7391 // distribute healing to all effects, reduce AoE damage
7392 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
7394 // 0% bonus for damage and healing spells for leech spells from healing bonus
7395 for(int j
= 0; j
< 3; ++j
)
7397 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
7398 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
7406 switch (spellProto
->SpellFamilyName
)
7408 case SPELLFAMILY_SHAMAN
:
7409 // Healing stream from totem (add 6% per tick from hill bonus owner)
7410 if (spellProto
->SpellFamilyFlags
& 0x000000002000LL
)
7412 // Earth Shield 30% per charge
7413 else if (spellProto
->SpellFamilyFlags
& 0x40000000000LL
)
7416 case SPELLFAMILY_DRUID
:
7418 if (spellProto
->SpellFamilyFlags
& 0x1000000000LL
)
7420 CastingTime
= damagetype
== DOT
? 3500 : 1200;
7421 DotFactor
= damagetype
== DOT
? 0.519f
: 1.0f
;
7423 // Tranquility triggered spell
7424 else if (spellProto
->SpellFamilyFlags
& 0x80LL
)
7427 else if (spellProto
->SpellFamilyFlags
& 0x10LL
)
7430 else if (spellProto
->SpellFamilyFlags
& 0x40LL
)
7432 DotFactor
= damagetype
== DOT
? 0.705f
: 1.0f
;
7433 CastingTime
= damagetype
== DOT
? 3500 : 1010;
7436 case SPELLFAMILY_PRIEST
:
7438 if ((spellProto
->SpellFamilyFlags
& 0x8000000LL
) && spellProto
->SpellIconID
== 1874)
7441 case SPELLFAMILY_PALADIN
:
7442 // Seal and Judgement of Light
7443 if ( spellProto
->SpellFamilyFlags
& 0x100040000LL
)
7446 case SPELLFAMILY_WARRIOR
:
7447 case SPELLFAMILY_ROGUE
:
7448 case SPELLFAMILY_HUNTER
:
7453 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
7455 // Spellmod SpellDamage
7456 float SpellModSpellDamage
= 100.0f
;
7458 if(Player
* modOwner
= GetSpellModOwner())
7459 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
7461 SpellModSpellDamage
/= 100.0f
;
7463 ActualBenefit
= (float)AdvertisedBenefit
* ((float)CastingTime
/ 3500.0f
) * DotFactor
* SpellModSpellDamage
* LvlPenalty
;
7466 // use float as more appropriate for negative values and percent applying
7467 float heal
= healamount
+ ActualBenefit
;
7469 // TODO: check for ALL/SPELLS type
7470 // Healing done percent
7471 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
7472 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
7473 heal
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
7475 // apply spellmod to Done amount
7476 if(Player
* modOwner
= GetSpellModOwner())
7477 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
7479 // Healing Wave cast
7480 if (spellProto
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& spellProto
->SpellFamilyFlags
& 0x0000000000000040LL
)
7482 // Search for Healing Way on Victim (stack up to 3 time)
7484 Unit::AuraList
const& auraDummy
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
7485 for(Unit::AuraList::const_iterator itr
= auraDummy
.begin(); itr
!=auraDummy
.end(); ++itr
)
7486 if((*itr
)->GetId() == 29203)
7487 pctMod
+= (*itr
)->GetModifier()->m_amount
;
7490 heal
= heal
* (100 + pctMod
) / 100;
7493 // Healing taken percent
7494 float minval
= pVictim
->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
7496 heal
*= (100.0f
+ minval
) / 100.0f
;
7498 float maxval
= pVictim
->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
7500 heal
*= (100.0f
+ maxval
) / 100.0f
;
7502 if (heal
< 0) heal
= 0;
7504 return uint32(heal
);
7507 int32
Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask
)
7509 int32 AdvertisedBenefit
= 0;
7511 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
7512 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
7513 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
7514 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7516 // Healing bonus of spirit, intellect and strength
7517 if (GetTypeId() == TYPEID_PLAYER
)
7519 // Healing bonus from stats
7520 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
7521 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
7523 // stat used dependent from misc value (stat index)
7524 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
7525 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
7528 // ... and attack power
7529 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
7530 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
7531 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
7532 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
7534 return AdvertisedBenefit
;
7537 int32
Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
7539 int32 AdvertisedBenefit
= 0;
7540 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING
);
7541 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
7542 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
7543 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7544 return AdvertisedBenefit
;
7547 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
)
7549 //If m_immuneToSchool type contain this school type, IMMUNE damage.
7550 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
7551 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
7552 if(itr
->type
& shoolMask
)
7555 //If m_immuneToDamage type contain magic, IMMUNE damage.
7556 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
7557 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
7558 if(itr
->type
& shoolMask
)
7564 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
)
7569 //FIX ME this hack: don't get feared if stunned
7570 if (spellInfo
->Mechanic
== MECHANIC_FEAR
)
7572 if ( hasUnitState(UNIT_STAT_STUNNED
) )
7576 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
7577 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
7578 if(itr
->type
== spellInfo
->Dispel
)
7581 if( !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
) && // unaffected by school immunity
7582 !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)) // can remove immune (by dispell or immune it)
7584 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
7585 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
7586 if( !(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
7587 (itr
->type
& GetSpellSchoolMask(spellInfo
)) )
7591 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
7592 for(SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
7594 if(itr
->type
== spellInfo
->Mechanic
)
7603 bool Unit::IsImmunedToSpellEffect(uint32 effect
, uint32 mechanic
) const
7605 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
7606 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
7607 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
7608 if(itr
->type
== effect
)
7611 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
7612 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
7613 if(itr
->type
== mechanic
)
7619 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
7624 uint32 family
= spellInfo
->SpellFamilyName
;
7625 uint64 flags
= spellInfo
->SpellFamilyFlags
;
7627 if((family
== 5 && flags
== 256) || //Searing Pain
7628 (family
== 6 && flags
== 8192) || //Mind Blast
7629 (family
== 11 && flags
== 1048576)) //Earth Shock
7635 void Unit::MeleeDamageBonus(Unit
*pVictim
, uint32
*pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
)
7643 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
7645 // Taken/Done fixed damage bonus auras
7646 int32 DoneFlatBenefit
= 0;
7647 int32 TakenFlatBenefit
= 0;
7649 // ..done (for creature type by mask) in taken
7650 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
7651 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
7652 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
7653 DoneFlatBenefit
+= (*i
)->GetModifier()->m_amount
;
7656 // SPELL_AURA_MOD_DAMAGE_DONE included in weapon damage
7658 // ..done (base at attack power for marked target and base at attack power for creature type)
7660 if(attType
== RANGED_ATTACK
)
7662 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
7664 // ..done (base at attack power and creature type)
7665 AuraList
const& mCreatureAttackPower
= GetAurasByType(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
);
7666 for(AuraList::const_iterator i
= mCreatureAttackPower
.begin();i
!= mCreatureAttackPower
.end(); ++i
)
7667 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
7668 APbonus
+= (*i
)->GetModifier()->m_amount
;
7672 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
7674 // ..done (base at attack power and creature type)
7675 AuraList
const& mCreatureAttackPower
= GetAurasByType(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
);
7676 for(AuraList::const_iterator i
= mCreatureAttackPower
.begin();i
!= mCreatureAttackPower
.end(); ++i
)
7677 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
7678 APbonus
+= (*i
)->GetModifier()->m_amount
;
7681 if (APbonus
!=0) // Can be negative
7683 bool normalized
= false;
7686 for (uint8 i
= 0; i
<3;i
++)
7688 if (spellProto
->Effect
[i
] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG
)
7696 DoneFlatBenefit
+= int32(APbonus
/14.0f
* GetAPMultiplier(attType
,normalized
));
7700 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
7701 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
7702 if((*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask())
7703 TakenFlatBenefit
+= (*i
)->GetModifier()->m_amount
;
7705 if(attType
!=RANGED_ATTACK
)
7706 TakenFlatBenefit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
7708 TakenFlatBenefit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
7710 // Done/Taken total percent damage auras
7711 float DoneTotalMod
= 1;
7712 float TakenTotalMod
= 1;
7715 // SPELL_AURA_MOD_DAMAGE_PERCENT_DONE included in weapon damage
7716 // SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT included in weapon damage
7718 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
7719 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
7720 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
7721 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7724 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
7725 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
7726 if((*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask())
7727 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7729 // .. taken pct: dummy auras
7730 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
7731 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
7733 switch((*i
)->GetSpellProto()->SpellIconID
)
7737 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
7739 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
7741 float mod
= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
7742 if (mod
< (*i
)->GetModifier()->m_amount
)
7743 mod
= (*i
)->GetModifier()->m_amount
;
7744 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
7749 if(spellProto
==NULL
)
7751 // Should increase Shred (initial Damage of Lacerate and Rake handled in Spell::EffectSchoolDMG)
7752 if(spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& (spellProto
->SpellFamilyFlags
==0x00008000LL
))
7753 TakenTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
7758 // .. taken pct: class scripts
7759 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7760 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
7762 switch((*i
)->GetMiscValue())
7764 case 6427: case 6428: // Dirty Deeds
7765 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
7767 Aura
* eff0
= GetAura((*i
)->GetId(),0);
7768 if(!eff0
|| (*i
)->GetEffIndex()!=1)
7770 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
7774 // effect 0 have expected value but in negative state
7775 TakenTotalMod
*= (-eff0
->GetModifier()->m_amount
+100.0f
)/100.0f
;
7781 if(attType
!= RANGED_ATTACK
)
7783 AuraList
const& mModMeleeDamageTakenPercent
= pVictim
->GetAurasByType(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
7784 for(AuraList::const_iterator i
= mModMeleeDamageTakenPercent
.begin(); i
!= mModMeleeDamageTakenPercent
.end(); ++i
)
7785 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7789 AuraList
const& mModRangedDamageTakenPercent
= pVictim
->GetAurasByType(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
7790 for(AuraList::const_iterator i
= mModRangedDamageTakenPercent
.begin(); i
!= mModRangedDamageTakenPercent
.end(); ++i
)
7791 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7794 float tmpDamage
= float(int32(*pdamage
) + DoneFlatBenefit
) * DoneTotalMod
;
7796 // apply spellmod to Done damage
7799 if(Player
* modOwner
= GetSpellModOwner())
7800 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_DAMAGE
, tmpDamage
);
7803 tmpDamage
= (tmpDamage
+ TakenFlatBenefit
)*TakenTotalMod
;
7805 // bonus result can be negative
7806 *pdamage
= tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
7809 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
7813 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
7816 if(itr
->type
== type
)
7818 m_spellImmune
[op
].erase(itr
);
7819 next
= m_spellImmune
[op
].begin();
7823 Immune
.spellId
= spellId
;
7825 m_spellImmune
[op
].push_back(Immune
);
7829 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
7831 if(itr
->spellId
== spellId
)
7833 m_spellImmune
[op
].erase(itr
);
7841 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
7843 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
7845 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
7846 RemoveAurasWithDispelType(type
);
7849 float Unit::GetWeaponProcChance() const
7851 // normalized proc chance for weapon attack speed
7853 if(isAttackReady(BASE_ATTACK
))
7854 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
7855 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
7856 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
7860 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
7862 // proc per minute chance calculation
7863 if (PPM
<= 0) return 0.0f
;
7864 uint32 result
= uint32((WeaponSpeed
* PPM
) / 600.0f
); // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
7868 void Unit::Mount(uint32 mount
)
7873 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
7875 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
7877 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
7880 if(GetTypeId() == TYPEID_PLAYER
)
7882 Pet
* pet
= GetPet();
7885 if(pet
->isControlled())
7887 ((Player
*)this)->SetTemporaryUnsummonedPetNumber(pet
->GetCharmInfo()->GetPetNumber());
7888 ((Player
*)this)->SetOldPetSpell(pet
->GetUInt32Value(UNIT_CREATED_BY_SPELL
));
7891 ((Player
*)this)->RemovePet(NULL
,PET_SAVE_NOT_IN_SLOT
);
7894 ((Player
*)this)->SetTemporaryUnsummonedPetNumber(0);
7898 void Unit::Unmount()
7903 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
7905 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
7906 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
7908 // only resummon old pet if the player is already added to a map
7909 // this prevents adding a pet to a not created map which would otherwise cause a crash
7910 // (it could probably happen when logging in after a previous crash)
7911 if(GetTypeId() == TYPEID_PLAYER
&& IsInWorld() && ((Player
*)this)->GetTemporaryUnsummonedPetNumber() && isAlive())
7913 Pet
* NewPet
= new Pet
;
7914 if(!NewPet
->LoadPetFromDB((Player
*)this, 0, ((Player
*)this)->GetTemporaryUnsummonedPetNumber(), true))
7917 ((Player
*)this)->SetTemporaryUnsummonedPetNumber(0);
7921 void Unit::SetInCombatWith(Unit
* enemy
)
7923 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
7926 SetInCombatState(true);
7931 if(eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
7933 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
7934 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
7936 SetInCombatState(true);
7940 SetInCombatState(false);
7943 void Unit::SetInCombatState(bool PvP
)
7945 // only alive units can be in combat
7950 m_CombatTimer
= 5000;
7951 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
7953 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
7954 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
7957 void Unit::ClearInCombat()
7960 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
7962 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
7963 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
7965 // Player's state will be cleared in Player::UpdateContestedPvP
7966 if(GetTypeId()!=TYPEID_PLAYER
)
7967 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
7970 bool Unit::isTargetableForAttack() const
7972 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
7975 if(HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
7978 return isAlive() && !hasUnitState(UNIT_STAT_DIED
)&& !isInFlight() /*&& !isStealth()*/;
7981 int32
Unit::ModifyHealth(int32 dVal
)
7988 int32 curHealth
= (int32
)GetHealth();
7990 int32 val
= dVal
+ curHealth
;
7997 int32 maxHealth
= (int32
)GetMaxHealth();
8002 gain
= val
- curHealth
;
8004 else if(curHealth
!= maxHealth
)
8006 SetHealth(maxHealth
);
8007 gain
= maxHealth
- curHealth
;
8013 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
8020 int32 curPower
= (int32
)GetPower(power
);
8022 int32 val
= dVal
+ curPower
;
8029 int32 maxPower
= (int32
)GetMaxPower(power
);
8033 SetPower(power
,val
);
8034 gain
= val
- curPower
;
8036 else if(curPower
!= maxPower
)
8038 SetPower(power
,maxPower
);
8039 gain
= maxPower
- curPower
;
8045 bool Unit::isVisibleForOrDetect(Unit
const* u
, bool detect
, bool inVisibleList
, bool is3dDistance
) const
8050 // Always can see self
8054 // player visible for other player if not logout and at same transport
8055 // including case when player is out of world
8056 bool at_same_transport
=
8057 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
8058 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
8059 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
8060 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
8063 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
8066 // forbidden to seen (at GM respawn command)
8067 if(m_Visibility
==VISIBILITY_RESPAWN
)
8070 // always seen by owner
8071 if(GetCharmerOrOwnerGUID()==u
->GetGUID())
8074 // Grid dead/alive checks
8075 if( u
->GetTypeId()==TYPEID_PLAYER
)
8077 // non visible at grid for any stealth state
8078 if(!IsVisibleInGridForPlayer((Player
*)u
))
8081 // if player is dead then he can't detect anyone in any cases
8087 // all dead creatures/players not visible for any creatures
8088 if(!u
->isAlive() || !isAlive())
8092 // different visible distance checks
8093 if(u
->isInFlight()) // what see player in flight
8095 // use object grey distance for all (only see objects any way)
8096 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
8099 else if(!isAlive()) // distance for show body
8101 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
8104 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
8106 if(u
->GetTypeId()==TYPEID_PLAYER
)
8108 // Players far than max visible distance for player or not in our map are not visible too
8109 if (!at_same_transport
&& !IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForPlayer()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8114 // Units far than max visible distance for creature or not in our map are not visible too
8115 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForCreature()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8119 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
8121 // Pet/charmed far than max visible distance for player or not in our map are not visible too
8122 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForPlayer()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8125 else // distance for show creature
8127 // Units far than max visible distance for creature or not in our map are not visible too
8128 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForCreature()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8132 // Visible units, always are visible for all units, except for units under invisibility
8133 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0)
8136 // GMs see any players, not higher GMs and all units
8137 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
8139 if(GetTypeId() == TYPEID_PLAYER
)
8140 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
8145 // non faction visibility non-breakable for non-GMs
8146 if (m_Visibility
== VISIBILITY_OFF
)
8150 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
8152 // detectable invisibility case
8154 // Invisible units, always are visible for units under same invisibility type
8155 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
8156 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
8157 u
->canDetectInvisibilityOf(this) ||
8158 // Units that can detect invisibility always are visible for units that can be detected
8159 canDetectInvisibilityOf(u
) ))
8164 // special cases for always overwrite invisibility/stealth
8165 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
8168 if (!u
->IsHostileTo(this))
8170 // 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)
8171 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
8173 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
8176 // else apply same rules as for hostile case (detecting check for stealth)
8182 // Hunter mark functionality
8183 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
8184 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
8185 if((*iter
)->GetCasterGUID()==u
->GetGUID())
8188 // else apply detecting check for stealth
8191 // none other cases for detect invisibility, so invisible
8195 // else apply stealth detecting check
8198 // unit got in stealth in this moment and must ignore old detected state
8199 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
8202 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
8203 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
8206 // NOW ONLY STEALTH CASE
8208 // stealth and detected and visible for some seconds
8209 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->m_DetectInvTimer
> 300 && ((Player
*)u
)->HaveAtClient(this))
8212 //if in non-detect mode then invisible for unit
8218 // If is attacked then stealth is lost, some creature can use stealth too
8219 if( !getAttackers().empty() )
8222 // If there is collision rogue is seen regardless of level difference
8223 // TODO: check sizes in DB
8224 float distance
= GetDistance(u
);
8225 if (distance
< 0.24f
)
8228 //If a mob or player is stunned he will not be able to detect stealth
8229 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
8232 // Creature can detect target only in aggro radius
8233 if(u
->GetTypeId() != TYPEID_PLAYER
)
8235 //Always invisible from back and out of aggro range
8236 bool isInFront
= u
->isInFront(this,((Creature
const*)u
)->GetAttackDistance(this));
8242 //Always invisible from back
8243 bool isInFront
= u
->isInFront(this,(GetTypeId()==TYPEID_PLAYER
|| GetCharmerOrOwnerGUID()) ? World::GetMaxVisibleDistanceForPlayer() : World::GetMaxVisibleDistanceForCreature());
8248 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
8249 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
8251 //Calculation if target is in front
8253 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
8254 float visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
8256 //Visible distance is modified by
8257 //-Level Diff (every level diff = 1.0f in visible distance)
8258 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
8260 //This allows to check talent tree and will add addition stealth dependent on used points)
8261 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
8265 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
8266 //based on wowwiki every 5 mod we have 1 more level diff in calculation
8267 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_DETECT
)) - stealthMod
)/5.0f
;
8269 if(distance
> visibleDistance
)
8273 // Now check is target visible with LoS
8275 u
->GetPosition(ox
,oy
,oz
);
8276 return IsWithinLOS(ox
,oy
,oz
);
8279 void Unit::SetVisibility(UnitVisibility x
)
8287 if(GetTypeId()==TYPEID_PLAYER
)
8288 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
8290 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
8294 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
8296 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
8298 for(uint32 i
= 0; i
< 10; ++i
)
8300 if(((1 << i
) & mask
)==0)
8303 // find invisibility level
8304 uint32 invLevel
= 0;
8305 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
8306 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
8307 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
8308 invLevel
= (*itr
)->GetModifier()->m_amount
;
8310 // find invisibility detect level
8311 uint32 detectLevel
= 0;
8312 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
8313 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
8314 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
8315 detectLevel
= (*itr
)->GetModifier()->m_amount
;
8317 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
8319 detectLevel
= ((Player
*)this)->GetDrunkValue();
8322 if(invLevel
<= detectLevel
)
8330 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
)
8332 int32 main_speed_mod
= 0;
8333 float stack_bonus
= 1.0f
;
8334 float non_stack_bonus
= 1.0f
;
8342 if (IsMounted()) // Use on mount auras
8344 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
8345 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
8346 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
8350 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
8351 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
8352 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
8360 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
8363 case MOVE_SWIM_BACK
:
8367 if (IsMounted()) // Use on mount auras
8368 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
);
8369 else // Use not mount (shapeshift for example) auras (should stack)
8370 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT
);
8371 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS
);
8372 non_stack_bonus
= (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
))/100.0f
;
8375 case MOVE_FLIGHT_BACK
:
8378 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
8382 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
8383 // now we ready for speed calculation
8384 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
8392 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
8393 // TODO: possible affect only on MOVE_RUN
8394 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
8396 // Use speed from aura
8397 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
8398 if (speed
> max_speed
)
8407 // Apply strongest slow aura mod to speed
8408 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
8410 speed
*=(100.0f
+ slow
)/100.0f
;
8411 SetSpeed(mtype
, speed
, forced
);
8414 float Unit::GetSpeed( UnitMoveType mtype
) const
8416 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
8419 void Unit::SetSpeed(UnitMoveType mtype
, float rate
, bool forced
)
8424 // Update speed only on change
8425 if (m_speed_rate
[mtype
] == rate
)
8428 m_speed_rate
[mtype
] = rate
;
8430 propagateSpeedChange();
8438 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
8441 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+2+4+4+4+4+4+4+4);
8444 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
8447 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+2+4+4+4+4+4+4+4);
8449 case MOVE_SWIM_BACK
:
8450 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
8452 case MOVE_TURN_RATE
:
8453 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+2+4+4+4+4+4+4+4);
8456 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+2+4+4+4+4+4+4+4);
8458 case MOVE_FLIGHT_BACK
:
8459 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
8461 case MOVE_PITCH_RATE
:
8462 data
.Initialize(MSG_MOVE_SET_PITCH_RATE
, 8+4+2+4+4+4+4+4+4+4);
8465 sLog
.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype
);
8469 data
.append(GetPackGUID());
8470 data
<< uint32(0); // movement flags
8471 data
<< uint16(0); // unk flags
8472 data
<< uint32(getMSTime());
8473 data
<< float(GetPositionX());
8474 data
<< float(GetPositionY());
8475 data
<< float(GetPositionZ());
8476 data
<< float(GetOrientation());
8477 data
<< uint32(0); // fall time
8478 data
<< float(GetSpeed(mtype
));
8479 SendMessageToSet( &data
, true );
8483 if(GetTypeId() == TYPEID_PLAYER
)
8485 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
8486 // and do it only for real sent packets and use run for run/mounted as client expected
8487 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
8493 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
8496 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
8499 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
8502 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
8504 case MOVE_SWIM_BACK
:
8505 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
8507 case MOVE_TURN_RATE
:
8508 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
8511 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
8513 case MOVE_FLIGHT_BACK
:
8514 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
8516 case MOVE_PITCH_RATE
:
8517 data
.Initialize(SMSG_FORCE_PITCH_RATE_CHANGE
, 16);
8520 sLog
.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype
);
8523 data
.append(GetPackGUID());
8524 data
<< (uint32
)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
8525 if (mtype
== MOVE_RUN
)
8526 data
<< uint8(0); // new 2.1.0
8527 data
<< float(GetSpeed(mtype
));
8528 SendMessageToSet( &data
, true );
8530 if(Pet
* pet
= GetPet())
8531 pet
->SetSpeed(MOVE_RUN
, m_speed_rate
[mtype
],forced
);
8534 void Unit::SetHover(bool on
)
8537 CastSpell(this,11010,true);
8539 RemoveAurasDueToSpell(11010);
8542 void Unit::setDeathState(DeathState s
)
8544 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
8548 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
8550 if(IsNonMeleeSpellCasted(false))
8551 InterruptNonMeleeSpells(false);
8556 RemoveAllAurasOnDeath();
8557 UnsummonAllTotems();
8559 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
8560 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
8561 // remove aurastates allowing special moves
8562 ClearAllReactives();
8563 ClearDiminishings();
8565 else if(s
== JUST_ALIVED
)
8567 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
8570 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
8572 //_ApplyAllAuraMods();
8577 /*########################################
8579 ######## AGGRO SYSTEM ########
8581 ########################################*/
8582 bool Unit::CanHaveThreatList() const
8584 // only creatures can have threat list
8585 if( GetTypeId() != TYPEID_UNIT
)
8588 // only alive units can have threat list
8592 // totems can not have threat list
8593 if( ((Creature
*)this)->isTotem() )
8596 // vehicles can not have threat list
8597 if( ((Creature
*)this)->isVehicle() )
8600 // pets can not have a threat list, unless they are controlled by a creature
8601 if( ((Creature
*)this)->isPet() && IS_PLAYER_GUID(((Pet
*)this)->GetOwnerGUID()) )
8607 //======================================================================
8609 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
8611 if(!HasAuraType(SPELL_AURA_MOD_THREAT
))
8614 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
8616 return threat
* m_threatModifier
[school
];
8619 //======================================================================
8621 void Unit::AddThreat(Unit
* pVictim
, float threat
, SpellSchoolMask schoolMask
, SpellEntry
const *threatSpell
)
8623 // Only mobs can manage threat lists
8624 if(CanHaveThreatList())
8625 m_ThreatManager
.addThreat(pVictim
, threat
, schoolMask
, threatSpell
);
8628 //======================================================================
8630 void Unit::DeleteThreatList()
8632 m_ThreatManager
.clearReferences();
8635 //======================================================================
8637 void Unit::TauntApply(Unit
* taunter
)
8639 assert(GetTypeId()== TYPEID_UNIT
);
8641 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
8644 if(!CanHaveThreatList())
8647 Unit
*target
= getVictim();
8648 if(target
&& target
== taunter
)
8651 SetInFront(taunter
);
8652 if (((Creature
*)this)->AI())
8653 ((Creature
*)this)->AI()->AttackStart(taunter
);
8655 m_ThreatManager
.tauntApply(taunter
);
8658 //======================================================================
8660 void Unit::TauntFadeOut(Unit
*taunter
)
8662 assert(GetTypeId()== TYPEID_UNIT
);
8664 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
8667 if(!CanHaveThreatList())
8670 Unit
*target
= getVictim();
8671 if(!target
|| target
!= taunter
)
8674 if(m_ThreatManager
.isThreatListEmpty())
8676 if(((Creature
*)this)->AI())
8677 ((Creature
*)this)->AI()->EnterEvadeMode();
8681 m_ThreatManager
.tauntFadeOut(taunter
);
8682 target
= m_ThreatManager
.getHostilTarget();
8684 if (target
&& target
!= taunter
)
8687 if (((Creature
*)this)->AI())
8688 ((Creature
*)this)->AI()->AttackStart(target
);
8692 //======================================================================
8694 bool Unit::SelectHostilTarget()
8696 //function provides main threat functionality
8697 //next-victim-selection algorithm and evade mode are called
8698 //threat list sorting etc.
8700 assert(GetTypeId()== TYPEID_UNIT
);
8701 Unit
* target
= NULL
;
8703 //This function only useful once AI has been initialized
8704 if (!((Creature
*)this)->AI())
8707 if(!m_ThreatManager
.isThreatListEmpty())
8709 if(!HasAuraType(SPELL_AURA_MOD_TAUNT
))
8711 target
= m_ThreatManager
.getHostilTarget();
8717 if(!hasUnitState(UNIT_STAT_STUNNED
))
8719 ((Creature
*)this)->AI()->AttackStart(target
);
8723 // no target but something prevent go to evade mode
8724 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
8727 // last case when creature don't must go to evade mode:
8728 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
8729 // for example at owner command to pet attack some far away creature
8730 // Note: creature not have targeted movement generator but have attacker in this case
8731 if( GetMotionMaster()->GetCurrentMovementGeneratorType() != TARGETED_MOTION_TYPE
)
8733 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
8735 if( (*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this) )
8740 // enter in evade mode in other case
8741 ((Creature
*)this)->AI()->EnterEvadeMode();
8746 //======================================================================
8747 //======================================================================
8748 //======================================================================
8750 int32
Unit::CalculateSpellDamage(SpellEntry
const* spellProto
, uint8 effect_index
, int32 effBasePoints
, Unit
const* target
)
8752 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
8754 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
8756 int32 level
= int32(getLevel());
8757 if (level
> (int32
)spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
8758 level
= (int32
)spellProto
->maxLevel
;
8759 else if (level
< (int32
)spellProto
->baseLevel
)
8760 level
= (int32
)spellProto
->baseLevel
;
8761 level
-= (int32
)spellProto
->spellLevel
;
8763 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
8764 float randomPointsPerLevel
= spellProto
->EffectDicePerLevel
[effect_index
];
8765 int32 basePoints
= int32(effBasePoints
+ level
* basePointsPerLevel
);
8766 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
] + level
* randomPointsPerLevel
);
8767 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
8769 // range can have possitive and negative values, so order its for irand
8770 int32 randvalue
= int32(spellProto
->EffectBaseDice
[effect_index
]) >= randomPoints
8771 ? irand(randomPoints
, int32(spellProto
->EffectBaseDice
[effect_index
]))
8772 : irand(int32(spellProto
->EffectBaseDice
[effect_index
]), randomPoints
);
8774 int32 value
= basePoints
+ randvalue
;
8776 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
8777 value
+= (int32
)(comboDamage
* comboPoints
);
8779 if(Player
* modOwner
= GetSpellModOwner())
8781 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_ALL_EFFECTS
, value
);
8782 switch(effect_index
)
8785 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT1
, value
);
8788 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT2
, value
);
8791 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT3
, value
);
8796 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
8797 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
8798 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
)
8799 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
8804 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, uint8 effect_index
, Unit
const* target
)
8806 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
8808 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
8810 int32 minduration
= GetSpellDuration(spellProto
);
8811 int32 maxduration
= GetSpellMaxDuration(spellProto
);
8815 if( minduration
!= -1 && minduration
!= maxduration
)
8816 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
8818 duration
= minduration
;
8822 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
8823 // Find total mod value (negative bonus)
8824 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
8825 // Modify from SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL aura (stack always ?)
8826 durationMod_always
+=target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
, spellProto
->Dispel
);
8827 // Find max mod (negative bonus)
8828 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
8830 int32 durationMod
= 0;
8831 // Select strongest negative mod
8832 if (durationMod_always
> durationMod_not_stack
)
8833 durationMod
= durationMod_not_stack
;
8835 durationMod
= durationMod_always
;
8837 if (durationMod
!= 0)
8838 duration
= int32(int64(duration
) * (100+durationMod
) /100);
8840 if (duration
< 0) duration
= 0;
8846 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
8848 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
8850 if(i
->DRGroup
!= group
)
8854 return DIMINISHING_LEVEL_1
;
8857 return DIMINISHING_LEVEL_1
;
8859 // If last spell was casted more than 15 seconds ago - reset the count.
8860 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
8862 i
->hitCount
= DIMINISHING_LEVEL_1
;
8863 return DIMINISHING_LEVEL_1
;
8865 // or else increase the count.
8868 return DiminishingLevels(i
->hitCount
);
8871 return DIMINISHING_LEVEL_1
;
8874 void Unit::IncrDiminishing(DiminishingGroup group
)
8876 // Checking for existing in the table
8877 bool IsExist
= false;
8878 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
8880 if(i
->DRGroup
!= group
)
8884 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
8891 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
8894 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
)
8896 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
8899 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
8900 if(duration
> 10000 && IsDiminishingReturnsGroupDurationLimited(group
))
8902 // test pet/charm masters instead pets/charmeds
8903 Unit
const* targetOwner
= GetCharmerOrOwner();
8904 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
8906 Unit
const* target
= targetOwner
? targetOwner
: this;
8907 Unit
const* source
= casterOwner
? casterOwner
: caster
;
8909 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
8915 // Some diminishings applies to mobs too (for example, Stun)
8916 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
8918 DiminishingLevels diminish
= Level
;
8921 case DIMINISHING_LEVEL_1
: break;
8922 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
8923 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
8924 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
8929 duration
= int32(duration
* mod
);
8932 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
8934 // Checking for existing in the table
8935 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
8937 if(i
->DRGroup
!= group
)
8940 i
->hitTime
= getMSTime();
8951 Unit
* Unit::GetUnit(WorldObject
& object
, uint64 guid
)
8953 return ObjectAccessor::GetUnit(object
,guid
);
8956 bool Unit::isVisibleForInState( Player
const* u
, bool inVisibleList
) const
8958 return isVisibleForOrDetect(u
, false, inVisibleList
, false);
8961 uint32
Unit::GetCreatureType() const
8963 if(GetTypeId() == TYPEID_PLAYER
)
8965 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(((Player
*)this)->m_form
);
8966 if(ssEntry
&& ssEntry
->creatureType
> 0)
8967 return ssEntry
->creatureType
;
8969 return CREATURE_TYPE_HUMANOID
;
8972 return ((Creature
*)this)->GetCreatureInfo()->type
;
8975 /*#######################################
8977 ######## STAT SYSTEM ########
8979 #######################################*/
8981 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
8983 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
8985 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
8991 switch(modifierType
)
8995 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
8999 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
9002 val
= (100.0f
+ amount
) / 100.0f
;
9003 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
9010 if(!CanModifyStats())
9015 case UNIT_MOD_STAT_STRENGTH
:
9016 case UNIT_MOD_STAT_AGILITY
:
9017 case UNIT_MOD_STAT_STAMINA
:
9018 case UNIT_MOD_STAT_INTELLECT
:
9019 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
9021 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
9022 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
9026 case UNIT_MOD_FOCUS
:
9027 case UNIT_MOD_ENERGY
:
9028 case UNIT_MOD_HAPPINESS
:
9030 case UNIT_MOD_RUNIC_POWER
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
9032 case UNIT_MOD_RESISTANCE_HOLY
:
9033 case UNIT_MOD_RESISTANCE_FIRE
:
9034 case UNIT_MOD_RESISTANCE_NATURE
:
9035 case UNIT_MOD_RESISTANCE_FROST
:
9036 case UNIT_MOD_RESISTANCE_SHADOW
:
9037 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
9039 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
9040 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
9042 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
9043 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
9044 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
9053 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
9055 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
9057 sLog
.outError("ERROR: trial to access non existed modifier value from UnitMods!");
9061 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
9064 return m_auraModifiersGroup
[unitMod
][modifierType
];
9067 float Unit::GetTotalStatValue(Stats stat
) const
9069 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
9071 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
9074 // value = ((base_value * base_pct) + total_value) * total_pct
9075 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
9076 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
9077 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
9078 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
9083 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
9085 if(unitMod
>= UNIT_MOD_END
)
9087 sLog
.outError("ERROR: trial to access non existed UnitMods in GetTotalAuraModValue()!");
9091 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
9094 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
9095 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
9096 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
9097 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
9102 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
9104 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
9108 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
9109 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
9110 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
9111 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
9112 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
9113 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
9122 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
9124 Stats stat
= STAT_STRENGTH
;
9128 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
9129 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
9130 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
9131 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
9132 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
9141 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
9145 case UNIT_MOD_MANA
: return POWER_MANA
;
9146 case UNIT_MOD_RAGE
: return POWER_RAGE
;
9147 case UNIT_MOD_FOCUS
: return POWER_FOCUS
;
9148 case UNIT_MOD_ENERGY
: return POWER_ENERGY
;
9149 case UNIT_MOD_HAPPINESS
: return POWER_HAPPINESS
;
9150 case UNIT_MOD_RUNE
: return POWER_RUNE
;
9151 case UNIT_MOD_RUNIC_POWER
:return POWER_RUNIC_POWER
;
9157 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
9159 UnitMods unitMod
= (attType
== RANGED_ATTACK
) ? UNIT_MOD_ATTACK_POWER_RANGED
: UNIT_MOD_ATTACK_POWER
;
9161 float val
= GetTotalAuraModValue(unitMod
);
9168 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
9170 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
9173 return m_weaponDamage
[attType
][type
];
9176 void Unit::SetLevel(uint32 lvl
)
9178 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
9181 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
9182 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
9185 void Unit::SetHealth(uint32 val
)
9187 uint32 maxHealth
= GetMaxHealth();
9191 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
9194 if(GetTypeId() == TYPEID_PLAYER
)
9196 if(((Player
*)this)->GetGroup())
9197 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
9199 else if(((Creature
*)this)->isPet())
9201 Pet
*pet
= ((Pet
*)this);
9202 if(pet
->isControlled())
9204 Unit
*owner
= GetOwner();
9205 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9206 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
9211 void Unit::SetMaxHealth(uint32 val
)
9213 uint32 health
= GetHealth();
9214 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
9217 if(GetTypeId() == TYPEID_PLAYER
)
9219 if(((Player
*)this)->GetGroup())
9220 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
9222 else if(((Creature
*)this)->isPet())
9224 Pet
*pet
= ((Pet
*)this);
9225 if(pet
->isControlled())
9227 Unit
*owner
= GetOwner();
9228 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9229 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP
);
9237 void Unit::SetPower(Powers power
, uint32 val
)
9239 if(GetPower(power
) == val
)
9242 uint32 maxPower
= GetMaxPower(power
);
9246 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
9248 WorldPacket
data(SMSG_POWER_UPDATE
);
9249 data
.append(GetPackGUID());
9250 data
<< uint8(power
);
9251 data
<< uint32(val
);
9252 SendMessageToSet(&data
, GetTypeId() == TYPEID_PLAYER
? true : false);
9255 if(GetTypeId() == TYPEID_PLAYER
)
9257 if(((Player
*)this)->GetGroup())
9258 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
9260 else if(((Creature
*)this)->isPet())
9262 Pet
*pet
= ((Pet
*)this);
9263 if(pet
->isControlled())
9265 Unit
*owner
= GetOwner();
9266 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9267 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
9270 // Update the pet's character sheet with happiness damage bonus
9271 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
9273 pet
->UpdateDamagePhysical(BASE_ATTACK
);
9278 void Unit::SetMaxPower(Powers power
, uint32 val
)
9280 uint32 cur_power
= GetPower(power
);
9281 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
9284 if(GetTypeId() == TYPEID_PLAYER
)
9286 if(((Player
*)this)->GetGroup())
9287 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
9289 else if(((Creature
*)this)->isPet())
9291 Pet
*pet
= ((Pet
*)this);
9292 if(pet
->isControlled())
9294 Unit
*owner
= GetOwner();
9295 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9296 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
9301 SetPower(power
, val
);
9304 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
9306 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
9309 if(GetTypeId() == TYPEID_PLAYER
)
9311 if(((Player
*)this)->GetGroup())
9312 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
9314 else if(((Creature
*)this)->isPet())
9316 Pet
*pet
= ((Pet
*)this);
9317 if(pet
->isControlled())
9319 Unit
*owner
= GetOwner();
9320 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9321 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
9326 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
9328 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
9331 if(GetTypeId() == TYPEID_PLAYER
)
9333 if(((Player
*)this)->GetGroup())
9334 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
9336 else if(((Creature
*)this)->isPet())
9338 Pet
*pet
= ((Pet
*)this);
9339 if(pet
->isControlled())
9341 Unit
*owner
= GetOwner();
9342 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9343 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
9348 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
9350 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
9352 tAuraProcTriggerDamage
.push_back(aura
);
9354 tAuraProcTriggerDamage
.remove(aura
);
9357 uint32
Unit::GetCreatePowers( Powers power
) const
9359 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
9362 case POWER_MANA
: return GetCreateMana();
9363 case POWER_RAGE
: return 1000;
9364 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
9365 case POWER_ENERGY
: return 100;
9366 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
9367 case POWER_RUNIC_POWER
: return 1000;
9373 void Unit::AddToWorld()
9375 Object::AddToWorld();
9378 void Unit::RemoveFromWorld()
9383 RemoveNotOwnSingleTargetAuras();
9386 Object::RemoveFromWorld();
9389 void Unit::CleanupsBeforeDelete()
9391 if(m_uint32Values
) // only for fully created object
9393 InterruptNonMeleeSpells(true);
9394 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
9396 ClearComboPointHolders();
9398 getHostilRefManager().setOnlineOfflineState(false);
9400 RemoveAllGameObjects();
9401 RemoveAllDynObjects();
9402 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
9407 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
9410 m_charmInfo
= new CharmInfo(charm
);
9414 CharmInfo::CharmInfo(Unit
* unit
)
9415 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
9417 for(int i
=0; i
<4; ++i
)
9419 m_charmspells
[i
].spellId
= 0;
9420 m_charmspells
[i
].active
= ACT_DISABLED
;
9424 void CharmInfo::InitPetActionBar()
9426 // the first 3 SpellOrActions are attack, follow and stay
9427 for(uint32 i
= 0; i
< 3; i
++)
9429 PetActionBar
[i
].Type
= ACT_COMMAND
;
9430 PetActionBar
[i
].SpellOrAction
= COMMAND_ATTACK
- i
;
9432 PetActionBar
[i
+ 7].Type
= ACT_REACTION
;
9433 PetActionBar
[i
+ 7].SpellOrAction
= COMMAND_ATTACK
- i
;
9435 for(uint32 i
=0; i
< 4; i
++)
9437 PetActionBar
[i
+ 3].Type
= ACT_DISABLED
;
9438 PetActionBar
[i
+ 3].SpellOrAction
= 0;
9442 void CharmInfo::InitEmptyActionBar()
9444 for(uint32 x
= 1; x
< 10; ++x
)
9446 PetActionBar
[x
].Type
= ACT_PASSIVE
;
9447 PetActionBar
[x
].SpellOrAction
= 0;
9449 PetActionBar
[0].Type
= ACT_COMMAND
;
9450 PetActionBar
[0].SpellOrAction
= COMMAND_ATTACK
;
9453 void CharmInfo::InitPossessCreateSpells()
9455 if(m_unit
->GetTypeId() == TYPEID_PLAYER
)
9458 InitEmptyActionBar(); //charm action bar
9460 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
9462 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
9463 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
9465 AddSpellToAB(0, ((Creature
*)m_unit
)->m_spells
[x
], ACT_PASSIVE
);
9469 void CharmInfo::InitCharmCreateSpells()
9471 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
9473 InitEmptyActionBar();
9479 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
9481 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
9482 m_charmspells
[x
].spellId
= spellId
;
9487 if (IsPassiveSpell(spellId
))
9489 m_unit
->CastSpell(m_unit
, spellId
, true);
9490 m_charmspells
[x
].active
= ACT_PASSIVE
;
9494 ActiveStates newstate
;
9495 bool onlyselfcast
= true;
9496 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
9498 if(!spellInfo
) onlyselfcast
= false;
9499 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
9501 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
9502 onlyselfcast
= false;
9505 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
9506 newstate
= ACT_DISABLED
;
9508 newstate
= ACT_PASSIVE
;
9510 AddSpellToAB(0, spellId
, newstate
);
9515 bool CharmInfo::AddSpellToAB(uint32 oldid
, uint32 newid
, ActiveStates newstate
)
9517 for(uint8 i
= 0; i
< 10; i
++)
9519 if((PetActionBar
[i
].Type
== ACT_DISABLED
|| PetActionBar
[i
].Type
== ACT_ENABLED
|| PetActionBar
[i
].Type
== ACT_PASSIVE
) && PetActionBar
[i
].SpellOrAction
== oldid
)
9521 PetActionBar
[i
].SpellOrAction
= newid
;
9524 if(newstate
== ACT_DECIDE
)
9525 PetActionBar
[i
].Type
= ACT_DISABLED
;
9527 PetActionBar
[i
].Type
= newstate
;
9536 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
9538 if(IsPassiveSpell(spellid
))
9541 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
9543 if(spellid
== m_charmspells
[x
].spellId
)
9545 m_charmspells
[x
].active
= apply
? ACT_ENABLED
: ACT_DISABLED
;
9550 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
9552 m_petnumber
= petnumber
;
9554 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
9556 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
9559 bool Unit::isFrozen() const
9561 AuraList
const& mRoot
= GetAurasByType(SPELL_AURA_MOD_ROOT
);
9562 for(AuraList::const_iterator i
= mRoot
.begin(); i
!= mRoot
.end(); ++i
)
9563 if( GetSpellSchoolMask((*i
)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST
)
9568 struct ProcTriggeredData
9570 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
9571 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
9572 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
9574 SpellProcEventEntry
const *spellProcEvent
;
9575 Aura
* triggeredByAura
;
9576 Unit::spellEffectPair triggeredByAura_SpellPair
;
9579 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
9580 typedef std::list
< uint32
> RemoveSpellList
;
9582 // List of auras that CAN be trigger but may not exist in spell_proc_event
9583 // in most case need for drop charges
9584 // in some types of aura need do additional check
9585 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
9586 bool InitTriggerAuraData()
9588 for (int i
=0;i
<TOTAL_AURAS
;i
++)
9590 isTriggerAura
[i
]=false;
9591 isNonTriggerAura
[i
] = false;
9593 isTriggerAura
[SPELL_AURA_PERIODIC_DAMAGE
] = true;
9594 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
9595 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
9596 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
9597 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
9598 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
9599 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
9600 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
9601 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
9602 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
9603 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
9604 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
9605 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
9606 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED
] = true;
9607 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
9608 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
9609 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
9610 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
9611 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
9612 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
9613 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
9614 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
9615 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
9616 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
9617 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
9618 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
9619 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
9620 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
9621 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
] = true;
9623 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
9624 isNonTriggerAura
[SPELL_AURA_RESIST_PUSHBACK
]=true;
9629 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
9631 uint32 procEx
= PROC_EX_NONE
;
9632 // Check victim state
9633 if (missCondition
!=SPELL_MISS_NONE
)
9634 switch (missCondition
)
9636 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
9637 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
9638 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
9639 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
9640 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
9641 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
9642 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
9643 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
9644 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
9645 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
9646 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
9653 if (damageInfo
->blocked
)
9654 procEx
|=PROC_EX_BLOCK
;
9656 if (damageInfo
->absorb
)
9657 procEx
|=PROC_EX_ABSORB
;
9659 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
9660 procEx
|=PROC_EX_CRITICAL_HIT
;
9662 procEx
|=PROC_EX_NORMAL_HIT
;
9667 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
9669 // For melee/ranged based attack need update skills and set some Aura states
9670 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
9672 // Update skills here for players
9673 if (GetTypeId() == TYPEID_PLAYER
)
9675 // On melee based hit/miss/resist need update skill (for victim and attacker)
9676 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
9678 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
9679 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, MELEE_HIT_MISS
, isVictim
);
9681 // Update defence if player is victim and parry/dodge/block
9682 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
9683 ((Player
*)this)->UpdateDefense();
9685 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
9686 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
9691 // if victim and dodge attack
9692 if (procExtra
&PROC_EX_DODGE
)
9694 //Update AURA_STATE on dodge
9695 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
9697 ModifyAuraState(AURA_STATE_DEFENSE
, true);
9698 StartReactiveTimer( REACTIVE_DEFENSE
);
9701 // if victim and parry attack
9702 if (procExtra
& PROC_EX_PARRY
)
9704 // For Hunters only Counterattack (skip Mongoose bite)
9705 if (getClass() == CLASS_HUNTER
)
9707 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
9708 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
9712 ModifyAuraState(AURA_STATE_DEFENSE
, true);
9713 StartReactiveTimer( REACTIVE_DEFENSE
);
9716 // if and victim block attack
9717 if (procExtra
& PROC_EX_BLOCK
)
9719 ModifyAuraState(AURA_STATE_DEFENSE
,true);
9720 StartReactiveTimer( REACTIVE_DEFENSE
);
9725 // Overpower on victim dodge
9726 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
9728 ((Player
*)this)->AddComboPoints(pTarget
, 1);
9729 StartReactiveTimer( REACTIVE_OVERPOWER
);
9735 RemoveSpellList removedSpells
;
9736 ProcTriggeredList procTriggered
;
9737 // Fill procTriggered list
9738 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
9740 SpellProcEventEntry
const* spellProcEvent
= NULL
;
9741 if(!IsTriggeredAtSpellProcEvent(pTarget
, itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
9744 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
9746 // Handle effects proceed this time
9747 for(ProcTriggeredList::iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
9749 // Some auras can be deleted in function called in this loop (except first, ofc)
9750 // Until storing auars in std::multimap to hard check deleting by another way
9751 if(i
!= procTriggered
.begin())
9754 AuraMap::const_iterator lower
= GetAuras().lower_bound(i
->triggeredByAura_SpellPair
);
9755 AuraMap::const_iterator upper
= GetAuras().upper_bound(i
->triggeredByAura_SpellPair
);
9756 for(AuraMap::const_iterator itr
= lower
; itr
!= upper
; ++itr
)
9758 if(itr
->second
==i
->triggeredByAura
)
9766 // 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);
9767 // sLog.outDebug("It can be deleted one from early proccesed auras:");
9768 // for(ProcTriggeredList::iterator i2 = procTriggered.begin(); i != i2; ++i2)
9769 // sLog.outDebug(" Spell aura %u (id:%u effect:%u)", i->triggeredByAura->GetModifier()->m_auraname,i2->triggeredByAura_SpellPair.first,i2->triggeredByAura_SpellPair.second);
9770 // sLog.outDebug(" <end of list>");
9775 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
9776 Aura
*triggeredByAura
= i
->triggeredByAura
;
9777 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
9778 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
9779 uint32 effIndex
= triggeredByAura
->GetEffIndex();
9780 bool useCharges
= triggeredByAura
->m_procCharges
> 0;
9781 // For players set spell cooldown if need
9782 uint32 cooldown
= 0;
9783 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
9784 cooldown
= spellProcEvent
->cooldown
;
9786 switch(auraModifier
->m_auraname
)
9788 case SPELL_AURA_PROC_TRIGGER_SPELL
:
9790 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
9791 // Don`t drop charge or add cooldown for not started trigger
9792 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
9796 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
9798 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());
9799 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, spellInfo
->SchoolMask
);
9800 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
9801 SendSpellNonMeleeDamageLog(&damageInfo
);
9802 DealSpellDamage(&damageInfo
, true);
9805 case SPELL_AURA_MANA_SHIELD
:
9806 case SPELL_AURA_DUMMY
:
9808 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());
9809 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
9813 case SPELL_AURA_MOD_HASTE
:
9815 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());
9816 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
9820 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
9822 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());
9823 if (!HandleOverrideClassScriptAuraProc(pTarget
, triggeredByAura
, procSpell
, cooldown
))
9827 case SPELL_AURA_PRAYER_OF_MENDING
:
9829 sLog
.outDebug("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
9830 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
9832 HandleMeandingAuraProc(triggeredByAura
);
9835 case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
:
9837 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());
9839 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
9843 case SPELL_AURA_MOD_STUN
:
9844 // Remove by default, but if charge exist drop it
9845 if (triggeredByAura
->m_procCharges
== 0)
9846 removedSpells
.push_back(triggeredByAura
->GetId());
9848 case SPELL_AURA_MOD_CASTING_SPEED
:
9849 // Skip melee hits or instant cast spells
9850 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
9853 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
9854 // Skip Melee hits and spells ws wrong school
9855 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
9858 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
9859 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
9860 // Skip melee hits and spells ws wrong school or zero cost
9861 if (procSpell
== NULL
||
9862 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
9863 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
9866 case SPELL_AURA_MECHANIC_IMMUNITY
:
9868 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
9871 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
9873 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
9877 // nothing do, just charges counter
9880 // Remove charge (aura can be removed by triggers)
9883 // need found aura on drop (can be dropped by triggers)
9884 AuraMap::const_iterator lower
= GetAuras().lower_bound(i
->triggeredByAura_SpellPair
);
9885 AuraMap::const_iterator upper
= GetAuras().upper_bound(i
->triggeredByAura_SpellPair
);
9886 for(AuraMap::const_iterator itr
= lower
; itr
!= upper
; ++itr
)
9888 if(itr
->second
== i
->triggeredByAura
)
9890 triggeredByAura
->m_procCharges
-=1;
9891 triggeredByAura
->UpdateAuraCharges();
9892 if (triggeredByAura
->m_procCharges
<= 0)
9893 removedSpells
.push_back(triggeredByAura
->GetId());
9899 if (removedSpells
.size())
9901 // Sort spells and remove dublicates
9902 removedSpells
.sort();
9903 removedSpells
.unique();
9904 // Remove auras from removedAuras
9905 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();i
++)
9906 RemoveAurasDueToSpell(*i
);
9910 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
9912 return SPELL_SCHOOL_MASK_NORMAL
;
9915 Player
* Unit::GetSpellModOwner()
9917 if(GetTypeId()==TYPEID_PLAYER
)
9918 return (Player
*)this;
9919 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
9921 Unit
* owner
= GetOwner();
9922 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
9923 return (Player
*)owner
;
9928 ///----------Pet responses methods-----------------
9929 void Unit::SendPetCastFail(uint32 spellid
, uint8 msg
)
9931 Unit
*owner
= GetCharmerOrOwner();
9932 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
9935 WorldPacket
data(SMSG_PET_CAST_FAILED
, (4+1));
9936 data
<< uint8(0); // cast count?
9937 data
<< uint32(spellid
);
9939 // uint32 for some reason
9940 // uint32 for some reason
9941 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
9944 void Unit::SendPetActionFeedback (uint8 msg
)
9946 Unit
* owner
= GetOwner();
9947 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
9950 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
9952 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
9955 void Unit::SendPetTalk (uint32 pettalk
)
9957 Unit
* owner
= GetOwner();
9958 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
9961 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8+4);
9962 data
<< uint64(GetGUID());
9963 data
<< uint32(pettalk
);
9964 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
9967 void Unit::SendPetSpellCooldown (uint32 spellid
, time_t cooltime
)
9969 Unit
* owner
= GetOwner();
9970 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
9973 WorldPacket
data(SMSG_SPELL_COOLDOWN
, 8+1+4+4);
9974 data
<< uint64(GetGUID());
9975 data
<< uint8(0x0); // flags (0x1, 0x2)
9976 data
<< uint32(spellid
);
9977 data
<< uint32(cooltime
);
9979 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
9982 void Unit::SendPetClearCooldown (uint32 spellid
)
9984 Unit
* owner
= GetOwner();
9985 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
9988 WorldPacket
data(SMSG_CLEAR_COOLDOWN
, (4+8));
9989 data
<< uint32(spellid
);
9990 data
<< uint64(GetGUID());
9991 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
9994 void Unit::SendPetAIReaction(uint64 guid
)
9996 Unit
* owner
= GetOwner();
9997 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10000 WorldPacket
data(SMSG_AI_REACTION
, 12);
10001 data
<< uint64(guid
) << uint32(00000002);
10002 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10005 ///----------End of Pet responses methods----------
10007 void Unit::StopMoving()
10009 clearUnitState(UNIT_STAT_MOVING
);
10011 // send explicit stop packet
10012 // rely on vmaps here because for example stormwind is in air
10013 //float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true);
10014 //if (fabs(GetPositionZ() - z) < 2.0f)
10015 // Relocate(GetPositionX(), GetPositionY(), z);
10016 Relocate(GetPositionX(), GetPositionY(),GetPositionZ());
10018 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, 0);
10020 // update position and orientation;
10022 BuildHeartBeatMsg(&data
);
10023 SendMessageToSet(&data
,false);
10026 void Unit::SetFeared(bool apply
, uint64 casterGUID
, uint32 spellID
)
10030 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
10033 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
10035 GetMotionMaster()->MovementExpired(false);
10036 CastStop(GetGUID()==casterGUID
? spellID
: 0);
10038 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
10040 GetMotionMaster()->MoveFleeing(caster
); // caster==NULL processed in MoveFleeing
10044 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
10046 GetMotionMaster()->MovementExpired(false);
10048 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
10050 // restore appropriate movement generator
10052 GetMotionMaster()->MoveChase(getVictim());
10054 GetMotionMaster()->Initialize();
10056 // attack caster if can
10057 Unit
* caster
= ObjectAccessor::GetObjectInWorld(casterGUID
, (Unit
*)NULL
);
10058 if(caster
&& caster
!= getVictim() && ((Creature
*)this)->AI())
10059 ((Creature
*)this)->AI()->AttackStart(caster
);
10063 if (GetTypeId() == TYPEID_PLAYER
)
10064 ((Player
*)this)->SetClientControl(this, !apply
);
10067 void Unit::SetConfused(bool apply
, uint64 casterGUID
, uint32 spellID
)
10071 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
10073 CastStop(GetGUID()==casterGUID
? spellID
: 0);
10075 GetMotionMaster()->MoveConfused();
10079 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
10081 GetMotionMaster()->MovementExpired(false);
10083 if (GetTypeId() == TYPEID_UNIT
)
10085 // if in combat restore movement generator
10087 GetMotionMaster()->MoveChase(getVictim());
10091 if(GetTypeId() == TYPEID_PLAYER
)
10092 ((Player
*)this)->SetClientControl(this, !apply
);
10095 bool Unit::IsSitState() const
10097 uint8 s
= getStandState();
10098 return s
== PLAYER_STATE_SIT_CHAIR
|| s
== PLAYER_STATE_SIT_LOW_CHAIR
||
10099 s
== PLAYER_STATE_SIT_MEDIUM_CHAIR
|| s
== PLAYER_STATE_SIT_HIGH_CHAIR
||
10100 s
== PLAYER_STATE_SIT
;
10103 bool Unit::IsStandState() const
10105 uint8 s
= getStandState();
10106 return !IsSitState() && s
!= PLAYER_STATE_SLEEP
&& s
!= PLAYER_STATE_KNEEL
;
10109 void Unit::SetStandState(uint8 state
)
10111 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
10113 if (IsStandState())
10114 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
10116 if(GetTypeId()==TYPEID_PLAYER
)
10118 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
10119 data
<< (uint8
)state
;
10120 ((Player
*)this)->GetSession()->SendPacket(&data
);
10124 bool Unit::IsPolymorphed() const
10126 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
10129 void Unit::SetDisplayId(uint32 modelId
)
10131 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
10133 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
10135 Pet
*pet
= ((Pet
*)this);
10136 if(!pet
->isControlled())
10138 Unit
*owner
= GetOwner();
10139 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10140 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
10144 void Unit::ClearComboPointHolders()
10146 while(!m_ComboPointHolders
.empty())
10148 uint32 lowguid
= *m_ComboPointHolders
.begin();
10150 Player
* plr
= objmgr
.GetPlayer(MAKE_NEW_GUID(lowguid
, 0, HIGHGUID_PLAYER
));
10151 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
10152 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
10154 m_ComboPointHolders
.erase(lowguid
); // or remove manually
10158 void Unit::ClearAllReactives()
10160 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
10161 m_reactiveTimer
[i
] = 0;
10163 if (HasAuraState( AURA_STATE_DEFENSE
))
10164 ModifyAuraState(AURA_STATE_DEFENSE
, false);
10165 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
10166 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
10167 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
10168 ((Player
*)this)->ClearComboPoints();
10171 void Unit::UpdateReactives( uint32 p_time
)
10173 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
10175 ReactiveType reactive
= ReactiveType(i
);
10177 if(!m_reactiveTimer
[reactive
])
10180 if ( m_reactiveTimer
[reactive
] <= p_time
)
10182 m_reactiveTimer
[reactive
] = 0;
10184 switch ( reactive
)
10186 case REACTIVE_DEFENSE
:
10187 if (HasAuraState(AURA_STATE_DEFENSE
))
10188 ModifyAuraState(AURA_STATE_DEFENSE
, false);
10190 case REACTIVE_HUNTER_PARRY
:
10191 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
10192 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
10194 case REACTIVE_OVERPOWER
:
10195 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
10196 ((Player
*)this)->ClearComboPoints();
10204 m_reactiveTimer
[reactive
] -= p_time
;
10209 Unit
* Unit::SelectNearbyTarget() const
10211 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
10213 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
10214 cell
.SetNoCreate();
10216 std::list
<Unit
*> targets
;
10219 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, ATTACK_DISTANCE
);
10220 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(targets
, u_check
);
10222 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
10223 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
10225 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
10226 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *GetMap());
10227 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *GetMap());
10230 // remove current target
10232 targets
.remove(getVictim());
10234 // remove not LoS targets
10235 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
10237 if(!IsWithinLOSInMap(*tIter
))
10239 std::list
<Unit
*>::iterator tIter2
= tIter
;
10241 targets
.erase(tIter2
);
10247 // no appropriate targets
10248 if(targets
.empty())
10252 uint32 rIdx
= urand(0,targets
.size()-1);
10253 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
10254 for(uint32 i
= 0; i
< rIdx
; ++i
)
10260 bool Unit::hasNegativeAuraWithInterruptFlag(uint32 flag
)
10262 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); ++iter
)
10264 if (!iter
->second
->IsPositive() && iter
->second
->GetSpellProto()->AuraInterruptFlags
& flag
)
10270 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
10274 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
10275 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
10279 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
10280 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
10284 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
10287 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
10289 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
10292 uint32
Unit::GetCastingTimeForBonus( SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 CastingTime
)
10294 // Not apply this to creature casted spells with casttime==0
10295 if(CastingTime
==0 && GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
10298 if (CastingTime
> 7000) CastingTime
= 7000;
10299 if (CastingTime
< 1500) CastingTime
= 1500;
10301 if(damagetype
== DOT
&& !IsChanneledSpell(spellProto
))
10302 CastingTime
= 3500;
10304 int32 overTime
= 0;
10306 bool DirectDamage
= false;
10307 bool AreaEffect
= false;
10309 for ( uint32 i
=0; i
<3;i
++)
10311 switch ( spellProto
->Effect
[i
] )
10313 case SPELL_EFFECT_SCHOOL_DAMAGE
:
10314 case SPELL_EFFECT_POWER_DRAIN
:
10315 case SPELL_EFFECT_HEALTH_LEECH
:
10316 case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
:
10317 case SPELL_EFFECT_POWER_BURN
:
10318 case SPELL_EFFECT_HEAL
:
10319 DirectDamage
= true;
10321 case SPELL_EFFECT_APPLY_AURA
:
10322 switch ( spellProto
->EffectApplyAuraName
[i
] )
10324 case SPELL_AURA_PERIODIC_DAMAGE
:
10325 case SPELL_AURA_PERIODIC_HEAL
:
10326 case SPELL_AURA_PERIODIC_LEECH
:
10327 if ( GetSpellDuration(spellProto
) )
10328 overTime
= GetSpellDuration(spellProto
);
10331 // -5% per additional effect
10339 if(IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetA
[i
])) || IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetB
[i
])))
10343 // Combined Spells with Both Over Time and Direct Damage
10344 if ( overTime
> 0 && CastingTime
> 0 && DirectDamage
)
10346 // mainly for DoTs which are 3500 here otherwise
10347 uint32 OriginalCastTime
= GetSpellCastTime(spellProto
);
10348 if (OriginalCastTime
> 7000) OriginalCastTime
= 7000;
10349 if (OriginalCastTime
< 1500) OriginalCastTime
= 1500;
10350 // Portion to Over Time
10351 float PtOT
= (overTime
/ 15000.f
) / ((overTime
/ 15000.f
) + (OriginalCastTime
/ 3500.f
));
10353 if ( damagetype
== DOT
)
10354 CastingTime
= uint32(CastingTime
* PtOT
);
10355 else if ( PtOT
< 1.0f
)
10356 CastingTime
= uint32(CastingTime
* (1 - PtOT
));
10361 // Area Effect Spells receive only half of bonus
10365 // -5% of total per any additional effect
10366 for ( uint8 i
=0; i
<effects
; ++i
)
10368 if ( CastingTime
> 175 )
10370 CastingTime
-= 175;
10379 return CastingTime
;
10382 void Unit::UpdateAuraForGroup(uint8 slot
)
10384 if(GetTypeId() == TYPEID_PLAYER
)
10386 Player
* player
= (Player
*)this;
10387 if(player
->GetGroup())
10389 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
10390 player
->SetAuraUpdateMask(slot
);
10393 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
10395 Pet
*pet
= ((Pet
*)this);
10396 if(pet
->isControlled())
10398 Unit
*owner
= GetOwner();
10399 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10401 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
10402 pet
->SetAuraUpdateMask(slot
);
10408 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
10410 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
10411 return float(GetAttackTime(attType
))/1000.0f
;
10413 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
);
10415 return 2.4; // fist attack
10417 switch (Weapon
->GetProto()->InventoryType
)
10419 case INVTYPE_2HWEAPON
:
10421 case INVTYPE_RANGED
:
10422 case INVTYPE_RANGEDRIGHT
:
10423 case INVTYPE_THROWN
:
10425 case INVTYPE_WEAPON
:
10426 case INVTYPE_WEAPONMAINHAND
:
10427 case INVTYPE_WEAPONOFFHAND
:
10429 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7 : 2.4;
10433 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
10435 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
10436 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
10437 if ((*itr
)->GetId() == spell_id
)
10443 bool Unit::IsUnderLastManaUseEffect() const
10445 return getMSTimeDiff(m_lastManaUse
,getMSTime()) < 5000;
10448 void Unit::SetContestedPvP(Player
*attackedPlayer
)
10450 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
10452 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
10455 player
->SetContestedPvPTimer(30000);
10456 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
10458 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
10459 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
10460 // call MoveInLineOfSight for nearby contested guards
10461 SetVisibility(GetVisibility());
10463 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
10465 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
10466 // call MoveInLineOfSight for nearby contested guards
10467 SetVisibility(GetVisibility());
10471 void Unit::AddPetAura(PetAura
const* petSpell
)
10473 m_petAuras
.insert(petSpell
);
10474 if(Pet
* pet
= GetPet())
10475 pet
->CastPetAura(petSpell
);
10478 void Unit::RemovePetAura(PetAura
const* petSpell
)
10480 m_petAuras
.erase(petSpell
);
10481 if(Pet
* pet
= GetPet())
10482 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
10485 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
10487 Pet
* pet
= new Pet(HUNTER_PET
);
10489 if(!pet
->CreateBaseAtCreature(creatureTarget
))
10495 pet
->SetOwnerGUID(GetGUID());
10496 pet
->SetCreatorGUID(GetGUID());
10497 pet
->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE
, getFaction());
10498 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
10500 if(GetTypeId()==TYPEID_PLAYER
)
10501 pet
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
10503 uint32 level
= (creatureTarget
->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget
->getLevel();
10504 pet
->SetFreeTalentPoints(pet
->GetMaxTalentPointsForLevel(level
));
10506 if(!pet
->InitStatsForLevel(level
))
10508 sLog
.outError("ERROR: Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
10513 pet
->GetCharmInfo()->SetPetNumber(objmgr
.GeneratePetNumber(), true);
10514 // this enables pet details window (Shift+P)
10515 pet
->AIM_Initialize();
10516 pet
->InitPetCreateSpells();
10517 pet
->SetHealth(pet
->GetMaxHealth());
10522 bool Unit::IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
10524 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
10526 // Get proc Event Entry
10527 spellProcEvent
= spellmgr
.GetSpellProcEvent(spellProto
->Id
);
10529 // Aura info stored here
10530 Modifier
*mod
= aura
->GetModifier();
10532 if (isNonTriggerAura
[mod
->m_auraname
])
10534 // If not trigger by default and spellProcEvent==NULL - skip
10535 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
10538 // Get EventProcFlag
10539 uint32 EventProcFlag
;
10540 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
10541 EventProcFlag
= spellProcEvent
->procFlags
;
10543 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
10544 // Continue if no trigger exist
10545 if (!EventProcFlag
)
10548 // Check spellProcEvent data requirements
10549 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
10552 // In most cases req get honor or XP from kill
10553 if (EventProcFlag
& PROC_FLAG_KILL
&& GetTypeId() == TYPEID_PLAYER
)
10555 bool allow
= ((Player
*)this)->isHonorOrXPTarget(pVictim
);
10556 // Shadow Word: Death - can trigger from every kill
10557 if (aura
->GetId() == 32409)
10562 // Aura added by spell can`t trogger from self (prevent drop charges/do triggers)
10563 // But except periodic triggers (can triggered from self)
10564 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
&PROC_FLAG_ON_TAKE_PERIODIC
))
10567 // Check if current equipment allows aura to proc
10568 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
10570 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
10573 if(attType
== BASE_ATTACK
)
10574 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
10575 else if (attType
== OFF_ATTACK
)
10576 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
10578 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
10580 if (!((Player
*)this)->IsUseEquipedWeapon(attType
==BASE_ATTACK
))
10583 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
10586 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
10588 // Check if player is wearing shield
10589 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
10590 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
10594 // Get chance from spell
10595 float chance
= (float)spellProto
->procChance
;
10596 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
10597 if(spellProcEvent
&& spellProcEvent
->customChance
)
10598 chance
= spellProcEvent
->customChance
;
10599 // If PPM exist calculate chance from PPM
10600 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
10602 uint32 WeaponSpeed
= GetAttackTime(attType
);
10603 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
10605 // Apply chance modifer aura
10606 if(Player
* modOwner
= GetSpellModOwner())
10607 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
10609 return roll_chance_f(chance
);
10612 bool Unit::HandleMeandingAuraProc( Aura
* triggeredByAura
)
10614 // aura can be deleted at casts
10615 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
10616 uint32 effIdx
= triggeredByAura
->GetEffIndex();
10617 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
10618 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
10621 int32 jumps
= triggeredByAura
->m_procCharges
-1;
10623 // current aura expire
10624 triggeredByAura
->m_procCharges
= 1; // will removed at next charges decrease
10626 // next target selection
10627 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
10630 if (spellProto
->EffectRadiusIndex
[effIdx
])
10631 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
10633 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
10635 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
10637 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
10639 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
10641 // aura will applied from caster, but spell casted from current aura holder
10642 SpellModifier
*mod
= new SpellModifier
;
10643 mod
->op
= SPELLMOD_CHARGES
;
10644 mod
->value
= jumps
-5; // negative
10645 mod
->type
= SPELLMOD_FLAT
;
10646 mod
->spellId
= spellProto
->Id
;
10647 mod
->mask
= spellProto
->SpellFamilyFlags
;
10648 mod
->mask2
= spellProto
->SpellFamilyFlags2
;
10650 caster
->AddSpellMod(mod
, true);
10651 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
10652 caster
->AddSpellMod(mod
, false);
10658 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
10662 void Unit::RemoveAurasAtChanneledTarget(SpellEntry
const* spellInfo
)
10664 uint64 target_guid
= GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
);
10666 if(!IS_UNIT_GUID(target_guid
))
10669 Unit
* target
= ObjectAccessor::GetUnit(*this, target_guid
);
10673 for (AuraMap::iterator iter
= target
->GetAuras().begin(); iter
!= target
->GetAuras().end(); )
10675 if (iter
->second
->GetId() == spellInfo
->Id
&& iter
->second
->GetCasterGUID()==GetGUID())
10676 target
->RemoveAura(iter
);