All pastes #947955 Raw Edit

Anonym

public text v1 · immutable
·published 2008-03-18 20:35 UTC
rendered paste body
Index: src/game/CreatureAISelector.cpp
===================================================================
--- src/game/CreatureAISelector.cpp	(revision 5442)
+++ src/game/CreatureAISelector.cpp	(working copy)
@@ -17,6 +17,7 @@
  */
 
 #include "Creature.h"
+#include "Pet.h"
 #include "CreatureAIImpl.h"
 #include "CreatureAISelector.h"
 #include "NullCreatureAI.h"
@@ -38,7 +39,7 @@
         //the commented condition is too db dependant to get into the core, but is an example to create the possibilty to have scripts for untamed pets and scripts for their tamed/owned equivalents
         //e.g. if there are scripts for warlock pets but not for hunter's the activation of the check will allow warlock pets to be scripted while hunter pets would retain standart pet AI
         CreatureAI* scriptedAI = Script->GetAI(creature);
-        if(scriptedAI && !((creature->isPet() || creature->isCharmed())/* && creature->GetCreatureInfo()->ScriptName == "generic_creature"*/))
+        if(scriptedAI && !((creature->isPet() && ((Pet*)creature)->getPetType() != GUARDIAN_PET || creature->isCharmed())/* && creature->GetCreatureInfo()->ScriptName == "generic_creature"*/))
             return scriptedAI;
 
         CreatureAIRegistry &ai_registry(CreatureAIRepository::Instance());
Index: src/game/Pet.cpp
===================================================================
--- src/game/Pet.cpp	(revision 5442)
+++ src/game/Pet.cpp	(working copy)
@@ -1604,13 +1604,9 @@
     SetSpeed(MOVE_SWIM,     cinfo->speed);
     SetSpeed(MOVE_SWIMBACK, cinfo->speed);
 
-    if(cinfo->MovementType < MAX_DB_MOTION_TYPE)
-        m_defaultMovementType = MovementGeneratorType(cinfo->MovementType);
-    else
-    {
-        m_defaultMovementType = IDLE_MOTION_TYPE;
-        sLog.outErrorDb("Creature template %u have wrong movement generator type value %u, ignore and set to IDLE.",Entry,cinfo->MovementType);
-    }
+	// use always idle generator for pets as default   
+	m_defaultMovementType = IDLE_MOTION_TYPE;
+    
 
     return true;
 }
@@ -1619,3 +1615,12 @@
 {
     return (m_spells.find(spell) != m_spells.end());
 }
+void Pet::SetCurrentDestiantionAsHome()
+{
+	if (!IsPositionValid()) return;
+
+	// use the respawn coords for COMMAND_STAY (->HomeMovementGenerator)
+	respawn_cord[0] = GetPositionX();
+    respawn_cord[1] = GetPositionY();
+    respawn_cord[2] = GetPositionZ();
+}
\ No newline at end of file
Index: src/game/Pet.h
===================================================================
--- src/game/Pet.h	(revision 5442)
+++ src/game/Pet.h	(working copy)
@@ -153,7 +153,9 @@
         bool HaveInDiet(ItemPrototype const* item) const;
         uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel);
         void SetDuration(int32 dur) { m_duration = dur; }
+		void SetCurrentDestiantionAsHome();
 
+
         int32 GetBonusDamage() { return m_bonusdamage; }
         void SetBonusDamage(int32 damage) { m_bonusdamage = damage; }
 
Index: src/game/PetAI.cpp
===================================================================
--- src/game/PetAI.cpp	(revision 5442)
+++ src/game/PetAI.cpp	(working copy)
@@ -71,6 +71,8 @@
         // hope it doesn't start to leak memory without this :-/
         //i_pet->Clear();
         i_victimGuid = u->GetGUID();
+		//but then we have to clear the FOLLOW stat manually
+		i_pet.clearUnitState(UNIT_STAT_FOLLOW); 
         i_pet.GetMotionMaster()->Mutate(new TargetedMovementGenerator<Creature>(*u));
     }
 }
@@ -145,19 +147,26 @@
 
     if(owner && i_pet.GetCharmInfo() && i_pet.GetCharmInfo()->HasCommandState(COMMAND_FOLLOW))
     {
-        i_pet.addUnitState(UNIT_STAT_FOLLOW);
         i_pet.GetMotionMaster()->Clear();
         i_pet.GetMotionMaster()->Mutate(new TargetedMovementGenerator<Creature>(*owner,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE));
     }
