OSDN Git Service

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

index cf61612..4fb1826 100644 (file)
@@ -423,22 +423,7 @@ bool BadStatusSetter::stun(const TIME_EFFECT tmp_v)
     if (new_aux > old_aux) {
         auto stun_mes = PlayerStun::get_stun_mes(new_aux);
         msg_print(stun_mes.data());
-        if (randint1(1000) < v || one_in_(16)) {
-            msg_print(_("割れるような頭痛がする。", "A vicious blow hits your head."));
-            if (one_in_(3)) {
-                if (!has_sustain_int(this->player_ptr))
-                    (void)do_dec_stat(this->player_ptr, A_INT);
-                if (!has_sustain_wis(this->player_ptr))
-                    (void)do_dec_stat(this->player_ptr, A_WIS);
-            } else if (one_in_(2)) {
-                if (!has_sustain_int(this->player_ptr))
-                    (void)do_dec_stat(this->player_ptr, A_INT);
-            } else {
-                if (!has_sustain_wis(this->player_ptr))
-                    (void)do_dec_stat(this->player_ptr, A_WIS);
-            }
-        }
-
+        this->decrease_int_wis(v);
         if (this->player_ptr->special_defense & KATA_MASK) {
             msg_print(_("型が崩れた。", "You lose your stance."));
             this->player_ptr->special_defense &= ~(KATA_MASK);
@@ -519,6 +504,45 @@ bool BadStatusSetter::cut(const TIME_EFFECT tmp_v)
     return true;
 }
 
+/*!
+ * @todo 後で知能と賢さが両方減る確率を減らす.
+ */
+void BadStatusSetter::decrease_int_wis(const short v)
+{
+    if ((v <= randint1(1000)) && !one_in_(16)) {
+        return;
+    }
+
+    msg_print(_("割れるような頭痛がする。", "A vicious blow hits your head."));
+    auto rand = randint0(3);
+    switch (rand) {
+    case 0:
+        if (has_sustain_int(this->player_ptr) == 0) {
+            (void)do_dec_stat(this->player_ptr, A_INT);
+        }
+
+        if (has_sustain_wis(this->player_ptr) == 0) {
+            (void)do_dec_stat(this->player_ptr, A_WIS);
+        }
+
+        return;
+    case 1:
+        if (has_sustain_int(this->player_ptr) == 0) {
+            (void)do_dec_stat(this->player_ptr, A_INT);
+        }
+        
+        return;
+    case 2:
+        if (has_sustain_wis(this->player_ptr) == 0) {
+            (void)do_dec_stat(this->player_ptr, A_WIS);
+        }
+
+        return;
+    default:
+        return;
+    }
+}
+
 bool BadStatusSetter::process_cut_effect(const short v)
 {
     auto player_cut = this->player_ptr->effects()->cut();
@@ -528,7 +552,7 @@ bool BadStatusSetter::process_cut_effect(const short v)
         this->decrease_charisma(new_aux, v);
         return true;
     }
-    
+
     if (new_aux < old_aux) {
         this->stop_blooding(new_aux);
         return true;
index a0cb3b2..818e111 100644 (file)
@@ -26,6 +26,7 @@ public:
 private:
     player_type *player_ptr;
 
+    void decrease_int_wis(const short v);
     bool process_cut_effect(const short v);
     void decrease_charisma(const PlayerCutRank new_aux, const short v);
     void stop_blooding(const PlayerCutRank new_aux);