From 2bc373b4f61d859442f0eaab321ec518f3a24c0d Mon Sep 17 00:00:00 2001 From: IntelligentQuantum Date: Wed, 5 Jan 2022 20:40:19 +0330 Subject: [PATCH] feat(Core/SmartScripts): SMART_ACTION_SET_MOVEMENT_SPEED (#10018) --- .../game/AI/SmartScripts/SmartScript.cpp | 23 +++++++++++++++++++ .../game/AI/SmartScripts/SmartScriptMgr.cpp | 15 ++++++++++++ .../game/AI/SmartScripts/SmartScriptMgr.h | 8 +++++++ 3 files changed, 46 insertions(+) diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 56e362a12..0890af7db 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -3330,6 +3330,29 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u } } + delete targets; + break; + } + case SMART_ACTION_SET_MOVEMENT_SPEED: + { + uint32 speedInteger = e.action.movementSpeed.speedInteger; + uint32 speedFraction = e.action.movementSpeed.speedFraction; + float speed = float(speedInteger) + float(speedFraction) / std::pow(10, std::floor(std::log10(float(speedFraction ? speedFraction : 1)) + 1)); + + ObjectList* targets = GetTargets(e, unit); + if (!targets) + { + break; + } + + for (auto const& target : *targets) + { + if (IsCreature(target)) + { + me->SetSpeed(UnitMoveType(e.action.movementSpeed.movementType), speed); + } + } + delete targets; break; } diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp index 57fa42f2c..8d9a7ba03 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp @@ -1182,6 +1182,21 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e) } break; } + case SMART_ACTION_SET_MOVEMENT_SPEED: + { + if (e.action.movementSpeed.movementType >= MAX_MOVE_TYPE) + { + LOG_ERROR("sql.sql", "SmartAIMgr: Entry %u SourceType %u Event %u Action %u uses invalid movementType %u, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.action.movementSpeed.movementType); + return false; + } + + if (!e.action.movementSpeed.speedInteger && !e.action.movementSpeed.speedFraction) + { + LOG_ERROR("sql.sql", "SmartAIMgr: Entry %u SourceType %u Event %u Action %u uses speed 0, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType()); + return false; + } + break; + } case SMART_ACTION_START_CLOSEST_WAYPOINT: case SMART_ACTION_FOLLOW: case SMART_ACTION_SET_ORIENTATION: diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h index ebdb99eb0..4273a396f 100644 --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h @@ -607,6 +607,7 @@ enum SMART_ACTION // SMART_ACTION_INVOKER_CAST = 134, // TODO: solve name conflicts SMART_ACTION_TC_END = 135, // placeholder + SMART_ACTION_SET_MOVEMENT_SPEED = 136, // movementType, speedInteger, speedFraction SMART_ACTION_SET_HEALTH_PCT = 142, // percent @@ -1289,6 +1290,13 @@ struct SmartAction uint32 timer; } corpseDelay; + struct + { + uint32 movementType; + uint32 speedInteger; + uint32 speedFraction; + } movementSpeed; + struct { uint32 percent;