[9243] Some spell rune code fixes

* Also replace check/take functions for runes by single 2 mode function
* Implement proper check for dead runes case
* Implement proper rune selection for Aura::HandleAuraConvertRune
This commit is contained in:
VladimirMangos 2010-01-23 20:04:19 +03:00
parent 546ee35953
commit bf9cccfd5b
4 changed files with 53 additions and 69 deletions

View file

@ -3712,7 +3712,7 @@ void Spell::TakePower()
if(powerType == POWER_RUNE)
{
TakeRunePower();
CheckOrTakeRunePower(true);
return;
}
@ -3723,7 +3723,7 @@ void Spell::TakePower()
m_caster->SetLastManaUse();
}
SpellCastResult Spell::CheckRuneCost(uint32 runeCostID)
SpellCastResult Spell::CheckOrTakeRunePower(bool take)
{
if(m_caster->GetTypeId() != TYPEID_PLAYER)
return SPELL_CAST_OK;
@ -3733,75 +3733,42 @@ SpellCastResult Spell::CheckRuneCost(uint32 runeCostID)
if(plr->getClass() != CLASS_DEATH_KNIGHT)
return SPELL_CAST_OK;
SpellRuneCostEntry const *src = sSpellRuneCostStore.LookupEntry(runeCostID);
SpellRuneCostEntry const *src = sSpellRuneCostStore.LookupEntry(m_spellInfo->runeCostID);
if(!src)
return SPELL_CAST_OK;
if(src->NoRuneCost())
if(src->NoRuneCost() && (!take || src->NoRunicPowerGain()))
return SPELL_CAST_OK;
int32 runeCost[NUM_RUNE_TYPES]; // blood, frost, unholy, death
for(uint32 i = 0; i < RUNE_DEATH; ++i)
runeCost[i] = src->RuneCost[i];
runeCost[RUNE_DEATH] = MAX_RUNES; // calculated later
for(uint32 i = 0; i < MAX_RUNES; ++i)
{
RuneType rune = plr->GetCurrentRune(i);
if((plr->GetRuneCooldown(i) == 0) && (runeCost[rune] > 0))
runeCost[rune]--;
}
for(uint32 i = 0; i < RUNE_DEATH; ++i)
if(runeCost[i] > 0)
runeCost[RUNE_DEATH] += runeCost[i];
if(runeCost[RUNE_DEATH] > MAX_RUNES)
return SPELL_FAILED_NO_POWER; // not sure if result code is correct
return SPELL_CAST_OK;
}
void Spell::TakeRunePower()
{
if(m_caster->GetTypeId() != TYPEID_PLAYER)
return;
Player *plr = (Player*)m_caster;
if(plr->getClass() != CLASS_DEATH_KNIGHT)
return;
SpellRuneCostEntry const *src = sSpellRuneCostStore.LookupEntry(m_spellInfo->runeCostID);
if(!src || (src->NoRuneCost() && src->NoRunicPowerGain()))
return;
m_runesState = plr->GetRunesState(); // store previous state
if (take)
m_runesState = plr->GetRunesState(); // store previous state
int32 runeCost[NUM_RUNE_TYPES]; // blood, frost, unholy, death
for(uint32 i = 0; i < RUNE_DEATH; ++i)
{
runeCost[i] = src->RuneCost[i];
}
runeCost[RUNE_DEATH] = 0; // calculated later
for(uint32 i = 0; i < MAX_RUNES; ++i)
{
RuneType rune = plr->GetCurrentRune(i);
if((plr->GetRuneCooldown(i) == 0) && (runeCost[rune] > 0))
if (runeCost[rune] <= 0)
continue;
if(plr->GetRuneCooldown(i) == 0)
{
plr->SetRuneCooldown(i, RUNE_COOLDOWN); // 5*2=10 sec
runeCost[rune]--;
if (take)
plr->SetRuneCooldown(i, RUNE_COOLDOWN); // 5*2=10 sec
--runeCost[rune];
}
}
runeCost[RUNE_DEATH] = runeCost[RUNE_BLOOD] + runeCost[RUNE_UNHOLY] + runeCost[RUNE_FROST];
for(uint32 i = 0; i < RUNE_DEATH; ++i)
if(runeCost[i] > 0)
runeCost[RUNE_DEATH] += runeCost[i];
if(runeCost[RUNE_DEATH] > 0)
{
@ -3810,19 +3777,32 @@ void Spell::TakeRunePower()
RuneType rune = plr->GetCurrentRune(i);
if((plr->GetRuneCooldown(i) == 0) && (rune == RUNE_DEATH))
{
plr->SetRuneCooldown(i, RUNE_COOLDOWN); // 5*2=10 sec
runeCost[rune]--;
plr->ConvertRune(i, plr->GetBaseRune(i));
if (take)
plr->SetRuneCooldown(i, RUNE_COOLDOWN); // 5*2=10 sec
--runeCost[rune];
if (take)
plr->ConvertRune(i, plr->GetBaseRune(i));
if(runeCost[RUNE_DEATH] == 0)
break;
}
}
}
// you can gain some runic power when use runes
float rp = src->runePowerGain;;
rp *= sWorld.getRate(RATE_POWER_RUNICPOWER_INCOME);
plr->ModifyPower(POWER_RUNIC_POWER, (int32)rp);
if(!take && runeCost[RUNE_DEATH] > 0)
return SPELL_FAILED_NO_POWER; // not sure if result code is correct
if(take)
{
// you can gain some runic power when use runes
float rp = src->runePowerGain;;
rp *= sWorld.getRate(RATE_POWER_RUNICPOWER_INCOME);
plr->ModifyPower(POWER_RUNIC_POWER, (int32)rp);
}
return SPELL_CAST_OK;
}
void Spell::TakeReagents()
@ -5385,7 +5365,7 @@ SpellCastResult Spell::CheckPower()
//check rune cost only if a spell has PowerType == POWER_RUNE
if(m_spellInfo->powerType == POWER_RUNE)
{
SpellCastResult failReason = CheckRuneCost(m_spellInfo->runeCostID);
SpellCastResult failReason = CheckOrTakeRunePower(false);
if(failReason != SPELL_CAST_OK)
return failReason;
}