*Update flee and confuse movement.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-01-17 00:00:48 -06:00
parent 0a1c601a1c
commit f414ab1686
8 changed files with 39 additions and 54 deletions
+6
View File
@@ -65,6 +65,9 @@ ConfusedMovementGenerator<T>::Initialize(T &unit)
i_waypoints[idx][2] = z; i_waypoints[idx][2] = z;
} }
unit.SetUInt64Value(UNIT_FIELD_TARGET, 0);
unit.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit.CastStop();
unit.StopMoving(); unit.StopMoving();
unit.RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); unit.RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
unit.addUnitState(UNIT_STAT_CONFUSED); unit.addUnitState(UNIT_STAT_CONFUSED);
@@ -144,7 +147,10 @@ template<class T>
void void
ConfusedMovementGenerator<T>::Finalize(T &unit) ConfusedMovementGenerator<T>::Finalize(T &unit)
{ {
unit.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit.clearUnitState(UNIT_STAT_CONFUSED); unit.clearUnitState(UNIT_STAT_CONFUSED);
if(unit.GetTypeId() == TYPEID_UNIT && unit.getVictim())
unit.SetUInt64Value(UNIT_FIELD_TARGET, unit.getVictim()->GetGUID());
} }
template void ConfusedMovementGenerator<Player>::Initialize(Player &player); template void ConfusedMovementGenerator<Player>::Initialize(Player &player);
+2 -10
View File
@@ -1872,18 +1872,10 @@ void Creature::DoFleeToGetAssistance(float radius) // Optional parameter
CellLock<GridReadGuard> cell_lock(cell, p); CellLock<GridReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, grid_creature_searcher, *(GetMap())); cell_lock->Visit(cell_lock, grid_creature_searcher, *(GetMap()));
if(!GetMotionMaster()->empty() && (GetMotionMaster()->GetCurrentMovementGeneratorType() != POINT_MOTION_TYPE)) if(!pCreature)
GetMotionMaster()->Clear(false);
if(pCreature == NULL)
{
GetMotionMaster()->MoveIdle();
GetMotionMaster()->MoveFleeing(getVictim()); GetMotionMaster()->MoveFleeing(getVictim());
}
else else
{
GetMotionMaster()->MoveIdle();
GetMotionMaster()->MovePoint(0,pCreature->GetPositionX(),pCreature->GetPositionY(),pCreature->GetPositionZ()); GetMotionMaster()->MovePoint(0,pCreature->GetPositionX(),pCreature->GetPositionY(),pCreature->GetPositionZ());
}
} }
Unit* Creature::SelectNearestTarget(float dist) const Unit* Creature::SelectNearestTarget(float dist) const
@@ -2143,7 +2135,7 @@ bool Creature::HasSpellCooldown(uint32 spell_id) const
bool Creature::IsInEvadeMode() const bool Creature::IsInEvadeMode() const
{ {
return !i_motionMaster.empty() && i_motionMaster.GetCurrentMovementGeneratorType() == HOME_MOTION_TYPE; return /*!i_motionMaster.empty() &&*/ i_motionMaster.GetCurrentMovementGeneratorType() == HOME_MOTION_TYPE;
} }
bool Creature::HasSpell(uint32 spellID) const bool Creature::HasSpell(uint32 spellID) const
+8 -1
View File
@@ -306,6 +306,10 @@ FleeingMovementGenerator<T>::Initialize(T &owner)
return; return;
_Init(owner); _Init(owner);
owner.CastStop();
owner.addUnitState(UNIT_STAT_FLEEING);
owner.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner.SetUInt64Value(UNIT_FIELD_TARGET, 0);
owner.RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); owner.RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
i_caster_x = fright->GetPositionX(); i_caster_x = fright->GetPositionX();
i_caster_y = fright->GetPositionY(); i_caster_y = fright->GetPositionY();
@@ -323,7 +327,7 @@ FleeingMovementGenerator<Creature>::_Init(Creature &owner)
{ {
if(!&owner) if(!&owner)
return; return;
owner.SetUInt64Value(UNIT_FIELD_TARGET, 0);
is_water_ok = owner.canSwim(); is_water_ok = owner.canSwim();
is_land_ok = owner.canWalk(); is_land_ok = owner.canWalk();
} }
@@ -340,7 +344,10 @@ template<class T>
void void
FleeingMovementGenerator<T>::Finalize(T &owner) FleeingMovementGenerator<T>::Finalize(T &owner)
{ {
owner.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner.clearUnitState(UNIT_STAT_FLEEING); owner.clearUnitState(UNIT_STAT_FLEEING);
if(owner.GetTypeId() == TYPEID_UNIT && owner.getVictim())
owner.SetUInt64Value(UNIT_FIELD_TARGET, owner.getVictim()->GetGUID());
} }
template<class T> template<class T>
+1 -1
View File
@@ -3728,7 +3728,7 @@ bool ChatHandler::HandleNpcUnFollowCommand(const char* /*args*/)
return false; return false;
} }
if (creature->GetMotionMaster()->empty() || if (/*creature->GetMotionMaster()->empty() ||*/
creature->GetMotionMaster()->GetCurrentMovementGeneratorType ()!=TARGETED_MOTION_TYPE) creature->GetMotionMaster()->GetCurrentMovementGeneratorType ()!=TARGETED_MOTION_TYPE)
{ {
PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU); PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU);
+10 -7
View File
@@ -5762,9 +5762,12 @@ bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow()); PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
MotionMaster* mm = unit->GetMotionMaster(); MotionMaster* mm = unit->GetMotionMaster();
for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr) for(int i = 0; i < MAX_MOTION_SLOT; ++i)
{ {
switch((*itr)->GetMovementGeneratorType()) MovementGenerator* mg = mm->GetMotionSlot(i);
if(!mg)
SendSysMessage("Empty");
switch(mg->GetMovementGeneratorType())
{ {
case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break; case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break; case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
@@ -5775,7 +5778,7 @@ bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
{ {
if(unit->GetTypeId()==TYPEID_PLAYER) if(unit->GetTypeId()==TYPEID_PLAYER)
{ {
TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr); TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(mg);
Unit* target = mgen->GetTarget(); Unit* target = mgen->GetTarget();
if(target) if(target)
PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow()); PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
@@ -5784,7 +5787,7 @@ bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
} }
else else
{ {
TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr); TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(mg);
Unit* target = mgen->GetTarget(); Unit* target = mgen->GetTarget();
if(target) if(target)
PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow()); PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
@@ -5797,7 +5800,7 @@ bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
if(unit->GetTypeId()==TYPEID_UNIT) if(unit->GetTypeId()==TYPEID_UNIT)
{ {
float x,y,z; float x,y,z;
(*itr)->GetDestination(x,y,z); mg->GetDestination(x,y,z);
PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z); PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
} }
else else
@@ -5807,14 +5810,14 @@ bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
case POINT_MOTION_TYPE: case POINT_MOTION_TYPE:
{ {
float x,y,z; float x,y,z;
(*itr)->GetDestination(x,y,z); mg->GetDestination(x,y,z);
PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z); PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
break; break;
} }
case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break; case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break; case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
default: default:
PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType()); PSendSysMessage(LANG_MOVEGENS_UNKNOWN,mg->GetMovementGeneratorType());
break; break;
} }
} }
+6 -2
View File
@@ -230,8 +230,6 @@ MotionMaster::MoveChase(Unit* target, float dist, float angle)
void void
MotionMaster::MoveFollow(Unit* target, float dist, float angle) MotionMaster::MoveFollow(Unit* target, float dist, float angle)
{ {
Clear();
// ignore movement request if target not exist // ignore movement request if target not exist
if(!target) if(!target)
return; return;
@@ -276,6 +274,9 @@ MotionMaster::MoveFleeing(Unit* enemy)
if(!enemy) if(!enemy)
return; return;
if(i_owner->HasAuraType(SPELL_AURA_PREVENTS_FLEEING))
return;
if(i_owner->GetTypeId()==TYPEID_PLAYER) if(i_owner->GetTypeId()==TYPEID_PLAYER)
{ {
DEBUG_LOG("Player (GUID: %u) flee from %s (GUID: %u)", i_owner->GetGUIDLow(), DEBUG_LOG("Player (GUID: %u) flee from %s (GUID: %u)", i_owner->GetGUIDLow(),
@@ -312,6 +313,9 @@ MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode)
void void
MotionMaster::MoveDistract(uint32 timer) MotionMaster::MoveDistract(uint32 timer)
{ {
if(Impl[MOTION_SLOT_CONTROLLED])
return;
if(i_owner->GetTypeId()==TYPEID_PLAYER) if(i_owner->GetTypeId()==TYPEID_PLAYER)
{ {
DEBUG_LOG("Player (GUID: %u) distracted (timer: %u)", i_owner->GetGUIDLow(), timer); DEBUG_LOG("Player (GUID: %u) distracted (timer: %u)", i_owner->GetGUIDLow(), timer);
+2 -1
View File
@@ -63,7 +63,6 @@ class TRINITY_DLL_SPEC MotionMaster //: private std::stack<MovementGenerator *>
_Ty Impl[MAX_MOTION_SLOT]; _Ty Impl[MAX_MOTION_SLOT];
int i_top; int i_top;
int size() const { return i_top + 1; }
bool empty() const { return i_top < 0; } bool empty() const { return i_top < 0; }
void pop() { Impl[i_top] = NULL; --i_top; } void pop() { Impl[i_top] = NULL; --i_top; }
void push(_Ty _Val) { ++i_top; Impl[i_top] = _Val; } void push(_Ty _Val) { ++i_top; Impl[i_top] = _Val; }
@@ -76,7 +75,9 @@ class TRINITY_DLL_SPEC MotionMaster //: private std::stack<MovementGenerator *>
//MovementGenerator* operator->(void) { return top(); } //MovementGenerator* operator->(void) { return top(); }
int size() const { return i_top + 1; }
_Ty top() const { return Impl[i_top]; } _Ty top() const { return Impl[i_top]; }
_Ty GetMotionSlot(int slot) { return Impl[slot]; }
/*using Impl::top; /*using Impl::top;
using Impl::empty; using Impl::empty;
+4 -32
View File
@@ -12857,13 +12857,6 @@ void Unit::SetFeared(bool apply)
{ {
if(apply) if(apply)
{ {
if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING))
return;
SetUInt64Value(UNIT_FIELD_TARGET, 0);
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
CastStop();
//GetMotionMaster()->MovementExpired(false);
Unit *caster = NULL; Unit *caster = NULL;
Unit::AuraList const& fearAuras = GetAurasByType(SPELL_AURA_MOD_FEAR); Unit::AuraList const& fearAuras = GetAurasByType(SPELL_AURA_MOD_FEAR);
if(!fearAuras.empty()) if(!fearAuras.empty())
@@ -12872,17 +12865,8 @@ void Unit::SetFeared(bool apply)
} }
else else
{ {
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); if(isAlive() && GetMotionMaster()->GetCurrentMovementGeneratorType() == FLEEING_MOTION_TYPE))
if(isAlive()) GetMotionMaster()->MovementExpired();
{
if( GetTypeId() != TYPEID_PLAYER && getVictim())
{
SetUInt64Value(UNIT_FIELD_TARGET, getVictim()->GetGUID());
GetMotionMaster()->MoveChase(getVictim());
}
else
GetMotionMaster()->Initialize();
}
} }
if (GetTypeId() == TYPEID_PLAYER) if (GetTypeId() == TYPEID_PLAYER)
@@ -12893,24 +12877,12 @@ void Unit::SetConfused(bool apply)
{ {
if(apply) if(apply)
{ {
SetUInt64Value(UNIT_FIELD_TARGET, 0);
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
CastStop();
GetMotionMaster()->MoveConfused(); GetMotionMaster()->MoveConfused();
} }
else else
{ {
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); if(isAlive() && GetMotionMaster()->GetCurrentMovementGeneratorType() == CONFUSED_MOTION_TYPE)
if(isAlive()) GetMotionMaster()->MovementExpired();
{
if( GetTypeId() != TYPEID_PLAYER && getVictim())
{
SetUInt64Value(UNIT_FIELD_TARGET, getVictim()->GetGUID());
GetMotionMaster()->MoveChase(getVictim());
}
else
GetMotionMaster()->Initialize();
}
} }
if(GetTypeId() == TYPEID_PLAYER) if(GetTypeId() == TYPEID_PLAYER)