mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Merge and simplify resistance calculation
This commit is contained in:
parent
7cf64a0628
commit
b6b12ad8f6
@ -723,39 +723,6 @@ const CGHeroInstance * BattleInfo::getHero( PlayerColor player ) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ui32> BattleInfo::calculateResistedStacks(const CSpell * sp, const CGHeroInstance * caster, const CGHeroInstance * hero2,
|
|
||||||
const std::vector<const CStack*> & affectedCreatures, PlayerColor casterSideOwner, ECastingMode::ECastingMode mode,
|
|
||||||
int usedSpellPower, int spellLevel, CRandomGenerator & rand) const
|
|
||||||
{
|
|
||||||
std::vector<ui32> ret;
|
|
||||||
for(auto & affectedCreature : affectedCreatures)
|
|
||||||
{
|
|
||||||
//non-negative spells should always succeed, unless immune
|
|
||||||
if(!sp->isNegative())// && (*it)->owner == casterSideOwner)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/*
|
|
||||||
const CGHeroInstance * bonusHero; //hero we should take bonuses from
|
|
||||||
if((*it)->owner == casterSideOwner)
|
|
||||||
bonusHero = caster;
|
|
||||||
else
|
|
||||||
bonusHero = hero2;*/
|
|
||||||
|
|
||||||
int prob = (affectedCreature)->magicResistance(); //probability of resistance in %
|
|
||||||
|
|
||||||
if(prob > 100) prob = 100;
|
|
||||||
|
|
||||||
//immunity from resistance
|
|
||||||
if(rand.nextInt(99) < prob)
|
|
||||||
{
|
|
||||||
ret.push_back((affectedCreature)->ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayerColor BattleInfo::theOtherPlayer(PlayerColor player) const
|
PlayerColor BattleInfo::theOtherPlayer(PlayerColor player) const
|
||||||
{
|
{
|
||||||
return sides[!whatSide(player)].color;
|
return sides[!whatSide(player)].color;
|
||||||
|
@ -144,8 +144,6 @@ struct DLL_LINKAGE BattleInfo : public CBonusSystemNode, public CBattleInfoCallb
|
|||||||
|
|
||||||
const CGHeroInstance * getHero(PlayerColor player) const; //returns fighting hero that belongs to given player
|
const CGHeroInstance * getHero(PlayerColor player) const; //returns fighting hero that belongs to given player
|
||||||
|
|
||||||
std::vector<ui32> calculateResistedStacks(const CSpell * sp, const CGHeroInstance * caster, const CGHeroInstance * hero2, const std::vector<const CStack*> & affectedCreatures, PlayerColor casterSideOwner, ECastingMode::ECastingMode mode, int usedSpellPower, int spellLevel, CRandomGenerator & rand) const;
|
|
||||||
|
|
||||||
const CStack * battleGetStack(BattleHex pos, bool onlyAlive); //returns stack at given tile
|
const CStack * battleGetStack(BattleHex pos, bool onlyAlive); //returns stack at given tile
|
||||||
const CGHeroInstance * battleGetOwner(const CStack * stack) const; //returns hero that owns given stack; nullptr if none
|
const CGHeroInstance * battleGetOwner(const CStack * stack) const; //returns hero that owns given stack; nullptr if none
|
||||||
void localInit();
|
void localInit();
|
||||||
|
@ -4059,7 +4059,19 @@ void CGameHandler::handleSpellCasting( SpellID spellID, int spellLvl, BattleHex
|
|||||||
}
|
}
|
||||||
|
|
||||||
//checking if creatures resist
|
//checking if creatures resist
|
||||||
sc.resisted = gs->curB->calculateResistedStacks(spell, caster, secHero, attackedCres, casterColor, mode, usedSpellPower, spellLvl, gs->getRandomGenerator());
|
//resistance is applied only to negative spells
|
||||||
|
if(spell->isNegative())
|
||||||
|
{
|
||||||
|
for(auto s : attackedCres)
|
||||||
|
{
|
||||||
|
const int prob = std::min((s)->magicResistance(), 100); //probability of resistance in %
|
||||||
|
|
||||||
|
if(gs->getRandomGenerator().nextInt(99) < prob)
|
||||||
|
{
|
||||||
|
sc.resisted.push_back(s->ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//calculating dmg to display
|
//calculating dmg to display
|
||||||
if (spellID == SpellID::DEATH_STARE || spellID == SpellID::ACID_BREATH_DAMAGE)
|
if (spellID == SpellID::DEATH_STARE || spellID == SpellID::ACID_BREATH_DAMAGE)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user