OSDN Git Service

[Refactor] #2267 AbstractEnchanterのコンストラクタで、強化/弱化に値する武器かどうかを判定するルーチンを追加した
authorHourier <66951241+Hourier@users.noreply.github.com>
Mon, 21 Feb 2022 13:14:28 +0000 (22:14 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Wed, 23 Feb 2022 02:34:38 +0000 (11:34 +0900)
src/object-enchant/apply-magic.cpp
src/object-enchant/weapon/abstract-weapon-enchanter.cpp
src/object-enchant/weapon/abstract-weapon-enchanter.h
src/object-enchant/weapon/apply-magic-weapon.cpp

index e629d3a..89673d1 100644 (file)
@@ -128,22 +128,14 @@ void apply_magic_to_object(PlayerType *player_ptr, ObjectType *o_ptr, DEPTH lev,
     case ItemKindType::SHOT:
     case ItemKindType::ARROW:
     case ItemKindType::BOLT:
-        if (power != 0) {
-            WeaponEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
-        }
-
+        WeaponEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
         break;
     case ItemKindType::POLEARM:
-        if ((power != 0) && (o_ptr->sval != SV_DEATH_SCYTHE)) {
-            WeaponEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
-        }
-
+        WeaponEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
         break;
     case ItemKindType::SWORD:
-        if ((power != 0) && (o_ptr->sval != SV_POISON_NEEDLE)) {
-            WeaponEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
-        }
-
+        // @todo いずれSwordEnchanter等作って分離する.
+        WeaponEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
         break;
     case ItemKindType::SHIELD:
         ShieldEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
index 794a8a1..c193b31 100644 (file)
@@ -1,6 +1,7 @@
 #include "object-enchant/weapon/abstract-weapon-enchanter.h"
 #include "object-enchant/object-boost.h"
 #include "object/tval-types.h"
+#include "sv-definition/sv-weapon-types.h"
 #include "system/object-type-definition.h"
 
 AbstractWeaponEnchanter::AbstractWeaponEnchanter(ObjectType *o_ptr, DEPTH level, int power)
@@ -8,6 +9,11 @@ AbstractWeaponEnchanter::AbstractWeaponEnchanter(ObjectType *o_ptr, DEPTH level,
     , level(level)
     , power(power)
 {
+    this->decide_skip();
+    if (this->should_skip) {
+        return;
+    }
+
     auto tohit1 = static_cast<short>(randint1(5) + m_bonus(5, this->level));
     auto todam1 = static_cast<short>(randint1(5) + m_bonus(5, this->level));
     auto tohit2 = static_cast<short>(m_bonus(10, this->level));
@@ -42,3 +48,18 @@ AbstractWeaponEnchanter::AbstractWeaponEnchanter(ObjectType *o_ptr, DEPTH level,
         }
     }
 }
+
+void AbstractWeaponEnchanter::decide_skip()
+{
+    this->should_skip = (this->o_ptr->tval == ItemKindType::SWORD) && (this->o_ptr->sval == SV_DIAMOND_EDGE);
+    this->should_skip |= (this->o_ptr->tval == ItemKindType::SWORD) && (this->o_ptr->sval == SV_POISON_NEEDLE) && (this->power != 0);
+    this->should_skip |= (this->o_ptr->tval == ItemKindType::POLEARM) && (this->o_ptr->sval == SV_DEATH_SCYTHE) && (this->power != 0);
+    auto other_weapons_enchant = this->o_ptr->tval == ItemKindType::DIGGING;
+    other_weapons_enchant |= this->o_ptr->tval == ItemKindType::HAFTED;
+    other_weapons_enchant |= this->o_ptr->tval == ItemKindType::BOW;
+    other_weapons_enchant |= this->o_ptr->tval == ItemKindType::SHOT;
+    other_weapons_enchant |= this->o_ptr->tval == ItemKindType::ARROW;
+    other_weapons_enchant |= this->o_ptr->tval == ItemKindType::BOLT;
+    other_weapons_enchant &= this->power != 0;
+    this->should_skip |= !other_weapons_enchant;
+}
index ee931d7..f5f918f 100644 (file)
@@ -13,4 +13,8 @@ protected:
     ObjectType *o_ptr;
     DEPTH level;
     int power;
+    bool should_skip = false;
+
+private:
+    void decide_skip();
 };
index 4a989b2..7d125d7 100644 (file)
@@ -38,8 +38,9 @@ WeaponEnchanter::WeaponEnchanter(PlayerType *player_ptr, ObjectType *o_ptr, DEPT
  */
 void WeaponEnchanter::apply_magic()
 {
-    if ((this->o_ptr->tval == ItemKindType::SWORD) && (this->o_ptr->sval == SV_DIAMOND_EDGE))
+    if (this->should_skip) {
         return;
+    }
 
     switch (this->o_ptr->tval) {
     case ItemKindType::DIGGING: {