From 830fb46b6db9cc3a5c6f0f05ea8e39ae7f54af37 Mon Sep 17 00:00:00 2001 From: Habu Date: Fri, 1 Oct 2021 22:17:08 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20=E9=9D=92=E9=AD=94=E6=B3=95?= =?utf8?q?=E3=81=AE=E5=A4=B1=E6=95=97=E7=8E=87=E3=81=AE=E8=A8=88=E7=AE=97?= =?utf8?q?=E3=82=92=E5=85=B1=E9=80=9A=E5=8C=96=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 青魔法の失敗率の計算が魔法リスト一覧表示用と実際の使用時用で別々に実装 されている。シンプルに良くないので魔法リスト一覧表示用でリファクタリング された関数を実際の使用時にも使用するようにする。 また、関数の先頭ですべての変数を宣言する悪しき習慣が残っていたので必要な 時になってからの宣言に変更しておく。 --- src/blue-magic/learnt-power-getter.cpp | 2 +- src/blue-magic/learnt-power-getter.h | 2 ++ src/mind/mind-blue-mage.cpp | 43 +++++++--------------------------- 3 files changed, 11 insertions(+), 36 deletions(-) diff --git a/src/blue-magic/learnt-power-getter.cpp b/src/blue-magic/learnt-power-getter.cpp index 9eab51d29..56204ab48 100644 --- a/src/blue-magic/learnt-power-getter.cpp +++ b/src/blue-magic/learnt-power-getter.cpp @@ -250,7 +250,7 @@ static bool switch_blue_magic_choice(char key, int &menu_line, const bluemage_da * @param need_mana 青魔法を使うのに必要なMP * @return int 失敗率(%)を返す */ -static int calculate_blue_magic_failure_probability(player_type *player_ptr, const monster_power &mp, int need_mana) +int calculate_blue_magic_failure_probability(player_type *player_ptr, const monster_power &mp, int need_mana) { auto chance = mp.fail; if (player_ptr->lev > mp.level) { diff --git a/src/blue-magic/learnt-power-getter.h b/src/blue-magic/learnt-power-getter.h index 4b0698a8f..b4740b523 100644 --- a/src/blue-magic/learnt-power-getter.h +++ b/src/blue-magic/learnt-power-getter.h @@ -10,4 +10,6 @@ enum class RF_ABILITY; struct player_type; +struct monster_power; +int calculate_blue_magic_failure_probability(player_type *player_ptr, const monster_power &mp, int need_mana); std::optional get_learned_power(player_type *player_ptr); diff --git a/src/mind/mind-blue-mage.cpp b/src/mind/mind-blue-mage.cpp index c85e31248..c57056655 100644 --- a/src/mind/mind-blue-mage.cpp +++ b/src/mind/mind-blue-mage.cpp @@ -31,13 +31,6 @@ */ bool do_cmd_cast_learned(player_type *player_ptr) { - PERCENTAGE chance; - PERCENTAGE minfail = 0; - PLAYER_LEVEL plev = player_ptr->lev; - monster_power spell; - bool cast; - MANA_POINT need_mana; - if (cmd_limit_confused(player_ptr)) return false; @@ -46,8 +39,8 @@ bool do_cmd_cast_learned(player_type *player_ptr) return false; } - spell = monster_powers.at(selected_spell.value()); - need_mana = mod_need_mana(player_ptr, spell.smana, 0, REALM_NONE); + const auto &spell = monster_powers.at(selected_spell.value()); + const auto need_mana = mod_need_mana(player_ptr, spell.smana, 0, REALM_NONE); if (need_mana > player_ptr->csp) { msg_print(_("MPが足りません。", "You do not have enough mana to use this power.")); if (!over_exert) @@ -57,42 +50,22 @@ bool do_cmd_cast_learned(player_type *player_ptr) return false; } - chance = spell.fail; - if (plev > spell.level) - chance -= 3 * (plev - spell.level); - else - chance += (spell.level - plev); - - chance -= 3 * (adj_mag_stat[player_ptr->stat_index[A_INT]] - 1); - chance = mod_spell_chance_1(player_ptr, chance); - if (need_mana > player_ptr->csp) { - chance += 5 * (need_mana - player_ptr->csp); - } - - minfail = adj_mag_fail[player_ptr->stat_index[A_INT]]; - if (chance < minfail) - chance = minfail; + const auto chance = calculate_blue_magic_failure_probability(player_ptr, spell, need_mana); - auto player_stun = player_ptr->effects()->stun(); - chance += player_stun->get_magic_chance_penalty(); - if (chance > 95) { - chance = 95; - } - - chance = mod_spell_chance_2(player_ptr, chance); if (randint0(100) < chance) { if (flush_failure) flush(); msg_print(_("魔法をうまく唱えられなかった。", "You failed to concentrate hard enough!")); sound(SOUND_FAIL); - if (RF_ABILITY_SUMMON_MASK.has(selected_spell.value())) - cast = cast_learned_spell(player_ptr, selected_spell.value(), false); + if (RF_ABILITY_SUMMON_MASK.has(selected_spell.value())) { + cast_learned_spell(player_ptr, selected_spell.value(), false); + } } else { sound(SOUND_ZAP); - cast = cast_learned_spell(player_ptr, selected_spell.value(), true); - if (!cast) + if (!cast_learned_spell(player_ptr, selected_spell.value(), true)) { return false; + } } if (need_mana <= player_ptr->csp) { -- 2.11.0