Skip to content

Commit

Permalink
[Refactor] hengband#1498 Replaced direct fail-rate calculation to dec…
Browse files Browse the repository at this point in the history
…rease_chance()
  • Loading branch information
Hourier committed Sep 18, 2021
1 parent 7b3561d commit 7f8096b
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 103 deletions.
10 changes: 4 additions & 6 deletions src/blue-magic/learnt-power-getter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,11 @@ static void calculate_blue_magic_success_probability(player_type *player_ptr, le
if (lm_ptr->chance < minfail)
lm_ptr->chance = minfail;

if (player_ptr->stun > 50)
lm_ptr->chance += 25;
else if (player_ptr->stun)
lm_ptr->chance += 15;

if (lm_ptr->chance > 95)
auto player_stun = player_ptr->effects()->stun();
lm_ptr->chance += player_stun->decrease_chance();
if (lm_ptr->chance > 95) {
lm_ptr->chance = 95;
}

lm_ptr->chance = mod_spell_chance_2(player_ptr, lm_ptr->chance);
}
Expand Down
24 changes: 8 additions & 16 deletions src/cmd-action/cmd-mane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,11 @@ static int get_mane_power(player_type *player_ptr, int *sn, bool baigaesi)
if (chance < minfail)
chance = minfail;

/* Stunning makes spells harder */
if (player_ptr->stun > 50)
chance += 25;
else if (player_ptr->stun)
chance += 15;

/* Always a 5 percent chance of working */
if (chance > 95)
auto player_stun = player_ptr->effects()->stun();
chance += player_stun->decrease_chance();
if (chance > 95) {
chance = 95;
}

/* Get info */
mane_info(player_ptr, comment, player_ptr->mane_spell[i], (baigaesi ? player_ptr->mane_dam[i] * 2 : player_ptr->mane_dam[i]));
Expand Down Expand Up @@ -1116,15 +1112,11 @@ bool do_cmd_mane(player_type *player_ptr, bool baigaesi)
if (chance < minfail)
chance = minfail;

/* Stunning makes spells harder */
if (player_ptr->stun > 50)
chance += 25;
else if (player_ptr->stun)
chance += 15;

/* Always a 5 percent chance of working */
if (chance > 95)
auto player_stun = player_ptr->effects()->stun();
chance += player_stun->decrease_chance();
if (chance > 95) {
chance = 95;
}

