diff options
Diffstat (limited to 'src/game/Unit.cpp')
-rw-r--r-- | src/game/Unit.cpp | 71 |
1 files changed, 51 insertions, 20 deletions
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index bb0229aeef5..a3fc2400208 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -149,7 +149,7 @@ bool IsPassiveStackableSpell( uint32 spellId ) Unit::Unit() : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this) -, m_IsInNotifyList(false), m_Notified(false), m_AI_enabled(false) +, m_IsInNotifyList(false), m_Notified(false), IsAIEnabled(false) { m_objectType |= TYPEMASK_UNIT; m_objectTypeId = TYPEID_UNIT; @@ -627,7 +627,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa } //Script Event damage taken - if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->AI() ) + if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->IsAIEnabled ) { ((Creature *)pVictim)->AI()->DamageTaken(this, damage); @@ -778,7 +778,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa if(!getVictim()) /*{ // if have target and damage pVictim just call AI reaction - if(pVictim != getVictim() && pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->AI()) + if(pVictim != getVictim() && pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsAIEnabled) ((Creature*)pVictim)->AI()->AttackedBy(this); } else*/ @@ -8283,7 +8283,7 @@ bool Unit::Attack(Unit *victim, bool meleeAttack) m_attacking = victim; m_attacking->_addAttacker(this); - //if(m_attacking->GetTypeId()==TYPEID_UNIT && ((Creature*)m_attacking)->AI()) + //if(m_attacking->GetTypeId()==TYPEID_UNIT && ((Creature*)m_attacking)->IsAIEnabled) // ((Creature*)m_attacking)->AI()->AttackedBy(this); if(GetTypeId()==TYPEID_UNIT) @@ -8703,6 +8703,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 } } + bool hasmangle=false; // .. taken pct: dummy auras AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); for(AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i) @@ -8725,6 +8726,10 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 //Mangle case 2312: case 44955: + // don't apply mod twice + if (hasmangle) + break; + hasmangle=true; for(int j=0;j<3;j++) { if(GetEffectMechanic(spellProto, j)==MECHANIC_BLEED) @@ -9831,7 +9836,7 @@ void Unit::CombatStart(Unit* target) target->SetStandState(PLAYER_STATE_NONE); if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER - && !((Creature*)target)->HasReactState(REACT_PASSIVE) && ((Creature*)target)->AI()) + && !((Creature*)target)->HasReactState(REACT_PASSIVE) && ((Creature*)target)->IsAIEnabled) ((Creature*)target)->AI()->AttackStart(this); SetInCombatWith(target); @@ -10454,7 +10459,7 @@ void Unit::TauntApply(Unit* taunter) return; SetInFront(taunter); - if (((Creature*)this)->AI()) + if (((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->AttackStart(taunter); m_ThreatManager.tauntApply(taunter); @@ -10478,7 +10483,7 @@ void Unit::TauntFadeOut(Unit *taunter) if(m_ThreatManager.isThreatListEmpty()) { - if(((Creature*)this)->AI()) + if(((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->EnterEvadeMode(); return; } @@ -10489,7 +10494,7 @@ void Unit::TauntFadeOut(Unit *taunter) if (target && target != taunter) { SetInFront(target); - if (((Creature*)this)->AI()) + if (((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->AttackStart(target); } } @@ -11225,21 +11230,43 @@ void Unit::CleanupsBeforeDelete() RemoveFromWorld(); } -CharmInfo* Unit::InitCharmInfo(Unit *charm) +CharmInfo* Unit::InitCharmInfo() { if(!m_charmInfo) - m_charmInfo = new CharmInfo(charm); + m_charmInfo = new CharmInfo(this); return m_charmInfo; } +void Unit::DeleteCharmInfo() +{ + if(!m_charmInfo) + return; + + delete m_charmInfo; + m_charmInfo = NULL; +} + CharmInfo::CharmInfo(Unit* unit) -: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_reactState(REACT_PASSIVE), m_petnumber(0), m_barInit(false) +: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_petnumber(0), m_barInit(false) { for(int i =0; i<4; ++i) { m_charmspells[i].spellId = 0; m_charmspells[i].active = ACT_DISABLED; } + if(m_unit->GetTypeId() == TYPEID_UNIT) + { + m_oldReactState = ((Creature*)m_unit)->GetReactState(); + ((Creature*)m_unit)->SetReactState(REACT_PASSIVE); + } +} + +CharmInfo::~CharmInfo() +{ + if(m_unit->GetTypeId() == TYPEID_UNIT) + { + ((Creature*)m_unit)->SetReactState(m_oldReactState); + } } void CharmInfo::InitPetActionBar() @@ -12084,7 +12111,7 @@ void Unit::SetFeared(bool apply, uint64 casterGUID, uint32 spellID) // attack caster if can Unit* caster = ObjectAccessor::GetObjectInWorld(casterGUID, (Unit*)NULL); - if(caster && caster != getVictim() && ((Creature*)this)->AI()) + if(caster && caster != getVictim() && ((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->AttackStart(caster); } } @@ -12768,7 +12795,7 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss) ((Player*)pVictim)->GetSession()->SendPacket(&data); } // Call KilledUnit for creatures - if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) + if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->KilledUnit(pVictim); // last damage from non duel opponent or opponent controlled creature @@ -12791,11 +12818,11 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss) } // Call KilledUnit for creatures, this needs to be called after the lootable flag is set - if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) + if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->IsAIEnabled) ((Creature*)this)->AI()->KilledUnit(pVictim); // Call creature just died function - if (cVictim->AI()) + if (cVictim->IsAIEnabled) cVictim->AI()->JustDied(this); // Dungeon specific stuff, only applies to players killing creatures @@ -13059,7 +13086,7 @@ void Unit::SetCharmedOrPossessedBy(Unit* charmer, bool possess) if(GetTypeId() == TYPEID_UNIT) { - ((Creature*)this)->InitPossessedAI(); + ((Creature*)this)->AI()->OnCharmed(true); StopMoving(); GetMotionMaster()->Clear(false); GetMotionMaster()->MoveIdle(); @@ -13074,8 +13101,7 @@ void Unit::SetCharmedOrPossessedBy(Unit* charmer, bool possess) // Pets already have a properly initialized CharmInfo, don't overwrite it. if(GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet()) { - CharmInfo *charmInfo = InitCharmInfo(this); - charmInfo->SetReactState(REACT_DEFENSIVE); + CharmInfo *charmInfo = InitCharmInfo(); if(possess) charmInfo->InitPossessCreateSpells(); else @@ -13145,8 +13171,8 @@ void Unit::RemoveCharmedOrPossessedBy(Unit *charmer) if(!((Creature*)this)->isPet()) RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); - ((Creature*)this)->DisablePossessedAI(); - if(isAlive() && ((Creature*)this)->AI()) + ((Creature*)this)->AI()->OnCharmed(false); + if(isAlive() && ((Creature*)this)->IsAIEnabled) { if(charmer && !IsFriendlyTo(charmer)) { @@ -13192,6 +13218,11 @@ void Unit::RemoveCharmedOrPossessedBy(Unit *charmer) } } + if(GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet()) + { + DeleteCharmInfo(); + } + if(possess || charmer->GetTypeId() == TYPEID_PLAYER) { // Remove pet spell action bar |