OSDN Git Service

[Refactor] #2403 Separated give_cursed() from apply_magic()
authorHourier <66951241+Hourier@users.noreply.github.com>
Fri, 11 Mar 2022 13:01:28 +0000 (22:01 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 13 Mar 2022 14:15:04 +0000 (23:15 +0900)
src/object-enchant/weapon/apply-magic-sword.cpp
src/object-enchant/weapon/apply-magic-sword.h

index 0c64ee6..27cad04 100644 (file)
@@ -55,27 +55,7 @@ void SwordEnchanter::apply_magic()
     }
 
     if (this->power < -1) {
-        if (randint0(MAX_DEPTH) < this->level) {
-            auto n = 0;
-            while (true) {
-                this->o_ptr->ego_idx = get_random_ego(INVEN_MAIN_HAND, false);
-                if (this->o_ptr->ego_idx == EgoType::WEIRD && this->o_ptr->tval != ItemKindType::SWORD) {
-                    continue;
-                }
-
-                auto *e_ptr = &e_info[this->o_ptr->ego_idx];
-                if (this->o_ptr->tval == ItemKindType::SWORD && this->o_ptr->sval == SV_HAYABUSA && e_ptr->max_pval < 0) {
-                    if (++n > 1000) {
-                        msg_print(_("エラー:隼の剣に割り当てるエゴ無し", "Error: Cannot find for Hayabusa."));
-                        return;
-                    }
-
-                    continue;
-                }
-
-                break;
-            }
-        }
+        this->give_cursed();
     }
 }
 
@@ -110,3 +90,30 @@ void SwordEnchanter::give_ego_index()
         break;
     }
 }
+
+void SwordEnchanter::give_cursed()
+{
+    if (randint0(MAX_DEPTH) >= this->level) {
+        return;
+    }
+
+    auto n = 0;
+    while (true) {
+        this->o_ptr->ego_idx = get_random_ego(INVEN_MAIN_HAND, false);
+        if ((this->o_ptr->ego_idx == EgoType::WEIRD) && (this->o_ptr->tval != ItemKindType::SWORD)) {
+            continue;
+        }
+
+        auto *e_ptr = &e_info[this->o_ptr->ego_idx];
+        if ((this->o_ptr->tval == ItemKindType::SWORD) && (this->o_ptr->sval == SV_HAYABUSA) && (e_ptr->max_pval < 0)) {
+            if (++n > 1000) {
+                msg_print(_("エラー:隼の剣に割り当てるエゴ無し", "Error: Cannot find for Hayabusa."));
+                return;
+            }
+
+            continue;
+        }
+
+        break;
+    }
+}
index f7abcf0..3e0b0a7 100644 (file)
@@ -14,7 +14,7 @@ protected:
     void sval_enchant() override{};
     void give_ego_index() override;
     void give_high_ego_index() override{};
-    void give_cursed() override{};
+    void give_cursed() override;
 
 private:
     PlayerType *player_ptr;