Files
DarkflameServer/dScripts/ai/LuaAI/LuaAIScript.h
Aaron Kimbrell c96d645b94 feat(ai): shared Lua AI custom state
Port o_Main's customState: a script that defines
onTemplateCustomStateEnter or onTemplateCustomStateArrived gets the
state, and its enter and arrived hooks run as LuaAIScript virtuals.
Pets and helpers stay unported: no original script turns them on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 23:50:19 -06:00

44 lines
2.1 KiB
C++

#pragma once
// The base for a script whose original requires the shared Lua AI (State, o_StateCreate, o_mis, o_Main) and runs
// loadOnce, getVarables, CreateStates and oStart: call StartLuaAI from OnStartup with its Set table. It handles the
// messages o_onEvent and the states do; a script with its own onTimerDone or onDie in the original overrides
// OnLuaTimerDone or OnLuaDie (the states still get theirs first), one with its own onNotifyObject overrides
// OnNotifyObject.
#include "CppScripts.h"
#include "LuaAIMachine.h"
class LuaAIScript : public CppScripts::Script {
public:
void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) override;
void OnHit(Entity* self, Entity* attacker) override;
void OnTimerDone(Entity* self, std::string timerName) final;
void OnDie(Entity* self, Entity* killer) final;
void OnUpdate(Entity* self) override;
// The waypoints of its path: the global onArrived (o_WayPointEvents)
void OnWaypointReached(Entity* self, uint32_t waypointIndex) override;
// o_onEvent onFireEvent: startpath
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override;
// o_onEvent onNotifyObject: GoHome
void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override;
// The machine running on this entity, or nullptr
static LuaAI::Machine* GetMachine(const Entity* self);
protected:
// loadOnce, getVarables, CreateStates and oStart
static void StartLuaAI(Entity* self, const LuaAI::Settings& settings);
// The global onTimerDone: o_onEvent's unless the original has its own
virtual void OnLuaTimerDone(Entity* self, const std::string& timerName);
// The global onDie: o_main's does nothing
virtual void OnLuaDie(Entity* self, Entity* killer) {}
public:
// onTemplateCustomStateEnter / onTemplateCustomStateArrived: a script with either sets
// Settings::hasCustomState and overrides them
virtual void OnTemplateCustomStateEnter(Entity* self) {}
virtual void OnTemplateCustomStateArrived(Entity* self) {}
};