From d8615b2f14ee4025e64a7b7ce979feb120960bfb Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 5 Aug 2018 11:00:43 +0200 Subject: [PATCH] Changes stun icon and fixes some syntax reports from codacy --- src/monster.c | 2 +- src/stats.c | 56 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/monster.c b/src/monster.c index e41784d..1a3f666 100644 --- a/src/monster.c +++ b/src/monster.c @@ -52,7 +52,7 @@ monster_set_sprite_clip_for_current_state(Monster *m) m->stateIndicator.sprite->clip = CLIP16(16 * 10, 16 * 4); break; case STUNNED: - m->stateIndicator.sprite->clip = CLIP16(16 * 13, 16 * 3); + m->stateIndicator.sprite->clip = CLIP16(16 * 10, 16 * 1); break; case SCANNING: m->stateIndicator.sprite->clip = CLIP16(16 * 13, 16 * 4); diff --git a/src/stats.c b/src/stats.c index 263e0f9..f713abc 100644 --- a/src/stats.c +++ b/src/stats.c @@ -27,31 +27,51 @@ #include "util.h" #include "defines.h" +static int +get_attack_roll(Stats *attacker) +{ + int roll; + int firstRoll = get_random(19) + 1; + int secondRoll = get_random(19) + 1; + + if (attacker->advantage) + roll = max(firstRoll, secondRoll); + else if (attacker->disadvantage) + roll = min(firstRoll, secondRoll); + else + roll = firstRoll; + + return roll + attacker->atk; +} + +static int +get_defence_roll(Stats *defender) +{ + int roll; + int firstRoll = get_random(19) + 1; + int secondRoll = get_random(19) + 1; + + if (defender->advantage) + roll = max(firstRoll, secondRoll); + else if (defender->disadvantage) + roll = min(firstRoll, secondRoll); + else + roll = firstRoll; + + return roll + defender->def; +} + unsigned int stats_fight(Stats *attacker, Stats *defender) { - int atkRoll, defRoll, dmgRoll; bool critical = false; - if (attacker->advantage) - atkRoll = max(get_random(19), get_random(19)) + 1; - else if (attacker->disadvantage) - atkRoll = min(get_random(19), get_random(19)) + 1; - else - atkRoll = get_random(19) + 1; - - if (atkRoll == 20) + int atkRoll = get_attack_roll(attacker); + if (atkRoll - attacker->atk == 20) critical = true; - atkRoll += attacker->atk; - - if (defender->advantage) - defRoll = max(get_random(19), get_random(19)) + 1 + defender->def; - else if (defender->disadvantage) - defRoll = min(get_random(19), get_random(19)) + 1 + defender->def; - else - defRoll = get_random(19) + 1 + defender->def; - dmgRoll = 0; + int defRoll = get_defence_roll(defender); + int dmgRoll = 0; if (atkRoll >= defRoll) { if (attacker->dmg > 0) dmgRoll = get_random(attacker->dmg) + 1;