From c0f0940b53ea5f6db461eed6a7981f9fdedaa948 Mon Sep 17 00:00:00 2001 From: Hourier Date: Tue, 7 Sep 2021 21:32:11 +0900 Subject: [PATCH] [Refactor] #1485 Moved eyes_on_eyes() and thief_teleport() from monster-attack-player.cpp to spells-hex.cpp/h --- src/monster-attack/monster-attack-player.cpp | 42 ++----------------- src/spell-realm/spells-hex.cpp | 61 ++++++++++++++++++++++++++++ src/spell-realm/spells-hex.h | 5 +++ 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/src/monster-attack/monster-attack-player.cpp b/src/monster-attack/monster-attack-player.cpp index aaf974db7..afea4a89c 100644 --- a/src/monster-attack/monster-attack-player.cpp +++ b/src/monster-attack/monster-attack-player.cpp @@ -454,47 +454,13 @@ static bool process_monster_blows(player_type *target_ptr, monap_type *monap_ptr return false; } -/*! - * @brief 呪術「目には目を」の効果処理 - * @param target_ptr プレーヤーへの参照ポインタ - * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ - */ -static void eyes_on_eyes(player_type *target_ptr, monap_type *monap_ptr) -{ - if (((target_ptr->tim_eyeeye == 0) && !RealmHex(target_ptr).is_spelling_specific(HEX_EYE_FOR_EYE)) || (monap_ptr->get_damage == 0) || target_ptr->is_dead) - return; - -#ifdef JP - msg_format("攻撃が%s自身を傷つけた!", monap_ptr->m_name); -#else - GAME_TEXT m_name_self[MAX_MONSTER_NAME]; - monster_desc(target_ptr, m_name_self, monap_ptr->m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE); - msg_format("The attack of %s has wounded %s!", monap_ptr->m_name, m_name_self); -#endif - project(target_ptr, 0, 0, monap_ptr->m_ptr->fy, monap_ptr->m_ptr->fx, monap_ptr->get_damage, GF_MISSILE, PROJECT_KILL); - if (target_ptr->tim_eyeeye) - set_tim_eyeeye(target_ptr, target_ptr->tim_eyeeye - 5, true); -} - -static void thief_teleport(player_type *target_ptr, monap_type *monap_ptr) -{ - if (!monap_ptr->blinked || !monap_ptr->alive || target_ptr->is_dead) - return; - - if (RealmHex(target_ptr).check_hex_barrier(monap_ptr->m_idx, HEX_ANTI_TELE)) { - msg_print(_("泥棒は笑って逃げ...ようとしたがバリアに防がれた。", "The thief flees laughing...? But a magic barrier obstructs it.")); - } else { - msg_print(_("泥棒は笑って逃げた!", "The thief flees laughing!")); - teleport_away(target_ptr, monap_ptr->m_idx, MAX_SIGHT * 2 + 5, TELEPORT_SPONTANEOUS); - } -} - static void postprocess_monster_blows(player_type *target_ptr, monap_type *monap_ptr) { - RealmHex(target_ptr).store_vengeful_damage(monap_ptr->get_damage); - eyes_on_eyes(target_ptr, monap_ptr); + RealmHex realm_hex(target_ptr, monap_ptr); + realm_hex.store_vengeful_damage(monap_ptr->get_damage); + realm_hex.eyes_on_eyes(); musou_counterattack(target_ptr, monap_ptr); - thief_teleport(target_ptr, monap_ptr); + realm_hex.thief_teleport(); monster_race *r_ptr = &r_info[monap_ptr->m_ptr->r_idx]; if (target_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !target_ptr->current_floor_ptr->inside_arena) r_ptr->r_deaths++; diff --git a/src/spell-realm/spells-hex.cpp b/src/spell-realm/spells-hex.cpp index 3ba71f7b9..5016e8e52 100644 --- a/src/spell-realm/spells-hex.cpp +++ b/src/spell-realm/spells-hex.cpp @@ -3,12 +3,18 @@ #include "core/player-redraw-types.h" #include "core/player-update-types.h" #include "core/window-redrawer.h" +#include "effect/effect-characteristics.h" +#include "effect/effect-processor.h" +#include "monster-attack/monster-attack-util.h" #include "monster-race/monster-race.h" #include "player/attack-defense-types.h" #include "player/player-skill.h" #include "realm/realm-hex-numbers.h" +#include "spell-kind/spells-teleport.h" +#include "spell-realm/spells-crusade.h" #include "spell-realm/spells-song.h" #include "spell/spell-info.h" +#include "spell/spell-types.h" #include "spell/spells-execution.h" #include "spell/technic-info-table.h" #include "status/action-setter.h" @@ -21,6 +27,12 @@ #include "util/int-char-converter.h" #include "view/display-messages.h" +#ifdef JP +#else +#include "monster/monster-describer.h" +#include "monster/monster-description-types.h" +#endif + /*!< 呪術の最大詠唱数 */ constexpr int MAX_KEEP = 4; @@ -39,6 +51,12 @@ RealmHex::RealmHex(player_type *caster_ptr) } } +RealmHex::RealmHex(player_type *caster_ptr, monap_type *monap_ptr) + : caster_ptr(caster_ptr) + , monap_ptr(monap_ptr) +{ +} + /*! * @brief プレイヤーが詠唱中の全呪術を停止する */ @@ -368,3 +386,46 @@ bool RealmHex::is_spelling_any() const { return (caster_ptr->realm1 == REALM_HEX) && (caster_ptr->magic_num1[0] != 0); } + +/*! + * @brief 呪術「目には目を」の効果処理 + * @param this->caster_ptr プレーヤーへの参照ポインタ + * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ + */ +void RealmHex::eyes_on_eyes() +{ + if (this->monap_ptr == nullptr) { + throw("Invalid constructor was used!"); + } + + if (((this->caster_ptr->tim_eyeeye == 0) && !this->is_spelling_specific(HEX_EYE_FOR_EYE)) || (this->monap_ptr->get_damage == 0) || this->caster_ptr->is_dead) + return; + +#ifdef JP + msg_format("攻撃が%s自身を傷つけた!", this->monap_ptr->m_name); +#else + GAME_TEXT m_name_self[MAX_MONSTER_NAME]; + monster_desc(this->caster_ptr, m_name_self, this->monap_ptr->m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE); + msg_format("The attack of %s has wounded %s!", this->monap_ptr->m_name, m_name_self); +#endif + project(this->caster_ptr, 0, 0, this->monap_ptr->m_ptr->fy, this->monap_ptr->m_ptr->fx, this->monap_ptr->get_damage, GF_MISSILE, PROJECT_KILL); + if (this->caster_ptr->tim_eyeeye) + set_tim_eyeeye(this->caster_ptr, this->caster_ptr->tim_eyeeye - 5, true); +} + +void RealmHex::thief_teleport() +{ + if (this->monap_ptr == nullptr) { + throw("Invalid constructor was used!"); + } + + if (!this->monap_ptr->blinked || !this->monap_ptr->alive || this->caster_ptr->is_dead) + return; + + if (this->check_hex_barrier(this->monap_ptr->m_idx, HEX_ANTI_TELE)) { + msg_print(_("泥棒は笑って逃げ...ようとしたがバリアに防がれた。", "The thief flees laughing...? But a magic barrier obstructs it.")); + } else { + msg_print(_("泥棒は笑って逃げた!", "The thief flees laughing!")); + teleport_away(this->caster_ptr, this->monap_ptr->m_idx, MAX_SIGHT * 2 + 5, TELEPORT_SPONTANEOUS); + } +} diff --git a/src/spell-realm/spells-hex.h b/src/spell-realm/spells-hex.h index 7a91873d5..979735d0d 100644 --- a/src/spell-realm/spells-hex.h +++ b/src/spell-realm/spells-hex.h @@ -3,11 +3,13 @@ #include "system/angband.h" #include "realm/realm-hex-numbers.h" +struct monap_type; struct player_type; class RealmHex { public: RealmHex() = delete; RealmHex(player_type *caster_ptr); + RealmHex(player_type *caster_ptr, monap_type *monap_ptr); virtual ~RealmHex() = default; bool stop_one_spell(); @@ -19,10 +21,13 @@ public: bool check_hex_barrier(MONSTER_IDX m_idx, realm_hex_type type) const; bool is_spelling_specific(int hex) const; bool is_spelling_any() const; + void eyes_on_eyes(); + void thief_teleport(); private: player_type *caster_ptr; std::vector casting_spells; + monap_type *monap_ptr = nullptr; bool select_spell_stopping(char *out_val, char &choice); void display_casting_spells_list(); -- 2.11.0