diff options
| author | Shauren <shauren.trinity@gmail.com> | 2026-01-09 00:37:42 +0100 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2026-01-09 00:37:42 +0100 |
| commit | 00542ca800113679d5897be9a63c620fb7c48d1c (patch) | |
| tree | 3b7922b149f86d415b05ce877196c79408089dc3 /src/server | |
| parent | 05406d034ed464f14a3879f7f990f0117d0f5fc8 (diff) | |
Core/Scripts: Remove Optional<> wrapper from all Scripting::v2::ActionResultSetter uses
Diffstat (limited to 'src/server')
29 files changed, 106 insertions, 90 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index c210b7ea582..20beb7bcbd2 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -47,7 +47,7 @@ bool SmartAI::IsAIControlled() const } void SmartAI::StartPath(uint32 pathId/* = 0*/, bool repeat/* = false*/, Unit* invoker/* = nullptr*/, uint32 nodeId/* = 0*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult/* = {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult/* = {}*/) { if (HasEscortState(SMART_ESCORT_ESCORTING)) StopPath(); diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h index 79ab404e971..712fd06788e 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.h +++ b/src/server/game/AI/SmartScripts/SmartAI.h @@ -53,7 +53,7 @@ class TC_GAME_API SmartAI : public CreatureAI // Start moving to the desired MovePoint void StartPath(uint32 pathId = 0, bool repeat = false, Unit* invoker = nullptr, uint32 nodeId = 0, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); WaypointPath const* LoadPath(uint32 entry); void PausePath(uint32 delay, bool forced = false); bool CanResumePath(); diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 28ee26256ed..c87f2f6ba92 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -1198,7 +1198,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u y = pos.GetPositionY() + (std::sin(o - (M_PI / 2))*e.target.x) + (std::sin(o)*e.target.y); z = pos.GetPositionZ() + e.target.z; - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> scriptResult; + Scripting::v2::ActionResultSetter<MovementStopReason> scriptResult; if (waitEvent) scriptResult = Scripting::v2::ActionResult<MovementStopReason>::GetResultSetter({ waitEvent, &waitEvent->Results.emplace_back() }); @@ -1424,7 +1424,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u } std::shared_ptr<Scripting::v2::ActionResult<MovementStopReason>> waitEvent = CreateTimedActionListWaitEventFor<MovementStopReason>(e); - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> scriptResult; + Scripting::v2::ActionResultSetter<MovementStopReason> scriptResult; if (waitEvent) scriptResult = Scripting::v2::ActionResult<MovementStopReason>::GetResultSetter(waitEvent); @@ -1499,7 +1499,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u target = Trinity::Containers::SelectRandomContainerElement(targets); std::shared_ptr<Scripting::v2::ActionResult<MovementStopReason>> waitEvent = CreateTimedActionListWaitEventFor<MovementStopReason>(e); - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> scriptResult; + Scripting::v2::ActionResultSetter<MovementStopReason> scriptResult; if (waitEvent) scriptResult = Scripting::v2::ActionResult<MovementStopReason>::GetResultSetter(waitEvent); @@ -1807,13 +1807,13 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u { if (Player* playerTarget = target->ToPlayer()) { - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> scriptResult; + Scripting::v2::ActionResultSetter<MovementStopReason> scriptResult; if (waitEvent) scriptResult = Scripting::v2::ActionResult<MovementStopReason>::GetResultSetter({ waitEvent, &waitEvent->Results.emplace_back() }); if (!playerTarget->ActivateTaxiPathTo(e.action.taxi.id, 0, {}, scriptResult)) if (scriptResult) - scriptResult->SetResult(MovementStopReason::Interrupted); + scriptResult.SetResult(MovementStopReason::Interrupted); } } if (waitEvent && !waitEvent->Results.empty()) @@ -1919,7 +1919,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u break; std::shared_ptr<Scripting::v2::ActionResult<MovementStopReason>> waitEvent = CreateTimedActionListWaitEventFor<MovementStopReason>(e); - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> actionResultSetter; + Scripting::v2::ActionResultSetter<MovementStopReason> actionResultSetter; if (waitEvent) actionResultSetter = Scripting::v2::ActionResult<MovementStopReason>::GetResultSetter(waitEvent); @@ -2138,7 +2138,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u if (closest.first != 0) { - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> actionResultSetter; + Scripting::v2::ActionResultSetter<MovementStopReason> actionResultSetter; if (waitEvent) actionResultSetter = Scripting::v2::ActionResult<MovementStopReason>::GetResultSetter({ waitEvent, &waitEvent->Results.emplace_back() }); @@ -2681,7 +2681,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u { if (Unit* unitTarget = target->ToUnit()) { - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> actionResultSetter; + Scripting::v2::ActionResultSetter<MovementStopReason> actionResultSetter; if (waitEvent) actionResultSetter = Scripting::v2::ActionResult<MovementStopReason>::GetResultSetter({ waitEvent, &waitEvent->Results.emplace_back() }); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index c5822c6fd69..0c78b827c80 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -22896,7 +22896,7 @@ UF::PVPInfo const* Player::GetPvpInfoForBracket(int8 bracket) const } bool Player::ActivateTaxiPathTo(std::vector<uint32> const& nodes, Creature* npc /*= nullptr*/, uint32 spellid /*= 0*/, uint32 preferredMountDisplay /*= 0*/, - Optional<float> speed /*= {}*/, Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> const& scriptResult /*= {}*/) + Optional<float> speed /*= {}*/, Scripting::v2::ActionResultSetter<MovementStopReason> const& scriptResult /*= {}*/) { if (nodes.size() < 2) { @@ -23076,13 +23076,13 @@ bool Player::ActivateTaxiPathTo(std::vector<uint32> const& nodes, Creature* npc ModifyMoney(-int64(firstcost)); UpdateCriteria(CriteriaType::MoneySpentOnTaxis, firstcost); GetSession()->SendActivateTaxiReply(ERR_TAXIOK); - StartTaxiMovement(mount_display_id, sourcepath, 0, speed, Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>(scriptResult)); + StartTaxiMovement(mount_display_id, sourcepath, 0, speed, Scripting::v2::ActionResultSetter(scriptResult)); } return true; } bool Player::ActivateTaxiPathTo(uint32 taxi_path_id, uint32 spellid /*= 0*/, Optional<float> speed /*= {}*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> const& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason> const& scriptResult /*= {}*/) { TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(taxi_path_id); if (!entry) @@ -23158,7 +23158,7 @@ void Player::ContinueTaxiFlight() } void Player::StartTaxiMovement(uint32 mountDisplayId, uint32 path, uint32 pathNode, Optional<float> speed, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult) { // remove fake death RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags::Interacting); diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index ead0c144f7f..19427470c1d 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1234,14 +1234,14 @@ class TC_GAME_API Player final : public Unit, public GridObject<Player> PlayerTaxi m_taxi; void InitTaxiNodesForLevel() { m_taxi.InitTaxiNodesForLevel(GetRace(), GetClass(), GetLevel()); } bool ActivateTaxiPathTo(std::vector<uint32> const& nodes, Creature* npc = nullptr, uint32 spellid = 0, uint32 preferredMountDisplay = 0, Optional<float> speed = {}, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> const& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason> const& scriptResult = {}); bool ActivateTaxiPathTo(uint32 taxi_path_id, uint32 spellid = 0, Optional<float> speed = {}, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> const& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason> const& scriptResult = {}); void FinishTaxiFlight(); void CleanupAfterTaxiFlight(); void ContinueTaxiFlight(); void StartTaxiMovement(uint32 mountDisplayId, uint32 path, uint32 pathNode, Optional<float> speed, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult); bool IsDeveloper() const { return HasPlayerFlag(PLAYER_FLAGS_DEVELOPER); } void SetDeveloper(bool on) { if (on) SetPlayerFlag(PLAYER_FLAGS_DEVELOPER); else RemovePlayerFlag(PLAYER_FLAGS_DEVELOPER); } diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index bf2d2669d7d..1c7b3621761 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -595,7 +595,7 @@ void MotionMaster::MoveTargetedHome() void MotionMaster::MoveRandom(float wanderDistance /*= 0.0f*/, Optional<Milliseconds> duration /*= {}*/, Optional<float> speed /*= {}*/, MovementWalkRunSpeedSelectionMode speedSelectionMode /*= MovementWalkRunSpeedSelectionMode::ForceWalk*/, MovementSlot slot /*= MOTION_SLOT_DEFAULT*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MoveRandom: '{}', started random movement (spawnDist: {})", _owner->GetGUID(), wanderDistance); if (_owner->GetTypeId() == TYPEID_UNIT) @@ -605,13 +605,13 @@ void MotionMaster::MoveRandom(float wanderDistance /*= 0.0f*/, Optional<Millisec } void MotionMaster::MoveFollow(Unit* target, float dist, Optional<ChaseAngle> angle /*= {}*/, Optional<Milliseconds> duration /*= {}*/, bool ignoreTargetWalk /*= false*/, MovementSlot slot/* = MOTION_SLOT_ACTIVE*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { // Ignore movement request if target not exist if (!target || target == _owner) { if (scriptResult) - scriptResult->SetResult(MovementStopReason::Interrupted); + scriptResult.SetResult(MovementStopReason::Interrupted); return; } @@ -644,12 +644,12 @@ void MotionMaster::MoveConfused() } void MotionMaster::MoveFleeing(Unit* enemy, Milliseconds time /*= 0ms*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { if (!enemy) { if (scriptResult) - scriptResult->SetResult(MovementStopReason::Interrupted); + scriptResult.SetResult(MovementStopReason::Interrupted); return; } @@ -662,14 +662,14 @@ void MotionMaster::MoveFleeing(Unit* enemy, Milliseconds time /*= 0ms*/, void MotionMaster::MovePoint(uint32 id, Position const& pos, bool generatePath/* = true*/, Optional<float> finalOrient/* = {}*/, Optional<float> speed /*= {}*/, MovementWalkRunSpeedSelectionMode speedSelectionMode /*= MovementWalkRunSpeedSelectionMode::Default*/, Optional<float> closeEnoughDistance /*= {}*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { MovePoint(id, pos.m_positionX, pos.m_positionY, pos.m_positionZ, generatePath, finalOrient, speed, speedSelectionMode, closeEnoughDistance, std::move(scriptResult)); } void MotionMaster::MovePoint(uint32 id, float x, float y, float z, bool generatePath /*= true*/, Optional<float> finalOrient /*= {}*/, Optional<float> speed /*= {}*/, MovementWalkRunSpeedSelectionMode speedSelectionMode /*= MovementWalkRunSpeedSelectionMode::Default*/, Optional<float> closeEnoughDistance /*= {}*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MovePoint: '{}', targeted point Id: {} (X: {}, Y: {}, Z: {})", _owner->GetGUID(), id, x, y, z); Add(new PointMovementGenerator(id, x, y, z, generatePath, speed, finalOrient, nullptr, nullptr, speedSelectionMode, closeEnoughDistance, std::move(scriptResult))); @@ -700,21 +700,21 @@ void MotionMaster::MoveCloserAndStop(uint32 id, Unit* target, float distance) void MotionMaster::MoveLand(uint32 id, Position const& pos, Optional<int32> tierTransitionId /*= {}*/, Optional<float> velocity /*= {}*/, MovementWalkRunSpeedSelectionMode speedSelectionMode /*= MovementWalkRunSpeedSelectionMode::Default*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { MoveTierTransition(id, pos, AnimTier::Ground, tierTransitionId, velocity, speedSelectionMode, std::move(scriptResult)); } void MotionMaster::MoveTakeoff(uint32 id, Position const& pos, Optional<int32> tierTransitionId /*= {}*/, Optional<float> velocity /*= {}*/, MovementWalkRunSpeedSelectionMode speedSelectionMode /*= MovementWalkRunSpeedSelectionMode::Default*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { MoveTierTransition(id, pos, AnimTier::Fly, tierTransitionId, velocity, speedSelectionMode, std::move(scriptResult)); } void MotionMaster::MoveTierTransition(uint32 id, Position const& pos, AnimTier newAnimTier, Optional<int32> tierTransitionId /*= {}*/, Optional<float> velocity /*= {}*/, MovementWalkRunSpeedSelectionMode speedSelectionMode /*= MovementWalkRunSpeedSelectionMode::Default*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MoveTierTransition: '{}', anim tier transition to {} Id: {} (X: {}, Y: {}, Z: {})", _owner->GetGUID(), newAnimTier, id, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ()); @@ -858,7 +858,7 @@ void MotionMaster::MoveJump(uint32 id, Position const& pos, std::variant<std::mo Optional<float> minHeight /*= {}*/, Optional<float> maxHeight /*= {}*/, MovementFacingTarget const& facing /*= {}*/, bool orientationFixed, bool unlimitedSpeed /*= false*/, Optional<float> speedMultiplier /*= {}*/, JumpArrivalCastArgs const* arrivalCast /*= nullptr*/, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MoveJump: '{}', jumps to point Id: {} ({})", _owner->GetGUID(), id, pos.ToString()); @@ -894,7 +894,7 @@ void MotionMaster::MoveJump(uint32 id, Position const& pos, std::variant<std::mo if (speedXY < 0.01f) { if (scriptResult) - scriptResult->SetResult(MovementStopReason::Interrupted); + scriptResult.SetResult(MovementStopReason::Interrupted); return; } @@ -933,7 +933,7 @@ void MotionMaster::MoveJump(uint32 id, Position const& pos, std::variant<std::mo void MotionMaster::MoveCirclePath(float x, float y, float z, float radius, bool clockwise, uint8 stepCount, Optional<Milliseconds> duration /*= {}*/, Optional<float> speed /*= {}*/, MovementWalkRunSpeedSelectionMode speedSelectionMode /*= MovementWalkRunSpeedSelectionMode::Default*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { std::function<void(Movement::MoveSplineInit&)> initializer = [=, this](Movement::MoveSplineInit& init) { @@ -1019,12 +1019,12 @@ void MotionMaster::ResumeSplineChain(SplineChainResumeInfo const& info) } void MotionMaster::MoveFall(uint32 id /*= 0*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { - auto setterScopeExit = Trinity::make_unique_ptr_with_deleter(&scriptResult, [](Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>* opt) + auto setterScopeExit = Trinity::make_unique_ptr_with_deleter(&scriptResult, [](Scripting::v2::ActionResultSetter<MovementStopReason>* opt) { - if (opt->has_value()) - (*opt)->SetResult(MovementStopReason::Interrupted); + if (bool(*opt)) + opt->SetResult(MovementStopReason::Interrupted); }); // Use larger distance for vmap height search than in most other cases @@ -1091,7 +1091,7 @@ void MotionMaster::MoveSeekAssistanceDistract(uint32 time) } void MotionMaster::MoveTaxiFlight(uint32 path, uint32 pathnode, Optional<float> speed /*= {}*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { if (_owner->GetTypeId() == TYPEID_PLAYER) { @@ -1129,12 +1129,12 @@ void MotionMaster::MovePath(uint32 pathId, bool repeatable, Optional<Millisecond Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd /*= {}*/, Optional<float> wanderDistanceAtPathEnds /*= {}*/, Optional<bool> followPathBackwardsFromEndToStart /*= {}*/, Optional<bool> exactSplinePath /*= {}*/, bool generatePath /*= true*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { if (!pathId) { if (scriptResult) - scriptResult->SetResult(MovementStopReason::Interrupted); + scriptResult.SetResult(MovementStopReason::Interrupted); return; } @@ -1154,7 +1154,7 @@ void MotionMaster::MovePath(WaypointPath const& path, bool repeatable, Optional< Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd /*= {}*/, Optional<float> wanderDistanceAtPathEnds /*= {}*/, Optional<bool> followPathBackwardsFromEndToStart /*= {}*/, Optional<bool> exactSplinePath /*= {}*/, bool generatePath /*= true*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MovePath: '{}', starts moving over path Id: {} (repeatable: {})", _owner->GetGUID(), path.Id, repeatable ? "YES" : "NO"); @@ -1169,7 +1169,7 @@ void MotionMaster::MovePath(WaypointPath const& path, bool repeatable, Optional< void MotionMaster::MoveRotate(uint32 id, RotateDirection direction, Optional<Milliseconds> time /*= {}*/, Optional<float> turnSpeed /*= {}*/, Optional<float> totalTurnAngle /*= {}*/, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) { TC_LOG_DEBUG("movement.motionmaster", "MotionMaster::MoveRotate: '{}', starts rotate (time: {}ms, turnSpeed: {}, totalTurnAngle: {}, direction: {})", _owner->GetGUID(), time.value_or(0ms).count(), turnSpeed, totalTurnAngle, direction); diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h index d8696cbb44a..438267011b7 100644 --- a/src/server/game/Movement/MotionMaster.h +++ b/src/server/game/Movement/MotionMaster.h @@ -159,20 +159,20 @@ class TC_GAME_API MotionMaster void MoveTargetedHome(); void MoveRandom(float wanderDistance = 0.0f, Optional<Milliseconds> duration = {}, Optional<float> speed = {}, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::ForceWalk, MovementSlot slot = MOTION_SLOT_DEFAULT, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MoveFollow(Unit* target, float dist, Optional<ChaseAngle> angle = {}, Optional<Milliseconds> duration = {}, bool ignoreTargetWalk = false, MovementSlot slot = MOTION_SLOT_ACTIVE, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MoveChase(Unit* target, Optional<ChaseRange> dist = {}, Optional<ChaseAngle> angle = {}); void MoveChase(Unit* target, float dist, float angle) { MoveChase(target, ChaseRange(dist), ChaseAngle(angle)); } void MoveConfused(); void MoveFleeing(Unit* enemy, Milliseconds time = 0ms, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MovePoint(uint32 id, Position const& pos, bool generatePath = true, Optional<float> finalOrient = {}, Optional<float> speed = {}, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, Optional<float> closeEnoughDistance = {}, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MovePoint(uint32 id, float x, float y, float z, bool generatePath = true, Optional<float> finalOrient = {}, Optional<float> speed = {}, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, Optional<float> closeEnoughDistance = {}, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); /* * Makes the unit move toward the target until it is at a certain distance from it. The unit then stops. * Only works in 2D. @@ -182,13 +182,13 @@ class TC_GAME_API MotionMaster // These two movement types should only be used with creatures having landing/takeoff animations void MoveLand(uint32 id, Position const& pos, Optional<int32> tierTransitionId = {}, Optional<float> velocity = {}, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MoveTakeoff(uint32 id, Position const& pos, Optional<int32> tierTransitionId = {}, Optional<float> velocity = {}, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MoveTierTransition(uint32 id, Position const& pos, AnimTier newAnimTier, Optional<int32> tierTransitionId = {}, Optional<float> velocity = {}, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MoveCharge(float x, float y, float z, float speed = SPEED_CHARGE, uint32 id = EVENT_CHARGE, bool generatePath = false, Unit const* target = nullptr, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr); 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, float angle = M_PI, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr); @@ -196,32 +196,32 @@ class TC_GAME_API MotionMaster Optional<float> minHeight = {}, Optional<float> maxHeight = {}, MovementFacingTarget const& facing = {}, bool orientationFixed = false, bool unlimitedSpeed = false, Optional<float> speedMultiplier = {}, JumpArrivalCastArgs const* arrivalCast = nullptr, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MoveCirclePath(float x, float y, float z, float radius, bool clockwise, uint8 stepCount, Optional<Milliseconds> duration = {}, Optional<float> speed = {}, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); // Walk along spline chain stored in DB (script_spline_chain_meta and script_spline_chain_waypoints) void MoveAlongSplineChain(uint32 pointId, uint16 dbChainId, bool walk); void MoveAlongSplineChain(uint32 pointId, std::vector<SplineChainLink> const& chain, bool walk); void ResumeSplineChain(SplineChainResumeInfo const& info); void MoveFall(uint32 id = 0, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MoveSeekAssistance(float x, float y, float z); void MoveSeekAssistanceDistract(uint32 timer); void MoveTaxiFlight(uint32 path, uint32 pathnode, Optional<float> speed = {}, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MoveDistract(uint32 time, float orientation); void MovePath(uint32 pathId, bool repeatable, Optional<Milliseconds> duration = {}, Optional<float> speed = {}, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd = {}, Optional<float> wanderDistanceAtPathEnds = {}, Optional<bool> followPathBackwardsFromEndToStart = {}, Optional<bool> exactSplinePath = {}, bool generatePath = true, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MovePath(WaypointPath const& path, bool repeatable, Optional<Milliseconds> duration = {}, Optional<float> speed = {}, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd = {}, Optional<float> wanderDistanceAtPathEnds = {}, Optional<bool> followPathBackwardsFromEndToStart = {}, Optional<bool> exactSplinePath = {}, bool generatePath = true, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); /** * \brief Makes the Unit turn in place @@ -234,7 +234,7 @@ class TC_GAME_API MotionMaster */ void MoveRotate(uint32 id, RotateDirection direction, Optional<Milliseconds> time = {}, Optional<float> turnSpeed = {}, Optional<float> totalTurnAngle = {}, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); void MoveFormation(Unit* leader, float range, float angle, uint32 point1, uint32 point2); void LaunchMoveSpline(std::function<void(Movement::MoveSplineInit& init)>&& initializer, uint32 id = 0, MovementGeneratorPriority priority = MOTION_PRIORITY_NORMAL, MovementGeneratorType type = EFFECT_MOTION_TYPE); diff --git a/src/server/game/Movement/MovementGenerator.cpp b/src/server/game/Movement/MovementGenerator.cpp index ee98f44a3a9..325b7258d4d 100644 --- a/src/server/game/Movement/MovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerator.cpp @@ -34,7 +34,7 @@ void MovementGenerator::SetScriptResult(MovementStopReason reason) { if (ScriptResult) { - ScriptResult->SetResult(reason); - ScriptResult.reset(); + ScriptResult.SetResult(reason); + ScriptResult.Reset(); } } diff --git a/src/server/game/Movement/MovementGenerator.h b/src/server/game/Movement/MovementGenerator.h index 08188c8b484..e677d65bb32 100755 --- a/src/server/game/Movement/MovementGenerator.h +++ b/src/server/game/Movement/MovementGenerator.h @@ -22,7 +22,6 @@ #include "FactoryHolder.h" #include "MovementDefines.h" #include "ObjectRegistry.h" -#include "Optional.h" #include "ScriptActionResult.h" class Creature; @@ -87,7 +86,7 @@ class TC_GAME_API MovementGenerator uint8 Priority; uint16 Flags; uint32 BaseUnitState; - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> ScriptResult; + Scripting::v2::ActionResultSetter<MovementStopReason> ScriptResult; protected: void SetScriptResult(MovementStopReason reason); diff --git a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp index 95fd612ae65..de0b5627542 100644 --- a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp @@ -27,7 +27,7 @@ #define MAX_QUIET_DISTANCE 43.0f FleeingMovementGenerator::FleeingMovementGenerator(ObjectGuid fleeTargetGUID, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) : _fleeTargetGUID(fleeTargetGUID), _timer(0) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) : _fleeTargetGUID(fleeTargetGUID), _timer(0) { Mode = MOTION_MODE_DEFAULT; Priority = MOTION_PRIORITY_HIGHEST; diff --git a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.h b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.h index 7da2589d647..06bdca1fe44 100755 --- a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.h @@ -29,7 +29,7 @@ class FleeingMovementGenerator : public MovementGenerator { public: explicit FleeingMovementGenerator(ObjectGuid fleeTargetGUID, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); FleeingMovementGenerator(FleeingMovementGenerator const&) = delete; FleeingMovementGenerator(FleeingMovementGenerator&&) = delete; FleeingMovementGenerator& operator=(FleeingMovementGenerator const&) = delete; @@ -59,7 +59,7 @@ class TimedFleeingMovementGenerator : public FleeingMovementGenerator { public: explicit TimedFleeingMovementGenerator(ObjectGuid fleeTargetGUID, Milliseconds time, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}) : FleeingMovementGenerator(fleeTargetGUID, std::move(scriptResult)), _totalFleeTime(time) { } bool Update(Unit*, uint32) override; diff --git a/src/server/game/Movement/MovementGenerators/FlightPathMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FlightPathMovementGenerator.cpp index 14fa5ee3e5f..abb1ea0777e 100644 --- a/src/server/game/Movement/MovementGenerators/FlightPathMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FlightPathMovementGenerator.cpp @@ -33,7 +33,7 @@ #define PLAYER_FLIGHT_SPEED 32.0f FlightPathMovementGenerator::FlightPathMovementGenerator(Optional<float> speed, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult) { _speed = speed; _endGridX = 0.0f; diff --git a/src/server/game/Movement/MovementGenerators/FlightPathMovementGenerator.h b/src/server/game/Movement/MovementGenerators/FlightPathMovementGenerator.h index 82969b337ca..ff2d8bc3f77 100644 --- a/src/server/game/Movement/MovementGenerators/FlightPathMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/FlightPathMovementGenerator.h @@ -34,7 +34,7 @@ class FlightPathMovementGenerator : public MovementGeneratorMedium<Player, Fligh { public: explicit FlightPathMovementGenerator(Optional<float> speed, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult); MovementGeneratorType GetMovementGeneratorType() const override; bool GetResetPosition(Unit* owner, float& x, float& y, float& z) override; diff --git a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp index ee4ab14195d..60bb5452c98 100644 --- a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.cpp @@ -35,7 +35,7 @@ static void DoMovementInform(Unit* owner, Unit* target) } FollowMovementGenerator::FollowMovementGenerator(Unit* target, float range, Optional<ChaseAngle> angle, Optional<Milliseconds> duration, - bool ignoreTargetWalk /*= false*/, Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + bool ignoreTargetWalk /*= false*/, Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) : AbstractFollower(ASSERT_NOTNULL(target)), _range(range), _angle(angle), _ignoreTargetWalk(ignoreTargetWalk), _checkTimer(CHECK_INTERVAL) { Mode = MOTION_MODE_DEFAULT; diff --git a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.h b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.h index 12eaf83bfa9..e5fffd6d2b0 100644 --- a/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/FollowMovementGenerator.h @@ -33,7 +33,7 @@ class FollowMovementGenerator : public MovementGenerator, public AbstractFollowe { public: explicit FollowMovementGenerator(Unit* target, float range, Optional<ChaseAngle> angle, Optional<Milliseconds> duration, - bool ignoreTargetWalk = false, Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + bool ignoreTargetWalk = false, Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); ~FollowMovementGenerator(); void Initialize(Unit*) override; diff --git a/src/server/game/Movement/MovementGenerators/GenericMovementGenerator.h b/src/server/game/Movement/MovementGenerators/GenericMovementGenerator.h index f88b53c3fb0..c66cb6e2f88 100644 --- a/src/server/game/Movement/MovementGenerators/GenericMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/GenericMovementGenerator.h @@ -32,7 +32,7 @@ struct GenericMovementGeneratorArgs Optional<uint32> ArrivalSpellId; Optional<ObjectGuid> ArrivalSpellTarget; Optional<Milliseconds> Duration; - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>> ScriptResult; + Scripting::v2::ActionResultSetter<MovementStopReason> ScriptResult; }; class GenericMovementGenerator : public MovementGenerator diff --git a/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.cpp index 30bc4b154c1..98874d56766 100644 --- a/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.cpp @@ -70,7 +70,7 @@ MovementGenerator* IdleMovementFactory::Create(Unit* /*object*/) const RotateMovementGenerator::RotateMovementGenerator(uint32 id, RotateDirection direction, Optional<Milliseconds> duration, Optional<float> turnSpeed, Optional<float> totalTurnAngle, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult) : _id(id), _duration(duration), + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult) : _id(id), _duration(duration), _turnSpeed(turnSpeed), _totalTurnAngle(totalTurnAngle), _direction(direction), _diffSinceLastUpdate(0) { diff --git a/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.h b/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.h index 6e9fe57ba9f..0d5b3e096fe 100755 --- a/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.h @@ -44,7 +44,7 @@ class RotateMovementGenerator : public MovementGenerator explicit RotateMovementGenerator(uint32 id, RotateDirection direction, Optional<Milliseconds> duration, Optional<float> turnSpeed, Optional<float> totalTurnAngle, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult); void Initialize(Unit*) override; void Reset(Unit*) override; diff --git a/src/server/game/Movement/MovementGenerators/PointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/PointMovementGenerator.cpp index d70b9b3b95a..e4324b3ef3d 100755 --- a/src/server/game/Movement/MovementGenerators/PointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/PointMovementGenerator.cpp @@ -31,7 +31,7 @@ PointMovementGenerator::PointMovementGenerator(uint32 id, float x, float y, float z, bool generatePath, Optional<float> speed /*= {}*/, Optional<float> finalOrient /*= {}*/, Unit const* faceTarget /*= nullptr*/, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/, MovementWalkRunSpeedSelectionMode speedSelectionMode /*= MovementWalkRunSpeedSelectionMode::Default*/, - Optional<float> closeEnoughDistance /*= {}*/, Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Optional<float> closeEnoughDistance /*= {}*/, Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) : _movementId(id), _destination(x, y, z), _speed(speed), _generatePath(generatePath), _finalOrient(finalOrient), i_faceTarget(faceTarget), _speedSelectionMode(speedSelectionMode), _closeEnoughDistance(closeEnoughDistance) { diff --git a/src/server/game/Movement/MovementGenerators/PointMovementGenerator.h b/src/server/game/Movement/MovementGenerators/PointMovementGenerator.h index e9e2210c919..28baf373a2d 100644 --- a/src/server/game/Movement/MovementGenerators/PointMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/PointMovementGenerator.h @@ -34,7 +34,7 @@ class PointMovementGenerator : public MovementGenerator Unit const* faceTarget = nullptr, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, Optional<float> closeEnoughDistance = {}, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); PointMovementGenerator(PointMovementGenerator const&) = delete; PointMovementGenerator(PointMovementGenerator&&) = delete; PointMovementGenerator& operator=(PointMovementGenerator const&) = delete; diff --git a/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp index 569cc519157..d54f349be19 100644 --- a/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp @@ -28,7 +28,7 @@ template<class T> RandomMovementGenerator<T>::RandomMovementGenerator(float distance, Optional<Milliseconds> duration, Optional<float> speed, MovementWalkRunSpeedSelectionMode speedSelectionMode, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) : _timer(0), _speed(speed), _speedSelectionMode(speedSelectionMode), _wanderDistance(distance), _wanderSteps(0) { this->Mode = MOTION_MODE_DEFAULT; diff --git a/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.h b/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.h index 51dcd19f8e8..af6fec3c18d 100644 --- a/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/RandomMovementGenerator.h @@ -31,7 +31,7 @@ class RandomMovementGenerator : public MovementGeneratorMedium<T, RandomMovement public: explicit RandomMovementGenerator(float distance, Optional<Milliseconds> duration = {}, Optional<float> speed = {}, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); MovementGeneratorType GetMovementGeneratorType() const override; diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp index aacaca8c950..122d1c693b9 100644 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp @@ -39,7 +39,7 @@ template <typename T> WaypointMovementGenerator<T>::WaypointMovementGenerator(uint32 pathId, bool repeating, Optional<Milliseconds> duration, Optional<float> speed, MovementWalkRunSpeedSelectionMode speedSelectionMode, Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd, Optional<float> wanderDistanceAtPathEnds, Optional<bool> followPathBackwardsFromEndToStart, Optional<bool> exactSplinePath, bool generatePath, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) : PathMovementBase(sWaypointMgr->GetPath(pathId)), _speed(speed), _speedSelectionMode(speedSelectionMode), _waitTimeRangeAtPathEnd(std::move(waitTimeRangeAtPathEnd)), _wanderDistanceAtPathEnds(wanderDistanceAtPathEnds), _followPathBackwardsFromEndToStart(followPathBackwardsFromEndToStart), _exactSplinePath(exactSplinePath), _repeating(repeating), _generatePath(generatePath), @@ -58,7 +58,7 @@ template <typename T> WaypointMovementGenerator<T>::WaypointMovementGenerator(WaypointPath const& path, bool repeating, Optional<Milliseconds> duration, Optional<float> speed, MovementWalkRunSpeedSelectionMode speedSelectionMode, Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd, Optional<float> wanderDistanceAtPathEnds, Optional<bool> followPathBackwardsFromEndToStart, Optional<bool> exactSplinePath, bool generatePath, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/) + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult /*= {}*/) : PathMovementBase(std::make_unique<WaypointPath>(path)), _speed(speed), _speedSelectionMode(speedSelectionMode), _waitTimeRangeAtPathEnd(std::move(waitTimeRangeAtPathEnd)), _wanderDistanceAtPathEnds(wanderDistanceAtPathEnds), _followPathBackwardsFromEndToStart(followPathBackwardsFromEndToStart), _exactSplinePath(exactSplinePath), _repeating(repeating), _generatePath(generatePath), diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h index 217687e12fb..001f9563210 100755 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h @@ -35,12 +35,12 @@ class WaypointMovementGenerator : public MovementGeneratorMedium<T, WaypointMove MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode::Default, Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd = {}, Optional<float> wanderDistanceAtPathEnds = {}, Optional<bool> followPathBackwardsFromEndToStart = {}, Optional<bool> exactSplinePath = {}, bool generatePath = true, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); explicit WaypointMovementGenerator(WaypointPath const& path, bool repeating, Optional<Milliseconds> duration, Optional<float> speed, MovementWalkRunSpeedSelectionMode speedSelectionMode, Optional<std::pair<Milliseconds, Milliseconds>> waitTimeRangeAtPathEnd, Optional<float> wanderDistanceAtPathEnds, Optional<bool> followPathBackwardsFromEndToStart, Optional<bool> exactSplinePath, bool generatePath, - Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {}); + Scripting::v2::ActionResultSetter<MovementStopReason>&& scriptResult = {}); ~WaypointMovementGenerator(); MovementGeneratorType GetMovementGeneratorType() const override; diff --git a/src/server/game/Scripting/v2/ScriptActionResult.h b/src/server/game/Scripting/v2/ScriptActionResult.h index 823aba61208..e7d1c056216 100644 --- a/src/server/game/Scripting/v2/ScriptActionResult.h +++ b/src/server/game/Scripting/v2/ScriptActionResult.h @@ -24,32 +24,46 @@ namespace Scripting::v2 { class ActionBase; +template <typename T> +struct ActionResultValueHolder +{ + ActionBase& Action; + T Result = { }; +}; + void MarkActionCompleted(ActionBase& action); template <typename T> class ActionResultSetter { public: - explicit ActionResultSetter(std::shared_ptr<ActionBase> action, T* result) : _action(std::move(action)), _result(result) { } + ActionResultSetter() = default; + + explicit ActionResultSetter(std::shared_ptr<ActionResultValueHolder<T>>&& action) : _action(std::move(action)) { } void SetResult(T result) { - if (std::shared_ptr<ActionBase> ptr = _action.lock()) + if (std::shared_ptr<ActionResultValueHolder<T>> ptr = _action.lock()) { - *_result = std::move(result); - MarkActionCompleted(*ptr); + ptr->Result = result; + MarkActionCompleted(ptr->Action); } } + explicit operator bool() const { return !_action.expired(); } + + void Reset() { _action.reset(); } + private: - std::weak_ptr<ActionBase> _action; - T* _result; + std::weak_ptr<ActionResultValueHolder<T>> _action; }; template <> class ActionResultSetter<void> { public: + ActionResultSetter() = default; + explicit ActionResultSetter(std::shared_ptr<ActionBase> action) : _action(std::move(action)) { } void SetResult() @@ -58,6 +72,10 @@ public: MarkActionCompleted(*ptr); } + explicit operator bool() const { return !_action.expired(); } + + void Reset() { _action.reset(); } + private: std::weak_ptr<ActionBase> _action; }; diff --git a/src/server/game/Scripting/v2/ScriptActions.h b/src/server/game/Scripting/v2/ScriptActions.h index 5c9fe5f204e..b02d2df1850 100644 --- a/src/server/game/Scripting/v2/ScriptActions.h +++ b/src/server/game/Scripting/v2/ScriptActions.h @@ -65,12 +65,11 @@ class ActionResult : public ActionBase public:
[[nodiscard]] static ActionResultSetter<T> GetResultSetter(std::shared_ptr<ActionResult> action)
{
- T* resultPtr = &action->_result;
- return ActionResultSetter<T>(std::move(action), resultPtr);
+ return ActionResultSetter<T>(std::shared_ptr<ActionResultValueHolder<T>>(std::move(action), &action->_result));
}
private:
- T _result = { };
+ ActionResultValueHolder<T> _result = { .Action = *this };
};
template<>
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 86e1d7f292a..01a42a8ccd0 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -3892,7 +3892,7 @@ void Spell::_cast(bool skipCheck) } if (m_scriptResult && !m_scriptWaitsForSpellHit) - m_scriptResult->SetResult(SPELL_CAST_OK); + m_scriptResult.SetResult(SPELL_CAST_OK); CallScriptAfterCastHandlers(); @@ -4381,7 +4381,7 @@ void Spell::finish(SpellCastResult result) m_spellState = SPELL_STATE_FINISHED; if (m_scriptResult && (m_scriptWaitsForSpellHit || result != SPELL_CAST_OK)) - m_scriptResult->SetResult(result); + m_scriptResult.SetResult(result); if (!m_caster) return; diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 507af8da2de..c84e6dd377c 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -630,7 +630,7 @@ class TC_GAME_API Spell UsedSpellMods m_appliedMods; - Optional<Scripting::v2::ActionResultSetter<SpellCastResult>> m_scriptResult; + Scripting::v2::ActionResultSetter<SpellCastResult> m_scriptResult; bool m_scriptWaitsForSpellHit = false; int32 GetCastTime() const { return m_casttime; } diff --git a/src/server/game/Spells/SpellDefines.h b/src/server/game/Spells/SpellDefines.h index f5c849c3b32..b32acd16ca7 100644 --- a/src/server/game/Spells/SpellDefines.h +++ b/src/server/game/Spells/SpellDefines.h @@ -484,7 +484,7 @@ struct CastSpellExtraArgsInit }; std::vector<SpellValueOverride> SpellValueOverrides; std::any CustomArg; - Optional<Scripting::v2::ActionResultSetter<SpellCastResult>> ScriptResult; + Scripting::v2::ActionResultSetter<SpellCastResult> ScriptResult; bool ScriptWaitsForSpellHit = false; }; @@ -520,7 +520,7 @@ struct TC_GAME_API CastSpellExtraArgs : public CastSpellExtraArgsInit CastSpellExtraArgs& AddSpellMod(SpellValueModFloat mod, float val) { SpellValueOverrides.emplace_back(mod, val); return *this; } CastSpellExtraArgs& AddSpellBP0(int32 val) { return AddSpellMod(SPELLVALUE_BASE_POINT0, val); } // because i don't want to type SPELLVALUE_BASE_POINT0 300 times CastSpellExtraArgs& SetCustomArg(std::any customArg) { CustomArg = std::move(customArg); return *this; } - CastSpellExtraArgs& SetScriptResult(Scripting::v2::ActionResultSetter<SpellCastResult> scriptResult) { ScriptResult.emplace(std::move(scriptResult)); return *this; } + CastSpellExtraArgs& SetScriptResult(Scripting::v2::ActionResultSetter<SpellCastResult>&& scriptResult) { ScriptResult = std::move(scriptResult); return *this; } CastSpellExtraArgs& SetScriptWaitsForSpellHit(bool scriptWaitsForSpellHit) { ScriptWaitsForSpellHit = scriptWaitsForSpellHit; return *this; } }; |
