Skip to content

Commit

Permalink
feat(Core/SmartAI): Add support for waypoint_data in SAI (azerothcore…
Browse files Browse the repository at this point in the history
…#18706)

* Create rev_1712670662273633900.sql

* eol?

* doesn't like a comment at the end, ok, ok

* init

* mack

* Update SmartScript.cpp

* kurzel

* random paths and garg

* Update rev_1712889530436412200.sql

* brend & marge

* Update rev_1712889530436412200.sql

* movement actions

* Update SmartScriptMgr.h
  • Loading branch information
Gultask authored Apr 18, 2024
1 parent 5386443 commit 6f154d0
Show file tree
Hide file tree
Showing 6 changed files with 813 additions and 2 deletions.
689 changes: 689 additions & 0 deletions data/sql/updates/pending_db_world/rev_1712889530436412200.sql

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/server/game/AI/SmartScripts/SmartAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ void SmartAI::MovementInform(uint32 MovementType, uint32 Data)
if (MovementType == POINT_MOTION_TYPE && Data == SMART_ESCORT_LAST_OOC_POINT)
me->ClearUnitState(UNIT_STATE_EVADE);

if (MovementType == WAYPOINT_MOTION_TYPE)
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_DATA_REACHED, nullptr, Data + 1); // Data + 1 to align smart_scripts and waypoint_data Id rows

GetScript()->ProcessEventsFor(SMART_EVENT_MOVEMENTINFORM, nullptr, MovementType, Data);
if (!HasEscortState(SMART_ESCORT_ESCORTING))
return;
Expand Down Expand Up @@ -1150,6 +1153,11 @@ void SmartAI::OnSpellClick(Unit* clicker, bool& /*result*/)
GetScript()->ProcessEventsFor(SMART_EVENT_ON_SPELLCLICK, clicker);
}

void SmartAI::PathEndReached(uint32 pathId)
{
GetScript()->ProcessEventsFor(SMART_EVENT_WAYPOINT_DATA_ENDED, nullptr, 0, me->GetWaypointPath());
}

