OSDN Git Service

[Refactor] #1301 Reshaped apply-magic-crown.cpp/h
authorHourier <grapefox.whitelucifer.0408@gmail.com>
Sun, 1 Aug 2021 11:29:11 +0000 (20:29 +0900)
committerHourier <grapefox.whitelucifer.0408@gmail.com>
Sun, 1 Aug 2021 11:29:11 +0000 (20:29 +0900)
src/object-enchant/apply-magic-crown.cpp
src/object-enchant/apply-magic-crown.h

index 3b2422b..fe9bb7a 100644 (file)
@@ -17,60 +17,59 @@ CrownEnchanter::CrownEnchanter(player_type *owner_ptr, object_type *o_ptr, DEPTH
 {
 }
 
-/*
- * @details power > 2はデバッグ専用.
- */
 void CrownEnchanter::apply_magic()
 {
     if (this->power > 1) {
-        if (one_in_(20) || (this->power > 2)) {
-            become_random_artifact(this->owner_ptr, this->o_ptr, false);
-            return;
-        }
-
-        while (true) {
-            bool ok_flag = true;
-            this->o_ptr->name2 = get_random_ego(INVEN_HEAD, true);
-
-            switch (this->o_ptr->name2) {
-            case EGO_TELEPATHY:
-            case EGO_MAGI:
-            case EGO_MIGHT:
-            case EGO_REGENERATION:
-            case EGO_LORDLINESS:
-            case EGO_BASILISK:
-                break;
-            case EGO_SEEING:
-                if (one_in_(3))
-                    add_low_telepathy(this->o_ptr);
-                break;
-            default:
-                /* not existing crown (wisdom,lite, etc...) */
-                ok_flag = false;
-            }
-
-            if (ok_flag)
-                break;
-        }
-
+        this->give_ego_index();
         return;
     }
 
     if (this->power < -1) {
-        while (true) {
-            bool ok_flag = true;
-            this->o_ptr->name2 = get_random_ego(INVEN_HEAD, false);
+        this->give_cursed();
+    }
+}
+
+/*
+ * @details power > 2はデバッグ専用.
+ */
+void CrownEnchanter::give_ego_index()
+{
+    if (one_in_(20) || (this->power > 2)) {
+        become_random_artifact(this->owner_ptr, this->o_ptr, false);
+        return;
+    }
 
-            switch (this->o_ptr->name2) {
-            case EGO_H_DEMON:
-                ok_flag = false;
-                break;
-            default:
-                break;
+    while (true) {
+        this->o_ptr->name2 = get_random_ego(INVEN_HEAD, true);
+        switch (this->o_ptr->name2) {
+        case EGO_TELEPATHY:
+        case EGO_MAGI:
+        case EGO_MIGHT:
+        case EGO_REGENERATION:
+        case EGO_LORDLINESS:
+        case EGO_BASILISK:
+            return;
+        case EGO_SEEING:
+            if (one_in_(3)) {
+                add_low_telepathy(this->o_ptr);
             }
 
-            if (ok_flag)
-                break;
+            return;
+        default:
+            continue;
+        }
+    }
+}
+
+void CrownEnchanter::give_cursed()
+{
+    while (true) {
+        this->o_ptr->name2 = get_random_ego(INVEN_HEAD, false);
+        switch (this->o_ptr->name2) {
+        case EGO_H_DEMON:
+            return;
+        default:
+            continue;
         }
     }
 }
index a8173b7..1174394 100644 (file)
@@ -15,9 +15,9 @@ public:
 
 protected:
     void enchant(){};
-    void give_ego_index(){};
+    void give_ego_index();
     void give_high_ego_index(){};
-    void give_cursed(){};
+    void give_cursed();
 
 private:
     player_type *owner_ptr;