Consolidate SetBotBlockedBuff/SetBotBlockedPetBuff

This commit is contained in:
nytmyr
2025-01-20 20:17:38 -06:00
parent 46a45679b2
commit 3a25d51095
+18 -55
View File
@@ -11975,42 +11975,23 @@ uint16 Bot::GetSpellByAA(int id, AA::Rank*& rank) {
return spell_id; return spell_id;
} }
void Bot::SetBotBlockedBuff(uint16 spell_id, bool block) { void Bot::SetBotBlockedBuff(uint16 spell_id, bool block)
{
if (!IsValidSpell(spell_id)) { if (!IsValidSpell(spell_id)) {
OwnerMessage("Failed to set blocked buff."); OwnerMessage("Failed to set blocked buff.");
return; return;
} }
if (!bot_blocked_buffs.empty()) { auto it = std::find_if(
bool found = false; bot_blocked_buffs.begin(), bot_blocked_buffs.end(),
[spell_id](const BotBlockedBuffs_Struct& buff) { return buff.spell_id == spell_id; }
);
for (int i = 0; i < bot_blocked_buffs.size(); i++) { if (it != bot_blocked_buffs.end()) {
if (bot_blocked_buffs[i].spell_id != spell_id) { it->blocked = block;
continue;
}
bot_blocked_buffs[i].blocked = block;
found = true;
}
if (!found) {
BotBlockedBuffs_Struct t;
t.spell_id = spell_id;
t.blocked = block;
bot_blocked_buffs.push_back(t);
}
} }
else { else {
bot_blocked_buffs.push_back({ GetBotID(), spell_id, block });
BotBlockedBuffs_Struct t;
t.spell_id = spell_id;
t.blocked = block;
bot_blocked_buffs.push_back(t);
} }
CleanBotBlockedBuffs(); CleanBotBlockedBuffs();
@@ -12041,41 +12022,23 @@ bool Bot::IsBlockedBuff(int32 spell_id)
return result; return result;
} }
void Bot::SetBotBlockedPetBuff(uint16 spell_id, bool block) { void Bot::SetBotBlockedPetBuff(uint16 spell_id, bool block)
{
if (!IsValidSpell(spell_id)) { if (!IsValidSpell(spell_id)) {
OwnerMessage("Failed to set blocked pet buff."); OwnerMessage("Failed to set blocked pet buff.");
return; return;
} }
if (!bot_blocked_buffs.empty()) { auto it = std::find_if(
bool found = false; bot_blocked_buffs.begin(), bot_blocked_buffs.end(),
[spell_id](const BotBlockedBuffs_Struct& buff) { return buff.spell_id == spell_id; }
);
for (int i = 0; i < bot_blocked_buffs.size(); i++) { if (it != bot_blocked_buffs.end()) {
if (bot_blocked_buffs[i].spell_id != spell_id) { it->blocked_pet = block;
continue;
}
bot_blocked_buffs[i].blocked_pet = block;
found = true;
}
if (!found) {
BotBlockedBuffs_Struct t;
t.spell_id = spell_id;
t.blocked_pet = block;
bot_blocked_buffs.push_back(t);
}
} }
else { else {
BotBlockedBuffs_Struct t; bot_blocked_buffs.push_back({ GetBotID(), spell_id, false, block });
t.spell_id = spell_id;
t.blocked_pet = block;
bot_blocked_buffs.push_back(t);
} }
CleanBotBlockedBuffs(); CleanBotBlockedBuffs();