From 000cccbddb6a5beb18433ce64ddeb2a9763ac9c5 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Thu, 10 Mar 2022 17:49:53 +0900 Subject: [PATCH] [Refactor] #1642 Moved booze() and detonation() from QuaffExecution to QuaffEffects --- src/object-use/quaff/quaff-effects.cpp | 72 ++++++++++++++++++++++++++++++++ src/object-use/quaff/quaff-effects.h | 4 ++ src/object-use/quaff/quaff-execution.cpp | 65 +--------------------------- src/object-use/quaff/quaff-execution.h | 2 - 4 files changed, 78 insertions(+), 65 deletions(-) diff --git a/src/object-use/quaff/quaff-effects.cpp b/src/object-use/quaff/quaff-effects.cpp index f3128d217..c8e3283a9 100644 --- a/src/object-use/quaff/quaff-effects.cpp +++ b/src/object-use/quaff/quaff-effects.cpp @@ -1,9 +1,81 @@ #include "object-use/quaff/quaff-effects.h" +#include "avatar/avatar.h" #include "object/object-info.h" +#include "player-base/player-class.h" +#include "player/attack-defense-types.h" +#include "player/player-damage.h" +#include "player/player-status-flags.h" +#include "spell-kind/spells-floor.h" +#include "spell-kind/spells-teleport.h" +#include "status/bad-status-setter.h" +#include "status/base-status.h" #include "system/object-type-definition.h" #include "system/player-type-definition.h" +#include "util/bit-flags-calculator.h" +#include "view/display-messages.h" QuaffEffects::QuaffEffects(PlayerType *player_ptr) : player_ptr(player_ptr) { } + +/*! + * @brief 酔っ払いの薬 + * @param player_ptr プレイヤーへの参照ポインタ + * @return カオス耐性があるかその他の一部確率でFALSE、それ以外はTRUE + */ +bool QuaffEffects::booze() +{ + auto ident = false; + auto is_monk = PlayerClass(this->player_ptr).equals(PlayerClassType::MONK); + if (!is_monk) { + chg_virtue(this->player_ptr, V_HARMONY, -1); + } else if (!has_resist_conf(this->player_ptr)) { + set_bits(this->player_ptr->special_attack, ATTACK_SUIKEN); + } + + BadStatusSetter bss(this->player_ptr); + if (!has_resist_conf(this->player_ptr) && bss.confusion(randint0(20) + 15)) { + ident = true; + } + + if (has_resist_chaos(this->player_ptr)) { + return ident; + } + + if (one_in_(2) && bss.mod_hallucination(randint0(150) + 150)) { + ident = true; + } + + if (!is_monk || !one_in_(13)) { + return ident; + } + + ident = true; + if (one_in_(3)) { + lose_all_info(this->player_ptr); + } else { + wiz_dark(this->player_ptr); + } + + (void)teleport_player_aux(this->player_ptr, 100, false, i2enum(TELEPORT_NONMAGICAL | TELEPORT_PASSIVE)); + wiz_dark(this->player_ptr); + msg_print(_("知らない場所で目が醒めた。頭痛がする。", "You wake up somewhere with a sore head...")); + msg_print(_("何も思い出せない。どうやってここへ来たのかも分からない!", "You can't remember a thing or how you got here!")); + return ident; +} + +/*! + * @brief 爆発の薬の効果処理 / Fumble ramble + * @param player_ptr プレイヤーへの参照ポインタ + * @return 常にTRUE + */ +bool QuaffEffects::detonation() +{ + msg_print(_("体の中で激しい爆発が起きた!", "Massive explosions rupture your body!")); + take_hit(this->player_ptr, DAMAGE_NOESCAPE, damroll(50, 20), _("爆発の薬", "a potion of Detonation")); + BadStatusSetter bss(this->player_ptr); + (void)bss.mod_stun(75); + (void)bss.mod_cut(5000); + return true; +} diff --git a/src/object-use/quaff/quaff-effects.h b/src/object-use/quaff/quaff-effects.h index 6220a3aa5..f5f2fb9e2 100644 --- a/src/object-use/quaff/quaff-effects.h +++ b/src/object-use/quaff/quaff-effects.h @@ -5,6 +5,10 @@ class QuaffEffects { public: QuaffEffects(PlayerType *player_ptr); + // @todo switch/case文を移してくるまでの一時的なpublicメソッド. + bool booze(); + bool detonation(); + private: PlayerType *player_ptr; }; diff --git a/src/object-use/quaff/quaff-execution.cpp b/src/object-use/quaff/quaff-execution.cpp index 568f21261..b56995e37 100644 --- a/src/object-use/quaff/quaff-execution.cpp +++ b/src/object-use/quaff/quaff-execution.cpp @@ -148,7 +148,7 @@ void ObjectQuaffEntity::execute(INVENTORY_IDX item) break; case SV_POTION_BOOZE: - ident = booze(); + ident = QuaffEffects(this->player_ptr).booze(); break; case SV_POTION_SLEEP: if (this->player_ptr->free_act) { @@ -224,7 +224,7 @@ void ObjectQuaffEntity::execute(INVENTORY_IDX item) break; case SV_POTION_DETONATIONS: - ident = detonation(); + ident = QuaffEffects(this->player_ptr).detonation(); break; case SV_POTION_DEATH: chg_virtue(this->player_ptr, V_VITALITY, -1); @@ -597,67 +597,6 @@ bool ObjectQuaffEntity::can_quaff() return ItemUseChecker(this->player_ptr).check_stun(_("朦朧としていて瓶の蓋を開けられなかった!", "You are too stunned to quaff it!")); } -/*! - * @brief 酔っ払いの薬 - * @param player_ptr プレイヤーへの参照ポインタ - * @return カオス耐性があるかその他の一部確率でFALSE、それ以外はTRUE - */ -bool ObjectQuaffEntity::booze() -{ - bool ident = false; - auto is_monk = PlayerClass(this->player_ptr).equals(PlayerClassType::MONK); - if (!is_monk) { - chg_virtue(this->player_ptr, V_HARMONY, -1); - } else if (!has_resist_conf(this->player_ptr)) { - this->player_ptr->special_attack |= ATTACK_SUIKEN; - } - - BadStatusSetter bss(this->player_ptr); - if (!has_resist_conf(this->player_ptr) && bss.confusion(randint0(20) + 15)) { - ident = true; - } - - if (has_resist_chaos(this->player_ptr)) { - return ident; - } - - if (one_in_(2) && bss.mod_hallucination(randint0(150) + 150)) { - ident = true; - } - - if (!is_monk || !one_in_(13)) { - return ident; - } - - ident = true; - if (one_in_(3)) { - lose_all_info(this->player_ptr); - } else { - wiz_dark(this->player_ptr); - } - - (void)teleport_player_aux(this->player_ptr, 100, false, i2enum(TELEPORT_NONMAGICAL | TELEPORT_PASSIVE)); - wiz_dark(this->player_ptr); - msg_print(_("知らない場所で目が醒めた。頭痛がする。", "You wake up somewhere with a sore head...")); - msg_print(_("何も思い出せない。どうやってここへ来たのかも分からない!", "You can't remember a thing or how you got here!")); - return ident; -} - -/*! - * @brief 爆発の薬の効果処理 / Fumble ramble - * @param player_ptr プレイヤーへの参照ポインタ - * @return 常にTRUE - */ -bool ObjectQuaffEntity::detonation() -{ - msg_print(_("体の中で激しい爆発が起きた!", "Massive explosions rupture your body!")); - take_hit(this->player_ptr, DAMAGE_NOESCAPE, damroll(50, 20), _("爆発の薬", "a potion of Detonation")); - BadStatusSetter bss(this->player_ptr); - (void)bss.mod_stun(75); - (void)bss.mod_cut(5000); - return true; -} - ObjectType ObjectQuaffEntity::copy_object(const INVENTORY_IDX item) { auto *tmp_o_ptr = ref_item(this->player_ptr, item); diff --git a/src/object-use/quaff/quaff-execution.h b/src/object-use/quaff/quaff-execution.h index 242e9c08b..d16bfdb70 100644 --- a/src/object-use/quaff/quaff-execution.h +++ b/src/object-use/quaff/quaff-execution.h @@ -16,6 +16,4 @@ private: bool can_quaff(); ObjectType copy_object(const INVENTORY_IDX item); - bool booze(); - bool detonation(); }; -- 2.11.0