Skip to content

Commit

Permalink
Fix: Chance to hit wasn't protected from becoming negative
Browse files Browse the repository at this point in the history
Manual merge of pull request #3550. Credit to @newfrenchy83.
  • Loading branch information
jyrkive committed Sep 23, 2018
1 parent 81ef9ea commit 79206d9
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/actions/attack.cpp
Expand Up @@ -157,21 +157,21 @@ battle_context_unit_stats::battle_context_unit_stats(const unit& u,
}

// Compute chance to hit.
chance_to_hit = opp.defense_modifier(resources::gameboard->map().get_terrain(opp_loc)) + weapon->accuracy()
signed int cth = opp.defense_modifier(resources::gameboard->map().get_terrain(opp_loc)) + weapon->accuracy()
- (opp_weapon ? opp_weapon->parry() : 0);

if(chance_to_hit > 100) {
chance_to_hit = 100;
}
cth = utils::clamp(cth, 0, 100);

unit_ability_list cth_specials = weapon->get_specials("chance_to_hit");
unit_abilities::effect cth_effects(cth_specials, chance_to_hit, backstab_pos);
chance_to_hit = cth_effects.get_composite_value();
unit_abilities::effect cth_effects(cth_specials, cth, backstab_pos);
cth = cth_effects.get_composite_value();

if(opp.get_state("invulnerable")) {
chance_to_hit = 0;
cth = 0;
}

chance_to_hit = utils::clamp(cth, 0, 100);

// Compute base damage done with the weapon.
int base_damage = weapon->modified_damage(backstab_pos);

Expand Down Expand Up @@ -306,13 +306,13 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type,
}

signed int cth = 100 - opp_terrain_defense + weapon->accuracy() - (opp_weapon ? opp_weapon->parry() : 0);
cth = std::min(100, cth);
cth = std::max(0, cth);
chance_to_hit = cth;
cth = utils::clamp(cth, 0, 100);

unit_ability_list cth_specials = weapon->get_specials("chance_to_hit");
unit_abilities::effect cth_effects(cth_specials, chance_to_hit, backstab_pos);
chance_to_hit = cth_effects.get_composite_value();
unit_abilities::effect cth_effects(cth_specials, cth, backstab_pos);
cth = cth_effects.get_composite_value();

chance_to_hit = utils::clamp(cth, 0, 100);

int base_damage = weapon->modified_damage(backstab_pos);
int damage_multiplier = 100;
Expand Down

0 comments on commit 79206d9

Please sign in to comment.