From ecf57975e9a8becfaa26f202215fed32d238827c Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Thu, 10 Mar 2022 19:12:51 +0900 Subject: [PATCH] [Refactor] #1642 Separated can_influence() from execute() --- src/object-use/quaff/quaff-execution.cpp | 31 ++++++++++++++++++++----------- src/object-use/quaff/quaff-execution.h | 1 + 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/object-use/quaff/quaff-execution.cpp b/src/object-use/quaff/quaff-execution.cpp index 023759214..13d2b86ec 100644 --- a/src/object-use/quaff/quaff-execution.cpp +++ b/src/object-use/quaff/quaff-execution.cpp @@ -72,20 +72,10 @@ ObjectQuaffEntity::ObjectQuaffEntity(PlayerType *player_ptr) */ void ObjectQuaffEntity::execute(INVENTORY_IDX item) { - PlayerEnergy(this->player_ptr).set_player_turn_energy(100); - if (!this->can_quaff()) { + if (!this->can_influence()) { return; } - if (music_singing_any(this->player_ptr)) { - stop_singing(this->player_ptr); - } - - SpellHex spell_hex(this->player_ptr); - if (spell_hex.is_spelling_any() && !spell_hex.is_spelling_specific(HEX_INHALE)) { - (void)SpellHex(this->player_ptr).stop_all_spells(); - } - const auto &o_ref = this->copy_object(item); vary_item(this->player_ptr, item, -1); sound(SOUND_QUAFF); @@ -111,6 +101,25 @@ void ObjectQuaffEntity::execute(INVENTORY_IDX item) this->moisten(o_ref); } +bool ObjectQuaffEntity::can_influence() +{ + PlayerEnergy(this->player_ptr).set_player_turn_energy(100); + if (!this->can_quaff()) { + return false; + } + + if (music_singing_any(this->player_ptr)) { + stop_singing(this->player_ptr); + } + + SpellHex spell_hex(this->player_ptr); + if (spell_hex.is_spelling_any() && !spell_hex.is_spelling_specific(HEX_INHALE)) { + (void)SpellHex(this->player_ptr).stop_all_spells(); + } + + return true; +} + bool ObjectQuaffEntity::can_quaff() { if (this->player_ptr->timewalk) { diff --git a/src/object-use/quaff/quaff-execution.h b/src/object-use/quaff/quaff-execution.h index 82ff522e2..069aab2aa 100644 --- a/src/object-use/quaff/quaff-execution.h +++ b/src/object-use/quaff/quaff-execution.h @@ -14,6 +14,7 @@ public: private: PlayerType *player_ptr; + bool can_influence(); bool can_quaff(); ObjectType copy_object(const INVENTORY_IDX item); void moisten(const ObjectType &o_ref); -- 2.11.0