From f3550d4f918eb9d31320e8104ee7dbfbf421632a Mon Sep 17 00:00:00 2001 From: Brian Mask Date: Mon, 4 May 2020 20:07:09 -0600 Subject: [PATCH] check if appropriate before loading gambit --- src/map/ai/helpers/gambits_container.cpp | 14 +++++++++++- src/map/mob_spell_container.cpp | 28 ++++-------------------- src/map/spell.cpp | 8 ++++++- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/map/ai/helpers/gambits_container.cpp b/src/map/ai/helpers/gambits_container.cpp index 80278fc323c..14aaa2a3564 100644 --- a/src/map/ai/helpers/gambits_container.cpp +++ b/src/map/ai/helpers/gambits_container.cpp @@ -1,10 +1,22 @@ #include "gambits_container.h" +#include "../../spell.h" #include "../../utils/battleutils.h" void CGambitsContainer::AddGambit(G_SELECTOR selector, G_TRIGGER trigger, uint16 trigger_condition, G_REACTION reaction, G_REACTION_MODIFIER reaction_mod, uint16 reaction_arg, uint16 retry_delay) { - actions.push_back(Action_t{ selector, trigger, trigger_condition, reaction, reaction_mod, reaction_arg, retry_delay }); + bool available = true; + if (reaction == G_REACTION::MA && reaction_mod == G_REACTION_MODIFIER::SELECT_SPECIFIC) + { + if (!spell::CanUseSpell(static_cast(POwner), static_cast(reaction_arg))) + { + available = false; + } + } + if (available) + { + actions.push_back(Action_t{ selector, trigger, trigger_condition, reaction, reaction_mod, reaction_arg, retry_delay }); + } } void CGambitsContainer::Tick(time_point tick) diff --git a/src/map/mob_spell_container.cpp b/src/map/mob_spell_container.cpp index c6015717cf1..938791cdc46 100644 --- a/src/map/mob_spell_container.cpp +++ b/src/map/mob_spell_container.cpp @@ -110,31 +110,11 @@ void CMobSpellContainer::RemoveSpell(SpellID spellId) std::optional CMobSpellContainer::GetAvailable(SpellID spellId) { - bool match = false; - auto searchInList = [&](std::vector& list) - { - for (auto id : list) - { - if (static_cast(spellId) == static_cast(id)) - { - auto spell = spell::GetSpell(id); - bool hasEnoughMP = spell->getMPCost() <= m_PMob->health.mp; - bool isNotInRecast = !m_PMob->PRecastContainer->Has(RECAST_MAGIC, static_cast(spellId)); - if (isNotInRecast && hasEnoughMP) - { - match = true; - } - } - }; - }; - searchInList(m_gaList); - searchInList(m_damageList); - searchInList(m_buffList); - searchInList(m_debuffList); - searchInList(m_healList); - searchInList(m_naList); + auto spell = spell::GetSpell(spellId); + bool hasEnoughMP = spell->getMPCost() <= m_PMob->health.mp; + bool isNotInRecast = !m_PMob->PRecastContainer->Has(RECAST_MAGIC, static_cast(spellId)); - return (match) ? std::optional(spellId) : std::nullopt; + return (isNotInRecast && hasEnoughMP) ? std::optional(spellId) : std::nullopt; } std::optional CMobSpellContainer::GetBestAvailable(SPELLFAMILY family) diff --git a/src/map/spell.cpp b/src/map/spell.cpp index 43d160602b7..0a90f2f6dff 100644 --- a/src/map/spell.cpp +++ b/src/map/spell.cpp @@ -602,8 +602,14 @@ namespace spell { // cant cast cause im hidden or untargetable if (PCaster->IsNameHidden() || static_cast(PCaster)->IsUntargetable()) + { return false; - + } + // ensure trust level is appropriate+ + if (PCaster->objtype == TYPE_TRUST && PCaster->GetMLevel() < JobMLVL) + { + return false; + } // Mobs can cast any non-given char spell return true; }