mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Support for Mana Channeling ability.
This commit is contained in:
parent
5e40d3da72
commit
b4d0ebf9ab
@ -3376,6 +3376,14 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
|
||||
console->addText(dmgInfo); //todo: casualties (?)
|
||||
}
|
||||
waitForAnims();
|
||||
//mana absorption
|
||||
if (sc->manaGained)
|
||||
{
|
||||
Point leftHero = Point(15, 30) + pos;
|
||||
Point rightHero = Point(755, 30) + pos;
|
||||
addNewAnim(new CSpellEffectAnim(this, sc->side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero.x, leftHero.y, 0, 0, false));
|
||||
addNewAnim(new CSpellEffectAnim(this, sc->side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero.x, rightHero.y, 0, 0, false));
|
||||
}
|
||||
}
|
||||
|
||||
void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse)
|
||||
|
@ -1382,6 +1382,8 @@ struct BattleSpellCast : public CPackForClient//3009
|
||||
ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
|
||||
ui32 id; //id of spell
|
||||
ui8 skill; //caster's skill level
|
||||
ui8 spellCost;
|
||||
ui8 manaGained; //mana channeling ability
|
||||
THex tile; //destination tile (may not be set in some global/mass spells
|
||||
std::vector<ui32> resisted; //ids of creatures that resisted this spell
|
||||
std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
|
||||
@ -1389,7 +1391,7 @@ struct BattleSpellCast : public CPackForClient//3009
|
||||
ui8 castedByHero; //if true - spell has been casted by hero, otherwise by a creature
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & dmgToDisplay & side & id & skill & tile & resisted & affectedCres & attackerType & castedByHero;
|
||||
h & dmgToDisplay & side & id & skill & spellCost & manaGained & tile & resisted & affectedCres & attackerType & castedByHero;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1044,27 +1044,20 @@ DLL_EXPORT void StartAction::applyGs( CGameState *gs )
|
||||
DLL_EXPORT void BattleSpellCast::applyGs( CGameState *gs )
|
||||
{
|
||||
assert(gs->curB);
|
||||
CGHeroInstance *h = (side) ? gs->curB->heroes[1] : gs->curB->heroes[0];
|
||||
if(h && castedByHero)
|
||||
if (castedByHero)
|
||||
{
|
||||
int spellCost = 0;
|
||||
if(gs->curB)
|
||||
{
|
||||
spellCost = gs->curB->getSpellCost(VLC->spellh->spells[id], h);
|
||||
}
|
||||
else
|
||||
{
|
||||
spellCost = VLC->spellh->spells[id]->costs[skill];
|
||||
}
|
||||
h->mana -= spellCost;
|
||||
if (h->mana < 0)
|
||||
h->mana = 0;
|
||||
}
|
||||
if(side >= 0 && side < 2 && castedByHero)
|
||||
{
|
||||
gs->curB->castSpells[side]++;
|
||||
}
|
||||
CGHeroInstance * h = gs->curB->heroes[side];
|
||||
CGHeroInstance * enemy = gs->curB->heroes[1-side];
|
||||
|
||||
h->mana -= spellCost;
|
||||
amax(h->mana, 0);
|
||||
if (enemy && manaGained)
|
||||
enemy->mana += manaGained;
|
||||
if (side >= 0 && side < 2)
|
||||
{
|
||||
gs->curB->castSpells[side]++;
|
||||
}
|
||||
}
|
||||
|
||||
if(id == 35 || id == 78) //dispel and dispel helpful spells
|
||||
{
|
||||
|
@ -3496,6 +3496,26 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
|
||||
sc.dmgToDisplay = 0;
|
||||
sc.castedByHero = (bool)caster;
|
||||
sc.attackerType = (stack ? stack->type->idNumber : -1);
|
||||
sc.manaGained = 0;
|
||||
sc.spellCost = 0;
|
||||
|
||||
if (caster) //calculate spell cost
|
||||
{
|
||||
sc.spellCost = gs->curB->getSpellCost(VLC->spellh->spells[spellID], caster);
|
||||
|
||||
if (secHero && mode == SpellCasting::HERO_CASTING) //handle mana channel
|
||||
{
|
||||
int manaChannel = 0;
|
||||
BOOST_FOREACH(CStack * stack, gs->curB->stacks) //TODO: shouldn't bonus system handle it somehow?
|
||||
{
|
||||
if (stack->owner == secHero->tempOwner)
|
||||
{
|
||||
amax(manaChannel, stack->valOfBonuses(Bonus::MANA_CHANNELING));
|
||||
}
|
||||
}
|
||||
sc.manaGained = (manaChannel * sc.spellCost) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
//calculating affected creatures for all spells
|
||||
std::set<CStack*> attackedCres;
|
||||
|
Loading…
Reference in New Issue
Block a user