From 73eebce685df4b68bcd60ee3bb70ddcc7e6991c3 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Tue, 14 Sep 2021 22:34:37 +0900 Subject: [PATCH] =?utf8?q?[Fix]=20#1473=20=E5=91=AA=E8=A1=93=E3=81=AE?= =?utf8?q?=E8=A9=A0=E5=94=B1=E5=81=9C=E6=AD=A2=E6=99=82=E3=81=AB=E9=85=8D?= =?utf8?q?=E5=88=97=E5=A4=96=E3=82=A2=E3=82=AF=E3=82=BB=E3=82=B9=E3=81=8C?= =?utf8?q?=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B=E4=BA=8B=E8=B1=A1=E3=82=92?= =?utf8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=9F=20/=20Resolved=20the=20issu?= =?utf8?q?e=20that=20out-of-order=20access=20would=20occur=20when=20all=20?= =?utf8?q?casting=20hex=20spells=20are=20stopped?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/cmd-action/cmd-spell.cpp | 2 +- src/racial/racial-switcher.cpp | 2 +- src/spell-realm/spells-hex.cpp | 31 +++++++++++++++++++------------ src/spell-realm/spells-hex.h | 7 ++++--- src/status/action-setter.cpp | 2 +- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/cmd-action/cmd-spell.cpp b/src/cmd-action/cmd-spell.cpp index 892427232..6e4ea0b39 100644 --- a/src/cmd-action/cmd-spell.cpp +++ b/src/cmd-action/cmd-spell.cpp @@ -1020,7 +1020,7 @@ bool do_cmd_cast(player_type *player_ptr) msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not cast more spells.")); flush(); if (player_ptr->lev >= 35) { - flag = SpellHex(player_ptr).stop_one_spell(); + flag = SpellHex(player_ptr).stop_spells_with_selection(); } if (!flag) { diff --git a/src/racial/racial-switcher.cpp b/src/racial/racial-switcher.cpp index 15b3d85f0..4895260e3 100644 --- a/src/racial/racial-switcher.cpp +++ b/src/racial/racial-switcher.cpp @@ -92,7 +92,7 @@ bool switch_class_racial_execution(player_type *player_ptr, const int32_t comman return sword_dancing(player_ptr); case CLASS_HIGH_MAGE: if (player_ptr->realm1 == REALM_HEX) { - auto retval = SpellHex(player_ptr).stop_one_spell(); + auto retval = SpellHex(player_ptr).stop_spells_with_selection(); if (retval) { PlayerEnergy(player_ptr).set_player_turn_energy(10); } diff --git a/src/spell-realm/spells-hex.cpp b/src/spell-realm/spells-hex.cpp index e552518e5..3bd51d76c 100644 --- a/src/spell-realm/spells-hex.cpp +++ b/src/spell-realm/spells-hex.cpp @@ -60,7 +60,7 @@ SpellHex::SpellHex(player_type *player_ptr, monap_type *monap_ptr) /*! * @brief プレイヤーが詠唱中の全呪術を停止する */ -bool SpellHex::stop_all_spells() +void SpellHex::stop_all_spells() { for (auto spell : this->casting_spells) { exe_spell(this->player_ptr, REALM_HEX, spell, SPELL_STOP); @@ -74,13 +74,13 @@ bool SpellHex::stop_all_spells() this->player_ptr->update |= PU_BONUS | PU_HP | PU_MANA | PU_SPELLS; this->player_ptr->redraw |= PR_EXTRA | PR_HP | PR_MANA; - return true; } /*! - * @brief プレイヤーが詠唱中の呪術から一つを選んで停止する + * @brief プレイヤーが詠唱中の呪術から選択式で一つまたは全てを停止する + * @return 停止したらtrue、停止をキャンセルしたらfalse */ -bool SpellHex::stop_one_spell() +bool SpellHex::stop_spells_with_selection() { if (!this->is_spelling_any()) { msg_print(_("呪文を詠唱していません。", "You are not casting a spell.")); @@ -89,7 +89,8 @@ bool SpellHex::stop_one_spell() auto casting_num = this->player_ptr->magic_num2[0]; if ((casting_num == 1) || (this->player_ptr->lev < 35)) { - return this->stop_all_spells(); + this->stop_all_spells(); + return true; } char out_val[160]; @@ -97,7 +98,11 @@ bool SpellHex::stop_one_spell() I2A(0), I2A(casting_num - 1)); screen_save(); char choice = 0; - auto is_selected = select_spell_stopping(out_val, choice); + auto [is_all, is_selected] = select_spell_stopping(out_val, choice); + if (is_all) { + return true; + } + screen_load(); if (is_selected) { auto n = this->casting_spells[A2I(choice)]; @@ -116,31 +121,33 @@ bool SpellHex::stop_one_spell() * @param spells 詠唱中の呪術リスト * @param out_val 呪文名 * @param choice 選択した呪文 - * @return 選択が完了したらtrue、キャンセルならばfalse + * @return + * Item1: 全ての呪文を中断するならばtrue、1つの呪文を中断するならばfalse + * Item2: 選択が完了したらtrue、キャンセルならばfalse */ -bool SpellHex::select_spell_stopping(char *out_val, char &choice) +std::tuple SpellHex::select_spell_stopping(char *out_val, char &choice) { while (true) { this->display_casting_spells_list(); if (!get_com(out_val, &choice, true)) { - return false; + return std::make_tuple(false, false); } if (isupper(choice)) { choice = static_cast(tolower(choice)); } - /* All */ if (choice == 'l') { screen_load(); - return this->stop_all_spells(); + this->stop_all_spells(); + return std::make_tuple(true, true); } if ((choice < I2A(0)) || (choice > I2A(this->player_ptr->magic_num2[0] - 1))) { continue; } - return true; + return std::make_tuple(false, true); } } diff --git a/src/spell-realm/spells-hex.h b/src/spell-realm/spells-hex.h index 6d4102ae8..97c358847 100644 --- a/src/spell-realm/spells-hex.h +++ b/src/spell-realm/spells-hex.h @@ -2,6 +2,7 @@ #include "system/angband.h" #include "realm/realm-hex-numbers.h" +#include enum class SpellHexRevengeType : byte { NONE = 0, @@ -18,9 +19,9 @@ public: SpellHex(player_type *player_ptr, monap_type *monap_ptr); virtual ~SpellHex() = default; - bool stop_one_spell(); + bool stop_spells_with_selection(); void decrease_mana(); - bool stop_all_spells(); + void stop_all_spells(); bool is_casting_full_capacity() const; void continue_revenge(); void store_vengeful_damage(HIT_POINT dam); @@ -45,7 +46,7 @@ private: std::vector casting_spells; monap_type *monap_ptr = nullptr; - bool select_spell_stopping(char *out_val, char &choice); + std::tuple select_spell_stopping(char *out_val, char &choice); void display_casting_spells_list(); bool process_mana_cost(const bool need_restart); bool check_restart(); diff --git a/src/status/action-setter.cpp b/src/status/action-setter.cpp index 9022d2033..6b6f986d2 100644 --- a/src/status/action-setter.cpp +++ b/src/status/action-setter.cpp @@ -84,7 +84,7 @@ void set_action(player_type *player_ptr, uint8_t typ) stop_singing(player_ptr); if (prev_typ == ACTION_SPELL) { - (void)SpellHex(player_ptr).stop_one_spell(); + (void)SpellHex(player_ptr).stop_spells_with_selection(); } switch (player_ptr->action) { -- 2.11.0