aboutsummaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorQAston <none@none>2009-07-23 18:32:32 +0200
committerQAston <none@none>2009-07-23 18:32:32 +0200
commit4a17224a652d2f87fdebdf7e572b7ce4da327336 (patch)
treee90262456ef36e3a062c236f39c9c03b6e9f16f2 /src/game
parent21ffe5f70adfaee9fb1567fb42d0e276e79b8ec7 (diff)
*Creature eventAI cancast power check - by smellbee.
--HG-- branch : trunk
Diffstat (limited to 'src/game')
-rw-r--r--src/game/CreatureEventAI.cpp3
-rw-r--r--src/game/Spell.cpp72
-rw-r--r--src/game/Spell.h1
-rw-r--r--src/game/SpellMgr.cpp64
-rw-r--r--src/game/SpellMgr.h2
5 files changed, 70 insertions, 72 deletions
diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp
index b9b3d5bb488..6e8ac6a4909 100644
--- a/src/game/CreatureEventAI.cpp
+++ b/src/game/CreatureEventAI.cpp
@@ -30,6 +30,7 @@
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "InstanceData.h"
+#include "SpellMgr.h"
bool CreatureEventAIHolder::UpdateRepeatTimer( Creature* creature, uint32 repeatMin, uint32 repeatMax )
{
@@ -1297,7 +1298,7 @@ bool CreatureEventAI::CanCast(Unit* Target, SpellEntry const *Spell, bool Trigge
return false;
//Check for power
- if (!Triggered && me->GetPower((Powers)Spell->powerType) < Spell->manaCost)
+ if (!Triggered && me->GetPower((Powers)Spell->powerType) < CalculatePowerCost(Spell, me, GetSpellSchoolMask(Spell)))
return false;
SpellRangeEntry const *TempRange = NULL;
diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp
index 090749b32db..8f47a8252d4 100644
--- a/src/game/Spell.cpp
+++ b/src/game/Spell.cpp
@@ -2621,8 +2621,8 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect* triggeredByAura
}
}
- // Fill cost data
- m_powerCost = CalculatePowerCost();
+ // Fill cost data (not use power for item casts
+ m_powerCost = m_CastItem ? 0 : CalculatePowerCost(m_spellInfo, m_caster, m_spellSchoolMask);
SpellCastResult result = CheckCast(true);
if(result != SPELL_CAST_OK && !IsAutoRepeat()) //always cast autorepeat dummy for triggering
@@ -5348,74 +5348,6 @@ SpellCastResult Spell::CheckRange(bool strict)
return SPELL_CAST_OK;
}
-int32 Spell::CalculatePowerCost()
-{
- // item cast not used power
- if(m_CastItem)
- return 0;
-
- // Spell drain all exist power on cast (Only paladin lay of Hands)
- if (m_spellInfo->AttributesEx & SPELL_ATTR_EX_DRAIN_ALL_POWER)
- {
- // If power type - health drain all
- if (m_spellInfo->powerType == POWER_HEALTH)
- return m_caster->GetHealth();
- // Else drain all power
- if (m_spellInfo->powerType < MAX_POWERS)
- return m_caster->GetPower(Powers(m_spellInfo->powerType));
- sLog.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo->powerType, m_spellInfo->Id);
- return 0;
- }
-
- // Base powerCost
- int32 powerCost = m_spellInfo->manaCost;
- // PCT cost from total amount
- if (m_spellInfo->ManaCostPercentage)
- {
- switch (m_spellInfo->powerType)
- {
- // health as power used
- case POWER_HEALTH:
- powerCost += m_spellInfo->ManaCostPercentage * m_caster->GetCreateHealth() / 100;
- break;
- case POWER_MANA:
- powerCost += m_spellInfo->ManaCostPercentage * m_caster->GetCreateMana() / 100;
- break;
- case POWER_RAGE:
- case POWER_FOCUS:
- case POWER_ENERGY:
- case POWER_HAPPINESS:
- powerCost += m_spellInfo->ManaCostPercentage * m_caster->GetMaxPower(Powers(m_spellInfo->powerType)) / 100;
- break;
- case POWER_RUNE:
- case POWER_RUNIC_POWER:
- sLog.outDebug("Spell::CalculateManaCost: Not implemented yet!");
- break;
- default:
- sLog.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo->powerType, m_spellInfo->Id);
- return 0;
- }
- }
- SpellSchools school = GetFirstSchoolInMask(m_spellSchoolMask);
- // Flat mod from caster auras by spell school
- powerCost += m_caster->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER + school);
- // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
- if ( m_spellInfo->AttributesEx4 & SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST )
- powerCost += m_caster->GetAttackTime(OFF_ATTACK)/100;
- // Apply cost mod by spell
- if(Player* modOwner = m_caster->GetSpellModOwner())
- modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_COST, powerCost, this);
-
- if(m_spellInfo->Attributes & SPELL_ATTR_LEVEL_DAMAGE_CALCULATION)
- powerCost = int32(powerCost/ (1.117f* m_spellInfo->spellLevel / m_caster->getLevel() -0.1327f));
-
- // PCT mod from user auras by school
- powerCost = int32(powerCost * (1.0f+m_caster->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER+school)));
- if (powerCost < 0)
- powerCost = 0;
- return powerCost;
-}
-
SpellCastResult Spell::CheckPower()
{
// item cast not used power
diff --git a/src/game/Spell.h b/src/game/Spell.h
index 51a2b91e63e..1f4086280f0 100644
--- a/src/game/Spell.h
+++ b/src/game/Spell.h
@@ -390,7 +390,6 @@ class Spell
SpellCastResult CheckCasterAuras() const;
int32 CalculateDamage(uint8 i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
- int32 CalculatePowerCost();
bool HaveTargetsForEffect(uint8 effect) const;
void Delayed();
diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp
index 0a7c436bb00..7b4da07988e 100644
--- a/src/game/SpellMgr.cpp
+++ b/src/game/SpellMgr.cpp
@@ -342,6 +342,70 @@ bool IsHigherHankOfSpell(uint32 spellId_1, uint32 spellId_2)
return spellmgr.GetSpellRank(spellId_1)<spellmgr.GetSpellRank(spellId_2);
}
+uint32 CalculatePowerCost(SpellEntry const * spellInfo, Unit const * caster, SpellSchoolMask schoolMask)
+{
+ // Spell drain all exist power on cast (Only paladin lay of Hands)
+ if (spellInfo->AttributesEx & SPELL_ATTR_EX_DRAIN_ALL_POWER)
+ {
+ // If power type - health drain all
+ if (spellInfo->powerType == POWER_HEALTH)
+ return caster->GetHealth();
+ // Else drain all power
+ if (spellInfo->powerType < MAX_POWERS)
+ return caster->GetPower(Powers(spellInfo->powerType));
+ sLog.outError("CalculateManaCost: Unknown power type '%d' in spell %d", spellInfo->powerType, spellInfo->Id);
+ return 0;
+ }
+
+ // Base powerCost
+ int32 powerCost = spellInfo->manaCost;
+ // PCT cost from total amount
+ if (spellInfo->ManaCostPercentage)
+ {
+ switch (spellInfo->powerType)
+ {
+ // health as power used
+ case POWER_HEALTH:
+ powerCost += spellInfo->ManaCostPercentage * caster->GetCreateHealth() / 100;
+ break;
+ case POWER_MANA:
+ powerCost += spellInfo->ManaCostPercentage * caster->GetCreateMana() / 100;
+ break;
+ case POWER_RAGE:
+ case POWER_FOCUS:
+ case POWER_ENERGY:
+ case POWER_HAPPINESS:
+ powerCost += spellInfo->ManaCostPercentage * caster->GetMaxPower(Powers(spellInfo->powerType)) / 100;
+ break;
+ case POWER_RUNE:
+ case POWER_RUNIC_POWER:
+ sLog.outDebug("CalculateManaCost: Not implemented yet!");
+ break;
+ default:
+ sLog.outError("CalculateManaCost: Unknown power type '%d' in spell %d", spellInfo->powerType, spellInfo->Id);
+ return 0;
+ }
+ }
+ SpellSchools school = GetFirstSchoolInMask(schoolMask);
+ // Flat mod from caster auras by spell school
+ powerCost += caster->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER + school);
+ // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
+ if ( spellInfo->AttributesEx4 & SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST )
+ powerCost += caster->GetAttackTime(OFF_ATTACK)/100;
+ // Apply cost mod by spell
+ if(Player* modOwner = caster->GetSpellModOwner())
+ modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_COST, powerCost);
+
+ if(spellInfo->Attributes & SPELL_ATTR_LEVEL_DAMAGE_CALCULATION)
+ powerCost = int32(powerCost/ (1.117f* spellInfo->spellLevel / caster->getLevel() -0.1327f));
+
+ // PCT mod from user auras by school
+ powerCost = int32(powerCost * (1.0f+caster->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER+school)));
+ if (powerCost < 0)
+ powerCost = 0;
+ return powerCost;
+}
+
SpellSpecific GetSpellSpecific(uint32 spellId)
{
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h
index ec602682a50..8315fdc2965 100644
--- a/src/game/SpellMgr.h
+++ b/src/game/SpellMgr.h
@@ -240,6 +240,8 @@ bool IsSingleFromSpellSpecificPerTarget(uint32 spellSpec1, uint32 spellSpec2);
bool IsPassiveSpell(uint32 spellId);
bool IsAutocastableSpell(uint32 spellId);
+uint32 CalculatePowerCost(SpellEntry const * spellInfo, Unit const * caster, SpellSchoolMask schoolMask);
+
inline bool IsPassiveSpellStackableWithRanks(SpellEntry const* spellProto)
{
if(!IsPassiveSpell(spellProto->Id))