OSDN Git Service

[Refactor] #1578 Separated PlayerClass::lose_balance() from stun()
authorHourier <66951241+Hourier@users.noreply.github.com>
Wed, 22 Sep 2021 12:55:18 +0000 (21:55 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Thu, 23 Sep 2021 07:26:40 +0000 (16:26 +0900)
src/player-base/player-class.cpp
src/player-base/player-class.h
src/status/bad-status-setter.cpp

index fe6b980..a1afc0c 100644 (file)
@@ -5,7 +5,12 @@
  * @details 本クラス作成時点で責務に対する余裕はかなりあるので、適宜ここへ移してくること.
  */
 #include "player-base/player-class.h"
+#include "core/player-redraw-types.h"
+#include "core/player-update-types.h"
+#include "player/attack-defense-types.h"
+#include "player/special-defense-types.h"
 #include "system/player-type-definition.h"
+#include "util/bit-flags-calculator.h"
 
 PlayerClass::PlayerClass(player_type* player_ptr)
     : player_ptr(player_ptr)
@@ -27,3 +32,22 @@ bool PlayerClass::is_wizard() const
     is_wizard |= this->player_ptr->pclass == CLASS_ELEMENTALIST;
     return is_wizard;
 }
+
+bool PlayerClass::lose_balance()
+{
+    if (this->player_ptr->pclass != CLASS_SAMURAI) {
+        return false;
+    }
+
+    if (none_bits(this->player_ptr->special_defense, KATA_MASK)) {
+        return false;
+    }
+
+    reset_bits(this->player_ptr->special_defense, KATA_MASK);
+    this->player_ptr->update |= PU_BONUS;
+    this->player_ptr->update |= PU_MONSTERS;
+    this->player_ptr->redraw |= PR_STATE;
+    this->player_ptr->redraw |= PR_STATUS;
+    this->player_ptr->action = ACTION_NONE;
+    return true;
+}
index edbb5bd..20aa414 100644 (file)
@@ -10,6 +10,8 @@ public:
     bool can_resist_stun() const;
     bool is_wizard() const;
 
+    bool lose_balance();
+
 private:
     player_type *player_ptr;
 };
index 4fb1826..d91fca0 100644 (file)
@@ -413,7 +413,8 @@ bool BadStatusSetter::stun(const TIME_EFFECT tmp_v)
         return false;
     }
 
-    if (PlayerRace(this->player_ptr).equals(player_race_type::GOLEM) || PlayerClass(this->player_ptr).can_resist_stun()) {
+    PlayerClass player_class(this->player_ptr);
+    if (PlayerRace(this->player_ptr).equals(player_race_type::GOLEM) || player_class.can_resist_stun()) {
         v = 0;
     }
 
@@ -424,14 +425,8 @@ bool BadStatusSetter::stun(const TIME_EFFECT tmp_v)
         auto stun_mes = PlayerStun::get_stun_mes(new_aux);
         msg_print(stun_mes.data());
         this->decrease_int_wis(v);
-        if (this->player_ptr->special_defense & KATA_MASK) {
+        if (player_class.lose_balance()) {
             msg_print(_("型が崩れた。", "You lose your stance."));
-            this->player_ptr->special_defense &= ~(KATA_MASK);
-            this->player_ptr->update |= PU_BONUS;
-            this->player_ptr->update |= PU_MONSTERS;
-            this->player_ptr->redraw |= PR_STATE;
-            this->player_ptr->redraw |= PR_STATUS;
-            this->player_ptr->action = ACTION_NONE;
         }
 
         if (this->player_ptr->concent) {