1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Add TERMINATOR ability support, small fixes

This commit is contained in:
Dydzio
2017-09-09 21:01:12 +02:00
parent 7cbd9acd67
commit 3eef689005
4 changed files with 44 additions and 5 deletions

View File

@@ -5418,6 +5418,38 @@ void CGameHandler::handleAfterAttackCasting(const BattleAttack & bat)
sendAndApply(&victimInfo);
sendAndApply(&resurrectInfo);
}
if(attacker->hasBonusOfType(Bonus::TERMINATOR, 0) || attacker->hasBonusOfType(Bonus::TERMINATOR, 1))
{
double chanceToTrigger = 0;
int amountToDie = 0;
if(attacker->hasBonusOfType(Bonus::TERMINATOR, 0)) //killing by percentage
{
chanceToTrigger = attacker->valOfBonuses(Bonus::TERMINATOR, 0) / 100.0f;
int percentageToDie = attacker->getBonus(Selector::type(Bonus::TERMINATOR).And(Selector::subtype(0)))->additionalInfo;
amountToDie = defender->getCount() * (percentageToDie / 100.0);
}
else if(attacker->hasBonusOfType(Bonus::TERMINATOR, 1)) //killing by count
{
chanceToTrigger = attacker->valOfBonuses(Bonus::TERMINATOR, 1) / 100.0f;
amountToDie = attacker->getBonus(Selector::type(Bonus::TERMINATOR).And(Selector::subtype(1)))->additionalInfo;
}
vstd::amin(chanceToTrigger, 1); //cap trigger chance at 100%
if(getRandomGenerator().getDoubleRange(0, 1)() > chanceToTrigger)
return;
BattleStackAttacked bsa;
bsa.attackerID = -1;
bsa.stackAttacked = defender->ID;
bsa.damageAmount = amountToDie * defender->getCreature()->MaxHealth();
bsa.flags = BattleStackAttacked::SPELL_EFFECT;
bsa.spellID = SpellID::SLAYER;
attacker->prepareAttacked(bsa, getRandomGenerator());
sendAndApply(&bsa);
}
}
void CGameHandler::visitObjectOnTile(const TerrainTile &t, const CGHeroInstance * h)