diff options
| author | QAston <qaston@gmail.com> | 2011-07-26 23:09:28 +0200 |
|---|---|---|
| committer | QAston <qaston@gmail.com> | 2011-07-26 23:09:28 +0200 |
| commit | b0fe236265465a0f39aa98a8cee2916d1ccfaa02 (patch) | |
| tree | 77ed4bde46de983c280a542d657a30b24865638c /src/server/game/AI/ScriptedAI | |
| parent | 29c228a80170e4264129d4e3bed4d2fc41aca5a7 (diff) | |
Core: Use new SpellInfo class in core. Sadly, this commit is not compatibile with some of the custom code. To make your code work again you may need to change:
*SpellEntry is now SpellInfo
*GetSpellProto is now GetSpellInfo
*SpellEntry::Effect*[effIndex] is now avalible under SpellInfo.Effects[effIndex].*
*sSpellStore.LookupEntry is no longer valid, use sSpellMgr->GetSpellInfo()
*SpellFunctions from SpellMgr.h like DoSpellStuff(spellId) are now: spellInfo->DoStuff()
*SpellMgr::CalculateEffectValue and similar functions are now avalible in SpellEffectInfo class.
*GET_SPELL macro is removed, code which used it is moved to SpellMgr::LoadDbcDataCorrections
*code which affected dbc data in SpellMgr::LoadSpellCustomAttr is now moved to LoadDbcDataCorrections
Diffstat (limited to 'src/server/game/AI/ScriptedAI')
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 43 | ||||
| -rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.h | 12 |
2 files changed, 20 insertions, 35 deletions
diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 470b4623ea2..84dad3a9b3f 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -164,7 +164,7 @@ void ScriptedAI::DoStopAttack() me->AttackStop(); } -void ScriptedAI::DoCastSpell(Unit* pTarget, SpellEntry const* pSpellInfo, bool bTriggered) +void ScriptedAI::DoCastSpell(Unit* pTarget, SpellInfo const* pSpellInfo, bool bTriggered) { if (!pTarget || me->IsNonMeleeSpellCasted(false)) return; @@ -192,7 +192,7 @@ Creature* ScriptedAI::DoSpawnCreature(uint32 entry, float offsetX, float offsetY return me->SummonCreature(entry, me->GetPositionX() + offsetX, me->GetPositionY() + offsetY, me->GetPositionZ() + offsetZ, angle, TempSummonType(type), despawntime); } -SpellEntry const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 mechanic, SelectTargetType targets, uint32 powerCostMin, uint32 powerCostMax, float rangeMin, float rangeMax, SelectEffect effects) +SpellInfo const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 mechanic, SelectTargetType targets, uint32 powerCostMin, uint32 powerCostMax, float rangeMin, float rangeMax, SelectEffect effects) { //No target so we can't cast if (!target) @@ -203,18 +203,18 @@ SpellEntry const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 me return false; //Using the extended script system we first create a list of viable spells - SpellEntry const* apSpell[CREATURE_MAX_SPELLS]; - memset(apSpell, 0, CREATURE_MAX_SPELLS * sizeof(SpellEntry*)); + SpellInfo const* apSpell[CREATURE_MAX_SPELLS]; + memset(apSpell, 0, CREATURE_MAX_SPELLS * sizeof(SpellInfo*)); uint32 spellCount = 0; - SpellEntry const* tempSpell = NULL; + SpellInfo const* tempSpell = NULL; SpellRangeEntry const* tempRange = NULL; //Check if each spell is viable(set it to null if not) for (uint32 i = 0; i < CREATURE_MAX_SPELLS; i++) { - tempSpell = sSpellStore.LookupEntry(me->m_spells[i]); + tempSpell = sSpellMgr->GetSpellInfo(me->m_spells[i]); //This spell doesn't exist if (!tempSpell) @@ -238,31 +238,24 @@ SpellEntry const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 me continue; //Make sure that the spell uses the requested amount of power - if (powerCostMin && tempSpell->manaCost < powerCostMin) + if (powerCostMin && tempSpell->ManaCost < powerCostMin) continue; - if (powerCostMax && tempSpell->manaCost > powerCostMax) + if (powerCostMax && tempSpell->ManaCost > powerCostMax) continue; //Continue if we don't have the mana to actually cast this spell - if (tempSpell->manaCost > me->GetPower(Powers(tempSpell->powerType))) - continue; - - //Get the Range - tempRange = GetSpellRangeStore()->LookupEntry(tempSpell->rangeIndex); - - //Spell has invalid range store so we can't use it - if (!tempRange) + if (tempSpell->ManaCost > me->GetPower(Powers(tempSpell->PowerType))) continue; //Check if the spell meets our range requirements - if (rangeMin && me->GetSpellMinRangeForTarget(target, tempRange) < rangeMin) + if (rangeMin && me->GetSpellMinRangeForTarget(target, tempSpell) < rangeMin) continue; - if (rangeMax && me->GetSpellMaxRangeForTarget(target, tempRange) > rangeMax) + if (rangeMax && me->GetSpellMaxRangeForTarget(target, tempSpell) > rangeMax) continue; //Check if our target is in range - if (me->IsWithinDistInMap(target, float(me->GetSpellMinRangeForTarget(target, tempRange))) || !me->IsWithinDistInMap(target, float(me->GetSpellMaxRangeForTarget(target, tempRange)))) + if (me->IsWithinDistInMap(target, float(me->GetSpellMinRangeForTarget(target, tempSpell))) || !me->IsWithinDistInMap(target, float(me->GetSpellMaxRangeForTarget(target, tempSpell)))) continue; //All good so lets add it to the spell list @@ -277,7 +270,7 @@ SpellEntry const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 me return apSpell[urand(0, spellCount - 1)]; } -bool ScriptedAI::CanCast(Unit* target, SpellEntry const* spell, bool triggered /*= false*/) +bool ScriptedAI::CanCast(Unit* target, SpellInfo const* spell, bool triggered /*= false*/) { //No target so we can't cast if (!target || !spell) @@ -288,17 +281,11 @@ bool ScriptedAI::CanCast(Unit* target, SpellEntry const* spell, bool triggered / return false; //Check for power - if (!triggered && me->GetPower(Powers(spell->powerType)) < spell->manaCost) - return false; - - SpellRangeEntry const* tempRange = GetSpellRangeStore()->LookupEntry(spell->rangeIndex); - - //Spell has invalid range store so we can't use it - if (!tempRange) + if (!triggered && me->GetPower(Powers(spell->PowerType)) < spell->ManaCost) return false; //Unit is out of range of this spell - if (me->IsInRange(target, float(me->GetSpellMinRangeForTarget(target, tempRange)), float(me->GetSpellMaxRangeForTarget(target, tempRange)))) + if (me->IsInRange(target, float(me->GetSpellMinRangeForTarget(target, spell)), float(me->GetSpellMaxRangeForTarget(target, spell)))) return false; return true; diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index b124f8d2fd6..e1de1fe091b 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -28,8 +28,6 @@ #define CAST_CRE(a) (dynamic_cast<Creature*>(a)) #define CAST_AI(a, b) (dynamic_cast<a*>(b)) -#define GET_SPELL(a) (const_cast<SpellEntry*>(GetSpellStore()->LookupEntry(a))) - class InstanceScript; class SummonList : public std::list<uint64> @@ -78,10 +76,10 @@ struct ScriptedAI : public CreatureAI void SummonedCreatureDespawn(Creature* /*summon*/) {} // Called when hit by a spell - void SpellHit(Unit* /*caster*/, SpellEntry const* /*spell*/) {} + void SpellHit(Unit* /*caster*/, SpellInfo const* /*spell*/) {} // Called when spell hits a target - void SpellHitTarget(Unit* /*target*/, SpellEntry const* /*spell*/) {} + void SpellHitTarget(Unit* /*target*/, SpellInfo const* /*spell*/) {} //Called at waypoint reached or PointMovement end void MovementInform(uint32 /*type*/, uint32 /*id*/) {} @@ -123,7 +121,7 @@ struct ScriptedAI : public CreatureAI void DoStopAttack(); //Cast spell by spell info - void DoCastSpell(Unit* target, SpellEntry const* spellInfo, bool triggered = false); + void DoCastSpell(Unit* target, SpellInfo const* spellInfo, bool triggered = false); //Plays a sound to all nearby players void DoPlaySoundToSet(WorldObject* source, uint32 soundId); @@ -160,10 +158,10 @@ struct ScriptedAI : public CreatureAI bool HealthAbovePct(uint32 pct) const { return me->HealthAbovePct(pct); } //Returns spells that meet the specified criteria from the creatures spell list - SpellEntry const* SelectSpell(Unit* target, uint32 school, uint32 mechanic, SelectTargetType targets, uint32 powerCostMin, uint32 powerCostMax, float rangeMin, float rangeMax, SelectEffect effect); + SpellInfo const* SelectSpell(Unit* target, uint32 school, uint32 mechanic, SelectTargetType targets, uint32 powerCostMin, uint32 powerCostMax, float rangeMin, float rangeMax, SelectEffect effect); //Checks if you can cast the specified spell - bool CanCast(Unit* target, SpellEntry const* spell, bool triggered = false); + bool CanCast(Unit* target, SpellInfo const* spell, bool triggered = false); void SetEquipmentSlots(bool loadDefault, int32 mainHand = EQUIP_NO_CHANGE, int32 offHand = EQUIP_NO_CHANGE, int32 ranged = EQUIP_NO_CHANGE); |
