mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 07:37:01 +00:00
[9435] Avoid useless creature running around at evade
* If creature near respawn point and by defult do random movement then restart from current point * If creature have default waypoints movegen restart from last updated point. Not reload waypoints
This commit is contained in:
parent
f47f5a1deb
commit
d3fc17a81d
7 changed files with 41 additions and 12 deletions
|
|
@ -39,14 +39,14 @@ HomeMovementGenerator<Creature>::Reset(Creature &)
|
|||
void
|
||||
HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner)
|
||||
{
|
||||
if( !&owner )
|
||||
return;
|
||||
|
||||
if( owner.hasUnitState(UNIT_STAT_NOT_MOVE) )
|
||||
if (owner.hasUnitState(UNIT_STAT_NOT_MOVE))
|
||||
return;
|
||||
|
||||
float x, y, z;
|
||||
owner.GetRespawnCoord(x, y, z);
|
||||
|
||||
// at apply we can select more nice return points base at current movegen
|
||||
if (owner.GetMotionMaster()->empty() || !owner.GetMotionMaster()->top()->GetResetPosition(owner,x,y,z))
|
||||
owner.GetRespawnCoord(x, y, z);
|
||||
|
||||
CreatureTraveller traveller(owner);
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ class MANGOS_DLL_SPEC MovementGenerator
|
|||
virtual void UpdateFinalDistance(float /*fDistance*/) { }
|
||||
|
||||
virtual bool GetDestination(float& /*x*/, float& /*y*/, float& /*z*/) const { return false; }
|
||||
|
||||
// used by Evade code for select point to evade with expected restart default movement
|
||||
virtual bool GetResetPosition(Unit &, float& /*x*/, float& /*y*/, float& /*z*/) { return false; }
|
||||
};
|
||||
|
||||
template<class T, class D>
|
||||
|
|
@ -83,6 +86,11 @@ class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator
|
|||
//u->AssertIsType<T>();
|
||||
return (static_cast<D*>(this))->Update(*((T*)&u), time_diff);
|
||||
}
|
||||
bool GetResetPosition(Unit& u, float& x, float& y, float& z)
|
||||
{
|
||||
//u->AssertIsType<T>();
|
||||
return (static_cast<D*>(this))->GetResetPosition(*((T*)&u), x, y, z);
|
||||
}
|
||||
public:
|
||||
// will not link if not overridden in the generators
|
||||
void Initialize(T &u);
|
||||
|
|
@ -90,6 +98,9 @@ class MANGOS_DLL_SPEC MovementGeneratorMedium : public MovementGenerator
|
|||
void Interrupt(T &u);
|
||||
void Reset(T &u);
|
||||
bool Update(T &u, const uint32 &time_diff);
|
||||
|
||||
// not need always overwrites
|
||||
bool GetResetPosition(T& /*u*/, float& /*x*/, float& /*y*/, float& /*z*/) { return false; }
|
||||
};
|
||||
|
||||
struct SelectableMovement : public FactoryHolder<MovementGenerator,MovementGeneratorType>
|
||||
|
|
|
|||
|
|
@ -137,15 +137,13 @@ void RandomMovementGenerator<Creature>::Interrupt(Creature &creature)
|
|||
}
|
||||
|
||||
template<>
|
||||
void
|
||||
RandomMovementGenerator<Creature>::Finalize(Creature &creature)
|
||||
void RandomMovementGenerator<Creature>::Finalize(Creature &creature)
|
||||
{
|
||||
creature.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool
|
||||
RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff)
|
||||
bool RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff)
|
||||
{
|
||||
if (creature.hasUnitState(UNIT_STAT_NOT_MOVE))
|
||||
{
|
||||
|
|
@ -183,3 +181,16 @@ RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32 &diff
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool RandomMovementGenerator<Creature>::GetResetPosition(Creature& c, float& x, float& y, float& z)
|
||||
{
|
||||
float radius;
|
||||
c.GetRespawnCoord(x, y, z, NULL, &radius);
|
||||
|
||||
// use current if in range
|
||||
if (c.IsWithinDist2d(x,y,radius))
|
||||
c.GetPosition(x,y,z);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ class MANGOS_DLL_SPEC RandomMovementGenerator
|
|||
i_destinationHolder.GetLocationNow(mapid, x,y,z);
|
||||
}
|
||||
MovementGeneratorType GetMovementGeneratorType() { return RANDOM_MOTION_TYPE; }
|
||||
|
||||
bool GetResetPosition(T&, float& x, float& y, float& z);
|
||||
private:
|
||||
TimeTrackerSmall i_nextMoveTime;
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@ void WaypointMovementGenerator<Creature>::Interrupt( Creature &u )
|
|||
|
||||
void WaypointMovementGenerator<Creature>::Reset( Creature &u )
|
||||
{
|
||||
ReloadPath(u);
|
||||
b_StoppedByPlayer = false;
|
||||
i_nextMoveTime.Reset(0);
|
||||
u.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class MANGOS_DLL_SPEC PathMovementBase
|
|||
uint32 GetCurrentNode() const { return i_currentNode; }
|
||||
|
||||
bool GetDestination(float& x, float& y, float& z) const { i_destinationHolder.GetDestination(x,y,z); return true; }
|
||||
bool GetPosition(float& x, float& y, float& z) const { i_destinationHolder.GetLocationNowNoMicroMovement(x,y,z); return true; }
|
||||
protected:
|
||||
uint32 i_currentNode;
|
||||
DestinationHolder< Traveller<T> > i_destinationHolder;
|
||||
|
|
@ -97,6 +98,11 @@ public PathMovementBase<Creature, WaypointPath const*>
|
|||
// allow use for overwrite empty implementation
|
||||
bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase<Creature, WaypointPath const*>::GetDestination(x,y,z); }
|
||||
|
||||
bool GetResetPosition(Creature&, float& x, float& y, float& z)
|
||||
{
|
||||
return PathMovementBase<Creature, WaypointPath const*>::GetPosition(x,y,z);
|
||||
}
|
||||
|
||||
private:
|
||||
void ClearWaypoints();
|
||||
|
||||
|
|
@ -135,4 +141,4 @@ public PathMovementBase<Player>
|
|||
// allow use for overwrite empty implementation
|
||||
bool GetDestination(float& x, float& y, float& z) const { return PathMovementBase<Player>::GetDestination(x,y,z); }
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "9434"
|
||||
#define REVISION_NR "9435"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue