OSDN Git Service

[Refactor] #3772 ActivationType::build_timeout_description() を定義して、ItemEntity::build_...
authorHourier <66951241+Hourier@users.noreply.github.com>
Sat, 2 Dec 2023 11:04:53 +0000 (20:04 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Mon, 4 Dec 2023 10:42:31 +0000 (19:42 +0900)
src/object-enchant/activation-info-table.cpp
src/object-enchant/activation-info-table.h
src/system/item-entity.cpp

index 3d3d3f5..e906e29 100644 (file)
@@ -1,6 +1,7 @@
 #include "object-enchant/activation-info-table.h"
 #include "artifact/random-art-effects.h"
 #include "locale/language-switcher.h"
+#include <sstream>
 
 /*!
  * @brief アイテムの発動効果テーブル
@@ -153,3 +154,30 @@ const std::vector<ActivationType> activation_info = {
     { "CREATE_AMMO", RandomArtActType::CREATE_AMMO, 10, 30000, 200, 0, _("弾/矢の製造", "Create Ammo") },
     { "DISPEL_MAGIC", RandomArtActType::DISPEL_MAGIC, 10, 10000, 50, 50, _("魔力消去", "Dispel Magic") },
 };
+
+std::optional<std::string> ActivationType::build_timeout_description() const
+{
+    if ((this->constant == 0) && (this->dice == 0)) {
+        return _("いつでも", "every turn");
+    }
+
+    if (!this->constant) {
+        return std::nullopt;
+    }
+
+    std::stringstream ss;
+    ss << _("", "every ");
+    if (this->constant > 0) {
+        ss << *this->constant;
+        if (this->dice > 0) {
+            ss << '+';
+        }
+    }
+
+    if (this->dice > 0) {
+        ss << 'd' << this->dice;
+    }
+
+    ss << _(" ターン毎", " turns");
+    return ss.str();
+}
index 3cb277a..dd5fc59 100644 (file)
@@ -14,6 +14,8 @@ public:
     std::optional<int> constant; // 発動間隔の最低ターン数
     int dice; // 発動間隔の追加ターン数
     std::string desc;
+
+    std::optional<std::string> build_timeout_description() const;
 };
 
 extern const std::vector<ActivationType> activation_info;
index 42acb87..968bbfe 100644 (file)
@@ -882,28 +882,9 @@ std::string ItemEntity::explain_activation() const
 
 std::string ItemEntity::build_timeout_description(const ActivationType &act) const
 {
-    const auto constant = act.constant;
-    const auto dice = act.dice;
-    if (constant == 0 && dice == 0) {
-        return _("いつでも", "every turn");
-    }
-
-    if (constant) {
-        std::stringstream ss;
-        ss << _("", "every ");
-        if (constant > 0) {
-            ss << *constant;
-            if (dice > 0) {
-                ss << '+';
-            }
-        }
-
-        if (dice > 0) {
-            ss << 'd' << dice;
-        }
-
-        ss << _(" ターン毎", " turns");
-        return ss.str();
+    const auto description = act.build_timeout_description();
+    if (description) {
+        return *description;
     }
 
     std::stringstream ss;