diff options
-rw-r--r-- | sql/world.sql | 10 | ||||
-rw-r--r-- | src/bindings/scripts/include/sc_creature.cpp | 23 | ||||
-rw-r--r-- | src/bindings/scripts/include/sc_creature.h | 3 | ||||
-rw-r--r-- | src/game/BattleGround.cpp | 4 | ||||
-rw-r--r-- | src/game/BattleGround.h | 2 | ||||
-rw-r--r-- | src/game/Creature.cpp | 14 | ||||
-rw-r--r-- | src/game/Creature.h | 4 | ||||
-rw-r--r-- | src/game/CreatureAI.cpp | 25 | ||||
-rw-r--r-- | src/game/CreatureAI.h | 3 | ||||
-rw-r--r-- | src/game/GridNotifiersImpl.h | 18 | ||||
-rw-r--r-- | src/game/Map.cpp | 49 | ||||
-rw-r--r-- | src/game/NullCreatureAI.cpp | 25 | ||||
-rw-r--r-- | src/game/NullCreatureAI.h | 12 | ||||
-rw-r--r-- | src/game/PetAI.cpp | 95 | ||||
-rw-r--r-- | src/game/PetAI.h | 2 | ||||
-rw-r--r-- | src/game/PetHandler.cpp | 4 | ||||
-rw-r--r-- | src/game/PossessedAI.cpp | 102 | ||||
-rw-r--r-- | src/game/PossessedAI.h | 28 | ||||
-rw-r--r-- | src/game/SharedDefines.h | 2 | ||||
-rw-r--r-- | src/game/Spell.cpp | 7 | ||||
-rw-r--r-- | src/game/SpellEffects.cpp | 7 | ||||
-rw-r--r-- | src/game/SpellMgr.cpp | 2 | ||||
-rw-r--r-- | src/game/Unit.cpp | 31 | ||||
-rw-r--r-- | src/game/Unit.h | 3 |
24 files changed, 170 insertions, 305 deletions
diff --git a/sql/world.sql b/sql/world.sql index 43e66c8110e..9ab43e606bf 100644 --- a/sql/world.sql +++ b/sql/world.sql @@ -550,7 +550,7 @@ CREATE TABLE `creature_formations` ( `dist` float unsigned NOT NULL, `angle` float unsigned NOT NULL, `groupAI` int(11) unsigned NOT NULL, - PRIMARY KEY (`follower`)); + PRIMARY KEY (`memberGUID`)); -- -- Dumping data for table `creature_formations` @@ -13707,7 +13707,7 @@ CREATE TABLE `transport_events` ( -- Dumping data for table `transport_events` -- -LOCK TABLES `trinity_string` WRITE; +LOCK TABLES `transport_events` WRITE; /*!40000 ALTER TABLE `transport_events` DISABLE KEYS */; /*!40000 ALTER TABLE `transport_events` ENABLE KEYS */; UNLOCK TABLES; @@ -13777,9 +13777,9 @@ CREATE TABLE `waypoint_data` ( -- Dumping data for table `waypoint_data` -- -LOCK TABLES `waypoint_scripts` WRITE; -/*!40000 ALTER TABLE `waypoint_scripts` DISABLE KEYS */; -/*!40000 ALTER TABLE `waypoint_scripts` ENABLE KEYS */; +LOCK TABLES `waypoint_data` WRITE; +/*!40000 ALTER TABLE `waypoint_data` DISABLE KEYS */; +/*!40000 ALTER TABLE `waypoint_data` ENABLE KEYS */; UNLOCK TABLES; -- diff --git a/src/bindings/scripts/include/sc_creature.cpp b/src/bindings/scripts/include/sc_creature.cpp index efb6ef36fa2..1f5dc77aa26 100644 --- a/src/bindings/scripts/include/sc_creature.cpp +++ b/src/bindings/scripts/include/sc_creature.cpp @@ -169,29 +169,6 @@ void ScriptedAI::DoStartNoMovement(Unit* victim) m_creature->StopMoving(); } -void ScriptedAI::DoMeleeAttackIfReady() -{ - //Make sure our attack is ready before checking distance - if (m_creature->isAttackReady()) - { - //If we are within range melee the target - if (m_creature->IsWithinMeleeRange(m_creature->getVictim())) - { - m_creature->AttackerStateUpdate(m_creature->getVictim()); - m_creature->resetAttackTimer(); - } - } - if (m_creature->haveOffhandWeapon() && m_creature->isAttackReady(OFF_ATTACK) && !m_creature->hasUnitState(UNIT_STAT_CASTING)) - { - //If we are within range melee the target - if (m_creature->IsWithinMeleeRange(m_creature->getVictim())) - { - m_creature->AttackerStateUpdate(m_creature->getVictim(), OFF_ATTACK); - m_creature->resetAttackTimer(OFF_ATTACK); - } - } -} - void ScriptedAI::DoStopAttack() { if (m_creature->getVictim() != NULL) diff --git a/src/bindings/scripts/include/sc_creature.h b/src/bindings/scripts/include/sc_creature.h index 03039fd709e..d6ea69bf457 100644 --- a/src/bindings/scripts/include/sc_creature.h +++ b/src/bindings/scripts/include/sc_creature.h @@ -113,9 +113,6 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI //Start no movement on victim void DoStartNoMovement(Unit* victim); - //Do melee swing of current victim if in rnage and ready and not casting - void DoMeleeAttackIfReady(); - //Stop attack of current victim void DoStopAttack(); diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp index 39dc135cffd..e058589483f 100644 --- a/src/game/BattleGround.cpp +++ b/src/game/BattleGround.cpp @@ -1128,9 +1128,7 @@ void BattleGround::AddPlayer(Player *plr) if(GetStatus() == STATUS_WAIT_JOIN) // not started yet { - if(GetStatus() == STATUS_IN_PROGRESS) - plr->RemoveAurasDueToSpell(SPELL_ARENA_PREPARATION); - else plr->CastSpell(plr, SPELL_ARENA_PREPARATION, true); + plr->CastSpell(plr, SPELL_ARENA_PREPARATION, true); plr->SetHealth(plr->GetMaxHealth()); plr->SetPower(POWER_MANA, plr->GetMaxPower(POWER_MANA)); diff --git a/src/game/BattleGround.h b/src/game/BattleGround.h index 7d11fc78944..5f483564c98 100644 --- a/src/game/BattleGround.h +++ b/src/game/BattleGround.h @@ -71,7 +71,7 @@ enum BattleGroundSpells SPELL_SPIRIT_HEAL_CHANNEL = 22011, // Spirit Heal Channel SPELL_SPIRIT_HEAL = 22012, // Spirit Heal SPELL_RESURRECTION_VISUAL = 24171, // Resurrection Impact Visual - SPELL_ARENA_PREPARATION = 32728, // use this one, 32727 has an invisibility aura which is wrong + SPELL_ARENA_PREPARATION = 32727, // use this one, 32728 not correct SPELL_ALLIANCE_GOLD_FLAG = 32724, SPELL_ALLIANCE_GREEN_FLAG = 32725, SPELL_HORDE_GOLD_FLAG = 35774, diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 71f53cdabb0..115906e94a3 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -45,7 +45,6 @@ #include "CellImpl.h" #include "OutdoorPvPMgr.h" #include "GameEventMgr.h" -#include "PossessedAI.h" #include "CreatureGroups.h" // apply implementation of the singletons #include "Policies/SingletonImp.h" @@ -133,7 +132,7 @@ bool AssistDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/) } Creature::Creature() : -Unit(), i_AI(NULL), +Unit(), 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), @@ -414,7 +413,7 @@ void Creature::Update(uint32 diff) setDeathState( JUST_ALIVED ); //Call AI respawn virtual function - i_AI->JustRespawned(); + AI()->JustRespawned(); uint16 poolid = poolhandler.IsPartOfAPool(GetGUIDLow(), GetTypeId()); if (poolid) @@ -478,6 +477,9 @@ void Creature::Update(uint32 diff) if(!isAlive()) break; + // if creature is charmed, switch to charmed AI + UpdateCharmAI(); + if(!IsInEvadeMode() && IsAIEnabled) { // do not allow the AI to be changed during update @@ -590,11 +592,9 @@ bool Creature::AIM_Initialize(CreatureAI* ai) return false; } - CreatureAI * oldAI = i_AI; - i_motionMaster.Initialize(); + if(i_AI) delete i_AI; i_AI = ai ? ai : FactorySelector::selectAI(this); - if (oldAI) - delete oldAI; + i_motionMaster.Initialize(); IsAIEnabled = true; return true; } diff --git a/src/game/Creature.h b/src/game/Creature.h index 8c448432cbe..7a2a9508216 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -416,8 +416,6 @@ typedef std::map<uint32,time_t> CreatureSpellCooldowns; class TRINITY_DLL_SPEC Creature : public Unit { - CreatureAI *i_AI; - public: explicit Creature(); @@ -484,7 +482,7 @@ class TRINITY_DLL_SPEC Creature : public Unit bool AIM_Initialize(CreatureAI* ai = NULL); void AI_SendMoveToPacket(float x, float y, float z, uint32 time, uint32 MovementFlags, uint8 type); - CreatureAI* AI() { return i_AI; } + CreatureAI* AI() { return (CreatureAI*)i_AI; } uint32 GetShieldBlockValue() const //dunno mob block value { diff --git a/src/game/CreatureAI.cpp b/src/game/CreatureAI.cpp index 06b2d382d8f..0fa85a4d9e2 100644 --- a/src/game/CreatureAI.cpp +++ b/src/game/CreatureAI.cpp @@ -36,11 +36,34 @@ void UnitAI::AttackStart(Unit *victim) } } +void UnitAI::DoMeleeAttackIfReady() +{ + //Make sure our attack is ready and we aren't currently casting before checking distance + if (me->isAttackReady() && !me->hasUnitState(UNIT_STAT_CASTING)) + { + //If we are within range melee the target + if (me->IsWithinMeleeRange(me->getVictim())) + { + me->AttackerStateUpdate(me->getVictim()); + me->resetAttackTimer(); + } + } + if (me->haveOffhandWeapon() && me->isAttackReady(OFF_ATTACK) && !me->hasUnitState(UNIT_STAT_CASTING)) + { + //If we are within range melee the target + if (me->IsWithinMeleeRange(me->getVictim())) + { + me->AttackerStateUpdate(me->getVictim(), OFF_ATTACK); + me->resetAttackTimer(OFF_ATTACK); + } + } +} + //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::OnCharmed(bool apply) { /*me->IsAIEnabled = !apply;*/ } void CreatureAI::MoveInLineOfSight(Unit *who) { diff --git a/src/game/CreatureAI.h b/src/game/CreatureAI.h index 78d856416ff..a15ae59a0ad 100644 --- a/src/game/CreatureAI.h +++ b/src/game/CreatureAI.h @@ -81,6 +81,9 @@ class TRINITY_DLL_SPEC UnitAI // Called when unit is charmed virtual void OnCharmed(bool apply) = 0; + + //Do melee swing of current victim if in rnage and ready and not casting + void DoMeleeAttackIfReady(); }; class TRINITY_DLL_SPEC PlayerAI : public UnitAI diff --git a/src/game/GridNotifiersImpl.h b/src/game/GridNotifiersImpl.h index 9bf0bbe6fb3..33e3563ae7e 100644 --- a/src/game/GridNotifiersImpl.h +++ b/src/game/GridNotifiersImpl.h @@ -175,7 +175,18 @@ inline void Trinity::DynamicObjectUpdater::VisitHelper(Unit* target) if( target->GetTypeId()==TYPEID_PLAYER && target != i_check && (((Player*)target)->isGameMaster() || ((Player*)target)->GetVisibility()==VISIBILITY_OFF) ) return; - if (i_check->GetTypeId()==TYPEID_PLAYER ) + if (i_dynobject.IsAffecting(target)) + return; + + SpellEntry const *spellInfo = sSpellStore.LookupEntry(i_dynobject.GetSpellId()); + uint32 eff_index = i_dynobject.GetEffIndex(); + if(spellInfo->EffectImplicitTargetB[eff_index] == TARGET_UNIT_AREA_ALLY_CHANNEL + || spellInfo->EffectImplicitTargetB[eff_index] == TARGET_UNIT_AREA_ALLY_GROUND) + { + if(!i_check->IsFriendlyTo(target)) + return; + } + else if( i_check->GetTypeId()==TYPEID_PLAYER ) { if (i_check->IsFriendlyTo( target )) return; @@ -186,11 +197,6 @@ inline void Trinity::DynamicObjectUpdater::VisitHelper(Unit* target) return; } - if (i_dynobject.IsAffecting(target)) - return; - - SpellEntry const *spellInfo = sSpellStore.LookupEntry(i_dynobject.GetSpellId()); - uint32 eff_index = i_dynobject.GetEffIndex(); // Check target immune to spell or aura if (target->IsImmunedToSpell(spellInfo) || target->IsImmunedToSpellEffect(spellInfo, eff_index)) return; diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 06ca05dee81..790a3661101 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -696,6 +696,33 @@ void Map::Update(const uint32 &t_diff) if(!obj->IsInWorld()) continue; + // Update bindsight players + /*if(obj->isType(TYPEMASK_UNIT)) + { + if(!((Unit*)obj)->GetSharedVisionList().empty()) + for(SharedVisionList::const_iterator itr = ((Unit*)obj)->GetSharedVisionList().begin(); itr != ((Unit*)obj)->GetSharedVisionList().end(); ++itr) + { + if(!*itr) + { + sLog.outError("unit %u has invalid shared vision player, list size %u", obj->GetEntry(), ((Unit*)obj)->GetSharedVisionList().size()); + continue; + } + Trinity::PlayerVisibilityNotifier notifier(**itr); + VisitAll(obj->GetPositionX(), obj->GetPositionY(), World::GetMaxVisibleDistance(), notifier); + notifier.Notify(); + } + } + else */if(obj->GetTypeId() == TYPEID_DYNAMICOBJECT) + { + if(Unit *caster = ((DynamicObject*)obj)->GetCaster()) + if(caster->GetTypeId() == TYPEID_PLAYER && caster->GetUInt64Value(PLAYER_FARSIGHT) == obj->GetGUID()) + { + Trinity::PlayerVisibilityNotifier notifier(*((Player*)caster)); + VisitAll(obj->GetPositionX(), obj->GetPositionY(), World::GetMaxVisibleDistance(), notifier); + notifier.Notify(); + } + } + CellPair standing_cell(Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY())); // Check for correctness of standing_cell, it also avoids problems with update_cell @@ -728,28 +755,6 @@ void Map::Update(const uint32 &t_diff) } } } - - // Update bindsight players - if(obj->isType(TYPEMASK_UNIT)) - { - if(!((Unit*)obj)->GetSharedVisionList().empty()) - for(SharedVisionList::const_iterator itr = ((Unit*)obj)->GetSharedVisionList().begin(); itr != ((Unit*)obj)->GetSharedVisionList().end(); ++itr) - { - Trinity::PlayerVisibilityNotifier notifier(**itr); - VisitAll(obj->GetPositionX(), obj->GetPositionY(), World::GetMaxVisibleDistance(), notifier); - notifier.Notify(); - } - } - else if(obj->GetTypeId() == TYPEID_DYNAMICOBJECT) - { - if(Unit *caster = ((DynamicObject*)obj)->GetCaster()) - if(caster->GetTypeId() == TYPEID_PLAYER && caster->GetUInt64Value(PLAYER_FARSIGHT) == obj->GetGUID()) - { - Trinity::PlayerVisibilityNotifier notifier(*((Player*)caster)); - VisitAll(obj->GetPositionX(), obj->GetPositionY(), World::GetMaxVisibleDistance(), notifier); - notifier.Notify(); - } - } } } diff --git a/src/game/NullCreatureAI.cpp b/src/game/NullCreatureAI.cpp index 33218251718..2745dd3ea8d 100644 --- a/src/game/NullCreatureAI.cpp +++ b/src/game/NullCreatureAI.cpp @@ -27,6 +27,30 @@ void PassiveAI::UpdateAI(const uint32) EnterEvadeMode(); } +void PossessedAI::UpdateAI(const uint32 diff) +{ + if(me->getVictim()) + { + if(!me->canAttack(me->getVictim())) + me->AttackStop(); + else + DoMeleeAttackIfReady(); + } +} + +void PossessedAI::JustDied(Unit *u) +{ + // We died while possessed, disable our loot + me->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); +} + +void PossessedAI::KilledUnit(Unit* victim) +{ + // We killed a creature, disable victim's loot + if (victim->GetTypeId() == TYPEID_UNIT) + victim->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); +} + void CritterAI::DamageTaken(Unit *done_by, uint32 &) { if(!me->hasUnitState(UNIT_STAT_FLEEING)) @@ -39,4 +63,3 @@ void CritterAI::EnterEvadeMode() me->SetControlled(false, UNIT_STAT_FLEEING); CreatureAI::EnterEvadeMode(); } - diff --git a/src/game/NullCreatureAI.h b/src/game/NullCreatureAI.h index 671e9ea63ab..f628a7e8ac9 100644 --- a/src/game/NullCreatureAI.h +++ b/src/game/NullCreatureAI.h @@ -36,6 +36,18 @@ class TRINITY_DLL_DECL PassiveAI : public CreatureAI static int Permissible(const Creature *) { return PERMIT_BASE_IDLE; } }; +class TRINITY_DLL_DECL PossessedAI : public PassiveAI +{ + public: + PossessedAI(Creature *c) : PassiveAI(c) {} + + void UpdateAI(const uint32); + void EnterEvadeMode() {} + + void JustDied(Unit*); + void KilledUnit(Unit* victim); +}; + class TRINITY_DLL_DECL NullCreatureAI : public PassiveAI { public: diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp index 6f43d511dd0..068548ac8d7 100644 --- a/src/game/PetAI.cpp +++ b/src/game/PetAI.cpp @@ -44,44 +44,6 @@ PetAI::PetAI(Creature *c) : CreatureAI(c), i_pet(*c), i_tracker(TIME_INTERVAL_LO UpdateAllies(); } -void PetAI::MoveInLineOfSight(Unit *u) -{ - if( !i_pet.getVictim() && i_pet.GetCharmInfo() && - i_pet.IsHostileTo( u ) && i_pet.canAttack(u) && - u->isInAccessiblePlaceFor(&i_pet)) - { - float attackRadius = i_pet.GetAttackDistance(u); - if(i_pet.IsWithinDistInMap(u, attackRadius) && i_pet.GetDistanceZ(u) <= CREATURE_Z_ATTACK_RANGE) - { - if(i_pet.IsWithinLOSInMap(u)) - { - AttackStart(u); - //u->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); - } - } - } -} - -void PetAI::AttackStart(Unit *u) -{ - if( !u || (i_pet.isPet() && ((Pet&)i_pet).getPetType() == MINI_PET) ) - return; - - if (inCombat && i_pet.getVictim() && u != i_pet.getVictim()) - i_pet.AttackStop(); - - if(i_pet.Attack(u,true)) - { - i_pet.clearUnitState(UNIT_STAT_FOLLOW); - // TMGs call CreatureRelocation which via MoveInLineOfSight can call this function - // thus with the following clear the original TMG gets invalidated and crash, doh - // hope it doesn't start to leak memory without this :-/ - //i_pet->Clear(); - i_pet.GetMotionMaster()->MoveChase(u); - inCombat = true; - } -} - void PetAI::EnterEvadeMode() { } @@ -138,9 +100,6 @@ void PetAI::UpdateAI(const uint32 diff) else m_updateAlliesTimer -= diff; - if (inCombat && !i_pet.getVictim()) - _stopAttack(); - // i_pet.getVictim() can't be used for check in case stop fighting, i_pet.getVictim() clear at Unit death etc. if( i_pet.getVictim() ) { @@ -150,50 +109,23 @@ void PetAI::UpdateAI(const uint32 diff) _stopAttack(); return; } - else if( i_pet.IsStopped() || i_pet.IsWithinMeleeRange(i_pet.getVictim())) - { - // required to be stopped cases - if ( i_pet.IsStopped() && i_pet.IsNonMeleeSpellCasted(false) ) - { - if( i_pet.hasUnitState(UNIT_STAT_FOLLOW) ) - i_pet.InterruptNonMeleeSpells(false); - else - return; - } - // not required to be stopped case - else if( i_pet.isAttackReady() && i_pet.IsWithinMeleeRange(i_pet.getVictim()) ) - { - i_pet.AttackerStateUpdate(i_pet.getVictim()); - i_pet.resetAttackTimer(); - - if ( !i_pet.getVictim() ) - return; - - //if pet misses its target, it will also be the first in threat list - i_pet.getVictim()->AddThreat(&i_pet,0.0f); - - if( _needToStop() ) - _stopAttack(); - } - } + DoMeleeAttackIfReady(); } - else if(owner && i_pet.GetCharmInfo()) + else { - if(owner->isInCombat() && !(i_pet.HasReactState(REACT_PASSIVE) || i_pet.GetCharmInfo()->HasCommandState(COMMAND_STAY))) + if(me->isInCombat()) + _stopAttack(); + else if(owner && i_pet.GetCharmInfo()) //no victim { - AttackStart(owner->getAttackerForHelper()); - } - else if(i_pet.GetCharmInfo()->HasCommandState(COMMAND_FOLLOW)) - { - if (!i_pet.hasUnitState(UNIT_STAT_FOLLOW) ) - { + if(owner->isInCombat() && !(i_pet.HasReactState(REACT_PASSIVE) || i_pet.GetCharmInfo()->HasCommandState(COMMAND_STAY))) + AttackStart(owner->getAttackerForHelper()); + else if(i_pet.GetCharmInfo()->HasCommandState(COMMAND_FOLLOW) && !i_pet.hasUnitState(UNIT_STAT_FOLLOW)) i_pet.GetMotionMaster()->MoveFollow(owner,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); - } } } - if (i_pet.GetGlobalCooldown() == 0 && !i_pet.IsNonMeleeSpellCasted(false)) + if (i_pet.GetGlobalCooldown() == 0 && !i_pet.hasUnitState(UNIT_STAT_CASTING)) { //Autocast for (uint8 i = 0; i < i_pet.GetPetAutoSpellSize(); i++) @@ -323,12 +255,3 @@ void PetAI::UpdateAllies() else //remove group m_AllySet.insert(owner->GetGUID()); } - -/*void PetAI::AttackedBy(Unit *attacker) -{ - //when attacked, fight back in case 1)no victim already AND 2)not set to passive AND 3)not set to stay, unless can it can reach attacker with melee attack anyway - if(!i_pet.getVictim() && i_pet.GetCharmInfo() && !i_pet.GetCharmInfo()->HasReactState(REACT_PASSIVE) && - (!i_pet.GetCharmInfo()->HasCommandState(COMMAND_STAY) || i_pet.IsWithinMeleeRange(attacker))) - AttackStart(attacker); -}*/ - diff --git a/src/game/PetAI.h b/src/game/PetAI.h index 82f143e725e..056a9efa205 100644 --- a/src/game/PetAI.h +++ b/src/game/PetAI.h @@ -33,8 +33,6 @@ class TRINITY_DLL_DECL PetAI : public CreatureAI PetAI(Creature *c); - void MoveInLineOfSight(Unit *); - void AttackStart(Unit *); void EnterEvadeMode(); void JustDied(Unit* who) { _stopAttack(); } diff --git a/src/game/PetHandler.cpp b/src/game/PetHandler.cpp index 2cc049ebd84..f158f3a8fcc 100644 --- a/src/game/PetHandler.cpp +++ b/src/game/PetHandler.cpp @@ -82,13 +82,15 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data ) switch(spellid) { case COMMAND_STAY: //flat=1792 //STAY + pet->AttackStop(); + pet->InterruptNonMeleeSpells(false); pet->StopMoving(); - pet->GetMotionMaster()->Clear(); pet->GetMotionMaster()->MoveIdle(); charmInfo->SetCommandState( COMMAND_STAY ); break; case COMMAND_FOLLOW: //spellid=1792 //FOLLOW pet->AttackStop(); + pet->InterruptNonMeleeSpells(false); pet->GetMotionMaster()->MoveFollow(_player,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); charmInfo->SetCommandState( COMMAND_FOLLOW ); break; diff --git a/src/game/PossessedAI.cpp b/src/game/PossessedAI.cpp index e8d499bf576..8fd2e5ca014 100644 --- a/src/game/PossessedAI.cpp +++ b/src/game/PossessedAI.cpp @@ -18,105 +18,3 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "PossessedAI.h" -#include "Creature.h" -#include "World.h" - -void PossessedAI::AttackStart(Unit *u) -{ - if( !u || i_pet.GetCharmer()->HasAuraType(SPELL_AURA_MOD_PACIFY)) - return; - - if (i_pet.getVictim() && u != i_pet.getVictim()) - i_pet.AttackStop(); - - if(i_pet.Attack(u, true)) - i_victimGuid = u->GetGUID(); - - // Do not autochase our target, and also make sure our current movement generator - // is removed since the motion master is reset before this function is called - i_pet.GetMotionMaster()->Clear(false); - i_pet.GetMotionMaster()->MoveIdle(); -} - -bool PossessedAI::_needToStop() const -{ - if(!i_pet.getVictim() || !i_pet.isAlive()) - return true; - - // This is needed for charmed creatures, as once their target was reset other effects can trigger threat - if(i_pet.getVictim() == i_pet.GetCharmer()) - return true; - - return !i_pet.canAttack(i_pet.getVictim()); -} - -void PossessedAI::_stopAttack() -{ - if( !i_victimGuid ) - return; - - Unit* victim = Unit::GetUnit(i_pet, i_victimGuid ); - - if ( !victim ) - return; - - assert(!i_pet.getVictim() || i_pet.getVictim() == victim); - - if( !i_pet.isAlive() ) - { - i_pet.StopMoving(); - i_pet.GetMotionMaster()->Clear(false); - i_pet.GetMotionMaster()->MoveIdle(); - i_victimGuid = 0; - i_pet.CombatStop(); - i_pet.getHostilRefManager().deleteReferences(); - - return; - } - - i_pet.GetMotionMaster()->Clear(false); - i_pet.GetMotionMaster()->MoveIdle(); - i_victimGuid = 0; - i_pet.AttackStop(); -} - -void PossessedAI::UpdateAI(const uint32 diff) -{ - // update i_victimGuid if i_pet.getVictim() !=0 and changed - if(i_pet.getVictim()) - i_victimGuid = i_pet.getVictim()->GetGUID(); - - // i_pet.getVictim() can't be used for check in case stop fighting, i_pet.getVictim() clear at Unit death etc. - if( i_victimGuid ) - { - if( _needToStop() ) - { - _stopAttack(); // i_victimGuid == 0 && i_pet.getVictim() == NULL now - return; - } - else if(i_pet.IsWithinMeleeRange(i_pet.getVictim()) && i_pet.isAttackReady() && !i_pet.GetCharmer()->HasAuraType(SPELL_AURA_MOD_PACIFY)) - { - i_pet.AttackerStateUpdate(i_pet.getVictim()); - - i_pet.resetAttackTimer(); - - if( _needToStop() ) - _stopAttack(); - } - } -} - -void PossessedAI::JustDied(Unit *u) -{ - // We died while possessed, disable our loot - i_pet.RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); -} - -void PossessedAI::KilledUnit(Unit* victim) -{ - // We killed a creature, disable victim's loot - if (victim->GetTypeId() == TYPEID_UNIT) - victim->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); -} - diff --git a/src/game/PossessedAI.h b/src/game/PossessedAI.h index fd90c5429b0..bef7853246e 100644 --- a/src/game/PossessedAI.h +++ b/src/game/PossessedAI.h @@ -21,33 +21,5 @@ #ifndef MANGOS_POSSESSEDAI_H #define MANGOS_POSSESSEDAI_H -#include "CreatureAI.h" -class Creature; - -class TRINITY_DLL_DECL PossessedAI : public CreatureAI -{ - public: - PossessedAI(Creature *c) : CreatureAI(c), i_pet(*c), i_victimGuid(0) {} - - // Possessed creatures shouldn't aggro by themselves - void MoveInLineOfSight(Unit *) {} - void AttackStart(Unit *); - void EnterEvadeMode() {} - void JustDied(Unit*); - void KilledUnit(Unit* victim); - - void UpdateAI(const uint32); - // Never permit this to be used, it must always be initialized with Creature::InitPossessedAI() - static int Permissible(const Creature *) { return PERMIT_BASE_NO; } - - private: - bool _isVisible(Unit *) const; - bool _needToStop(void) const; - void _stopAttack(void); - - Creature &i_pet; - uint64 i_victimGuid; -}; #endif - diff --git a/src/game/SharedDefines.h b/src/game/SharedDefines.h index 3d76e2aec79..1411e78cb14 100644 --- a/src/game/SharedDefines.h +++ b/src/game/SharedDefines.h @@ -893,7 +893,7 @@ enum Targets TARGET_UNIT_CLASS_TARGET = 61, TARGET_TEST = 62, // for a test spell TARGET_DUELVSPLAYER_COORDINATES = 63, - TARGET_DEST_TARGET_FRIEND = 63, + TARGET_DEST_TARGET_ANY = 63, TARGET_DEST_TARGET_FRONT = 64, TARGET_DEST_TARGET_BACK = 65, // uses in teleport behind spells TARGET_DEST_TARGET_RIGHT = 66, diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 7067a55dc01..34f52daa974 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -1892,16 +1892,11 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,std::list<Unit*> &TagUnitMap) break; } - if(cur == TARGET_DEST_TARGET_ENEMY) + if(cur == TARGET_DEST_TARGET_ENEMY || cur == TARGET_DEST_TARGET_ANY) { m_targets.setDestination(target, true); break; } - else if(cur == TARGET_DEST_TARGET_FRIEND) // no ground? - { - m_targets.setDestination(target, false); - break; - } float x, y, z, angle, dist; diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index ef206ae4660..b9eb8af9e02 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -2818,9 +2818,10 @@ void Spell::EffectPersistentAA(uint32 i) if(Player* modOwner = m_originalCaster->GetSpellModOwner()) modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RADIUS, radius); + Unit *caster = m_caster->GetEntry() == WORLD_TRIGGER ? m_originalCaster : m_caster; int32 duration = GetSpellDuration(m_spellInfo); DynamicObject* dynObj = new DynamicObject; - if(!dynObj->Create(objmgr.GenerateLowGuid(HIGHGUID_DYNAMICOBJECT), m_originalCaster, m_spellInfo->Id, i, m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, duration, radius)) + if(!dynObj->Create(objmgr.GenerateLowGuid(HIGHGUID_DYNAMICOBJECT), caster, m_spellInfo->Id, i, m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, duration, radius)) { delete dynObj; return; @@ -2828,8 +2829,8 @@ void Spell::EffectPersistentAA(uint32 i) dynObj->SetUInt32Value(OBJECT_FIELD_TYPE, 65); dynObj->SetUInt32Value(GAMEOBJECT_DISPLAYID, 368003); dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x01eeeeee); - m_originalCaster->AddDynObject(dynObj); - MapManager::Instance().GetMap(dynObj->GetMapId(), dynObj)->Add(dynObj); + caster->AddDynObject(dynObj); + dynObj->GetMap()->Add(dynObj); } void Spell::EffectEnergize(uint32 i) diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp index ccc6cc85f5a..57efba7560a 100644 --- a/src/game/SpellMgr.cpp +++ b/src/game/SpellMgr.cpp @@ -129,7 +129,7 @@ SpellMgr::SpellMgr() SpellTargetType[i] = TARGET_TYPE_AREA_DEST; break; case TARGET_DEST_TARGET_ENEMY: - case TARGET_DEST_TARGET_FRIEND: + case TARGET_DEST_TARGET_ANY: case TARGET_DEST_TARGET_FRONT: case TARGET_DEST_TARGET_BACK: case TARGET_DEST_TARGET_RIGHT: diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 85661e97dbf..a77155ab87a 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -47,6 +47,8 @@ #include "CellImpl.h" #include "Path.h" #include "CreatureGroups.h" +#include "PetAI.h" +#include "NullCreatureAI.h" #include "Traveller.h" #include <math.h> @@ -76,6 +78,7 @@ static bool procPrepared = InitTriggerAuraData(); Unit::Unit() : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this) , m_IsInNotifyList(false), m_Notified(false), IsAIEnabled(false) +, i_AI(NULL), i_disabledAI(NULL) { m_objectType |= TYPEMASK_UNIT; m_objectTypeId = TYPEID_UNIT; @@ -11284,10 +11287,38 @@ void Unit::CleanupsBeforeDelete() RemoveFromWorld(); } +void Unit::UpdateCharmAI() +{ + if(GetTypeId() == TYPEID_PLAYER) + return; + + if(i_disabledAI) // disabled AI must be primary AI + { + if(!isCharmed()) + { + if(i_AI) delete i_AI; + i_AI = i_disabledAI; + i_disabledAI = NULL; + } + } + else + { + if(isCharmed()) + { + i_disabledAI = i_AI; + if(isPossessed()) + i_AI = new PossessedAI((Creature*)this); + else + i_AI = new PetAI((Creature*)this); + } + } +} + CharmInfo* Unit::InitCharmInfo() { if(!m_charmInfo) m_charmInfo = new CharmInfo(this); + return m_charmInfo; } diff --git a/src/game/Unit.h b/src/game/Unit.h index 1f40b748fb6..cae075b07dc 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1214,6 +1214,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject CharmInfo* GetCharmInfo() { return m_charmInfo; } CharmInfo* InitCharmInfo(); void DeleteCharmInfo(); + void UpdateCharmAI(); SharedVisionList const& GetSharedVisionList() { return m_sharedVision; } void AddPlayerToVision(Player* plr); void RemovePlayerFromVision(Player* plr); @@ -1549,6 +1550,8 @@ class TRINITY_DLL_SPEC Unit : public WorldObject protected: explicit Unit (); + UnitAI *i_AI, *i_disabledAI; + void _UpdateSpells(uint32 time); void _UpdateAutoRepeatSpell(); |