-    else
-    {
-        i_pet.clearUnitState(UNIT_STAT_FOLLOW);
-        i_pet.addUnitState(UNIT_STAT_STOPPED);
+    else if (i_pet.GetCharmInfo()->HasCommandState(COMMAND_STAY))
+	{	
         i_pet.GetMotionMaster()->Clear();
         i_pet.GetMotionMaster()->Idle();
+		i_pet.GetMotionMaster()->TargetedHome();
     }
-    i_victimGuid = 0;
+	else //should not happen
+	{
+		i_pet.addUnitState(UNIT_STAT_STOPPED);
+        i_pet.GetMotionMaster()->Clear();
+        i_pet.GetMotionMaster()->Idle();
+    }
+    
+	i_victimGuid = 0;
     i_pet.AttackStop();
+	i_pet.InterruptNonMeleeSpells(false);
+
 }
 
 void PetAI::UpdateAI(const uint32 diff)
@@ -213,7 +222,7 @@
     }
     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.GetCharmInfo()->HasReactState(REACT_PASSIVE) )
         {
             AttackStart(owner->getAttackerForHelper());
         }
@@ -221,7 +230,6 @@
         {
             if (!i_pet.hasUnitState(UNIT_STAT_FOLLOW) )
             {
-                i_pet.addUnitState(UNIT_STAT_FOLLOW);
                 i_pet.GetMotionMaster()->Clear();
                 i_pet.GetMotionMaster()->Mutate(new TargetedMovementGenerator<Creature>(*owner,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE));
             }
@@ -245,7 +253,7 @@
 
         Spell *spell = new Spell(&i_pet, spellInfo, false, 0);
 
-        if(!IsPositiveSpell(spellInfo->Id) && i_pet.getVictim() && !_needToStop() && !i_pet.hasUnitState(UNIT_STAT_FOLLOW) && spell->CanAutoCast(i_pet.getVictim()))
+        if(!IsPositiveSpell(spellInfo->Id) && i_pet.getVictim() && !_needToStop() && i_pet.hasUnitState(UNIT_STAT_CHASE) && spell->CanAutoCast(i_pet.getVictim()))
             targetMap[spellID] = i_pet.getVictim();
         else
         {
Index: src/game/PetHandler.cpp
===================================================================
--- src/game/PetHandler.cpp	(revision 5442)
+++ src/game/PetHandler.cpp	(working copy)
@@ -79,14 +79,13 @@
             switch(spellid)
             {
                 case COMMAND_STAY:                          //flat=1792  //STAY
-                    pet->StopMoving();
+                    ((Pet*)pet)->SetCurrentDestiantionAsHome();
                     pet->GetMotionMaster()->Clear();
                     pet->GetMotionMaster()->Idle();
                     charmInfo->SetCommandState( COMMAND_STAY );
                     break;
                 case COMMAND_FOLLOW:                        //spellid=1792  //FOLLOW
                     pet->AttackStop();
-                    pet->addUnitState(UNIT_STAT_FOLLOW);
                     pet->GetMotionMaster()->Clear();
                     pet->GetMotionMaster()->Mutate(new TargetedMovementGenerator<Creature>(*_player,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE));
                     charmInfo->SetCommandState( COMMAND_FOLLOW );
@@ -94,7 +93,6 @@
                 case COMMAND_ATTACK:                        //spellid=1792  //ATTACK
                 {
                     // only place where pet can be player
-                    pet->clearUnitState(UNIT_STAT_FOLLOW);
                     uint64 selguid = _player->GetSelection();
                     Unit *TargetUnit = ObjectAccessor::GetUnit(*_player, selguid);
                     if(TargetUnit == NULL) return;
@@ -183,10 +181,8 @@
             if(!pet->HasSpell(spellid) || IsPassiveSpell(spellid))
                 return;
 
-            pet->clearUnitState(UNIT_STAT_FOLLOW);
+           Spell *spell = new Spell(pet, spellInfo, false);
 
-            Spell *spell = new Spell(pet, spellInfo, false);
-
             int16 result = spell->PetCanCast(unit_target);
 
                                                             //auto turn to target unless possessed
@@ -219,7 +215,6 @@
 
                 if( unit_target && !GetPlayer()->IsFriendlyTo(unit_target) && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS))
                 {
-                    pet->clearUnitState(UNIT_STAT_FOLLOW);
                     if(pet->getVictim())
                         pet->AttackStop();
                     pet->GetMotionMaster()->Clear();
Index: src/game/TargetedMovementGenerator.cpp
===================================================================
--- src/game/TargetedMovementGenerator.cpp	(revision 5442)
+++ src/game/TargetedMovementGenerator.cpp	(working copy)
@@ -65,13 +65,9 @@
         i_target->GetClosePoint(x,y,z,owner.GetObjectSize() + i_offset,i_angle);
     }
 
-    //We don't update Mob Movement, if the difference between New destination and last destination is < BothObjectSize
-    float  bothObjectSize = i_target->GetObjectSize() + owner.GetObjectSize() + CONTACT_DISTANCE;
-    if( i_destinationHolder.HasDestination() && i_destinationHolder.GetDestinationDiff(x,y,z) < bothObjectSize )
-        return;
     Traveller<T> traveller(owner);
     i_destinationHolder.SetDestination(traveller, x, y, z);
-    owner.addUnitState(UNIT_STAT_CHASE);
+	owner.addUnitState(i_offset ? UNIT_STAT_FOLLOW : UNIT_STAT_CHASE);
 }
 
 template<class T>
@@ -88,7 +84,7 @@
 void
 TargetedMovementGenerator<T>::Finalize(T &owner)
 {
-    owner.clearUnitState(UNIT_STAT_CHASE);
+    owner.clearUnitState(i_offset ? UNIT_STAT_FOLLOW : UNIT_STAT_CHASE);
 }
 
 template<class T>
@@ -133,7 +129,7 @@
         _setTargetLocation(owner);
     if( owner.IsStopped() && !i_destinationHolder.HasArrived() )
     {
-        owner.addUnitState(UNIT_STAT_CHASE);
+        owner.addUnitState(i_offset ? UNIT_STAT_FOLLOW : UNIT_STAT_CHASE);
         i_destinationHolder.StartTravel(traveller);
         return true;
     }
@@ -144,10 +140,12 @@
         if (owner.GetObjectSize())
             i_destinationHolder.ResetUpdate(50);
 
-        float dist = i_target->GetObjectSize() + owner.GetObjectSize() + CONTACT_DISTANCE;
-
-        // try to counter precision differences
-        if( i_destinationHolder.GetDistanceFromDestSq(*i_target.getTarget()) > dist * dist + 0.8)
+        float deltamax = owner.GetFloatValue(UNIT_FIELD_COMBATREACH)* 0.9 > CONTACT_DISTANCE ?
+							owner.GetFloatValue(UNIT_FIELD_COMBATREACH)* 0.9 : CONTACT_DISTANCE;
+		float dist = i_target->GetObjectSize() + owner.GetObjectSize() + deltamax;
+		
+		// don't update when target is in combatrange
+        if( i_destinationHolder.GetDistanceFromDestSq(*i_target.getTarget()) > dist * dist)
         {
             owner.SetInFront(i_target.getTarget());         // Set new Angle For Map::
             _setTargetLocation(owner);                      //Calculate New Dest and Send data To Player
@@ -159,10 +157,9 @@
         if(( owner.IsStopped() && !i_destinationHolder.HasArrived() ) || i_recalculateTravel )
         {
             i_recalculateTravel = false;
-            //Angle update will take place into owner.StopMoving()
+           
             owner.SetInFront(i_target.getTarget());
 
-            owner.StopMoving();
             if(owner.canReachWithAttack(i_target.getTarget()) && !owner.hasUnitState(UNIT_STAT_FOLLOW))
                 owner.Attack(i_target.getTarget());
         }
Index: src/game/Unit.cpp
===================================================================
--- src/game/Unit.cpp	(revision 5442)
+++ src/game/Unit.cpp	(working copy)
@@ -270,7 +270,7 @@
                                                             //update combat timer only for players and pets
     if (isInCombat() && (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->isPet() || ((Creature*)this)->isCharmed()))
     {
-        if(m_HostilRefManager.isEmpty())
+        if(m_HostilRefManager.isEmpty() && !getVictim())
         {
             // m_CombatTimer set at aura start and it will be freeze until aura removing
             if ( m_CombatTimer <= p_time )
Index: src/game/Unit.h
===================================================================
--- src/game/Unit.h	(revision 5442)
+++ src/game/Unit.h	(working copy)
@@ -302,9 +302,9 @@
     UNIT_STAT_CHASE         = 32,
     UNIT_STAT_SEARCHING     = 64,
     UNIT_STAT_FLEEING       = 128,
-    UNIT_STAT_MOVING        = (UNIT_STAT_ROAMING | UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING),
     UNIT_STAT_IN_FLIGHT     = 256,                          // player is in flight mode
     UNIT_STAT_FOLLOW        = 512,
+	UNIT_STAT_MOVING        = (UNIT_STAT_ROAMING | UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING | UNIT_STAT_FOLLOW),
     UNIT_STAT_ROOT          = 1024,
     UNIT_STAT_CONFUSED      = 2048,
     UNIT_STAT_ALL_STATE     = 0xffff                        //(UNIT_STAT_STOPPED | UNIT_STAT_MOVING | UNIT_STAT_IN_COMBAT | UNIT_STAT_IN_FLIGHT)