OSDN Git Service

[Refactor] #2205 Separated enchant_figurine() from OtherItemsEnchanter::apply_magic()
authorHourier <66951241+Hourier@users.noreply.github.com>
Tue, 22 Feb 2022 13:17:00 +0000 (22:17 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Wed, 23 Feb 2022 02:55:12 +0000 (11:55 +0900)
src/object-enchant/others/apply-magic-others.cpp
src/object-enchant/others/apply-magic-others.h

index 135c409..2528f3e 100644 (file)
@@ -63,36 +63,9 @@ void OtherItemsEnchanter::apply_magic()
         object_aware(this->player_ptr, this->o_ptr);
         object_known(this->o_ptr);
         break;
-    case ItemKindType::FIGURINE: {
-        PARAMETER_VALUE i = 1;
-        int check;
-        monster_race *r_ptr;
-        while (true) {
-            i = randint1(r_info.size() - 1);
-
-            if (!item_monster_okay(this->player_ptr, i))
-                continue;
-            if (i == MON_TSUCHINOKO)
-                continue;
-
-            r_ptr = &r_info[i];
-            check = (floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - floor_ptr->dun_level) : 0;
-            if (!r_ptr->rarity)
-                continue;
-            if (r_ptr->rarity > 100)
-                continue;
-            if (randint0(check))
-                continue;
-
-            break;
-        }
-
-        this->o_ptr->pval = i;
-        if (one_in_(6))
-            this->o_ptr->curse_flags.set(CurseTraitType::CURSED);
-
+    case ItemKindType::FIGURINE:
+        this->enchant_figurine();
         break;
-    }
     case ItemKindType::CORPSE: {
         PARAMETER_VALUE i = 1;
         int check;
@@ -175,3 +148,29 @@ void OtherItemsEnchanter::enchant_wand_staff()
     auto *k_ptr = &k_info[this->o_ptr->k_idx];
     this->o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
 }
+
+void OtherItemsEnchanter::enchant_figurine()
+{
+    auto *floor_ptr = this->player_ptr->current_floor_ptr;
+    short r_idx;
+    while (true)
+    {
+        r_idx = randint1(r_info.size() - 1);
+        if (!item_monster_okay(this->player_ptr, r_idx) || (r_idx == MON_TSUCHINOKO)) {
+            continue;
+        }
+
+        auto *r_ptr = &r_info[r_idx];
+        auto check = (floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - floor_ptr->dun_level) : 0;
+        if ((r_ptr->rarity == 0) || (r_ptr->rarity > 100) || (randint0(check) > 0)) {
+            continue;
+        }
+
+        break;
+    }
+
+    this->o_ptr->pval = r_idx;
+    if (one_in_(6)) {
+        this->o_ptr->curse_flags.set(CurseTraitType::CURSED);
+    }
+}
index 1fbc04d..b2925ed 100644 (file)
@@ -19,4 +19,5 @@ private:
     ObjectType *o_ptr;
 
     void enchant_wand_staff();
+    void enchant_figurine();
 };