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"
46 #include "Traveller.h"
50 float baseMoveSpeed
[MAX_MOVE_TYPE
] =
54 1.25f
, // MOVE_RUN_BACK
55 4.722222f
, // MOVE_SWIM
56 4.5f
, // MOVE_SWIM_BACK
57 3.141594f
, // MOVE_TURN_RATE
59 4.5f
, // MOVE_FLIGHT_BACK
60 3.14f
// MOVE_PITCH_RATE
63 // Used for prepare can/can`t triggr aura
64 static bool InitTriggerAuraData();
65 // Define can trigger auras
66 static bool isTriggerAura
[TOTAL_AURAS
];
67 // Define can`t trigger auras (need for disable second trigger)
68 static bool isNonTriggerAura
[TOTAL_AURAS
];
70 static bool procPrepared
= InitTriggerAuraData();
73 : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this)
75 m_objectType
|= TYPEMASK_UNIT
;
76 m_objectTypeId
= TYPEID_UNIT
;
78 m_updateFlag
= (UPDATEFLAG_LOWGUID
| UPDATEFLAG_HIGHGUID
| UPDATEFLAG_LIVING
| UPDATEFLAG_HAS_POSITION
);
80 m_attackTimer
[BASE_ATTACK
] = 0;
81 m_attackTimer
[OFF_ATTACK
] = 0;
82 m_attackTimer
[RANGED_ATTACK
] = 0;
83 m_modAttackSpeedPct
[BASE_ATTACK
] = 1.0f
;
84 m_modAttackSpeedPct
[OFF_ATTACK
] = 1.0f
;
85 m_modAttackSpeedPct
[RANGED_ATTACK
] = 1.0f
;
93 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
94 m_currentSpells
[i
] = NULL
;
98 for(int i
= 0; i
< MAX_TOTEM
; ++i
)
101 m_ObjectSlot
[0] = m_ObjectSlot
[1] = m_ObjectSlot
[2] = m_ObjectSlot
[3] = 0;
103 //m_AurasCheck = 2000;
104 //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
< MAX_ATTACK
; ++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
);
219 ModifyAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT
, GetHealth() > GetMaxHealth()*0.75f
);
221 i_motionMaster
.UpdateMotion(p_time
);
224 bool Unit::haveOffhandWeapon() const
226 if(GetTypeId() == TYPEID_PLAYER
)
227 return ((Player
*)this)->GetWeaponForAttack(OFF_ATTACK
,true);
232 void Unit::SendMonsterMoveWithSpeedToCurrentDestination(Player
* player
)
235 if(GetMotionMaster()->GetDestination(x
, y
, z
))
236 SendMonsterMoveWithSpeed(x
, y
, z
, 0, player
);
239 void Unit::SendMonsterMoveWithSpeed(float x
, float y
, float z
, uint32 transitTime
, Player
* player
)
243 if(GetTypeId()==TYPEID_PLAYER
)
245 Traveller
<Player
> traveller(*(Player
*)this);
246 transitTime
= traveller
.GetTotalTrevelTimeTo(x
,y
,z
);
250 Traveller
<Creature
> traveller(*(Creature
*)this);
251 transitTime
= traveller
.GetTotalTrevelTimeTo(x
,y
,z
);
254 //float orientation = (float)atan2((double)dy, (double)dx);
255 SendMonsterMove(x
, y
, z
, 0, GetUnitMovementFlags(), transitTime
, player
);
258 void Unit::SendMonsterMove(float NewPosX
, float NewPosY
, float NewPosZ
, uint8 type
, uint32 MovementFlags
, uint32 Time
, Player
* player
)
260 WorldPacket
data( SMSG_MONSTER_MOVE
, (41 + GetPackGUID().size()) );
261 data
.append(GetPackGUID());
263 data
<< GetPositionX() << GetPositionY() << GetPositionZ();
264 data
<< uint32(getMSTime());
266 data
<< uint8(type
); // unknown
269 case 0: // normal packet
271 case 1: // stop packet (raw pos?)
272 SendMessageToSet( &data
, true );
274 case 2: // facing spot, not used currently
279 case 3: // not used currently
280 data
<< uint64(0); // probably target guid (facing target?)
282 case 4: // not used currently
283 data
<< float(0); // facing angle
287 data
<< uint32(MovementFlags
);
288 data
<< uint32(Time
); // Time in between points
289 data
<< uint32(1); // 1 single waypoint
290 data
<< NewPosX
<< NewPosY
<< NewPosZ
; // the single waypoint Point B
293 player
->GetSession()->SendPacket(&data
);
295 SendMessageToSet( &data
, true );
298 void Unit::SendMonsterMoveByPath(Path
const& path
, uint32 start
, uint32 end
, uint32 MovementFlags
)
300 uint32 traveltime
= uint32(path
.GetTotalLength(start
, end
) * 32);
302 uint32 pathSize
= end
-start
;
304 WorldPacket
data( SMSG_MONSTER_MOVE
, (GetPackGUID().size()+4+4+4+4+1+4+4+4+pathSize
*4*3) );
305 data
.append(GetPackGUID());
306 data
<< GetPositionX();
307 data
<< GetPositionY();
308 data
<< GetPositionZ();
311 data
<< uint32( MovementFlags
);
312 data
<< uint32( traveltime
);
313 data
<< uint32( pathSize
);
314 data
.append( (char*)path
.GetNodes(start
), pathSize
* 4 * 3 );
315 SendMessageToSet(&data
, true);
318 void Unit::resetAttackTimer(WeaponAttackType type
)
320 m_attackTimer
[type
] = uint32(GetAttackTime(type
) * m_modAttackSpeedPct
[type
]);
323 bool Unit::canReachWithAttack(Unit
*pVictim
) const
326 float reach
= GetFloatValue(UNIT_FIELD_COMBATREACH
);
329 return IsWithinDistInMap(pVictim
, reach
);
332 void Unit::RemoveSpellsCausingAura(AuraType auraType
)
334 if (auraType
>= TOTAL_AURAS
) return;
335 AuraList::iterator iter
, next
;
336 for (iter
= m_modAuras
[auraType
].begin(); iter
!= m_modAuras
[auraType
].end(); iter
= next
)
343 RemoveAurasDueToSpell((*iter
)->GetId());
344 if (!m_modAuras
[auraType
].empty())
345 next
= m_modAuras
[auraType
].begin();
352 bool Unit::HasAuraType(AuraType auraType
) const
354 return (!m_modAuras
[auraType
].empty());
357 /* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */
358 void Unit::RemoveSpellbyDamageTaken(AuraType auraType
, uint32 damage
)
360 if(!HasAuraType(auraType
))
363 // The chance to dispel an aura depends on the damage taken with respect to the casters level.
364 uint32 max_dmg
= getLevel() > 8 ? 25 * getLevel() - 150 : 50;
365 float chance
= float(damage
) / max_dmg
* 100.0f
;
366 if (roll_chance_f(chance
))
367 RemoveSpellsCausingAura(auraType
);
370 uint32
Unit::DealDamage(Unit
*pVictim
, uint32 damage
, CleanDamage
const* cleanDamage
, DamageEffectType damagetype
, SpellSchoolMask damageSchoolMask
, SpellEntry
const *spellProto
, bool durabilityLoss
)
372 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
375 //You don't lose health from damage taken from another player while in a sanctuary
376 //You still see it in the combat log though
377 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
379 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
380 if(area
&& area
->flags
& AREA_FLAG_SANCTUARY
) //sanctuary
384 // remove affects from victim (including from 0 damage and DoTs)
386 pVictim
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
388 // remove affects from attacker at any non-DoT damage (including 0 damage)
389 if( damagetype
!= DOT
)
391 RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
392 RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
395 RemoveSpellsCausingAura(SPELL_AURA_MOD_INVISIBILITY
);
397 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->IsStandState() && !pVictim
->hasUnitState(UNIT_STAT_STUNNED
))
398 pVictim
->SetStandState(UNIT_STAND_STATE_STAND
);
401 //Script Event damage Deal
402 if( GetTypeId()== TYPEID_UNIT
&& ((Creature
*)this)->AI())
403 ((Creature
*)this)->AI()->DamageDeal(pVictim
, damage
);
404 //Script Event damage taken
405 if( pVictim
->GetTypeId()== TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI() )
406 ((Creature
*)pVictim
)->AI()->DamageTaken(this, damage
);
410 // Rage from physical damage received .
411 if(cleanDamage
&& cleanDamage
->damage
&& (damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
) && pVictim
->GetTypeId() == TYPEID_PLAYER
&& (pVictim
->getPowerType() == POWER_RAGE
))
412 ((Player
*)pVictim
)->RewardRage(cleanDamage
->damage
, 0, false);
416 if (!spellProto
|| !IsAuraAddedBySpell(SPELL_AURA_MOD_FEAR
, spellProto
->Id
))
417 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_FEAR
, damage
);
418 // root type spells do not dispel the root effect
419 if (!spellProto
|| !(spellProto
->Mechanic
== MECHANIC_ROOT
|| IsAuraAddedBySpell(SPELL_AURA_MOD_ROOT
, spellProto
->Id
)))
420 pVictim
->RemoveSpellbyDamageTaken(SPELL_AURA_MOD_ROOT
, damage
);
422 // no xp,health if type 8 /critters/
423 if(pVictim
->GetTypeId() != TYPEID_PLAYER
&& pVictim
->GetCreatureType() == CREATURE_TYPE_CRITTER
)
425 pVictim
->setDeathState(JUST_DIED
);
426 pVictim
->SetHealth(0);
428 // allow loot only if has loot_id in creature_template
429 CreatureInfo
const* cInfo
= ((Creature
*)pVictim
)->GetCreatureInfo();
430 if(cInfo
&& cInfo
->lootid
)
431 pVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
433 // some critters required for quests
434 if(GetTypeId() == TYPEID_PLAYER
)
435 ((Player
*)this)->KilledMonster(pVictim
->GetEntry(),pVictim
->GetGUID());
440 DEBUG_LOG("DealDamageStart");
442 uint32 health
= pVictim
->GetHealth();
443 sLog
.outDetail("deal dmg:%d to health:%d ",damage
,health
);
445 // duel ends when player has 1 or less hp
446 bool duel_hasEnded
= false;
447 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->duel
&& damage
>= (health
-1))
449 // prevent kill only if killed in duel and killed by opponent or opponent controlled creature
450 if(((Player
*)pVictim
)->duel
->opponent
==this || ((Player
*)pVictim
)->duel
->opponent
->GetGUID() == GetOwnerGUID())
453 duel_hasEnded
= true;
456 if(pVictim
!= this && damagetype
!= DOT
)
458 SetInCombatWith(pVictim
);
459 pVictim
->SetInCombatWith(this);
461 if(Player
* attackedPlayer
= pVictim
->GetCharmerOrOwnerPlayerOrPlayerItself())
462 SetContestedPvP(attackedPlayer
);
465 // Rage from Damage made (only from direct weapon damage)
466 if( cleanDamage
&& damagetype
==DIRECT_DAMAGE
&& this != pVictim
&& GetTypeId() == TYPEID_PLAYER
&& (getPowerType() == POWER_RAGE
))
468 uint32 weaponSpeedHitFactor
;
470 switch(cleanDamage
->attackType
)
474 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
475 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 7);
477 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
479 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
485 if(cleanDamage
->hitOutCome
== MELEE_HIT_CRIT
)
486 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 3.5f
);
488 weaponSpeedHitFactor
= uint32(GetAttackTime(cleanDamage
->attackType
)/1000.0f
* 1.75f
);
490 ((Player
*)this)->RewardRage(damage
, weaponSpeedHitFactor
, true);
499 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& GetTypeId() == TYPEID_PLAYER
)
501 if(((Player
*)pVictim
)->InBattleGround())
503 Player
*killer
= ((Player
*)this);
504 if(killer
!= ((Player
*)pVictim
))
505 if(BattleGround
*bg
= killer
->GetBattleGround())
506 bg
->UpdatePlayerScore(killer
, SCORE_DAMAGE_DONE
, damage
);
510 if (pVictim
->GetTypeId() == TYPEID_UNIT
&& !((Creature
*)pVictim
)->isPet() && !((Creature
*)pVictim
)->hasLootRecipient())
511 ((Creature
*)pVictim
)->SetLootRecipient(this);
513 if (health
<= damage
)
515 DEBUG_LOG("DealDamage: victim just died");
517 // find player: owner of controlled `this` or `this` itself maybe
518 Player
*player
= GetCharmerOrOwnerPlayerOrPlayerItself();
520 if(pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->GetLootRecipient())
521 player
= ((Creature
*)pVictim
)->GetLootRecipient();
522 // Reward player, his pets, and group/raid members
523 // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop)
524 if(player
&& player
!=pVictim
)
526 player
->RewardPlayerAndGroupAtKill(pVictim
);
527 player
->ProcDamageAndSpell(pVictim
, PROC_FLAG_KILL
, PROC_FLAG_KILLED
, PROC_EX_NONE
, 0);
530 DEBUG_LOG("DealDamageAttackStop");
533 pVictim
->CombatStop();
534 pVictim
->getHostilRefManager().deleteReferences();
536 bool damageFromSpiritOfRedemtionTalent
= spellProto
&& spellProto
->Id
== 27795;
538 // if talent known but not triggered (check priest class for speedup check)
539 Aura
* spiritOfRedemtionTalentReady
= NULL
;
540 if( !damageFromSpiritOfRedemtionTalent
&& // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION
541 pVictim
->GetTypeId()==TYPEID_PLAYER
&& pVictim
->getClass()==CLASS_PRIEST
)
543 AuraList
const& vDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
544 for(AuraList::const_iterator itr
= vDummyAuras
.begin(); itr
!= vDummyAuras
.end(); ++itr
)
546 if((*itr
)->GetSpellProto()->SpellIconID
==1654)
548 spiritOfRedemtionTalentReady
= *itr
;
554 DEBUG_LOG("SET JUST_DIED");
555 if(!spiritOfRedemtionTalentReady
)
556 pVictim
->setDeathState(JUST_DIED
);
558 DEBUG_LOG("DealDamageHealth1");
560 if(spiritOfRedemtionTalentReady
)
562 // save value before aura remove
563 uint32 ressSpellId
= pVictim
->GetUInt32Value(PLAYER_SELF_RES_SPELL
);
565 ressSpellId
= ((Player
*)pVictim
)->GetResurrectionSpellId();
567 //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers)
568 pVictim
->RemoveAllAurasOnDeath();
570 // restore for use at real death
571 pVictim
->SetUInt32Value(PLAYER_SELF_RES_SPELL
,ressSpellId
);
573 // FORM_SPIRITOFREDEMPTION and related auras
574 pVictim
->CastSpell(pVictim
,27827,true,NULL
,spiritOfRedemtionTalentReady
);
577 pVictim
->SetHealth(0);
579 // remember victim PvP death for corpse type and corpse reclaim delay
580 // at original death (not at SpiritOfRedemtionTalent timeout)
581 if( pVictim
->GetTypeId()==TYPEID_PLAYER
&& !damageFromSpiritOfRedemtionTalent
)
582 ((Player
*)pVictim
)->SetPvPDeath(player
!=NULL
);
584 // Call KilledUnit for creatures
585 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->AI())
586 ((Creature
*)this)->AI()->KilledUnit(pVictim
);
589 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
591 if (GetTypeId() == TYPEID_UNIT
)
592 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE
, GetEntry());
593 else if(GetTypeId() == TYPEID_PLAYER
&& pVictim
!= this)
594 ((Player
*)pVictim
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER
, 1, ((Player
*)this)->GetTeam());
597 // 10% durability loss on death
598 // clean InHateListOf
599 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
601 // only if not player and not controlled by player pet. And not at BG
602 if (durabilityLoss
&& !player
&& !((Player
*)pVictim
)->InBattleGround())
604 DEBUG_LOG("We are dead, loosing 10 percents durability");
605 ((Player
*)pVictim
)->DurabilityLossAll(0.10f
,false);
606 // durability lost message
607 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
608 ((Player
*)pVictim
)->GetSession()->SendPacket(&data
);
611 else // creature died
613 DEBUG_LOG("DealDamageNotPlayer");
614 Creature
*cVictim
= (Creature
*)pVictim
;
616 if(!cVictim
->isPet())
618 cVictim
->DeleteThreatList();
619 cVictim
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_LOOTABLE
);
621 // Call creature just died function
623 cVictim
->AI()->JustDied(this);
625 // Dungeon specific stuff, only applies to players killing creatures
626 if(cVictim
->GetInstanceId())
628 Map
*m
= cVictim
->GetMap();
629 Player
*creditedPlayer
= GetCharmerOrOwnerPlayerOrPlayerItself();
630 // TODO: do instance binding anyway if the charmer/owner is offline
632 if(m
->IsDungeon() && creditedPlayer
)
634 if(m
->IsRaid() || m
->IsHeroic())
636 if(cVictim
->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_INSTANCE_BIND
)
637 ((InstanceMap
*)m
)->PermBindAllPlayers(creditedPlayer
);
641 // the reset time is set but not added to the scheduler
642 // until the players leave the instance
643 time_t resettime
= cVictim
->GetRespawnTimeEx() + 2 * HOUR
;
644 if(InstanceSave
*save
= sInstanceSaveManager
.GetInstanceSave(cVictim
->GetInstanceId()))
645 if(save
->GetResetTime() < resettime
) save
->SetResetTime(resettime
);
651 // last damage from non duel opponent or opponent controlled creature
654 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
655 Player
*he
= (Player
*)pVictim
;
659 he
->duel
->opponent
->CombatStopWithPets(true);
660 he
->CombatStopWithPets(true);
662 he
->DuelComplete(DUEL_INTERUPTED
);
665 // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill)
666 if(pVictim
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)pVictim
)->InBattleGround())
668 Player
*killed
= ((Player
*)pVictim
);
669 if(BattleGround
*bg
= killed
->GetBattleGround())
671 bg
->HandleKillPlayer(killed
, player
);
672 //later we can add support for creature->player kills here i'm
673 //not sure, but i guess those kills also get counted in av
674 //else if(GetTypeId() == TYPEID_UNIT)
675 // bg->HandleKillPlayer(killed,(Creature*)this);
678 else // if (health <= damage)
680 DEBUG_LOG("DealDamageAlive");
682 pVictim
->ModifyHealth(- (int32
)damage
);
684 if(damagetype
!= DOT
)
688 // if not have main target then attack state with target (including AI call)
689 //start melee attacks only after melee hit
690 Attack(pVictim
,(damagetype
== DIRECT_DAMAGE
));
693 // if damage pVictim call AI reaction
694 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
695 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
698 // polymorphed and other negative transformed cases
699 if(pVictim
->getTransForm() && pVictim
->hasUnitState(UNIT_STAT_CONFUSED
))
700 pVictim
->RemoveAurasDueToSpell(pVictim
->getTransForm());
702 if(damagetype
== DIRECT_DAMAGE
|| damagetype
== SPELL_DIRECT_DAMAGE
)
704 if (!spellProto
|| !(spellProto
->AuraInterruptFlags
&AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
))
705 pVictim
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
);
707 if (pVictim
->GetTypeId() != TYPEID_PLAYER
)
709 if(spellProto
&& IsDamageToThreatSpell(spellProto
))
710 pVictim
->AddThreat(this, damage
*2, damageSchoolMask
, spellProto
);
712 pVictim
->AddThreat(this, damage
, damageSchoolMask
, spellProto
);
714 else // victim is a player
716 // Rage from damage received
717 if(this != pVictim
&& pVictim
->getPowerType() == POWER_RAGE
)
719 uint32 rage_damage
= damage
+ (cleanDamage
? cleanDamage
->damage
: 0);
720 ((Player
*)pVictim
)->RewardRage(rage_damage
, 0, false);
723 // random durability for items (HIT TAKEN)
724 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
726 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
727 ((Player
*)pVictim
)->DurabilityPointLossForEquipSlot(slot
);
731 if(GetTypeId()==TYPEID_PLAYER
)
733 // random durability for items (HIT DONE)
734 if (roll_chance_f(sWorld
.getRate(RATE_DURABILITY_LOSS_DAMAGE
)))
736 EquipmentSlots slot
= EquipmentSlots(urand(0,EQUIPMENT_SLOT_END
-1));
737 ((Player
*)this)->DurabilityPointLossForEquipSlot(slot
);
741 // TODO: Store auras by interrupt flag to speed this up.
742 AuraMap
& vAuras
= pVictim
->GetAuras();
743 for (AuraMap::iterator i
= vAuras
.begin(), next
; i
!= vAuras
.end(); i
= next
)
745 const SpellEntry
*se
= i
->second
->GetSpellProto();
747 if (spellProto
&& spellProto
->Id
== se
->Id
) // Not drop auras added by self
749 if( se
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_DAMAGE
)
752 if (se
->procFlags
& (1<<3))
754 if (!roll_chance_i(se
->procChance
))
759 pVictim
->RemoveAurasDueToSpell(i
->second
->GetId());
760 // FIXME: this may cause the auras with proc chance to be rerolled several times
761 next
= vAuras
.begin();
766 if (damagetype
!= NODAMAGE
&& damage
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
768 if( damagetype
!= DOT
)
770 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
772 // skip channeled spell (processed differently below)
773 if (i
== CURRENT_CHANNELED_SPELL
)
776 if(Spell
* spell
= pVictim
->m_currentSpells
[i
])
777 if(spell
->getState() == SPELL_STATE_PREPARING
)
779 if(spell
->m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_ABORT_ON_DMG
)
780 pVictim
->InterruptSpell(i
);
787 if(Spell
* spell
= pVictim
->m_currentSpells
[CURRENT_CHANNELED_SPELL
])
789 if (spell
->getState() == SPELL_STATE_CASTING
)
791 uint32 channelInterruptFlags
= spell
->m_spellInfo
->ChannelInterruptFlags
;
792 if( channelInterruptFlags
& CHANNEL_FLAG_DELAY
)
794 if(pVictim
!=this) //don't shorten the duration of channeling if you damage yourself
795 spell
->DelayedChannel();
797 else if( (channelInterruptFlags
& (CHANNEL_FLAG_DAMAGE
| CHANNEL_FLAG_DAMAGE2
)) )
799 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
800 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
803 else if (spell
->getState() == SPELL_STATE_DELAYED
)
804 // break channeled spell in delayed state on damage
806 sLog
.outDetail("Spell %u canceled at damage!",spell
->m_spellInfo
->Id
);
807 pVictim
->InterruptSpell(CURRENT_CHANNELED_SPELL
);
812 // last damage from duel opponent
815 assert(pVictim
->GetTypeId()==TYPEID_PLAYER
);
816 Player
*he
= (Player
*)pVictim
;
822 he
->duel
->opponent
->CombatStopWithPets(true);
823 he
->CombatStopWithPets(true);
825 he
->CastSpell(he
, 7267, true); // beg
826 he
->DuelComplete(DUEL_WON
);
830 DEBUG_LOG("DealDamageEnd returned %d damage", damage
);
835 void Unit::CastStop(uint32 except_spellid
)
837 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
838 if (m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
!=except_spellid
)
839 InterruptSpell(i
,false);
842 void Unit::CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
844 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
848 sLog
.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId
,(GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
852 CastSpell(Victim
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
855 void Unit::CastSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
859 sLog
.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
864 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
866 if(!originalCaster
&& triggeredByAura
)
867 originalCaster
= triggeredByAura
->GetCasterGUID();
869 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
871 SpellCastTargets targets
;
872 targets
.setUnitTarget( Victim
);
873 spell
->m_CastItem
= castItem
;
874 spell
->prepare(&targets
, triggeredByAura
);
877 void Unit::CastCustomSpell(Unit
* Victim
,uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
879 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
883 sLog
.outError("CastCustomSpell: unknown spell id %i", spellId
);
887 CastCustomSpell(Victim
,spellInfo
,bp0
,bp1
,bp2
,triggered
,castItem
,triggeredByAura
, originalCaster
);
890 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
)
894 sLog
.outError("CastCustomSpell: unknown spell");
899 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
901 if(!originalCaster
&& triggeredByAura
)
902 originalCaster
= triggeredByAura
->GetCasterGUID();
904 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
907 spell
->m_currentBasePoints
[0] = *bp0
-int32(spellInfo
->EffectBaseDice
[0]);
910 spell
->m_currentBasePoints
[1] = *bp1
-int32(spellInfo
->EffectBaseDice
[1]);
913 spell
->m_currentBasePoints
[2] = *bp2
-int32(spellInfo
->EffectBaseDice
[2]);
915 SpellCastTargets targets
;
916 targets
.setUnitTarget( Victim
);
917 spell
->m_CastItem
= castItem
;
918 spell
->prepare(&targets
, triggeredByAura
);
921 // used for scripting
922 void Unit::CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
924 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
928 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()));
932 CastSpell(x
, y
, z
,spellInfo
,triggered
,castItem
,triggeredByAura
, originalCaster
);
935 // used for scripting
936 void Unit::CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
, Aura
* triggeredByAura
, uint64 originalCaster
)
940 sLog
.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER
? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER
? GetGUIDLow() : GetEntry()));
945 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo
->Id
);
947 if(!originalCaster
&& triggeredByAura
)
948 originalCaster
= triggeredByAura
->GetCasterGUID();
950 Spell
*spell
= new Spell(this, spellInfo
, triggered
, originalCaster
);
952 SpellCastTargets targets
;
953 targets
.setDestination(x
, y
, z
);
954 spell
->m_CastItem
= castItem
;
955 spell
->prepare(&targets
, triggeredByAura
);
958 // Obsolete func need remove, here only for comotability vs another patches
959 uint32
Unit::SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
, bool isTriggeredSpell
, bool useSpellDamage
)
961 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellID
);
962 SpellNonMeleeDamage
damageInfo(this, pVictim
, spellInfo
->Id
, spellInfo
->SchoolMask
);
963 CalculateSpellDamage(&damageInfo
, damage
, spellInfo
);
964 SendSpellNonMeleeDamageLog(&damageInfo
);
965 DealSpellDamage(&damageInfo
, true);
966 return damageInfo
.damage
;
969 void Unit::CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
)
971 SpellSchoolMask damageSchoolMask
= SpellSchoolMask(damageInfo
->schoolMask
);
972 Unit
*pVictim
= damageInfo
->target
;
977 if(!this || !pVictim
)
979 if(!this->isAlive() || !pVictim
->isAlive())
982 uint32 crTypeMask
= pVictim
->GetCreatureTypeMask();
983 // Check spell crit chance
984 bool crit
= isSpellCrit(pVictim
, spellInfo
, damageSchoolMask
, attackType
);
985 bool blocked
= false;
987 switch (spellInfo
->DmgClass
)
989 // Melee and Ranged Spells
990 case SPELL_DAMAGE_CLASS_RANGED
:
991 case SPELL_DAMAGE_CLASS_MELEE
:
994 if ( damageSchoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
996 //Calculate armor mitigation
997 damage
= CalcArmorReducedDamage(pVictim
, damage
);
998 // Get blocked status
999 blocked
= isSpellBlocked(pVictim
, spellInfo
, attackType
);
1004 // Calculate damage bonus
1005 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1009 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1011 // Calculate crit bonus
1012 uint32 crit_bonus
= damage
;
1013 // Apply crit_damage bonus for melee spells
1014 if(Player
* modOwner
= GetSpellModOwner())
1015 modOwner
->ApplySpellMod(spellInfo
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
1016 damage
+= crit_bonus
;
1018 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1019 int32 critPctDamageMod
=0;
1020 if(attackType
== RANGED_ATTACK
)
1021 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1024 critPctDamageMod
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1025 critPctDamageMod
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
);
1027 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1028 critPctDamageMod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1030 if (critPctDamageMod
!=0)
1031 damage
= int32((damage
) * float((100.0f
+ critPctDamageMod
)/100.0f
));
1033 // Resilience - reduce crit damage
1034 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1035 damage
-= ((Player
*)pVictim
)->GetMeleeCritDamageReduction(damage
);
1037 // Spell weapon based damage CAN BE crit & blocked at same time
1040 damageInfo
->blocked
= uint32(pVictim
->GetShieldBlockValue());
1041 if (damage
< damageInfo
->blocked
)
1042 damageInfo
->blocked
= damage
;
1043 damage
-=damageInfo
->blocked
;
1048 case SPELL_DAMAGE_CLASS_NONE
:
1049 case SPELL_DAMAGE_CLASS_MAGIC
:
1051 // Calculate damage bonus
1052 damage
= SpellDamageBonus(pVictim
, spellInfo
, damage
, SPELL_DIRECT_DAMAGE
);
1053 // If crit add critical bonus
1056 damageInfo
->HitInfo
|= SPELL_HIT_TYPE_CRIT
;
1057 damage
= SpellCriticalDamageBonus(spellInfo
, damage
, pVictim
);
1058 // Resilience - reduce crit damage
1059 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1060 damage
-= ((Player
*)pVictim
)->GetSpellCritDamageReduction(damage
);
1066 // Calculate absorb resist
1069 // lookup absorb/resist ignore auras on caster for spell
1070 bool ignore
= false;
1071 Unit::AuraList
const& ignoreAbsorb
= GetAurasByType(SPELL_AURA_MOD_IGNORE_ABSORB_FOR_SPELL
);
1072 for(Unit::AuraList::const_iterator i
= ignoreAbsorb
.begin(); i
!= ignoreAbsorb
.end(); ++i
)
1073 if ((*i
)->isAffectedOnSpell(spellInfo
))
1081 CalcAbsorbResist(pVictim
, damageSchoolMask
, SPELL_DIRECT_DAMAGE
, damage
, &damageInfo
->absorb
, &damageInfo
->resist
);
1082 damage
-= damageInfo
->absorb
+ damageInfo
->resist
;
1087 damageInfo
->damage
= damage
;
1090 void Unit::DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
)
1095 Unit
*pVictim
= damageInfo
->target
;
1097 if(!this || !pVictim
)
1100 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1103 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry(damageInfo
->SpellID
);
1104 if (spellProto
== NULL
)
1106 sLog
.outDebug("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", damageInfo
->SpellID
);
1110 //You don't lose health from damage taken from another player while in a sanctuary
1111 //You still see it in the combat log though
1112 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1114 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1115 if(area
&& area
->flags
& 0x800) //sanctuary
1119 // Call default DealDamage
1120 CleanDamage
cleanDamage(damageInfo
->cleanDamage
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
1121 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, SPELL_DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->schoolMask
), spellProto
, durabilityLoss
);
1124 //TODO for melee need create structure as in
1125 void Unit::CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
)
1127 damageInfo
->attacker
= this;
1128 damageInfo
->target
= pVictim
;
1129 damageInfo
->damageSchoolMask
= GetMeleeDamageSchoolMask();
1130 damageInfo
->attackType
= attackType
;
1131 damageInfo
->damage
= 0;
1132 damageInfo
->cleanDamage
= 0;
1133 damageInfo
->absorb
= 0;
1134 damageInfo
->resist
= 0;
1135 damageInfo
->blocked_amount
= 0;
1137 damageInfo
->TargetState
= 0;
1138 damageInfo
->HitInfo
= 0;
1139 damageInfo
->procAttacker
= PROC_FLAG_NONE
;
1140 damageInfo
->procVictim
= PROC_FLAG_NONE
;
1141 damageInfo
->procEx
= PROC_EX_NONE
;
1142 damageInfo
->hitOutCome
= MELEE_HIT_EVADE
;
1144 if(!this || !pVictim
)
1146 if(!this->isAlive() || !pVictim
->isAlive())
1149 // Select HitInfo/procAttacker/procVictim flag based on attack type
1153 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MILEE_HIT
;
1154 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;
1155 damageInfo
->HitInfo
= HITINFO_NORMALSWING2
;
1158 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_MILEE_HIT
| PROC_FLAG_SUCCESSFUL_OFFHAND_HIT
;
1159 damageInfo
->procVictim
= PROC_FLAG_TAKEN_MELEE_HIT
;//|PROC_FLAG_TAKEN_OFFHAND_HIT // not used
1160 damageInfo
->HitInfo
= HITINFO_LEFTSWING
;
1163 damageInfo
->procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
1164 damageInfo
->procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
1165 damageInfo
->HitInfo
= 0x08;// test
1171 // Physical Immune check
1172 if(damageInfo
->target
->IsImmunedToDamage(SpellSchoolMask(damageInfo
->damageSchoolMask
)))
1174 damageInfo
->HitInfo
|= HITINFO_NORMALSWING
;
1175 damageInfo
->TargetState
= VICTIMSTATE_IS_IMMUNE
;
1177 damageInfo
->procEx
|=PROC_EX_IMMUNE
;
1178 damageInfo
->damage
= 0;
1179 damageInfo
->cleanDamage
= 0;
1182 damage
+= CalculateDamage (damageInfo
->attackType
, false);
1183 // Add melee damage bonus
1184 MeleeDamageBonus(damageInfo
->target
, &damage
, damageInfo
->attackType
);
1185 // Calculate armor reduction
1186 damageInfo
->damage
= CalcArmorReducedDamage(damageInfo
->target
, damage
);
1187 damageInfo
->cleanDamage
+= damage
- damageInfo
->damage
;
1189 damageInfo
->hitOutCome
= RollMeleeOutcomeAgainst(damageInfo
->target
, damageInfo
->attackType
);
1191 // Disable parry or dodge for ranged attack
1192 if(damageInfo
->attackType
== RANGED_ATTACK
)
1194 if (damageInfo
->hitOutCome
== MELEE_HIT_PARRY
) damageInfo
->hitOutCome
= MELEE_HIT_NORMAL
;
1195 if (damageInfo
->hitOutCome
== MELEE_HIT_DODGE
) damageInfo
->hitOutCome
= MELEE_HIT_MISS
;
1198 switch(damageInfo
->hitOutCome
)
1200 case MELEE_HIT_EVADE
:
1202 damageInfo
->HitInfo
|= HITINFO_MISS
|HITINFO_SWINGNOHITSOUND
;
1203 damageInfo
->TargetState
= VICTIMSTATE_EVADES
;
1205 damageInfo
->procEx
|=PROC_EX_EVADE
;
1206 damageInfo
->damage
= 0;
1207 damageInfo
->cleanDamage
= 0;
1210 case MELEE_HIT_MISS
:
1212 damageInfo
->HitInfo
|= HITINFO_MISS
;
1213 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1215 damageInfo
->procEx
|=PROC_EX_MISS
;
1216 damageInfo
->damage
= 0;
1217 damageInfo
->cleanDamage
= 0;
1220 case MELEE_HIT_NORMAL
:
1221 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1222 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1224 case MELEE_HIT_CRIT
:
1226 damageInfo
->HitInfo
|= HITINFO_CRITICALHIT
;
1227 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1229 damageInfo
->procEx
|=PROC_EX_CRITICAL_HIT
;
1231 damageInfo
->damage
+= damageInfo
->damage
;
1233 // Apply SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE or SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
1234 if(damageInfo
->attackType
== RANGED_ATTACK
)
1235 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE
);
1238 mod
+= damageInfo
->target
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE
);
1239 mod
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE
);
1242 uint32 crTypeMask
= damageInfo
->target
->GetCreatureTypeMask();
1244 // Increase crit damage from SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
1245 mod
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, crTypeMask
);
1247 damageInfo
->damage
= int32((damageInfo
->damage
) * float((100.0f
+ mod
)/100.0f
));
1249 // Resilience - reduce crit damage
1250 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
1252 uint32 resilienceReduction
= ((Player
*)pVictim
)->GetMeleeCritDamageReduction(damageInfo
->damage
);
1253 damageInfo
->damage
-= resilienceReduction
;
1254 damageInfo
->cleanDamage
+= resilienceReduction
;
1258 case MELEE_HIT_PARRY
:
1259 damageInfo
->TargetState
= VICTIMSTATE_PARRY
;
1260 damageInfo
->procEx
|=PROC_EX_PARRY
;
1261 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1262 damageInfo
->damage
= 0;
1265 case MELEE_HIT_DODGE
:
1266 damageInfo
->TargetState
= VICTIMSTATE_DODGE
;
1267 damageInfo
->procEx
|=PROC_EX_DODGE
;
1268 damageInfo
->cleanDamage
+= damageInfo
->damage
;
1269 damageInfo
->damage
= 0;
1271 case MELEE_HIT_BLOCK
:
1273 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1274 damageInfo
->HitInfo
|= HITINFO_BLOCK
;
1275 damageInfo
->procEx
|=PROC_EX_BLOCK
;
1276 damageInfo
->blocked_amount
= damageInfo
->target
->GetShieldBlockValue();
1277 if (damageInfo
->blocked_amount
>= damageInfo
->damage
)
1279 damageInfo
->TargetState
= VICTIMSTATE_BLOCKS
;
1280 damageInfo
->blocked_amount
= damageInfo
->damage
;
1282 damageInfo
->damage
-= damageInfo
->blocked_amount
;
1283 damageInfo
->cleanDamage
+= damageInfo
->blocked_amount
;
1286 case MELEE_HIT_GLANCING
:
1288 damageInfo
->HitInfo
|= HITINFO_GLANCING
;
1289 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1290 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1291 float reducePercent
= 1.0f
; //damage factor
1292 // calculate base values and mods
1293 float baseLowEnd
= 1.3;
1294 float baseHighEnd
= 1.2;
1295 switch(getClass()) // lowering base values for casters
1307 float maxLowEnd
= 0.6;
1308 switch(getClass()) // upper for melee classes
1312 maxLowEnd
= 0.91; //If the attacker is a melee class then instead the lower value of 0.91
1316 int32 diff
= damageInfo
->target
->GetDefenseSkillValue() - GetWeaponSkillValue(damageInfo
->attackType
);
1317 float lowEnd
= baseLowEnd
- ( 0.05f
* diff
);
1318 float highEnd
= baseHighEnd
- ( 0.03f
* diff
);
1320 // apply max/min bounds
1321 if ( lowEnd
< 0.01f
) //the low end must not go bellow 0.01f
1323 else if ( lowEnd
> maxLowEnd
) //the smaller value of this and 0.6 is kept as the low end
1326 if ( highEnd
< 0.2f
) //high end limits
1328 if ( highEnd
> 0.99f
)
1331 if(lowEnd
> highEnd
) // prevent negative range size
1334 reducePercent
= lowEnd
+ rand_norm() * ( highEnd
- lowEnd
);
1336 damageInfo
->cleanDamage
+= damageInfo
->damage
-uint32(reducePercent
* damageInfo
->damage
);
1337 damageInfo
->damage
= uint32(reducePercent
* damageInfo
->damage
);
1340 case MELEE_HIT_CRUSHING
:
1342 damageInfo
->HitInfo
|= HITINFO_CRUSHING
;
1343 damageInfo
->TargetState
= VICTIMSTATE_NORMAL
;
1344 damageInfo
->procEx
|=PROC_EX_NORMAL_HIT
;
1345 // 150% normal damage
1346 damageInfo
->damage
+= (damageInfo
->damage
/ 2);
1354 // Calculate absorb resist
1355 if(int32(damageInfo
->damage
) > 0)
1357 damageInfo
->procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1358 // Calculate absorb & resists
1359 CalcAbsorbResist(damageInfo
->target
, SpellSchoolMask(damageInfo
->damageSchoolMask
), DIRECT_DAMAGE
, damageInfo
->damage
, &damageInfo
->absorb
, &damageInfo
->resist
);
1360 damageInfo
->damage
-=damageInfo
->absorb
+ damageInfo
->resist
;
1361 if (damageInfo
->absorb
)
1363 damageInfo
->HitInfo
|=HITINFO_ABSORB
;
1364 damageInfo
->procEx
|=PROC_EX_ABSORB
;
1366 if (damageInfo
->resist
)
1367 damageInfo
->HitInfo
|=HITINFO_RESIST
;
1370 else // Umpossible get negative result but....
1371 damageInfo
->damage
= 0;
1374 void Unit::DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
)
1376 if (damageInfo
==0) return;
1377 Unit
*pVictim
= damageInfo
->target
;
1379 if(!this || !pVictim
)
1382 if (!pVictim
->isAlive() || pVictim
->isInFlight() || pVictim
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
1385 //You don't lose health from damage taken from another player while in a sanctuary
1386 //You still see it in the combat log though
1387 if(pVictim
!= this && GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
1389 const AreaTableEntry
*area
= GetAreaEntryByAreaID(pVictim
->GetAreaId());
1390 if(area
&& area
->flags
& 0x800) //sanctuary
1394 // Hmmmm dont like this emotes cloent must by self do all animations
1395 if (damageInfo
->HitInfo
&HITINFO_CRITICALHIT
)
1396 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL
);
1397 if(damageInfo
->blocked_amount
&& damageInfo
->TargetState
!=VICTIMSTATE_BLOCKS
)
1398 pVictim
->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD
);
1400 if(damageInfo
->TargetState
== VICTIMSTATE_PARRY
)
1402 // Get attack timers
1403 float offtime
= float(pVictim
->getAttackTimer(OFF_ATTACK
));
1404 float basetime
= float(pVictim
->getAttackTimer(BASE_ATTACK
));
1405 // Reduce attack time
1406 if (pVictim
->haveOffhandWeapon() && offtime
< basetime
)
1408 float percent20
= pVictim
->GetAttackTime(OFF_ATTACK
) * 0.20;
1409 float percent60
= 3 * percent20
;
1410 if(offtime
> percent20
&& offtime
<= percent60
)
1412 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(percent20
));
1414 else if(offtime
> percent60
)
1416 offtime
-= 2 * percent20
;
1417 pVictim
->setAttackTimer(OFF_ATTACK
, uint32(offtime
));
1422 float percent20
= pVictim
->GetAttackTime(BASE_ATTACK
) * 0.20;
1423 float percent60
= 3 * percent20
;
1424 if(basetime
> percent20
&& basetime
<= percent60
)
1426 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(percent20
));
1428 else if(basetime
> percent60
)
1430 basetime
-= 2 * percent20
;
1431 pVictim
->setAttackTimer(BASE_ATTACK
, uint32(basetime
));
1436 // Call default DealDamage
1437 CleanDamage
cleanDamage(damageInfo
->cleanDamage
,damageInfo
->attackType
,damageInfo
->hitOutCome
);
1438 DealDamage(pVictim
, damageInfo
->damage
, &cleanDamage
, DIRECT_DAMAGE
, SpellSchoolMask(damageInfo
->damageSchoolMask
), NULL
, durabilityLoss
);
1440 // If this is a creature and it attacks from behind it has a probability to daze it's victim
1441 if( (damageInfo
->hitOutCome
==MELEE_HIT_CRIT
|| damageInfo
->hitOutCome
==MELEE_HIT_CRUSHING
|| damageInfo
->hitOutCome
==MELEE_HIT_NORMAL
|| damageInfo
->hitOutCome
==MELEE_HIT_GLANCING
) &&
1442 GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)this)->GetCharmerOrOwnerGUID() && !pVictim
->HasInArc(M_PI
, this) )
1444 // -probability is between 0% and 40%
1446 float Probability
= 20;
1448 //there is a newbie protection, at level 10 just 7% base chance; assuming linear function
1449 if( pVictim
->getLevel() < 30 )
1450 Probability
= 0.65f
*pVictim
->getLevel()+0.5;
1452 uint32 VictimDefense
=pVictim
->GetDefenseSkillValue();
1453 uint32 AttackerMeleeSkill
=GetUnitMeleeSkill();
1455 Probability
*= AttackerMeleeSkill
/(float)VictimDefense
;
1457 if(Probability
> 40)
1460 if(roll_chance_f(Probability
))
1461 CastSpell(pVictim
, 1604, true);
1465 if (!(damageInfo
->HitInfo
& HITINFO_MISS
))
1467 if(GetTypeId() == TYPEID_PLAYER
&& pVictim
->isAlive())
1469 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
1470 ((Player
*)this)->CastItemCombatSpell(((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
,i
), pVictim
, damageInfo
->attackType
);
1473 // victim's damage shield
1474 std::set
<Aura
*> alreadyDone
;
1475 uint32 removedAuras
= pVictim
->m_removedAuras
;
1476 AuraList
const& vDamageShields
= pVictim
->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD
);
1477 for(AuraList::const_iterator i
= vDamageShields
.begin(), next
= vDamageShields
.begin(); i
!= vDamageShields
.end(); i
= next
)
1480 if (alreadyDone
.find(*i
) == alreadyDone
.end())
1482 alreadyDone
.insert(*i
);
1483 uint32 damage
=(*i
)->GetModifier()->m_amount
;
1484 SpellEntry
const *spellProto
= sSpellStore
.LookupEntry((*i
)->GetId());
1487 //Calculate absorb resist ??? no data in opcode for this possibly unable to absorb or resist?
1490 //CalcAbsorbResist(pVictim, SpellSchools(spellProto->School), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
1491 //damage-=absorb + resist;
1493 WorldPacket
data(SMSG_SPELLDAMAGESHIELD
,(8+8+4+4+4+4));
1494 data
<< uint64(pVictim
->GetGUID());
1495 data
<< uint64(GetGUID());
1496 data
<< uint32(spellProto
->Id
);
1497 data
<< uint32(damage
); // Damage
1498 data
<< uint32(0); // Overkill
1499 data
<< uint32(spellProto
->SchoolMask
);
1500 pVictim
->SendMessageToSet(&data
, true );
1502 pVictim
->DealDamage(this, damage
, 0, SPELL_DIRECT_DAMAGE
, GetSpellSchoolMask(spellProto
), spellProto
, true);
1504 if (pVictim
->m_removedAuras
> removedAuras
)
1506 removedAuras
= pVictim
->m_removedAuras
;
1507 next
= vDamageShields
.begin();
1515 void Unit::HandleEmoteCommand(uint32 anim_id
)
1517 WorldPacket
data( SMSG_EMOTE
, 12 );
1518 data
<< uint32(anim_id
);
1519 data
<< uint64(GetGUID());
1520 SendMessageToSet(&data
, true);
1523 uint32
Unit::CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
)
1525 uint32 newdamage
= 0;
1526 float armor
= pVictim
->GetArmor();
1527 // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura
1528 armor
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, SPELL_SCHOOL_MASK_NORMAL
);
1530 // Apply Player CR_ARMOR_PENETRATION rating
1531 if (GetTypeId()==TYPEID_PLAYER
)
1532 armor
*= 1.0f
- ((Player
*)this)->GetRatingBonusValue(CR_ARMOR_PENETRATION
) / 100.0f
;
1534 if (armor
< 0.0f
) armor
=0.0f
;
1536 float levelModifier
= getLevel();
1537 if ( levelModifier
> 59 )
1538 levelModifier
= levelModifier
+ (4.5f
* (levelModifier
-59));
1540 float tmpvalue
= 0.1f
* armor
/ (8.5f
* levelModifier
+ 40);
1541 tmpvalue
= tmpvalue
/(1.0f
+ tmpvalue
);
1545 if(tmpvalue
> 0.75f
)
1547 newdamage
= uint32(damage
- (damage
* tmpvalue
));
1549 return (newdamage
> 1) ? newdamage
: 1;
1552 void Unit::CalcAbsorbResist(Unit
*pVictim
,SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
)
1554 if(!pVictim
|| !pVictim
->isAlive() || !damage
)
1557 // Magic damage, check for resists
1558 if ((schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)==0)
1560 // Get base victim resistance for school
1561 float tmpvalue2
= (float)pVictim
->GetResistance(GetFirstSchoolInMask(schoolMask
));
1562 // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura
1563 tmpvalue2
+= (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE
, schoolMask
);
1565 tmpvalue2
*= (float)(0.15f
/ getLevel());
1566 if (tmpvalue2
< 0.0f
)
1568 if (tmpvalue2
> 0.75f
)
1570 uint32 ran
= urand(0, 100);
1571 uint32 faq
[4] = {24,6,4,6};
1574 for (uint8 i
= 0; i
< 4; i
++)
1576 Binom
+= 2400 *( powf(tmpvalue2
, i
) * powf( (1-tmpvalue2
), (4-i
)))/faq
[i
];
1582 if (damagetype
== DOT
&& m
== 4)
1583 *resist
+= uint32(damage
- 1);
1585 *resist
+= uint32(damage
* m
/ 4);
1586 if(*resist
> damage
)
1592 int32 RemainingDamage
= damage
- *resist
;
1594 // Get unit state (need for some absorb check)
1595 uint32 unitflag
= pVictim
->GetUInt32Value(UNIT_FIELD_FLAGS
);
1596 // Reflect damage spells (not cast any damage spell in aura lookup)
1597 uint32 reflectSpell
= 0;
1598 int32 reflectDamage
= 0;
1599 // Need remove expired auras after
1600 bool existExpired
= false;
1601 // absorb without mana cost
1602 AuraList
const& vSchoolAbsorb
= pVictim
->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB
);
1603 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end() && RemainingDamage
> 0; ++i
)
1605 Modifier
* mod
= (*i
)->GetModifier();
1606 if (!(mod
->m_miscvalue
& schoolMask
))
1609 SpellEntry
const* spellProto
= (*i
)->GetSpellProto();
1611 // Max Amount can be absorbed by this aura
1612 int32 currentAbsorb
= mod
->m_amount
;
1614 // Found empty aura (umpossible but..)
1615 if (currentAbsorb
<=0)
1617 existExpired
= true;
1620 // Handle custom absorb auras
1621 // TODO: try find better way
1622 switch(spellProto
->SpellFamilyName
)
1624 case SPELLFAMILY_GENERIC
:
1627 if (spellProto
->SpellIconID
== 3066)
1629 //reduces all damage taken while stun, fear or silence
1630 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1631 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1635 if (spellProto
->SpellIconID
== 2115)
1637 // while affected by Stun and Fear
1638 if (unitflag
&(UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
))
1639 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1643 if (spellProto
->SpellIconID
== 3006)
1645 // You have a chance equal to your Parry chance
1646 if (damagetype
== DIRECT_DAMAGE
&& // Only for direct damage
1647 roll_chance_f(pVictim
->GetUnitParryChance())) // Roll chance
1648 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1651 // Reflective Shield (Lady Malande boss)
1652 if (spellProto
->Id
== 41475)
1654 if(RemainingDamage
< currentAbsorb
)
1655 reflectDamage
= RemainingDamage
/ 2;
1657 reflectDamage
= currentAbsorb
/ 2;
1658 reflectSpell
= 33619;
1661 if (spellProto
->Id
== 39228 || // Argussian Compass
1662 spellProto
->Id
== 60218) // Essence of Gossamer
1664 // Max absorb stored in 1 dummy effect
1665 if (spellProto
->EffectBasePoints
[1] < currentAbsorb
)
1666 currentAbsorb
= spellProto
->EffectBasePoints
[1];
1671 case SPELLFAMILY_DRUID
:
1674 if (spellProto
->SpellIconID
== 2253)
1676 //reduces all damage taken while Stunned
1677 if (unitflag
& UNIT_FLAG_STUNNED
)
1678 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1683 case SPELLFAMILY_ROGUE
:
1686 if(spellProto
->SpellIconID
== 2109)
1688 if (pVictim
->GetTypeId()==TYPEID_PLAYER
&& // Only players
1689 pVictim
->GetHealth() <= RemainingDamage
&& // Only if damage kill
1690 !((Player
*)pVictim
)->HasSpellCooldown(31231) && // Only if no cooldown
1691 roll_chance_i(currentAbsorb
)) // Only if roll
1693 pVictim
->CastSpell(pVictim
,31231,true);
1694 ((Player
*)pVictim
)->AddSpellCooldown(31231,0,time(NULL
)+60);
1695 // with health > 10% lost health until health==10%, in other case no losses
1696 uint32 health10
= pVictim
->GetMaxHealth()/10;
1697 RemainingDamage
= pVictim
->GetHealth() > health10
? pVictim
->GetHealth() - health10
: 0;
1703 case SPELLFAMILY_PRIEST
:
1705 // Reflective Shield
1706 if (spellProto
->SpellFamilyFlags
== 0x1)
1708 if (pVictim
== this)
1710 Unit
* caster
= (*i
)->GetCaster();
1713 AuraList
const& vOverRideCS
= caster
->GetAurasByType(SPELL_AURA_DUMMY
);
1714 for(AuraList::const_iterator k
= vOverRideCS
.begin(); k
!= vOverRideCS
.end(); ++k
)
1716 switch((*k
)->GetModifier()->m_miscvalue
)
1718 case 5065: // Rank 1
1719 case 5064: // Rank 2
1720 case 5063: // Rank 3
1722 if(RemainingDamage
>= currentAbsorb
)
1723 reflectDamage
= (*k
)->GetModifier()->m_amount
* currentAbsorb
/100;
1725 reflectDamage
= (*k
)->GetModifier()->m_amount
* RemainingDamage
/100;
1726 reflectSpell
= 33619;
1735 case SPELLFAMILY_SHAMAN
:
1738 if (spellProto
->SpellIconID
== 3066)
1740 //reduces all damage taken while stun, fear or silence
1741 if (unitflag
& (UNIT_FLAG_STUNNED
|UNIT_FLAG_FLEEING
|UNIT_FLAG_SILENCED
))
1742 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1747 case SPELLFAMILY_DEATHKNIGHT
:
1750 if (spellProto
->SpellIconID
== 1958)
1752 // TODO: absorb only while transform
1755 // Anti-Magic Shell (on self)
1756 if (spellProto
->Id
== 48707)
1758 // damage absorbed by Anti-Magic Shell energizes the DK with additional runic power.
1759 // This, if I'm not mistaken, shows that we get back ~2% of the absorbed damage as runic power.
1760 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
1761 int32 regen
= absorbed
* 2 / 10;
1762 pVictim
->CastCustomSpell(pVictim
, 49088, ®en
, 0, 0, true, 0, *i
);
1763 RemainingDamage
-= absorbed
;
1766 // Anti-Magic Shell (on single party/raid member)
1767 if (spellProto
->Id
== 50462)
1769 RemainingDamage
-= RemainingDamage
* currentAbsorb
/ 100;
1773 if (spellProto
->Id
== 50461)
1775 Unit
* caster
= (*i
)->GetCaster();
1778 int32 absorbed
= RemainingDamage
* currentAbsorb
/ 100;
1779 int32 canabsorb
= caster
->GetHealth();
1780 if (canabsorb
< absorbed
)
1781 absorbed
= canabsorb
;
1782 DealDamage(caster
, absorbed
, NULL
, damagetype
, schoolMask
, 0, false);
1783 RemainingDamage
-= absorbed
;
1792 // currentAbsorb - damage can be absorbed by shield
1793 // If need absorb less damage
1794 if (RemainingDamage
< currentAbsorb
)
1795 currentAbsorb
= RemainingDamage
;
1797 RemainingDamage
-= currentAbsorb
;
1799 // Reduce shield amount
1800 mod
->m_amount
-=currentAbsorb
;
1801 // Need remove it later
1802 if (mod
->m_amount
<=0)
1803 existExpired
= true;
1806 // Remove all expired absorb auras
1809 for(AuraList::const_iterator i
= vSchoolAbsorb
.begin(); i
!= vSchoolAbsorb
.end();)
1811 if ((*i
)->GetModifier()->m_amount
<=0)
1813 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
1814 i
= vSchoolAbsorb
.begin();
1820 // Cast back reflect damage spell
1822 pVictim
->CastCustomSpell(this, reflectSpell
, &reflectDamage
, NULL
, NULL
, true);
1824 // absorb by mana cost
1825 AuraList
const& vManaShield
= pVictim
->GetAurasByType(SPELL_AURA_MANA_SHIELD
);
1826 for(AuraList::const_iterator i
= vManaShield
.begin(), next
; i
!= vManaShield
.end() && RemainingDamage
> 0; i
= next
)
1830 // check damage school mask
1831 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1834 int32 currentAbsorb
;
1835 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
1836 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
1838 currentAbsorb
= RemainingDamage
;
1840 float manaMultiplier
= (*i
)->GetSpellProto()->EffectMultipleValue
[(*i
)->GetEffIndex()];
1841 if(Player
*modOwner
= pVictim
->GetSpellModOwner())
1842 modOwner
->ApplySpellMod((*i
)->GetId(), SPELLMOD_MULTIPLE_VALUE
, manaMultiplier
);
1844 int32 maxAbsorb
= int32(pVictim
->GetPower(POWER_MANA
) / manaMultiplier
);
1845 if (currentAbsorb
> maxAbsorb
)
1846 currentAbsorb
= maxAbsorb
;
1848 (*i
)->GetModifier()->m_amount
-= currentAbsorb
;
1849 if((*i
)->GetModifier()->m_amount
<= 0)
1851 pVictim
->RemoveAurasDueToSpell((*i
)->GetId());
1852 next
= vManaShield
.begin();
1855 int32 manaReduction
= int32(currentAbsorb
* manaMultiplier
);
1856 pVictim
->ApplyPowerMod(POWER_MANA
, manaReduction
, false);
1858 RemainingDamage
-= currentAbsorb
;
1861 // only split damage if not damaging yourself
1864 AuraList
const& vSplitDamageFlat
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT
);
1865 for(AuraList::const_iterator i
= vSplitDamageFlat
.begin(), next
; i
!= vSplitDamageFlat
.end() && RemainingDamage
>= 0; i
= next
)
1869 // check damage school mask
1870 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1873 // Damage can be splitted only if aura has an alive caster
1874 Unit
*caster
= (*i
)->GetCaster();
1875 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
1878 int32 currentAbsorb
;
1879 if (RemainingDamage
>= (*i
)->GetModifier()->m_amount
)
1880 currentAbsorb
= (*i
)->GetModifier()->m_amount
;
1882 currentAbsorb
= RemainingDamage
;
1884 RemainingDamage
-= currentAbsorb
;
1886 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, currentAbsorb
, schoolMask
, 0, 0, false, 0, false);
1888 CleanDamage cleanDamage
= CleanDamage(currentAbsorb
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
1889 DealDamage(caster
, currentAbsorb
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
1892 AuraList
const& vSplitDamagePct
= pVictim
->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT
);
1893 for(AuraList::const_iterator i
= vSplitDamagePct
.begin(), next
; i
!= vSplitDamagePct
.end() && RemainingDamage
>= 0; i
= next
)
1897 // check damage school mask
1898 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
)==0)
1901 // Damage can be splitted only if aura has an alive caster
1902 Unit
*caster
= (*i
)->GetCaster();
1903 if(!caster
|| caster
== pVictim
|| !caster
->IsInWorld() || !caster
->isAlive())
1906 int32 splitted
= int32(RemainingDamage
* (*i
)->GetModifier()->m_amount
/ 100.0f
);
1908 RemainingDamage
-= splitted
;
1910 SendSpellNonMeleeDamageLog(caster
, (*i
)->GetSpellProto()->Id
, splitted
, schoolMask
, 0, 0, false, 0, false);
1912 CleanDamage cleanDamage
= CleanDamage(splitted
, BASE_ATTACK
, MELEE_HIT_NORMAL
);
1913 DealDamage(caster
, splitted
, &cleanDamage
, DIRECT_DAMAGE
, schoolMask
, (*i
)->GetSpellProto(), false);
1917 *absorb
= damage
- RemainingDamage
- *resist
;
1920 void Unit::AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
, bool extra
)
1922 if(hasUnitState(UNIT_STAT_CONFUSED
| UNIT_STAT_STUNNED
| UNIT_STAT_FLEEING
) || HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) )
1925 if (!pVictim
->isAlive())
1928 if(IsNonMeleeSpellCasted(false))
1932 if (attType
== BASE_ATTACK
)
1933 hitInfo
= HITINFO_NORMALSWING2
;
1934 else if (attType
== OFF_ATTACK
)
1935 hitInfo
= HITINFO_LEFTSWING
;
1937 return; // ignore ranged case
1939 uint32 extraAttacks
= m_extraAttacks
;
1941 // melee attack spell casted at main hand attack only
1942 if (attType
== BASE_ATTACK
&& m_currentSpells
[CURRENT_MELEE_SPELL
])
1944 m_currentSpells
[CURRENT_MELEE_SPELL
]->cast();
1946 // not recent extra attack only at any non extra attack (melee spell case)
1947 if(!extra
&& extraAttacks
)
1949 while(m_extraAttacks
)
1951 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
1952 if(m_extraAttacks
> 0)
1957 // if damage pVictim call AI reaction
1958 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
1959 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
1964 CalcDamageInfo damageInfo
;
1965 CalculateMeleeDamage(pVictim
, 0, &damageInfo
, attType
);
1966 // Send log damage message to client
1967 SendAttackStateUpdate(&damageInfo
);
1968 ProcDamageAndSpell(damageInfo
.target
, damageInfo
.procAttacker
, damageInfo
.procVictim
, damageInfo
.procEx
, damageInfo
.damage
, damageInfo
.attackType
);
1969 DealMeleeDamage(&damageInfo
,true);
1971 if (GetTypeId() == TYPEID_PLAYER
)
1972 DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
1973 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
1975 DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.",
1976 GetGUIDLow(), pVictim
->GetGUIDLow(), pVictim
->GetTypeId(), damageInfo
.damage
, damageInfo
.absorb
, damageInfo
.blocked_amount
, damageInfo
.resist
);
1978 // extra attack only at any non extra attack (normal case)
1979 if(!extra
&& extraAttacks
)
1981 while(m_extraAttacks
)
1983 AttackerStateUpdate(pVictim
, BASE_ATTACK
, true);
1984 if(m_extraAttacks
> 0)
1989 // if damage pVictim call AI reaction
1990 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->AI())
1991 ((Creature
*)pVictim
)->AI()->AttackedBy(this);
1994 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst(const Unit
*pVictim
, WeaponAttackType attType
) const
1996 // This is only wrapper
1998 // Miss chance based on melee
1999 float miss_chance
= MeleeMissChanceCalc(pVictim
, attType
);
2001 // Critical hit chance
2002 float crit_chance
= GetUnitCriticalChance(attType
, pVictim
);
2004 // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case)
2005 float dodge_chance
= pVictim
->GetUnitDodgeChance();
2006 float block_chance
= pVictim
->GetUnitBlockChance();
2007 float parry_chance
= pVictim
->GetUnitParryChance();
2009 // Useful if want to specify crit & miss chances for melee, else it could be removed
2010 DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance
,crit_chance
,dodge_chance
,parry_chance
,block_chance
);
2012 return RollMeleeOutcomeAgainst(pVictim
, attType
, int32(crit_chance
*100), int32(miss_chance
*100), int32(dodge_chance
*100),int32(parry_chance
*100),int32(block_chance
*100));
2015 MeleeHitOutcome
Unit::RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const
2017 if(pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2018 return MELEE_HIT_EVADE
;
2020 int32 attackerMaxSkillValueForLevel
= GetMaxSkillValueForLevel(pVictim
);
2021 int32 victimMaxSkillValueForLevel
= pVictim
->GetMaxSkillValueForLevel(this);
2023 int32 attackerWeaponSkill
= GetWeaponSkillValue(attType
,pVictim
);
2024 int32 victimDefenseSkill
= pVictim
->GetDefenseSkillValue(this);
2026 // bonus from skills is 0.04%
2027 int32 skillBonus
= 4 * ( attackerWeaponSkill
- victimMaxSkillValueForLevel
);
2028 int32 sum
= 0, tmp
= 0;
2029 int32 roll
= urand (0, 10000);
2031 DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus
);
2032 DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d",
2033 roll
, miss_chance
, dodge_chance
, parry_chance
, block_chance
, crit_chance
);
2037 if (tmp
> 0 && roll
< (sum
+= tmp
))
2039 DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS");
2040 return MELEE_HIT_MISS
;
2043 // always crit against a sitting target (except 0 crit chance)
2044 if( pVictim
->GetTypeId() == TYPEID_PLAYER
&& crit_chance
> 0 && !pVictim
->IsStandState() )
2046 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)");
2047 return MELEE_HIT_CRIT
;
2052 // only players can't dodge if attacker is behind
2053 if (pVictim
->GetTypeId() == TYPEID_PLAYER
&& !pVictim
->HasInArc(M_PI
,this))
2055 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player.");
2059 // Reduce dodge chance by attacker expertise rating
2060 if (GetTypeId() == TYPEID_PLAYER
)
2061 dodge_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2063 // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2064 dodge_chance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
);
2067 if ( (tmp
> 0) // check if unit _can_ dodge
2068 && ((tmp
-= skillBonus
) > 0)
2069 && roll
< (sum
+= tmp
))
2071 DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum
-tmp
, sum
);
2072 return MELEE_HIT_DODGE
;
2076 // parry & block chances
2078 // check if attack comes from behind, nobody can parry or block if attacker is behind
2079 if (!pVictim
->HasInArc(M_PI
,this))
2081 DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind.");
2085 // Reduce parry chance by attacker expertise rating
2086 if (GetTypeId() == TYPEID_PLAYER
)
2087 parry_chance
-= int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
)*100);
2089 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_PARRY
) )
2091 int32 tmp
= int32(parry_chance
);
2092 if ( (tmp
> 0) // check if unit _can_ parry
2093 && ((tmp
-= skillBonus
) > 0)
2094 && (roll
< (sum
+= tmp
)))
2096 DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum
-tmp
, sum
);
2097 return MELEE_HIT_PARRY
;
2101 if(pVictim
->GetTypeId()==TYPEID_PLAYER
|| !(((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
) )
2104 if ( (tmp
> 0) // check if unit _can_ block
2105 && ((tmp
-= skillBonus
) > 0)
2106 && (roll
< (sum
+= tmp
)))
2108 DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum
-tmp
, sum
);
2109 return MELEE_HIT_BLOCK
;
2117 if (tmp
> 0 && roll
< (sum
+= tmp
))
2119 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum
-tmp
, sum
);
2120 return MELEE_HIT_CRIT
;
2123 // 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)
2124 if( attType
!= RANGED_ATTACK
&&
2125 (GetTypeId() == TYPEID_PLAYER
|| ((Creature
*)this)->isPet()) &&
2126 pVictim
->GetTypeId() != TYPEID_PLAYER
&& !((Creature
*)pVictim
)->isPet() &&
2127 getLevel() < pVictim
->getLevelForTarget(this) )
2129 // cap possible value (with bonuses > max skill)
2130 int32 skill
= attackerWeaponSkill
;
2131 int32 maxskill
= attackerMaxSkillValueForLevel
;
2132 skill
= (skill
> maxskill
) ? maxskill
: skill
;
2134 tmp
= (10 + (victimDefenseSkill
- skill
)) * 100;
2135 tmp
= tmp
> 4000 ? 4000 : tmp
;
2136 if (roll
< (sum
+= tmp
))
2138 DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum
-4000, sum
);
2139 return MELEE_HIT_GLANCING
;
2143 // mobs can score crushing blows if they're 4 or more levels above victim
2144 if (getLevelForTarget(pVictim
) >= pVictim
->getLevelForTarget(this) + 4 &&
2145 // can be from by creature (if can) or from controlled player that considered as creature
2146 (GetTypeId()!=TYPEID_PLAYER
&& !((Creature
*)this)->isPet() &&
2147 !(((Creature
*)this)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_CRUSH
) ||
2148 GetTypeId()==TYPEID_PLAYER
&& GetCharmerOrOwnerGUID()))
2150 // when their weapon skill is 15 or more above victim's defense skill
2151 tmp
= victimDefenseSkill
;
2152 int32 tmpmax
= victimMaxSkillValueForLevel
;
2153 // having defense above your maximum (from items, talents etc.) has no effect
2154 tmp
= tmp
> tmpmax
? tmpmax
: tmp
;
2155 // tmp = mob's level * 5 - player's current defense skill
2156 tmp
= attackerMaxSkillValueForLevel
- tmp
;
2159 // add 2% chance per lacking skill point, min. is 15%
2160 tmp
= tmp
* 200 - 1500;
2161 if (roll
< (sum
+= tmp
))
2163 DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum
-tmp
, sum
);
2164 return MELEE_HIT_CRUSHING
;
2169 DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL");
2170 return MELEE_HIT_NORMAL
;
2173 uint32
Unit::CalculateDamage (WeaponAttackType attType
, bool normalized
)
2175 float min_damage
, max_damage
;
2177 if (normalized
&& GetTypeId()==TYPEID_PLAYER
)
2178 ((Player
*)this)->CalculateMinMaxDamage(attType
,normalized
,min_damage
, max_damage
);
2184 min_damage
= GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
);
2185 max_damage
= GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
);
2188 min_damage
= GetFloatValue(UNIT_FIELD_MINDAMAGE
);
2189 max_damage
= GetFloatValue(UNIT_FIELD_MAXDAMAGE
);
2192 min_damage
= GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
);
2193 max_damage
= GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
);
2195 // Just for good manner
2203 if (min_damage
> max_damage
)
2205 std::swap(min_damage
,max_damage
);
2208 if(max_damage
== 0.0f
)
2211 return urand((uint32
)min_damage
, (uint32
)max_damage
);
2214 float Unit::CalculateLevelPenalty(SpellEntry
const* spellProto
) const
2216 if(spellProto
->spellLevel
<= 0)
2219 float LvlPenalty
= 0.0f
;
2221 if(spellProto
->spellLevel
< 20)
2222 LvlPenalty
= 20.0f
- spellProto
->spellLevel
* 3.75f
;
2223 float LvlFactor
= (float(spellProto
->spellLevel
) + 6.0f
) / float(getLevel());
2224 if(LvlFactor
> 1.0f
)
2227 return (100.0f
- LvlPenalty
) * LvlFactor
/ 100.0f
;
2230 void Unit::SendAttackStart(Unit
* pVictim
)
2232 WorldPacket
data( SMSG_ATTACKSTART
, 16 );
2233 data
<< uint64(GetGUID());
2234 data
<< uint64(pVictim
->GetGUID());
2236 SendMessageToSet(&data
, true);
2237 DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" );
2240 void Unit::SendAttackStop(Unit
* victim
)
2245 WorldPacket
data( SMSG_ATTACKSTOP
, (4+16) ); // we guess size
2246 data
.append(GetPackGUID());
2247 data
.append(victim
->GetPackGUID()); // can be 0x00...
2248 data
<< uint32(0); // can be 0x1
2249 SendMessageToSet(&data
, true);
2250 sLog
.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER
? "player" : "creature"), GetGUIDLow(), (victim
->GetTypeId()==TYPEID_PLAYER
? "player" : "creature"),victim
->GetGUIDLow());
2252 /*if(victim->GetTypeId() == TYPEID_UNIT)
2253 ((Creature*)victim)->AI().EnterEvadeMode(this);*/
2256 bool Unit::isSpellBlocked(Unit
*pVictim
, SpellEntry
const *spellProto
, WeaponAttackType attackType
)
2258 if (pVictim
->HasInArc(M_PI
,this))
2260 /* Currently not exist spells with ignore block
2261 // Ignore combat result aura (parry/dodge check on prepare)
2262 AuraList const& ignore = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT);
2263 for(AuraList::const_iterator i = ignore.begin(); i != ignore.end(); ++i)
2265 if (!(*i)->isAffectedOnSpell(spellProto))
2267 if ((*i)->GetModifier()->m_miscvalue == )
2272 // Check creatures flags_extra for disable block
2273 if(pVictim
->GetTypeId()==TYPEID_UNIT
&&
2274 ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_BLOCK
)
2277 float blockChance
= pVictim
->GetUnitBlockChance();
2278 blockChance
+= (int32(GetWeaponSkillValue(attackType
)) - int32(pVictim
->GetMaxSkillValueForLevel()))*0.04f
;
2279 if (roll_chance_f(blockChance
))
2285 // Melee based spells can be miss, parry or dodge on this step
2286 // Crit or block - determined on damage calculation phase! (and can be both in some time)
2287 float Unit::MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
)
2289 // Calculate hit chance (more correct for chance mod)
2292 // PvP - PvE melee chances
2293 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2294 int32 leveldif
= pVictim
->getLevelForTarget(this) - getLevelForTarget(pVictim
);
2296 HitChance
= 95 - leveldif
;
2298 HitChance
= 93 - (leveldif
- 2) * lchance
;
2300 // Hit chance depends from victim auras
2301 if(attType
== RANGED_ATTACK
)
2302 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2304 HitChance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2306 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2307 if(Player
*modOwner
= GetSpellModOwner())
2308 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, HitChance
);
2311 float miss_chance
= 100.0f
- HitChance
;
2313 // Bonuses from attacker aura and ratings
2314 if (attType
== RANGED_ATTACK
)
2315 miss_chance
-= m_modRangedHitChance
;
2317 miss_chance
-= m_modMeleeHitChance
;
2319 // bonus from skills is 0.04%
2320 miss_chance
-= skillDiff
* 0.04f
;
2322 // Limit miss chance from 0 to 60%
2323 if (miss_chance
< 0.0f
)
2325 if (miss_chance
> 60.0f
)
2330 // Melee based spells hit result calculations
2331 SpellMissInfo
Unit::MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2333 WeaponAttackType attType
= BASE_ATTACK
;
2335 if (spell
->DmgClass
== SPELL_DAMAGE_CLASS_RANGED
)
2336 attType
= RANGED_ATTACK
;
2338 // bonus from skills is 0.04% per skill Diff
2339 int32 attackerWeaponSkill
= int32(GetWeaponSkillValue(attType
,pVictim
));
2340 int32 skillDiff
= attackerWeaponSkill
- int32(pVictim
->GetMaxSkillValueForLevel(this));
2341 int32 fullSkillDiff
= attackerWeaponSkill
- int32(pVictim
->GetDefenseSkillValue(this));
2343 uint32 roll
= urand (0, 10000);
2345 uint32 missChance
= uint32(MeleeSpellMissChance(pVictim
, attType
, fullSkillDiff
, spell
)*100.0f
);
2347 uint32 tmp
= missChance
;
2349 return SPELL_MISS_MISS
;
2351 // Chance resist mechanic (select max value from every mechanic spell effect)
2352 int32 resist_mech
= 0;
2353 // Get effects mechanic and chance
2354 for(int eff
= 0; eff
< 3; ++eff
)
2356 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2359 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2360 if (resist_mech
< temp
*100)
2361 resist_mech
= temp
*100;
2367 return SPELL_MISS_RESIST
;
2369 bool canDodge
= true;
2370 bool canParry
= true;
2372 // Same spells cannot be parry/dodge
2373 if (spell
->Attributes
& SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK
)
2374 return SPELL_MISS_NONE
;
2376 // Ranged attack cannot be parry/dodge only deflect
2377 if (attType
== RANGED_ATTACK
)
2380 if (pVictim
->HasInArc(M_PI
,this))
2382 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2383 tmp
+=deflect_chance
;
2385 return SPELL_MISS_DEFLECT
;
2387 return SPELL_MISS_NONE
;
2390 // Check for attack from behind
2391 if (!pVictim
->HasInArc(M_PI
,this))
2393 // Can`t dodge from behind in PvP (but its possible in PvE)
2394 if (GetTypeId() == TYPEID_PLAYER
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
2399 // Check creatures flags_extra for disable parry
2400 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
2402 uint32 flagEx
= ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
;
2403 if( flagEx
& CREATURE_FLAG_EXTRA_NO_PARRY
)
2406 // Ignore combat result aura
2407 AuraList
const& ignore
= GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT
);
2408 for(AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
2410 if (!(*i
)->isAffectedOnSpell(spell
))
2412 switch((*i
)->GetModifier()->m_miscvalue
)
2414 case MELEE_HIT_DODGE
: canDodge
= false; break;
2415 case MELEE_HIT_BLOCK
: break; // Block check in hit step
2416 case MELEE_HIT_PARRY
: canParry
= false; break;
2418 DEBUG_LOG("Spell %u SPELL_AURA_IGNORE_COMBAT_RESULT have unhandled state %d", (*i
)->GetId(), (*i
)->GetModifier()->m_miscvalue
);
2426 int32 dodgeChance
= int32(pVictim
->GetUnitDodgeChance()*100.0f
) - skillDiff
* 4;
2427 // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
2428 dodgeChance
+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
, VICTIMSTATE_DODGE
)*100;
2429 // Reduce dodge chance by attacker expertise rating
2430 if (GetTypeId() == TYPEID_PLAYER
)
2431 dodgeChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2432 if (dodgeChance
< 0)
2437 return SPELL_MISS_DODGE
;
2443 int32 parryChance
= int32(pVictim
->GetUnitParryChance()*100.0f
) - skillDiff
* 4;
2444 // Reduce parry chance by attacker expertise rating
2445 if (GetTypeId() == TYPEID_PLAYER
)
2446 parryChance
-=int32(((Player
*)this)->GetExpertiseDodgeOrParryReduction(attType
) * 100.0f
);
2447 if (parryChance
< 0)
2452 return SPELL_MISS_PARRY
;
2455 return SPELL_MISS_NONE
;
2458 // TODO need use unit spell resistances in calculations
2459 SpellMissInfo
Unit::MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
)
2461 // Can`t miss on dead target (on skinning for example)
2462 if (!pVictim
->isAlive())
2463 return SPELL_MISS_NONE
;
2465 SpellSchoolMask schoolMask
= GetSpellSchoolMask(spell
);
2466 // PvP - PvE spell misschances per leveldif > 2
2467 int32 lchance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 7 : 11;
2468 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2470 // Base hit chance from attacker and victim levels
2473 modHitChance
= 96 - leveldif
;
2475 modHitChance
= 94 - (leveldif
- 2) * lchance
;
2477 // Spellmod from SPELLMOD_RESIST_MISS_CHANCE
2478 if(Player
*modOwner
= GetSpellModOwner())
2479 modOwner
->ApplySpellMod(spell
->Id
, SPELLMOD_RESIST_MISS_CHANCE
, modHitChance
);
2480 // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras
2481 modHitChance
+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT
, schoolMask
);
2482 // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras
2483 modHitChance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE
, schoolMask
);
2484 // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura
2485 if (IsAreaOfEffectSpell(spell
))
2486 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE
);
2487 // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST
2488 if (IsDispelSpell(spell
))
2489 modHitChance
-=pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST
);
2490 // Chance resist mechanic (select max value from every mechanic spell effect)
2491 int32 resist_mech
= 0;
2492 // Get effects mechanic and chance
2493 for(int eff
= 0; eff
< 3; ++eff
)
2495 int32 effect_mech
= GetEffectMechanic(spell
, eff
);
2498 int32 temp
= pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE
, effect_mech
);
2499 if (resist_mech
< temp
)
2504 modHitChance
-=resist_mech
;
2506 // Chance resist debuff
2507 modHitChance
-=pVictim
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE
, int32(spell
->Dispel
));
2509 int32 HitChance
= modHitChance
* 100;
2510 // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
2511 HitChance
+= int32(m_modSpellHitChance
*100.0f
);
2513 // Decrease hit chance from victim rating bonus
2514 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2515 HitChance
-= int32(((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL
)*100.0f
);
2517 if (HitChance
< 100) HitChance
= 100;
2518 if (HitChance
> 10000) HitChance
= 10000;
2520 int32 tmp
= 10000 - HitChance
;
2522 uint32 rand
= urand(0,10000);
2525 return SPELL_MISS_RESIST
;
2527 // cast by caster in front of victim
2528 if (pVictim
->HasInArc(M_PI
,this))
2530 int32 deflect_chance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS
)*100;
2531 tmp
+=deflect_chance
;
2533 return SPELL_MISS_DEFLECT
;
2536 return SPELL_MISS_NONE
;
2539 // Calculate spell hit result can be:
2540 // Every spell can: Evade/Immune/Reflect/Sucesful hit
2541 // For melee based spells:
2547 SpellMissInfo
Unit::SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool CanReflect
)
2549 // Return evade for units in evade mode
2550 if (pVictim
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)pVictim
)->IsInEvadeMode())
2551 return SPELL_MISS_EVADE
;
2554 if (pVictim
->IsImmunedToSpell(spell
))
2555 return SPELL_MISS_IMMUNE
;
2557 // All positive spells can`t miss
2558 // TODO: client not show miss log for this spells - so need find info for this in dbc and use it!
2559 if (IsPositiveSpell(spell
->Id
))
2560 return SPELL_MISS_NONE
;
2563 if (pVictim
->IsImmunedToDamage(GetSpellSchoolMask(spell
)))
2564 return SPELL_MISS_IMMUNE
;
2566 // Try victim reflect spell
2569 int32 reflectchance
= pVictim
->GetTotalAuraModifier(SPELL_AURA_REFLECT_SPELLS
);
2570 Unit::AuraList
const& mReflectSpellsSchool
= pVictim
->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL
);
2571 for(Unit::AuraList::const_iterator i
= mReflectSpellsSchool
.begin(); i
!= mReflectSpellsSchool
.end(); ++i
)
2572 if((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spell
))
2573 reflectchance
+= (*i
)->GetModifier()->m_amount
;
2574 if (reflectchance
> 0 && roll_chance_i(reflectchance
))
2576 // Start triggers for remove charges if need (trigger only for victim, and mark as active spell)
2577 ProcDamageAndSpell(pVictim
, PROC_FLAG_NONE
, PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
, PROC_EX_REFLECT
, 1, BASE_ATTACK
, spell
);
2578 return SPELL_MISS_REFLECT
;
2582 switch (spell
->DmgClass
)
2584 case SPELL_DAMAGE_CLASS_RANGED
:
2585 case SPELL_DAMAGE_CLASS_MELEE
:
2586 return MeleeSpellHitResult(pVictim
, spell
);
2587 case SPELL_DAMAGE_CLASS_NONE
:
2588 case SPELL_DAMAGE_CLASS_MAGIC
:
2589 return MagicSpellHitResult(pVictim
, spell
);
2591 return SPELL_MISS_NONE
;
2594 float Unit::MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const
2599 // Base misschance 5%
2600 float misschance
= 5.0f
;
2602 // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
2603 if (haveOffhandWeapon() && attType
!= RANGED_ATTACK
)
2605 bool isNormal
= false;
2606 for (uint32 i
= CURRENT_FIRST_NON_MELEE_SPELL
; i
< CURRENT_MAX_SPELL
; i
++)
2608 if( m_currentSpells
[i
] && (GetSpellSchoolMask(m_currentSpells
[i
]->m_spellInfo
) & SPELL_SCHOOL_MASK_NORMAL
) )
2614 if (isNormal
|| m_currentSpells
[CURRENT_MELEE_SPELL
])
2624 // PvP : PvE melee misschances per leveldif > 2
2625 int32 chance
= pVictim
->GetTypeId() == TYPEID_PLAYER
? 5 : 7;
2627 int32 leveldif
= int32(pVictim
->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim
));
2631 // Hit chance from attacker based on ratings and auras
2632 float m_modHitChance
;
2633 if (attType
== RANGED_ATTACK
)
2634 m_modHitChance
= m_modRangedHitChance
;
2636 m_modHitChance
= m_modMeleeHitChance
;
2639 misschance
+= (leveldif
- m_modHitChance
);
2641 misschance
+= ((leveldif
- 2) * chance
- m_modHitChance
);
2643 // Hit chance for victim based on ratings
2644 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2646 if (attType
== RANGED_ATTACK
)
2647 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED
);
2649 misschance
+= ((Player
*)pVictim
)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE
);
2652 // Modify miss chance by victim auras
2653 if(attType
== RANGED_ATTACK
)
2654 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE
);
2656 misschance
-= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
);
2658 // Modify miss chance from skill difference ( bonus from skills is 0.04% )
2659 int32 skillBonus
= int32(GetWeaponSkillValue(attType
,pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this));
2660 misschance
-= skillBonus
* 0.04f
;
2662 // Limit miss chance from 0 to 60%
2663 if ( misschance
< 0.0f
)
2665 if ( misschance
> 60.0f
)
2671 uint32
Unit::GetDefenseSkillValue(Unit
const* target
) const
2673 if(GetTypeId() == TYPEID_PLAYER
)
2675 // in PvP use full skill instead current skill value
2676 uint32 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
2677 ? ((Player
*)this)->GetMaxSkillValue(SKILL_DEFENSE
)
2678 : ((Player
*)this)->GetSkillValue(SKILL_DEFENSE
);
2679 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL
));
2683 return GetUnitMeleeSkill(target
);
2686 float Unit::GetUnitDodgeChance() const
2688 if(hasUnitState(UNIT_STAT_STUNNED
))
2690 if( GetTypeId() == TYPEID_PLAYER
)
2691 return GetFloatValue(PLAYER_DODGE_PERCENTAGE
);
2694 if(((Creature
const*)this)->isTotem())
2699 dodge
+= GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT
);
2700 return dodge
> 0.0f
? dodge
: 0.0f
;
2705 float Unit::GetUnitParryChance() const
2707 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
2710 float chance
= 0.0f
;
2712 if(GetTypeId() == TYPEID_PLAYER
)
2714 Player
const* player
= (Player
const*)this;
2715 if(player
->CanParry() )
2717 Item
*tmpitem
= player
->GetWeaponForAttack(BASE_ATTACK
,true);
2719 tmpitem
= player
->GetWeaponForAttack(OFF_ATTACK
,true);
2722 chance
= GetFloatValue(PLAYER_PARRY_PERCENTAGE
);
2725 else if(GetTypeId() == TYPEID_UNIT
)
2727 if(GetCreatureType() == CREATURE_TYPE_HUMANOID
)
2730 chance
+= GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT
);
2734 return chance
> 0.0f
? chance
: 0.0f
;
2737 float Unit::GetUnitBlockChance() const
2739 if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED
))
2742 if(GetTypeId() == TYPEID_PLAYER
)
2744 Player
const* player
= (Player
const*)this;
2745 if(player
->CanBlock() )
2747 Item
*tmpitem
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
2748 if(tmpitem
&& !tmpitem
->IsBroken() && tmpitem
->GetProto()->Block
)
2749 return GetFloatValue(PLAYER_BLOCK_PERCENTAGE
);
2751 // is player but has no block ability or no not broken shield equipped
2756 if(((Creature
const*)this)->isTotem())
2761 block
+= GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT
);
2762 return block
> 0.0f
? block
: 0.0f
;
2767 float Unit::GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const
2771 if(GetTypeId() == TYPEID_PLAYER
)
2776 crit
= GetFloatValue( PLAYER_CRIT_PERCENTAGE
);
2779 crit
= GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE
);
2782 crit
= GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE
);
2784 // Just for good manner
2793 crit
+= GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT
);
2797 if(attackType
== RANGED_ATTACK
)
2798 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE
);
2800 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE
);
2802 crit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
2804 // reduce crit chance from Rating for players
2805 if (pVictim
->GetTypeId()==TYPEID_PLAYER
)
2807 if (attackType
==RANGED_ATTACK
)
2808 crit
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_RANGED
);
2810 crit
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
);
2813 // Apply crit chance from defence skill
2814 crit
+= (int32(GetMaxSkillValueForLevel(pVictim
)) - int32(pVictim
->GetDefenseSkillValue(this))) * 0.04f
;
2821 uint32
Unit::GetWeaponSkillValue (WeaponAttackType attType
, Unit
const* target
) const
2824 if(GetTypeId() == TYPEID_PLAYER
)
2826 Item
* item
= ((Player
*)this)->GetWeaponForAttack(attType
,true);
2828 // feral or unarmed skill only for base attack
2829 if(attType
!= BASE_ATTACK
&& !item
)
2833 return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact
2835 // weapon skill or (unarmed for base attack)
2836 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
2838 // in PvP use full skill instead current skill value
2839 value
= (target
&& target
->GetTypeId() == TYPEID_PLAYER
)
2840 ? ((Player
*)this)->GetMaxSkillValue(skill
)
2841 : ((Player
*)this)->GetSkillValue(skill
);
2842 // Modify value from ratings
2843 value
+= uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL
));
2846 case BASE_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND
));break;
2847 case OFF_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND
));break;
2848 case RANGED_ATTACK
: value
+=uint32(((Player
*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED
));break;
2852 value
= GetUnitMeleeSkill(target
);
2856 void Unit::_UpdateSpells( uint32 time
)
2858 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
])
2859 _UpdateAutoRepeatSpell();
2861 // remove finished spells from current pointers
2862 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
2864 if (m_currentSpells
[i
] && m_currentSpells
[i
]->getState() == SPELL_STATE_FINISHED
)
2866 m_currentSpells
[i
]->SetReferencedFromCurrent(false);
2867 m_currentSpells
[i
] = NULL
; // remove pointer
2871 // TODO: Find a better way to prevent crash when multiple auras are removed.
2873 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
2875 (*i
).second
->SetUpdated(false);
2877 for (AuraMap::iterator i
= m_Auras
.begin(), next
; i
!= m_Auras
.end(); i
= next
)
2883 // prevent double update
2884 if ((*i
).second
->IsUpdated())
2886 (*i
).second
->SetUpdated(true);
2887 (*i
).second
->Update( time
);
2888 // several auras can be deleted due to update
2891 if (m_Auras
.empty()) break;
2892 next
= m_Auras
.begin();
2898 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end();)
2902 if ( !(*i
).second
->GetAuraDuration() && !((*i
).second
->IsPermanent() || ((*i
).second
->IsPassive())) )
2917 if(!m_gameObj
.empty())
2919 GameObjectList::iterator ite1
, dnext1
;
2920 for (ite1
= m_gameObj
.begin(); ite1
!= m_gameObj
.end(); ite1
= dnext1
)
2923 //(*i)->Update( difftime );
2924 if( !(*ite1
)->isSpawned() )
2926 (*ite1
)->SetOwnerGUID(0);
2927 (*ite1
)->SetRespawnTime(0);
2929 dnext1
= m_gameObj
.erase(ite1
);
2937 void Unit::_UpdateAutoRepeatSpell()
2939 //check "realtime" interrupts
2940 if ( (GetTypeId() == TYPEID_PLAYER
&& ((Player
*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) )
2942 // cancel wand shoot
2943 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
2944 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
2945 m_AutoRepeatFirstCast
= true;
2950 if ( m_AutoRepeatFirstCast
&& getAttackTimer(RANGED_ATTACK
) < 500 )
2951 setAttackTimer(RANGED_ATTACK
,500);
2952 m_AutoRepeatFirstCast
= false;
2955 if (isAttackReady(RANGED_ATTACK
))
2957 // Check if able to cast
2958 if(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->CheckCast(true) != SPELL_CAST_OK
)
2960 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
2965 Spell
* spell
= new Spell(this, m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
, true, 0);
2966 spell
->prepare(&(m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_targets
));
2968 // all went good, reset attack
2969 resetAttackTimer(RANGED_ATTACK
);
2973 void Unit::SetCurrentCastedSpell( Spell
* pSpell
)
2975 assert(pSpell
); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
2977 uint32 CSpellType
= pSpell
->GetCurrentContainer();
2979 if (pSpell
== m_currentSpells
[CSpellType
]) return; // avoid breaking self
2981 // break same type spell if it is not delayed
2982 InterruptSpell(CSpellType
,false);
2984 // special breakage effects:
2987 case CURRENT_GENERIC_SPELL
:
2989 // generic spells always break channeled not delayed spells
2990 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
2992 // autorepeat breaking
2993 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
2995 // break autorepeat if not Auto Shot
2996 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
2997 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
2998 m_AutoRepeatFirstCast
= true;
3002 case CURRENT_CHANNELED_SPELL
:
3004 // channel spells always break generic non-delayed and any channeled spells
3005 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3006 InterruptSpell(CURRENT_CHANNELED_SPELL
);
3008 // it also does break autorepeat if not Auto Shot
3009 if ( m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] &&
3010 m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3011 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
);
3014 case CURRENT_AUTOREPEAT_SPELL
:
3016 // only Auto Shoot does not break anything
3017 if (pSpell
->m_spellInfo
->Id
!= SPELL_ID_AUTOSHOT
)
3019 // generic autorepeats break generic non-delayed and channeled non-delayed spells
3020 InterruptSpell(CURRENT_GENERIC_SPELL
,false);
3021 InterruptSpell(CURRENT_CHANNELED_SPELL
,false);
3023 // special action: set first cast flag
3024 m_AutoRepeatFirstCast
= true;
3029 // other spell types don't break anything now
3033 // current spell (if it is still here) may be safely deleted now
3034 if (m_currentSpells
[CSpellType
])
3035 m_currentSpells
[CSpellType
]->SetReferencedFromCurrent(false);
3037 // set new current spell
3038 m_currentSpells
[CSpellType
] = pSpell
;
3039 pSpell
->SetReferencedFromCurrent(true);
3042 void Unit::InterruptSpell(uint32 spellType
, bool withDelayed
)
3044 assert(spellType
< CURRENT_MAX_SPELL
);
3046 if (m_currentSpells
[spellType
] && (withDelayed
|| m_currentSpells
[spellType
]->getState() != SPELL_STATE_DELAYED
) )
3048 // send autorepeat cancel message for autorepeat spells
3049 if (spellType
== CURRENT_AUTOREPEAT_SPELL
)
3051 if(GetTypeId()==TYPEID_PLAYER
)
3052 ((Player
*)this)->SendAutoRepeatCancel();
3055 if (m_currentSpells
[spellType
]->getState() != SPELL_STATE_FINISHED
)
3056 m_currentSpells
[spellType
]->cancel();
3058 // cancel can interrupt spell already (caster cancel ->target aura remove -> caster iterrupt)
3059 if (m_currentSpells
[spellType
])
3061 m_currentSpells
[spellType
]->SetReferencedFromCurrent(false);
3062 m_currentSpells
[spellType
] = NULL
;
3067 bool Unit::IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
, bool skipAutorepeat
) const
3069 // We don't do loop here to explicitly show that melee spell is excluded.
3070 // Maybe later some special spells will be excluded too.
3072 // generic spells are casted when they are not finished and not delayed
3073 if ( m_currentSpells
[CURRENT_GENERIC_SPELL
] &&
3074 (m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_FINISHED
) &&
3075 (withDelayed
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->getState() != SPELL_STATE_DELAYED
) )
3078 // channeled spells may be delayed, but they are still considered casted
3079 else if ( !skipChanneled
&& m_currentSpells
[CURRENT_CHANNELED_SPELL
] &&
3080 (m_currentSpells
[CURRENT_CHANNELED_SPELL
]->getState() != SPELL_STATE_FINISHED
) )
3083 // autorepeat spells may be finished or delayed, but they are still considered casted
3084 else if ( !skipAutorepeat
&& m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] )
3090 void Unit::InterruptNonMeleeSpells(bool withDelayed
, uint32 spell_id
)
3092 // generic spells are interrupted if they are not finished or delayed
3093 if (m_currentSpells
[CURRENT_GENERIC_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Id
==spell_id
))
3094 InterruptSpell(CURRENT_GENERIC_SPELL
,withDelayed
);
3096 // autorepeat spells are interrupted if they are not finished or delayed
3097 if (m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_AUTOREPEAT_SPELL
]->m_spellInfo
->Id
==spell_id
))
3098 InterruptSpell(CURRENT_AUTOREPEAT_SPELL
,withDelayed
);
3100 // channeled spells are interrupted if they are not finished, even if they are delayed
3101 if (m_currentSpells
[CURRENT_CHANNELED_SPELL
] && (!spell_id
|| m_currentSpells
[CURRENT_CHANNELED_SPELL
]->m_spellInfo
->Id
==spell_id
))
3102 InterruptSpell(CURRENT_CHANNELED_SPELL
,true);
3105 Spell
* Unit::FindCurrentSpellBySpellId(uint32 spell_id
) const
3107 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
3108 if(m_currentSpells
[i
] && m_currentSpells
[i
]->m_spellInfo
->Id
==spell_id
)
3109 return m_currentSpells
[i
];
3113 bool Unit::isInFront(Unit
const* target
, float distance
, float arc
) const
3115 return IsWithinDistInMap(target
, distance
) && HasInArc( arc
, target
);
3118 void Unit::SetInFront(Unit
const* target
)
3120 SetOrientation(GetAngle(target
));
3123 bool Unit::isInBack(Unit
const* target
, float distance
, float arc
) const
3125 return IsWithinDistInMap(target
, distance
) && !HasInArc( 2 * M_PI
- arc
, target
);
3128 bool Unit::isInAccessablePlaceFor(Creature
const* c
) const
3131 return c
->canSwim();
3133 return c
->canWalk() || c
->canFly();
3136 bool Unit::IsInWater() const
3138 return MapManager::Instance().GetBaseMap(GetMapId())->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ());
3141 bool Unit::IsUnderWater() const
3143 return MapManager::Instance().GetBaseMap(GetMapId())->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ());
3146 void Unit::DeMorph()
3148 SetDisplayId(GetNativeDisplayId());
3151 int32
Unit::GetTotalAuraModifier(AuraType auratype
) const
3155 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3156 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3157 modifier
+= (*i
)->GetModifier()->m_amount
;
3162 float Unit::GetTotalAuraMultiplier(AuraType auratype
) const
3164 float multiplier
= 1.0f
;
3166 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3167 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3168 multiplier
*= (100.0f
+ (*i
)->GetModifier()->m_amount
)/100.0f
;
3173 int32
Unit::GetMaxPositiveAuraModifier(AuraType auratype
) const
3177 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3178 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3179 if ((*i
)->GetModifier()->m_amount
> modifier
)
3180 modifier
= (*i
)->GetModifier()->m_amount
;
3185 int32
Unit::GetMaxNegativeAuraModifier(AuraType auratype
) const
3189 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3190 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3191 if ((*i
)->GetModifier()->m_amount
< modifier
)
3192 modifier
= (*i
)->GetModifier()->m_amount
;
3197 int32
Unit::GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3201 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3202 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3204 Modifier
* mod
= (*i
)->GetModifier();
3205 if (mod
->m_miscvalue
& misc_mask
)
3206 modifier
+= mod
->m_amount
;
3211 float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3213 float multiplier
= 1.0f
;
3215 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3216 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3218 Modifier
* mod
= (*i
)->GetModifier();
3219 if (mod
->m_miscvalue
& misc_mask
)
3220 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3225 int32
Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3229 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3230 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3232 Modifier
* mod
= (*i
)->GetModifier();
3233 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
> modifier
)
3234 modifier
= mod
->m_amount
;
3240 int32
Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const
3244 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3245 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3247 Modifier
* mod
= (*i
)->GetModifier();
3248 if (mod
->m_miscvalue
& misc_mask
&& mod
->m_amount
< modifier
)
3249 modifier
= mod
->m_amount
;
3255 int32
Unit::GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3259 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3260 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3262 Modifier
* mod
= (*i
)->GetModifier();
3263 if (mod
->m_miscvalue
== misc_value
)
3264 modifier
+= mod
->m_amount
;
3269 float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const
3271 float multiplier
= 1.0f
;
3273 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3274 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3276 Modifier
* mod
= (*i
)->GetModifier();
3277 if (mod
->m_miscvalue
== misc_value
)
3278 multiplier
*= (100.0f
+ mod
->m_amount
)/100.0f
;
3283 int32
Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3287 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3288 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3290 Modifier
* mod
= (*i
)->GetModifier();
3291 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
> modifier
)
3292 modifier
= mod
->m_amount
;
3298 int32
Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const
3302 AuraList
const& mTotalAuraList
= GetAurasByType(auratype
);
3303 for(AuraList::const_iterator i
= mTotalAuraList
.begin();i
!= mTotalAuraList
.end(); ++i
)
3305 Modifier
* mod
= (*i
)->GetModifier();
3306 if (mod
->m_miscvalue
== misc_value
&& mod
->m_amount
< modifier
)
3307 modifier
= mod
->m_amount
;
3313 bool Unit::AddAura(Aura
*Aur
)
3315 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
3316 if( !isAlive() && Aur
->GetId() != 20584 && Aur
->GetId() != 8326 && Aur
->GetId() != 2584 &&
3317 (GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)this)->GetSession()->PlayerLoading()) )
3323 if(Aur
->GetTarget() != this)
3325 sLog
.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)",
3326 Aur
->GetId(),Aur
->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER
?"player":"creature"),GetGUIDLow(),
3327 (Aur
->GetTarget()->GetTypeId()==TYPEID_PLAYER
?"player":"creature"),Aur
->GetTarget()->GetGUIDLow());
3332 SpellEntry
const* aurSpellInfo
= Aur
->GetSpellProto();
3334 spellEffectPair spair
= spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex());
3335 AuraMap::iterator i
= m_Auras
.find( spair
);
3337 // take out same spell
3338 if (i
!= m_Auras
.end())
3340 // passive and persistent auras can stack with themselves any number of times
3341 if (!Aur
->IsPassive() && !Aur
->IsPersistent())
3343 for(AuraMap::iterator i2
= m_Auras
.lower_bound(spair
); i2
!= m_Auras
.upper_bound(spair
); ++i2
)
3345 if(i2
->second
->GetCasterGUID()==Aur
->GetCasterGUID())
3347 // Aura can stack on self -> Stack it;
3348 if(aurSpellInfo
->StackAmount
)
3350 i2
->second
->modStackAmount(1);
3354 // can be only single (this check done at _each_ aura add
3355 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3360 switch(aurSpellInfo
->EffectApplyAuraName
[Aur
->GetEffIndex()])
3363 case SPELL_AURA_PERIODIC_DAMAGE
: // allow stack
3364 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT
:
3365 case SPELL_AURA_PERIODIC_LEECH
:
3366 case SPELL_AURA_PERIODIC_HEAL
:
3367 case SPELL_AURA_OBS_MOD_HEALTH
:
3368 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3369 case SPELL_AURA_PERIODIC_ENERGIZE
:
3370 case SPELL_AURA_OBS_MOD_MANA
:
3371 case SPELL_AURA_POWER_BURN_MANA
:
3373 default: // not allow
3374 // can be only single (this check done at _each_ aura add
3375 RemoveAura(i2
,AURA_REMOVE_BY_STACK
);
3386 // passive auras not stacable with other ranks
3387 if (!IsPassiveSpellStackableWithRanks(aurSpellInfo
))
3389 if (!RemoveNoStackAurasDueToAura(Aur
))
3392 return false; // couldn't remove conflicting aura with higher rank
3396 // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura)
3397 if (Aur
->IsSingleTarget() && Aur
->GetTarget())
3399 // caster pointer can be deleted in time aura remove, find it by guid at each iteration
3402 Unit
* caster
= Aur
->GetCaster();
3403 if(!caster
) // caster deleted and not required adding scAura
3406 bool restart
= false;
3407 AuraList
& scAuras
= caster
->GetSingleCastAuras();
3408 for(AuraList::iterator itr
= scAuras
.begin(); itr
!= scAuras
.end(); ++itr
)
3410 if( (*itr
)->GetTarget() != Aur
->GetTarget() &&
3411 IsSingleTargetSpells((*itr
)->GetSpellProto(),aurSpellInfo
) )
3413 if ((*itr
)->IsInUse())
3415 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());
3418 (*itr
)->GetTarget()->RemoveAura((*itr
)->GetId(), (*itr
)->GetEffIndex());
3427 scAuras
.push_back(Aur
);
3433 // add aura, register in lists and arrays
3435 m_Auras
.insert(AuraMap::value_type(spellEffectPair(Aur
->GetId(), Aur
->GetEffIndex()), Aur
));
3436 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
3438 m_modAuras
[Aur
->GetModifier()->m_auraname
].push_back(Aur
);
3441 Aur
->ApplyModifier(true,true);
3442 sLog
.outDebug("Aura %u now is in use", Aur
->GetModifier()->m_auraname
);
3446 void Unit::RemoveRankAurasDueToSpell(uint32 spellId
)
3448 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3451 AuraMap::iterator i
,next
;
3452 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3456 uint32 i_spellId
= (*i
).second
->GetId();
3457 if((*i
).second
&& i_spellId
&& i_spellId
!= spellId
)
3459 if(spellmgr
.IsRankSpellDueToSpell(spellInfo
,i_spellId
))
3461 RemoveAurasDueToSpell(i_spellId
);
3463 if( m_Auras
.empty() )
3466 next
= m_Auras
.begin();
3472 bool Unit::RemoveNoStackAurasDueToAura(Aura
*Aur
)
3477 SpellEntry
const* spellProto
= Aur
->GetSpellProto();
3481 uint32 spellId
= Aur
->GetId();
3482 uint32 effIndex
= Aur
->GetEffIndex();
3484 // passive spell special case (only non stackable with ranks)
3485 if(IsPassiveSpell(spellId
))
3487 if(IsPassiveSpellStackableWithRanks(spellProto
))
3491 SpellSpecific spellId_spec
= GetSpellSpecific(spellId
);
3493 AuraMap::iterator i
,next
;
3494 for (i
= m_Auras
.begin(); i
!= m_Auras
.end(); i
= next
)
3498 if (!(*i
).second
) continue;
3500 SpellEntry
const* i_spellProto
= (*i
).second
->GetSpellProto();
3505 uint32 i_spellId
= i_spellProto
->Id
;
3507 // early checks that spellId is passive non stackable spell
3508 if(IsPassiveSpell(i_spellId
))
3510 // passive non-stackable spells not stackable only for same caster
3511 if(Aur
->GetCasterGUID()!=i
->second
->GetCasterGUID())
3514 // passive non-stackable spells not stackable only with another rank of same spell
3515 if (!spellmgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3519 uint32 i_effIndex
= (*i
).second
->GetEffIndex();
3521 if(i_spellId
== spellId
) continue;
3523 bool is_triggered_by_spell
= false;
3524 // prevent triggered aura of removing aura that triggered it
3525 for(int j
= 0; j
< 3; ++j
)
3526 if (i_spellProto
->EffectTriggerSpell
[j
] == spellProto
->Id
)
3527 is_triggered_by_spell
= true;
3529 if (is_triggered_by_spell
)
3532 SpellSpecific i_spellId_spec
= GetSpellSpecific(i_spellId
);
3534 bool is_sspc
= IsSingleFromSpellSpecificPerCaster(spellId_spec
,i_spellId_spec
);
3535 bool is_sspt
= IsSingleFromSpellSpecificRanksPerTarget(spellId_spec
,i_spellId_spec
);
3537 if( is_sspc
&& Aur
->GetCasterGUID() == (*i
).second
->GetCasterGUID() )
3539 // cannot remove higher rank
3540 if (spellmgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
))
3541 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3544 // Its a parent aura (create this aura in ApplyModifier)
3545 if ((*i
).second
->IsInUse())
3547 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());
3550 RemoveAurasDueToSpell(i_spellId
);
3552 if( m_Auras
.empty() )
3555 next
= m_Auras
.begin();
3557 else if( is_sspt
&& Aur
->GetCasterGUID() != (*i
).second
->GetCasterGUID() && spellmgr
.IsRankSpellDueToSpell(spellProto
, i_spellId
) )
3559 // cannot remove higher rank
3560 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3563 // Its a parent aura (create this aura in ApplyModifier)
3564 if ((*i
).second
->IsInUse())
3566 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());
3569 RemoveAurasDueToSpell(i_spellId
);
3571 if( m_Auras
.empty() )
3574 next
= m_Auras
.begin();
3576 else if( !is_sspc
&& spellmgr
.IsNoStackSpellDueToSpell(spellId
, i_spellId
) )
3578 // Its a parent aura (create this aura in ApplyModifier)
3579 if ((*i
).second
->IsInUse())
3581 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());
3584 RemoveAurasDueToSpell(i_spellId
);
3586 if( m_Auras
.empty() )
3589 next
= m_Auras
.begin();
3591 // Potions stack aura by aura (elixirs/flask already checked)
3592 else if( spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
&& i_spellProto
->SpellFamilyName
== SPELLFAMILY_POTION
)
3594 if (IsNoStackAuraDueToAura(spellId
, effIndex
, i_spellId
, i_effIndex
))
3596 if(CompareAuraRanks(spellId
, effIndex
, i_spellId
, i_effIndex
) < 0)
3597 return false; // cannot remove higher rank
3599 // Its a parent aura (create this aura in ApplyModifier)
3600 if ((*i
).second
->IsInUse())
3602 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());
3613 void Unit::RemoveAura(uint32 spellId
, uint32 effindex
, Aura
* except
)
3615 spellEffectPair spair
= spellEffectPair(spellId
, effindex
);
3616 for(AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
3618 if(iter
->second
!=except
)
3621 iter
= m_Auras
.lower_bound(spair
);
3628 void Unit::RemoveAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
)
3630 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3632 Aura
*aur
= iter
->second
;
3633 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3640 void Unit::RemoveAurasDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
)
3642 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3644 Aura
*aur
= iter
->second
;
3645 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3647 // Custom dispel case
3648 // Unstable Affliction
3649 if (aur
->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& (aur
->GetSpellProto()->SpellFamilyFlags
& 0x010000000000LL
))
3651 int32 damage
= aur
->GetModifier()->m_amount
*9;
3652 uint64 caster_guid
= aur
->GetCasterGUID();
3655 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
3657 // backfire damage and silence
3658 dispeler
->CastCustomSpell(dispeler
, 31117, &damage
, NULL
, NULL
, true, NULL
, NULL
,caster_guid
);
3660 iter
= m_Auras
.begin(); // iterator can be invalidate at cast if self-dispel
3663 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
3670 void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
)
3672 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3674 Aura
*aur
= iter
->second
;
3675 if (aur
->GetId() == spellId
&& aur
->GetCasterGUID() == casterGUID
)
3677 int32 basePoints
= aur
->GetBasePoints();
3678 // construct the new aura for the attacker - will never return NULL, it's just a wrapper for
3679 // some different constructors
3680 Aura
* new_aur
= CreateAura(aur
->GetSpellProto(), aur
->GetEffIndex(), &basePoints
, stealer
, this);
3682 // set its duration and maximum duration
3683 // max duration 2 minutes (in msecs)
3684 int32 dur
= aur
->GetAuraDuration();
3685 const int32 max_dur
= 2*MINUTE
*IN_MILISECONDS
;
3686 new_aur
->SetAuraMaxDuration( max_dur
> dur
? dur
: max_dur
);
3687 new_aur
->SetAuraDuration( max_dur
> dur
? dur
: max_dur
);
3689 // Unregister _before_ adding to stealer
3690 aur
->UnregisterSingleCastAura();
3692 // strange but intended behaviour: Stolen single target auras won't be treated as single targeted
3693 new_aur
->SetIsSingleTarget(false);
3695 // add the new aura to stealer
3696 stealer
->AddAura(new_aur
);
3698 // Remove aura as dispel
3699 RemoveAura(iter
, AURA_REMOVE_BY_DISPEL
);
3706 void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId
)
3708 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3710 if (iter
->second
->GetId() == spellId
)
3711 RemoveAura(iter
, AURA_REMOVE_BY_CANCEL
);
3717 void Unit::RemoveAurasWithDispelType( DispelType type
)
3719 // Create dispel mask by dispel type
3720 uint32 dispelMask
= GetDispellMask(type
);
3721 // Dispel all existing auras vs current dispel type
3722 AuraMap
& auras
= GetAuras();
3723 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
3725 SpellEntry
const* spell
= itr
->second
->GetSpellProto();
3726 if( (1<<spell
->Dispel
) & dispelMask
)
3729 RemoveAurasDueToSpell(spell
->Id
);
3730 itr
= auras
.begin();
3737 void Unit::RemoveSingleAuraFromStack(uint32 spellId
, uint32 effindex
)
3739 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
3740 if(iter
!= m_Auras
.end())
3742 if (iter
->second
->modStackAmount(-1))
3747 void Unit::RemoveSingleSpellAurasFromStack(uint32 spellId
)
3749 for (int i
=0; i
<3; ++i
)
3750 RemoveSingleAuraFromStack(spellId
, i
);
3753 void Unit::RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
)
3755 for (int i
= 0; i
< 3; ++i
)
3756 RemoveAura(spellId
,i
,except
);
3759 void Unit::RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
)
3761 for (int k
=0; k
< 3; ++k
)
3763 spellEffectPair spair
= spellEffectPair(spellId
, k
);
3764 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
);)
3766 if (iter
->second
->GetCastItemGUID() == castItem
->GetGUID())
3769 iter
= m_Auras
.upper_bound(spair
); // overwrite by more appropriate
3777 void Unit::RemoveAurasWithInterruptFlags(uint32 flags
)
3779 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3781 if (iter
->second
->GetSpellProto()->AuraInterruptFlags
& flags
)
3788 void Unit::RemoveNotOwnSingleTargetAuras()
3790 // single target auras from other casters
3791 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); )
3793 if (iter
->second
->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter
->second
->GetSpellProto()))
3799 // single target auras at other targets
3800 AuraList
& scAuras
= GetSingleCastAuras();
3801 for (AuraList::iterator iter
= scAuras
.begin(); iter
!= scAuras
.end(); )
3804 if (aura
->GetTarget()!=this)
3806 scAuras
.erase(iter
); // explicitly remove, instead waiting remove in RemoveAura
3807 aura
->GetTarget()->RemoveAura(aura
->GetId(),aura
->GetEffIndex());
3808 iter
= scAuras
.begin();
3816 void Unit::RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
)
3818 Aura
* Aur
= i
->second
;
3819 SpellEntry
const* AurSpellInfo
= Aur
->GetSpellProto();
3821 Aur
->UnregisterSingleCastAura();
3823 // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order)
3824 if (Aur
->GetModifier()->m_auraname
< TOTAL_AURAS
)
3826 m_modAuras
[Aur
->GetModifier()->m_auraname
].remove(Aur
);
3830 Aur
->SetRemoveMode(mode
);
3831 // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura
3832 // remove aura from list before to prevent deleting it before
3834 ++m_removedAuras
; // internal count used by unit update
3836 // Statue unsummoned at aura remove
3837 Totem
* statue
= NULL
;
3838 bool caster_channeled
= false;
3839 if(IsChanneledSpell(AurSpellInfo
))
3841 Unit
* caster
= Aur
->GetCaster();
3845 if(caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)caster
)->isTotem() && ((Totem
*)caster
)->GetTotemType()==TOTEM_STATUE
)
3846 statue
= ((Totem
*)caster
);
3848 caster_channeled
= caster
==this;
3852 sLog
.outDebug("Aura %u now is remove mode %d",Aur
->GetModifier()->m_auraname
, mode
);
3853 Aur
->ApplyModifier(false,true);
3857 if(caster_channeled
)
3858 RemoveAurasAtChanneledTarget (AurSpellInfo
);
3863 // only way correctly remove all auras from list
3864 if( m_Auras
.empty() )
3867 i
= m_Auras
.begin();
3870 void Unit::RemoveAllAuras()
3872 while (!m_Auras
.empty())
3874 AuraMap::iterator iter
= m_Auras
.begin();
3879 void Unit::RemoveArenaAuras(bool onleave
)
3881 // in join, remove positive buffs, on end, remove negative
3882 // used to remove positive visible auras in arenas
3883 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
3885 if ( !(iter
->second
->GetSpellProto()->AttributesEx4
& (1<<21)) // don't remove stances, shadowform, pally/hunter auras
3886 && !iter
->second
->IsPassive() // don't remove passive auras
3887 && (!(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)
3888 && (iter
->second
->IsPositive() ^ onleave
)) // remove positive buffs on enter, negative buffs on leave
3895 void Unit::RemoveAllAurasOnDeath()
3897 // used just after dieing to remove all visible auras
3898 // and disable the mods for the passive ones
3899 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
3901 if (!iter
->second
->IsPassive() && !iter
->second
->IsDeathPersistent())
3902 RemoveAura(iter
, AURA_REMOVE_BY_DEATH
);
3908 void Unit::DelayAura(uint32 spellId
, uint32 effindex
, int32 delaytime
)
3910 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
3911 if (iter
!= m_Auras
.end())
3913 if (iter
->second
->GetAuraDuration() < delaytime
)
3914 iter
->second
->SetAuraDuration(0);
3916 iter
->second
->SetAuraDuration(iter
->second
->GetAuraDuration() - delaytime
);
3917 iter
->second
->SendAuraUpdate(false);
3918 sLog
.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter
->second
->GetModifier()->m_auraname
, GetGUIDLow(), iter
->second
->GetAuraDuration());
3922 void Unit::_RemoveAllAuraMods()
3924 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
3926 (*i
).second
->ApplyModifier(false);
3930 void Unit::_ApplyAllAuraMods()
3932 for (AuraMap::iterator i
= m_Auras
.begin(); i
!= m_Auras
.end(); ++i
)
3934 (*i
).second
->ApplyModifier(true);
3938 Aura
* Unit::GetAura(uint32 spellId
, uint32 effindex
)
3940 AuraMap::iterator iter
= m_Auras
.find(spellEffectPair(spellId
, effindex
));
3941 if (iter
!= m_Auras
.end())
3942 return iter
->second
;
3946 Aura
* Unit::GetAura(AuraType type
, uint32 family
, uint64 familyFlag
, uint32 familyFlag2
, uint64 casterGUID
)
3948 AuraList
const& auras
= GetAurasByType(type
);
3949 for(AuraList::const_iterator i
= auras
.begin();i
!= auras
.end(); ++i
)
3951 SpellEntry
const *spell
= (*i
)->GetSpellProto();
3952 if (spell
->SpellFamilyName
== family
&& (spell
->SpellFamilyFlags
& familyFlag
|| spell
->SpellFamilyFlags2
& familyFlag2
))
3954 if (casterGUID
&& (*i
)->GetCasterGUID()!=casterGUID
)
3962 bool Unit::HasAura(uint32 spellId
) const
3964 for (int i
= 0; i
< 3 ; ++i
)
3966 AuraMap::const_iterator iter
= m_Auras
.find(spellEffectPair(spellId
, i
));
3967 if (iter
!= m_Auras
.end())
3973 void Unit::AddDynObject(DynamicObject
* dynObj
)
3975 m_dynObjGUIDs
.push_back(dynObj
->GetGUID());
3978 void Unit::RemoveDynObject(uint32 spellid
)
3980 if(m_dynObjGUIDs
.empty())
3982 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
3984 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*i
);
3987 i
= m_dynObjGUIDs
.erase(i
);
3989 else if(spellid
== 0 || dynObj
->GetSpellId() == spellid
)
3992 i
= m_dynObjGUIDs
.erase(i
);
3999 void Unit::RemoveAllDynObjects()
4001 while(!m_dynObjGUIDs
.empty())
4003 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs
.begin());
4006 m_dynObjGUIDs
.erase(m_dynObjGUIDs
.begin());
4010 DynamicObject
* Unit::GetDynObject(uint32 spellId
, uint32 effIndex
)
4012 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4014 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*i
);
4017 i
= m_dynObjGUIDs
.erase(i
);
4021 if (dynObj
->GetSpellId() == spellId
&& dynObj
->GetEffIndex() == effIndex
)
4028 DynamicObject
* Unit::GetDynObject(uint32 spellId
)
4030 for (DynObjectGUIDs::iterator i
= m_dynObjGUIDs
.begin(); i
!= m_dynObjGUIDs
.end();)
4032 DynamicObject
* dynObj
= ObjectAccessor::GetDynamicObject(*this,*i
);
4035 i
= m_dynObjGUIDs
.erase(i
);
4039 if (dynObj
->GetSpellId() == spellId
)
4046 GameObject
* Unit::GetGameObject(uint32 spellId
) const
4048 for (GameObjectList::const_iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4049 if ((*i
)->GetSpellId() == spellId
)
4055 void Unit::AddGameObject(GameObject
* gameObj
)
4057 assert(gameObj
&& gameObj
->GetOwnerGUID()==0);
4058 m_gameObj
.push_back(gameObj
);
4059 gameObj
->SetOwnerGUID(GetGUID());
4061 if ( GetTypeId()==TYPEID_PLAYER
&& gameObj
->GetSpellId() )
4063 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(gameObj
->GetSpellId());
4064 // Need disable spell use for owner
4065 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4066 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4067 ((Player
*)this)->AddSpellAndCategoryCooldowns(createBySpell
,0,NULL
,true);
4071 void Unit::RemoveGameObject(GameObject
* gameObj
, bool del
)
4073 assert(gameObj
&& gameObj
->GetOwnerGUID()==GetGUID());
4075 gameObj
->SetOwnerGUID(0);
4077 // GO created by some spell
4078 if (uint32 spellid
= gameObj
->GetSpellId())
4080 RemoveAurasDueToSpell(spellid
);
4082 if (GetTypeId()==TYPEID_PLAYER
)
4084 SpellEntry
const* createBySpell
= sSpellStore
.LookupEntry(spellid
);
4085 // Need activate spell use for owner
4086 if (createBySpell
&& createBySpell
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
4087 // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existed cases)
4088 ((Player
*)this)->SendCooldownEvent(createBySpell
);
4092 m_gameObj
.remove(gameObj
);
4096 gameObj
->SetRespawnTime(0);
4101 void Unit::RemoveGameObject(uint32 spellid
, bool del
)
4103 if(m_gameObj
.empty())
4105 GameObjectList::iterator i
, next
;
4106 for (i
= m_gameObj
.begin(); i
!= m_gameObj
.end(); i
= next
)
4109 if(spellid
== 0 || (*i
)->GetSpellId() == spellid
)
4111 (*i
)->SetOwnerGUID(0);
4114 (*i
)->SetRespawnTime(0);
4118 next
= m_gameObj
.erase(i
);
4125 void Unit::RemoveAllGameObjects()
4127 // remove references to unit
4128 for(GameObjectList::iterator i
= m_gameObj
.begin(); i
!= m_gameObj
.end();)
4130 (*i
)->SetOwnerGUID(0);
4131 (*i
)->SetRespawnTime(0);
4133 i
= m_gameObj
.erase(i
);
4137 void Unit::SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
)
4139 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size
4140 data
.append(log
->target
->GetPackGUID());
4141 data
.append(log
->attacker
->GetPackGUID());
4142 data
<< uint32(log
->SpellID
);
4143 data
<< uint32(log
->damage
); //damage amount
4145 data
<< uint8 (log
->schoolMask
); //damage school
4146 data
<< uint32(log
->absorb
); //AbsorbedDamage
4147 data
<< uint32(log
->resist
); //resist
4148 data
<< uint8 (log
->phusicalLog
); // damsge type? flag
4149 data
<< uint8 (log
->unused
); //unused
4150 data
<< uint32(log
->blocked
); //blocked
4151 data
<< uint32(log
->HitInfo
);
4152 data
<< uint8 (0); // flag to use extend data
4153 SendMessageToSet( &data
, true );
4156 void Unit::SendSpellNonMeleeDamageLog(Unit
*target
,uint32 SpellID
,uint32 Damage
, SpellSchoolMask damageSchoolMask
,uint32 AbsorbedDamage
, uint32 Resist
,bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
)
4158 sLog
.outDebug("Sending: SMSG_SPELLNONMELEEDAMAGELOG");
4159 WorldPacket
data(SMSG_SPELLNONMELEEDAMAGELOG
, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size
4160 data
.append(target
->GetPackGUID());
4161 data
.append(GetPackGUID());
4162 data
<< uint32(SpellID
);
4163 data
<< uint32(Damage
-AbsorbedDamage
-Resist
-Blocked
);
4164 data
<< uint32(0); // wotlk
4165 data
<< uint8(damageSchoolMask
); // spell school
4166 data
<< uint32(AbsorbedDamage
); // AbsorbedDamage
4167 data
<< uint32(Resist
); // resist
4168 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
4169 data
<< uint8(0); // unk isFromAura
4170 data
<< uint32(Blocked
); // blocked
4171 data
<< uint32(CriticalHit
? 0x27 : 0x25); // hitType, flags: 0x2 - SPELL_HIT_TYPE_CRIT, 0x10 - replace caster?
4172 data
<< uint8(0); // isDebug?
4173 SendMessageToSet( &data
, true );
4176 void Unit::ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procExtra
, uint32 amount
, WeaponAttackType attType
, SpellEntry
const *procSpell
)
4178 // Not much to do if no flags are set.
4180 ProcDamageAndSpellFor(false,pVictim
,procAttacker
, procExtra
,attType
, procSpell
, amount
);
4181 // Now go on with a victim's events'n'auras
4182 // Not much to do if no flags are set or there is no victim
4183 if(pVictim
&& pVictim
->isAlive() && procVictim
)
4184 pVictim
->ProcDamageAndSpellFor(true,this,procVictim
, procExtra
, attType
, procSpell
, amount
);
4187 void Unit::SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
)
4189 WorldPacket
data(SMSG_SPELLLOGMISS
, (4+8+1+4+8+1));
4190 data
<< uint32(spellID
);
4191 data
<< uint64(GetGUID());
4192 data
<< uint8(0); // can be 0 or 1
4193 data
<< uint32(1); // target count
4194 // for(i = 0; i < target count; ++i)
4195 data
<< uint64(target
->GetGUID()); // target GUID
4196 data
<< uint8(missInfo
);
4198 SendMessageToSet(&data
, true);
4201 void Unit::SendAttackStateUpdate(CalcDamageInfo
*damageInfo
)
4204 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, (16+45)); // we guess size
4205 data
<< (uint32
)damageInfo
->HitInfo
;
4206 data
.append(GetPackGUID());
4207 data
.append(damageInfo
->target
->GetPackGUID());
4208 data
<< (uint32
)(damageInfo
->damage
); // Full damage
4209 data
<< uint32(0); // overkill value
4211 data
<< (uint8
)count
; // Sub damage count
4213 for(int i
= 0; i
< count
; ++i
)
4215 data
<< (uint32
)(damageInfo
->damageSchoolMask
); // School of sub damage
4216 data
<< (float)damageInfo
->damage
; // sub damage
4217 data
<< (uint32
)damageInfo
->damage
; // Sub Damage
4220 if(damageInfo
->HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4222 for(int i
= 0; i
< count
; ++i
)
4223 data
<< (uint32
)damageInfo
->absorb
; // Absorb
4226 if(damageInfo
->HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4228 for(int i
= 0; i
< count
; ++i
)
4229 data
<< (uint32
)damageInfo
->resist
; // Resist
4232 data
<< (uint8
)damageInfo
->TargetState
;
4236 if(damageInfo
->HitInfo
& HITINFO_BLOCK
)
4237 data
<< (uint32
)damageInfo
->blocked_amount
;
4239 if(damageInfo
->HitInfo
& HITINFO_UNK3
)
4242 if(damageInfo
->HitInfo
& HITINFO_UNK1
)
4253 for(uint8 i
= 0; i
< 5; ++i
)
4261 SendMessageToSet( &data
, true );
4264 void Unit::SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8 SwingType
, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
)
4266 sLog
.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE");
4268 WorldPacket
data(SMSG_ATTACKERSTATEUPDATE
, (16+45)); // we guess size
4269 data
<< uint32(HitInfo
); // flags
4270 data
.append(GetPackGUID());
4271 data
.append(target
->GetPackGUID());
4272 data
<< uint32(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);// damage
4273 data
<< uint32(0); // overkill value
4275 data
<< (uint8
)SwingType
; // count?
4277 // for(i = 0; i < SwingType; ++i)
4278 data
<< (uint32
)damageSchoolMask
;
4279 data
<< (float)(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);
4280 data
<< (uint32
)(Damage
-AbsorbDamage
-Resist
-BlockedAmount
);
4283 if(HitInfo
& (HITINFO_ABSORB
| HITINFO_ABSORB2
))
4285 // for(i = 0; i < SwingType; ++i)
4286 data
<< uint32(AbsorbDamage
);
4290 if(HitInfo
& (HITINFO_RESIST
| HITINFO_RESIST2
))
4292 // for(i = 0; i < SwingType; ++i)
4293 data
<< uint32(Resist
);
4297 data
<< (uint8
)TargetState
;
4301 if(HitInfo
& HITINFO_BLOCK
)
4303 data
<< uint32(BlockedAmount
);
4306 if(HitInfo
& HITINFO_UNK3
)
4311 if(HitInfo
& HITINFO_UNK1
)
4322 for(uint8 i
= 0; i
< 5; ++i
)
4330 SendMessageToSet( &data
, true );
4333 bool Unit::HandleHasteAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32
/*procFlag*/, uint32
/*procEx*/, uint32 cooldown
)
4335 SpellEntry
const *hasteSpell
= triggeredByAura
->GetSpellProto();
4337 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4338 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4340 uint32 triggered_spell_id
= 0;
4341 Unit
* target
= pVictim
;
4342 int32 basepoints0
= 0;
4344 switch(hasteSpell
->SpellFamilyName
)
4346 case SPELLFAMILY_ROGUE
:
4348 switch(hasteSpell
->Id
)
4354 target
= SelectNearbyTarget();
4357 basepoints0
= damage
;
4358 triggered_spell_id
= 22482;
4366 // processed charge only counting case
4367 if(!triggered_spell_id
)
4370 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
4374 sLog
.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell
->Id
,triggered_spell_id
);
4379 if(!target
|| target
!=this && !target
->isAlive())
4382 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
4386 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
4388 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
4390 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
4391 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
4396 bool Unit::HandleDummyAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const * procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
)
4398 SpellEntry
const *dummySpell
= triggeredByAura
->GetSpellProto ();
4399 uint32 effIndex
= triggeredByAura
->GetEffIndex();
4400 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
4402 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
4403 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
4405 uint32 triggered_spell_id
= 0;
4406 Unit
* target
= pVictim
;
4407 int32 basepoints0
= 0;
4409 switch(dummySpell
->SpellFamilyName
)
4411 case SPELLFAMILY_GENERIC
:
4413 switch (dummySpell
->Id
)
4419 // return damage % to attacker but < 50% own total health
4420 basepoints0
= triggerAmount
*int32(damage
)/100;
4421 if(basepoints0
> GetMaxHealth()/2)
4422 basepoints0
= GetMaxHealth()/2;
4424 triggered_spell_id
= 25997;
4432 // prevent chain of triggered spell from same triggered spell
4433 if(procSpell
&& procSpell
->Id
==26654)
4436 target
= SelectNearbyTarget();
4440 triggered_spell_id
= 26654;
4446 if (!procSpell
|| procSpell
->Id
== 24659)
4448 // Need remove one 24659 aura
4449 RemoveSingleSpellAurasFromStack(24659);
4452 // Restless Strength
4455 // Need remove one 24662 aura
4456 RemoveSingleSpellAurasFromStack(24662);
4459 // Adaptive Warding (Frostfire Regalia set)
4467 AuraList
const& mRegenInterupt
= GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT
);
4468 for(AuraList::const_iterator iter
= mRegenInterupt
.begin(); iter
!= mRegenInterupt
.end(); ++iter
)
4470 if(SpellEntry
const* iterSpellProto
= (*iter
)->GetSpellProto())
4472 if(iterSpellProto
->SpellFamilyName
==SPELLFAMILY_MAGE
&& (iterSpellProto
->SpellFamilyFlags
& 0x10000000))
4482 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
4484 case SPELL_SCHOOL_NORMAL
:
4485 case SPELL_SCHOOL_HOLY
:
4486 return false; // ignored
4487 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 28765; break;
4488 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 28768; break;
4489 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 28766; break;
4490 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 28769; break;
4491 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 28770; break;
4499 // Obsidian Armor (Justice Bearer`s Pauldrons shoulder)
4505 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
4507 case SPELL_SCHOOL_NORMAL
:
4508 return false; // ignore
4509 case SPELL_SCHOOL_HOLY
: triggered_spell_id
= 27536; break;
4510 case SPELL_SCHOOL_FIRE
: triggered_spell_id
= 27533; break;
4511 case SPELL_SCHOOL_NATURE
: triggered_spell_id
= 27538; break;
4512 case SPELL_SCHOOL_FROST
: triggered_spell_id
= 27534; break;
4513 case SPELL_SCHOOL_SHADOW
: triggered_spell_id
= 27535; break;
4514 case SPELL_SCHOOL_ARCANE
: triggered_spell_id
= 27540; break;
4522 // Mana Leech (Passive) (Priest Pet Aura)
4526 target
= GetOwner();
4530 triggered_spell_id
= 34650;
4536 // Cast finish spell at last charge
4537 if (triggeredByAura
->GetAuraCharges() > 1)
4541 triggered_spell_id
= 33494;
4544 // Twisted Reflection (boss spell)
4546 triggered_spell_id
= 21064;
4548 // Vampiric Aura (boss spell)
4551 basepoints0
= 3 * damage
; // 300%
4552 if (basepoints0
< 0)
4555 triggered_spell_id
= 31285;
4559 // Aura of Madness (Darkmoon Card: Madness trinket)
4560 //=====================================================
4561 // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior)
4562 // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid)
4563 // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid)
4564 // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin)
4565 // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes)
4566 // 41005 Manic: +35 haste (spell, melee and ranged) (All classes)
4567 // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter)
4568 // 41011 Martyr Complex: +35 stamina (All classes)
4569 // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
4570 // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin)
4573 if(GetTypeId() != TYPEID_PLAYER
)
4576 // Select class defined buff
4579 case CLASS_PALADIN
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
4580 case CLASS_DRUID
: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
4582 uint32 RandomSpell
[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
4583 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4586 case CLASS_ROGUE
: // 39511,40997,40998,41002,41005,41011
4587 case CLASS_WARRIOR
: // 39511,40997,40998,41002,41005,41011
4589 uint32 RandomSpell
[]={39511,40997,40998,41002,41005,41011};
4590 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4593 case CLASS_PRIEST
: // 40999,41002,41005,41009,41011,41406,41409
4594 case CLASS_SHAMAN
: // 40999,41002,41005,41009,41011,41406,41409
4595 case CLASS_MAGE
: // 40999,41002,41005,41009,41011,41406,41409
4596 case CLASS_WARLOCK
: // 40999,41002,41005,41009,41011,41406,41409
4598 uint32 RandomSpell
[]={40999,41002,41005,41009,41011,41406,41409};
4599 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4602 case CLASS_HUNTER
: // 40997,40999,41002,41005,41009,41011,41406,41409
4604 uint32 RandomSpell
[]={40997,40999,41002,41005,41009,41011,41406,41409};
4605 triggered_spell_id
= RandomSpell
[ irand(0, sizeof(RandomSpell
)/sizeof(uint32
) - 1) ];
4613 if (roll_chance_i(10))
4614 ((Player
*)this)->Say("This is Madness!", LANG_UNIVERSAL
);
4618 // TODO: need find item for aura and triggered spells
4619 // Sunwell Exalted Caster Neck (??? neck)
4620 // cast ??? Light's Wrath if Exalted by Aldor
4621 // cast ??? Arcane Bolt if Exalted by Scryers*/
4623 return false; // disable for while
4626 if(GetTypeId() != TYPEID_PLAYER)
4629 // Get Aldor reputation rank
4630 if (((Player *)this)->GetReputationRank(932) == REP_EXALTED)
4633 triggered_spell_id = ???
4636 // Get Scryers reputation rank
4637 if (((Player *)this)->GetReputationRank(934) == REP_EXALTED)
4639 triggered_spell_id = ???
4644 // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck)
4645 // cast 45479 Light's Wrath if Exalted by Aldor
4646 // cast 45429 Arcane Bolt if Exalted by Scryers
4649 if(GetTypeId() != TYPEID_PLAYER
)
4652 // Get Aldor reputation rank
4653 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4656 triggered_spell_id
= 45479;
4659 // Get Scryers reputation rank
4660 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4662 triggered_spell_id
= 45429;
4667 // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck)
4668 // cast 45480 Light's Strength if Exalted by Aldor
4669 // cast 45428 Arcane Strike if Exalted by Scryers
4672 if(GetTypeId() != TYPEID_PLAYER
)
4675 // Get Aldor reputation rank
4676 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4679 triggered_spell_id
= 45480;
4682 // Get Scryers reputation rank
4683 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4685 triggered_spell_id
= 45428;
4690 // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck)
4691 // cast 45431 Arcane Insight if Exalted by Aldor
4692 // cast 45432 Light's Ward if Exalted by Scryers
4695 if(GetTypeId() != TYPEID_PLAYER
)
4698 // Get Aldor reputation rank
4699 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4702 triggered_spell_id
= 45432;
4705 // Get Scryers reputation rank
4706 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4709 triggered_spell_id
= 45431;
4714 // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck)
4715 // cast 45478 Light's Salvation if Exalted by Aldor
4716 // cast 45430 Arcane Surge if Exalted by Scryers
4719 if(GetTypeId() != TYPEID_PLAYER
)
4722 // Get Aldor reputation rank
4723 if (((Player
*)this)->GetReputationRank(932) == REP_EXALTED
)
4726 triggered_spell_id
= 45478;
4729 // Get Scryers reputation rank
4730 if (((Player
*)this)->GetReputationRank(934) == REP_EXALTED
)
4732 triggered_spell_id
= 45430;
4740 triggered_spell_id
= 48503;
4741 basepoints0
= triggerAmount
;
4745 // Vampiric Touch (generic, used by some boss)
4749 triggered_spell_id
= 52724;
4750 basepoints0
= damage
/ 2;
4759 if (!roll_chance_i(triggerAmount
))
4762 // Remove any stun effect on target
4763 AuraMap
& Auras
= pVictim
->GetAuras();
4764 for(AuraMap::iterator iter
= Auras
.begin(); iter
!= Auras
.end();)
4766 SpellEntry
const *spell
= iter
->second
->GetSpellProto();
4767 if( spell
->Mechanic
== MECHANIC_STUN
||
4768 spell
->EffectMechanic
[iter
->second
->GetEffIndex()] == MECHANIC_STUN
)
4770 pVictim
->RemoveAurasDueToSpell(spell
->Id
);
4771 iter
= Auras
.begin();
4781 case SPELLFAMILY_MAGE
:
4784 if (dummySpell
->SpellIconID
== 459) // only this spell have SpellIconID == 459 and dummy aura
4786 if (getPowerType() != POWER_MANA
)
4790 basepoints0
= (triggerAmount
* GetMaxPower(POWER_MANA
) / 100);
4792 triggered_spell_id
= 29442;
4795 // Master of Elements
4796 if (dummySpell
->SpellIconID
== 1920)
4802 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
4803 basepoints0
= cost
* triggerAmount
/100;
4804 if( basepoints0
<=0 )
4808 triggered_spell_id
= 29077;
4812 if (dummySpell
->SpellIconID
== 2999)
4816 Aura
*counter
= GetAura(triggeredByAura
->GetId(), 1);
4820 // Count spell criticals in a row in second aura
4821 Modifier
*mod
= counter
->GetModifier();
4822 if (procEx
& PROC_EX_CRITICAL_HIT
)
4825 if (mod
->m_amount
< 100) // not enough
4827 // Crititcal counted -> roll chance
4828 if (roll_chance_i(triggerAmount
))
4829 CastSpell(this, 48108, true, castItem
, triggeredByAura
);
4835 if (dummySpell
->SpellIconID
== 2998)
4840 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
4841 basepoints0
= cost
* triggerAmount
/100;
4842 if( basepoints0
<=0 )
4844 triggered_spell_id
= 44450;
4848 // Incanter's Regalia set (add trigger chance to Mana Shield)
4849 if (dummySpell
->SpellFamilyFlags
& 0x0000000000008000LL
)
4851 if(GetTypeId() != TYPEID_PLAYER
)
4855 triggered_spell_id
= 37436;
4858 switch(dummySpell
->Id
)
4867 switch (dummySpell
->Id
)
4869 case 11119: basepoints0
= int32(0.04f
*damage
); break;
4870 case 11120: basepoints0
= int32(0.08f
*damage
); break;
4871 case 12846: basepoints0
= int32(0.12f
*damage
); break;
4872 case 12847: basepoints0
= int32(0.16f
*damage
); break;
4873 case 12848: basepoints0
= int32(0.20f
*damage
); break;
4875 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell
->Id
);
4879 triggered_spell_id
= 12654;
4885 //last charge and crit
4886 if (triggeredByAura
->GetAuraCharges() <= 1 && (procEx
& PROC_EX_CRITICAL_HIT
) )
4888 RemoveAurasDueToSpell(28682); //-> remove Combustion auras
4889 return true; // charge counting (will removed)
4892 CastSpell(this, 28682, true, castItem
, triggeredByAura
);
4893 return (procEx
& PROC_EX_CRITICAL_HIT
);// charge update only at crit hits, no hidden cooldowns
4898 case SPELLFAMILY_WARRIOR
:
4901 if(dummySpell
->SpellFamilyFlags
==0x0000000800000000LL
)
4903 // check attack comes not from behind
4904 if (!HasInArc(M_PI
, pVictim
))
4907 triggered_spell_id
= 22858;
4911 if (dummySpell
->SpellIconID
== 1697)
4913 // only for spells and hit/crit (trigger start always) and not start from self casted spells (5530 Mace Stun Effect for example)
4914 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
4916 // Need stun or root mechanic
4917 if (!(GetAllSpellMechanicMask(procSpell
) & ((1<<MECHANIC_ROOT
)|(1<<MECHANIC_STUN
))))
4920 switch (dummySpell
->Id
)
4922 case 29838: triggered_spell_id
=29842; break;
4923 case 29834: triggered_spell_id
=29841; break;
4924 case 42770: triggered_spell_id
=42771; break;
4926 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (SW)",dummySpell
->Id
);
4934 if (dummySpell
->SpellIconID
== 3214)
4936 triggered_spell_id
= 59653;
4937 basepoints0
= GetShieldBlockValue() * triggerAmount
/ 100;
4942 case SPELLFAMILY_WARLOCK
:
4944 // Seed of Corruption
4945 if (dummySpell
->SpellFamilyFlags
& 0x0000001000000000LL
)
4947 Modifier
* mod
= triggeredByAura
->GetModifier();
4948 // if damage is more than need or target die from damage deal finish spell
4949 if( mod
->m_amount
<= damage
|| GetHealth() <= damage
)
4951 // remember guid before aura delete
4952 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
4954 // Remove aura (before cast for prevent infinite loop handlers)
4955 RemoveAurasDueToSpell(triggeredByAura
->GetId());
4957 // Cast finish spell (triggeredByAura already not exist!)
4958 CastSpell(this, 27285, true, castItem
, NULL
, casterGuid
);
4959 return true; // no hidden cooldown
4963 mod
->m_amount
-=damage
;
4966 // Seed of Corruption (Mobs cast) - no die req
4967 if (dummySpell
->SpellFamilyFlags
== 0x00LL
&& dummySpell
->SpellIconID
== 1932)
4969 Modifier
* mod
= triggeredByAura
->GetModifier();
4970 // if damage is more than need deal finish spell
4971 if( mod
->m_amount
<= damage
)
4973 // remember guid before aura delete
4974 uint64 casterGuid
= triggeredByAura
->GetCasterGUID();
4976 // Remove aura (before cast for prevent infinite loop handlers)
4977 RemoveAurasDueToSpell(triggeredByAura
->GetId());
4979 // Cast finish spell (triggeredByAura already not exist!)
4980 CastSpell(this, 32865, true, castItem
, NULL
, casterGuid
);
4981 return true; // no hidden cooldown
4984 mod
->m_amount
-=damage
;
4988 if (dummySpell
->SpellIconID
== 3222)
4993 triggered_spell_id
= 54181;
4994 basepoints0
= damage
* triggerAmount
/ 100;
4997 switch(dummySpell
->Id
)
5004 triggered_spell_id
= 17941;
5013 basepoints0
= int32(damage
*triggerAmount
/100);
5015 triggered_spell_id
= 30294;
5018 // Shadowflame (Voidheart Raiment set bonus)
5021 triggered_spell_id
= 37379;
5024 // Pet Healing (Corruptor Raiment or Rift Stalker Armor)
5032 basepoints0
= damage
* triggerAmount
/100;
5033 triggered_spell_id
= 37382;
5036 // Shadowflame Hellfire (Voidheart Raiment set bonus)
5039 triggered_spell_id
= 37378;
5045 case SPELLFAMILY_PRIEST
:
5048 if( dummySpell
->SpellFamilyFlags
& 0x0000040000000000LL
)
5050 if(!pVictim
|| !pVictim
->isAlive())
5053 // pVictim is caster of aura
5054 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5058 basepoints0
= triggerAmount
*damage
/100;
5059 pVictim
->CastCustomSpell(pVictim
,34919,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5060 return true; // no hidden cooldown
5063 if (dummySpell
->SpellIconID
== 2820)
5065 basepoints0
= damage
* triggerAmount
/100;
5066 triggered_spell_id
= 47753;
5069 switch(dummySpell
->Id
)
5074 if(!pVictim
|| !pVictim
->isAlive())
5077 // pVictim is caster of aura
5078 if(triggeredByAura
->GetCasterGUID() != pVictim
->GetGUID())
5082 int32 team
= triggerAmount
*damage
/500;
5083 int32 self
= triggerAmount
*damage
/100 - team
;
5084 pVictim
->CastCustomSpell(pVictim
,15290,&team
,&self
,NULL
,true,castItem
,triggeredByAura
);
5085 return true; // no hidden cooldown
5087 // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen)
5090 // Shadow Word: Pain
5091 if( procSpell
->SpellFamilyFlags
& 0x0000000000008000LL
)
5092 triggered_spell_id
= 40441;
5094 else if( procSpell
->SpellFamilyFlags
& 0x0000000000000010LL
)
5095 triggered_spell_id
= 40440;
5102 // Oracle Healing Bonus ("Garments of the Oracle" set)
5106 basepoints0
= int32(damage
* 10/100);
5108 triggered_spell_id
= 26170;
5111 // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set
5114 if(!procSpell
|| (GetSpellSchoolMask(procSpell
) & (SPELL_SCHOOL_MASK_FROST
| SPELL_SCHOOL_MASK_SHADOW
))==0 )
5118 basepoints0
= damage
* triggerAmount
/100;
5120 triggered_spell_id
= 39373;
5123 // Greater Heal (Vestments of Faith (Priest Tier 3) - 4 pieces bonus)
5126 triggered_spell_id
= 28810;
5129 // Glyph of Dispel Magic
5132 if(!target
->IsFriendlyTo(this))
5135 basepoints0
= int32(target
->GetMaxHealth() * triggerAmount
/ 100);
5136 triggered_spell_id
= 56131;
5142 case SPELLFAMILY_DRUID
:
5144 switch(dummySpell
->Id
)
5146 // Healing Touch (Dreamwalker Raiment set)
5150 basepoints0
= int32(procSpell
->manaCost
* 30 / 100);
5152 triggered_spell_id
= 28742;
5155 // Healing Touch Refund (Idol of Longevity trinket)
5159 triggered_spell_id
= 28848;
5162 // Mana Restore (Malorne Raiment set / Malorne Regalia set)
5167 triggered_spell_id
= 37238;
5170 // Druid Tier 6 Trinket
5176 if( procSpell
->SpellFamilyFlags
& 0x0000000000000004LL
)
5178 triggered_spell_id
= 40445;
5182 else if( procSpell
->SpellFamilyFlags
& 0x0000000000000010LL
)
5184 triggered_spell_id
= 40446;
5187 // Mangle (cat/bear)
5188 else if( procSpell
->SpellFamilyFlags
& 0x0000044000000000LL
)
5190 triggered_spell_id
= 40452;
5196 if (!roll_chance_f(chance
))
5205 // Deadly Interrupt Effect
5206 triggered_spell_id
= 32747;
5211 if (dummySpell
->SpellIconID
== 2856)
5215 // Only 0 aura can proc
5219 if (procSpell
->SpellFamilyFlags
& 0x0000000000000001LL
)
5221 if (!roll_chance_i(60))
5223 triggered_spell_id
= 48518;
5228 if (procSpell
->SpellFamilyFlags
& 0x0000000000000004LL
)
5230 triggered_spell_id
= 48517;
5237 else if (dummySpell
->SpellIconID
== 2860)
5239 triggered_spell_id
= 48504;
5240 basepoints0
= triggerAmount
* damage
/ 100;
5245 case SPELLFAMILY_ROGUE
:
5247 switch(dummySpell
->Id
)
5249 // Deadly Throw Interrupt
5252 // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw
5256 triggered_spell_id
= 32747;
5261 if( dummySpell
->SpellIconID
== 2909 )
5263 // "refresh your Slice and Dice duration to its 5 combo point maximum"
5264 // lookup Slice and Dice
5265 AuraList
const& sd
= GetAurasByType(SPELL_AURA_MOD_HASTE
);
5266 for(AuraList::const_iterator itr
= sd
.begin(); itr
!= sd
.end(); ++itr
)
5268 SpellEntry
const *spellProto
= (*itr
)->GetSpellProto();
5269 if( spellProto
->SpellFamilyName
== SPELLFAMILY_ROGUE
&&
5270 spellProto
->SpellFamilyFlags
& 0x0000000000040000LL
)
5272 (*itr
)->SetAuraMaxDuration(GetSpellMaxDuration(spellProto
));
5273 (*itr
)->RefreshAura();
5280 if( dummySpell
->SpellIconID
== 2963 )
5282 triggered_spell_id
= 25809;
5286 if( dummySpell
->SpellIconID
== 2116 )
5292 basepoints0
= procSpell
->manaCost
* triggerAmount
/100;
5293 if(basepoints0
<= 0)
5297 triggered_spell_id
= 31663;
5302 case SPELLFAMILY_HUNTER
:
5304 // Thrill of the Hunt
5305 if ( dummySpell
->SpellIconID
== 2236 )
5311 int32 mana
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
5312 basepoints0
= mana
* 40/100;
5313 if(basepoints0
<= 0)
5317 triggered_spell_id
= 34720;
5321 if ( dummySpell
->SpellIconID
== 3406 )
5323 triggered_spell_id
= 57669;
5328 if ( dummySpell
->SpellIconID
== 3579 )
5330 // Proc only from periodic (from trap activation proc another aura of this spell)
5331 if (!(procFlag
& PROC_FLAG_ON_DO_PERIODIC
) || !roll_chance_i(triggerAmount
))
5333 triggered_spell_id
= 56453;
5337 // Rapid Recuperation
5338 if ( dummySpell
->SpellIconID
== 3560 )
5340 // This effect only from Rapid Killing (mana regen)
5341 if (!(procSpell
->SpellFamilyFlags
& 0x0100000000000000LL
))
5343 triggered_spell_id
= 56654;
5349 case SPELLFAMILY_PALADIN
:
5351 // Seal of Righteousness - melee proc dummy (addition ${$MWS*(0.022*$AP+0.044*$SPH)} damage)
5352 if (dummySpell
->SpellFamilyFlags
&0x000000008000000LL
&& effIndex
==0)
5354 triggered_spell_id
= 25742;
5355 float ap
= GetTotalAttackPowerValue(BASE_ATTACK
);
5356 int32 holy
= SpellBaseDamageBonus(SPELL_SCHOOL_MASK_HOLY
) +
5357 SpellBaseDamageBonusForVictim(SPELL_SCHOOL_MASK_HOLY
, pVictim
);
5358 basepoints0
= GetAttackTime(BASE_ATTACK
) * int32(ap
*0.022f
+ 0.044f
* holy
) / 1000;
5362 if (dummySpell
->SpellFamilyFlags
&0x0008000000000000LL
)
5364 triggered_spell_id
= 58597;
5368 // Righteous Vengeance
5369 if (dummySpell
->SpellIconID
== 3025)
5372 basepoints0
= triggerAmount
*damage
/400;
5373 triggered_spell_id
= 61840;
5377 if (dummySpell
->SpellIconID
== 3030)
5380 basepoints0
= triggerAmount
*damage
/400;
5381 triggered_spell_id
= 54203;
5384 switch(dummySpell
->Id
)
5386 // Judgement of Light
5389 // Get judgement caster
5390 Unit
*caster
= triggeredByAura
->GetCaster();
5393 float ap
= caster
->GetTotalAttackPowerValue(BASE_ATTACK
);
5394 int32 holy
= caster
->SpellBaseDamageBonus(SPELL_SCHOOL_MASK_HOLY
) +
5395 caster
->SpellBaseDamageBonusForVictim(SPELL_SCHOOL_MASK_HOLY
, this);
5396 basepoints0
= int32(ap
*0.10f
+ 0.10f
*holy
);
5397 pVictim
->CastCustomSpell(pVictim
, 20267, &basepoints0
, 0, 0, true, 0, triggeredByAura
);
5400 // Judgement of Wisdom
5403 if (pVictim
->getPowerType() == POWER_MANA
)
5404 pVictim
->CastSpell(pVictim
, 20268, true, 0, triggeredByAura
);
5407 // Holy Power (Redemption Armor set)
5413 // Set class defined buff
5414 switch (pVictim
->getClass())
5420 triggered_spell_id
= 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
5424 triggered_spell_id
= 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
5428 triggered_spell_id
= 28791; // Increases the friendly target's attack power by $s1 for $d.
5431 triggered_spell_id
= 28790; // Increases the friendly target's armor
5438 // Seal of Vengeance (damage calc on apply aura)
5441 if(effIndex
!= 0) // effect 1,2 used by seal unleashing code
5444 triggered_spell_id
= 31803;
5447 // Spiritual Attunement
5451 // if healed by another unit (pVictim)
5456 basepoints0
= triggerAmount
*damage
/100;
5458 triggered_spell_id
= 31786;
5461 // Seal of Blood do damage trigger
5464 if (effIndex
== 0) // 0 effect - is proc on enemy
5465 triggered_spell_id
= 31893;
5466 else if (effIndex
== 1) // 1 effect - is proc on self
5468 // add spell damage from prev effect (27%)
5469 damage
+= CalculateDamage(BASE_ATTACK
, false) * 27 / 100;
5470 basepoints0
= triggerAmount
* damage
/ 100;
5472 triggered_spell_id
= 32221;
5478 // Seal of the Martyr do damage trigger
5481 if (effIndex
== 0) // 0 effect - is proc on enemy
5482 triggered_spell_id
= 53719;
5483 else if (effIndex
== 1) // 1 effect - is proc on self
5485 // add spell damage from prev effect (27%)
5486 damage
+= CalculateDamage(BASE_ATTACK
, false) * 27 / 100;
5487 basepoints0
= triggerAmount
* damage
/ 100;
5489 triggered_spell_id
= 53718;
5495 // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal)
5503 // Flash of light/Holy light
5504 if( procSpell
->SpellFamilyFlags
& 0x00000000C0000000LL
)
5506 triggered_spell_id
= 40471;
5510 else if( procSpell
->SpellFamilyFlags
& 0x0000000000800000LL
)
5512 triggered_spell_id
= 40472;
5518 if (!roll_chance_f(chance
))
5523 // Glyph of Divinity
5526 // Lookup base amount mana restore
5527 for (int i
=0; i
<3;i
++)
5528 if (procSpell
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
5530 int32 mana
= procSpell
->EffectBasePoints
[i
];
5531 CastCustomSpell(this, 54986, 0, &mana
, 0, true, castItem
, triggeredByAura
);
5536 // Glyph of Flash of Light
5539 triggered_spell_id
= 54957;
5540 basepoints0
= triggerAmount
*damage
/100;
5543 // Glyph of Holy Light
5546 triggered_spell_id
= 54968;
5547 basepoints0
= triggerAmount
*damage
/100;
5553 case SPELLFAMILY_SHAMAN
:
5555 switch(dummySpell
->Id
)
5557 // Totemic Power (The Earthshatterer set)
5563 // Set class defined buff
5564 switch (pVictim
->getClass())
5570 triggered_spell_id
= 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d.
5574 triggered_spell_id
= 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d.
5578 triggered_spell_id
= 28826; // Increases the friendly target's attack power by $s1 for $d.
5581 triggered_spell_id
= 28827; // Increases the friendly target's armor
5588 // Lesser Healing Wave (Totem of Flowing Water Relic)
5592 triggered_spell_id
= 28850;
5595 // Windfury Weapon (Passive) 1-5 Ranks
5598 if(GetTypeId()!=TYPEID_PLAYER
)
5601 if(!castItem
|| !castItem
->IsEquipped())
5604 // custom cooldown processing case
5605 if( cooldown
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
5608 // Now amount of extra power stored in 1 effect of Enchant spell
5609 // Get it by item enchant id
5611 switch (castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)))
5613 case 283: spellId
= 8232; break; // 1 Rank
5614 case 284: spellId
= 8235; break; // 2 Rank
5615 case 525: spellId
= 10486; break; // 3 Rank
5616 case 1669:spellId
= 16362; break; // 4 Rank
5617 case 2636:spellId
= 25505; break; // 5 Rank
5618 case 3785:spellId
= 58801; break; // 6 Rank
5619 case 3786:spellId
= 58803; break; // 7 Rank
5620 case 3787:spellId
= 58804; break; // 8 Rank
5623 sLog
.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)",
5624 castItem
->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT
)),dummySpell
->Id
);
5629 SpellEntry
const* windfurySpellEntry
= sSpellStore
.LookupEntry(spellId
);
5630 if(!windfurySpellEntry
)
5632 sLog
.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId
);
5636 int32 extra_attack_power
= CalculateSpellDamage(windfurySpellEntry
, 1, windfurySpellEntry
->EffectBasePoints
[1], pVictim
);
5639 if ( castItem
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
5641 // Value gained from additional AP
5642 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(OFF_ATTACK
)/1000/2);
5643 triggered_spell_id
= 33750;
5648 // Value gained from additional AP
5649 basepoints0
= int32(extra_attack_power
/14.0f
* GetAttackTime(BASE_ATTACK
)/1000);
5650 triggered_spell_id
= 25504;
5653 // apply cooldown before cast to prevent processing itself
5655 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
5658 for ( uint32 i
= 0; i
<2; ++i
)
5659 CastCustomSpell(pVictim
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5663 // Shaman Tier 6 Trinket
5670 if (procSpell
->SpellFamilyFlags
& 0x0000000000000001LL
)
5672 triggered_spell_id
= 40465; // Lightning Bolt
5675 else if (procSpell
->SpellFamilyFlags
& 0x0000000000000080LL
)
5677 triggered_spell_id
= 40465; // Lesser Healing Wave
5680 else if (procSpell
->SpellFamilyFlags
& 0x0000001000000000LL
)
5682 triggered_spell_id
= 40466; // Stormstrike
5688 if (!roll_chance_f(chance
))
5694 // Glyph of Healing Wave
5697 // Not proc from self heals
5700 basepoints0
= triggerAmount
* damage
/ 100;
5702 triggered_spell_id
= 55533;
5709 target
= GetOwner();
5712 basepoints0
= triggerAmount
* damage
/ 100;
5713 triggered_spell_id
= 58879;
5717 // Ancestral Awakening
5718 if (dummySpell
->SpellIconID
== 3065)
5720 // TODO: frite dummy fot triggered spell
5721 triggered_spell_id
= 52759;
5722 basepoints0
= triggerAmount
* damage
/ 100;
5727 if(dummySpell
->SpellFamilyFlags
& 0x0000040000000000LL
)
5729 basepoints0
= triggerAmount
;
5731 triggered_spell_id
= 379;
5734 // Improved Water Shield
5735 if (dummySpell
->SpellIconID
== 2287)
5737 // Lesser Healing Wave need aditional 60% roll
5738 if (procSpell
->SpellFamilyFlags
& 0x0000000000000080LL
&& !roll_chance_i(60))
5740 // lookup water shield
5741 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
5742 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
5744 if( (*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
5745 (*itr
)->GetSpellProto()->SpellFamilyFlags
& 0x0000002000000000LL
)
5747 uint32 spell
= (*itr
)->GetSpellProto()->EffectTriggerSpell
[(*itr
)->GetEffIndex()];
5748 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
5749 if ((*itr
)->DropAuraCharge())
5750 RemoveAurasDueToSpell((*itr
)->GetId());
5757 // Lightning Overload
5758 if (dummySpell
->SpellIconID
== 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura
5760 if(!procSpell
|| GetTypeId() != TYPEID_PLAYER
|| !pVictim
)
5763 // custom cooldown processing case
5764 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(dummySpell
->Id
))
5768 // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost
5769 switch (procSpell
->Id
)
5772 case 403: spellId
= 45284; break; // Rank 1
5773 case 529: spellId
= 45286; break; // Rank 2
5774 case 548: spellId
= 45287; break; // Rank 3
5775 case 915: spellId
= 45288; break; // Rank 4
5776 case 943: spellId
= 45289; break; // Rank 5
5777 case 6041: spellId
= 45290; break; // Rank 6
5778 case 10391: spellId
= 45291; break; // Rank 7
5779 case 10392: spellId
= 45292; break; // Rank 8
5780 case 15207: spellId
= 45293; break; // Rank 9
5781 case 15208: spellId
= 45294; break; // Rank 10
5782 case 25448: spellId
= 45295; break; // Rank 11
5783 case 25449: spellId
= 45296; break; // Rank 12
5784 case 49237: spellId
= 49239; break; // Rank 13
5785 case 49238: spellId
= 49240; break; // Rank 14
5787 case 421: spellId
= 45297; break; // Rank 1
5788 case 930: spellId
= 45298; break; // Rank 2
5789 case 2860: spellId
= 45299; break; // Rank 3
5790 case 10605: spellId
= 45300; break; // Rank 4
5791 case 25439: spellId
= 45301; break; // Rank 5
5792 case 25442: spellId
= 45302; break; // Rank 6
5793 case 49268: spellId
= 49270; break; // Rank 7
5794 case 49269: spellId
= 49271; break; // Rank 8
5796 sLog
.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell
->Id
);
5799 // No thread generated mod
5800 // TODO: exist special flag in spell attributes for this, need found and use!
5801 SpellModifier
*mod
= new SpellModifier
;
5802 mod
->op
= SPELLMOD_THREAT
;
5804 mod
->type
= SPELLMOD_PCT
;
5805 mod
->spellId
= dummySpell
->Id
;
5806 mod
->mask
= 0x0000000000000003LL
;
5808 ((Player
*)this)->AddSpellMod(mod
, true);
5810 // Remove cooldown (Chain Lightning - have Category Recovery time)
5811 if (procSpell
->SpellFamilyFlags
& 0x0000000000000002LL
)
5812 ((Player
*)this)->RemoveSpellCooldown(spellId
);
5814 CastSpell(pVictim
, spellId
, true, castItem
, triggeredByAura
);
5816 ((Player
*)this)->AddSpellMod(mod
, false);
5818 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5819 ((Player
*)this)->AddSpellCooldown(dummySpell
->Id
,0,time(NULL
) + cooldown
);
5824 if(dummySpell
->SpellIconID
== 3059)
5826 // lookup Lightning Shield
5827 AuraList
const& vs
= GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL
);
5828 for(AuraList::const_iterator itr
= vs
.begin(); itr
!= vs
.end(); ++itr
)
5830 if( (*itr
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_SHAMAN
&&
5831 (*itr
)->GetSpellProto()->SpellFamilyFlags
& 0x0000000000000400LL
)
5834 switch ((*itr
)->GetId())
5836 case 324: spell
= 26364; break;
5837 case 325: spell
= 26365; break;
5838 case 905: spell
= 26366; break;
5839 case 945: spell
= 26367; break;
5840 case 8134: spell
= 26369; break;
5841 case 10431: spell
= 26370; break;
5842 case 10432: spell
= 26363; break;
5843 case 25469: spell
= 26371; break;
5844 case 25472: spell
= 26372; break;
5845 case 49280: spell
= 49278; break;
5846 case 49281: spell
= 49279; break;
5850 CastSpell(this, spell
, true, castItem
, triggeredByAura
);
5851 if ((*itr
)->DropAuraCharge())
5852 RemoveAurasDueToSpell((*itr
)->GetId());
5861 case SPELLFAMILY_DEATHKNIGHT
:
5864 if (dummySpell
->SpellIconID
== 2636)
5866 if (GetTypeId() != TYPEID_PLAYER
|| !((Player
*)this)->isHonorOrXPTarget(pVictim
))
5868 basepoints0
= triggerAmount
* damage
/ 100;
5869 triggered_spell_id
= 53168;
5873 if (dummySpell
->SpellIconID
== 2664)
5875 basepoints0
= triggerAmount
;
5876 triggered_spell_id
= 50163;
5880 // Dancing Rune Weapon
5881 if (dummySpell
->Id
== 49028)
5883 // 1 dummy aura for dismiss rune blade
5886 // TODO: wite script for this "fights on its own, doing the same attacks"
5887 // NOTE: Trigger here on every attack and spell cast
5891 if (dummySpell
->Id
== 49005)
5893 // TODO: need more info (cooldowns/PPM)
5894 triggered_spell_id
= 50424;
5898 if (dummySpell
->SpellFamilyFlags
& 0x0000000000010000LL
)
5900 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
5901 triggered_spell_id
= 50181;
5906 if (dummySpell
->SpellIconID
== 2709)
5908 basepoints0
= triggerAmount
* damage
/ 100;
5909 triggered_spell_id
= 51460;
5912 // Runic Power Back on Snare/Root
5913 if (dummySpell
->Id
== 61257)
5915 // only for spells and hit/crit (trigger start always) and not start from self casted spells
5916 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
5918 // Need snare or root mechanic
5919 if (!(GetAllSpellMechanicMask(procSpell
) & ((1<<MECHANIC_ROOT
)|(1<<MECHANIC_SNARE
))))
5921 triggered_spell_id
= 61258;
5926 if (dummySpell
->SpellIconID
== 1614)
5928 if (!roll_chance_f(GetUnitCriticalChance(BASE_ATTACK
, pVictim
)))
5930 basepoints0
= triggerAmount
* damage
/ 100;
5931 triggered_spell_id
= 50526;
5940 // processed charge only counting case
5941 if(!triggered_spell_id
)
5944 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
5948 sLog
.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell
->Id
,triggered_spell_id
);
5953 if(!target
|| target
!=this && !target
->isAlive())
5956 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
5960 CastCustomSpell(target
,triggered_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
5962 CastSpell(target
,triggered_spell_id
,true,castItem
,triggeredByAura
);
5964 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
5965 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
5970 bool Unit::HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggeredByAura
, SpellEntry
const *procSpell
, uint32 procFlags
, uint32 procEx
, uint32 cooldown
)
5972 // Get triggered aura spell info
5973 SpellEntry
const* auraSpellInfo
= triggeredByAura
->GetSpellProto();
5975 // Basepoints of trigger aura
5976 int32 triggerAmount
= triggeredByAura
->GetModifier()->m_amount
;
5978 // Set trigger spell id, target, custom basepoints
5979 uint32 trigger_spell_id
= auraSpellInfo
->EffectTriggerSpell
[triggeredByAura
->GetEffIndex()];
5980 Unit
* target
= NULL
;
5981 int32 basepoints0
= 0;
5983 if(triggeredByAura
->GetModifier()->m_auraname
== SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
)
5984 basepoints0
= triggerAmount
;
5986 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
5987 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
5989 // Try handle uncnown trigger spells
5990 if (sSpellStore
.LookupEntry(trigger_spell_id
)==NULL
)
5992 switch (auraSpellInfo
->SpellFamilyName
)
5994 case SPELLFAMILY_GENERIC
:
5995 //if (auraSpellInfo->Id==59532) // Abandon Passengers on Poly
5996 //if (auraSpellInfo->Id==54775) // Abandon Vehicle on Poly
5997 //if (auraSpellInfo->Id==34082) // Advantaged State (DND)
5998 if (auraSpellInfo
->Id
== 23780) // Aegis of Preservation (Aegis of Preservation trinket)
5999 trigger_spell_id
= 23781;
6000 //else if (auraSpellInfo->Id==43504) // Alterac Valley OnKill Proc Aura
6001 //else if (auraSpellInfo->Id == 48876) // Beast's Mark
6003 // trigger_spell_id = 48877;
6005 //else if (auraSpellInfo->Id == 59237) // Beast's Mark
6007 // trigger_spell_id = 59233;
6009 //else if (auraSpellInfo->Id==46939) // Black Bow of the Betrayer
6011 // trigger_spell_id = 29471; // gain mana
6012 // 27526; // drain mana if possible
6014 //else if (auraSpellInfo->Id==50844) // Blood Mirror
6015 //else if (auraSpellInfo->Id==54476) // Blood Presence
6016 //else if (auraSpellInfo->Id==50689) // Blood Presence (Rank 1)
6017 //else if (auraSpellInfo->Id==37030) // Chaotic Temperament
6018 //else if (auraSpellInfo->Id==52856) // Charge
6019 else if (auraSpellInfo
->Id
==43820) // Charm of the Witch Doctor (Amani Charm of the Witch Doctor trinket)
6021 // Pct value stored in dummy
6022 basepoints0
= pVictim
->GetCreateHealth() * auraSpellInfo
->EffectBasePoints
[1] / 100;
6026 //else if (auraSpellInfo->Id==41248) // Consuming Strikes
6027 // trigger_spell_id = 41249;
6028 //else if (auraSpellInfo->Id==45205) // Copy Offhand Weapon
6029 //else if (auraSpellInfo->Id==57594) // Copy Ranged Weapon
6030 //else if (auraSpellInfo->Id==41054) // Copy Weapon
6031 // trigger_spell_id = 41055;
6032 //else if (auraSpellInfo->Id==45343) // Dark Flame Aura
6033 //else if (auraSpellInfo->Id==47300) // Dark Flame Aura
6034 else if (auraSpellInfo
->Id
==57345) // Darkmoon Card: Greatness
6038 if (GetStat(STAT_STRENGTH
) > stat
) { trigger_spell_id
= 60229;stat
= GetStat(STAT_STRENGTH
); }
6040 if (GetStat(STAT_AGILITY
) > stat
) { trigger_spell_id
= 60233;stat
= GetStat(STAT_AGILITY
); }
6042 if (GetStat(STAT_INTELLECT
)> stat
) { trigger_spell_id
= 60234;stat
= GetStat(STAT_INTELLECT
);}
6044 if (GetStat(STAT_SPIRIT
) > stat
) { trigger_spell_id
= 60235;stat
= GetStat(STAT_SPIRIT
); }
6046 //else if (auraSpellInfo->Id==31255) // Deadly Swiftness (Rank 1)
6047 //else if (auraSpellInfo->Id==5301) // Defensive State (DND)
6048 //else if (auraSpellInfo->Id==13358) // Defensive State (DND)
6049 //else if (auraSpellInfo->Id==16092) // Defensive State (DND)
6050 //else if (auraSpellInfo->Id==24949) // Defensive State 2 (DND)
6051 //else if (auraSpellInfo->Id==40329) // Demo Shout Sensor
6052 else if (auraSpellInfo
->Id
== 33896) // Desperate Defense (Stonescythe Whelp, Stonescythe Alpha, Stonescythe Ambusher)
6053 trigger_spell_id
= 33898;
6054 //else if (auraSpellInfo->Id==18943) // Double Attack
6055 //else if (auraSpellInfo->Id==19194) // Double Attack
6056 //else if (auraSpellInfo->Id==19817) // Double Attack
6057 //else if (auraSpellInfo->Id==19818) // Double Attack
6058 //else if (auraSpellInfo->Id==22835) // Drunken Rage
6059 // trigger_spell_id = 14822;
6061 else if (auraSpellInfo->SpellIconID==191) // Elemental Response
6063 switch (auraSpellInfo->Id && auraSpellInfo->AttributesEx==0)
6072 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Elemental Response",auraSpellInfo->Id);
6075 //This generic aura self-triggers a different spell for each school of magic that lands on the wearer:
6076 switch (procSpell->School)
6078 case SPELL_SCHOOL_FIRE: trigger_spell_id = 34192; break;
6079 case SPELL_SCHOOL_FROST: trigger_spell_id = 34193; break;
6080 case SPELL_SCHOOL_ARCANE:trigger_spell_id = 34194; break;
6081 case SPELL_SCHOOL_NATURE:trigger_spell_id = 34195; break;
6082 case SPELL_SCHOOL_SHADOW:trigger_spell_id = 34196; break;
6083 case SPELL_SCHOOL_HOLY: trigger_spell_id = 34197; break;
6084 case SPELL_SCHOOL_NORMAL:trigger_spell_id = 34198; break;
6086 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u Elemental Response wrong school",auraSpellInfo->Id);
6091 //else if (auraSpellInfo->Id==40364) // Entangling Roots Sensor
6092 //else if (auraSpellInfo->Id==33207) // Gossip NPC Periodic - Fidget
6093 //else if (auraSpellInfo->Id==50051) // Ethereal Pet Aura
6094 //else if (auraSpellInfo->Id==35321) // Gushing Wound
6095 //else if (auraSpellInfo->Id==38363) // Gushing Wound
6096 //else if (auraSpellInfo->Id==39215) // Gushing Wound
6097 //else if (auraSpellInfo->Id==44527) // Hate Monster (Spar Buddy) (30 sec)
6098 //else if (auraSpellInfo->Id==44819) // Hate Monster (Spar Buddy) (>30% Health)
6099 //else if (auraSpellInfo->Id==44526) // Hate Monster (Spar) (30 sec)
6100 //else if (auraSpellInfo->Id==44820) // Hate Monster (Spar) (<30%)
6101 //else if (auraSpellInfo->Id==49059) // Horde, Hate Monster (Spar Buddy) (>30% Health)
6102 //else if (auraSpellInfo->Id==40250) // Improved Duration
6103 //else if (auraSpellInfo->Id==59288) // Infra-Green Shield
6104 //else if (auraSpellInfo->Id==54072) // Knockback Ball Passive
6105 else if (auraSpellInfo
->Id
==27522 || auraSpellInfo
->Id
==40336)
6106 // Mana Drain Trigger
6108 // On successful melee or ranged attack gain $29471s1 mana and if possible drain $27526s1 mana from the target.
6109 if (this && this->isAlive())
6110 CastSpell(this, 29471, true, castItem
, triggeredByAura
);
6111 if (pVictim
&& pVictim
->isAlive())
6112 CastSpell(pVictim
, 27526, true, castItem
, triggeredByAura
);
6115 //else if (auraSpellInfo->Id==55580) // Mana Link
6116 //else if (auraSpellInfo->Id==45903) // Offensive State
6117 //else if (auraSpellInfo->Id==44326) // Pure Energy Passive
6118 //else if (auraSpellInfo->Id==43453) // Rune Ward
6119 //else if (auraSpellInfo->Id== 7137) // Shadow Charge (Rank 1)
6120 //else if (auraSpellInfo->Id==36576) // Shaleskin (Shaleskin Flayer, Shaleskin Ripper) 30023 trigger
6121 //else if (auraSpellInfo->Id==34783) // Spell Reflection
6122 //else if (auraSpellInfo->Id==36096) // Spell Reflection
6123 //else if (auraSpellInfo->Id==57587) // Steal Ranged ()
6124 //else if (auraSpellInfo->Id==36207) // Steal Weapon
6125 //else if (auraSpellInfo->Id== 7377) // Take Immune Periodic Damage <Not Working>
6126 //else if (auraSpellInfo->Id==35205) // Vanish
6127 //else if (auraSpellInfo->Id==42730) // Woe Strike
6128 //else if (auraSpellInfo->Id==59735) // Woe Strike
6129 //else if (auraSpellInfo->Id==46146) // [PH] Ahune Spanky Hands
6131 case SPELLFAMILY_MAGE
:
6132 if (auraSpellInfo
->SpellIconID
== 2127) // Blazing Speed
6134 switch (auraSpellInfo
->Id
)
6136 case 31641: // Rank 1
6137 case 31642: // Rank 2
6138 trigger_spell_id
= 31643;
6141 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blazing Speed",auraSpellInfo
->Id
);
6146 case SPELLFAMILY_WARRIOR
:
6147 if (auraSpellInfo
->Id
== 50421) // Scent of Blood
6148 trigger_spell_id
= 50422;
6150 case SPELLFAMILY_WARLOCK
:
6153 if (auraSpellInfo
->SpellIconID
== 1137)
6155 if(!pVictim
|| !pVictim
->isAlive() || pVictim
== this || procSpell
== NULL
)
6157 // Calculate spell tick count for spells
6158 uint32 tick
= 1; // Default tick = 1
6160 // Hellfire have 15 tick
6161 if (procSpell
->SpellFamilyFlags
&0x0000000000000040LL
)
6163 // Rain of Fire have 4 tick
6164 else if (procSpell
->SpellFamilyFlags
&0x0000000000000020LL
)
6169 // Calculate chance = baseChance / tick
6171 switch (auraSpellInfo
->Id
)
6173 case 18096: chance
= 13.0f
/ tick
; break;
6174 case 18073: chance
= 26.0f
/ tick
; break;
6177 if (!roll_chance_f(chance
))
6180 trigger_spell_id
= 18093;
6183 else if (auraSpellInfo
->SpellFamilyFlags
& 0x0000000000004000LL
)
6185 Unit::AuraList
const& mAddFlatModifier
= GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER
);
6186 for(Unit::AuraList::const_iterator i
= mAddFlatModifier
.begin(); i
!= mAddFlatModifier
.end(); ++i
)
6188 if ((*i
)->GetModifier()->m_miscvalue
== SPELLMOD_CHANCE_OF_SUCCESS
&& (*i
)->GetSpellProto()->SpellIconID
== 113)
6190 int32 value2
= CalculateSpellDamage((*i
)->GetSpellProto(),2,(*i
)->GetSpellProto()->EffectBasePoints
[2],this);
6192 CastCustomSpell(this, 18371, &basepoints0
, NULL
, NULL
, true, castItem
, triggeredByAura
);
6196 // Not remove charge (aura removed on death in any cases)
6197 // Need for correct work Drain Soul SPELL_AURA_CHANNEL_DEATH_ITEM aura
6200 // Nether Protection
6201 else if (auraSpellInfo
->SpellIconID
== 1985)
6205 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
6207 case SPELL_SCHOOL_NORMAL
:
6208 case SPELL_SCHOOL_HOLY
:
6209 return false; // ignore
6210 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 54371; break;
6211 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 54375; break;
6212 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 54372; break;
6213 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 54374; break;
6214 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
6221 case SPELLFAMILY_PRIEST
:
6223 // Greater Heal Refund
6224 if (auraSpellInfo
->Id
==37594)
6225 trigger_spell_id
= 37595;
6227 else if (auraSpellInfo
->SpellIconID
== 1875)
6229 switch (auraSpellInfo
->Id
)
6231 case 27811: trigger_spell_id
= 27813; break;
6232 case 27815: trigger_spell_id
= 27817; break;
6233 case 27816: trigger_spell_id
= 27818; break;
6235 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR", auraSpellInfo
->Id
);
6238 basepoints0
= damage
* triggerAmount
/ 100 / 3;
6243 case SPELLFAMILY_DRUID
:
6245 // Druid Forms Trinket
6246 if (auraSpellInfo
->Id
==37336)
6250 case FORM_NONE
: trigger_spell_id
= 37344;break;
6251 case FORM_CAT
: trigger_spell_id
= 37341;break;
6253 case FORM_DIREBEAR
: trigger_spell_id
= 37340;break;
6254 case FORM_TREE
: trigger_spell_id
= 37342;break;
6255 case FORM_MOONKIN
: trigger_spell_id
= 37343;break;
6260 //else if (auraSpellInfo->Id==40363)// Entangling Roots ()
6261 // trigger_spell_id = ????;
6262 // Leader of the Pack
6263 else if (auraSpellInfo
->Id
== 24932)
6265 if (triggerAmount
== 0)
6267 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
6268 trigger_spell_id
= 34299;
6272 case SPELLFAMILY_HUNTER
:
6274 case SPELLFAMILY_PALADIN
:
6278 if (auraSpellInfo->SpellIconID == 2137)
6280 switch (auraSpellInfo->Id)
6282 case 31828: // Rank 1
6283 case 31829: // Rank 2
6284 case 31830: // Rank 3
6287 sLog.outError("Unit::HandleProcTriggerSpell: Spell %u miss posibly Blessed Life", auraSpellInfo->Id);
6293 if (auraSpellInfo
->Id
==37705)
6295 trigger_spell_id
= 37706;
6299 if (auraSpellInfo
->Id
==60510)
6301 trigger_spell_id
= 60515;
6305 else if (auraSpellInfo
->SpellIconID
==241)
6309 // procspell is triggered spell but we need mana cost of original casted spell
6310 uint32 originalSpellId
= procSpell
->Id
;
6312 if(procSpell
->SpellFamilyFlags
& 0x0001000000000000LL
)
6314 switch(procSpell
->Id
)
6316 case 25914: originalSpellId
= 20473; break;
6317 case 25913: originalSpellId
= 20929; break;
6318 case 25903: originalSpellId
= 20930; break;
6319 case 27175: originalSpellId
= 27174; break;
6320 case 33074: originalSpellId
= 33072; break;
6321 case 48820: originalSpellId
= 48824; break;
6322 case 48821: originalSpellId
= 48825; break;
6324 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell
->Id
);
6328 SpellEntry
const *originalSpell
= sSpellStore
.LookupEntry(originalSpellId
);
6331 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId
);
6334 // percent stored in effect 1 (class scripts) base points
6335 int32 cost
= originalSpell
->manaCost
+ originalSpell
->ManaCostPercentage
* GetCreateMana() / 100;
6336 basepoints0
= cost
*auraSpellInfo
->CalculateSimpleValue(1)/100;
6337 trigger_spell_id
= 20272;
6340 // Lightning Capacitor
6341 else if (auraSpellInfo
->Id
==37657)
6343 if(!pVictim
|| !pVictim
->isAlive())
6346 CastSpell(this, 37658, true, NULL
, triggeredByAura
);
6348 Aura
* dummy
= GetDummyAura(37658);
6349 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
6350 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
6353 RemoveAurasDueToSpell(37658);
6354 trigger_spell_id
= 37661;
6357 // Thunder Capacitor
6358 else if (auraSpellInfo
->Id
== 54841)
6360 if(!pVictim
|| !pVictim
->isAlive())
6363 CastSpell(this, 54842, true, NULL
, triggeredByAura
);
6366 Aura
* dummy
= GetDummyAura(54842);
6367 // release at 3 aura in stack (cont contain in basepoint of trigger aura)
6368 if(!dummy
|| dummy
->GetStackAmount() < triggerAmount
)
6371 RemoveAurasDueToSpell(54842);
6372 trigger_spell_id
= 54843;
6377 case SPELLFAMILY_SHAMAN
:
6379 // Lightning Shield (overwrite non existing triggered spell call in spell.dbc
6380 if(auraSpellInfo
->SpellFamilyFlags
& 0x0000000000000400)
6382 switch(auraSpellInfo
->Id
)
6385 trigger_spell_id
= 26364; break;
6387 trigger_spell_id
= 26365; break;
6389 trigger_spell_id
= 26366; break;
6391 trigger_spell_id
= 26367; break;
6392 case 8134: // Rank 5
6393 trigger_spell_id
= 26369; break;
6394 case 10431: // Rank 6
6395 trigger_spell_id
= 26370; break;
6396 case 10432: // Rank 7
6397 trigger_spell_id
= 26363; break;
6398 case 25469: // Rank 8
6399 trigger_spell_id
= 26371; break;
6400 case 25472: // Rank 9
6401 trigger_spell_id
= 26372; break;
6402 case 49280: // Rank 10
6403 trigger_spell_id
= 49278; break;
6404 case 49281: // Rank 11
6405 trigger_spell_id
= 49279; break;
6407 sLog
.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield", auraSpellInfo
->Id
);
6411 // Lightning Shield (The Ten Storms set)
6412 else if (auraSpellInfo
->Id
== 23551)
6414 trigger_spell_id
= 23552;
6417 // Damage from Lightning Shield (The Ten Storms set)
6418 else if (auraSpellInfo
->Id
== 23552)
6419 trigger_spell_id
= 27635;
6420 // Mana Surge (The Earthfury set)
6421 else if (auraSpellInfo
->Id
== 23572)
6425 basepoints0
= procSpell
->manaCost
* 35 / 100;
6426 trigger_spell_id
= 23571;
6429 // Nature's Guardian
6430 else if (auraSpellInfo
->SpellIconID
== 2013)
6432 // Check health condition - should drop to less 30% (damage deal after this!)
6433 if (!(10*(int32(GetHealth() - damage
)) < 3 * GetMaxHealth()))
6436 if(pVictim
&& pVictim
->isAlive())
6437 pVictim
->getThreatManager().modifyThreatPercent(this,-10);
6439 basepoints0
= triggerAmount
* GetMaxHealth() / 100;
6440 trigger_spell_id
= 31616;
6445 case SPELLFAMILY_DEATHKNIGHT
:
6448 if (auraSpellInfo
->SpellIconID
== 1930)
6452 switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell
)))
6454 case SPELL_SCHOOL_NORMAL
:
6455 return false; // ignore
6456 case SPELL_SCHOOL_HOLY
: trigger_spell_id
= 50490; break;
6457 case SPELL_SCHOOL_FIRE
: trigger_spell_id
= 50362; break;
6458 case SPELL_SCHOOL_NATURE
: trigger_spell_id
= 50488; break;
6459 case SPELL_SCHOOL_FROST
: trigger_spell_id
= 50485; break;
6460 case SPELL_SCHOOL_SHADOW
: trigger_spell_id
= 50489; break;
6461 case SPELL_SCHOOL_ARCANE
: trigger_spell_id
= 54373; break;
6467 else if (auraSpellInfo
->Id
== 48266)
6469 if (GetTypeId() != TYPEID_PLAYER
)
6471 if (!((Player
*)this)->isHonorOrXPTarget(pVictim
))
6473 trigger_spell_id
= 50475;
6474 basepoints0
= damage
* triggerAmount
/ 100;
6483 // All ok. Check current trigger spell
6484 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(trigger_spell_id
);
6485 if ( triggerEntry
== NULL
)
6487 // Not cast unknown spell
6488 // sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex());
6492 // not allow proc extra attack spell at extra attack
6493 if( m_extraAttacks
&& IsSpellHaveEffect(triggerEntry
, SPELL_EFFECT_ADD_EXTRA_ATTACKS
) )
6496 // Costum requirements (not listed in procEx) Warning! damage dealing after this
6497 // Custom triggered spells
6498 switch (auraSpellInfo
->Id
)
6500 // Persistent Shield (Scarab Brooch trinket)
6501 // This spell originally trigger 13567 - Dummy Trigger (vs dummy efect)
6504 basepoints0
= damage
* 15 / 100;
6506 trigger_spell_id
= 26470;
6512 // When your health drops below 20% ....
6513 if (GetHealth() - damage
> GetMaxHealth() / 5 || GetHealth() < GetMaxHealth() / 5)
6517 // Deadly Swiftness (Rank 1)
6520 // whenever you deal damage to a target who is below 20% health.
6521 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() / 5)
6525 trigger_spell_id
= 22588;
6527 // Greater Heal Refund (Avatar Raiment set)
6530 // Not give if target alredy have full health
6531 if (pVictim
->GetHealth() == pVictim
->GetMaxHealth())
6533 // If your Greater Heal brings the target to full health, you gain $37595s1 mana.
6534 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
6538 // Bonus Healing (Crystal Spire of Karabor mace)
6541 // If your target is below $s1% health
6542 if (pVictim
->GetHealth() > pVictim
->GetMaxHealth() * triggerAmount
/ 100)
6546 // Evasive Maneuvers (Commendation of Kael`thas trinket)
6549 // reduce you below $s1% health
6550 if (GetHealth() - damage
> GetMaxHealth() * triggerAmount
/ 100)
6554 // Rapid Recuperation
6558 // This effect only from Rapid Fire (ability cast)
6559 if (!(procSpell
->SpellFamilyFlags
& 0x0000000000000020LL
))
6565 // Costum basepoints/target for exist spell
6566 // dummy basepoints or other customs
6567 switch(trigger_spell_id
)
6569 // Cast positive spell on enemy target
6570 case 7099: // Curse of Mending
6571 case 39647: // Curse of Mending
6572 case 29494: // Temptation
6573 case 20233: // Improved Lay on Hands (cast on target)
6578 // Combo points add triggers (need add combopoint only for main tatget, and after possible combopoints reset)
6579 case 15250: // Rogue Setup
6581 if(!pVictim
|| pVictim
!= getVictim()) // applied only for main target
6583 break; // continue normal case
6585 // Finish movies that add combo
6586 case 14189: // Seal Fate (Netherblade set)
6587 case 14157: // Ruthlessness
6589 // Need add combopoint AFTER finish movie (or they dropped in finish phase)
6592 // Bloodthirst (($m/100)% of max health)
6595 basepoints0
= int32(GetMaxHealth() * triggerAmount
/ 100);
6598 // Shamanistic Rage triggered spell
6601 basepoints0
= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * triggerAmount
/ 100);
6604 // Enlightenment (trigger only from mana cost spells)
6607 if(!procSpell
|| procSpell
->powerType
!=POWER_MANA
|| procSpell
->manaCost
==0 && procSpell
->ManaCostPercentage
==0 && procSpell
->manaCostPerlevel
==0)
6616 // For trigger from Blizzard need exist Improved Blizzard
6617 if (procSpell
->SpellFamilyName
==SPELLFAMILY_MAGE
&& procSpell
->SpellFamilyFlags
& 0x0000000000000080LL
)
6620 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
6621 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
6623 int32 script
= (*i
)->GetModifier()->m_miscvalue
;
6624 if(script
==836 || script
==988 || script
==989)
6638 if (procSpell
== 0 || !(procEx
& (PROC_EX_NORMAL_HIT
|PROC_EX_CRITICAL_HIT
)) || this == pVictim
)
6641 // Need stun, fear or silence mechanic
6642 if (!(GetAllSpellMechanicMask(procSpell
) & ((1<<MECHANIC_SILENCE
)|(1<<MECHANIC_STUN
)|(1<<MECHANIC_FEAR
))))
6646 // Burning Determination
6651 // Need Interrupt or Silenced mechanic
6652 if (!(GetAllSpellMechanicMask(procSpell
) & ((1<<MECHANIC_INTERRUPT
)|(1<<MECHANIC_SILENCE
))))
6659 // Proc only from trap activation (from periodic proc another aura of this spell)
6660 if (!(procFlags
& PROC_FLAG_ON_TRAP_ACTIVATION
) || !roll_chance_i(triggerAmount
))
6666 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(trigger_spell_id
))
6669 // try detect target manually if not set
6670 if ( target
== NULL
)
6671 target
= !(procFlags
& PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
) && IsPositiveSpell(trigger_spell_id
) ? this : pVictim
;
6674 if(!target
|| target
!=this && !target
->isAlive())
6678 CastCustomSpell(target
,trigger_spell_id
,&basepoints0
,NULL
,NULL
,true,castItem
,triggeredByAura
);
6680 CastSpell(target
,trigger_spell_id
,true,castItem
,triggeredByAura
);
6682 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6683 ((Player
*)this)->AddSpellCooldown(trigger_spell_id
,0,time(NULL
) + cooldown
);
6688 bool Unit::HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32 damage
, Aura
*triggeredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
)
6690 int32 scriptId
= triggeredByAura
->GetModifier()->m_miscvalue
;
6692 if(!pVictim
|| !pVictim
->isAlive())
6695 Item
* castItem
= triggeredByAura
->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER
6696 ? ((Player
*)this)->GetItemByGuid(triggeredByAura
->GetCastItemGUID()) : NULL
;
6698 uint32 triggered_spell_id
= 0;
6702 case 836: // Improved Blizzard (Rank 1)
6704 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
6706 triggered_spell_id
= 12484;
6709 case 988: // Improved Blizzard (Rank 2)
6711 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
6713 triggered_spell_id
= 12485;
6716 case 989: // Improved Blizzard (Rank 3)
6718 if (!procSpell
|| procSpell
->SpellVisual
[0]!=9487)
6720 triggered_spell_id
= 12486;
6723 case 4086: // Improved Mend Pet (Rank 1)
6724 case 4087: // Improved Mend Pet (Rank 2)
6726 int32 chance
= triggeredByAura
->GetSpellProto()->EffectBasePoints
[triggeredByAura
->GetEffIndex()];
6727 if(!roll_chance_i(chance
))
6730 triggered_spell_id
= 24406;
6733 case 4533: // Dreamwalker Raiment 2 pieces bonus
6736 if (!roll_chance_i(50))
6739 switch (pVictim
->getPowerType())
6741 case POWER_MANA
: triggered_spell_id
= 28722; break;
6742 case POWER_RAGE
: triggered_spell_id
= 28723; break;
6743 case POWER_ENERGY
: triggered_spell_id
= 28724; break;
6749 case 4537: // Dreamwalker Raiment 6 pieces bonus
6750 triggered_spell_id
= 28750; // Blessing of the Claw
6752 case 5497: // Improved Mana Gems (Serpent-Coil Braid)
6753 triggered_spell_id
= 37445; // Mana Surge
6755 case 8152: // Serendipity
6757 // if heal your target over maximum health
6758 if (pVictim
->GetHealth() + damage
< pVictim
->GetMaxHealth())
6760 int32 cost
= procSpell
->manaCost
+ procSpell
->ManaCostPercentage
* GetCreateMana() / 100;
6761 int32 basepoints0
= cost
* triggeredByAura
->GetModifier()->m_amount
/100;
6762 CastCustomSpell(this, 47762, &basepoints0
, 0, 0, true, 0, triggeredByAura
);
6768 if(!triggered_spell_id
)
6771 // standard non-dummy case
6772 SpellEntry
const* triggerEntry
= sSpellStore
.LookupEntry(triggered_spell_id
);
6776 sLog
.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id
,scriptId
);
6780 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->HasSpellCooldown(triggered_spell_id
))
6783 CastSpell(pVictim
, triggered_spell_id
, true, castItem
, triggeredByAura
);
6785 if( cooldown
&& GetTypeId()==TYPEID_PLAYER
)
6786 ((Player
*)this)->AddSpellCooldown(triggered_spell_id
,0,time(NULL
) + cooldown
);
6791 void Unit::setPowerType(Powers new_powertype
)
6793 SetByteValue(UNIT_FIELD_BYTES_0
, 3, new_powertype
);
6795 if(GetTypeId() == TYPEID_PLAYER
)
6797 if(((Player
*)this)->GetGroup())
6798 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE
);
6800 else if(((Creature
*)this)->isPet())
6802 Pet
*pet
= ((Pet
*)this);
6803 if(pet
->isControlled())
6805 Unit
*owner
= GetOwner();
6806 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
6807 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE
);
6811 switch(new_powertype
)
6817 SetMaxPower(POWER_RAGE
,GetCreatePowers(POWER_RAGE
));
6818 SetPower( POWER_RAGE
,0);
6821 SetMaxPower(POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
6822 SetPower( POWER_FOCUS
,GetCreatePowers(POWER_FOCUS
));
6825 SetMaxPower(POWER_ENERGY
,GetCreatePowers(POWER_ENERGY
));
6826 SetPower( POWER_ENERGY
,0);
6828 case POWER_HAPPINESS
:
6829 SetMaxPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
6830 SetPower(POWER_HAPPINESS
,GetCreatePowers(POWER_HAPPINESS
));
6835 FactionTemplateEntry
const* Unit::getFactionTemplateEntry() const
6837 FactionTemplateEntry
const* entry
= sFactionTemplateStore
.LookupEntry(getFaction());
6840 static uint64 guid
= 0; // prevent repeating spam same faction problem
6842 if(GetGUID() != guid
)
6844 if(GetTypeId() == TYPEID_PLAYER
)
6845 sLog
.outError("Player %s have invalid faction (faction template id) #%u", ((Player
*)this)->GetName(), getFaction());
6847 sLog
.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature
*)this)->GetCreatureInfo()->Entry
, getFaction());
6854 bool Unit::IsHostileTo(Unit
const* unit
) const
6856 // always non-hostile to self
6860 // always non-hostile to GM in GM mode
6861 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
6864 // always hostile to enemy
6865 if(getVictim()==unit
|| unit
->getVictim()==this)
6868 // test pet/charm masters instead pers/charmeds
6869 Unit
const* testerOwner
= GetCharmerOrOwner();
6870 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
6872 // always hostile to owner's enemy
6873 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
6876 // always hostile to enemy owner
6877 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
6880 // always hostile to owner of owner's enemy
6881 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
6884 Unit
const* tester
= testerOwner
? testerOwner
: this;
6885 Unit
const* target
= targetOwner
? targetOwner
: unit
;
6887 // always non-hostile to target with common owner, or to owner/pet
6891 // special cases (Duel, etc)
6892 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
6894 Player
const* pTester
= (Player
const*)tester
;
6895 Player
const* pTarget
= (Player
const*)target
;
6898 if(pTester
->duel
&& pTester
->duel
->opponent
== pTarget
&& pTester
->duel
->startTime
!= 0)
6902 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
6906 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
6910 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
))
6914 // Green/Blue (can't attack)
6915 if(pTester
->GetTeam()==pTarget
->GetTeam())
6918 // Red (can attack) if true, Blue/Yellow (can't attack) in another case
6919 return pTester
->IsPvP() && pTarget
->IsPvP();
6922 // faction base cases
6923 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
6924 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
6925 if(!tester_faction
|| !target_faction
)
6928 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
6931 // PvC forced reaction and reputation case
6932 if(tester
->GetTypeId()==TYPEID_PLAYER
)
6935 if(target_faction
->faction
)
6937 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
6938 return *force
<= REP_HOSTILE
;
6940 // if faction have reputation then hostile state for tester at 100% dependent from at_war state
6941 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
6942 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
6943 return (factionState
->Flags
& FACTION_FLAG_AT_WAR
);
6946 // CvP forced reaction and reputation case
6947 else if(target
->GetTypeId()==TYPEID_PLAYER
)
6950 if(tester_faction
->faction
)
6952 if(ReputationRank
const* force
= ((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
6953 return *force
<= REP_HOSTILE
;
6955 // apply reputation state
6956 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
6957 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
6958 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) <= REP_HOSTILE
;
6962 // common faction based case (CvC,PvC,CvP)
6963 return tester_faction
->IsHostileTo(*target_faction
);
6966 bool Unit::IsFriendlyTo(Unit
const* unit
) const
6968 // always friendly to self
6972 // always friendly to GM in GM mode
6973 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
6976 // always non-friendly to enemy
6977 if(getVictim()==unit
|| unit
->getVictim()==this)
6980 // test pet/charm masters instead pers/charmeds
6981 Unit
const* testerOwner
= GetCharmerOrOwner();
6982 Unit
const* targetOwner
= unit
->GetCharmerOrOwner();
6984 // always non-friendly to owner's enemy
6985 if(testerOwner
&& (testerOwner
->getVictim()==unit
|| unit
->getVictim()==testerOwner
))
6988 // always non-friendly to enemy owner
6989 if(targetOwner
&& (getVictim()==targetOwner
|| targetOwner
->getVictim()==this))
6992 // always non-friendly to owner of owner's enemy
6993 if(testerOwner
&& targetOwner
&& (testerOwner
->getVictim()==targetOwner
|| targetOwner
->getVictim()==testerOwner
))
6996 Unit
const* tester
= testerOwner
? testerOwner
: this;
6997 Unit
const* target
= targetOwner
? targetOwner
: unit
;
6999 // always friendly to target with common owner, or to owner/pet
7003 // special cases (Duel)
7004 if(tester
->GetTypeId()==TYPEID_PLAYER
&& target
->GetTypeId()==TYPEID_PLAYER
)
7006 Player
const* pTester
= (Player
const*)tester
;
7007 Player
const* pTarget
= (Player
const*)target
;
7010 if(pTester
->duel
&& pTester
->duel
->opponent
== target
&& pTester
->duel
->startTime
!= 0)
7014 if(pTester
->GetGroup() && pTester
->GetGroup()==pTarget
->GetGroup())
7018 if(pTarget
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
) && pTester
->HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
))
7022 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
))
7026 // Green/Blue (non-attackable)
7027 if(pTester
->GetTeam()==pTarget
->GetTeam())
7030 // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable)
7031 return !pTarget
->IsPvP();
7034 // faction base cases
7035 FactionTemplateEntry
const*tester_faction
= tester
->getFactionTemplateEntry();
7036 FactionTemplateEntry
const*target_faction
= target
->getFactionTemplateEntry();
7037 if(!tester_faction
|| !target_faction
)
7040 if(target
->isAttackingPlayer() && tester
->IsContestedGuard())
7043 // PvC forced reaction and reputation case
7044 if(tester
->GetTypeId()==TYPEID_PLAYER
)
7047 if(target_faction
->faction
)
7049 if(ReputationRank
const* force
=((Player
*)tester
)->GetReputationMgr().GetForcedRankIfAny(target_faction
))
7050 return *force
>= REP_FRIENDLY
;
7052 // if faction have reputation then friendly state for tester at 100% dependent from at_war state
7053 if(FactionEntry
const* raw_target_faction
= sFactionStore
.LookupEntry(target_faction
->faction
))
7054 if(FactionState
const* factionState
= ((Player
*)tester
)->GetReputationMgr().GetState(raw_target_faction
))
7055 return !(factionState
->Flags
& FACTION_FLAG_AT_WAR
);
7058 // CvP forced reaction and reputation case
7059 else if(target
->GetTypeId()==TYPEID_PLAYER
)
7062 if(tester_faction
->faction
)
7064 if(ReputationRank
const* force
=((Player
*)target
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
7065 return *force
>= REP_FRIENDLY
;
7067 // apply reputation state
7068 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
7069 if(raw_tester_faction
->reputationListID
>=0 )
7070 return ((Player
const*)target
)->GetReputationMgr().GetRank(raw_tester_faction
) >= REP_FRIENDLY
;
7074 // common faction based case (CvC,PvC,CvP)
7075 return tester_faction
->IsFriendlyTo(*target_faction
);
7078 bool Unit::IsHostileToPlayers() const
7080 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
7081 if(!my_faction
|| !my_faction
->faction
)
7084 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
7085 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
7088 return my_faction
->IsHostileToPlayers();
7091 bool Unit::IsNeutralToAll() const
7093 FactionTemplateEntry
const* my_faction
= getFactionTemplateEntry();
7094 if(!my_faction
|| !my_faction
->faction
)
7097 FactionEntry
const* raw_faction
= sFactionStore
.LookupEntry(my_faction
->faction
);
7098 if(raw_faction
&& raw_faction
->reputationListID
>=0 )
7101 return my_faction
->IsNeutralToAll();
7104 bool Unit::Attack(Unit
*victim
, bool meleeAttack
)
7106 if(!victim
|| victim
== this)
7109 // dead units can neither attack nor be attacked
7110 if(!isAlive() || !victim
->isAlive())
7113 // player cannot attack in mount state
7114 if(GetTypeId()==TYPEID_PLAYER
&& IsMounted())
7117 // nobody can attack GM in GM-mode
7118 if(victim
->GetTypeId()==TYPEID_PLAYER
)
7120 if(((Player
*)victim
)->isGameMaster())
7125 if(((Creature
*)victim
)->IsInEvadeMode())
7129 // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack)
7130 if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE
))
7131 RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE
);
7133 // in fighting already
7136 if (m_attacking
== victim
)
7138 // switch to melee attack from ranged/magic
7139 if( meleeAttack
&& !hasUnitState(UNIT_STAT_MELEE_ATTACKING
) )
7141 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
7142 SendAttackStart(victim
);
7148 // remove old target data
7154 // set position before any AI calls/assistance
7155 if(GetTypeId()==TYPEID_UNIT
)
7156 ((Creature
*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ());
7160 SetUInt64Value(UNIT_FIELD_TARGET
, victim
->GetGUID());
7163 addUnitState(UNIT_STAT_MELEE_ATTACKING
);
7165 m_attacking
= victim
;
7166 m_attacking
->_addAttacker(this);
7168 if(GetTypeId()==TYPEID_UNIT
)
7170 WorldPacket
data(SMSG_AI_REACTION
, 12);
7171 data
<< uint64(GetGUID());
7172 data
<< uint32(AI_REACTION_AGGRO
); // Aggro sound
7173 ((WorldObject
*)this)->SendMessageToSet(&data
, true);
7175 ((Creature
*)this)->CallAssistance();
7178 // delay offhand weapon attack to next attack time
7179 if(haveOffhandWeapon())
7180 resetAttackTimer(OFF_ATTACK
);
7183 SendAttackStart(victim
);
7188 bool Unit::AttackStop(bool targetSwitch
/*=false*/)
7193 Unit
* victim
= m_attacking
;
7195 m_attacking
->_removeAttacker(this);
7199 SetUInt64Value(UNIT_FIELD_TARGET
, 0);
7201 clearUnitState(UNIT_STAT_MELEE_ATTACKING
);
7203 InterruptSpell(CURRENT_MELEE_SPELL
);
7205 // reset only at real combat stop
7206 if(!targetSwitch
&& GetTypeId()==TYPEID_UNIT
)
7207 ((Creature
*)this)->SetNoCallAssistance(false);
7209 SendAttackStop(victim
);
7214 void Unit::CombatStop(bool cast
)
7216 if(cast
& IsNonMeleeSpellCasted(false))
7217 InterruptNonMeleeSpells(false);
7220 RemoveAllAttackers();
7221 if( GetTypeId()==TYPEID_PLAYER
)
7222 ((Player
*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel
7226 void Unit::CombatStopWithPets(bool cast
)
7229 if(Pet
* pet
= GetPet())
7230 pet
->CombatStop(cast
);
7231 if(Unit
* charm
= GetCharm())
7232 charm
->CombatStop(cast
);
7233 if(GetTypeId()==TYPEID_PLAYER
)
7235 GuardianPetList
const& guardians
= ((Player
*)this)->GetGuardians();
7236 for(GuardianPetList::const_iterator itr
= guardians
.begin(); itr
!= guardians
.end(); ++itr
)
7237 if(Unit
* guardian
= Unit::GetUnit(*this,*itr
))
7238 guardian
->CombatStop(cast
);
7242 bool Unit::isAttackingPlayer() const
7244 if(hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
7247 Pet
* pet
= GetPet();
7248 if(pet
&& pet
->isAttackingPlayer())
7251 Unit
* charmed
= GetCharm();
7252 if(charmed
&& charmed
->isAttackingPlayer())
7255 for (int8 i
= 0; i
< MAX_TOTEM
; i
++)
7259 Creature
*totem
= ObjectAccessor::GetCreature(*this, m_TotemSlot
[i
]);
7260 if(totem
&& totem
->isAttackingPlayer())
7268 void Unit::RemoveAllAttackers()
7270 while (!m_attackers
.empty())
7272 AttackerSet::iterator iter
= m_attackers
.begin();
7273 if(!(*iter
)->AttackStop())
7275 sLog
.outError("WORLD: Unit has an attacker that isn't attacking it!");
7276 m_attackers
.erase(iter
);
7281 void Unit::ModifyAuraState(AuraState flag
, bool apply
)
7283 ApplyModFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1), apply
);
7286 Unit
*Unit::GetOwner() const
7288 uint64 ownerid
= GetOwnerGUID();
7291 return ObjectAccessor::GetUnit(*this, ownerid
);
7294 Unit
*Unit::GetCharmer() const
7296 if(uint64 charmerid
= GetCharmerGUID())
7297 return ObjectAccessor::GetUnit(*this, charmerid
);
7301 Player
* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
7303 uint64 guid
= GetCharmerOrOwnerGUID();
7304 if(IS_PLAYER_GUID(guid
))
7305 return ObjectAccessor::GetPlayer(*this, guid
);
7307 return GetTypeId()==TYPEID_PLAYER
? (Player
*)this : NULL
;
7310 Pet
* Unit::GetPet() const
7312 if(uint64 pet_guid
= GetPetGUID())
7314 if(Pet
* pet
= ObjectAccessor::GetPet(pet_guid
))
7317 sLog
.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid
));
7318 const_cast<Unit
*>(this)->SetPet(0);
7324 Unit
* Unit::GetCharm() const
7326 if(uint64 charm_guid
= GetCharmGUID())
7328 if(Unit
* pet
= ObjectAccessor::GetUnit(*this, charm_guid
))
7331 sLog
.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid
));
7332 const_cast<Unit
*>(this)->SetCharm(NULL
);
7338 float Unit::GetCombatDistance( const Unit
* target
) const
7340 float radius
= target
->GetFloatValue(UNIT_FIELD_COMBATREACH
) + GetFloatValue(UNIT_FIELD_COMBATREACH
);
7341 float dx
= GetPositionX() - target
->GetPositionX();
7342 float dy
= GetPositionY() - target
->GetPositionY();
7343 float dz
= GetPositionZ() - target
->GetPositionZ();
7344 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - radius
;
7345 return ( dist
> 0 ? dist
: 0);
7348 void Unit::SetPet(Pet
* pet
)
7350 SetUInt64Value(UNIT_FIELD_SUMMON
, pet
? pet
->GetGUID() : 0);
7352 // FIXME: hack, speed must be set only at follow
7354 for(int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
7355 pet
->SetSpeed(UnitMoveType(i
), m_speed_rate
[i
], true);
7358 void Unit::SetCharm(Unit
* pet
)
7360 SetUInt64Value(UNIT_FIELD_CHARM
, pet
? pet
->GetGUID() : 0);
7362 if(GetTypeId() == TYPEID_PLAYER
)
7363 ((Player
*)this)->m_mover
= pet
? pet
: this;
7366 void Unit::UnsummonAllTotems()
7368 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
7373 Creature
*OldTotem
= ObjectAccessor::GetCreature(*this, m_TotemSlot
[i
]);
7374 if (OldTotem
&& OldTotem
->isTotem())
7375 ((Totem
*)OldTotem
)->UnSummon();
7379 void Unit::SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, bool critical
)
7382 WorldPacket
data(SMSG_SPELLHEALLOG
, (8+8+4+4+1));
7383 data
.append(pVictim
->GetPackGUID());
7384 data
.append(GetPackGUID());
7385 data
<< uint32(SpellID
);
7386 data
<< uint32(Damage
);
7387 data
<< uint32(0); // over healing?
7388 data
<< uint8(critical
? 1 : 0);
7389 data
<< uint8(0); // unused in client?
7390 SendMessageToSet(&data
, true);
7393 void Unit::SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
)
7395 WorldPacket
data(SMSG_SPELLENERGIZELOG
, (8+8+4+4+4+1));
7396 data
.append(pVictim
->GetPackGUID());
7397 data
.append(GetPackGUID());
7398 data
<< uint32(SpellID
);
7399 data
<< uint32(powertype
);
7400 data
<< uint32(Damage
);
7401 SendMessageToSet(&data
, true);
7404 uint32
Unit::SpellDamageBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
)
7406 if(!spellProto
|| !pVictim
|| damagetype
==DIRECT_DAMAGE
)
7409 // For totems get damage bonus from owner (statue isn't totem in fact)
7410 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
7412 if(Unit
* owner
= GetOwner())
7413 return owner
->SpellDamageBonus(pVictim
, spellProto
, pdamage
, damagetype
);
7416 // Taken/Done total percent damage auras
7417 float DoneTotalMod
= 1.0f
;
7418 float TakenTotalMod
= 1.0f
;
7419 int32 DoneTotal
= 0;
7420 int32 TakenTotal
= 0;
7424 if( GetTypeId() == TYPEID_UNIT
&& !((Creature
*)this)->isPet() )
7425 DoneTotalMod
*= ((Creature
*)this)->GetSpellDamageMod(((Creature
*)this)->GetCreatureInfo()->rank
);
7427 AuraList
const& mModDamagePercentDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
7428 for(AuraList::const_iterator i
= mModDamagePercentDone
.begin(); i
!= mModDamagePercentDone
.end(); ++i
)
7430 if( ((*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
)) &&
7431 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
7432 // -1 == any item class (not wand then)
7433 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
7434 // 0 == any inventory type (not wand then)
7436 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7440 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
7441 // Add flat bonus from spell damage versus
7442 DoneTotal
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS
, creatureTypeMask
);
7443 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
7444 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
7445 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
7446 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7448 // done scripted mod (take it from owner)
7449 Unit
*owner
= GetOwner();
7450 if (!owner
) owner
= this;
7451 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7452 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7454 if (!(*i
)->isAffectedOnSpell(spellProto
))
7456 switch((*i
)->GetModifier()->m_miscvalue
)
7458 case 4920: // Molten Fury
7460 case 6917: // Death's Embrace
7464 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
7465 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
7472 // effect 1 m_amount
7473 int32 maxPercent
= (*i
)->GetModifier()->m_amount
;
7474 // effect 0 m_amount
7475 int32 stepPercent
= CalculateSpellDamage((*i
)->GetSpellProto(), 0, (*i
)->GetSpellProto()->EffectBasePoints
[0], this);
7476 // count affliction effects and calc additional damage in percentage
7477 int32 modPercent
= 0;
7478 AuraMap
const& victimAuras
= pVictim
->GetAuras();
7479 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
7481 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
7482 if (m_spell
->SpellFamilyName
!= SPELLFAMILY_WARLOCK
|| !(m_spell
->SpellFamilyFlags
& 0x0004071B8044C402LL
))
7484 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
7485 if (modPercent
>= maxPercent
)
7487 modPercent
= maxPercent
;
7491 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
7494 case 6916: // Death's Embrace
7497 if (HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
))
7498 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
7500 case 5481: // Starfire Bonus
7502 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DRUID
, 0x0000000000200002LL
))
7503 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7506 case 4418: // Increased Shock Damage
7507 case 4554: // Increased Lightning Damage
7508 case 4555: // Improved Moonfire
7509 case 5142: // Increased Lightning Damage
7510 case 5147: // Improved Consecration / Libram of Resurgence
7511 case 5148: // Idol of the Shooting Star
7512 case 6008: // Increased Lightning Damage / Totem of Hex
7514 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
7522 if ((*i
)->GetSpellProto()->SpellIconID
== 2656)
7524 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
7525 DoneTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
7527 else // Tundra Stalker
7529 if (pVictim
->GetAura(SPELL_AURA_DUMMY
, SPELLFAMILY_DEATHKNIGHT
, 0x0400000000000000LL
))
7530 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7535 case 7293: // Rage of Rivendare
7537 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_DEATHKNIGHT
, 0x0200000000000000LL
))
7538 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7544 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_PRIEST
, 0x0000000000008000LL
, 0, GetGUID()))
7545 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7555 if (pVictim
->GetAura(SPELL_AURA_MOD_STALKED
, SPELLFAMILY_HUNTER
, 0x0000000000000400LL
))
7556 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7562 // Custom scripted damage
7564 if (spellProto
->SpellFamilyName
== SPELLFAMILY_MAGE
&& spellProto
->SpellIconID
== 186)
7566 if (pVictim
->isFrozen())
7567 DoneTotalMod
*= 3.0f
;
7571 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
7572 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
7573 if( (*i
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellProto
) )
7574 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7576 // .. taken pct: dummy auras
7577 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
7580 if (Aura
*dummy
= pVictim
->GetDummyAura(45182))
7582 float mod
= -((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2*4;
7583 if (mod
< dummy
->GetModifier()->m_amount
)
7584 mod
= dummy
->GetModifier()->m_amount
;
7585 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
7589 // From caster spells
7590 AuraList
const& mOwnerTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_FROM_CASTER
);
7591 for(AuraList::const_iterator i
= mOwnerTaken
.begin(); i
!= mOwnerTaken
.end(); ++i
)
7592 if( (*i
)->GetCasterGUID() == GetGUID() && (*i
)->isAffectedOnSpell(spellProto
))
7593 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7595 // Mod damage from spell mechanic
7596 uint32 mechanicMask
= GetAllSpellMechanicMask(spellProto
);
7599 AuraList
const& mDamageDoneMechanic
= pVictim
->GetAurasByType(SPELL_AURA_MOD_MECHANIC_DAMAGE_TAKEN_PERCENT
);
7600 for(AuraList::const_iterator i
= mDamageDoneMechanic
.begin();i
!= mDamageDoneMechanic
.end(); ++i
)
7601 if(mechanicMask
& uint32(1<<((*i
)->GetModifier()->m_miscvalue
)))
7602 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7605 // Taken/Done fixed damage bonus auras
7606 int32 DoneAdvertisedBenefit
= SpellBaseDamageBonus(GetSpellSchoolMask(spellProto
));
7607 int32 TakenAdvertisedBenefit
= SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
7609 // Pets just add their bonus damage to their spell damage
7610 // note that their spell damage is just gain of their own auras
7611 if (GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
7612 DoneAdvertisedBenefit
+= ((Pet
*)this)->GetBonusDamage();
7614 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
7615 // Spellmod SpellDamage
7616 float SpellModSpellDamage
= 100.0f
;
7617 if(Player
* modOwner
= GetSpellModOwner())
7618 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_SPELL_BONUS_DAMAGE
,SpellModSpellDamage
);
7619 SpellModSpellDamage
/= 100.0f
;
7621 // Check for table values
7622 SpellBonusEntry
const* bonus
= spellmgr
.GetSpellBonusData(spellProto
->Id
);
7626 if (damagetype
== DOT
)
7627 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
7629 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
7631 if (bonus
->ap_bonus
)
7632 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
) * stack
);
7634 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* SpellModSpellDamage
);
7635 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
);
7637 // Default calculation
7638 else if (DoneAdvertisedBenefit
|| TakenAdvertisedBenefit
)
7640 // Damage Done from spell damage bonus
7641 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
7642 // Damage over Time spells bonus calculation
7643 float DotFactor
= 1.0f
;
7644 if(damagetype
== DOT
)
7646 int32 DotDuration
= GetSpellDuration(spellProto
);
7650 if(DotDuration
> 30000) DotDuration
= 30000;
7651 if(!IsChanneledSpell(spellProto
)) DotFactor
= DotDuration
/ 15000.0f
;
7653 for(int j
= 0; j
< 3; j
++)
7655 if( spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& (
7656 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_DAMAGE
||
7657 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
) )
7664 if(spellProto
->EffectAmplitude
[x
] != 0)
7665 DotTicks
= DotDuration
/ spellProto
->EffectAmplitude
[x
];
7668 DoneAdvertisedBenefit
= DoneAdvertisedBenefit
* int32(stack
) / DotTicks
;
7669 TakenAdvertisedBenefit
= TakenAdvertisedBenefit
* int32(stack
) / DotTicks
;
7673 // Distribute Damage over multiple effects, reduce by AoE
7674 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
7675 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
7676 for(int j
= 0; j
< 3; ++j
)
7678 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
7679 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
7685 DoneTotal
+= int32(DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* SpellModSpellDamage
);
7686 TakenTotal
+= int32(TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
);
7689 float tmpDamage
= (pdamage
+ DoneTotal
) * DoneTotalMod
;
7690 // apply spellmod to Done damage (flat and pct)
7691 if(Player
* modOwner
= GetSpellModOwner())
7692 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, tmpDamage
);
7694 tmpDamage
= (tmpDamage
+ TakenTotal
) * TakenTotalMod
;
7696 return tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
7699 int32
Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask
)
7701 int32 DoneAdvertisedBenefit
= 0;
7704 AuraList
const& mDamageDone
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
7705 for(AuraList::const_iterator i
= mDamageDone
.begin();i
!= mDamageDone
.end(); ++i
)
7706 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0 &&
7707 (*i
)->GetSpellProto()->EquippedItemClass
== -1 &&
7708 // -1 == any item class (not wand then)
7709 (*i
)->GetSpellProto()->EquippedItemInventoryTypeMask
== 0 )
7710 // 0 == any inventory type (not wand then)
7711 DoneAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7713 if (GetTypeId() == TYPEID_PLAYER
)
7716 DoneAdvertisedBenefit
+=((Player
*)this)->GetBaseSpellDamageBonus();
7718 // Damage bonus from stats
7719 AuraList
const& mDamageDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT
);
7720 for(AuraList::const_iterator i
= mDamageDoneOfStatPercent
.begin();i
!= mDamageDoneOfStatPercent
.end(); ++i
)
7722 if((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
7724 // stat used stored in miscValueB for this aura
7725 Stats usedStat
= Stats((*i
)->GetMiscBValue());
7726 DoneAdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
7729 // ... and attack power
7730 AuraList
const& mDamageDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER
);
7731 for(AuraList::const_iterator i
=mDamageDonebyAP
.begin();i
!= mDamageDonebyAP
.end(); ++i
)
7732 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
7733 DoneAdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
7736 return DoneAdvertisedBenefit
;
7739 int32
Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
7741 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
7743 int32 TakenAdvertisedBenefit
= 0;
7744 // ..done (for creature type by mask) in taken
7745 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
7746 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
7747 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
7748 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7751 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
7752 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
7753 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
7754 TakenAdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
7756 return TakenAdvertisedBenefit
;
7759 bool Unit::isSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
)
7761 // not critting spell
7762 if((spellProto
->AttributesEx2
& SPELL_ATTR_EX2_CANT_CRIT
))
7765 float crit_chance
= 0.0f
;
7766 switch(spellProto
->DmgClass
)
7768 case SPELL_DAMAGE_CLASS_NONE
:
7770 case SPELL_DAMAGE_CLASS_MAGIC
:
7772 if (schoolMask
& SPELL_SCHOOL_MASK_NORMAL
)
7774 // For other schools
7775 else if (GetTypeId() == TYPEID_PLAYER
)
7776 crit_chance
= GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1
+ GetFirstSchoolInMask(schoolMask
));
7779 crit_chance
= m_baseSpellCritChance
;
7780 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
7785 if (!IsPositiveSpell(spellProto
->Id
))
7787 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
7788 crit_chance
+= pVictim
->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
, schoolMask
);
7789 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
7790 crit_chance
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
);
7791 // Modify by player victim resilience
7792 if (pVictim
->GetTypeId() == TYPEID_PLAYER
)
7793 crit_chance
-= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
);
7796 // scripted (increase crit chance ... against ... target by x%
7797 AuraList
const& mOverrideClassScript
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7798 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7800 if (!((*i
)->isAffectedOnSpell(spellProto
)))
7802 switch((*i
)->GetModifier()->m_miscvalue
)
7804 case 849: if (pVictim
->isFrozen()) crit_chance
+= 17.0f
; break; //Shatter Rank 1
7805 case 910: if (pVictim
->isFrozen()) crit_chance
+= 34.0f
; break; //Shatter Rank 2
7806 case 911: if (pVictim
->isFrozen()) crit_chance
+= 50.0f
; break; //Shatter Rank 3
7807 case 7917: // Glyph of Shadowburn
7808 if (pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
7809 crit_chance
+=(*i
)->GetModifier()->m_amount
;
7811 case 7997: // Renewed Hope
7813 if (pVictim
->HasAura(6788))
7814 crit_chance
+=(*i
)->GetModifier()->m_amount
;
7816 case 21: // Test of Faith
7819 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
7820 crit_chance
+=(*i
)->GetModifier()->m_amount
;
7826 // Custom crit by class
7827 switch(spellProto
->SpellFamilyName
)
7829 case SPELLFAMILY_PALADIN
:
7831 if (spellProto
->SpellFamilyFlags
& 0x0000000040000000LL
)
7833 Aura
*aura
= pVictim
->GetDummyAura(58597);
7834 if (aura
&& aura
->GetCasterGUID() == GetGUID())
7835 crit_chance
+=aura
->GetModifier()->m_amount
;
7839 case SPELLFAMILY_SHAMAN
:
7841 if (spellProto
->SpellFamilyFlags
& 0x0000100000000000LL
)
7843 if (Aura
*flameShock
= pVictim
->GetAura(SPELL_AURA_PERIODIC_DAMAGE
, SPELLFAMILY_SHAMAN
, 0x0000000010000000LL
, 0, GetGUID()))
7845 // Consume shock aura if not have Glyph of Flame Shock
7846 if (!GetAura(55447, 0))
7847 pVictim
->RemoveAurasByCasterSpell(flameShock
->GetId(), GetGUID());
7858 case SPELL_DAMAGE_CLASS_MELEE
:
7859 case SPELL_DAMAGE_CLASS_RANGED
:
7863 crit_chance
= GetUnitCriticalChance(attackType
, pVictim
);
7864 crit_chance
+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL
, schoolMask
);
7872 // only players use intelligence for critical chance computations
7873 if(Player
* modOwner
= GetSpellModOwner())
7874 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRITICAL_CHANCE
, crit_chance
);
7876 crit_chance
= crit_chance
> 0.0f
? crit_chance
: 0.0f
;
7877 if (roll_chance_f(crit_chance
))
7882 uint32
Unit::SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
7884 // Calculate critical bonus
7886 switch(spellProto
->DmgClass
)
7888 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
7889 case SPELL_DAMAGE_CLASS_RANGED
:
7890 // TODO: write here full calculation for melee/ranged spells
7891 crit_bonus
= damage
;
7894 crit_bonus
= damage
/ 2; // for spells is 50%
7898 // adds additional damage to crit_bonus (from talents)
7899 if(Player
* modOwner
= GetSpellModOwner())
7900 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_CRIT_DAMAGE_BONUS
, crit_bonus
);
7904 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
7905 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
7909 damage
+= crit_bonus
;
7914 uint32
Unit::SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
)
7916 // Calculate critical bonus
7918 switch(spellProto
->DmgClass
)
7920 case SPELL_DAMAGE_CLASS_MELEE
: // for melee based spells is 100%
7921 case SPELL_DAMAGE_CLASS_RANGED
:
7922 // TODO: write here full calculation for melee/ranged spells
7923 crit_bonus
= damage
;
7926 crit_bonus
= damage
/ 2; // for spells is 50%
7930 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplier(SPELL_AURA_MOD_CRITICAL_HEALING_BONUS
));
7934 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
7935 crit_bonus
= int32(crit_bonus
* GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS
, creatureTypeMask
));
7939 damage
+= crit_bonus
;
7944 uint32
Unit::SpellHealingBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 healamount
, DamageEffectType damagetype
, uint32 stack
)
7946 // No heal amount for this class spells
7947 if (spellProto
->DmgClass
== SPELL_DAMAGE_CLASS_NONE
)
7950 // For totems get healing bonus from owner (statue isn't totem in fact)
7951 if( GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->isTotem() && ((Totem
*)this)->GetTotemType()!=TOTEM_STATUE
)
7952 if(Unit
* owner
= GetOwner())
7953 return owner
->SpellHealingBonus(pVictim
, spellProto
, healamount
, damagetype
, stack
);
7956 // Taken/Done total percent damage auras
7957 float DoneTotalMod
= 1.0f
;
7958 float TakenTotalMod
= 1.0f
;
7959 int32 DoneTotal
= 0;
7960 int32 TakenTotal
= 0;
7962 // Healing done percent
7963 AuraList
const& mHealingDonePct
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT
);
7964 for(AuraList::const_iterator i
= mHealingDonePct
.begin();i
!= mHealingDonePct
.end(); ++i
)
7965 DoneTotalMod
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
7967 // done scripted mod (take it from owner)
7968 Unit
*owner
= GetOwner();
7969 if (!owner
) owner
= this;
7970 AuraList
const& mOverrideClassScript
= owner
->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
7971 for(AuraList::const_iterator i
= mOverrideClassScript
.begin(); i
!= mOverrideClassScript
.end(); ++i
)
7973 if (!(*i
)->isAffectedOnSpell(spellProto
))
7975 switch((*i
)->GetModifier()->m_miscvalue
)
7977 case 4415: // Increased Rejuvenation Healing
7979 case 3736: // Hateful Totem of the Third Wind / Increased Lesser Healing Wave / LK Arena (4/5/6) Totem of the Third Wind / Savage Totem of the Third Wind
7980 DoneTotal
+=(*i
)->GetModifier()->m_amount
;
7982 case 7997: // Renewed Hope
7984 if (pVictim
->HasAura(6788))
7985 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
7987 case 21: // Test of Faith
7990 if (pVictim
->GetHealth() < pVictim
->GetMaxHealth()/2)
7991 DoneTotalMod
*=((*i
)->GetModifier()->m_amount
+ 100.0f
)/100.0f
;
7993 case 7798: // Glyph of Regrowth
7995 if (pVictim
->GetAura(SPELL_AURA_PERIODIC_HEAL
, SPELLFAMILY_DRUID
, 0x0000000000000040LL
))
7996 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
7999 case 8477: // Nourish Heal Boost
8001 int32 stepPercent
= (*i
)->GetModifier()->m_amount
;
8002 int32 modPercent
= 0;
8003 AuraMap
const& victimAuras
= pVictim
->GetAuras();
8004 for (AuraMap::const_iterator itr
= victimAuras
.begin(); itr
!= victimAuras
.end(); ++itr
)
8006 if (itr
->second
->GetCasterGUID()!=GetGUID())
8008 SpellEntry
const* m_spell
= itr
->second
->GetSpellProto();
8009 if ( m_spell
->SpellFamilyName
!= SPELLFAMILY_DRUID
||
8010 !(m_spell
->SpellFamilyFlags
& 0x0000001000000050LL
))
8012 modPercent
+= stepPercent
* itr
->second
->GetStackAmount();
8014 DoneTotalMod
*= (modPercent
+100.0f
)/100.0f
;
8017 case 7871: // Glyph of Lesser Healing Wave
8019 if (pVictim
->GetAura(SPELL_AURA_DUMMY
, SPELLFAMILY_SHAMAN
, 0x0000040000000000LL
, 0, GetGUID()))
8020 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8028 // Taken/Done fixed damage bonus auras
8029 int32 DoneAdvertisedBenefit
= SpellBaseHealingBonus(GetSpellSchoolMask(spellProto
));
8030 int32 TakenAdvertisedBenefit
= SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto
), pVictim
);
8032 float LvlPenalty
= CalculateLevelPenalty(spellProto
);
8033 // Spellmod SpellDamage
8034 float SpellModSpellDamage
= 100.0f
;
8035 if(Player
* modOwner
= GetSpellModOwner())
8036 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_SPELL_BONUS_DAMAGE
, SpellModSpellDamage
);
8037 SpellModSpellDamage
/= 100.0f
;
8039 // Check for table values
8040 SpellBonusEntry
const* bonus
= spellmgr
.GetSpellBonusData(spellProto
->Id
);
8044 if (damagetype
== DOT
)
8045 coeff
= bonus
->dot_damage
* LvlPenalty
* stack
;
8047 coeff
= bonus
->direct_damage
* LvlPenalty
* stack
;
8049 if (bonus
->ap_bonus
)
8050 DoneTotal
+= int32(bonus
->ap_bonus
* GetTotalAttackPowerValue(BASE_ATTACK
) * stack
);
8052 DoneTotal
+= int32(DoneAdvertisedBenefit
* coeff
* SpellModSpellDamage
);
8053 TakenTotal
+= int32(TakenAdvertisedBenefit
* coeff
);
8055 // Default calculation
8056 else if (DoneAdvertisedBenefit
|| TakenAdvertisedBenefit
)
8058 // Damage Done from spell damage bonus
8059 uint32 CastingTime
= !IsChanneledSpell(spellProto
) ? GetSpellCastTime(spellProto
) : GetSpellDuration(spellProto
);
8060 // Damage over Time spells bonus calculation
8061 float DotFactor
= 1.0f
;
8062 if(damagetype
== DOT
)
8064 int32 DotDuration
= GetSpellDuration(spellProto
);
8068 if(DotDuration
> 30000) DotDuration
= 30000;
8069 if(!IsChanneledSpell(spellProto
)) DotFactor
= DotDuration
/ 15000.0f
;
8071 for(int j
= 0; j
< 3; j
++)
8073 if( spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& (
8074 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_DAMAGE
||
8075 spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
) )
8082 if(spellProto
->EffectAmplitude
[x
] != 0)
8083 DotTicks
= DotDuration
/ spellProto
->EffectAmplitude
[x
];
8086 DoneAdvertisedBenefit
= DoneAdvertisedBenefit
* int32(stack
) / DotTicks
;
8087 TakenAdvertisedBenefit
= TakenAdvertisedBenefit
* int32(stack
) / DotTicks
;
8091 // Distribute Damage over multiple effects, reduce by AoE
8092 CastingTime
= GetCastingTimeForBonus( spellProto
, damagetype
, CastingTime
);
8093 // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing
8094 for(int j
= 0; j
< 3; ++j
)
8096 if( spellProto
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
||
8097 spellProto
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
&& spellProto
->EffectApplyAuraName
[j
] == SPELL_AURA_PERIODIC_LEECH
)
8103 DoneTotal
+= int32(DoneAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* SpellModSpellDamage
* 1.88f
);
8104 TakenTotal
+= int32(TakenAdvertisedBenefit
* (CastingTime
/ 3500.0f
) * DotFactor
* LvlPenalty
* 1.88f
);
8107 // use float as more appropriate for negative values and percent applying
8108 float heal
= (healamount
+ DoneTotal
)*DoneTotalMod
;
8109 // apply spellmod to Done amount
8110 if(Player
* modOwner
= GetSpellModOwner())
8111 modOwner
->ApplySpellMod(spellProto
->Id
, damagetype
== DOT
? SPELLMOD_DOT
: SPELLMOD_DAMAGE
, heal
);
8114 // Healing Wave cast
8115 if (spellProto
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& spellProto
->SpellFamilyFlags
& 0x0000000000000040LL
)
8117 // Search for Healing Way on Victim
8118 Unit::AuraList
const& auraDummy
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
8119 for(Unit::AuraList::const_iterator itr
= auraDummy
.begin(); itr
!=auraDummy
.end(); ++itr
)
8120 if((*itr
)->GetId() == 29203)
8121 TakenTotalMod
*= ((*itr
)->GetModifier()->m_amount
+100.0f
) / 100.0f
;
8124 // Healing taken percent
8125 float minval
= pVictim
->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
8127 TakenTotalMod
*= (100.0f
+ minval
) / 100.0f
;
8129 float maxval
= pVictim
->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT
);
8131 TakenTotalMod
*= (100.0f
+ maxval
) / 100.0f
;
8133 AuraList
const& mHealingGet
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING_RECEIVED
);
8134 for(AuraList::const_iterator i
= mHealingGet
.begin(); i
!= mHealingGet
.end(); ++i
)
8135 if ((*i
)->isAffectedOnSpell(spellProto
))
8136 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+ 100.0f
) / 100.0f
;
8138 heal
= (heal
+ TakenTotal
) * TakenTotalMod
;
8140 return heal
< 0 ? 0 : uint32(heal
);
8143 int32
Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask
)
8145 int32 AdvertisedBenefit
= 0;
8147 AuraList
const& mHealingDone
= GetAurasByType(SPELL_AURA_MOD_HEALING_DONE
);
8148 for(AuraList::const_iterator i
= mHealingDone
.begin();i
!= mHealingDone
.end(); ++i
)
8149 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
8150 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8152 // Healing bonus of spirit, intellect and strength
8153 if (GetTypeId() == TYPEID_PLAYER
)
8156 AdvertisedBenefit
+=((Player
*)this)->GetBaseSpellHealingBonus();
8158 // Healing bonus from stats
8159 AuraList
const& mHealingDoneOfStatPercent
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT
);
8160 for(AuraList::const_iterator i
= mHealingDoneOfStatPercent
.begin();i
!= mHealingDoneOfStatPercent
.end(); ++i
)
8162 // stat used dependent from misc value (stat index)
8163 Stats usedStat
= Stats((*i
)->GetSpellProto()->EffectMiscValue
[(*i
)->GetEffIndex()]);
8164 AdvertisedBenefit
+= int32(GetStat(usedStat
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
8167 // ... and attack power
8168 AuraList
const& mHealingDonebyAP
= GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER
);
8169 for(AuraList::const_iterator i
= mHealingDonebyAP
.begin();i
!= mHealingDonebyAP
.end(); ++i
)
8170 if ((*i
)->GetModifier()->m_miscvalue
& schoolMask
)
8171 AdvertisedBenefit
+= int32(GetTotalAttackPowerValue(BASE_ATTACK
) * (*i
)->GetModifier()->m_amount
/ 100.0f
);
8173 return AdvertisedBenefit
;
8176 int32
Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
)
8178 int32 AdvertisedBenefit
= 0;
8179 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_HEALING
);
8180 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
8181 if(((*i
)->GetModifier()->m_miscvalue
& schoolMask
) != 0)
8182 AdvertisedBenefit
+= (*i
)->GetModifier()->m_amount
;
8183 return AdvertisedBenefit
;
8186 bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask
)
8188 //If m_immuneToSchool type contain this school type, IMMUNE damage.
8189 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
8190 for (SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
8191 if(itr
->type
& shoolMask
)
8194 //If m_immuneToDamage type contain magic, IMMUNE damage.
8195 SpellImmuneList
const& damageList
= m_spellImmune
[IMMUNITY_DAMAGE
];
8196 for (SpellImmuneList::const_iterator itr
= damageList
.begin(); itr
!= damageList
.end(); ++itr
)
8197 if(itr
->type
& shoolMask
)
8203 bool Unit::IsImmunedToSpell(SpellEntry
const* spellInfo
)
8208 //FIX ME this hack: don't get feared if stunned
8209 if (spellInfo
->Mechanic
== MECHANIC_FEAR
)
8211 if ( hasUnitState(UNIT_STAT_STUNNED
) )
8215 //TODO add spellEffect immunity checks!, player with flag in bg is imune to imunity buffs from other friendly players!
8216 //SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_EFFECT];
8218 SpellImmuneList
const& dispelList
= m_spellImmune
[IMMUNITY_DISPEL
];
8219 for(SpellImmuneList::const_iterator itr
= dispelList
.begin(); itr
!= dispelList
.end(); ++itr
)
8220 if(itr
->type
== spellInfo
->Dispel
)
8223 if( !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE
) && // unaffected by school immunity
8224 !(spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)) // can remove immune (by dispell or immune it)
8226 SpellImmuneList
const& schoolList
= m_spellImmune
[IMMUNITY_SCHOOL
];
8227 for(SpellImmuneList::const_iterator itr
= schoolList
.begin(); itr
!= schoolList
.end(); ++itr
)
8228 if( !(IsPositiveSpell(itr
->spellId
) && IsPositiveSpell(spellInfo
->Id
)) &&
8229 (itr
->type
& GetSpellSchoolMask(spellInfo
)) )
8233 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
8234 for(SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
8236 if(itr
->type
== spellInfo
->Mechanic
)
8245 bool Unit::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, uint32 index
) const
8247 //If m_immuneToEffect type contain this effect type, IMMUNE effect.
8248 uint32 effect
= spellInfo
->Effect
[index
];
8249 SpellImmuneList
const& effectList
= m_spellImmune
[IMMUNITY_EFFECT
];
8250 for (SpellImmuneList::const_iterator itr
= effectList
.begin(); itr
!= effectList
.end(); ++itr
)
8251 if(itr
->type
== effect
)
8254 if(uint32 mechanic
= spellInfo
->EffectMechanic
[index
])
8256 SpellImmuneList
const& mechanicList
= m_spellImmune
[IMMUNITY_MECHANIC
];
8257 for (SpellImmuneList::const_iterator itr
= mechanicList
.begin(); itr
!= mechanicList
.end(); ++itr
)
8258 if(itr
->type
== mechanic
)
8262 if(uint32 aura
= spellInfo
->EffectApplyAuraName
[index
])
8264 SpellImmuneList
const& list
= m_spellImmune
[IMMUNITY_STATE
];
8265 for(SpellImmuneList::const_iterator itr
= list
.begin(); itr
!= list
.end(); ++itr
)
8266 if(itr
->type
== aura
)
8268 // Check for immune to application of harmful magical effects
8269 AuraList
const& immuneAuraApply
= GetAurasByType(SPELL_AURA_MOD_IMMUNE_AURA_APPLY_SCHOOL
);
8270 for(AuraList::const_iterator iter
= immuneAuraApply
.begin(); iter
!= immuneAuraApply
.end(); ++iter
)
8271 if (spellInfo
->Dispel
== DISPEL_MAGIC
&& // Magic debuff
8272 ((*iter
)->GetModifier()->m_miscvalue
& GetSpellSchoolMask(spellInfo
)) && // Check school
8273 !IsPositiveEffect(spellInfo
->Id
, index
)) // Harmful
8280 bool Unit::IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const
8285 uint32 family
= spellInfo
->SpellFamilyName
;
8286 uint64 flags
= spellInfo
->SpellFamilyFlags
;
8288 if((family
== 5 && flags
== 256) || //Searing Pain
8289 (family
== 6 && flags
== 8192) || //Mind Blast
8290 (family
== 11 && flags
== 1048576)) //Earth Shock
8296 void Unit::MeleeDamageBonus(Unit
*pVictim
, uint32
*pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
)
8304 uint32 creatureTypeMask
= pVictim
->GetCreatureTypeMask();
8306 // Taken/Done fixed damage bonus auras
8307 int32 DoneFlatBenefit
= 0;
8308 int32 TakenFlatBenefit
= 0;
8310 // ..done (for creature type by mask) in taken
8311 AuraList
const& mDamageDoneCreature
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE
);
8312 for(AuraList::const_iterator i
= mDamageDoneCreature
.begin();i
!= mDamageDoneCreature
.end(); ++i
)
8313 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8314 DoneFlatBenefit
+= (*i
)->GetModifier()->m_amount
;
8317 // SPELL_AURA_MOD_DAMAGE_DONE included in weapon damage
8319 // ..done (base at attack power for marked target and base at attack power for creature type)
8321 if(attType
== RANGED_ATTACK
)
8323 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
);
8325 // ..done (base at attack power and creature type)
8326 AuraList
const& mCreatureAttackPower
= GetAurasByType(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS
);
8327 for(AuraList::const_iterator i
= mCreatureAttackPower
.begin();i
!= mCreatureAttackPower
.end(); ++i
)
8328 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8329 APbonus
+= (*i
)->GetModifier()->m_amount
;
8333 APbonus
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS
);
8335 // ..done (base at attack power and creature type)
8336 AuraList
const& mCreatureAttackPower
= GetAurasByType(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS
);
8337 for(AuraList::const_iterator i
= mCreatureAttackPower
.begin();i
!= mCreatureAttackPower
.end(); ++i
)
8338 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8339 APbonus
+= (*i
)->GetModifier()->m_amount
;
8342 if (APbonus
!=0) // Can be negative
8344 bool normalized
= false;
8347 for (uint8 i
= 0; i
<3;i
++)
8349 if (spellProto
->Effect
[i
] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG
)
8357 DoneFlatBenefit
+= int32(APbonus
/14.0f
* GetAPMultiplier(attType
,normalized
));
8361 AuraList
const& mDamageTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN
);
8362 for(AuraList::const_iterator i
= mDamageTaken
.begin();i
!= mDamageTaken
.end(); ++i
)
8363 if((*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask())
8364 TakenFlatBenefit
+= (*i
)->GetModifier()->m_amount
;
8366 if(attType
!=RANGED_ATTACK
)
8367 TakenFlatBenefit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN
);
8369 TakenFlatBenefit
+= pVictim
->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN
);
8371 // Done/Taken total percent damage auras
8372 float DoneTotalMod
= 1.0f
;
8373 float TakenTotalMod
= 1.0f
;
8376 // SPELL_AURA_MOD_DAMAGE_PERCENT_DONE included in weapon damage
8377 // SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT included in weapon damage
8379 AuraList
const& mDamageDoneVersus
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS
);
8380 for(AuraList::const_iterator i
= mDamageDoneVersus
.begin();i
!= mDamageDoneVersus
.end(); ++i
)
8381 if(creatureTypeMask
& uint32((*i
)->GetModifier()->m_miscvalue
))
8382 DoneTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8385 AuraList
const& mModDamagePercentTaken
= pVictim
->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
);
8386 for(AuraList::const_iterator i
= mModDamagePercentTaken
.begin(); i
!= mModDamagePercentTaken
.end(); ++i
)
8387 if((*i
)->GetModifier()->m_miscvalue
& GetMeleeDamageSchoolMask())
8388 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8390 // .. taken pct: dummy auras
8391 AuraList
const& mDummyAuras
= pVictim
->GetAurasByType(SPELL_AURA_DUMMY
);
8392 for(AuraList::const_iterator i
= mDummyAuras
.begin(); i
!= mDummyAuras
.end(); ++i
)
8394 switch((*i
)->GetSpellProto()->SpellIconID
)
8398 if((*i
)->GetModifier()->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)
8400 if(pVictim
->GetTypeId() != TYPEID_PLAYER
)
8402 float mod
= ((Player
*)pVictim
)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*(-8.0f
);
8403 if (mod
< (*i
)->GetModifier()->m_amount
)
8404 mod
= (*i
)->GetModifier()->m_amount
;
8405 TakenTotalMod
*= (mod
+100.0f
)/100.0f
;
8410 if(spellProto
==NULL
)
8412 // Should increase Shred (initial Damage of Lacerate and Rake handled in Spell::EffectSchoolDMG)
8413 if(spellProto
->SpellFamilyName
==SPELLFAMILY_DRUID
&& (spellProto
->SpellFamilyFlags
==0x00008000LL
))
8414 TakenTotalMod
*= (100.0f
+(*i
)->GetModifier()->m_amount
)/100.0f
;
8419 // .. taken pct: class scripts
8420 AuraList
const& mclassScritAuras
= GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
);
8421 for(AuraList::const_iterator i
= mclassScritAuras
.begin(); i
!= mclassScritAuras
.end(); ++i
)
8423 switch((*i
)->GetMiscValue())
8425 case 6427: case 6428: // Dirty Deeds
8426 if(pVictim
->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
))
8428 Aura
* eff0
= GetAura((*i
)->GetId(),0);
8429 if(!eff0
|| (*i
)->GetEffIndex()!=1)
8431 sLog
.outError("Spell structure of DD (%u) changed.",(*i
)->GetId());
8435 // effect 0 have expected value but in negative state
8436 TakenTotalMod
*= (-eff0
->GetModifier()->m_amount
+100.0f
)/100.0f
;
8442 if(attType
!= RANGED_ATTACK
)
8444 AuraList
const& mModMeleeDamageTakenPercent
= pVictim
->GetAurasByType(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT
);
8445 for(AuraList::const_iterator i
= mModMeleeDamageTakenPercent
.begin(); i
!= mModMeleeDamageTakenPercent
.end(); ++i
)
8446 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8450 AuraList
const& mModRangedDamageTakenPercent
= pVictim
->GetAurasByType(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT
);
8451 for(AuraList::const_iterator i
= mModRangedDamageTakenPercent
.begin(); i
!= mModRangedDamageTakenPercent
.end(); ++i
)
8452 TakenTotalMod
*= ((*i
)->GetModifier()->m_amount
+100.0f
)/100.0f
;
8455 float tmpDamage
= float(int32(*pdamage
) + DoneFlatBenefit
) * DoneTotalMod
;
8457 // apply spellmod to Done damage
8460 if(Player
* modOwner
= GetSpellModOwner())
8461 modOwner
->ApplySpellMod(spellProto
->Id
, SPELLMOD_DAMAGE
, tmpDamage
);
8464 tmpDamage
= (tmpDamage
+ TakenFlatBenefit
)*TakenTotalMod
;
8466 // bonus result can be negative
8467 *pdamage
= tmpDamage
> 0 ? uint32(tmpDamage
) : 0;
8470 void Unit::ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
)
8474 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(), next
; itr
!= m_spellImmune
[op
].end(); itr
= next
)
8477 if(itr
->type
== type
)
8479 m_spellImmune
[op
].erase(itr
);
8480 next
= m_spellImmune
[op
].begin();
8484 Immune
.spellId
= spellId
;
8486 m_spellImmune
[op
].push_back(Immune
);
8490 for (SpellImmuneList::iterator itr
= m_spellImmune
[op
].begin(); itr
!= m_spellImmune
[op
].end(); ++itr
)
8492 if(itr
->spellId
== spellId
)
8494 m_spellImmune
[op
].erase(itr
);
8502 void Unit::ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
)
8504 ApplySpellImmune(spellProto
->Id
,IMMUNITY_DISPEL
, type
, apply
);
8506 if (apply
&& spellProto
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
8507 RemoveAurasWithDispelType(type
);
8510 float Unit::GetWeaponProcChance() const
8512 // normalized proc chance for weapon attack speed
8514 if(isAttackReady(BASE_ATTACK
))
8515 return (GetAttackTime(BASE_ATTACK
) * 1.8f
/ 1000.0f
);
8516 else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
8517 return (GetAttackTime(OFF_ATTACK
) * 1.6f
/ 1000.0f
);
8521 float Unit::GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const
8523 // proc per minute chance calculation
8524 if (PPM
<= 0) return 0.0f
;
8525 uint32 result
= uint32((WeaponSpeed
* PPM
) / 600.0f
); // result is chance in percents (probability = Speed_in_sec * (PPM / 60))
8529 void Unit::Mount(uint32 mount
)
8534 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNTING
);
8536 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, mount
);
8538 SetFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
8541 if(GetTypeId() == TYPEID_PLAYER
)
8542 ((Player
*)this)->UnsummonPetTemporaryIfAny();
8545 void Unit::Unmount()
8550 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED
);
8552 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
8553 RemoveFlag( UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
);
8555 // only resummon old pet if the player is already added to a map
8556 // this prevents adding a pet to a not created map which would otherwise cause a crash
8557 // (it could probably happen when logging in after a previous crash)
8558 if(GetTypeId() == TYPEID_PLAYER
)
8559 ((Player
*)this)->ResummonPetTemporaryUnSummonedIfAny();
8562 void Unit::SetInCombatWith(Unit
* enemy
)
8564 Unit
* eOwner
= enemy
->GetCharmerOrOwnerOrSelf();
8567 SetInCombatState(true);
8572 if(eOwner
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)eOwner
)->duel
)
8574 Unit
const* myOwner
= GetCharmerOrOwnerOrSelf();
8575 if(((Player
const*)eOwner
)->duel
->opponent
== myOwner
)
8577 SetInCombatState(true);
8581 SetInCombatState(false);
8584 void Unit::SetInCombatState(bool PvP
)
8586 // only alive units can be in combat
8591 m_CombatTimer
= 5000;
8592 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
8594 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
8595 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
8598 void Unit::ClearInCombat()
8601 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
);
8603 if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER
&& ((Creature
*)this)->isPet()))
8604 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PET_IN_COMBAT
);
8606 // Player's state will be cleared in Player::UpdateContestedPvP
8607 if(GetTypeId()!=TYPEID_PLAYER
)
8608 clearUnitState(UNIT_STAT_ATTACK_PLAYER
);
8610 ((Player
*)this)->UpdatePotionCooldown();
8613 bool Unit::isTargetableForAttack() const
8615 if (GetTypeId()==TYPEID_PLAYER
&& ((Player
*)this)->isGameMaster())
8618 if(HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
8621 return isAlive() && !hasUnitState(UNIT_STAT_DIED
)&& !isInFlight() /*&& !isStealth()*/;
8624 int32
Unit::ModifyHealth(int32 dVal
)
8631 int32 curHealth
= (int32
)GetHealth();
8633 int32 val
= dVal
+ curHealth
;
8640 int32 maxHealth
= (int32
)GetMaxHealth();
8645 gain
= val
- curHealth
;
8647 else if(curHealth
!= maxHealth
)
8649 SetHealth(maxHealth
);
8650 gain
= maxHealth
- curHealth
;
8656 int32
Unit::ModifyPower(Powers power
, int32 dVal
)
8663 int32 curPower
= (int32
)GetPower(power
);
8665 int32 val
= dVal
+ curPower
;
8672 int32 maxPower
= (int32
)GetMaxPower(power
);
8676 SetPower(power
,val
);
8677 gain
= val
- curPower
;
8679 else if(curPower
!= maxPower
)
8681 SetPower(power
,maxPower
);
8682 gain
= maxPower
- curPower
;
8688 bool Unit::isVisibleForOrDetect(Unit
const* u
, bool detect
, bool inVisibleList
, bool is3dDistance
) const
8693 // Always can see self
8697 // player visible for other player if not logout and at same transport
8698 // including case when player is out of world
8699 bool at_same_transport
=
8700 GetTypeId() == TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
&&
8701 !((Player
*)this)->GetSession()->PlayerLogout() && !((Player
*)u
)->GetSession()->PlayerLogout() &&
8702 !((Player
*)this)->GetSession()->PlayerLoading() && !((Player
*)u
)->GetSession()->PlayerLoading() &&
8703 ((Player
*)this)->GetTransport() && ((Player
*)this)->GetTransport() == ((Player
*)u
)->GetTransport();
8706 if(!at_same_transport
&& (!IsInWorld() || !u
->IsInWorld()))
8709 // forbidden to seen (at GM respawn command)
8710 if(m_Visibility
==VISIBILITY_RESPAWN
)
8713 // always seen by owner
8714 if(GetCharmerOrOwnerGUID()==u
->GetGUID())
8717 // Grid dead/alive checks
8718 if( u
->GetTypeId()==TYPEID_PLAYER
)
8720 // non visible at grid for any stealth state
8721 if(!IsVisibleInGridForPlayer((Player
*)u
))
8724 // if player is dead then he can't detect anyone in any cases
8730 // all dead creatures/players not visible for any creatures
8731 if(!u
->isAlive() || !isAlive())
8735 // different visible distance checks
8736 if(u
->isInFlight()) // what see player in flight
8738 // use object grey distance for all (only see objects any way)
8739 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceInFlight()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
8742 else if(!isAlive()) // distance for show body
8744 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForObject()+(inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), is3dDistance
))
8747 else if(GetTypeId()==TYPEID_PLAYER
) // distance for show player
8749 if(u
->GetTypeId()==TYPEID_PLAYER
)
8751 // Players far than max visible distance for player or not in our map are not visible too
8752 if (!at_same_transport
&& !IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForPlayer()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8757 // Units far than max visible distance for creature or not in our map are not visible too
8758 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForCreature()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8762 else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
8764 // Pet/charmed far than max visible distance for player or not in our map are not visible too
8765 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForPlayer()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8768 else // distance for show creature
8770 // Units far than max visible distance for creature or not in our map are not visible too
8771 if (!IsWithinDistInMap(u
,World::GetMaxVisibleDistanceForCreature()+(inVisibleList
? World::GetVisibleUnitGreyDistance() : 0.0f
), is3dDistance
))
8775 // Visible units, always are visible for all units, except for units under invisibility and phases
8776 if (m_Visibility
== VISIBILITY_ON
&& u
->m_invisibilityMask
==0 && InSamePhase(u
))
8779 // GMs see any players, not higher GMs and all units in any phase
8780 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->isGameMaster())
8782 if(GetTypeId() == TYPEID_PLAYER
)
8783 return ((Player
*)this)->GetSession()->GetSecurity() <= ((Player
*)u
)->GetSession()->GetSecurity();
8788 // non faction visibility non-breakable for non-GMs
8789 if (m_Visibility
== VISIBILITY_OFF
)
8792 // phased visibility (both must phased in same way)
8797 bool invisible
= (m_invisibilityMask
!= 0 || u
->m_invisibilityMask
!=0);
8799 // detectable invisibility case
8801 // Invisible units, always are visible for units under same invisibility type
8802 (m_invisibilityMask
& u
->m_invisibilityMask
)!=0 ||
8803 // Invisible units, always are visible for unit that can detect this invisibility (have appropriate level for detect)
8804 u
->canDetectInvisibilityOf(this) ||
8805 // Units that can detect invisibility always are visible for units that can be detected
8806 canDetectInvisibilityOf(u
) ))
8811 // special cases for always overwrite invisibility/stealth
8812 if(invisible
|| m_Visibility
== VISIBILITY_GROUP_STEALTH
)
8815 if (!u
->IsHostileTo(this))
8817 // 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)
8818 if(GetTypeId()==TYPEID_PLAYER
&& u
->GetTypeId()==TYPEID_PLAYER
)
8820 if(((Player
*)this)->IsGroupVisibleFor(((Player
*)u
)))
8823 // else apply same rules as for hostile case (detecting check for stealth)
8829 // Hunter mark functionality
8830 AuraList
const& auras
= GetAurasByType(SPELL_AURA_MOD_STALKED
);
8831 for(AuraList::const_iterator iter
= auras
.begin(); iter
!= auras
.end(); ++iter
)
8832 if((*iter
)->GetCasterGUID()==u
->GetGUID())
8835 // else apply detecting check for stealth
8838 // none other cases for detect invisibility, so invisible
8842 // else apply stealth detecting check
8845 // unit got in stealth in this moment and must ignore old detected state
8846 if (m_Visibility
== VISIBILITY_GROUP_NO_DETECT
)
8849 // GM invisibility checks early, invisibility if any detectable, so if not stealth then visible
8850 if (m_Visibility
!= VISIBILITY_GROUP_STEALTH
)
8853 // NOW ONLY STEALTH CASE
8855 // stealth and detected and visible for some seconds
8856 if (u
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)u
)->m_DetectInvTimer
> 300 && ((Player
*)u
)->HaveAtClient(this))
8859 //if in non-detect mode then invisible for unit
8865 // If is attacked then stealth is lost, some creature can use stealth too
8866 if( !getAttackers().empty() )
8869 // If there is collision rogue is seen regardless of level difference
8870 // TODO: check sizes in DB
8871 float distance
= GetDistance(u
);
8872 if (distance
< 0.24f
)
8875 //If a mob or player is stunned he will not be able to detect stealth
8876 if (u
->hasUnitState(UNIT_STAT_STUNNED
) && (u
!= this))
8879 // Creature can detect target only in aggro radius
8880 if(u
->GetTypeId() != TYPEID_PLAYER
)
8882 //Always invisible from back and out of aggro range
8883 bool isInFront
= u
->isInFront(this,((Creature
const*)u
)->GetAttackDistance(this));
8889 //Always invisible from back
8890 bool isInFront
= u
->isInFront(this,(GetTypeId()==TYPEID_PLAYER
|| GetCharmerOrOwnerGUID()) ? World::GetMaxVisibleDistanceForPlayer() : World::GetMaxVisibleDistanceForCreature());
8895 // if doesn't have stealth detection (Shadow Sight), then check how stealthy the unit is, otherwise just check los
8896 if(!u
->HasAuraType(SPELL_AURA_DETECT_STEALTH
))
8898 //Calculation if target is in front
8900 //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5)
8901 float visibleDistance
= 10.5f
- (GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH
)/100.0f
);
8903 //Visible distance is modified by
8904 //-Level Diff (every level diff = 1.0f in visible distance)
8905 visibleDistance
+= int32(u
->getLevelForTarget(this)) - int32(getLevelForTarget(u
));
8907 //This allows to check talent tree and will add addition stealth dependent on used points)
8908 int32 stealthMod
= GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL
);
8912 //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia)
8913 //based on wowwiki every 5 mod we have 1 more level diff in calculation
8914 visibleDistance
+= (int32(u
->GetTotalAuraModifier(SPELL_AURA_MOD_DETECT
)) - stealthMod
)/5.0f
;
8916 if(distance
> visibleDistance
)
8920 // Now check is target visible with LoS
8922 u
->GetPosition(ox
,oy
,oz
);
8923 return IsWithinLOS(ox
,oy
,oz
);
8926 void Unit::SetVisibility(UnitVisibility x
)
8934 if(GetTypeId()==TYPEID_PLAYER
)
8935 m
->PlayerRelocation((Player
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
8937 m
->CreatureRelocation((Creature
*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
8941 bool Unit::canDetectInvisibilityOf(Unit
const* u
) const
8943 if(uint32 mask
= (m_detectInvisibilityMask
& u
->m_invisibilityMask
))
8945 for(uint32 i
= 0; i
< 10; ++i
)
8947 if(((1 << i
) & mask
)==0)
8950 // find invisibility level
8951 uint32 invLevel
= 0;
8952 Unit::AuraList
const& iAuras
= u
->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY
);
8953 for(Unit::AuraList::const_iterator itr
= iAuras
.begin(); itr
!= iAuras
.end(); ++itr
)
8954 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& invLevel
< (*itr
)->GetModifier()->m_amount
)
8955 invLevel
= (*itr
)->GetModifier()->m_amount
;
8957 // find invisibility detect level
8958 uint32 detectLevel
= 0;
8959 Unit::AuraList
const& dAuras
= GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION
);
8960 for(Unit::AuraList::const_iterator itr
= dAuras
.begin(); itr
!= dAuras
.end(); ++itr
)
8961 if(((*itr
)->GetModifier()->m_miscvalue
)==i
&& detectLevel
< (*itr
)->GetModifier()->m_amount
)
8962 detectLevel
= (*itr
)->GetModifier()->m_amount
;
8964 if(i
==6 && GetTypeId()==TYPEID_PLAYER
) // special drunk detection case
8966 detectLevel
= ((Player
*)this)->GetDrunkValue();
8969 if(invLevel
<= detectLevel
)
8977 void Unit::UpdateSpeed(UnitMoveType mtype
, bool forced
)
8979 int32 main_speed_mod
= 0;
8980 float stack_bonus
= 1.0f
;
8981 float non_stack_bonus
= 1.0f
;
8989 if (IsMounted()) // Use on mount auras
8991 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED
);
8992 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS
);
8993 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK
))/100.0f
;
8997 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED
);
8998 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS
);
8999 non_stack_bonus
= (100.0f
+ GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK
))/100.0f
;
9007 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED
);
9010 case MOVE_SWIM_BACK
:
9014 if (IsMounted()) // Use on mount auras
9015 main_speed_mod
= GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
);
9016 else // Use not mount (shapeshift for example) auras (should stack)
9017 main_speed_mod
= GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT
);
9018 stack_bonus
= GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS
);
9019 non_stack_bonus
= (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK
))/100.0f
;
9022 case MOVE_FLIGHT_BACK
:
9025 sLog
.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype
);
9029 float bonus
= non_stack_bonus
> stack_bonus
? non_stack_bonus
: stack_bonus
;
9030 // now we ready for speed calculation
9031 float speed
= main_speed_mod
? bonus
*(100.0f
+ main_speed_mod
)/100.0f
: bonus
;
9039 // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
9040 // TODO: possible affect only on MOVE_RUN
9041 if(int32 normalization
= GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED
))
9043 // Use speed from aura
9044 float max_speed
= normalization
/ baseMoveSpeed
[mtype
];
9045 if (speed
> max_speed
)
9054 // Apply strongest slow aura mod to speed
9055 int32 slow
= GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED
);
9057 speed
*=(100.0f
+ slow
)/100.0f
;
9058 SetSpeed(mtype
, speed
, forced
);
9061 float Unit::GetSpeed( UnitMoveType mtype
) const
9063 return m_speed_rate
[mtype
]*baseMoveSpeed
[mtype
];
9066 void Unit::SetSpeed(UnitMoveType mtype
, float rate
, bool forced
)
9071 // Update speed only on change
9072 if (m_speed_rate
[mtype
] == rate
)
9075 m_speed_rate
[mtype
] = rate
;
9077 propagateSpeedChange();
9085 data
.Initialize(MSG_MOVE_SET_WALK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9088 data
.Initialize(MSG_MOVE_SET_RUN_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9091 data
.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9094 data
.Initialize(MSG_MOVE_SET_SWIM_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9096 case MOVE_SWIM_BACK
:
9097 data
.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9099 case MOVE_TURN_RATE
:
9100 data
.Initialize(MSG_MOVE_SET_TURN_RATE
, 8+4+2+4+4+4+4+4+4+4);
9103 data
.Initialize(MSG_MOVE_SET_FLIGHT_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9105 case MOVE_FLIGHT_BACK
:
9106 data
.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED
, 8+4+2+4+4+4+4+4+4+4);
9108 case MOVE_PITCH_RATE
:
9109 data
.Initialize(MSG_MOVE_SET_PITCH_RATE
, 8+4+2+4+4+4+4+4+4+4);
9112 sLog
.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype
);
9116 data
.append(GetPackGUID());
9117 data
<< uint32(0); // movement flags
9118 data
<< uint16(0); // unk flags
9119 data
<< uint32(getMSTime());
9120 data
<< float(GetPositionX());
9121 data
<< float(GetPositionY());
9122 data
<< float(GetPositionZ());
9123 data
<< float(GetOrientation());
9124 data
<< uint32(0); // fall time
9125 data
<< float(GetSpeed(mtype
));
9126 SendMessageToSet( &data
, true );
9130 if(GetTypeId() == TYPEID_PLAYER
)
9132 // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
9133 // and do it only for real sent packets and use run for run/mounted as client expected
9134 ++((Player
*)this)->m_forced_speed_changes
[mtype
];
9140 data
.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE
, 16);
9143 data
.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE
, 17);
9146 data
.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE
, 16);
9149 data
.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE
, 16);
9151 case MOVE_SWIM_BACK
:
9152 data
.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
, 16);
9154 case MOVE_TURN_RATE
:
9155 data
.Initialize(SMSG_FORCE_TURN_RATE_CHANGE
, 16);
9158 data
.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE
, 16);
9160 case MOVE_FLIGHT_BACK
:
9161 data
.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
, 16);
9163 case MOVE_PITCH_RATE
:
9164 data
.Initialize(SMSG_FORCE_PITCH_RATE_CHANGE
, 16);
9167 sLog
.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype
);
9170 data
.append(GetPackGUID());
9171 data
<< (uint32
)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
9172 if (mtype
== MOVE_RUN
)
9173 data
<< uint8(0); // new 2.1.0
9174 data
<< float(GetSpeed(mtype
));
9175 SendMessageToSet( &data
, true );
9177 if(Pet
* pet
= GetPet())
9178 pet
->SetSpeed(MOVE_RUN
, m_speed_rate
[mtype
],forced
);
9181 void Unit::SetHover(bool on
)
9184 CastSpell(this,11010,true);
9186 RemoveAurasDueToSpell(11010);
9189 void Unit::setDeathState(DeathState s
)
9191 if (s
!= ALIVE
&& s
!= JUST_ALIVED
)
9195 ClearComboPointHolders(); // any combo points pointed to unit lost at it death
9197 if(IsNonMeleeSpellCasted(false))
9198 InterruptNonMeleeSpells(false);
9203 RemoveAllAurasOnDeath();
9204 UnsummonAllTotems();
9206 ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT
, false);
9207 ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT
, false);
9208 // remove aurastates allowing special moves
9209 ClearAllReactives();
9210 ClearDiminishings();
9212 else if(s
== JUST_ALIVED
)
9214 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
); // clear skinnable for creature and player (at battleground)
9217 if (m_deathState
!= ALIVE
&& s
== ALIVE
)
9219 //_ApplyAllAuraMods();
9224 /*########################################
9226 ######## AGGRO SYSTEM ########
9228 ########################################*/
9229 bool Unit::CanHaveThreatList() const
9231 // only creatures can have threat list
9232 if( GetTypeId() != TYPEID_UNIT
)
9235 // only alive units can have threat list
9239 // totems can not have threat list
9240 if( ((Creature
*)this)->isTotem() )
9243 // vehicles can not have threat list
9244 if( ((Creature
*)this)->isVehicle() )
9247 // pets can not have a threat list, unless they are controlled by a creature
9248 if( ((Creature
*)this)->isPet() && IS_PLAYER_GUID(((Pet
*)this)->GetOwnerGUID()) )
9254 //======================================================================
9256 float Unit::ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
)
9258 if(!HasAuraType(SPELL_AURA_MOD_THREAT
))
9261 SpellSchools school
= GetFirstSchoolInMask(schoolMask
);
9263 return threat
* m_threatModifier
[school
];
9266 //======================================================================
9268 void Unit::AddThreat(Unit
* pVictim
, float threat
, SpellSchoolMask schoolMask
, SpellEntry
const *threatSpell
)
9270 // Only mobs can manage threat lists
9271 if(CanHaveThreatList())
9272 m_ThreatManager
.addThreat(pVictim
, threat
, schoolMask
, threatSpell
);
9275 //======================================================================
9277 void Unit::DeleteThreatList()
9279 m_ThreatManager
.clearReferences();
9282 //======================================================================
9284 void Unit::TauntApply(Unit
* taunter
)
9286 assert(GetTypeId()== TYPEID_UNIT
);
9288 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
9291 if(!CanHaveThreatList())
9294 Unit
*target
= getVictim();
9295 if(target
&& target
== taunter
)
9298 SetInFront(taunter
);
9299 if (((Creature
*)this)->AI())
9300 ((Creature
*)this)->AI()->AttackStart(taunter
);
9302 m_ThreatManager
.tauntApply(taunter
);
9305 //======================================================================
9307 void Unit::TauntFadeOut(Unit
*taunter
)
9309 assert(GetTypeId()== TYPEID_UNIT
);
9311 if(!taunter
|| (taunter
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)taunter
)->isGameMaster()))
9314 if(!CanHaveThreatList())
9317 Unit
*target
= getVictim();
9318 if(!target
|| target
!= taunter
)
9321 if(m_ThreatManager
.isThreatListEmpty())
9323 if(((Creature
*)this)->AI())
9324 ((Creature
*)this)->AI()->EnterEvadeMode();
9328 m_ThreatManager
.tauntFadeOut(taunter
);
9329 target
= m_ThreatManager
.getHostilTarget();
9331 if (target
&& target
!= taunter
)
9334 if (((Creature
*)this)->AI())
9335 ((Creature
*)this)->AI()->AttackStart(target
);
9339 //======================================================================
9341 bool Unit::SelectHostilTarget()
9343 //function provides main threat functionality
9344 //next-victim-selection algorithm and evade mode are called
9345 //threat list sorting etc.
9347 assert(GetTypeId()== TYPEID_UNIT
);
9349 if (!this->isAlive())
9351 //This function only useful once AI has been initialized
9352 if (!((Creature
*)this)->AI())
9355 Unit
* target
= NULL
;
9357 // First checking if we have some taunt on us
9358 const AuraList
& tauntAuras
= GetAurasByType(SPELL_AURA_MOD_TAUNT
);
9359 if ( !tauntAuras
.empty() )
9363 // The last taunt aura caster is alive an we are happy to attack him
9364 if ( (caster
= tauntAuras
.back()->GetCaster()) && caster
->isAlive() )
9366 else if (tauntAuras
.size() > 1)
9368 // We do not have last taunt aura caster but we have more taunt auras,
9369 // so find first available target
9371 // Auras are pushed_back, last caster will be on the end
9372 AuraList::const_iterator aura
= --tauntAuras
.end();
9376 if ( (caster
= (*aura
)->GetCaster()) &&
9377 caster
->IsInMap(this) && caster
->isTargetableForAttack() && caster
->isInAccessablePlaceFor((Creature
*)this) )
9382 }while (aura
!= tauntAuras
.begin());
9386 if ( !target
&& !m_ThreatManager
.isThreatListEmpty() )
9387 // No taunt aura or taunt aura caster is dead standart target selection
9388 target
= m_ThreatManager
.getHostilTarget();
9392 if(!hasUnitState(UNIT_STAT_STUNNED
))
9394 ((Creature
*)this)->AI()->AttackStart(target
);
9398 // no target but something prevent go to evade mode
9399 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT
) )
9402 // last case when creature don't must go to evade mode:
9403 // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list
9404 // for example at owner command to pet attack some far away creature
9405 // Note: creature not have targeted movement generator but have attacker in this case
9406 if( GetMotionMaster()->GetCurrentMovementGeneratorType() != TARGETED_MOTION_TYPE
)
9408 for(AttackerSet::const_iterator itr
= m_attackers
.begin(); itr
!= m_attackers
.end(); ++itr
)
9410 if( (*itr
)->IsInMap(this) && (*itr
)->isTargetableForAttack() && (*itr
)->isInAccessablePlaceFor((Creature
*)this) )
9415 // enter in evade mode in other case
9416 ((Creature
*)this)->AI()->EnterEvadeMode();
9421 //======================================================================
9422 //======================================================================
9423 //======================================================================
9425 int32
Unit::CalculateSpellDamage(SpellEntry
const* spellProto
, uint8 effect_index
, int32 effBasePoints
, Unit
const* target
)
9427 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
9429 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
9431 int32 level
= int32(getLevel());
9432 if (level
> (int32
)spellProto
->maxLevel
&& spellProto
->maxLevel
> 0)
9433 level
= (int32
)spellProto
->maxLevel
;
9434 else if (level
< (int32
)spellProto
->baseLevel
)
9435 level
= (int32
)spellProto
->baseLevel
;
9436 level
-= (int32
)spellProto
->spellLevel
;
9438 float basePointsPerLevel
= spellProto
->EffectRealPointsPerLevel
[effect_index
];
9439 float randomPointsPerLevel
= spellProto
->EffectDicePerLevel
[effect_index
];
9440 int32 basePoints
= int32(effBasePoints
+ level
* basePointsPerLevel
);
9441 int32 randomPoints
= int32(spellProto
->EffectDieSides
[effect_index
] + level
* randomPointsPerLevel
);
9442 float comboDamage
= spellProto
->EffectPointsPerComboPoint
[effect_index
];
9444 // range can have possitive and negative values, so order its for irand
9445 int32 randvalue
= int32(spellProto
->EffectBaseDice
[effect_index
]) >= randomPoints
9446 ? irand(randomPoints
, int32(spellProto
->EffectBaseDice
[effect_index
]))
9447 : irand(int32(spellProto
->EffectBaseDice
[effect_index
]), randomPoints
);
9449 int32 value
= basePoints
+ randvalue
;
9451 if(comboDamage
!= 0 && unitPlayer
&& target
&& (target
->GetGUID() == unitPlayer
->GetComboTarget()))
9452 value
+= (int32
)(comboDamage
* comboPoints
);
9454 if(Player
* modOwner
= GetSpellModOwner())
9456 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_ALL_EFFECTS
, value
);
9457 switch(effect_index
)
9460 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT1
, value
);
9463 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT2
, value
);
9466 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_EFFECT3
, value
);
9471 if(spellProto
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
&& spellProto
->spellLevel
&&
9472 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
&&
9473 spellProto
->Effect
[effect_index
] != SPELL_EFFECT_KNOCK_BACK
)
9474 value
= int32(value
*0.25f
*exp(getLevel()*(70-spellProto
->spellLevel
)/1000.0f
));
9479 int32
Unit::CalculateSpellDuration(SpellEntry
const* spellProto
, uint8 effect_index
, Unit
const* target
)
9481 Player
* unitPlayer
= (GetTypeId() == TYPEID_PLAYER
) ? (Player
*)this : NULL
;
9483 uint8 comboPoints
= unitPlayer
? unitPlayer
->GetComboPoints() : 0;
9485 int32 minduration
= GetSpellDuration(spellProto
);
9486 int32 maxduration
= GetSpellMaxDuration(spellProto
);
9490 if( minduration
!= -1 && minduration
!= maxduration
)
9491 duration
= minduration
+ int32((maxduration
- minduration
) * comboPoints
/ 5);
9493 duration
= minduration
;
9497 int32 mechanic
= GetEffectMechanic(spellProto
, effect_index
);
9498 // Find total mod value (negative bonus)
9499 int32 durationMod_always
= target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD
, mechanic
);
9500 // Modify from SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL aura (stack always ?)
9501 durationMod_always
+=target
->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DURATION_OF_EFFECTS_BY_DISPEL
, spellProto
->Dispel
);
9502 // Find max mod (negative bonus)
9503 int32 durationMod_not_stack
= target
->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK
, mechanic
);
9505 int32 durationMod
= 0;
9506 // Select strongest negative mod
9507 if (durationMod_always
> durationMod_not_stack
)
9508 durationMod
= durationMod_not_stack
;
9510 durationMod
= durationMod_always
;
9512 if (durationMod
!= 0)
9513 duration
= int32(int64(duration
) * (100+durationMod
) /100);
9515 if (duration
< 0) duration
= 0;
9521 DiminishingLevels
Unit::GetDiminishing(DiminishingGroup group
)
9523 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
9525 if(i
->DRGroup
!= group
)
9529 return DIMINISHING_LEVEL_1
;
9532 return DIMINISHING_LEVEL_1
;
9534 // If last spell was casted more than 15 seconds ago - reset the count.
9535 if(i
->stack
==0 && getMSTimeDiff(i
->hitTime
,getMSTime()) > 15000)
9537 i
->hitCount
= DIMINISHING_LEVEL_1
;
9538 return DIMINISHING_LEVEL_1
;
9540 // or else increase the count.
9543 return DiminishingLevels(i
->hitCount
);
9546 return DIMINISHING_LEVEL_1
;
9549 void Unit::IncrDiminishing(DiminishingGroup group
)
9551 // Checking for existing in the table
9552 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
9554 if(i
->DRGroup
!= group
)
9556 if(i
->hitCount
< DIMINISHING_LEVEL_IMMUNE
)
9560 m_Diminishing
.push_back(DiminishingReturn(group
,getMSTime(),DIMINISHING_LEVEL_2
));
9563 void Unit::ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
,DiminishingLevels Level
)
9565 if(duration
== -1 || group
== DIMINISHING_NONE
|| caster
->IsFriendlyTo(this) )
9568 // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0)
9569 if(duration
> 10000 && IsDiminishingReturnsGroupDurationLimited(group
))
9571 // test pet/charm masters instead pets/charmeds
9572 Unit
const* targetOwner
= GetCharmerOrOwner();
9573 Unit
const* casterOwner
= caster
->GetCharmerOrOwner();
9575 Unit
const* target
= targetOwner
? targetOwner
: this;
9576 Unit
const* source
= casterOwner
? casterOwner
: caster
;
9578 if(target
->GetTypeId() == TYPEID_PLAYER
&& source
->GetTypeId() == TYPEID_PLAYER
)
9584 // Some diminishings applies to mobs too (for example, Stun)
9585 if((GetDiminishingReturnsGroupType(group
) == DRTYPE_PLAYER
&& GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(group
) == DRTYPE_ALL
)
9587 DiminishingLevels diminish
= Level
;
9590 case DIMINISHING_LEVEL_1
: break;
9591 case DIMINISHING_LEVEL_2
: mod
= 0.5f
; break;
9592 case DIMINISHING_LEVEL_3
: mod
= 0.25f
; break;
9593 case DIMINISHING_LEVEL_IMMUNE
: mod
= 0.0f
;break;
9598 duration
= int32(duration
* mod
);
9601 void Unit::ApplyDiminishingAura( DiminishingGroup group
, bool apply
)
9603 // Checking for existing in the table
9604 for(Diminishing::iterator i
= m_Diminishing
.begin(); i
!= m_Diminishing
.end(); ++i
)
9606 if(i
->DRGroup
!= group
)
9614 // Remember time after last aura from group removed
9616 i
->hitTime
= getMSTime();
9622 Unit
* Unit::GetUnit(WorldObject
& object
, uint64 guid
)
9624 return ObjectAccessor::GetUnit(object
,guid
);
9627 bool Unit::isVisibleForInState( Player
const* u
, bool inVisibleList
) const
9629 return isVisibleForOrDetect(u
, false, inVisibleList
, false);
9632 uint32
Unit::GetCreatureType() const
9634 if(GetTypeId() == TYPEID_PLAYER
)
9636 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(m_form
);
9637 if(ssEntry
&& ssEntry
->creatureType
> 0)
9638 return ssEntry
->creatureType
;
9640 return CREATURE_TYPE_HUMANOID
;
9643 return ((Creature
*)this)->GetCreatureInfo()->type
;
9646 /*#######################################
9648 ######## STAT SYSTEM ########
9650 #######################################*/
9652 bool Unit::HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
)
9654 if(unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
9656 sLog
.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!");
9662 switch(modifierType
)
9666 m_auraModifiersGroup
[unitMod
][modifierType
] += apply
? amount
: -amount
;
9670 if(amount
<= -100.0f
) //small hack-fix for -100% modifiers
9673 val
= (100.0f
+ amount
) / 100.0f
;
9674 m_auraModifiersGroup
[unitMod
][modifierType
] *= apply
? val
: (1.0f
/val
);
9681 if(!CanModifyStats())
9686 case UNIT_MOD_STAT_STRENGTH
:
9687 case UNIT_MOD_STAT_AGILITY
:
9688 case UNIT_MOD_STAT_STAMINA
:
9689 case UNIT_MOD_STAT_INTELLECT
:
9690 case UNIT_MOD_STAT_SPIRIT
: UpdateStats(GetStatByAuraGroup(unitMod
)); break;
9692 case UNIT_MOD_ARMOR
: UpdateArmor(); break;
9693 case UNIT_MOD_HEALTH
: UpdateMaxHealth(); break;
9697 case UNIT_MOD_FOCUS
:
9698 case UNIT_MOD_ENERGY
:
9699 case UNIT_MOD_HAPPINESS
:
9701 case UNIT_MOD_RUNIC_POWER
: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod
)); break;
9703 case UNIT_MOD_RESISTANCE_HOLY
:
9704 case UNIT_MOD_RESISTANCE_FIRE
:
9705 case UNIT_MOD_RESISTANCE_NATURE
:
9706 case UNIT_MOD_RESISTANCE_FROST
:
9707 case UNIT_MOD_RESISTANCE_SHADOW
:
9708 case UNIT_MOD_RESISTANCE_ARCANE
: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod
)); break;
9710 case UNIT_MOD_ATTACK_POWER
: UpdateAttackPowerAndDamage(); break;
9711 case UNIT_MOD_ATTACK_POWER_RANGED
: UpdateAttackPowerAndDamage(true); break;
9713 case UNIT_MOD_DAMAGE_MAINHAND
: UpdateDamagePhysical(BASE_ATTACK
); break;
9714 case UNIT_MOD_DAMAGE_OFFHAND
: UpdateDamagePhysical(OFF_ATTACK
); break;
9715 case UNIT_MOD_DAMAGE_RANGED
: UpdateDamagePhysical(RANGED_ATTACK
); break;
9724 float Unit::GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const
9726 if( unitMod
>= UNIT_MOD_END
|| modifierType
>= MODIFIER_TYPE_END
)
9728 sLog
.outError("trial to access non existed modifier value from UnitMods!");
9732 if(modifierType
== TOTAL_PCT
&& m_auraModifiersGroup
[unitMod
][modifierType
] <= 0.0f
)
9735 return m_auraModifiersGroup
[unitMod
][modifierType
];
9738 float Unit::GetTotalStatValue(Stats stat
) const
9740 UnitMods unitMod
= UnitMods(UNIT_MOD_STAT_START
+ stat
);
9742 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
9745 // value = ((base_value * base_pct) + total_value) * total_pct
9746 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
] + GetCreateStat(stat
);
9747 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
9748 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
9749 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
9754 float Unit::GetTotalAuraModValue(UnitMods unitMod
) const
9756 if(unitMod
>= UNIT_MOD_END
)
9758 sLog
.outError("trial to access non existed UnitMods in GetTotalAuraModValue()!");
9762 if(m_auraModifiersGroup
[unitMod
][TOTAL_PCT
] <= 0.0f
)
9765 float value
= m_auraModifiersGroup
[unitMod
][BASE_VALUE
];
9766 value
*= m_auraModifiersGroup
[unitMod
][BASE_PCT
];
9767 value
+= m_auraModifiersGroup
[unitMod
][TOTAL_VALUE
];
9768 value
*= m_auraModifiersGroup
[unitMod
][TOTAL_PCT
];
9773 SpellSchools
Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod
) const
9775 SpellSchools school
= SPELL_SCHOOL_NORMAL
;
9779 case UNIT_MOD_RESISTANCE_HOLY
: school
= SPELL_SCHOOL_HOLY
; break;
9780 case UNIT_MOD_RESISTANCE_FIRE
: school
= SPELL_SCHOOL_FIRE
; break;
9781 case UNIT_MOD_RESISTANCE_NATURE
: school
= SPELL_SCHOOL_NATURE
; break;
9782 case UNIT_MOD_RESISTANCE_FROST
: school
= SPELL_SCHOOL_FROST
; break;
9783 case UNIT_MOD_RESISTANCE_SHADOW
: school
= SPELL_SCHOOL_SHADOW
; break;
9784 case UNIT_MOD_RESISTANCE_ARCANE
: school
= SPELL_SCHOOL_ARCANE
; break;
9793 Stats
Unit::GetStatByAuraGroup(UnitMods unitMod
) const
9795 Stats stat
= STAT_STRENGTH
;
9799 case UNIT_MOD_STAT_STRENGTH
: stat
= STAT_STRENGTH
; break;
9800 case UNIT_MOD_STAT_AGILITY
: stat
= STAT_AGILITY
; break;
9801 case UNIT_MOD_STAT_STAMINA
: stat
= STAT_STAMINA
; break;
9802 case UNIT_MOD_STAT_INTELLECT
: stat
= STAT_INTELLECT
; break;
9803 case UNIT_MOD_STAT_SPIRIT
: stat
= STAT_SPIRIT
; break;
9812 Powers
Unit::GetPowerTypeByAuraGroup(UnitMods unitMod
) const
9816 case UNIT_MOD_MANA
: return POWER_MANA
;
9817 case UNIT_MOD_RAGE
: return POWER_RAGE
;
9818 case UNIT_MOD_FOCUS
: return POWER_FOCUS
;
9819 case UNIT_MOD_ENERGY
: return POWER_ENERGY
;
9820 case UNIT_MOD_HAPPINESS
: return POWER_HAPPINESS
;
9821 case UNIT_MOD_RUNE
: return POWER_RUNE
;
9822 case UNIT_MOD_RUNIC_POWER
:return POWER_RUNIC_POWER
;
9828 float Unit::GetTotalAttackPowerValue(WeaponAttackType attType
) const
9830 if (attType
== RANGED_ATTACK
)
9832 int32 ap
= GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER_MODS
);
9835 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER
));
9839 int32 ap
= GetInt32Value(UNIT_FIELD_ATTACK_POWER
) + GetInt32Value(UNIT_FIELD_ATTACK_POWER_MODS
);
9842 return ap
* (1.0f
+ GetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER
));
9846 float Unit::GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const
9848 if (attType
== OFF_ATTACK
&& !haveOffhandWeapon())
9851 return m_weaponDamage
[attType
][type
];
9854 void Unit::SetLevel(uint32 lvl
)
9856 SetUInt32Value(UNIT_FIELD_LEVEL
, lvl
);
9859 if ((GetTypeId() == TYPEID_PLAYER
) && ((Player
*)this)->GetGroup())
9860 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL
);
9863 void Unit::SetHealth(uint32 val
)
9865 uint32 maxHealth
= GetMaxHealth();
9869 SetUInt32Value(UNIT_FIELD_HEALTH
, val
);
9872 if(GetTypeId() == TYPEID_PLAYER
)
9874 if(((Player
*)this)->GetGroup())
9875 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP
);
9877 else if(((Creature
*)this)->isPet())
9879 Pet
*pet
= ((Pet
*)this);
9880 if(pet
->isControlled())
9882 Unit
*owner
= GetOwner();
9883 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9884 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP
);
9889 void Unit::SetMaxHealth(uint32 val
)
9891 uint32 health
= GetHealth();
9892 SetUInt32Value(UNIT_FIELD_MAXHEALTH
, val
);
9895 if(GetTypeId() == TYPEID_PLAYER
)
9897 if(((Player
*)this)->GetGroup())
9898 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP
);
9900 else if(((Creature
*)this)->isPet())
9902 Pet
*pet
= ((Pet
*)this);
9903 if(pet
->isControlled())
9905 Unit
*owner
= GetOwner();
9906 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9907 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP
);
9915 void Unit::SetPower(Powers power
, uint32 val
)
9917 if(GetPower(power
) == val
)
9920 uint32 maxPower
= GetMaxPower(power
);
9924 SetStatInt32Value(UNIT_FIELD_POWER1
+ power
, val
);
9926 WorldPacket
data(SMSG_POWER_UPDATE
);
9927 data
.append(GetPackGUID());
9928 data
<< uint8(power
);
9929 data
<< uint32(val
);
9930 SendMessageToSet(&data
, GetTypeId() == TYPEID_PLAYER
? true : false);
9933 if(GetTypeId() == TYPEID_PLAYER
)
9935 if(((Player
*)this)->GetGroup())
9936 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
9938 else if(((Creature
*)this)->isPet())
9940 Pet
*pet
= ((Pet
*)this);
9941 if(pet
->isControlled())
9943 Unit
*owner
= GetOwner();
9944 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9945 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
9948 // Update the pet's character sheet with happiness damage bonus
9949 if(pet
->getPetType() == HUNTER_PET
&& power
== POWER_HAPPINESS
)
9951 pet
->UpdateDamagePhysical(BASE_ATTACK
);
9956 void Unit::SetMaxPower(Powers power
, uint32 val
)
9958 uint32 cur_power
= GetPower(power
);
9959 SetStatInt32Value(UNIT_FIELD_MAXPOWER1
+ power
, val
);
9962 if(GetTypeId() == TYPEID_PLAYER
)
9964 if(((Player
*)this)->GetGroup())
9965 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
9967 else if(((Creature
*)this)->isPet())
9969 Pet
*pet
= ((Pet
*)this);
9970 if(pet
->isControlled())
9972 Unit
*owner
= GetOwner();
9973 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9974 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
9979 SetPower(power
, val
);
9982 void Unit::ApplyPowerMod(Powers power
, uint32 val
, bool apply
)
9984 ApplyModUInt32Value(UNIT_FIELD_POWER1
+power
, val
, apply
);
9987 if(GetTypeId() == TYPEID_PLAYER
)
9989 if(((Player
*)this)->GetGroup())
9990 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER
);
9992 else if(((Creature
*)this)->isPet())
9994 Pet
*pet
= ((Pet
*)this);
9995 if(pet
->isControlled())
9997 Unit
*owner
= GetOwner();
9998 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
9999 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER
);
10004 void Unit::ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
)
10006 ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1
+power
, val
, apply
);
10009 if(GetTypeId() == TYPEID_PLAYER
)
10011 if(((Player
*)this)->GetGroup())
10012 ((Player
*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER
);
10014 else if(((Creature
*)this)->isPet())
10016 Pet
*pet
= ((Pet
*)this);
10017 if(pet
->isControlled())
10019 Unit
*owner
= GetOwner();
10020 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10021 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER
);
10026 void Unit::ApplyAuraProcTriggerDamage( Aura
* aura
, bool apply
)
10028 AuraList
& tAuraProcTriggerDamage
= m_modAuras
[SPELL_AURA_PROC_TRIGGER_DAMAGE
];
10030 tAuraProcTriggerDamage
.push_back(aura
);
10032 tAuraProcTriggerDamage
.remove(aura
);
10035 uint32
Unit::GetCreatePowers( Powers power
) const
10037 // POWER_FOCUS and POWER_HAPPINESS only have hunter pet
10040 case POWER_MANA
: return GetCreateMana();
10041 case POWER_RAGE
: return 1000;
10042 case POWER_FOCUS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 100);
10043 case POWER_ENERGY
: return 100;
10044 case POWER_HAPPINESS
: return (GetTypeId()==TYPEID_PLAYER
|| !((Creature
const*)this)->isPet() || ((Pet
const*)this)->getPetType()!=HUNTER_PET
? 0 : 1050000);
10045 case POWER_RUNIC_POWER
: return 1000;
10051 void Unit::AddToWorld()
10053 Object::AddToWorld();
10056 void Unit::RemoveFromWorld()
10061 RemoveNotOwnSingleTargetAuras();
10064 Object::RemoveFromWorld();
10067 void Unit::CleanupsBeforeDelete()
10069 if(m_uint32Values
) // only for fully created object
10071 InterruptNonMeleeSpells(true);
10072 m_Events
.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList
10074 ClearComboPointHolders();
10075 DeleteThreatList();
10076 getHostilRefManager().setOnlineOfflineState(false);
10078 RemoveAllGameObjects();
10079 RemoveAllDynObjects();
10080 GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
10085 CharmInfo
* Unit::InitCharmInfo(Unit
*charm
)
10088 m_charmInfo
= new CharmInfo(charm
);
10089 return m_charmInfo
;
10092 CharmInfo::CharmInfo(Unit
* unit
)
10093 : m_unit(unit
), m_CommandState(COMMAND_FOLLOW
), m_reactState(REACT_PASSIVE
), m_petnumber(0)
10095 for(int i
=0; i
<4; ++i
)
10097 m_charmspells
[i
].spellId
= 0;
10098 m_charmspells
[i
].active
= ACT_DISABLED
;
10102 void CharmInfo::InitPetActionBar()
10104 // the first 3 SpellOrActions are attack, follow and stay
10105 for(uint32 i
= 0; i
< 3; i
++)
10107 PetActionBar
[i
].Type
= ACT_COMMAND
;
10108 PetActionBar
[i
].SpellOrAction
= COMMAND_ATTACK
- i
;
10110 PetActionBar
[i
+ 7].Type
= ACT_REACTION
;
10111 PetActionBar
[i
+ 7].SpellOrAction
= COMMAND_ATTACK
- i
;
10113 for(uint32 i
=0; i
< 4; i
++)
10115 PetActionBar
[i
+ 3].Type
= ACT_DISABLED
;
10116 PetActionBar
[i
+ 3].SpellOrAction
= 0;
10120 void CharmInfo::InitEmptyActionBar()
10122 for(uint32 x
= 1; x
< 10; ++x
)
10124 PetActionBar
[x
].Type
= ACT_PASSIVE
;
10125 PetActionBar
[x
].SpellOrAction
= 0;
10127 PetActionBar
[0].Type
= ACT_COMMAND
;
10128 PetActionBar
[0].SpellOrAction
= COMMAND_ATTACK
;
10131 void CharmInfo::InitPossessCreateSpells()
10133 InitEmptyActionBar(); //charm action bar
10135 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //possessed players don't have spells, keep the action bar empty
10138 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
10140 if (IsPassiveSpell(((Creature
*)m_unit
)->m_spells
[x
]))
10141 m_unit
->CastSpell(m_unit
, ((Creature
*)m_unit
)->m_spells
[x
], true);
10143 AddSpellToAB(0, ((Creature
*)m_unit
)->m_spells
[x
], ACT_PASSIVE
);
10147 void CharmInfo::InitCharmCreateSpells()
10149 if(m_unit
->GetTypeId() == TYPEID_PLAYER
) //charmed players don't have spells
10151 InitEmptyActionBar();
10155 InitPetActionBar();
10157 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
10159 uint32 spellId
= ((Creature
*)m_unit
)->m_spells
[x
];
10160 m_charmspells
[x
].spellId
= spellId
;
10165 if (IsPassiveSpell(spellId
))
10167 m_unit
->CastSpell(m_unit
, spellId
, true);
10168 m_charmspells
[x
].active
= ACT_PASSIVE
;
10172 ActiveStates newstate
;
10173 bool onlyselfcast
= true;
10174 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
10176 if(!spellInfo
) onlyselfcast
= false;
10177 for(uint32 i
= 0;i
<3 && onlyselfcast
;++i
) //non existent spell will not make any problems as onlyselfcast would be false -> break right away
10179 if(spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
&& spellInfo
->EffectImplicitTargetA
[i
] != 0)
10180 onlyselfcast
= false;
10183 if(onlyselfcast
|| !IsPositiveSpell(spellId
)) //only self cast and spells versus enemies are autocastable
10184 newstate
= ACT_DISABLED
;
10186 newstate
= ACT_PASSIVE
;
10188 AddSpellToAB(0, spellId
, newstate
);
10193 bool CharmInfo::AddSpellToAB(uint32 oldid
, uint32 newid
, ActiveStates newstate
)
10195 for(uint8 i
= 0; i
< 10; i
++)
10197 if((PetActionBar
[i
].Type
== ACT_DISABLED
|| PetActionBar
[i
].Type
== ACT_ENABLED
|| PetActionBar
[i
].Type
== ACT_PASSIVE
) && PetActionBar
[i
].SpellOrAction
== oldid
)
10199 PetActionBar
[i
].SpellOrAction
= newid
;
10202 if(newstate
== ACT_DECIDE
)
10203 PetActionBar
[i
].Type
= ACT_DISABLED
;
10205 PetActionBar
[i
].Type
= newstate
;
10214 void CharmInfo::ToggleCreatureAutocast(uint32 spellid
, bool apply
)
10216 if(IsPassiveSpell(spellid
))
10219 for(uint32 x
= 0; x
< CREATURE_MAX_SPELLS
; ++x
)
10221 if(spellid
== m_charmspells
[x
].spellId
)
10223 m_charmspells
[x
].active
= apply
? ACT_ENABLED
: ACT_DISABLED
;
10228 void CharmInfo::SetPetNumber(uint32 petnumber
, bool statwindow
)
10230 m_petnumber
= petnumber
;
10232 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, m_petnumber
);
10234 m_unit
->SetUInt32Value(UNIT_FIELD_PETNUMBER
, 0);
10237 bool Unit::isFrozen() const
10239 return HasAuraState(AURA_STATE_FROZEN
);
10242 struct ProcTriggeredData
10244 ProcTriggeredData(SpellProcEventEntry
const * _spellProcEvent
, Aura
* _triggeredByAura
)
10245 : spellProcEvent(_spellProcEvent
), triggeredByAura(_triggeredByAura
),
10246 triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura
->GetId(),triggeredByAura
->GetEffIndex()))
10248 SpellProcEventEntry
const *spellProcEvent
;
10249 Aura
* triggeredByAura
;
10250 Unit::spellEffectPair triggeredByAura_SpellPair
;
10253 typedef std::list
< ProcTriggeredData
> ProcTriggeredList
;
10254 typedef std::list
< uint32
> RemoveSpellList
;
10256 // List of auras that CAN be trigger but may not exist in spell_proc_event
10257 // in most case need for drop charges
10258 // in some types of aura need do additional check
10259 // for example SPELL_AURA_MECHANIC_IMMUNITY - need check for mechanic
10260 bool InitTriggerAuraData()
10262 for (int i
=0;i
<TOTAL_AURAS
;i
++)
10264 isTriggerAura
[i
]=false;
10265 isNonTriggerAura
[i
] = false;
10267 isTriggerAura
[SPELL_AURA_DUMMY
] = true;
10268 isTriggerAura
[SPELL_AURA_MOD_CONFUSE
] = true;
10269 isTriggerAura
[SPELL_AURA_MOD_THREAT
] = true;
10270 isTriggerAura
[SPELL_AURA_MOD_STUN
] = true; // Aura not have charges but need remove him on trigger
10271 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_DONE
] = true;
10272 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_TAKEN
] = true;
10273 isTriggerAura
[SPELL_AURA_MOD_RESISTANCE
] = true;
10274 isTriggerAura
[SPELL_AURA_MOD_ROOT
] = true;
10275 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS
] = true;
10276 isTriggerAura
[SPELL_AURA_DAMAGE_IMMUNITY
] = true;
10277 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL
] = true;
10278 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_DAMAGE
] = true;
10279 isTriggerAura
[SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
] = true;
10280 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
] = true;
10281 isTriggerAura
[SPELL_AURA_MOD_POWER_COST_SCHOOL
] = true;
10282 isTriggerAura
[SPELL_AURA_REFLECT_SPELLS_SCHOOL
] = true;
10283 isTriggerAura
[SPELL_AURA_MECHANIC_IMMUNITY
] = true;
10284 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN
] = true;
10285 isTriggerAura
[SPELL_AURA_SPELL_MAGNET
] = true;
10286 isTriggerAura
[SPELL_AURA_MOD_ATTACK_POWER
] = true;
10287 isTriggerAura
[SPELL_AURA_ADD_CASTER_HIT_TRIGGER
] = true;
10288 isTriggerAura
[SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
] = true;
10289 isTriggerAura
[SPELL_AURA_MOD_MECHANIC_RESISTANCE
] = true;
10290 isTriggerAura
[SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
] = true;
10291 isTriggerAura
[SPELL_AURA_MOD_HASTE
] = true;
10292 isTriggerAura
[SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE
]=true;
10293 isTriggerAura
[SPELL_AURA_PRAYER_OF_MENDING
] = true;
10294 isTriggerAura
[SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
] = true;
10295 isTriggerAura
[SPELL_AURA_MOD_DAMAGE_FROM_CASTER
] = true;
10297 isNonTriggerAura
[SPELL_AURA_MOD_POWER_REGEN
]=true;
10298 isNonTriggerAura
[SPELL_AURA_REDUCE_PUSHBACK
]=true;
10303 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
)
10305 uint32 procEx
= PROC_EX_NONE
;
10306 // Check victim state
10307 if (missCondition
!=SPELL_MISS_NONE
)
10308 switch (missCondition
)
10310 case SPELL_MISS_MISS
: procEx
|=PROC_EX_MISS
; break;
10311 case SPELL_MISS_RESIST
: procEx
|=PROC_EX_RESIST
; break;
10312 case SPELL_MISS_DODGE
: procEx
|=PROC_EX_DODGE
; break;
10313 case SPELL_MISS_PARRY
: procEx
|=PROC_EX_PARRY
; break;
10314 case SPELL_MISS_BLOCK
: procEx
|=PROC_EX_BLOCK
; break;
10315 case SPELL_MISS_EVADE
: procEx
|=PROC_EX_EVADE
; break;
10316 case SPELL_MISS_IMMUNE
: procEx
|=PROC_EX_IMMUNE
; break;
10317 case SPELL_MISS_IMMUNE2
: procEx
|=PROC_EX_IMMUNE
; break;
10318 case SPELL_MISS_DEFLECT
: procEx
|=PROC_EX_DEFLECT
;break;
10319 case SPELL_MISS_ABSORB
: procEx
|=PROC_EX_ABSORB
; break;
10320 case SPELL_MISS_REFLECT
: procEx
|=PROC_EX_REFLECT
;break;
10327 if (damageInfo
->blocked
)
10328 procEx
|=PROC_EX_BLOCK
;
10330 if (damageInfo
->absorb
)
10331 procEx
|=PROC_EX_ABSORB
;
10333 if (damageInfo
->HitInfo
& SPELL_HIT_TYPE_CRIT
)
10334 procEx
|=PROC_EX_CRITICAL_HIT
;
10336 procEx
|=PROC_EX_NORMAL_HIT
;
10341 void Unit::ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
)
10343 // For melee/ranged based attack need update skills and set some Aura states
10344 if (procFlag
& MELEE_BASED_TRIGGER_MASK
)
10346 // Update skills here for players
10347 if (GetTypeId() == TYPEID_PLAYER
)
10349 // On melee based hit/miss/resist need update skill (for victim and attacker)
10350 if (procExtra
&(PROC_EX_NORMAL_HIT
|PROC_EX_MISS
|PROC_EX_RESIST
))
10352 if (pTarget
->GetTypeId() != TYPEID_PLAYER
&& pTarget
->GetCreatureType() != CREATURE_TYPE_CRITTER
)
10353 ((Player
*)this)->UpdateCombatSkills(pTarget
, attType
, isVictim
);
10355 // Update defence if player is victim and parry/dodge/block
10356 if (isVictim
&& procExtra
&(PROC_EX_DODGE
|PROC_EX_PARRY
|PROC_EX_BLOCK
))
10357 ((Player
*)this)->UpdateDefense();
10359 // If exist crit/parry/dodge/block need update aura state (for victim and attacker)
10360 if (procExtra
& (PROC_EX_CRITICAL_HIT
|PROC_EX_PARRY
|PROC_EX_DODGE
|PROC_EX_BLOCK
))
10365 // if victim and dodge attack
10366 if (procExtra
&PROC_EX_DODGE
)
10368 //Update AURA_STATE on dodge
10369 if (getClass() != CLASS_ROGUE
) // skip Rogue Riposte
10371 ModifyAuraState(AURA_STATE_DEFENSE
, true);
10372 StartReactiveTimer( REACTIVE_DEFENSE
);
10375 // if victim and parry attack
10376 if (procExtra
& PROC_EX_PARRY
)
10378 // For Hunters only Counterattack (skip Mongoose bite)
10379 if (getClass() == CLASS_HUNTER
)
10381 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, true);
10382 StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
10386 ModifyAuraState(AURA_STATE_DEFENSE
, true);
10387 StartReactiveTimer( REACTIVE_DEFENSE
);
10390 // if and victim block attack
10391 if (procExtra
& PROC_EX_BLOCK
)
10393 ModifyAuraState(AURA_STATE_DEFENSE
,true);
10394 StartReactiveTimer( REACTIVE_DEFENSE
);
10397 else //For attacker
10399 // Overpower on victim dodge
10400 if (procExtra
&PROC_EX_DODGE
&& GetTypeId() == TYPEID_PLAYER
&& getClass() == CLASS_WARRIOR
)
10402 ((Player
*)this)->AddComboPoints(pTarget
, 1);
10403 StartReactiveTimer( REACTIVE_OVERPOWER
);
10409 RemoveSpellList removedSpells
;
10410 ProcTriggeredList procTriggered
;
10411 // Fill procTriggered list
10412 for(AuraMap::const_iterator itr
= GetAuras().begin(); itr
!= GetAuras().end(); ++itr
)
10414 SpellProcEventEntry
const* spellProcEvent
= NULL
;
10415 if(!IsTriggeredAtSpellProcEvent(pTarget
, itr
->second
, procSpell
, procFlag
, procExtra
, attType
, isVictim
, (damage
> 0), spellProcEvent
))
10418 procTriggered
.push_back( ProcTriggeredData(spellProcEvent
, itr
->second
) );
10422 if (procTriggered
.empty())
10425 // Handle effects proceed this time
10426 for(ProcTriggeredList::iterator i
= procTriggered
.begin(); i
!= procTriggered
.end(); ++i
)
10428 // Some auras can be deleted in function called in this loop (except first, ofc)
10429 // Until storing auars in std::multimap to hard check deleting by another way
10430 if(i
!= procTriggered
.begin())
10432 bool found
= false;
10433 AuraMap::const_iterator lower
= GetAuras().lower_bound(i
->triggeredByAura_SpellPair
);
10434 AuraMap::const_iterator upper
= GetAuras().upper_bound(i
->triggeredByAura_SpellPair
);
10435 for(AuraMap::const_iterator itr
= lower
; itr
!= upper
; ++itr
)
10437 if(itr
->second
==i
->triggeredByAura
)
10445 // 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);
10446 // sLog.outDebug("It can be deleted one from early proccesed auras:");
10447 // for(ProcTriggeredList::iterator i2 = procTriggered.begin(); i != i2; ++i2)
10448 // sLog.outDebug(" Spell aura %u (id:%u effect:%u)", i->triggeredByAura->GetModifier()->m_auraname,i2->triggeredByAura_SpellPair.first,i2->triggeredByAura_SpellPair.second);
10449 // sLog.outDebug(" <end of list>");
10454 SpellProcEventEntry
const *spellProcEvent
= i
->spellProcEvent
;
10455 Aura
*triggeredByAura
= i
->triggeredByAura
;
10456 Modifier
*auraModifier
= triggeredByAura
->GetModifier();
10457 SpellEntry
const *spellInfo
= triggeredByAura
->GetSpellProto();
10458 uint32 effIndex
= triggeredByAura
->GetEffIndex();
10459 bool useCharges
= triggeredByAura
->GetAuraCharges() > 0;
10460 // For players set spell cooldown if need
10461 uint32 cooldown
= 0;
10462 if (GetTypeId() == TYPEID_PLAYER
&& spellProcEvent
&& spellProcEvent
->cooldown
)
10463 cooldown
= spellProcEvent
->cooldown
;
10465 switch(auraModifier
->m_auraname
)
10467 case SPELL_AURA_PROC_TRIGGER_SPELL
:
10469 sLog
.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", spellInfo
->Id
,(isVictim
?"a victim's":"an attacker's"), triggeredByAura
->GetId());
10470 // Don`t drop charge or add cooldown for not started trigger
10471 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
10475 case SPELL_AURA_PROC_TRIGGER_DAMAGE
:
10477 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());
10478 SpellNonMeleeDamage
damageInfo(this, pTarget
, spellInfo
->Id
, spellInfo
->SchoolMask
);
10479 CalculateSpellDamage(&damageInfo
, auraModifier
->m_amount
, spellInfo
);
10480 SendSpellNonMeleeDamageLog(&damageInfo
);
10481 DealSpellDamage(&damageInfo
, true);
10484 case SPELL_AURA_MANA_SHIELD
:
10485 case SPELL_AURA_DUMMY
:
10487 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());
10488 if (!HandleDummyAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
10492 case SPELL_AURA_MOD_HASTE
:
10494 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());
10495 if (!HandleHasteAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
10499 case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS
:
10501 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());
10502 if (!HandleOverrideClassScriptAuraProc(pTarget
, damage
, triggeredByAura
, procSpell
, cooldown
))
10506 case SPELL_AURA_PRAYER_OF_MENDING
:
10508 sLog
.outDebug("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)",
10509 (isVictim
?"a victim's":"an attacker's"),triggeredByAura
->GetId());
10511 HandleMeandingAuraProc(triggeredByAura
);
10514 case SPELL_AURA_PROC_TRIGGER_SPELL_WITH_VALUE
:
10516 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());
10518 if (!HandleProcTriggerSpell(pTarget
, damage
, triggeredByAura
, procSpell
, procFlag
, procExtra
, cooldown
))
10522 case SPELL_AURA_MOD_CASTING_SPEED_NOT_STACK
:
10523 // Skip melee hits or instant cast spells
10524 if (procSpell
== NULL
|| GetSpellCastTime(procSpell
) == 0)
10527 case SPELL_AURA_REFLECT_SPELLS_SCHOOL
:
10528 // Skip Melee hits and spells ws wrong school
10529 if (procSpell
== NULL
|| (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0)
10532 case SPELL_AURA_MOD_POWER_COST_SCHOOL_PCT
:
10533 case SPELL_AURA_MOD_POWER_COST_SCHOOL
:
10534 // Skip melee hits and spells ws wrong school or zero cost
10535 if (procSpell
== NULL
||
10536 (procSpell
->manaCost
== 0 && procSpell
->ManaCostPercentage
== 0) || // Cost check
10537 (auraModifier
->m_miscvalue
& procSpell
->SchoolMask
) == 0) // School check
10540 case SPELL_AURA_MECHANIC_IMMUNITY
:
10541 // Compare mechanic
10542 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
10545 case SPELL_AURA_MOD_MECHANIC_RESISTANCE
:
10546 // Compare mechanic
10547 if (procSpell
==NULL
|| procSpell
->Mechanic
!= auraModifier
->m_miscvalue
)
10550 case SPELL_AURA_MOD_DAMAGE_FROM_CASTER
:
10552 if (triggeredByAura
->GetCasterGUID() != pTarget
->GetGUID())
10556 // nothing do, just charges counter
10559 // Remove charge (aura can be removed by triggers)
10562 // need found aura on drop (can be dropped by triggers)
10563 AuraMap::const_iterator lower
= GetAuras().lower_bound(i
->triggeredByAura_SpellPair
);
10564 AuraMap::const_iterator upper
= GetAuras().upper_bound(i
->triggeredByAura_SpellPair
);
10565 for(AuraMap::const_iterator itr
= lower
; itr
!= upper
; ++itr
)
10567 // If last charge dropped add spell to remove list
10568 if(itr
->second
== i
->triggeredByAura
&& triggeredByAura
->DropAuraCharge())
10570 removedSpells
.push_back(triggeredByAura
->GetId());
10576 if (!removedSpells
.empty())
10578 // Sort spells and remove dublicates
10579 removedSpells
.sort();
10580 removedSpells
.unique();
10581 // Remove auras from removedAuras
10582 for(RemoveSpellList::const_iterator i
= removedSpells
.begin(); i
!= removedSpells
.end();i
++)
10583 RemoveAurasDueToSpell(*i
);
10587 SpellSchoolMask
Unit::GetMeleeDamageSchoolMask() const
10589 return SPELL_SCHOOL_MASK_NORMAL
;
10592 Player
* Unit::GetSpellModOwner()
10594 if(GetTypeId()==TYPEID_PLAYER
)
10595 return (Player
*)this;
10596 if(((Creature
*)this)->isPet() || ((Creature
*)this)->isTotem())
10598 Unit
* owner
= GetOwner();
10599 if(owner
&& owner
->GetTypeId()==TYPEID_PLAYER
)
10600 return (Player
*)owner
;
10605 ///----------Pet responses methods-----------------
10606 void Unit::SendPetCastFail(uint32 spellid
, SpellCastResult msg
)
10608 if(msg
== SPELL_CAST_OK
)
10611 Unit
*owner
= GetCharmerOrOwner();
10612 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10615 WorldPacket
data(SMSG_PET_CAST_FAILED
, (4+1));
10616 data
<< uint8(0); // cast count?
10617 data
<< uint32(spellid
);
10618 data
<< uint8(msg
);
10619 // uint32 for some reason
10620 // uint32 for some reason
10621 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10624 void Unit::SendPetActionFeedback (uint8 msg
)
10626 Unit
* owner
= GetOwner();
10627 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10630 WorldPacket
data(SMSG_PET_ACTION_FEEDBACK
, 1);
10631 data
<< uint8(msg
);
10632 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10635 void Unit::SendPetTalk (uint32 pettalk
)
10637 Unit
* owner
= GetOwner();
10638 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10641 WorldPacket
data(SMSG_PET_ACTION_SOUND
, 8+4);
10642 data
<< uint64(GetGUID());
10643 data
<< uint32(pettalk
);
10644 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10647 void Unit::SendPetSpellCooldown (uint32 spellid
, time_t cooltime
)
10649 Unit
* owner
= GetOwner();
10650 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10653 WorldPacket
data(SMSG_SPELL_COOLDOWN
, 8+1+4+4);
10654 data
<< uint64(GetGUID());
10655 data
<< uint8(0x0); // flags (0x1, 0x2)
10656 data
<< uint32(spellid
);
10657 data
<< uint32(cooltime
);
10659 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10662 void Unit::SendPetClearCooldown (uint32 spellid
)
10664 Unit
* owner
= GetOwner();
10665 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10668 WorldPacket
data(SMSG_CLEAR_COOLDOWN
, (4+8));
10669 data
<< uint32(spellid
);
10670 data
<< uint64(GetGUID());
10671 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10674 void Unit::SendPetAIReaction(uint64 guid
)
10676 Unit
* owner
= GetOwner();
10677 if(!owner
|| owner
->GetTypeId() != TYPEID_PLAYER
)
10680 WorldPacket
data(SMSG_AI_REACTION
, 12);
10681 data
<< uint64(guid
) << uint32(00000002);
10682 ((Player
*)owner
)->GetSession()->SendPacket(&data
);
10685 ///----------End of Pet responses methods----------
10687 void Unit::StopMoving()
10689 clearUnitState(UNIT_STAT_MOVING
);
10691 // send explicit stop packet
10692 // rely on vmaps here because for example stormwind is in air
10693 //float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true);
10694 //if (fabs(GetPositionZ() - z) < 2.0f)
10695 // Relocate(GetPositionX(), GetPositionY(), z);
10696 Relocate(GetPositionX(), GetPositionY(),GetPositionZ());
10698 SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, 0);
10700 // update position and orientation;
10702 BuildHeartBeatMsg(&data
);
10703 SendMessageToSet(&data
,false);
10706 void Unit::SetFeared(bool apply
, uint64 casterGUID
, uint32 spellID
)
10710 if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING
))
10713 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
10715 GetMotionMaster()->MovementExpired(false);
10716 CastStop(GetGUID()==casterGUID
? spellID
: 0);
10718 Unit
* caster
= ObjectAccessor::GetUnit(*this,casterGUID
);
10720 GetMotionMaster()->MoveFleeing(caster
); // caster==NULL processed in MoveFleeing
10724 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
);
10726 GetMotionMaster()->MovementExpired(false);
10728 if( GetTypeId() != TYPEID_PLAYER
&& isAlive() )
10730 // restore appropriate movement generator
10732 GetMotionMaster()->MoveChase(getVictim());
10734 GetMotionMaster()->Initialize();
10736 // attack caster if can
10737 Unit
* caster
= ObjectAccessor::GetObjectInWorld(casterGUID
, (Unit
*)NULL
);
10738 if(caster
&& ((Creature
*)this)->AI())
10739 ((Creature
*)this)->AI()->AttackedBy(caster
);
10743 if (GetTypeId() == TYPEID_PLAYER
)
10744 ((Player
*)this)->SetClientControl(this, !apply
);
10747 void Unit::SetConfused(bool apply
, uint64 casterGUID
, uint32 spellID
)
10751 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
10753 CastStop(GetGUID()==casterGUID
? spellID
: 0);
10755 GetMotionMaster()->MoveConfused();
10759 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
);
10761 GetMotionMaster()->MovementExpired(false);
10763 if (GetTypeId() == TYPEID_UNIT
)
10765 // if in combat restore movement generator
10767 GetMotionMaster()->MoveChase(getVictim());
10771 if(GetTypeId() == TYPEID_PLAYER
)
10772 ((Player
*)this)->SetClientControl(this, !apply
);
10775 bool Unit::IsSitState() const
10777 uint8 s
= getStandState();
10779 s
== UNIT_STAND_STATE_SIT_CHAIR
|| s
== UNIT_STAND_STATE_SIT_LOW_CHAIR
||
10780 s
== UNIT_STAND_STATE_SIT_MEDIUM_CHAIR
|| s
== UNIT_STAND_STATE_SIT_HIGH_CHAIR
||
10781 s
== UNIT_STAND_STATE_SIT
;
10784 bool Unit::IsStandState() const
10786 uint8 s
= getStandState();
10787 return !IsSitState() && s
!= UNIT_STAND_STATE_SLEEP
&& s
!= UNIT_STAND_STATE_KNEEL
;
10790 void Unit::SetStandState(uint8 state
)
10792 SetByteValue(UNIT_FIELD_BYTES_1
, 0, state
);
10794 if (IsStandState())
10795 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED
);
10797 if(GetTypeId()==TYPEID_PLAYER
)
10799 WorldPacket
data(SMSG_STANDSTATE_UPDATE
, 1);
10800 data
<< (uint8
)state
;
10801 ((Player
*)this)->GetSession()->SendPacket(&data
);
10805 bool Unit::IsPolymorphed() const
10807 return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH
;
10810 void Unit::SetDisplayId(uint32 modelId
)
10812 SetUInt32Value(UNIT_FIELD_DISPLAYID
, modelId
);
10814 if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
10816 Pet
*pet
= ((Pet
*)this);
10817 if(!pet
->isControlled())
10819 Unit
*owner
= GetOwner();
10820 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
10821 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID
);
10825 void Unit::ClearComboPointHolders()
10827 while(!m_ComboPointHolders
.empty())
10829 uint32 lowguid
= *m_ComboPointHolders
.begin();
10831 Player
* plr
= objmgr
.GetPlayer(MAKE_NEW_GUID(lowguid
, 0, HIGHGUID_PLAYER
));
10832 if(plr
&& plr
->GetComboTarget()==GetGUID()) // recheck for safe
10833 plr
->ClearComboPoints(); // remove also guid from m_ComboPointHolders;
10835 m_ComboPointHolders
.erase(lowguid
); // or remove manually
10839 void Unit::ClearAllReactives()
10841 for(int i
=0; i
< MAX_REACTIVE
; ++i
)
10842 m_reactiveTimer
[i
] = 0;
10844 if (HasAuraState( AURA_STATE_DEFENSE
))
10845 ModifyAuraState(AURA_STATE_DEFENSE
, false);
10846 if (getClass() == CLASS_HUNTER
&& HasAuraState( AURA_STATE_HUNTER_PARRY
))
10847 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
10848 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
10849 ((Player
*)this)->ClearComboPoints();
10852 void Unit::UpdateReactives( uint32 p_time
)
10854 for(int i
= 0; i
< MAX_REACTIVE
; ++i
)
10856 ReactiveType reactive
= ReactiveType(i
);
10858 if(!m_reactiveTimer
[reactive
])
10861 if ( m_reactiveTimer
[reactive
] <= p_time
)
10863 m_reactiveTimer
[reactive
] = 0;
10865 switch ( reactive
)
10867 case REACTIVE_DEFENSE
:
10868 if (HasAuraState(AURA_STATE_DEFENSE
))
10869 ModifyAuraState(AURA_STATE_DEFENSE
, false);
10871 case REACTIVE_HUNTER_PARRY
:
10872 if ( getClass() == CLASS_HUNTER
&& HasAuraState(AURA_STATE_HUNTER_PARRY
))
10873 ModifyAuraState(AURA_STATE_HUNTER_PARRY
, false);
10875 case REACTIVE_OVERPOWER
:
10876 if(getClass() == CLASS_WARRIOR
&& GetTypeId() == TYPEID_PLAYER
)
10877 ((Player
*)this)->ClearComboPoints();
10885 m_reactiveTimer
[reactive
] -= p_time
;
10890 Unit
* Unit::SelectNearbyTarget() const
10892 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
10894 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
10895 cell
.SetNoCreate();
10897 std::list
<Unit
*> targets
;
10900 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, this, ATTACK_DISTANCE
);
10901 MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> searcher(this, targets
, u_check
);
10903 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
10904 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
10906 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
10907 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *GetMap());
10908 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *GetMap());
10911 // remove current target
10913 targets
.remove(getVictim());
10915 // remove not LoS targets
10916 for(std::list
<Unit
*>::iterator tIter
= targets
.begin(); tIter
!= targets
.end();)
10918 if(!IsWithinLOSInMap(*tIter
))
10920 std::list
<Unit
*>::iterator tIter2
= tIter
;
10922 targets
.erase(tIter2
);
10928 // no appropriate targets
10929 if(targets
.empty())
10933 uint32 rIdx
= urand(0,targets
.size()-1);
10934 std::list
<Unit
*>::const_iterator tcIter
= targets
.begin();
10935 for(uint32 i
= 0; i
< rIdx
; ++i
)
10941 bool Unit::hasNegativeAuraWithInterruptFlag(uint32 flag
)
10943 for (AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end(); ++iter
)
10945 if (!iter
->second
->IsPositive() && iter
->second
->GetSpellProto()->AuraInterruptFlags
& flag
)
10951 void Unit::ApplyAttackTimePercentMod( WeaponAttackType att
,float val
, bool apply
)
10955 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], val
, !apply
);
10956 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
,!apply
);
10960 ApplyPercentModFloatVar(m_modAttackSpeedPct
[att
], -val
, apply
);
10961 ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,-val
,apply
);
10965 void Unit::ApplyCastTimePercentMod(float val
, bool apply
)
10968 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,val
,!apply
);
10970 ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED
,-val
,apply
);
10973 uint32
Unit::GetCastingTimeForBonus( SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 CastingTime
)
10975 // Not apply this to creature casted spells with casttime==0
10976 if(CastingTime
==0 && GetTypeId()==TYPEID_UNIT
&& !((Creature
*)this)->isPet())
10979 if (CastingTime
> 7000) CastingTime
= 7000;
10980 if (CastingTime
< 1500) CastingTime
= 1500;
10982 if(damagetype
== DOT
&& !IsChanneledSpell(spellProto
))
10983 CastingTime
= 3500;
10985 int32 overTime
= 0;
10987 bool DirectDamage
= false;
10988 bool AreaEffect
= false;
10990 for ( uint32 i
=0; i
<3;i
++)
10992 switch ( spellProto
->Effect
[i
] )
10994 case SPELL_EFFECT_SCHOOL_DAMAGE
:
10995 case SPELL_EFFECT_POWER_DRAIN
:
10996 case SPELL_EFFECT_HEALTH_LEECH
:
10997 case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
:
10998 case SPELL_EFFECT_POWER_BURN
:
10999 case SPELL_EFFECT_HEAL
:
11000 DirectDamage
= true;
11002 case SPELL_EFFECT_APPLY_AURA
:
11003 switch ( spellProto
->EffectApplyAuraName
[i
] )
11005 case SPELL_AURA_PERIODIC_DAMAGE
:
11006 case SPELL_AURA_PERIODIC_HEAL
:
11007 case SPELL_AURA_PERIODIC_LEECH
:
11008 if ( GetSpellDuration(spellProto
) )
11009 overTime
= GetSpellDuration(spellProto
);
11012 // -5% per additional effect
11020 if(IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetA
[i
])) || IsAreaEffectTarget(Targets(spellProto
->EffectImplicitTargetB
[i
])))
11024 // Combined Spells with Both Over Time and Direct Damage
11025 if ( overTime
> 0 && CastingTime
> 0 && DirectDamage
)
11027 // mainly for DoTs which are 3500 here otherwise
11028 uint32 OriginalCastTime
= GetSpellCastTime(spellProto
);
11029 if (OriginalCastTime
> 7000) OriginalCastTime
= 7000;
11030 if (OriginalCastTime
< 1500) OriginalCastTime
= 1500;
11031 // Portion to Over Time
11032 float PtOT
= (overTime
/ 15000.f
) / ((overTime
/ 15000.f
) + (OriginalCastTime
/ 3500.f
));
11034 if ( damagetype
== DOT
)
11035 CastingTime
= uint32(CastingTime
* PtOT
);
11036 else if ( PtOT
< 1.0f
)
11037 CastingTime
= uint32(CastingTime
* (1 - PtOT
));
11042 // Area Effect Spells receive only half of bonus
11046 // -5% of total per any additional effect
11047 for ( uint8 i
=0; i
<effects
; ++i
)
11049 if ( CastingTime
> 175 )
11051 CastingTime
-= 175;
11060 return CastingTime
;
11063 void Unit::UpdateAuraForGroup(uint8 slot
)
11065 if(GetTypeId() == TYPEID_PLAYER
)
11067 Player
* player
= (Player
*)this;
11068 if(player
->GetGroup())
11070 player
->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS
);
11071 player
->SetAuraUpdateMask(slot
);
11074 else if(GetTypeId() == TYPEID_UNIT
&& ((Creature
*)this)->isPet())
11076 Pet
*pet
= ((Pet
*)this);
11077 if(pet
->isControlled())
11079 Unit
*owner
= GetOwner();
11080 if(owner
&& (owner
->GetTypeId() == TYPEID_PLAYER
) && ((Player
*)owner
)->GetGroup())
11082 ((Player
*)owner
)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS
);
11083 pet
->SetAuraUpdateMask(slot
);
11089 float Unit::GetAPMultiplier(WeaponAttackType attType
, bool normalized
)
11091 if (!normalized
|| GetTypeId() != TYPEID_PLAYER
)
11092 return float(GetAttackTime(attType
))/1000.0f
;
11094 Item
*Weapon
= ((Player
*)this)->GetWeaponForAttack(attType
);
11096 return 2.4; // fist attack
11098 switch (Weapon
->GetProto()->InventoryType
)
11100 case INVTYPE_2HWEAPON
:
11102 case INVTYPE_RANGED
:
11103 case INVTYPE_RANGEDRIGHT
:
11104 case INVTYPE_THROWN
:
11106 case INVTYPE_WEAPON
:
11107 case INVTYPE_WEAPONMAINHAND
:
11108 case INVTYPE_WEAPONOFFHAND
:
11110 return Weapon
->GetProto()->SubClass
==ITEM_SUBCLASS_WEAPON_DAGGER
? 1.7 : 2.4;
11114 Aura
* Unit::GetDummyAura( uint32 spell_id
) const
11116 Unit::AuraList
const& mDummy
= GetAurasByType(SPELL_AURA_DUMMY
);
11117 for(Unit::AuraList::const_iterator itr
= mDummy
.begin(); itr
!= mDummy
.end(); ++itr
)
11118 if ((*itr
)->GetId() == spell_id
)
11124 bool Unit::IsUnderLastManaUseEffect() const
11126 return getMSTimeDiff(m_lastManaUse
,getMSTime()) < 5000;
11129 void Unit::SetContestedPvP(Player
*attackedPlayer
)
11131 Player
* player
= GetCharmerOrOwnerPlayerOrPlayerItself();
11133 if(!player
|| attackedPlayer
&& (attackedPlayer
== player
|| player
->duel
&& player
->duel
->opponent
== attackedPlayer
))
11136 player
->SetContestedPvPTimer(30000);
11137 if(!player
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
11139 player
->addUnitState(UNIT_STAT_ATTACK_PLAYER
);
11140 player
->SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_CONTESTED_PVP
);
11141 // call MoveInLineOfSight for nearby contested guards
11142 SetVisibility(GetVisibility());
11144 if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
11146 addUnitState(UNIT_STAT_ATTACK_PLAYER
);
11147 // call MoveInLineOfSight for nearby contested guards
11148 SetVisibility(GetVisibility());
11152 void Unit::AddPetAura(PetAura
const* petSpell
)
11154 m_petAuras
.insert(petSpell
);
11155 if(Pet
* pet
= GetPet())
11156 pet
->CastPetAura(petSpell
);
11159 void Unit::RemovePetAura(PetAura
const* petSpell
)
11161 m_petAuras
.erase(petSpell
);
11162 if(Pet
* pet
= GetPet())
11163 pet
->RemoveAurasDueToSpell(petSpell
->GetAura(pet
->GetEntry()));
11166 Pet
* Unit::CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
)
11168 Pet
* pet
= new Pet(HUNTER_PET
);
11170 if(!pet
->CreateBaseAtCreature(creatureTarget
))
11176 pet
->SetOwnerGUID(GetGUID());
11177 pet
->SetCreatorGUID(GetGUID());
11178 pet
->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE
, getFaction());
11179 pet
->SetUInt32Value(UNIT_CREATED_BY_SPELL
, spell_id
);
11181 if(GetTypeId()==TYPEID_PLAYER
)
11182 pet
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
11184 uint32 level
= (creatureTarget
->getLevel() < (getLevel() - 5)) ? (getLevel() - 5) : creatureTarget
->getLevel();
11186 if(!pet
->InitStatsForLevel(level
))
11188 sLog
.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget
->GetEntry());
11193 pet
->GetCharmInfo()->SetPetNumber(objmgr
.GeneratePetNumber(), true);
11194 // this enables pet details window (Shift+P)
11195 pet
->AIM_Initialize();
11196 pet
->InitPetCreateSpells();
11197 pet
->InitTalentForLevel();
11198 pet
->SetHealth(pet
->GetMaxHealth());
11203 bool Unit::IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
)
11205 SpellEntry
const* spellProto
= aura
->GetSpellProto ();
11207 // Get proc Event Entry
11208 spellProcEvent
= spellmgr
.GetSpellProcEvent(spellProto
->Id
);
11210 // Aura info stored here
11211 Modifier
*mod
= aura
->GetModifier();
11213 if (isNonTriggerAura
[mod
->m_auraname
])
11215 // If not trigger by default and spellProcEvent==NULL - skip
11216 if (!isTriggerAura
[mod
->m_auraname
] && spellProcEvent
==NULL
)
11219 // Get EventProcFlag
11220 uint32 EventProcFlag
;
11221 if (spellProcEvent
&& spellProcEvent
->procFlags
) // if exist get custom spellProcEvent->procFlags
11222 EventProcFlag
= spellProcEvent
->procFlags
;
11224 EventProcFlag
= spellProto
->procFlags
; // else get from spell proto
11225 // Continue if no trigger exist
11226 if (!EventProcFlag
)
11229 // Check spellProcEvent data requirements
11230 if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent
, EventProcFlag
, procSpell
, procFlag
, procExtra
, active
))
11233 // In most cases req get honor or XP from kill
11234 if (EventProcFlag
& PROC_FLAG_KILL
&& GetTypeId() == TYPEID_PLAYER
)
11236 bool allow
= ((Player
*)this)->isHonorOrXPTarget(pVictim
);
11237 // Shadow Word: Death - can trigger from every kill
11238 if (aura
->GetId() == 32409)
11243 // Aura added by spell can`t trogger from self (prevent drop charges/do triggers)
11244 // But except periodic triggers (can triggered from self)
11245 if(procSpell
&& procSpell
->Id
== spellProto
->Id
&& !(spellProto
->procFlags
&PROC_FLAG_ON_TAKE_PERIODIC
))
11248 // Check if current equipment allows aura to proc
11249 if(!isVictim
&& GetTypeId() == TYPEID_PLAYER
)
11251 if(spellProto
->EquippedItemClass
== ITEM_CLASS_WEAPON
)
11254 if(attType
== BASE_ATTACK
)
11255 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
11256 else if (attType
== OFF_ATTACK
)
11257 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
11259 item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
);
11261 if (!((Player
*)this)->IsUseEquipedWeapon(attType
==BASE_ATTACK
))
11264 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
11267 else if(spellProto
->EquippedItemClass
== ITEM_CLASS_ARMOR
)
11269 // Check if player is wearing shield
11270 Item
*item
= ((Player
*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
11271 if(!item
|| item
->IsBroken() || item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
|| !((1<<item
->GetProto()->SubClass
) & spellProto
->EquippedItemSubClassMask
))
11275 // Get chance from spell
11276 float chance
= (float)spellProto
->procChance
;
11277 // If in spellProcEvent exist custom chance, chance = spellProcEvent->customChance;
11278 if(spellProcEvent
&& spellProcEvent
->customChance
)
11279 chance
= spellProcEvent
->customChance
;
11280 // If PPM exist calculate chance from PPM
11281 if(!isVictim
&& spellProcEvent
&& spellProcEvent
->ppmRate
!= 0)
11283 uint32 WeaponSpeed
= GetAttackTime(attType
);
11284 chance
= GetPPMProcChance(WeaponSpeed
, spellProcEvent
->ppmRate
);
11286 // Apply chance modifer aura
11287 if(Player
* modOwner
= GetSpellModOwner())
11288 modOwner
->ApplySpellMod(spellProto
->Id
,SPELLMOD_CHANCE_OF_SUCCESS
,chance
);
11290 return roll_chance_f(chance
);
11293 bool Unit::HandleMeandingAuraProc( Aura
* triggeredByAura
)
11295 // aura can be deleted at casts
11296 SpellEntry
const* spellProto
= triggeredByAura
->GetSpellProto();
11297 uint32 effIdx
= triggeredByAura
->GetEffIndex();
11298 int32 heal
= triggeredByAura
->GetModifier()->m_amount
;
11299 uint64 caster_guid
= triggeredByAura
->GetCasterGUID();
11302 int32 jumps
= triggeredByAura
->GetAuraCharges()-1;
11304 // current aura expire
11305 triggeredByAura
->SetAuraCharges(1); // will removed at next charges decrease
11307 // next target selection
11308 if(jumps
> 0 && GetTypeId()==TYPEID_PLAYER
&& IS_PLAYER_GUID(caster_guid
))
11311 if (spellProto
->EffectRadiusIndex
[effIdx
])
11312 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(spellProto
->EffectRadiusIndex
[effIdx
]));
11314 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(spellProto
->rangeIndex
));
11316 if(Player
* caster
= ((Player
*)triggeredByAura
->GetCaster()))
11318 caster
->ApplySpellMod(spellProto
->Id
, SPELLMOD_RADIUS
, radius
,NULL
);
11320 if(Player
* target
= ((Player
*)this)->GetNextRandomRaidMember(radius
))
11322 // aura will applied from caster, but spell casted from current aura holder
11323 SpellModifier
*mod
= new SpellModifier
;
11324 mod
->op
= SPELLMOD_CHARGES
;
11325 mod
->value
= jumps
-5; // negative
11326 mod
->type
= SPELLMOD_FLAT
;
11327 mod
->spellId
= spellProto
->Id
;
11328 mod
->mask
= spellProto
->SpellFamilyFlags
;
11329 mod
->mask2
= spellProto
->SpellFamilyFlags2
;
11331 caster
->AddSpellMod(mod
, true);
11332 CastCustomSpell(target
,spellProto
->Id
,&heal
,NULL
,NULL
,true,NULL
,triggeredByAura
,caster
->GetGUID());
11333 caster
->AddSpellMod(mod
, false);
11339 CastCustomSpell(this,33110,&heal
,NULL
,NULL
,true,NULL
,NULL
,caster_guid
);
11343 void Unit::RemoveAurasAtChanneledTarget(SpellEntry
const* spellInfo
)
11345 uint64 target_guid
= GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
);
11347 if(!IS_UNIT_GUID(target_guid
))
11350 Unit
* target
= ObjectAccessor::GetUnit(*this, target_guid
);
11354 for (AuraMap::iterator iter
= target
->GetAuras().begin(); iter
!= target
->GetAuras().end(); )
11356 if (iter
->second
->GetId() == spellInfo
->Id
&& iter
->second
->GetCasterGUID()==GetGUID())
11357 target
->RemoveAura(iter
);
11363 void Unit::SetPhaseMask(uint32 newPhaseMask
, bool update
)
11365 WorldObject::SetPhaseMask(newPhaseMask
,update
);
11368 if(Pet
* pet
= GetPet())
11369 pet
->SetPhaseMask(newPhaseMask
,true);
11372 void Unit::NearTeleportTo( float x
, float y
, float z
, float orientation
, bool casting
/*= false*/ )
11374 if(GetTypeId() == TYPEID_PLAYER
)
11375 ((Player
*)this)->TeleportTo(GetMapId(), x
, y
, z
, orientation
, TELE_TO_NOT_LEAVE_TRANSPORT
| TELE_TO_NOT_LEAVE_COMBAT
| TELE_TO_NOT_UNSUMMON_PET
| (casting
? TELE_TO_SPELL
: 0));
11378 GetMap()->CreatureRelocation((Creature
*)this, x
, y
, z
, orientation
);
11381 // Work strange for many spells: triggered active mover set for targeted player to creature
11382 //BuildTeleportAckMsg(&data, x, y, z, orientation);
11383 BuildHeartBeatMsg(&data
);
11384 SendMessageToSet(&data
, false);