/* Failed spell */
if (randint0(100) < chance) {
Expand Down
6 changes: 2 additions & 4 deletions src/cmd-action/cmd-mind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,8 @@ static void decide_mind_chance(player_type *player_ptr, cm_type *cm_ptr)
if (cm_ptr->chance < cm_ptr->minfail)
cm_ptr->chance = cm_ptr->minfail;

if (player_ptr->stun > 50)
cm_ptr->chance += 25;
else if (player_ptr->stun)
cm_ptr->chance += 15;
auto player_stun = player_ptr->effects()->stun();
cm_ptr->chance += player_stun->decrease_chance();

if (cm_ptr->use_mind != mind_kind_type::KI)
return;
Expand Down
22 changes: 8 additions & 14 deletions src/cmd-item/cmd-magiceat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,11 @@ static OBJECT_SUBTYPE_VALUE select_magic_eater(player_type *player_ptr, bool onl
}
chance = mod_spell_chance_1(player_ptr, chance);
chance = MAX(chance, adj_mag_fail[player_ptr->stat_index[mp_ptr->spell_stat]]);
/* Stunning makes spells harder */
if (player_ptr->stun > 50)
chance += 25;
else if (player_ptr->stun)
chance += 15;

if (chance > 95)
auto player_stun = player_ptr->effects()->stun();
chance += player_stun->decrease_chance();
if (chance > 95) {
chance = 95;
}

chance = mod_spell_chance_2(player_ptr, chance);

Expand Down Expand Up @@ -532,14 +529,11 @@ bool do_cmd_magic_eater(player_type *player_ptr, bool only_browse, bool powerful
}
chance = mod_spell_chance_1(player_ptr, chance);
chance = MAX(chance, adj_mag_fail[player_ptr->stat_index[mp_ptr->spell_stat]]);
/* Stunning makes spells harder */
if (player_ptr->stun > 50)
chance += 25;
else if (player_ptr->stun)
chance += 15;

if (chance > 95)
auto player_stun = player_ptr->effects()->stun();
chance += player_stun->decrease_chance();
if (chance > 95) {
chance = 95;
}

chance = mod_spell_chance_2(player_ptr, chance);

Expand Down
10 changes: 4 additions & 6 deletions src/mind/mind-blue-mage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ bool do_cmd_cast_learned(player_type *player_ptr)
if (chance < minfail)
chance = minfail;

if (player_ptr->stun > 50)
chance += 25;
else if (player_ptr->stun)
chance += 15;

if (chance > 95)
auto player_stun = player_ptr->effects()->stun();
chance += player_stun->decrease_chance();
if (chance > 95) {
chance = 95;
}

chance = mod_spell_chance_2(player_ptr, chance);
const auto spell_type = i2enum<RF_ABILITY>(n);
Expand Down
7 changes: 2 additions & 5 deletions src/mind/mind-elementalist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,8 @@ static PERCENTAGE decide_element_chance(player_type *player_ptr, mind_type spell
if (chance < minfail)
chance = minfail;

if (player_ptr->stun > 50)
chance += 25;
else if (player_ptr->stun)
chance += 15;

auto player_stun = player_ptr->effects()->stun();
chance += player_stun->decrease_chance();
if (heavy_armor(player_ptr))
chance += 5;

Expand Down
8 changes: 2 additions & 6 deletions src/mind/mind-power-getter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,8 @@ void MindPowerGetter::calculate_mind_chance(bool *has_weapon)
this->chance = minfail;
}

if (this->player_ptr->stun > 50) {
this->chance += 25;
} else if (this->player_ptr->stun) {
this->chance += 15;
}

auto player_stun = this->player_ptr->effects()->stun();
this->chance += player_stun->decrease_chance();
add_ki_chance();
if (this->chance > 95) {
this->chance = 95;
Expand Down
10 changes: 4 additions & 6 deletions src/spell/spell-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,11 @@ PERCENTAGE spell_chance(player_type *player_ptr, SPELL_IDX spell, int16_t use_re
if (chance < minfail)
chance = minfail;

if (player_ptr->stun > 50)
chance += 25;
else if (player_ptr->stun)
chance += 15;

if (chance > 95)
auto player_stun = player_ptr->effects()->stun();
chance += player_stun->decrease_chance();
if (chance > 95) {
chance = 95;
}

if ((use_realm == player_ptr->realm1) || (use_realm == player_ptr->realm2) || (player_ptr->pclass == CLASS_SORCERER)
|| (player_ptr->pclass == CLASS_RED_MAGE)) {
Expand Down
40 changes: 6 additions & 34 deletions src/status/bad-status-setter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,47 +383,19 @@ bool set_slow(player_type *player_ptr, TIME_EFFECT v, bool do_dec)
*/
bool set_stun(player_type *player_ptr, TIME_EFFECT v)
{
int old_aux, new_aux;
bool notice = false;
v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
if (player_ptr->is_dead)
return false;
if (PlayerRace(player_ptr).equals(player_race_type::GOLEM) || PlayerClass(player_ptr).can_resist_stun())
v = 0;

if (player_ptr->stun > 100) {
old_aux = 3;
} else if (player_ptr->stun > 50) {
old_aux = 2;
} else if (player_ptr->stun > 0) {
old_aux = 1;
} else {
old_aux = 0;
}

if (v > 100) {
new_aux = 3;
} else if (v > 50) {
new_aux = 2;
} else if (v > 0) {
new_aux = 1;
} else {
new_aux = 0;
}

auto player_stun = player_ptr->effects()->stun();
auto old_aux = player_stun->get_rank();
auto new_aux = player_stun->get_rank(v);
if (new_aux > old_aux) {
switch (new_aux) {
case 1:
msg_print(_("意識がもうろうとしてきた。", "You have been stunned."));
break;
case 2:
msg_print(_("意識がひどくもうろうとしてきた。", "You have been heavily stunned."));
break;
case 3:
msg_print(_("頭がクラクラして意識が遠のいてきた。", "You have been knocked out."));
break;
}

auto stun_mes = player_stun->get_stun_mes(new_aux);
msg_print(stun_mes.data());
if (randint1(1000) < v || one_in_(16)) {
msg_print(_("割れるような頭痛がする。", "A vicious blow hits your head."));

Expand Down Expand Up @@ -461,7 +433,7 @@ bool set_stun(player_type *player_ptr, TIME_EFFECT v)

notice = true;
} else if (new_aux < old_aux) {
if (new_aux == 0) {
if (new_aux == StunRank::NONE) {
msg_print(_("やっと朦朧状態から回復した。", "You are no longer stunned."));
if (disturb_state)
disturb(player_ptr, false, false);
Expand Down
10 changes: 4 additions & 6 deletions src/window/display-sub-window-spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,11 @@ static void display_spell_list(player_type *player_ptr)
if (chance < minfail)
chance = minfail;

if (player_ptr->stun > 50)
chance += 25;
else if (player_ptr->stun)
chance += 15;

if (chance > 95)
auto player_stun = player_ptr->effects()->stun();
chance += player_stun->decrease_chance();
if (chance > 95) {
chance = 95;
}

mindcraft_info(player_ptr, comment, use_mind, i);
sprintf(psi_desc, " %c) %-30s%2d %4d %3d%%%s", I2A(i), spell.name, spell.min_lev, spell.mana_cost, chance, comment);
Expand Down

0 comments on commit 7f8096b

Please sign in to comment.