OSDN Git Service

[Refactor] #2828 '魔法棒または杖' という判定をItemEntity::is_wand_staff() 及びBaseitemKey::is_wand_s...
authorHourier <66951241+Hourier@users.noreply.github.com>
Wed, 23 Nov 2022 11:46:02 +0000 (20:46 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 26 Nov 2022 02:20:20 +0000 (11:20 +0900)
14 files changed:
src/autopick/autopick-entry.cpp
src/cmd-item/cmd-eat.cpp
src/flavor/flavor-describer.cpp
src/floor/floor-object.cpp
src/mind/mind-mage.cpp
src/monster-attack/monster-eating.cpp
src/object-hook/hook-expendable.cpp
src/spell-kind/magic-item-recharger.cpp
src/store/store-util.cpp
src/system/baseitem-info.cpp
src/system/baseitem-info.h
src/system/item-entity.cpp
src/system/item-entity.h
src/view/object-describer.cpp

index 47b8f3c..9cc35fc 100644 (file)
@@ -469,7 +469,7 @@ void autopick_entry_from_object(PlayerType *player_ptr, autopick_type *entry, It
 
     if (o_ptr->is_ammo()) {
         ADD_FLG(FLG_MISSILES);
-    } else if (o_ptr->tval == ItemKindType::SCROLL || o_ptr->tval == ItemKindType::STAFF || o_ptr->is_wand_rod()) {
+    } else if (o_ptr->tval == ItemKindType::SCROLL || o_ptr->is_wand_staff() || o_ptr->is_wand_rod()) {
         ADD_FLG(FLG_DEVICES);
     } else if (o_ptr->tval == ItemKindType::LITE) {
         ADD_FLG(FLG_LIGHTS);
index 7ef557d..833b2ab 100644 (file)
@@ -153,7 +153,7 @@ bool exe_eat_food_type_object(PlayerType *player_ptr, ItemEntity *o_ptr)
  */
 bool exe_eat_charge_of_magic_device(PlayerType *player_ptr, ItemEntity *o_ptr, INVENTORY_IDX item)
 {
-    if (o_ptr->tval != ItemKindType::STAFF && o_ptr->tval != ItemKindType::WAND) {
+    if (!o_ptr->is_wand_staff()) {
         return false;
     }
 
index e397482..21e14db 100644 (file)
@@ -483,7 +483,7 @@ static void describe_remaining(flavor_type *flavor_ptr)
         return;
     }
 
-    if (((flavor_ptr->o_ptr->tval == ItemKindType::STAFF) || (flavor_ptr->o_ptr->tval == ItemKindType::WAND))) {
+    if (flavor_ptr->o_ptr->is_wand_staff()) {
         describe_charges_staff_wand(flavor_ptr);
     } else if (flavor_ptr->o_ptr->tval == ItemKindType::ROD) {
         describe_charges_rod(flavor_ptr);
index 7671084..62145e1 100644 (file)
@@ -578,10 +578,7 @@ OBJECT_IDX drop_near(PlayerType *player_ptr, ItemEntity *j_ptr, PERCENTAGE chanc
 void floor_item_charges(FloorType *floor_ptr, INVENTORY_IDX item)
 {
     auto *o_ptr = &floor_ptr->o_list[item];
-    if ((o_ptr->tval != ItemKindType::STAFF) && (o_ptr->tval != ItemKindType::WAND)) {
-        return;
-    }
-    if (!o_ptr->is_known()) {
+    if (!o_ptr->is_wand_staff() || !o_ptr->is_known()) {
         return;
     }
 
index cba8259..47e3276 100644 (file)
@@ -103,7 +103,7 @@ bool eat_magic(PlayerType *player_ptr, int power)
         msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
         if (o_ptr->tval == ItemKindType::ROD) {
             o_ptr->timeout = k_ptr->pval * o_ptr->number;
-        } else if ((o_ptr->tval == ItemKindType::WAND) || (o_ptr->tval == ItemKindType::STAFF)) {
+        } else if (o_ptr->is_wand_staff()) {
             o_ptr->pval = 0;
         }
 
index 56df7c9..510e62e 100644 (file)
@@ -223,7 +223,7 @@ void process_eat_lite(PlayerType *player_ptr, MonsterAttackPlayer *monap_ptr)
  */
 bool process_un_power(PlayerType *player_ptr, MonsterAttackPlayer *monap_ptr)
 {
-    if (((monap_ptr->o_ptr->tval != ItemKindType::STAFF) && (monap_ptr->o_ptr->tval != ItemKindType::WAND)) || (monap_ptr->o_ptr->pval == 0)) {
+    if (!monap_ptr->o_ptr->is_wand_staff() || (monap_ptr->o_ptr->pval == 0)) {
         return false;
     }
 
index 907b72a..c5d12b8 100644 (file)
@@ -31,7 +31,7 @@ bool item_tester_hook_eatable(PlayerType *player_ptr, const ItemEntity *o_ptr)
 
     auto food_type = PlayerRace(player_ptr).food();
     if (food_type == PlayerRaceFoodType::MANA) {
-        if (o_ptr->tval == ItemKindType::STAFF || o_ptr->tval == ItemKindType::WAND) {
+        if (o_ptr->is_wand_staff()) {
             return true;
         }
     } else if (food_type == PlayerRaceFoodType::CORPSE) {
index 9320cdf..2e0de93 100644 (file)
@@ -125,7 +125,7 @@ bool recharge(PlayerType *player_ptr, int power)
         msg_format(_("魔力が逆流した!%sは完全に魔力を失った。", "The recharging backfires - %s is completely drained!"), o_name);
         if ((o_ptr->tval == ItemKindType::ROD) && (o_ptr->timeout < 10000)) {
             o_ptr->timeout = (o_ptr->timeout + 100) * 2;
-        } else if ((o_ptr->tval == ItemKindType::WAND) || (o_ptr->tval == ItemKindType::STAFF)) {
+        } else if (o_ptr->is_wand_staff()) {
             o_ptr->pval = 0;
         }
         return update_player(player_ptr);
index ffcc253..d4828db 100644 (file)
@@ -101,17 +101,13 @@ std::vector<PARAMETER_VALUE> store_same_magic_device_pvals(ItemEntity *j_ptr)
     auto list = std::vector<PARAMETER_VALUE>();
     for (INVENTORY_IDX i = 0; i < st_ptr->stock_num; i++) {
         auto *o_ptr = &st_ptr->stock[i];
-        if (o_ptr == j_ptr) {
-            continue;
-        }
-        if (o_ptr->bi_id != j_ptr->bi_id) {
-            continue;
-        }
-        if (o_ptr->tval != ItemKindType::STAFF && o_ptr->tval != ItemKindType::WAND) {
+        if ((o_ptr == j_ptr) || (o_ptr->bi_id != j_ptr->bi_id) || !o_ptr->is_wand_staff()) {
             continue;
         }
+
         list.push_back(o_ptr->pval);
     }
+
     return list;
 }
 
index 313eb9b..9b018cf 100644 (file)
@@ -184,6 +184,17 @@ bool BaseitemKey::is_wand_rod() const
     }
 }
 
+bool BaseitemKey::is_wand_staff() const
+{
+    switch (this->type_value) {
+    case ItemKindType::WAND:
+    case ItemKindType::STAFF:
+        return true;
+    default:
+        return false;
+    }
+}
+
 bool BaseitemKey::is_mushrooms() const
 {
     if (!this->subtype_value.has_value()) {
index bf5247d..8fc2bad 100644 (file)
@@ -45,6 +45,7 @@ public:
     bool has_unidentified_name() const;
     bool can_recharge() const;
     bool is_wand_rod() const;
+    bool is_wand_staff() const;
 
 private:
     ItemKindType type_value;
index 13626a5..258a032 100644 (file)
@@ -814,3 +814,8 @@ bool ItemEntity::is_wand_rod() const
 {
     return BaseitemKey(this->tval).is_wand_rod();
 }
+
+bool ItemEntity::is_wand_staff() const
+{
+    return BaseitemKey(this->tval).is_wand_staff();
+}
index 5ae1ade..fd62f9f 100644 (file)
@@ -124,6 +124,7 @@ public:
     bool has_unidentified_name() const;
     ItemKindType get_arrow_kind() const;
     bool is_wand_rod() const;
+    bool is_wand_staff() const;
 
 private:
     int get_baseitem_price() const;
index 9bab6b0..eb221ee 100644 (file)
  */
 void inven_item_charges(const ItemEntity &item)
 {
-    const auto tval = item.tval;
-    if ((tval != ItemKindType::STAFF) && (tval != ItemKindType::WAND)) {
-        return;
-    }
-
-    if (!item.is_known()) {
+    if (!item.is_wand_staff() || !item.is_known()) {
         return;
     }