OSDN Git Service

[Fix] 練気術師の練気による格闘ダメージ修正が機能していなかった
authortaotao54321 <taotao54321@gmail.com>
Sat, 6 Feb 2021 08:29:30 +0000 (17:29 +0900)
committertaotao54321 <taotao54321@gmail.com>
Sat, 6 Feb 2021 09:05:27 +0000 (18:05 +0900)
calc_num_blow() 内で計算したものが後から calc_to_damage() の戻り値で上書きされていた。
当該コードを calc_to_damage() に統合して解決。
ダメージ修正を計算するコード自体もトリッキーだったので、素直な実装にした。

プログラム設計の面では、現状以下のような問題が存在すると考えられる。今後の課題。

* 関数名から副作用の有無がわかりにくい。player_type* の内容を直接変更し
  ているのに calc_foo() といった名前になっているものがある。update_foo()
  などの方がわかりやすい。
* 副作用のない calc_foo() 関数の player_type* 引数に const が付いていれ
  ば本件のようなミスは防げる。ただし、下請け関数も含めて広範囲に const
  を付ける必要があるため作業量は多い。
* ステータス間に依存関係が存在するため、計算の順番を間違えないよう人手で
  チェックする必要がある。

src/player/player-status.c

index 3fccdd5..d8ab04f 100644 (file)
@@ -1742,12 +1742,6 @@ static s16b calc_num_blow(player_type *creature_ptr, int i)
                 num_blow++;
             if (blow_base > 58)
                 num_blow++;
-
-            MAGIC_NUM1 current_ki = get_current_ki(creature_ptr);
-            if (current_ki != i) {
-                creature_ptr->to_d[i] += current_ki / 5;
-                creature_ptr->dis_to_d[i] += current_ki / 5;
-            }
         } else {
             if (blow_base > 12)
                 num_blow++;
@@ -2941,6 +2935,11 @@ static s16b calc_to_damage(player_type *creature_ptr, INVENTORY_IDX slot, bool i
         } else {
             damage -= 10;
         }
+    } else if (creature_ptr->pclass == CLASS_FORCETRAINER) {
+        // 練気術師は格闘ダメージに (気)/5 の修正を得る。
+        if (is_martial_arts_mode(creature_ptr) && calc_hand == PLAYER_HAND_MAIN) {
+            damage += get_current_ki(creature_ptr) / 5;
+        }
     }
 
     if ((creature_ptr->realm1 == REALM_HEX) && object_is_cursed(o_ptr)) {
@@ -4121,4 +4120,4 @@ static player_hand main_attack_hand(player_type *creature_ptr)
         return PLAYER_HAND_MAIN;
     }
     return 0;
-}
\ No newline at end of file
+}