OSDN Git Service

[Refactor] #1578 Separated process_stun_effect() from stun()
authorHourier <66951241+Hourier@users.noreply.github.com>
Wed, 22 Sep 2021 13:07:09 +0000 (22:07 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Thu, 23 Sep 2021 07:26:41 +0000 (16:26 +0900)
src/status/bad-status-setter.cpp
src/status/bad-status-setter.h

index 31efd27..026782c 100644 (file)
@@ -407,7 +407,6 @@ bool BadStatusSetter::slowness(const TIME_EFFECT tmp_v, bool do_dec)
  */
 bool BadStatusSetter::stun(const TIME_EFFECT tmp_v)
 {
-    auto notice = false;
     auto v = std::clamp<short>(tmp_v, 0, 10000);
     if (this->player_ptr->is_dead) {
         return false;
@@ -417,18 +416,8 @@ bool BadStatusSetter::stun(const TIME_EFFECT tmp_v)
         v = 0;
     }
 
-    auto player_stun = this->player_ptr->effects()->stun();
-    auto old_aux = player_stun->get_rank();
-    auto new_aux = PlayerStun::get_rank(v);
-    if (new_aux > old_aux) {
-        this->process_stun_status(new_aux, v);
-        notice = true;
-    } else if (new_aux < old_aux) {
-        this->clear_head(new_aux);
-        notice = true;
-    }
-
-    player_stun->set(v);
+    auto notice = this->process_stun_effect(v);
+    this->player_ptr->effects()->stun()->set(v);
     if (!notice) {
         return false;
     }
@@ -477,6 +466,23 @@ bool BadStatusSetter::cut(const TIME_EFFECT tmp_v)
     return true;
 }
 
+bool BadStatusSetter::process_stun_effect(const short v)
+{
+    auto old_aux = this->player_ptr->effects()->stun()->get_rank();
+    auto new_aux = PlayerStun::get_rank(v);
+    if (new_aux > old_aux) {
+        this->process_stun_status(new_aux, v);
+        return true;
+    }
+    
+    if (new_aux < old_aux) {
+        this->clear_head(new_aux);
+        return true;
+    }
+
+    return false;
+}
+
 void BadStatusSetter::process_stun_status(const PlayerStunRank new_aux, const short v)
 {
     auto stun_mes = PlayerStun::get_stun_mes(new_aux);
index e3eba85..f8c129e 100644 (file)
@@ -27,6 +27,7 @@ public:
 private:
     player_type *player_ptr;
 
+    bool process_stun_effect(const short v);
     void process_stun_status(const PlayerStunRank new_aux, const short v);
     void clear_head(const PlayerStunRank new_aux);
     void decrease_int_wis(const short v);