OSDN Git Service

[Refactor] #3766 Separated build_timeout_description() from item_activation_aux()
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 12 Nov 2023 10:06:03 +0000 (19:06 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Wed, 29 Nov 2023 11:09:20 +0000 (20:09 +0900)
src/object/object-info.cpp

index 564477e..d560b51 100644 (file)
@@ -108,6 +108,49 @@ static std::string build_activation_description(const activation_type &act, cons
     }
 }
 
+static std::string build_timeout_description(const activation_type &act, const ItemEntity &item)
+{
+    const auto constant = act.timeout.constant;
+    const auto dice = act.timeout.dice;
+    if (constant == 0 && dice == 0) {
+        return _("いつでも", "every turn");
+    }
+
+    if (constant >= 0) {
+        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();
+    }
+
+    std::stringstream ss;
+    switch (act.index) {
+    case RandomArtActType::BR_FIRE:
+        ss << _("", "every ") << (item.bi_key == BaseitemKey(ItemKindType::RING, SV_RING_FLAMES) ? 200 : 250) << _(" ターン毎", " turns");
+        return ss.str();
+    case RandomArtActType::BR_COLD:
+        ss << _("", "every ") << (item.bi_key == BaseitemKey(ItemKindType::RING, SV_RING_ICE) ? 200 : 250) << _(" ターン毎", " turns");
+        return ss.str();
+    case RandomArtActType::TERROR:
+        return _("3*(レベル+10) ターン毎", "every 3 * (level+10) turns");
+    case RandomArtActType::MURAMASA:
+        return _("確率50%で壊れる", "(destroyed 50%)");
+    default:
+        return "undefined";
+    }
+}
+
 /*!
  * @brief オブジェクトの発動効果名称を返す(サブルーチン/汎用)
  * @param o_ptr 名称を取得する元のオブジェクト構造体参照ポインタ
@@ -121,49 +164,9 @@ static std::string item_activation_aux(const ItemEntity *o_ptr)
     }
 
     const auto desc = build_activation_description(*it, *o_ptr);
-
-    /* Timeout description */
-    std::stringstream timeout;
-    const auto constant = it->timeout.constant;
-    const auto dice = it->timeout.dice;
-    if (constant == 0 && dice == 0) {
-        /* We can activate it every turn */
-        timeout << _("いつでも", "every turn");
-    } else if (constant < 0) {
-        /* Activations that have special timeout */
-        switch (it->index) {
-        case RandomArtActType::BR_FIRE:
-            timeout << _("", "every ") << (o_ptr->bi_key == BaseitemKey(ItemKindType::RING, SV_RING_FLAMES) ? 200 : 250) << _(" ターン毎", " turns");
-            break;
-        case RandomArtActType::BR_COLD:
-            timeout << _("", "every ") << (o_ptr->bi_key == BaseitemKey(ItemKindType::RING, SV_RING_ICE) ? 200 : 250) << _(" ターン毎", " turns");
-            break;
-        case RandomArtActType::TERROR:
-            timeout << _("3*(レベル+10) ターン毎", "every 3 * (level+10) turns");
-            break;
-        case RandomArtActType::MURAMASA:
-            timeout << _("確率50%で壊れる", "(destroyed 50%)");
-            break;
-        default:
-            timeout << "undefined";
-            break;
-        }
-    } else {
-        timeout << _("", "every ");
-        if (constant > 0) {
-            timeout << constant;
-            if (dice > 0) {
-                timeout << '+';
-            }
-        }
-        if (dice > 0) {
-            timeout << 'd' << dice;
-        }
-        timeout << _(" ターン毎", " turns");
-    }
-
+    const auto timeout = build_timeout_description(*it, *o_ptr);
     std::stringstream ss;
-    ss << desc << _(" : ", " ") << timeout.str();
+    ss << desc << _(" : ", " ") << timeout;
     return ss.str();
 }