Skip to content

Commit

Permalink
Core/Movement: flee at 66% speed (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongdove authored Oct 22, 2024
1 parent 8ed42de commit bbe1a31
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 51 deletions.
7 changes: 1 addition & 6 deletions src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,6 @@ void Creature::DoFleeToGetAssistance()
cell.Visit(p, Trinity::makeGridVisitor(searcher), *GetMap(), *this, radius);

SetNoSearchAssistance(true);
UpdateSpeed(MOVE_RUN, false);

if (!creature)
//SetFeared(true, getVictim()->GetGUID(), 0, sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_FLEE_DELAY));
Expand Down Expand Up @@ -2584,11 +2583,7 @@ void Creature::setDeathState(DeathState s)
if (hasLootRecipient())
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);

if (HasSearchedAssistance())
{
SetNoSearchAssistance(false);
UpdateSpeed(MOVE_RUN, false);
}
SetNoSearchAssistance(false);

//Dismiss group if is leader
if (m_formation && m_formation->getLeader() == this)
Expand Down
73 changes: 40 additions & 33 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11485,16 +11485,8 @@ bool Unit::AttackStop()

// reset only at real combat stop
if (Creature* creature = ToCreature())
{
creature->SetNoCallAssistance(false);

if (creature->HasSearchedAssistance())
{
creature->SetNoSearchAssistance(false);
UpdateSpeed(MOVE_RUN, false);
}
}

SendMeleeAttackStop(victim);

return true;
Expand Down Expand Up @@ -15751,11 +15743,6 @@ void Unit::UpdateSpeed(UnitMoveType mtype, bool forced)
break;
}

// for creature case, we check explicit if mob searched for assistance
if (auto creature = ToCreature())
if (creature->HasSearchedAssistance())
speed *= 0.66f; // best guessed value, so this will be 33% reduction. Based off initial speed, mob can then "run", "walk fast" or "walk".

// Apply strongest slow aura mod to speed
float slow = 0.f;

Expand Down Expand Up @@ -22332,6 +22319,9 @@ void Unit::SetControlled(bool apply, UnitState state)
if (HasUnitState(state))
return;

if (state & UNIT_STATE_CONTROLLED)
CastStop();

AddUnitState(state);

switch (state)
Expand All @@ -22350,7 +22340,6 @@ void Unit::SetControlled(bool apply, UnitState state)
SendMeleeAttackStop();
// SendCancelAutoRepeat ?
SetConfused(true);
CastStop();
}
break;
case UNIT_STATE_FLEEING:
Expand All @@ -22360,7 +22349,6 @@ void Unit::SetControlled(bool apply, UnitState state)
SendMeleeAttackStop();
// SendCancelAutoRepeat ?
SetFeared(true);
CastStop();
}
break;
default:
Expand All @@ -22373,46 +22361,62 @@ void Unit::SetControlled(bool apply, UnitState state)
{
case UNIT_STATE_STUNNED:
{
if (HasAuraType(SPELL_AURA_MOD_STUN)) return;
if (HasAuraType(SPELL_AURA_MOD_STUN))
return;

ClearUnitState(state);
SetStunned(false);
}
break;
case UNIT_STATE_ROOT:
{
if (HasAuraType(SPELL_AURA_MOD_ROOT) || HasAuraType(SPELL_AURA_MOD_ROOTED) || GetVehicle()) return;
if (HasAuraType(SPELL_AURA_MOD_ROOT) || HasAuraType(SPELL_AURA_MOD_ROOTED) || GetVehicle())
return;

ClearUnitState(state);
SetRooted(false);
}
break;
case UNIT_STATE_CONFUSED:
{
if (HasAuraType(SPELL_AURA_MOD_CONFUSE)) return;
if (HasAuraType(SPELL_AURA_MOD_CONFUSE))
return;

ClearUnitState(state);
SetConfused(false);
}
break;
case UNIT_STATE_FLEEING:
{
if (HasAuraType(SPELL_AURA_MOD_FEAR)) return;
if (HasAuraType(SPELL_AURA_MOD_FEAR))
return;

ClearUnitState(state);
SetFeared(false);
}
break;
default: return;
default:
return;
}

ClearUnitState(state);
ApplyControlStatesIfNeeded();
}
}

