From 5a9c8c18c1d23816e33ad90317d29ea186c2eb79 Mon Sep 17 00:00:00 2001 From: neckkola <65987027+neckkola@users.noreply.github.com> Date: Fri, 21 Jan 2022 23:31:59 -0400 Subject: [PATCH] Bot Death fixed and few other crashes --- zone/bot.cpp | 27 +++++++++++++++++++++++++-- zone/bot.h | 1 + zone/bot_raid.cpp | 30 ++++++++++++------------------ zone/botspellsai.cpp | 2 +- zone/client.cpp | 7 ++++--- zone/raids.cpp | 13 ++++++++++++- zone/raids.h | 1 + 7 files changed, 56 insertions(+), 25 deletions(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index 09d3549fb..f5bb347fd 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -4049,7 +4049,13 @@ bool Bot::Spawn(Client* botCharacterOwner) { this->SendWearChange(materialFromSlot); } } + Raid* raid = entity_list.GetRaidByBotName(this->GetName()); + if (raid) + { + raid->VerifyRaid(); + this->SetRaidGrouped(true); + } return true; } @@ -5028,8 +5034,23 @@ bool Bot::Death(Mob *killerMob, int32 damage, uint16 spell_id, EQ::skills::Skill if ((GetPullingFlag() || GetReturningFlag()) && my_owner && my_owner->IsClient()) { my_owner->CastToClient()->SetBotPulling(false); } - if (!this->IsRaidGrouped()) + + Raid* raid = entity_list.GetRaidByBotName(this->GetName()); + uint32 gid = raid->GetGroup(this->GetName()); + if (raid) + { + for (int x = 0; x < MAX_RAID_MEMBERS; x++) + { + if (strcmp(raid->members[x].membername, this->GetName()) == 0) + { + raid->members[x].member = nullptr; + } + } + } + else + { entity_list.RemoveBot(this->GetID()); + } return true; } @@ -9294,8 +9315,10 @@ bool EntityList::Bot_AICheckCloseBeneficialSpells(Bot* caster, uint8 iChance, fl break; } Group* g = caster->GetGroup(); + uint32 gid = 0xff; Raid* raid = entity_list.GetRaidByBotName(caster->GetName()); - uint32 gid = raid->GetGroup(caster->GetName()); + if (raid) + uint32 gid = raid->GetGroup(caster->GetName()); if(g) { for(int i = 0; i < MAX_GROUP_MEMBERS; i++) { diff --git a/zone/bot.h b/zone/bot.h index 90ae7e8cb..323a8f227 100644 --- a/zone/bot.h +++ b/zone/bot.h @@ -35,6 +35,7 @@ #include "../common/global_define.h" #include "guild_mgr.h" #include "worldserver.h" +#include "raids.h" #include diff --git a/zone/bot_raid.cpp b/zone/bot_raid.cpp index 74cd5592f..3d946b292 100644 --- a/zone/bot_raid.cpp +++ b/zone/bot_raid.cpp @@ -19,7 +19,6 @@ #ifdef BOTS #include "bot.h" -#include "bot_raid.h" #include "object.h" #include "raids.h" #include "doors.h" @@ -75,7 +74,7 @@ void Bot::AI_Process_Raid() // We also need a leash owner and follow mob (subset of primary AI criteria) Client* leash_owner = nullptr; - if (r_group < 12) { + if (r_group < 12 && !leash_owner) { leash_owner = raid->GetGroupLeader(r_group); } else { @@ -313,9 +312,7 @@ void Bot::AI_Process_Raid() std::vector raid_group_members = raid->GetRaidGroupMembers(r_group); for (RaidMember iter : raid_group_members) { - -// for (int counter = 0; counter < raid->GroupCount(r_group); counter++) { -// Group* bot_group = this->GetGroup(); + Mob* bg_member = iter.member;// bot_group->members[counter]; if (!bg_member) { continue; @@ -422,9 +419,9 @@ void Bot::AI_Process_Raid() else if (bo_alt_combat && m_alt_combat_hate_timer.Check()) { // Find a mob from hate list to target - // Group roles can be expounded upon in the future - Group* bot_group = this->GetGroup(); //Mitch - auto assist_mob = entity_list.GetMob(bot_group->GetMainAssistName()); + // Raid Group roles can be expounded upon in the future + //r_group is the uint32 group id + auto assist_mob = raid->GetRaidMainAssistOneByName(this->GetName()); bool find_target = true; if (assist_mob) { @@ -1540,6 +1537,7 @@ bool Bot::AICastSpell_Raid(Mob* tar, uint8 iChance, uint32 iSpellTypes) { // Bot AI Raid Raid* raid = entity_list.GetRaidByBotName(this->GetName()); + uint32 r_group = raid->GetGroup(GetName()); if (!raid) return false; @@ -2424,7 +2422,7 @@ bool Bot::AICastSpell_Raid(Mob* tar, uint8 iChance, uint32 iSpellTypes) { break; } case SpellType_Cure: { - if (GetNeedsCured(tar) && (tar->DontCureMeBefore() < Timer::GetCurrentTime()) && !(GetNumberNeedingHealedInGroup(25, false) > 0) && !(GetNumberNeedingHealedInGroup(40, false) > 2)) + if (GetNeedsCured(tar) && (tar->DontCureMeBefore() < Timer::GetCurrentTime()) && !(GetNumberNeedingHealedInRaidGroup(25, false) > 0) && !(GetNumberNeedingHealedInRaidGroup(40, false) > 2)) { botSpell = GetBestBotSpellForCure(this, tar); @@ -2438,16 +2436,12 @@ bool Bot::AICastSpell_Raid(Mob* tar, uint8 iChance, uint32 iSpellTypes) { if (castedSpell) { if (botClass != BARD) { if (IsGroupSpell(botSpell.SpellId)) { - Group* g; - - if (this->HasGroup()) { - Group* g = this->GetGroup(); - - if (g) { - for (int i = 0; i < MAX_GROUP_MEMBERS; i++) { - if (g->members[i] && !g->members[i]->qglobal) { + if (this->IsRaidGrouped()) { + if (r_group) { + for (RaidMember iter : raid->GetRaidGroupMembers(r_group)) { + if (iter.member && !iter.member->qglobal) { if (TempDontCureMeBeforeTime != tar->DontCureMeBefore()) - g->members[i]->SetDontCureMeBefore(Timer::GetCurrentTime() + 4000); + iter.member->SetDontCureMeBefore(Timer::GetCurrentTime() + 4000); } } } diff --git a/zone/botspellsai.cpp b/zone/botspellsai.cpp index 5b0288485..94b119e71 100644 --- a/zone/botspellsai.cpp +++ b/zone/botspellsai.cpp @@ -3,7 +3,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. + the Free Software Foundation; version 2 ogroupf the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY except by those people which sell it, which diff --git a/zone/client.cpp b/zone/client.cpp index e47acc2ad..0dfd55dfd 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -812,9 +812,10 @@ void Client::QueuePacket(const EQApplicationPacket* app, bool ack_req, CLIENT_CO // todo: save packets for later use AddPacket(app, ack_req); } - else - if(eqs && !IsBot()) //Mitch added the BoTcheck for a fail safe on trying to send a packet to a BoT! - eqs->QueuePacket(app, ack_req); + else if (eqs && !IsBot()) //Mitch added the BoTcheck for a fail safe on trying to send a packet to a BoT! + { + eqs->QueuePacket(app, ack_req); + } } void Client::FastQueuePacket(EQApplicationPacket** app, bool ack_req, CLIENT_CONN_STATUS required_state) { diff --git a/zone/raids.cpp b/zone/raids.cpp index 7fd865f12..689aff450 100644 --- a/zone/raids.cpp +++ b/zone/raids.cpp @@ -1738,7 +1738,7 @@ void Raid::SendHPManaEndPacketsFrom(Mob *mob) mob->CreateHPPacket(&hpapp); for(int x = 0; x < MAX_RAID_MEMBERS; x++) { - if(members[x].member && members[x].membername) { + 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->IsClient() && members[x].member->ClientVersion() >= EQ::versions::ClientVersion::SoD) { //Mitch @@ -1988,3 +1988,14 @@ bool Raid::DoesAnyMemberHaveExpeditionLockout( return Expedition::HasLockoutByCharacterName(raid_member.membername, expedition_name, event_name); }); } +Mob* Raid::GetRaidMainAssistOneByName(const char* name) +{ + Raid* raid = entity_list.GetRaidByBotName(name); + std::vector raid_members = raid->GetMembers(); + + for (RaidMember& iter : raid_members) + { + if (iter.IsRaidMainAssistOne) + return iter.member->CastToMob(); + } +} diff --git a/zone/raids.h b/zone/raids.h index 5ac1910f5..8c31d210f 100644 --- a/zone/raids.h +++ b/zone/raids.h @@ -124,6 +124,7 @@ public: #ifdef BOTS void AddBot(Bot* b, uint32 group = 0xFFFFFFFF, bool rleader=false, bool groupleader=false, bool looter=false); //Mitch void RaidBotGroupSay(Bot* b, uint8 language, uint8 lang_skill, const char* msg, ...); //Mitch + static Mob* GetRaidMainAssistOneByName(const char* name); #endif void RemoveMember(const char *c); void DisbandRaid();