Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
check if appropriate before loading gambit
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmask committed May 5, 2020
1 parent 1a1519d commit f3550d4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
14 changes: 13 additions & 1 deletion src/map/ai/helpers/gambits_container.cpp
Original file line number Diff line number Diff line change
@@ -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<CBattleEntity*>(POwner), static_cast<SpellID>(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)
Expand Down
28 changes: 4 additions & 24 deletions src/map/mob_spell_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,11 @@ void CMobSpellContainer::RemoveSpell(SpellID spellId)

std::optional<SpellID> CMobSpellContainer::GetAvailable(SpellID spellId)
{
bool match = false;
auto searchInList = [&](std::vector<SpellID>& list)
{
for (auto id : list)
{
if (static_cast<uint16>(spellId) == static_cast<uint16>(id))
{
auto spell = spell::GetSpell(id);
bool hasEnoughMP = spell->getMPCost() <= m_PMob->health.mp;
bool isNotInRecast = !m_PMob->PRecastContainer->Has(RECAST_MAGIC, static_cast<uint16>(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<uint16>(spellId));

return (match) ? std::optional<SpellID>(spellId) : std::nullopt;
return (isNotInRecast && hasEnoughMP) ? std::optional<SpellID>(spellId) : std::nullopt;
}

std::optional<SpellID> CMobSpellContainer::GetBestAvailable(SPELLFAMILY family)
Expand Down
8 changes: 7 additions & 1 deletion src/map/spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,14 @@ namespace spell
{
// cant cast cause im hidden or untargetable
if (PCaster->IsNameHidden() || static_cast<CMobEntity*>(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;
}
Expand Down

0 comments on commit f3550d4

Please sign in to comment.