void SmartGameObjectAI::SummonedCreatureDies(Creature* summon, Unit* /*killer*/)
{
GetScript()->ProcessEventsFor(SMART_EVENT_SUMMONED_UNIT_DIES, summon);
Expand Down
2 changes: 2 additions & 0 deletions src/server/game/AI/SmartScripts/SmartAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ class SmartAI : public CreatureAI

void OnSpellClick(Unit* clicker, bool& result) override;

void PathEndReached(uint32 pathId) override;

// Xinef
void SetWPPauseTimer(uint32 time) { mWPPauseTimer = time; }

Expand Down
65 changes: 65 additions & 0 deletions src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3057,6 +3057,63 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
break;
}
case SMART_ACTION_WAYPOINT_DATA_START:
{
if (e.action.wpData.pathId)
{
for (WorldObject* target : targets)
{
if (IsCreature(target))
{
target->ToCreature()->LoadPath(e.action.wpData.pathId);
target->ToCreature()->GetMotionMaster()->MovePath(e.action.wpData.pathId, e.action.wpData.repeat);
}
}
}

break;
}
case SMART_ACTION_WAYPOINT_DATA_RANDOM:
{
if (e.action.wpDataRandom.pathId1 && e.action.wpDataRandom.pathId2)
{
for (WorldObject* target : targets)
{
if (IsCreature(target))
{
uint32 path = urand(e.action.wpDataRandom.pathId1, e.action.wpDataRandom.pathId2);
target->ToCreature()->LoadPath(path);
target->ToCreature()->GetMotionMaster()->MovePath(path, e.action.wpDataRandom.repeat);
}
}
}

break;
}
case SMART_ACTION_MOVEMENT_STOP:
{
for (WorldObject* target : targets)
if (IsUnit(target))
target->ToUnit()->StopMoving();

break;
}
case SMART_ACTION_MOVEMENT_PAUSE:
{
for (WorldObject* target : targets)
if (IsUnit(target))
target->ToUnit()->PauseMovement(e.action.move.timer);

break;
}
case SMART_ACTION_MOVEMENT_RESUME:
{
for (WorldObject* target : targets)
if (IsUnit(target))
target->ToUnit()->ResumeMovement(e.action.move.timer);

break;
}
default:
LOG_ERROR("sql.sql", "SmartScript::ProcessAction: Entry {} SourceType {}, Event {}, Unhandled Action type {}", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
break;
Expand Down Expand Up @@ -4538,6 +4595,14 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
RecalcTimer(e, 1200, 1200);
break;
}
case SMART_EVENT_WAYPOINT_DATA_REACHED:
case SMART_EVENT_WAYPOINT_DATA_ENDED:
{
if (!me || (e.event.wpData.pointId && var0 != e.event.wpData.pointId) || (e.event.wpData.pathId && me->GetWaypointPath() != e.event.wpData.pathId))
return;
ProcessAction(e, unit);
break;
}
default:
LOG_ERROR("sql.sql", "SmartScript::ProcessEvent: Unhandled Event type {}", e.GetEventType());
break;
Expand Down
14 changes: 14 additions & 0 deletions src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ bool SmartAIMgr::CheckUnusedEventParams(SmartScriptHolder const& e)
case SMART_EVENT_AREA_CASTING: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_AREA_RANGE: return sizeof(SmartEvent::minMaxRepeat);
case SMART_EVENT_SUMMONED_UNIT_EVADE: return sizeof(SmartEvent::summoned);
case SMART_EVENT_WAYPOINT_DATA_REACHED: return sizeof(SmartEvent::wpData);
case SMART_EVENT_WAYPOINT_DATA_ENDED: return sizeof(SmartEvent::wpData);
default:
LOG_WARN("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} is using an event {} with no unused params specified in SmartAIMgr::CheckUnusedEventParams(), please report this.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetEventType());
Expand Down Expand Up @@ -769,6 +771,11 @@ bool SmartAIMgr::CheckUnusedActionParams(SmartScriptHolder const& e)
case SMART_ACTION_PLAY_SPELL_VISUAL: return sizeof(SmartAction::spellVisual);
case SMART_ACTION_FOLLOW_GROUP: return sizeof(SmartAction::followGroup);
case SMART_ACTION_SET_ORIENTATION_TARGET: return sizeof(SmartAction::orientationTarget);
case SMART_ACTION_WAYPOINT_DATA_START: return sizeof(SmartAction::wpData);
case SMART_ACTION_WAYPOINT_DATA_RANDOM: return sizeof(SmartAction::wpDataRandom);
case SMART_ACTION_MOVEMENT_STOP: return NO_PARAMS;
case SMART_ACTION_MOVEMENT_PAUSE: return sizeof(SmartAction::move);
case SMART_ACTION_MOVEMENT_RESUME: return sizeof(SmartAction::move);
default:
LOG_WARN("sql.sql", "SmartAIMgr: entryorguid {} source_type {} id {} action_type {} is using an action with no unused params specified in SmartAIMgr::CheckUnusedActionParams(), please report this.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
Expand Down Expand Up @@ -1321,6 +1328,8 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
case SMART_EVENT_JUST_CREATED:
case SMART_EVENT_FOLLOW_COMPLETED:
case SMART_EVENT_ON_SPELLCLICK:
case SMART_EVENT_WAYPOINT_DATA_REACHED:
case SMART_EVENT_WAYPOINT_DATA_ENDED:
break;
default:
LOG_ERROR("sql.sql", "SmartAIMgr: Not handled event_type({}), Entry {} SourceType {} Event {} Action {}, skipped.", e.GetEventType(), e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
Expand Down Expand Up @@ -1945,6 +1954,11 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
case SMART_ACTION_PLAY_SPELL_VISUAL:
case SMART_ACTION_FOLLOW_GROUP:
case SMART_ACTION_SET_ORIENTATION_TARGET:
case SMART_ACTION_WAYPOINT_DATA_START:
case SMART_ACTION_WAYPOINT_DATA_RANDOM:
case SMART_ACTION_MOVEMENT_STOP:
case SMART_ACTION_MOVEMENT_PAUSE:
case SMART_ACTION_MOVEMENT_RESUME:
break;
default:
LOG_ERROR("sql.sql", "SmartAIMgr: Not handled action_type({}), event_type({}), Entry {} SourceType {} Event {}, skipped.", e.GetActionType(), e.GetEventType(), e.entryOrGuid, e.GetScriptType(), e.event_id);
Expand Down
37 changes: 35 additions & 2 deletions src/server/game/AI/SmartScripts/SmartScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ enum SMART_EVENT
SMART_EVENT_AREA_CASTING = 105, // min, max, repeatMin, repeatMax, rangeMin, rangeMax
SMART_EVENT_AREA_RANGE = 106, // min, max, repeatMin, repeatMax, rangeMin, rangeMax
SMART_EVENT_SUMMONED_UNIT_EVADE = 107, // CreatureId(0 all), CooldownMin, CooldownMax
SMART_EVENT_WAYPOINT_DATA_REACHED = 108, // PointId (0: any), pathId (0: any)
SMART_EVENT_WAYPOINT_DATA_ENDED = 109, // PointId (0: any), pathId (0: any)

SMART_EVENT_AC_END = 108
SMART_EVENT_AC_END = 110
};

struct SmartEvent
Expand Down Expand Up @@ -507,6 +509,12 @@ struct SmartEvent
uint32 timer;
} nearUnitNegation;

struct
{
uint32 pointId;
uint32 pathId;
} wpData;

struct
{
uint32 param1;
Expand Down Expand Up @@ -714,8 +722,13 @@ enum SMART_ACTION
SMART_ACTION_PLAY_SPELL_VISUAL = 229, // visualId, visualIdImpact
SMART_ACTION_FOLLOW_GROUP = 230, // followState, followType, dist
SMART_ACTION_SET_ORIENTATION_TARGET = 231, // type, target_type, target_param1, target_param2, target_param3, target_param4
SMART_ACTION_WAYPOINT_DATA_START = 232, // pathId, repeat
SMART_ACTION_WAYPOINT_DATA_RANDOM = 233, // pathId1, pathId2, repeat
SMART_ACTION_MOVEMENT_STOP = 234, //
SMART_ACTION_MOVEMENT_PAUSE = 235, // timer
SMART_ACTION_MOVEMENT_RESUME = 236, // timerOverride

SMART_ACTION_AC_END = 232, // placeholder
SMART_ACTION_AC_END = 237, // placeholder
};

enum class SmartActionSummonCreatureFlags
Expand Down Expand Up @@ -1434,6 +1447,24 @@ struct SmartAction
uint32 targetParam3;
uint32 targetParam4;
} orientationTarget;

struct
{
uint32 pathId;
SAIBool repeat;
} wpData;

struct
{
uint32 pathId1;
uint32 pathId2;
SAIBool repeat;
} wpDataRandom;

struct
{
uint32 timer;
} move;
//! Note for any new future actions
//! All parameters must have type uint32

Expand Down Expand Up @@ -1844,6 +1875,8 @@ const uint32 SmartAIEventMask[SMART_EVENT_AC_END][2] =
{SMART_EVENT_AREA_CASTING, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_AREA_RANGE, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_SUMMONED_UNIT_EVADE, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
{SMART_EVENT_WAYPOINT_DATA_REACHED, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_WAYPOINT_DATA_ENDED, SMART_SCRIPT_TYPE_MASK_CREATURE },
};

enum SmartEventFlags
Expand Down

0 comments on commit 6f154d0

Please sign in to comment.