From dbb368865c840542ba4d6099ea3d412e58fbcb14 Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Sat, 3 Nov 2018 17:44:19 -0400 Subject: [PATCH] Add some Follow stuff to lua You can also disallow following code from allowing the NPC to run if they're far enough away --- zone/lua_npc.cpp | 18 ++++++++++++++++++ zone/lua_npc.h | 3 +++ zone/mob.cpp | 3 ++- zone/mob.h | 9 ++++++--- zone/mob_ai.cpp | 3 ++- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/zone/lua_npc.cpp b/zone/lua_npc.cpp index a16d78361..9079049b7 100644 --- a/zone/lua_npc.cpp +++ b/zone/lua_npc.cpp @@ -333,6 +333,21 @@ void Lua_NPC::AI_SetRoambox(float dist, float max_x, float min_x, float max_y, f self->AI_SetRoambox(dist, max_x, min_x, max_y, min_y, delay, mindelay); } +void Lua_NPC::SetFollowID(int id) { + Lua_Safe_Call_Void(); + self->SetFollowID(id); +} + +void Lua_NPC::SetFollowDistance(int dist) { + Lua_Safe_Call_Void(); + self->SetFollowDistance(dist); +} + +void Lua_NPC::SetFollowCanRun(bool v) { + Lua_Safe_Call_Void(); + self->SetFollowCanRun(v); +} + int Lua_NPC::GetNPCSpellsID() { Lua_Safe_Call_Int(); return self->GetNPCSpellsID(); @@ -572,6 +587,9 @@ luabind::scope lua_register_npc() { .def("IsGuarding", (bool(Lua_NPC::*)(void))&Lua_NPC::IsGuarding) .def("AI_SetRoambox", (void(Lua_NPC::*)(float,float,float,float,float))&Lua_NPC::AI_SetRoambox) .def("AI_SetRoambox", (void(Lua_NPC::*)(float,float,float,float,float,uint32,uint32))&Lua_NPC::AI_SetRoambox) + .def("SetFollowID", (void(Lua_NPC::*)(int))&Lua_NPC::SetFollowID) + .def("SetFollowDistance", (void(Lua_NPC::*)(int))&Lua_NPC::SetFollowDistance) + .def("SetFollowCanRun", (void(Lua_NPC::*)(bool))&Lua_NPC::SetFollowCanRun) .def("GetNPCSpellsID", (int(Lua_NPC::*)(void))&Lua_NPC::GetNPCSpellsID) .def("GetSpawnPointID", (int(Lua_NPC::*)(void))&Lua_NPC::GetSpawnPointID) .def("GetSpawnPointX", (float(Lua_NPC::*)(void))&Lua_NPC::GetSpawnPointX) diff --git a/zone/lua_npc.h b/zone/lua_npc.h index 972adee90..a0097eb90 100644 --- a/zone/lua_npc.h +++ b/zone/lua_npc.h @@ -92,6 +92,9 @@ public: bool IsGuarding(); void AI_SetRoambox(float dist, float max_x, float min_x, float max_y, float min_y); void AI_SetRoambox(float dist, float max_x, float min_x, float max_y, float min_y, uint32 delay, uint32 mindelay); + void SetFollowID(int id); + void SetFollowDistance(int dist); + void SetFollowCanRun(bool v); int GetNPCSpellsID(); int GetSpawnPointID(); float GetSpawnPointX(); diff --git a/zone/mob.cpp b/zone/mob.cpp index 45a41df6e..e4c7b5f26 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -383,8 +383,9 @@ Mob::Mob(const char* in_name, m_CurrentWayPoint = glm::vec4(); cur_wp_pause = 0; patrol = 0; - follow = 0; + follow_id = 0; follow_dist = 100; // Default Distance for Follow + follow_run = true; // We can run if distance great enough no_target_hotkey = false; flee_mode = false; currently_fleeing = false; diff --git a/zone/mob.h b/zone/mob.h index 30464822c..59b4a5079 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -695,10 +695,12 @@ public: virtual bool IsAttackAllowed(Mob *target, bool isSpellAttack = false); bool IsTargeted() const { return (targeted > 0); } inline void IsTargeted(int in_tar) { targeted += in_tar; if(targeted < 0) targeted = 0;} - void SetFollowID(uint32 id) { follow = id; } + void SetFollowID(uint32 id) { follow_id = id; } void SetFollowDistance(uint32 dist) { follow_dist = dist; } - uint32 GetFollowID() const { return follow; } + void SetFollowCanRun(bool v) { follow_run = v; } + uint32 GetFollowID() const { return follow_id; } uint32 GetFollowDistance() const { return follow_dist; } + bool GetFollowCanRun() const { return follow_run; } inline bool IsRareSpawn() const { return rare_spawn; } inline void SetRareSpawn(bool in) { rare_spawn = in; } @@ -1235,8 +1237,9 @@ protected: uint16 ownerid; PetType typeofpet; int16 petpower; - uint32 follow; + uint32 follow_id; uint32 follow_dist; + bool follow_run; bool no_target_hotkey; bool rare_spawn; diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index e4066e2cc..bab3b78d2 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -1647,7 +1647,8 @@ void Mob::AI_Process() { if (distance >= follow_distance) { int speed = GetWalkspeed(); - if (distance >= follow_distance + 150) { + // maybe we want the NPC to only walk doing follow logic + if (GetFollowCanRun() && distance >= follow_distance + 150) { speed = GetRunspeed(); }