OSDN Git Service

[Refactor] #2403 Separated apply-magic-digging.cpp/h from apply-magic.cpp
authorHourier <66951241+Hourier@users.noreply.github.com>
Fri, 11 Mar 2022 13:45:36 +0000 (22:45 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 13 Mar 2022 14:15:04 +0000 (23:15 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/object-enchant/apply-magic.cpp
src/object-enchant/weapon/apply-magic-digging.cpp [new file with mode: 0644]
src/object-enchant/weapon/apply-magic-digging.h [new file with mode: 0644]
src/object-enchant/weapon/apply-magic-weapon.cpp

index c4f7c10..f8f2b9a 100644 (file)
     <ClCompile Include="..\..\src\object-enchant\protector\apply-magic-hard-armor.cpp" />\r
     <ClCompile Include="..\..\src\object-enchant\weapon\abstract-weapon-enchanter.cpp" />\r
     <ClCompile Include="..\..\src\object-use\quaff\quaff-effects.cpp" />\r
+    <ClCompile Include="..\..\src\object-enchant\weapon\apply-magic-digging.cpp" />\r
     <ClCompile Include="..\..\src\object-enchant\weapon\apply-magic-sword.cpp" />\r
     <ClCompile Include="..\..\src\object-use\read\gbh-shirt-read-executor.cpp" />\r
     <ClCompile Include="..\..\src\object-use\read\parchment-read-executor.cpp" />\r
     <ClInclude Include="..\..\src\object-enchant\protector\apply-magic-hard-armor.h" />\r
     <ClInclude Include="..\..\src\object-enchant\weapon\abstract-weapon-enchanter.h" />\r
     <ClInclude Include="..\..\src\object-use\quaff\quaff-effects.h" />\r
+    <ClInclude Include="..\..\src\object-enchant\weapon\apply-magic-digging.h" />\r
     <ClInclude Include="..\..\src\object-enchant\weapon\apply-magic-sword.h" />\r
     <ClInclude Include="..\..\src\object-use\read\gbh-shirt-read-executor.h" />\r
     <ClInclude Include="..\..\src\object-use\read\parchment-read-executor.h" />\r
index 56309c9..5ea3138 100644 (file)
     <ClCompile Include="..\..\src\object-enchant\weapon\apply-magic-sword.cpp">\r
       <Filter>object-enchant\weapon</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\src\object-enchant\weapon\apply-magic-digging.cpp">\r
+      <Filter>object-enchant\weapon</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\src\combat\shoot.h">\r
     <ClInclude Include="..\..\src\object-enchant\weapon\apply-magic-sword.h">\r
       <Filter>object-enchant\weapon</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\..\src\object-enchant\weapon\apply-magic-digging.h">\r
+      <Filter>object-enchant\weapon</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <None Include="..\..\src\wall.bmp" />\r
index 6aaaab3..462cfcd 100644 (file)
@@ -619,6 +619,7 @@ hengband_SOURCES = \
        object-enchant/protector/apply-magic-soft-armor.cpp object-enchant/protector/apply-magic-soft-armor.h \
        \
        object-enchant/weapon/abstract-weapon-enchanter.cpp object-enchant/weapon/abstract-weapon-enchanter.h \
+       object-enchant/weapon/apply-magic-digging.cpp object-enchant/weapon/apply-magic-digging.h \
        object-enchant/weapon/apply-magic-sword.cpp object-enchant/weapon/apply-magic-sword.h \
        object-enchant/weapon/apply-magic-weapon.cpp object-enchant/weapon/apply-magic-weapon.h \
        \
index 4196a6f..eeef971 100644 (file)
@@ -31,6 +31,7 @@
 #include "object-enchant/tr-types.h"
 #include "object-enchant/trc-types.h"
 #include "object-enchant/trg-types.h"
+#include "object-enchant/weapon/apply-magic-digging.h"
 #include "object-enchant/weapon/apply-magic-sword.h"
 #include "object-enchant/weapon/apply-magic-weapon.h"
 #include "object/object-kind.h"
@@ -139,6 +140,8 @@ void apply_magic_to_object(PlayerType *player_ptr, ObjectType *o_ptr, DEPTH lev,
     // @todo ファクトリパターンで抽象化する.
     switch (o_ptr->tval) {
     case ItemKindType::DIGGING:
+        DiggingEnchanter(player_ptr, o_ptr, lev, power).apply_magic();
+        break;
     case ItemKindType::BOW:
     case ItemKindType::SHOT:
     case ItemKindType::ARROW:
diff --git a/src/object-enchant/weapon/apply-magic-digging.cpp b/src/object-enchant/weapon/apply-magic-digging.cpp
new file mode 100644 (file)
index 0000000..663efa8
--- /dev/null
@@ -0,0 +1,54 @@
+/*!
+ * @brief 掘削武器に耐性等の追加効果を付与する処理
+ * @date 2022/03/11
+ * @author Hourier
+ */
+
+#include "object-enchant/weapon/apply-magic-digging.h"
+#include "artifact/random-art-generator.h"
+#include "system/object-type-definition.h"
+#include "system/player-type-definition.h"
+
+/*!
+ * @brief 掘削武器強化クラスのコンストラクタ
+ * @param player_ptr プレイヤーへの参照ポインタ
+ * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
+ * @param level 生成基準階
+ * @param power 生成ランク
+ */
+DiggingEnchanter::DiggingEnchanter(PlayerType *player_ptr, ObjectType *o_ptr, DEPTH level, int power)
+    : AbstractWeaponEnchanter(o_ptr, level, power)
+    , player_ptr(player_ptr)
+{
+}
+
+/*!
+ * @brief 掘削武器に生成ランクごとの強化を与えるサブルーチン
+ * @details power > 2はデバッグ専用.
+ */
+void DiggingEnchanter::apply_magic()
+{
+    if (this->should_skip) {
+        return;
+    }
+
+    if (this->power > 1) {
+        if ((this->power > 2) || one_in_(30)) {
+            become_random_artifact(this->player_ptr, this->o_ptr, false);
+        } else {
+            this->o_ptr->ego_idx = EgoType::DIGGING;
+        }
+
+        return;
+    }
+
+    if (this->power < -1) {
+        this->o_ptr->pval = 0 - (5 + randint1(5));
+        return;
+    }
+
+    if (this->power < 0) {
+        this->o_ptr->pval = 0 - (this->o_ptr->pval);
+        return;
+    }
+}
diff --git a/src/object-enchant/weapon/apply-magic-digging.h b/src/object-enchant/weapon/apply-magic-digging.h
new file mode 100644 (file)
index 0000000..72d93a2
--- /dev/null
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "object-enchant/weapon/abstract-weapon-enchanter.h"
+#include "system/angband.h"
+
+class ObjectType;
+class PlayerType;
+class DiggingEnchanter : AbstractWeaponEnchanter {
+public:
+    DiggingEnchanter(PlayerType *player_ptr, ObjectType *o_ptr, DEPTH level, int power);
+    void apply_magic() override;
+
+protected:
+    void sval_enchant() override{};
+    void give_ego_index() override{};
+    void give_high_ego_index() override{};
+    void give_cursed() override{};
+
+private:
+    PlayerType *player_ptr;
+};
index add4f74..7323862 100644 (file)
@@ -43,21 +43,6 @@ void WeaponEnchanter::apply_magic()
     }
 
     switch (this->o_ptr->tval) {
-    case ItemKindType::DIGGING: {
-        if (this->power > 1) {
-            if ((this->power > 2) || one_in_(30)) {
-                become_random_artifact(this->player_ptr, this->o_ptr, false);
-            } else {
-                this->o_ptr->ego_idx = EgoType::DIGGING;
-            }
-        } else if (this->power < -1) {
-            this->o_ptr->pval = 0 - (5 + randint1(5));
-        } else if (this->power < 0) {
-            this->o_ptr->pval = 0 - (this->o_ptr->pval);
-        }
-
-        break;
-    }
     case ItemKindType::BOW: {
         if (this->power > 1) {
             if ((this->power > 2) || one_in_(20)) {