OSDN Git Service

[Refactor] #3325 MonsterEntity/MonsterRace::is_explodable() を実装し、爆発判定を移した
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 20 May 2023 02:13:59 +0000 (11:13 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 20 May 2023 13:56:23 +0000 (22:56 +0900)
src/monster/monster-damage.cpp
src/monster/monster-damage.h
src/system/monster-entity.cpp
src/system/monster-entity.h
src/system/monster-race-info.cpp
src/system/monster-race-info.h

index 0028058..0590daa 100644 (file)
@@ -47,7 +47,6 @@
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
 #include "world/world.h"
-#include <algorithm>
 #include <optional>
 #include <string>
 
@@ -354,7 +353,6 @@ void MonsterDamageProcessor::show_kill_message(std::string_view note, std::strin
 {
     auto *floor_ptr = this->player_ptr->current_floor_ptr;
     auto *m_ptr = &floor_ptr->m_list[this->m_idx];
-    const auto &r_ref = m_ptr->get_real_r_ref();
     if (!note.empty()) {
         msg_format("%s^%s", m_name.data(), note.data());
         return;
@@ -367,12 +365,11 @@ void MonsterDamageProcessor::show_kill_message(std::string_view note, std::strin
         return;
     }
 
-    const auto explode = std::any_of(std::begin(r_ref.blow), std::end(r_ref.blow),
-        [](const auto &blow) { return blow.method == RaceBlowMethodType::EXPLODE; });
-
+    const auto is_explodable = m_ptr->is_explodable();
+    const auto died_mes = m_ptr->get_died_message();
     if (m_ptr->has_living_flag()) {
-        if (explode) {
-            msg_format(_("%sは爆発して死んだ。", "%s^ explodes and dies."), m_name.data());
+        if (is_explodable) {
+            this->show_explosion_message(died_mes, m_name);
             return;
         }
 
@@ -382,8 +379,8 @@ void MonsterDamageProcessor::show_kill_message(std::string_view note, std::strin
         return;
     }
 
-    if (explode) {
-        msg_format(_("%sは爆発して粉々になった。", "%s^ explodes into tiny shreds."), m_name.data());
+    if (is_explodable) {
+        this->show_explosion_message(died_mes, m_name);
         return;
     }
 
@@ -392,6 +389,15 @@ void MonsterDamageProcessor::show_kill_message(std::string_view note, std::strin
     msg_format(mes, m_name.data());
 }
 
+void MonsterDamageProcessor::show_explosion_message(std::string_view died_mes, std::string_view m_name)
+{
+    std::stringstream ss;
+    ss << _(m_name, format("%s^", m_name.data()));
+    ss << died_mes;
+    msg_print(ss.str());
+    return;
+}
+
 void MonsterDamageProcessor::show_bounty_message(std::string_view m_name)
 {
     auto *floor_ptr = this->player_ptr->current_floor_ptr;
index 447ef6c..567a0b7 100644 (file)
@@ -37,6 +37,7 @@ private:
     void death_amberites(std::string_view m_name);
     void dying_scream(std::string_view m_name);
     void show_kill_message(std::string_view note, std::string_view m_name);
+    void show_explosion_message(std::string_view died_mes, std::string_view m_name);
     void show_bounty_message(std::string_view m_name);
     void set_redraw();
     void summon_special_unique();
index 89f7a93..ae11514 100644 (file)
@@ -199,6 +199,12 @@ bool MonsterEntity::has_living_flag(bool is_apperance) const
     return monrace.has_living_flag();
 }
 
+bool MonsterEntity::is_explodable() const
+{
+    const auto &monrace = monraces_info[this->r_idx];
+    return monrace.is_explodable();
+}
+
 std::string MonsterEntity::get_died_message() const
 {
     const auto &monrace = monraces_info[this->r_idx];
index 56b89f3..a0e6e04 100644 (file)
@@ -82,5 +82,6 @@ public:
     bool is_invulnerable() const;
     byte get_temporary_speed() const;
     bool has_living_flag(bool is_apperance = false) const;
+    bool is_explodable() const;
     std::string get_died_message() const;
 };
index 3be1468..f9d4f35 100644 (file)
@@ -1,5 +1,6 @@
 #include "system/monster-race-info.h"
 #include "monster/horror-descriptions.h"
+#include <algorithm>
 
 /*!
  * @brief エルドリッチホラーの形容詞種別を決める
@@ -29,14 +30,19 @@ bool MonsterRaceInfo::has_living_flag() const
     return this->kind_flags.has_none_of({ MonsterKindType::DEMON, MonsterKindType::UNDEAD, MonsterKindType::NONLIVING });
 }
 
+bool MonsterRaceInfo::is_explodable() const
+{
+    return std::any_of(std::begin(this->blow), std::end(this->blow),
+        [](const auto &blow) { return blow.method == RaceBlowMethodType::EXPLODE; });
+}
+
 /*!
  * @brief モンスターを撃破した際の述語メッセージを返す
  * @return 撃破されたモンスターの述語
  */
 std::string MonsterRaceInfo::get_died_message() const
 {
-    const auto is_explodable = std::any_of(std::begin(this->blow), std::end(this->blow),
-        [](const auto &blow) { return blow.method == RaceBlowMethodType::EXPLODE; });
+    const auto is_explodable = this->is_explodable();
     if (this->has_living_flag()) {
         return is_explodable ? _("は爆発して死んだ。", " explodes and dies.") : _("は死んだ。", " dies.");
     }
index 9af4cbb..58e2574 100644 (file)
@@ -138,5 +138,6 @@ public:
 
     const std::string &decide_horror_message() const;
     bool has_living_flag() const;
+    bool is_explodable() const;
     std::string get_died_message() const;
 };