From 036e4739ae44aa644d4c8a587f6889f0d6946dd9 Mon Sep 17 00:00:00 2001 From: Uleat Date: Sun, 27 Jan 2019 09:14:47 -0500 Subject: [PATCH] Fix for bots disappearing while idle --- zone/bot.cpp | 24 ++++++++++++++++++++++-- zone/bot.h | 3 +++ zone/mob.h | 4 ++-- zone/waypoints.cpp | 6 ++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index 5c37e47fa..b6496fd80 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -29,7 +29,7 @@ extern volatile bool is_zone_loaded; // This constructor is used during the bot create command -Bot::Bot(NPCType *npcTypeData, Client* botOwner) : NPC(npcTypeData, nullptr, glm::vec4(), Ground, false), rest_timer(1) { +Bot::Bot(NPCType *npcTypeData, Client* botOwner) : NPC(npcTypeData, nullptr, glm::vec4(), Ground, false), rest_timer(1), ping_timer(1) { if(botOwner) { this->SetBotOwner(botOwner); this->_botOwnerCharacterID = botOwner->CharacterID(); @@ -80,6 +80,7 @@ Bot::Bot(NPCType *npcTypeData, Client* botOwner) : NPC(npcTypeData, nullptr, glm SetShowHelm(true); SetPauseAI(false); rest_timer.Disable(); + ping_timer.Disable(); SetFollowDistance(BOT_FOLLOW_DISTANCE_DEFAULT); if (IsCasterClass(GetClass())) SetStopMeleeLevel((uint8)RuleI(Bots, CasterStopMeleeLevel)); @@ -105,7 +106,7 @@ Bot::Bot(NPCType *npcTypeData, Client* botOwner) : NPC(npcTypeData, nullptr, glm // This constructor is used when the bot is loaded out of the database Bot::Bot(uint32 botID, uint32 botOwnerCharacterID, uint32 botSpellsID, double totalPlayTime, uint32 lastZoneId, NPCType *npcTypeData) - : NPC(npcTypeData, nullptr, glm::vec4(), Ground, false), rest_timer(1) + : NPC(npcTypeData, nullptr, glm::vec4(), Ground, false), rest_timer(1), ping_timer(1) { this->_botOwnerCharacterID = botOwnerCharacterID; if(this->_botOwnerCharacterID > 0) @@ -162,6 +163,7 @@ Bot::Bot(uint32 botID, uint32 botOwnerCharacterID, uint32 botSpellsID, double to SetPauseAI(false); rest_timer.Disable(); + ping_timer.Disable(); SetFollowDistance(BOT_FOLLOW_DISTANCE_DEFAULT); if (IsCasterClass(GetClass())) SetStopMeleeLevel((uint8)RuleI(Bots, CasterStopMeleeLevel)); @@ -2010,6 +2012,9 @@ bool Bot::Process() { if (IsStunned() || IsMezzed()) return true; + if (!IsMoving() && ping_timer.Check()) + SentPositionPacket(0.0f, 0.0f, 0.0f, 0.0f, 0); + // Bot AI AI_Process(); return true; @@ -3251,6 +3256,7 @@ bool Bot::Spawn(Client* botCharacterOwner) { // Load pet LoadPet(); SentPositionPacket(0.0f, 0.0f, 0.0f, 0.0f, 0); + ping_timer.Start(8000); // there is something askew with spawn struct appearance fields... // I re-enabled this until I can sort it out uint32 itemID = 0; @@ -9072,4 +9078,18 @@ std::string Bot::CreateSayLink(Client* c, const char* message, const char* name) return saylink; } +void Bot::StopMoving() { + if (!ping_timer.Enabled()) + ping_timer.Start(8000); + + Mob::StopMoving(); +} + +void Bot::StopMoving(float new_heading) { + if (!ping_timer.Enabled()) + ping_timer.Start(8000); + + Mob::StopMoving(new_heading); +} + #endif diff --git a/zone/bot.h b/zone/bot.h index 7b8bb59c5..ed3cf8d92 100644 --- a/zone/bot.h +++ b/zone/bot.h @@ -341,6 +341,8 @@ public: virtual int GetRunspeed() const { return (int)((float)_GetRunSpeed() * 1.785714f); } virtual void WalkTo(float x, float y, float z); virtual void RunTo(float x, float y, float z); + virtual void StopMoving(); + virtual void StopMoving(float new_heading); bool UseDiscipline(uint32 spell_id, uint32 target); uint8 GetNumberNeedingHealedInGroup(uint8 hpr, bool includePets); bool GetNeedsCured(Mob *tar); @@ -731,6 +733,7 @@ private: unsigned int RestRegenMana; unsigned int RestRegenEndurance; Timer rest_timer; + Timer ping_timer; int32 base_end; int32 cur_end; int32 max_end; diff --git a/zone/mob.h b/zone/mob.h index 423dbb63e..809e7841c 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -589,8 +589,8 @@ public: void MakeSpawnUpdateNoDelta(PlayerPositionUpdateServer_Struct* spu); void MakeSpawnUpdate(PlayerPositionUpdateServer_Struct* spu); void SentPositionPacket(float dx, float dy, float dz, float dh, int anim, bool send_to_self = false); - void StopMoving(); - void StopMoving(float new_heading); + virtual void StopMoving(); + virtual void StopMoving(float new_heading); void SetSpawned() { spawned = true; }; bool Spawned() { return spawned; }; virtual bool ShouldISpawnFor(Client *c) { return true; } diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index cf79aae08..968300e56 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -1075,6 +1075,9 @@ void Bot::WalkTo(float x, float y, float z) if (IsSitting()) Stand(); + if (ping_timer.Enabled()) + ping_timer.Disable(); + Mob::WalkTo(x, y, z); } @@ -1083,6 +1086,9 @@ void Bot::RunTo(float x, float y, float z) if (IsSitting()) Stand(); + if (ping_timer.Enabled()) + ping_timer.Disable(); + Mob::RunTo(x, y, z); } #endif