Skip to content

Commit

Permalink
Core/Movement: Allow setting position or object facing targets for ju…
Browse files Browse the repository at this point in the history
…mp movement
  • Loading branch information
Shauren committed Jun 21, 2024
1 parent 721103c commit ac73edc
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1973,11 +1973,11 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
float gravity = e.action.jump.UseDefaultGravity ? Movement::gravity : e.action.jump.Gravity;
me->GetMotionMaster()->MoveJumpWithGravity(pos, float(e.action.jump.SpeedXY), gravity, e.action.jump.PointId,
false, nullptr, nullptr, std::move(actionResultSetter));
{}, nullptr, nullptr, std::move(actionResultSetter));
}
else
me->GetMotionMaster()->MoveJump(pos, float(e.action.jump.SpeedXY), float(e.action.jump.SpeedZ), e.action.jump.PointId,
false, nullptr, nullptr, std::move(actionResultSetter));
{}, nullptr, nullptr, std::move(actionResultSetter));

mTimedActionWaitEvent = std::move(waitEvent);
break;
Expand Down
8 changes: 0 additions & 8 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12111,14 +12111,6 @@ void Unit::JumpTo(float speedXY, float speedZ, float angle, Optional<Position> d
}
}

void Unit::JumpTo(WorldObject* obj, float speedZ, bool withOrientation)
{
float x, y, z;
obj->GetContactPoint(this, x, y, z);
float speedXY = GetExactDist2d(x, y) * 10.0f / speedZ;
GetMotionMaster()->MoveJump(x, y, z, GetAbsoluteAngle(obj), speedXY, speedZ, EVENT_JUMP, withOrientation);
}

void Unit::HandleSpellClick(Unit* clicker, int8 seatId /*= -1*/)
{
bool spellClickHandled = false;
Expand Down
1 change: 0 additions & 1 deletion src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,6 @@ class TC_GAME_API Unit : public WorldObject
void SendMoveKnockBack(Player* player, float speedXY, float speedZ, float vcos, float vsin);
void KnockbackFrom(Position const& origin, float speedXY, float speedZ, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr);
void JumpTo(float speedXY, float speedZ, float angle, Optional<Position> dest = {});
void JumpTo(WorldObject* obj, float speedZ, bool withOrientation = false);

void MonsterMoveWithSpeed(float x, float y, float z, float speed, bool generatePath = false, bool forceDestination = false);

Expand Down
18 changes: 8 additions & 10 deletions src/server/game/Movement/MotionMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,18 +843,18 @@ void MotionMaster::MoveJumpTo(float angle, float speedXY, float speedZ)
_owner->GetNearPoint2D(nullptr, x, y, dist, _owner->GetOrientation() + angle);
_owner->UpdateAllowedPositionZ(x, y, z);

MoveJump(x, y, z, 0.0f, speedXY, speedZ);
MoveJump(x, y, z, speedXY, speedZ);
}

void MotionMaster::MoveJump(Position const& pos, float speedXY, float speedZ, uint32 id/* = EVENT_JUMP*/, bool hasOrientation/* = false*/,
void MotionMaster::MoveJump(Position const& pos, float speedXY, float speedZ, uint32 id/* = EVENT_JUMP*/, MovementFacingTarget const& facing/* = {}*/,
JumpArrivalCastArgs const* arrivalCast /*= nullptr*/, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/)
{
MoveJump(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), speedXY, speedZ, id, hasOrientation,
arrivalCast, spellEffectExtraData, std::move(scriptResult));
MoveJump(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), speedXY, speedZ, id, facing, arrivalCast,
spellEffectExtraData, std::move(scriptResult));
}

