From 4098d9db519820be5ea7c876331442710f218ae2 Mon Sep 17 00:00:00 2001 From: neckkola <65987027+neckkola@users.noreply.github.com> Date: Tue, 11 Jan 2022 17:40:10 -0400 Subject: [PATCH] Jan 11 --- zone/bot.cpp | 30 +++++++++++++++++++++++------- zone/client_packet.cpp | 13 ++++++++++++- zone/entity.cpp | 27 ++++++++++++++++++++++++--- zone/entity.h | 3 +++ zone/raids.cpp | 12 +++++++++++- 5 files changed, 73 insertions(+), 12 deletions(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index e937098c6..db8f5b40d 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -2540,15 +2540,12 @@ void Bot::AI_Process() Client* bot_owner = (GetBotOwner() && GetBotOwner()->IsClient() ? GetBotOwner()->CastToClient() : nullptr); Group* bot_group = GetGroup(); - Raid* bot_raid = entity_list.GetRaidByClient(bot_owner); - int bot_raid_group = 0; - if (bot_raid) - bot_raid_group = bot_raid->GetGroup(GetName()) + 1; - + Raid* bot_raid = entity_list.GetRaidByBot(this); + //#pragma region PRIMARY AI SKIP CHECKS // Primary reasons for not processing AI - if (!bot_owner || (!bot_group && !bot_raid_group) || !IsAIControlled()) { + if (!bot_owner || (!bot_group && !bot_raid) || !IsAIControlled()) { return; } @@ -2561,7 +2558,21 @@ void Bot::AI_Process() } // We also need a leash owner and follow mob (subset of primary AI criteria) - Client* leash_owner = (bot_group->GetLeader() && bot_group->GetLeader()->IsClient() ? bot_group->GetLeader()->CastToClient() : bot_owner); + Client* leash_owner = nullptr; + + if (bot_group) { + leash_owner = (bot_group->GetLeader() && bot_group->GetLeader()->IsClient() ? bot_group->GetLeader()->CastToClient() : bot_owner); + } + else if (bot_raid) { + int bot_raid_group = bot_raid->GetGroup(GetName()); + if (bot_raid_group > 0) { + leash_owner = bot_raid->GetGroupLeader(bot_raid_group)->CastToClient(); + } + else { + leash_owner = bot_raid->GetLeader(); + } + } + if (!leash_owner) { return; } @@ -8382,6 +8393,11 @@ void Bot::Camp(bool databaseSave) { //auto group = GetGroup(); if(GetGroup()) RemoveBotFromGroup(this, GetGroup()); + + //Mitch + Raid* bot_raid = entity_list.GetRaidByBot(this); + if (bot_raid) + bot_raid->RemoveMember(this->GetName()); // RemoveBotFromGroup() code is too complicated for this to work as-is (still needs to be addressed to prevent memory leaks) //if (group->GroupCount() < 2) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 60f2b9f1d..6dbdfdc33 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -11723,6 +11723,8 @@ void Client::Handle_OP_RaidCommand(const EQApplicationPacket *app) } case RaidCommandDisband: { Raid *raid = entity_list.GetRaidByClient(this); + Client* c = entity_list.GetClientByName(raid_command_packet->leader_name); + if (raid) { uint32 group = raid->GetGroup(raid_command_packet->leader_name); @@ -11753,7 +11755,16 @@ void Client::Handle_OP_RaidCommand(const EQApplicationPacket *app) } } } - +#ifdef BOTS + //check to see if the leader_name has any bots in the raid + //if so, remove them as well + + for (int i = 0; i < MAX_RAID_MEMBERS; ++i) + { + if (raid->members[i] && raid->members[i].member->IsBot() && raid->members[i].member->GetOwnerID() == entity_list.GetClientByName(raid_command_packet->leader_name)->CharacterID()) + raid->RemoveMember(raid->members[i].membername); + } +#endif raid->RemoveMember(raid_command_packet->leader_name); Client *c = entity_list.GetClientByName(raid_command_packet->leader_name); if (c) diff --git a/zone/entity.cpp b/zone/entity.cpp index bf6e44a2d..f301f6726 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -2023,17 +2023,17 @@ Raid *EntityList::GetRaidByID(uint32 id) return nullptr; } -Raid *EntityList::GetRaidByClient(Client* client) +Raid* EntityList::GetRaidByClient(Client* client) { if (client->p_raid_instance) { return client->p_raid_instance; } - std::list::iterator iterator; + std::list::iterator iterator; iterator = raid_list.begin(); while (iterator != raid_list.end()) { - for (auto &member : (*iterator)->members) { + for (auto& member : (*iterator)->members) { if (member.member) { if (member.member == client) { client->p_raid_instance = *iterator; @@ -2048,6 +2048,27 @@ Raid *EntityList::GetRaidByClient(Client* client) return nullptr; } +Raid* EntityList::GetRaidByBot(Bot* bot) +{ + std::list::iterator iterator; + iterator = raid_list.begin(); + + while (iterator != raid_list.end()) { + for (auto& member : (*iterator)->members) { + if (member.member) { + if (member.member == bot->CastToClient()) { + //client->p_raid_instance = *iterator; + return *iterator; + } + } + } + + ++iterator; + } + + return nullptr; +} + Raid *EntityList::GetRaidByMob(Mob *mob) { std::list::iterator iterator; diff --git a/zone/entity.h b/zone/entity.h index b4855b42e..0bbc298bc 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -197,6 +197,9 @@ public: Raid *GetRaidByClient(Client* client); Raid *GetRaidByID(uint32 id); Raid *GetRaidByLeaderName(const char *leader); +#ifdef BOTS + Raid* GetRaidByBot(Bot* bot); +#endif Corpse *GetCorpseByOwner(Client* client); Corpse *GetCorpseByOwnerWithinRange(Client* client, Mob* center, int range); diff --git a/zone/raids.cpp b/zone/raids.cpp index dcec202e2..2777bb637 100644 --- a/zone/raids.cpp +++ b/zone/raids.cpp @@ -246,6 +246,16 @@ void Raid::RemoveMember(const char *characterName) auto results = database.QueryDatabase(query); Client *client = entity_list.GetClientByName(characterName); +#ifdef BOTS + Bot* bot = entity_list.GetBotByBotName(characterName); + + if (bot) { + bot->SetFollowID(bot->GetOwner()->GetID()); + bot->SetGrouped(0); + bot->SetTarget(nullptr); + } +#endif + disbandCheck = true; SendRaidRemoveAll(characterName); SendRaidDisband(client); @@ -1731,7 +1741,7 @@ void Raid::SendHPManaEndPacketsFrom(Mob *mob) if(members[x].member) { if(!mob->IsClient() || ((members[x].member != mob->CastToClient()) && (members[x].GroupNumber == group_id))) { members[x].member->QueuePacket(&hpapp, false); - if (members[x].member->ClientVersion() >= EQ::versions::ClientVersion::SoD) { + if (members[x].member->IsClient() && members[x].member->ClientVersion() >= EQ::versions::ClientVersion::SoD) { //Mitch outapp.SetOpcode(OP_MobManaUpdate); MobManaUpdate_Struct *mana_update = (MobManaUpdate_Struct *)outapp.pBuffer; mana_update->spawn_id = mob->GetID();