if (HasUnitState(UNIT_STATE_STUNNED))
SetStunned(true);
else
{
if (HasUnitState(UNIT_STATE_ROOT))
SetRooted(true);
void Unit::ApplyControlStatesIfNeeded()
{
// Unit States might have been already cleared but auras still present. I need to check with HasAuraType
if (HasUnitState(UNIT_STATE_STUNNED) || HasAuraType(SPELL_AURA_MOD_STUN)) // || HasAuraType(SPELL_AURA_MOD_STUN_DISABLE_GRAVITY))
SetStunned(true);

if (HasUnitState(UNIT_STATE_CONFUSED))
SetConfused(true);
else if (HasUnitState(UNIT_STATE_FLEEING))
SetFeared(true);
}
}
if (HasUnitState(UNIT_STATE_ROOT) || HasAuraType(SPELL_AURA_MOD_ROOT)) // || HasAuraType(SPELL_AURA_MOD_ROOT_2) || HasAuraType(SPELL_AURA_MOD_ROOT_DISABLE_GRAVITY))
SetRooted(true);

if (HasUnitState(UNIT_STATE_CONFUSED) || HasAuraType(SPELL_AURA_MOD_CONFUSE))
SetConfused(true);

if (HasUnitState(UNIT_STATE_FLEEING) || HasAuraType(SPELL_AURA_MOD_FEAR))
SetFeared(true);
}

void Unit::SetStunned(bool apply)
Expand Down Expand Up @@ -22837,6 +22841,9 @@ void Unit::RemoveCharmedBy(Unit* charmer)
charmer->ToPlayer()->SendRemoveControlBar();
else if (IsPlayer() || (IsCreature() && !ToCreature()->isGuardian()))
DeleteCharmInfo();

// reset confused movement for example
ApplyControlStatesIfNeeded();
}

void Unit::RestoreFaction()
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@ class Unit : public WorldObject
void SendSetVehicleRecId(uint32 vehicleID);

void SetControlled(bool apply, UnitState state);
void ApplyControlStatesIfNeeded();

///----------Pet responses methods-----------------
void SendPetActionFeedback (uint32 spellID, uint8 msg);
Expand Down
10 changes: 6 additions & 4 deletions src/server/game/Movement/MotionMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,14 @@ void MotionMaster::MoveSeekAssistance(float x, float y, float z)
{
TC_LOG_ERROR("misc", "Player (GUID: %u) attempt to seek assistance", _owner->GetGUIDLow());
}
else
else if (Creature* creature = _owner->ToCreature())
{
TC_LOG_DEBUG("misc", "Creature (Entry: %u GUID: %u) seek assistance (X: %f Y: %f Z: %f)",
_owner->GetEntry(), _owner->GetGUIDLow(), x, y, z);
_owner->AttackStop();
_owner->ToCreature()->SetReactState(REACT_PASSIVE);
creature->GetEntry(), creature->GetGUIDLow(), x, y, z);
creature->AttackStop();
creature->CastStop();
//creature->DoNotReacquireSpellFocusTarget();
creature->SetReactState(REACT_PASSIVE);
Mutate(new AssistanceMovementGenerator(x, y, z), MOTION_SLOT_ACTIVE);
}
}
Expand Down
25 changes: 17 additions & 8 deletions src/server/game/Movement/Spline/MoveSplineInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,34 @@ namespace Movement
move_spline.onTransport = transport;

uint32 moveFlags = unit.m_movementInfo.GetMovementFlags();
if (args.walk)
moveFlags |= MOVEMENTFLAG_WALKING;
else
moveFlags &= ~MOVEMENTFLAG_WALKING;

if (!args.flags.backward)
moveFlags = (moveFlags & ~MOVEMENTFLAG_BACKWARD) | MOVEMENTFLAG_FORWARD;
else
moveFlags = (moveFlags & ~MOVEMENTFLAG_FORWARD) | MOVEMENTFLAG_BACKWARD;

if (moveFlags & MOVEMENTFLAG_ROOT)
moveFlags &= ~MOVEMENTFLAG_MASK_MOVING;

if (!args.HasVelocity)
args.velocity = unit.GetSpeed(UnitMoveType(SelectSpeedType(moveFlags)));
{
// If spline is initialized with SetWalk method it only means we need to select
// walk move speed for it but not add walk flag to unit
uint32 moveFlagsForSpeed = moveFlags;
if (args.walk)
moveFlagsForSpeed |= MOVEMENTFLAG_WALKING;
else
moveFlagsForSpeed &= ~MOVEMENTFLAG_WALKING;

args.velocity = unit.GetSpeed(UnitMoveType(SelectSpeedType(moveFlagsForSpeed)));
if (Creature* creature = unit.ToCreature())
if (creature->HasSearchedAssistance())
args.velocity *= 0.66f;
}

if (!args.Validate())
return 0;

if (moveFlags & MOVEMENTFLAG_ROOT)
moveFlags &= ~MOVEMENTFLAG_MASK_MOVING;

unit.m_movementInfo.SetMovementFlags(moveFlags);
move_spline.Initialize(args);

Expand Down

0 comments on commit bbe1a31

Please sign in to comment.