void MotionMaster::MoveJump(float x, float y, float z, float o, float speedXY, float speedZ, uint32 id /*= EVENT_JUMP*/, bool hasOrientation /* = false*/,
void MotionMaster::MoveJump(float x, float y, float z, float speedXY, float speedZ, uint32 id /*= EVENT_JUMP*/, MovementFacingTarget const& facing /* = {}*/,
JumpArrivalCastArgs const* arrivalCast /*= nullptr*/, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/)
{
Expand All @@ -874,8 +874,7 @@ void MotionMaster::MoveJump(float x, float y, float z, float o, float speedXY, f
init.MoveTo(x, y, z, false);
init.SetParabolic(max_height, 0);
init.SetVelocity(speedXY);
if (hasOrientation)
init.SetFacing(o);
std::visit(Movement::MoveSplineInitFacingVisitor(init), facing);
if (effect)
init.SetSpellEffectExtraData(*effect);
};
Expand All @@ -895,7 +894,7 @@ void MotionMaster::MoveJump(float x, float y, float z, float o, float speedXY, f
Add(movement);
}

void MotionMaster::MoveJumpWithGravity(Position const& pos, float speedXY, float gravity, uint32 id/* = EVENT_JUMP*/, bool hasOrientation/* = false*/,
void MotionMaster::MoveJumpWithGravity(Position const& pos, float speedXY, float gravity, uint32 id/* = EVENT_JUMP*/, MovementFacingTarget const& facing/* = {}*/,
JumpArrivalCastArgs const* arrivalCast /*= nullptr*/, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/)
{
Expand All @@ -914,8 +913,7 @@ void MotionMaster::MoveJumpWithGravity(Position const& pos, float speedXY, float
init.SetUncompressed();
init.SetVelocity(speedXY);
init.SetUnlimitedSpeed();
if (hasOrientation)
init.SetFacing(pos.GetOrientation());
std::visit(Movement::MoveSplineInitFacingVisitor(init), facing);
if (effect)
init.SetSpellEffectExtraData(*effect);
};
Expand Down
6 changes: 3 additions & 3 deletions src/server/game/Movement/MotionMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ class TC_GAME_API MotionMaster
void MoveCharge(PathGenerator const& path, float speed = SPEED_CHARGE, Unit const* target = nullptr, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr);
void MoveKnockbackFrom(Position const& origin, float speedXY, float speedZ, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr);
void MoveJumpTo(float angle, float speedXY, float speedZ);
void MoveJump(Position const& pos, float speedXY, float speedZ, uint32 id = EVENT_JUMP, bool hasOrientation = false,
void MoveJump(Position const& pos, float speedXY, float speedZ, uint32 id = EVENT_JUMP, MovementFacingTarget const& facing = {},
JumpArrivalCastArgs const* arrivalCast = nullptr, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {});
void MoveJump(float x, float y, float z, float o, float speedXY, float speedZ, uint32 id = EVENT_JUMP, bool hasOrientation = false,
void MoveJump(float x, float y, float z, float speedXY, float speedZ, uint32 id = EVENT_JUMP, MovementFacingTarget const& facing = {},
JumpArrivalCastArgs const* arrivalCast = nullptr, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {});
void MoveJumpWithGravity(Position const& pos, float speedXY, float gravity, uint32 id = EVENT_JUMP, bool hasOrientation = false,
void MoveJumpWithGravity(Position const& pos, float speedXY, float gravity, uint32 id = EVENT_JUMP, MovementFacingTarget const& facing = {},
JumpArrivalCastArgs const* arrivalCast = nullptr, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {});
void MoveCirclePath(float x, float y, float z, float radius, bool clockwise, uint8 stepCount,
Expand Down
6 changes: 6 additions & 0 deletions src/server/game/Movement/MovementDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "Common.h"
#include "ObjectGuid.h"
#include "Optional.h"
#include "Position.h"
#include <variant>

class Unit;

#define SPEED_CHARGE 42.0f // assume it is 25 yard per 0.6 second

Expand Down Expand Up @@ -151,6 +155,8 @@ struct JumpChargeParams
Optional<uint32> ParabolicCurveId;
};

using MovementFacingTarget = std::variant<std::monostate, Position, Unit const*, float>;

inline bool IsInvalidMovementGeneratorType(uint8 const type) { return type == MAX_DB_MOTION_TYPE || type >= MAX_MOTION_TYPE; }
inline bool IsInvalidMovementSlot(uint8 const slot) { return slot >= MAX_MOTION_SLOT; }

Expand Down
5 changes: 5 additions & 0 deletions src/server/game/Movement/Spline/MoveSplineInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,9 @@ namespace Movement

return input;
}

void MoveSplineInitFacingVisitor::operator()(Position const& point) const
{
init.SetFacing(point.GetPositionX(), point.GetPositionY(), point.GetPositionZ());
}
}
13 changes: 13 additions & 0 deletions src/server/game/Movement/Spline/MoveSplineInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class ObjectGuid;
class Unit;

struct Position;
enum class AnimTier : uint8;

namespace Movement
Expand Down Expand Up @@ -222,5 +223,17 @@ namespace Movement
{
args.spellEffectExtra = spellEffectExtraData;
}

struct TC_GAME_API MoveSplineInitFacingVisitor
{
explicit MoveSplineInitFacingVisitor(MoveSplineInit& init_) : init(init_) { }

void operator()(std::monostate) const { }
void operator()(Position const& point) const;
void operator()(Unit const* target) const { init.SetFacing(target); }
void operator()(float angle) const { init.SetFacing(angle); }

MoveSplineInit& init;
};
}
#endif // TRINITYSERVER_MOVESPLINEINIT_H
9 changes: 6 additions & 3 deletions src/server/game/Spells/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ void Spell::EffectJump()
JumpArrivalCastArgs arrivalCast;
arrivalCast.SpellId = effectInfo->TriggerSpell;
arrivalCast.Target = unitTarget->GetGUID();
unitCaster->GetMotionMaster()->MoveJump(*unitTarget, speedXY, speedZ, EVENT_JUMP, false, &arrivalCast);
unitCaster->GetMotionMaster()->MoveJump(*unitTarget, speedXY, speedZ, EVENT_JUMP, {}, &arrivalCast);
}

void Spell::EffectJumpDest()
Expand All @@ -916,9 +916,12 @@ void Spell::EffectJumpDest()

float speedXY, speedZ;
CalculateJumpSpeeds(effectInfo, unitCaster->GetExactDist2d(destTarget), speedXY, speedZ);
MovementFacingTarget facing;
if (!m_targets.GetUnitTargetGUID().IsEmpty())
facing = destTarget->GetOrientation();
JumpArrivalCastArgs arrivalCast;
arrivalCast.SpellId = effectInfo->TriggerSpell;
unitCaster->GetMotionMaster()->MoveJump(*destTarget, speedXY, speedZ, EVENT_JUMP, !m_targets.GetObjectTargetGUID().IsEmpty(), &arrivalCast);
unitCaster->GetMotionMaster()->MoveJump(*destTarget, speedXY, speedZ, EVENT_JUMP, facing, &arrivalCast);
}

TeleportToOptions GetTeleportOptions(WorldObject const* caster, Unit const* unitTarget, SpellDestination const& targetDest)
Expand Down Expand Up @@ -5782,7 +5785,7 @@ void Spell::EffectJumpCharge()
effectExtra->ParabolicCurveId = *params->ParabolicCurveId;
}

unitCaster->GetMotionMaster()->MoveJumpWithGravity(*destTarget, speed, params->JumpGravity, EVENT_JUMP, false,
unitCaster->GetMotionMaster()->MoveJumpWithGravity(*destTarget, speed, params->JumpGravity, EVENT_JUMP, {},
arrivalCast ? &*arrivalCast : nullptr,
effectExtra ? &*effectExtra : nullptr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class StartLaunchEvent : public BasicEvent
float dist = player->GetExactDist2d(&_pos);

player->ExitVehicle();
player->GetMotionMaster()->MoveJump(_pos, dist, speedZ, EVENT_JUMP, true);
player->GetMotionMaster()->MoveJump(_pos, dist, speedZ, EVENT_JUMP, _pos.GetOrientation());
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct boss_lava_guard_gordoth : public BossAI

me->SetAIAnimKitId(ANIMKIT_GORDOTH_NONE);
DoCastSelf(SPELL_JAIL_BREAK);
me->GetMotionMaster()->MoveJumpWithGravity(GordothJumpPos, 50.0f, 55.5477f, POINT_JUMP, true);
me->GetMotionMaster()->MoveJumpWithGravity(GordothJumpPos, 50.0f, 55.5477f, POINT_JUMP, GordothJumpPos.GetOrientation());

scheduler.Schedule(30ms, [this](TaskContext /*task*/)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ struct boss_toc_champion_controller : public BossAI
else
{
champion->SetHomePosition((ToCCommonLoc[1].GetPositionX()*2)-vChampionJumpTarget[pos].GetPositionX(), vChampionJumpTarget[pos].GetPositionY(), vChampionJumpTarget[pos].GetPositionZ(), 3);
champion->GetMotionMaster()->MoveJump((ToCCommonLoc[1].GetPositionX() * 2) - vChampionJumpTarget[pos].GetPositionX(), vChampionJumpTarget[pos].GetPositionY(), vChampionJumpTarget[pos].GetPositionZ(), vChampionJumpTarget[pos].GetOrientation(), 20.0f, 20.0f);
champion->GetMotionMaster()->MoveJump((ToCCommonLoc[1].GetPositionX() * 2) - vChampionJumpTarget[pos].GetPositionX(), vChampionJumpTarget[pos].GetPositionY(), vChampionJumpTarget[pos].GetPositionZ(), 20.0f, 20.0f);
champion->SetOrientation(3);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class boss_mimiron : public CreatureScript
DoCastAOE(SPELL_DESPAWN_ASSAULT_BOTS);
me->ExitVehicle();
// ExitVehicle() offset position is not implemented, so we make up for that with MoveJump()...
me->GetMotionMaster()->MoveJump(me->GetPositionX() + (10.f * std::cos(me->GetOrientation())), me->GetPositionY() + (10.f * std::sin(me->GetOrientation())), me->GetPositionZ(), me->GetOrientation(), 10.f, 5.f);
me->GetMotionMaster()->MoveJump(me->GetPositionX() + (10.f * std::cos(me->GetOrientation())), me->GetPositionY() + (10.f * std::sin(me->GetOrientation())), me->GetPositionZ(), 10.f, 5.f);
events.ScheduleEvent(EVENT_OUTTRO_1, 7s);
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Northrend/Ulduar/Ulduar/boss_thorim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ class boss_thorim : public CreatureScript
me->SetReactState(REACT_AGGRESSIVE);
me->SetDisableGravity(false);
me->SetControlled(false, UNIT_STATE_ROOT);
me->GetMotionMaster()->MoveJump(2134.8f, -263.056f, 419.983f, me->GetOrientation(), 30.0f, 20.0f);
me->GetMotionMaster()->MoveJump(2134.8f, -263.056f, 419.983f, 30.0f, 20.0f);
events.ScheduleEvent(EVENT_START_PERIODIC_CHARGE, 2s, 0, PHASE_2);
events.ScheduleEvent(EVENT_UNBALANCING_STRIKE, 15s, 0, PHASE_2);
events.ScheduleEvent(EVENT_CHAIN_LIGHTNING, 20s, 0, PHASE_2);
Expand Down

0 comments on commit ac73edc

Please sign in to comment.