diff --git a/zone/bot.cpp b/zone/bot.cpp index 46d762ad1..dc7fd196e 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -111,7 +111,9 @@ Bot::Bot(NPCType *npcTypeData, Client* botOwner) : NPC(npcTypeData, nullptr, glm bot_blocked_buffs.clear(); _spellTargetList.clear(); _groupSpellTargetList.clear(); - _storedRaid = nullptr; + SetStoredRaid(nullptr); + SetVerifiedRaid(false); + p_raid_instance = nullptr; // Calculate HitPoints Last As It Uses Base Stats current_hp = GenerateBaseHitPoints(); @@ -263,7 +265,9 @@ Bot::Bot( _spellTargetList.clear(); _groupSpellTargetList.clear(); - _storedRaid = nullptr; + SetStoredRaid(nullptr); + SetVerifiedRaid(false); + p_raid_instance = nullptr; LoadAAs(); if (database.botdb.LoadBuffs(this)) { @@ -1637,10 +1641,6 @@ bool Bot::Process() entity_list.ScanCloseMobs(this); } - //if (m_mob_check_moving_timer.Check()) { //TODO bot rewrite - is this necessary - // CheckScanCloseMobsMovingTimer(); - //} - // SpellProcess(); if (tic_timer.Check()) { @@ -2064,12 +2064,16 @@ void Bot::AI_Process() return; } - auto raid = entity_list.GetRaidByBot(this); + Raid* raid = entity_list.GetRaidByBot(this); SetStoredRaid(raid); uint32 r_group = RAID_GROUPLESS; if (raid) { - //raid->VerifyRaid(); + if (!GetVerifiedRaid()) { + raid->VerifyRaid(); + SetVerifiedRaid(true); + } + r_group = raid->GetGroup(GetName()); //if (mana_timer.Check(false)) { @@ -3568,7 +3572,7 @@ bool Bot::Spawn(Client* botCharacterOwner) { ChangeBotRangedWeapons(true); } - if (auto raid = entity_list.GetRaidByBot(this)) { + if (auto raid = entity_list.GetRaidByBotName(GetName())) { // Safety Check to confirm we have a valid raid auto owner = GetBotOwner(); if (owner && !raid->IsRaidMember(owner->GetCleanName())) { @@ -3577,6 +3581,9 @@ bool Bot::Spawn(Client* botCharacterOwner) { SetRaidGrouped(true); raid->LearnMembers(); raid->VerifyRaid(); + SetStoredRaid(raid); + p_raid_instance = raid; + SetVerifiedRaid(true); } } else if (auto group = entity_list.GetGroupByMob(this)) { @@ -7051,6 +7058,10 @@ void Bot::RemoveBotFromRaid(Bot* bot) { bot_raid->DisbandRaid(); } } + + bot->SetStoredRaid(nullptr); + bot->p_raid_instance = nullptr; + bot->SetVerifiedRaid(false); } // Handles all client zone change event diff --git a/zone/bot.h b/zone/bot.h index e0177e257..f1c8e0482 100644 --- a/zone/bot.h +++ b/zone/bot.h @@ -467,6 +467,8 @@ public: void SetGroupSpellTargetList(std::vector spellTargetList) { _groupSpellTargetList = spellTargetList; } Raid* GetStoredRaid() { return _storedRaid; } void SetStoredRaid(Raid* storedRaid) { _storedRaid = storedRaid; } + bool GetVerifiedRaid() { return _verifiedRaid; } + void SetVerifiedRaid(bool status) { _verifiedRaid = status; } uint16 GetTempSpellType() { return _tempSpellType; } void SetTempSpellType(uint16 spellType) { _tempSpellType = spellType; } void AssignBotSpellsToTypes(std::vector& AIBot_spells, std::unordered_map>& AIBot_spells_by_type); @@ -1107,6 +1109,7 @@ private: std::vector _spellTargetList; std::vector _groupSpellTargetList; Raid* _storedRaid; + bool _verifiedRaid; uint16 _tempSpellType; // Private "base stats" Members diff --git a/zone/bot_raid.cpp b/zone/bot_raid.cpp index 458ae03c4..4e93b5d49 100644 --- a/zone/bot_raid.cpp +++ b/zone/bot_raid.cpp @@ -313,7 +313,9 @@ void Client::SpawnRaidBotsOnConnect(Raid* raid) { if (bot) { bot->SetRaidGrouped(true); + bot->SetStoredRaid(raid); bot->p_raid_instance = raid; + bot->SetVerifiedRaid(false); } } } diff --git a/zone/entity.cpp b/zone/entity.cpp index a756c9fdc..a7ba7f396 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -2244,14 +2244,24 @@ Raid* EntityList::GetRaidByBotName(const char* name) return nullptr; } -Raid* EntityList::GetRaidByBot(const Bot* bot) +Raid* EntityList::GetRaidByBot(Bot* bot) { - for (const auto& r : raid_list) { - for (const auto& m : r->members) { - if (m.is_bot && m.member->CastToBot() == bot) { - return r; + if (bot->p_raid_instance) { + return bot->p_raid_instance; + } + + std::list::iterator iterator; + iterator = raid_list.begin(); + + while (iterator != raid_list.end()) { + for (const auto& member : (*iterator)->members) { + if (member.member && member.is_bot && member.member->CastToBot() == bot) { + bot->p_raid_instance = *iterator; + return *iterator; } } + + ++iterator; } return nullptr; diff --git a/zone/entity.h b/zone/entity.h index 4b5c9b690..d1798c6bc 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -200,7 +200,7 @@ public: Raid *GetRaidByClient(Client* client); Raid *GetRaidByID(uint32 id); Raid* GetRaidByBotName(const char* name); - Raid* GetRaidByBot(const Bot* bot); + Raid* GetRaidByBot(Bot* bot); Raid* GetRaidByName(const char* name); Corpse *GetCorpseByOwner(Client* client); diff --git a/zone/raids.cpp b/zone/raids.cpp index 4dd710e3a..7bb6ab4e5 100644 --- a/zone/raids.cpp +++ b/zone/raids.cpp @@ -240,8 +240,6 @@ void Raid::AddBot(Bot* b, uint32 group, bool raid_leader, bool group_leader, boo SendRaidAddAll(b->GetName()); b->SetRaidGrouped(true); - b->p_raid_instance = this; - auto pack = new ServerPacket(ServerOP_RaidAdd, sizeof(ServerRaidGeneralAction_Struct)); auto* rga = (ServerRaidGeneralAction_Struct*) pack->pBuffer; @@ -267,6 +265,9 @@ void Raid::RemoveMember(const char *character_name) b->SetFollowID(b->GetOwner()->CastToClient()->GetID()); b->SetTarget(nullptr); b->SetRaidGrouped(false); + b->p_raid_instance = nullptr; + b->SetStoredRaid(nullptr); + b->SetVerifiedRaid(false); } disbandCheck = true;