mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
feat(ai): shared Lua AI runs its waypoint actions
Objects on the Lua AI (unless Set.SuspendLuaMovementAI) get the waypoint's actions in Arrived, in order with empty values nil, run them in the WayPointEvent state and send ContinueWaypoints themselves; the movement AI only waits for it. The actions the Lua hands on run through the movement AI's handlers. isLastPoint is the path's last waypoint on every path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -176,16 +176,19 @@ namespace {
|
||||
if (movement && !path.empty()) movement->SetPath(path, start);
|
||||
}
|
||||
|
||||
// MovementAIComponent goes on along the path by itself
|
||||
void ContinueWaypoints() override {}
|
||||
void ContinueWaypoints() override {
|
||||
auto* const movement = m_Self->GetComponent<MovementAIComponent>();
|
||||
if (movement) movement->ContinueWaypoints();
|
||||
}
|
||||
|
||||
float GetAnimationTime(const std::u16string& animation) const override {
|
||||
return RenderComponent::GetAnimationTime(m_Self, animation);
|
||||
}
|
||||
|
||||
// MovementAIComponent runs the waypoint commands itself, so the waypoints this binding reports have no actions
|
||||
void RunWaypointAction(const std::string& name, const std::string&, std::optional<uint32_t>) override {
|
||||
LOG_DEBUG("Lua AI waypoint action %s on %llu is run by the movement AI", name.c_str(), m_Self->GetObjectID());
|
||||
// The actions the shared Lua hands to the object's own handlers, as the movement AI runs them
|
||||
void RunWaypointAction(const std::string& name, const std::string& value, std::optional<uint32_t>) override {
|
||||
auto* const movement = m_Self->GetComponent<MovementAIComponent>();
|
||||
if (movement) movement->RunWaypointAction(name, value == LuaAI::NO_VALUE ? "" : value);
|
||||
}
|
||||
|
||||
LWOOBJID GetObjectID() const override { return m_Self->GetObjectID(); }
|
||||
@@ -268,6 +271,9 @@ void LuaAIScript::StartLuaAI(Entity* self, const LuaAI::Settings& settings) {
|
||||
withConfig.hasGroupID = !self->GetVarAsString(u"groupID").empty();
|
||||
auto& brain = g_Brains[self->GetObjectID()];
|
||||
brain = std::make_unique<Brain>(self, withConfig, managed);
|
||||
// The Lua AI runs the waypoint actions and sends ContinueWaypoints itself, unless SuspendLuaMovementAI
|
||||
auto* const movement = self->GetComponent<MovementAIComponent>();
|
||||
if (movement) movement->SetScriptRunsWaypointActions(!settings.suspendLuaMovementAI);
|
||||
brain->machine.Start();
|
||||
}
|
||||
|
||||
@@ -312,8 +318,14 @@ void LuaAIScript::OnWaypointReached(Entity* self, const uint32_t waypointIndex)
|
||||
msg.wayPoint = waypointIndex;
|
||||
if (path) {
|
||||
msg.pathName = path->pathName;
|
||||
// Loop and bounce paths have no end
|
||||
msg.isLastPoint = path->pathBehavior == PathBehavior::Once && waypointIndex + 1 >= path->pathWaypoints.size();
|
||||
msg.isLastPoint = waypointIndex + 1 == path->pathWaypoints.size();
|
||||
// The waypoint's config in order; an empty value is nil
|
||||
if (waypointIndex < path->pathWaypoints.size() && !path->pathWaypoints[waypointIndex].actions.empty()) {
|
||||
auto& actions = msg.actions.emplace();
|
||||
for (const auto& [name, value] : path->pathWaypoints[waypointIndex].actions) {
|
||||
actions.push_back({ name, value.empty() ? LuaAI::NO_VALUE : value });
|
||||
}
|
||||
}
|
||||
}
|
||||
// The end of the path is this arrival, not another one once the movement is done
|
||||
brain->host.moving = false;
|
||||
|
||||
Reference in New Issue
Block a user