more raid optimizations, should be final.

10 clients, 710 bots, 10 raids, ~250 pets sits around 3.5% CPU idle
This commit is contained in:
nytmyr
2024-12-28 22:58:07 -06:00
parent e652bc02b9
commit 8ed6dece34
6 changed files with 44 additions and 17 deletions
+20 -9
View File
@@ -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
+3
View File
@@ -467,6 +467,8 @@ public:
void SetGroupSpellTargetList(std::vector<Mob*> 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<BotSpells_Struct>& AIBot_spells, std::unordered_map<uint16, std::vector<BotSpells_Struct_wIndex>>& AIBot_spells_by_type);
@@ -1107,6 +1109,7 @@ private:
std::vector<Mob*> _spellTargetList;
std::vector<Mob*> _groupSpellTargetList;
Raid* _storedRaid;
bool _verifiedRaid;
uint16 _tempSpellType;
// Private "base stats" Members
+2
View File
@@ -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);
}
}
}
+15 -5
View File
@@ -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<Raid*>::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;
+1 -1
View File
@@ -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);
+3 -2
View File
@@ -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;