Skip to content

Commit

Permalink
Improve spell range checking
Browse files Browse the repository at this point in the history
This commit adds new member PlayerbotAI::m_spellRangeMap
which holds spell ranges for registered spells. Also CastSpell()
have been updated to use it.
  • Loading branch information
chelobaka committed Sep 16, 2010
1 parent 07f3705 commit 602064d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/game/playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,18 @@ uint32 PlayerbotAI::initSpell(uint32 spellId)
}
}
if (next == 0)
{
sLog.outDebug("initSpell: Found spellid: %u", spellId);

// Add spell to spellrange map
const SpellEntry* const pSpellInfo = sSpellStore.LookupEntry(spellId);
Spell *spell = new Spell(m_bot, pSpellInfo, false);
SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(pSpellInfo->rangeIndex);
float range = GetSpellMaxRange(srange, IsPositiveSpell(spellId));
m_bot->ApplySpellMod(spellId, SPELLMOD_RANGE, range, spell);
m_spellRangeMap.insert(std::pair<uint32,float>(spellId, range));
delete spell;
}
return (next == 0) ? spellId : next;
}

Expand Down Expand Up @@ -2331,13 +2342,14 @@ bool PlayerbotAI::CastSpell(uint32 spellId)
uint64 targetGUID = m_bot->GetSelection();
Unit* pTarget = ObjectAccessor::GetUnit(*m_bot, m_bot->GetSelection());

SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(pSpellInfo->rangeIndex);
float max_range = GetSpellMaxRange(srange, false);
float dist = m_bot->GetCombatDistance(pTarget);

if(dist > max_range)
return false;

// Check spell range
std::map<uint32, float>::iterator it = m_spellRangeMap.find(spellId);
if (it != m_spellRangeMap.end() && (int)it->second != 0)
{
float dist = m_bot->GetCombatDistance(pTarget);
if (dist > it->second + 1.25) // See Spell::CheckRange for modifier value
return false;
}

if (!pTarget)
pTarget = m_bot;
Expand Down
2 changes: 2 additions & 0 deletions src/game/playerbot/PlayerbotAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ class MANGOS_DLL_SPEC PlayerbotAI
Unit *m_targetProtect; // check

Unit *m_followTarget; // whom to follow in non combat situation?

std::map<uint32, float> m_spellRangeMap;
};

#endif

0 comments on commit 602064d

Please sign in to comment.