aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBlaymoira <none@none>2009-03-06 20:14:07 +0100
committerBlaymoira <none@none>2009-03-06 20:14:07 +0100
commitb49732c04db0d5bf67bf78e73e9c22f2078fd47c (patch)
treee445fa32d805789d966505ffac97535152e852f6 /src
parentba05670747d7f5cc91ce4e623f2b89ba60e8081e (diff)
parent0b9d3f95de06da9e23bdd075a286679395dab49c (diff)
*Merge
--HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/bindings/scripts/scripts/npc/npcs_special.cpp2
-rw-r--r--src/game/Creature.cpp40
-rw-r--r--src/game/Creature.h7
-rw-r--r--src/game/CreatureAI.cpp6
-rw-r--r--src/game/CreatureAI.h8
-rw-r--r--src/game/GridNotifiersImpl.h6
-rw-r--r--src/game/Object.cpp2
-rw-r--r--src/game/OutdoorPvP.cpp2
-rw-r--r--src/game/Pet.cpp10
-rw-r--r--src/game/PetAI.cpp3
-rw-r--r--src/game/PetHandler.cpp7
-rw-r--r--src/game/Player.cpp4
-rw-r--r--src/game/Spell.cpp4
-rw-r--r--src/game/SpellEffects.cpp12
-rw-r--r--src/game/SpellMgr.cpp1
-rw-r--r--src/game/TemporarySummon.cpp2
-rw-r--r--src/game/Unit.cpp71
-rw-r--r--src/game/Unit.h18
18 files changed, 109 insertions, 96 deletions
diff --git a/src/bindings/scripts/scripts/npc/npcs_special.cpp b/src/bindings/scripts/scripts/npc/npcs_special.cpp
index 3a113b8fae6..dd043c73494 100644
--- a/src/bindings/scripts/scripts/npc/npcs_special.cpp
+++ b/src/bindings/scripts/scripts/npc/npcs_special.cpp
@@ -905,7 +905,7 @@ struct TRINITY_DLL_DECL npc_steam_tonkAI : public ScriptedAI
if (apply)
{
// Initialize the action bar without the melee attack command
- m_creature->InitCharmInfo(m_creature);
+ m_creature->InitCharmInfo();
m_creature->GetCharmInfo()->InitEmptyActionBar(false);
m_creature->SetReactState(REACT_PASSIVE);
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 23ae8229251..00e826404e6 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -132,7 +132,7 @@ bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
{
assistant->SetNoCallAssistance(true);
assistant->CombatStart(victim);
- if(assistant->AI())
+ if(assistant->IsAIEnabled)
assistant->AI()->AttackStart(victim);
}
}
@@ -141,7 +141,7 @@ bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
}
Creature::Creature() :
-Unit(), i_AI(NULL), i_AI_possessed(NULL),
+Unit(), i_AI(NULL),
lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLeaderGUID(0),
m_lootMoney(0), m_lootRecipient(0),
m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f),
@@ -169,12 +169,6 @@ Creature::~Creature()
delete i_AI;
i_AI = NULL;
-
- if (i_AI_possessed)
- {
- delete i_AI_possessed;
- i_AI_possessed = NULL;
- }
}
void Creature::AddToWorld()
@@ -490,7 +484,7 @@ void Creature::Update(uint32 diff)
if(!isAlive())
break;
- if(!IsInEvadeMode() && m_AI_enabled)
+ if(!IsInEvadeMode() && IsAIEnabled)
{
// do not allow the AI to be changed during update
m_AI_locked = true;
@@ -607,36 +601,10 @@ bool Creature::AIM_Initialize(CreatureAI* ai)
i_AI = ai ? ai : FactorySelector::selectAI(this);
if (oldAI)
delete oldAI;
- m_AI_enabled = true;
+ IsAIEnabled = true;
return true;
}
-void Creature::InitPossessedAI()
-{
- if (!isPossessed()) return;
-
- if (!i_AI_possessed)
- i_AI_possessed = new PossessedAI(this);
-
- // Signal the old AI that it's been disabled
- i_AI->OnPossess(true);
-
- if(!(GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_CHARM_AI))
- m_AI_enabled = false;
-}
-
-void Creature::DisablePossessedAI()
-{
- if (!i_AI_possessed) return;
-
- delete i_AI_possessed;
-
- // Signal the old AI that it's been re-enabled
- i_AI->OnPossess(false);
-
- m_AI_enabled = true;
-}
-
bool Creature::Create (uint32 guidlow, Map *map, uint32 Entry, uint32 team, const CreatureData *data)
{
SetMapId(map->GetId());
diff --git a/src/game/Creature.h b/src/game/Creature.h
index ea81053aab3..fc5318c1cdb 100644
--- a/src/game/Creature.h
+++ b/src/game/Creature.h
@@ -132,7 +132,7 @@ enum CreatureFlagsExtra
CREATURE_FLAG_EXTRA_NO_XP_AT_KILL = 0x00000040, // creature kill not provide XP
CREATURE_FLAG_EXTRA_TRIGGER = 0x00000080, // trigger creature
CREATURE_FLAG_EXTRA_WORLDEVENT = 0x00004000, // custom flag for world event creatures (left room for merging)
- CREATURE_FLAG_EXTRA_CHARM_AI = 0x00008000, // use ai when charmed
+ //CREATURE_FLAG_EXTRA_CHARM_AI = 0x00008000, // use ai when charmed
CREATURE_FLAG_EXTRA_NO_TAUNT = 0x00010000, // cannot be taunted
};
@@ -402,7 +402,6 @@ typedef std::map<uint32,time_t> CreatureSpellCooldowns;
class TRINITY_DLL_SPEC Creature : public Unit
{
CreatureAI *i_AI;
- CreatureAI *i_AI_possessed;
public:
@@ -467,11 +466,9 @@ class TRINITY_DLL_SPEC Creature : public Unit
bool IsInEvadeMode() const;
bool AIM_Initialize(CreatureAI* ai = NULL);
- void InitPossessedAI();
- void DisablePossessedAI();
void AI_SendMoveToPacket(float x, float y, float z, uint32 time, uint32 MovementFlags, uint8 type);
- CreatureAI* AI() { return isPossessed() && i_AI_possessed ? i_AI_possessed : i_AI; }
+ CreatureAI* AI() { return i_AI; }
uint32 GetShieldBlockValue() const //dunno mob block value
{
diff --git a/src/game/CreatureAI.cpp b/src/game/CreatureAI.cpp
index 409463b0052..fa512fce726 100644
--- a/src/game/CreatureAI.cpp
+++ b/src/game/CreatureAI.cpp
@@ -36,6 +36,12 @@ void UnitAI::AttackStart(Unit *victim)
}
}
+//Enable PlayerAI when charmed
+void PlayerAI::OnCharmed(bool apply) { me->IsAIEnabled = apply; }
+
+//Disable CreatureAI when charmed
+void CreatureAI::OnCharmed(bool apply) { me->IsAIEnabled = !apply; }
+
void CreatureAI::MoveInLineOfSight(Unit *who)
{
if(!me->getVictim() && me->canStartAttack(who))
diff --git a/src/game/CreatureAI.h b/src/game/CreatureAI.h
index a259475b543..fbfb8605866 100644
--- a/src/game/CreatureAI.h
+++ b/src/game/CreatureAI.h
@@ -78,6 +78,9 @@ class TRINITY_DLL_SPEC UnitAI
UnitAI(Unit *u) : me(u) {}
virtual void AttackStart(Unit *);
virtual void UpdateAI(const uint32 diff) = 0;
+
+ // Called when unit is charmed
+ virtual void OnCharmed(bool apply) = 0;
};
class TRINITY_DLL_SPEC PlayerAI : public UnitAI
@@ -86,6 +89,8 @@ class TRINITY_DLL_SPEC PlayerAI : public UnitAI
Player *me;
public:
PlayerAI(Player *p) : UnitAI((Unit*)p), me(p) {}
+
+ void OnCharmed(bool apply);
};
class TRINITY_DLL_SPEC SimpleCharmedAI : public PlayerAI
@@ -140,8 +145,7 @@ class TRINITY_DLL_SPEC CreatureAI : public UnitAI
// Called at waypoint reached or point movement finished
virtual void MovementInform(uint32 /*MovementType*/, uint32 /*Data*/) {}
- // Called when AI is temporarily replaced or put back when possess is applied or removed
- virtual void OnPossess(bool apply) {}
+ void OnCharmed(bool apply);
};
struct SelectableAI : public FactoryHolder<CreatureAI>, public Permissible<Creature>
diff --git a/src/game/GridNotifiersImpl.h b/src/game/GridNotifiersImpl.h
index 57fde9423d5..2a8b41f4fc8 100644
--- a/src/game/GridNotifiersImpl.h
+++ b/src/game/GridNotifiersImpl.h
@@ -74,7 +74,7 @@ inline void PlayerCreatureRelocationWorker(Player* pl, Creature* c)
// Creature AI reaction
if(c->HasReactState(REACT_AGGRESSIVE) && !c->hasUnitState(UNIT_STAT_SIGHTLESS))
{
- if( c->AI() && c->IsWithinSightDist(pl) && !c->IsInEvadeMode() )
+ if( c->IsAIEnabled && c->IsWithinSightDist(pl) && !c->IsInEvadeMode() )
c->AI()->MoveInLineOfSight(pl);
}
}
@@ -83,13 +83,13 @@ inline void CreatureCreatureRelocationWorker(Creature* c1, Creature* c2)
{
if(c1->HasReactState(REACT_AGGRESSIVE) && !c1->hasUnitState(UNIT_STAT_SIGHTLESS))
{
- if( c1->AI() && c1->IsWithinSightDist(c2) && !c1->IsInEvadeMode() )
+ if( c1->IsAIEnabled && c1->IsWithinSightDist(c2) && !c1->IsInEvadeMode() )
c1->AI()->MoveInLineOfSight(c2);
}
if(c2->HasReactState(REACT_AGGRESSIVE) && !c2->hasUnitState(UNIT_STAT_SIGHTLESS))
{
- if( c2->AI() && c1->IsWithinSightDist(c2) && !c2->IsInEvadeMode() )
+ if( c2->IsAIEnabled && c1->IsWithinSightDist(c2) && !c2->IsInEvadeMode() )
c2->AI()->MoveInLineOfSight(c1);
}
}
diff --git a/src/game/Object.cpp b/src/game/Object.cpp
index 3952ed12ed4..10eafcba93d 100644
--- a/src/game/Object.cpp
+++ b/src/game/Object.cpp
@@ -1601,7 +1601,7 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa
pCreature->SetHomePosition(x, y, z, ang);
pCreature->Summon(spwtype, despwtime);
- if(GetTypeId()==TYPEID_UNIT && ((Creature*)this)->AI())
+ if(GetTypeId()==TYPEID_UNIT && ((Creature*)this)->IsAIEnabled)
((Creature*)this)->AI()->JustSummoned(pCreature);
if(pCreature->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER && pCreature->m_spells[0])
diff --git a/src/game/OutdoorPvP.cpp b/src/game/OutdoorPvP.cpp
index 57f072ebbef..99b1c9a55f0 100644
--- a/src/game/OutdoorPvP.cpp
+++ b/src/game/OutdoorPvP.cpp
@@ -56,7 +56,7 @@ void OutdoorPvPObjective::HandlePlayerActivityChanged(Player * plr)
{
if(m_CapturePointCreature)
if(Creature * c = HashMapHolder<Creature>::Find(m_CapturePointCreature))
- if(c->AI())
+ if(c->IsAIEnabled)
c->AI()->MoveInLineOfSight(plr);
}
diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp
index 00452fc0d95..a5d80266242 100644
--- a/src/game/Pet.cpp
+++ b/src/game/Pet.cpp
@@ -83,12 +83,12 @@ Pet::Pet(PetType type) : Creature()
m_auraUpdateMask = 0;
// pets always have a charminfo, even if they are not actually charmed
- CharmInfo* charmInfo = InitCharmInfo(this);
+ CharmInfo* charmInfo = InitCharmInfo();
if(type == MINI_PET || type == POSSESSED_PET) // always passive
- charmInfo->SetReactState(REACT_PASSIVE);
+ SetReactState(REACT_PASSIVE);
else if(type == GUARDIAN_PET) // always aggressive
- charmInfo->SetReactState(REACT_AGGRESSIVE);
+ SetReactState(REACT_AGGRESSIVE);
m_spells.clear();
m_Auras.clear();
@@ -253,7 +253,7 @@ bool Pet::LoadPetFromDB( Unit* owner, uint32 petentry, uint32 petnumber, bool cu
SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32());
SetUInt64Value(UNIT_FIELD_CREATEDBY, owner->GetGUID());
- m_charmInfo->SetReactState( ReactStates( fields[6].GetUInt8() ));
+ SetReactState( ReactStates( fields[6].GetUInt8() ));
m_loyaltyPoints = fields[7].GetInt32();
uint32 savedhealth = fields[13].GetUInt32();
@@ -445,7 +445,7 @@ void Pet::SavePetToDB(PetSaveMode mode)
<< GetNativeDisplayId() << ", "
<< getLevel() << ", "
<< GetUInt32Value(UNIT_FIELD_PETEXPERIENCE) << ", "
- << uint32(m_charmInfo->GetReactState()) << ", "
+ << uint32(GetReactState()) << ", "
<< m_loyaltyPoints << ", "
<< GetLoyaltyLevel() << ", "
<< m_TrainingPoints << ", "
diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp
index f841d83fdb0..cf639f84db5 100644
--- a/src/game/PetAI.cpp
+++ b/src/game/PetAI.cpp
@@ -47,7 +47,6 @@ PetAI::PetAI(Creature *c) : CreatureAI(c), i_pet(*c), i_tracker(TIME_INTERVAL_LO
void PetAI::MoveInLineOfSight(Unit *u)
{
if( !i_pet.getVictim() && i_pet.GetCharmInfo() &&
- i_pet.GetCharmInfo()->HasReactState(REACT_AGGRESSIVE) &&
i_pet.IsHostileTo( u ) && i_pet.canAttack(u) &&
u->isInAccessiblePlaceFor(&i_pet))
{
@@ -181,7 +180,7 @@ void PetAI::UpdateAI(const uint32 diff)
}
else if(owner && i_pet.GetCharmInfo())
{
- if(owner->isInCombat() && !(i_pet.GetCharmInfo()->HasReactState(REACT_PASSIVE) || i_pet.GetCharmInfo()->HasCommandState(COMMAND_STAY)))
+ if(owner->isInCombat() && !(i_pet.HasReactState(REACT_PASSIVE) || i_pet.GetCharmInfo()->HasCommandState(COMMAND_STAY)))
{
AttackStart(owner->getAttackerForHelper());
}
diff --git a/src/game/PetHandler.cpp b/src/game/PetHandler.cpp
index 05c889b8cf9..19b05797618 100644
--- a/src/game/PetHandler.cpp
+++ b/src/game/PetHandler.cpp
@@ -120,7 +120,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
if(pet->GetTypeId() != TYPEID_PLAYER)
{
- if (((Creature*)pet)->AI())
+ if (((Creature*)pet)->IsAIEnabled)
((Creature*)pet)->AI()->AttackStart(TargetUnit);
//10% chance to play special pet attack talk, else growl
@@ -165,7 +165,8 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
case REACT_PASSIVE: //passive
case REACT_DEFENSIVE: //recovery
case REACT_AGGRESSIVE: //activete
- charmInfo->SetReactState( ReactStates(spellid) );
+ if(pet->GetTypeId() == TYPEID_UNIT)
+ ((Creature*)pet)->SetReactState( ReactStates(spellid) );
break;
}
break;
@@ -241,7 +242,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
if(pet->getVictim())
pet->AttackStop();
pet->GetMotionMaster()->Clear();
- if (((Creature*)pet)->AI())
+ if (((Creature*)pet)->IsAIEnabled)
((Creature*)pet)->AI()->AttackStart(unit_target);
}
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index 9aa5d9b8b74..5c9c0c978e2 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -16429,7 +16429,7 @@ void Player::PetSpellInitialize()
CharmInfo *charmInfo = pet->GetCharmInfo();
//16
- data << (uint64)pet->GetGUID() << uint32(0x00000000) << uint8(charmInfo->GetReactState()) << uint8(charmInfo->GetCommandState()) << uint16(0);
+ data << (uint64)pet->GetGUID() << uint32(0x00000000) << uint8(pet->GetReactState()) << uint8(charmInfo->GetCommandState()) << uint16(0);
for(uint32 i = 0; i < 10; i++) //40
{
@@ -16538,7 +16538,7 @@ void Player::CharmSpellInitialize()
data << (uint64)charm->GetGUID() << uint32(0x00000000);
if(charm->GetTypeId() != TYPEID_PLAYER)
- data << uint8(charmInfo->GetReactState()) << uint8(charmInfo->GetCommandState());
+ data << uint8(((Creature*)charm)->GetReactState()) << uint8(charmInfo->GetCommandState());
else
data << uint8(0) << uint8(0);
diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp
index cc75eed5b4e..707f1819968 100644
--- a/src/game/Spell.cpp
+++ b/src/game/Spell.cpp
@@ -1212,10 +1212,10 @@ void Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask)
}
}
- if(unit->GetTypeId() == TYPEID_UNIT && ((Creature*)unit)->AI())
+ if(unit->GetTypeId() == TYPEID_UNIT && ((Creature*)unit)->IsAIEnabled)
((Creature*)unit)->AI()->SpellHit(m_caster, m_spellInfo);
- if(m_caster->GetTypeId() == TYPEID_UNIT && ((Creature*)m_caster)->AI())
+ if(m_caster->GetTypeId() == TYPEID_UNIT && ((Creature*)m_caster)->IsAIEnabled)
((Creature*)m_caster)->AI()->SpellHitTarget(unit, m_spellInfo);
for(ChanceTriggerSpells::const_iterator i = m_ChanceTriggerSpells.begin(); i != m_ChanceTriggerSpells.end(); ++i)
diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp
index cad6190294d..64b7811d462 100644
--- a/src/game/SpellEffects.cpp
+++ b/src/game/SpellEffects.cpp
@@ -1146,7 +1146,7 @@ void Spell::EffectDummy(uint32 i)
pCreature->SetHealth(health);
- if(pCreature->AI())
+ if(pCreature->IsAIEnabled)
pCreature->AI()->AttackStart(m_caster);
return;
@@ -1178,7 +1178,7 @@ void Spell::EffectDummy(uint32 i)
pCreature->SetHealth(health);
((Player*)m_caster)->KilledMonster(16992,pCreature->GetGUID());
- if (pCreature->AI())
+ if (pCreature->IsAIEnabled)
pCreature->AI()->AttackStart(m_caster);
return;
@@ -3244,7 +3244,7 @@ void Spell::EffectSummon(uint32 i)
name.append(petTypeSuffix[spawnCreature->getPetType()]);
spawnCreature->SetName( name );
- spawnCreature->GetCharmInfo()->SetReactState( REACT_DEFENSIVE );
+ spawnCreature->SetReactState( REACT_DEFENSIVE );
}
void Spell::EffectLearnSpell(uint32 i)
@@ -3471,7 +3471,7 @@ void Spell::EffectPickPocket(uint32 /*i*/)
{
// Reveal action + get attack
m_caster->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_TALK);
- if (((Creature*)unitTarget)->AI())
+ if (((Creature*)unitTarget)->IsAIEnabled)
((Creature*)unitTarget)->AI()->AttackStart(m_caster);
}
}
@@ -4022,9 +4022,9 @@ void Spell::EffectSummonPet(uint32 i)
if(m_caster->GetTypeId() == TYPEID_UNIT)
{
if ( ((Creature*)m_caster)->isTotem() )
- pet->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE);
+ pet->SetReactState(REACT_AGGRESSIVE);
else
- pet->GetCharmInfo()->SetReactState(REACT_DEFENSIVE);
+ pet->SetReactState(REACT_DEFENSIVE);
}
pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp
index 6ab141bba90..c01b3c69ca3 100644
--- a/src/game/SpellMgr.cpp
+++ b/src/game/SpellMgr.cpp
@@ -751,6 +751,7 @@ bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellI
switch(spec1)
{
case SPELL_JUDGEMENT:
+ case SPELL_MAGE_POLYMORPH:
if(GetSpellSpecific(spellInfo2->Id) == spec1)
return true;
break;
diff --git a/src/game/TemporarySummon.cpp b/src/game/TemporarySummon.cpp
index d30ad9ec56e..bbe8fa9c104 100644
--- a/src/game/TemporarySummon.cpp
+++ b/src/game/TemporarySummon.cpp
@@ -176,7 +176,7 @@ void TemporarySummon::UnSummon()
AddObjectToRemoveList();
Unit* sum = m_summoner ? ObjectAccessor::GetUnit(*this, m_summoner) : NULL;
- if (sum && sum->GetTypeId() == TYPEID_UNIT && ((Creature*)sum)->AI())
+ if (sum && sum->GetTypeId() == TYPEID_UNIT && ((Creature*)sum)->IsAIEnabled)
{
((Creature*)sum)->AI()->SummonedCreatureDespawn(this);
}
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
diff --git a/src/game/Unit.h b/src/game/Unit.h
index c6648f00a30..d103525208c 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -709,15 +709,16 @@ struct TRINITY_DLL_SPEC CharmInfo
{
public:
explicit CharmInfo(Unit* unit);
+ ~CharmInfo();
uint32 GetPetNumber() const { return m_petnumber; }
void SetPetNumber(uint32 petnumber, bool statwindow);
void SetCommandState(CommandStates st) { m_CommandState = st; }
CommandStates GetCommandState() { return m_CommandState; }
bool HasCommandState(CommandStates state) { return (m_CommandState == state); }
- void SetReactState(ReactStates st) { m_reactState = st; }
- ReactStates GetReactState() { return m_reactState; }
- bool HasReactState(ReactStates state) { return (m_reactState == state); }
+ //void SetReactState(ReactStates st) { m_reactState = st; }
+ //ReactStates GetReactState() { return m_reactState; }
+ //bool HasReactState(ReactStates state) { return (m_reactState == state); }
void InitPossessCreateSpells();
void InitCharmCreateSpells();
@@ -734,9 +735,12 @@ struct TRINITY_DLL_SPEC CharmInfo
UnitActionBarEntry PetActionBar[10];
CharmSpellEntry m_charmspells[4];
CommandStates m_CommandState;
- ReactStates m_reactState;
+ //ReactStates m_reactState;
uint32 m_petnumber;
bool m_barInit;
+
+ //for restoration after charmed
+ ReactStates m_oldReactState;
};
// for clearing special attacks
@@ -1103,7 +1107,8 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
bool isPossessing(Unit* u) const { return u->isPossessed() && GetCharmGUID() == u->GetGUID(); }
CharmInfo* GetCharmInfo() { return m_charmInfo; }
- CharmInfo* InitCharmInfo(Unit* charm);
+ CharmInfo* InitCharmInfo();
+ void DeleteCharmInfo();
SharedVisionList const& GetSharedVisionList() { return m_sharedVision; }
void AddPlayerToVision(Player* plr);
void RemovePlayerFromVision(Player* plr);
@@ -1414,6 +1419,8 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
}
uint32 GetReducedThreatPercent() { return m_reducedThreatPercent; }
Unit *GetMisdirectionTarget() { return m_misdirectionTargetGUID ? GetUnit(*this, m_misdirectionTargetGUID) : NULL; }
+
+ bool IsAIEnabled;
protected:
explicit Unit ();
@@ -1466,7 +1473,6 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
ThreatManager m_ThreatManager;
- bool m_AI_enabled;
private:
void SendAttackStop(Unit* victim); // only from AttackStop(Unit*)
//void SendAttackStart(Unit* pVictim); // only from Unit::AttackStart(Unit*)