OSDN Git Service

[Refactor] #1370 Moved display_potion_throw() from cmd-throw.cpp to throw-util.cpp/h
authorHourier <grapefox.whitelucifer.0408@gmail.com>
Thu, 19 Aug 2021 16:10:34 +0000 (01:10 +0900)
committerHourier <grapefox.whitelucifer.0408@gmail.com>
Thu, 19 Aug 2021 16:10:39 +0000 (01:10 +0900)
src/action/throw-util.cpp
src/action/throw-util.h
src/cmd-item/cmd-throw.cpp

index 6f9a523..9853621 100644 (file)
@@ -40,6 +40,7 @@
 #include "object-hook/hook-weapon.h"
 #include "object/item-tester-hooker.h"
 #include "object/item-use-flags.h"
+#include "object/object-broken.h"
 #include "object/object-flags.h"
 #include "object/object-info.h"
 #include "object/object-kind.h"
@@ -217,6 +218,35 @@ void it_type::display_figurine_throw()
         msg_print(_("これはあまり良くない気がする。", "You have a bad feeling about this."));
 }
 
+void it_type::display_potion_throw()
+{
+    if (!object_is_potion(this->q_ptr))
+        return;
+
+    if (!this->hit_body && !this->hit_wall && (randint1(100) >= this->corruption_possibility)) {
+        this->corruption_possibility = 0;
+        return;
+    }
+
+    msg_format(_("%sは砕け散った!", "The %s shatters!"), this->o_name);
+    if (!potion_smash_effect(this->creature_ptr, 0, this->y, this->x, this->q_ptr->k_idx)) {
+        this->do_drop = false;
+        return;
+    }
+
+    monster_type *angry_m_ptr = &this->creature_ptr->current_floor_ptr->m_list[this->creature_ptr->current_floor_ptr->grid_array[this->y][this->x].m_idx];
+    if ((this->creature_ptr->current_floor_ptr->grid_array[this->y][this->x].m_idx == 0) || !is_friendly(angry_m_ptr) || monster_invulner_remaining(angry_m_ptr)) {
+        this->do_drop = false;
+        return;
+    }
+
+    GAME_TEXT angry_m_name[MAX_NLEN];
+    monster_desc(this->creature_ptr, angry_m_name, angry_m_ptr, 0);
+    msg_format(_("%sは怒った!", "%^s gets angry!"), angry_m_name);
+    set_hostile(this->creature_ptr, &this->creature_ptr->current_floor_ptr->m_list[this->creature_ptr->current_floor_ptr->grid_array[this->y][this->x].m_idx]);
+    this->do_drop = false;
+}
+
 bool it_type::check_what_throw()
 {
     if (this->shuriken >= 0) {
index f4d0297..7fbb802 100644 (file)
@@ -61,6 +61,7 @@ public:
     void set_racial_chance();
     void exe_throw();
     void display_figurine_throw();
+    void display_potion_throw();
 
 private:
     player_type *creature_ptr;
index e81308d..a9ce898 100644 (file)
@@ -70,35 +70,6 @@ ThrowCommand::ThrowCommand(player_type* creature_ptr)
 {
 }
 
-void display_potion_throw(player_type *creature_ptr, it_type *it_ptr)
-{
-    if (!object_is_potion(it_ptr->q_ptr))
-        return;
-
-    if (!it_ptr->hit_body && !it_ptr->hit_wall && (randint1(100) >= it_ptr->corruption_possibility)) {
-        it_ptr->corruption_possibility = 0;
-        return;
-    }
-
-    msg_format(_("%sは砕け散った!", "The %s shatters!"), it_ptr->o_name);
-    if (!potion_smash_effect(creature_ptr, 0, it_ptr->y, it_ptr->x, it_ptr->q_ptr->k_idx)) {
-        it_ptr->do_drop = false;
-        return;
-    }
-
-    monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[it_ptr->y][it_ptr->x].m_idx];
-    if ((creature_ptr->current_floor_ptr->grid_array[it_ptr->y][it_ptr->x].m_idx == 0) || !is_friendly(m_ptr) || monster_invulner_remaining(m_ptr)) {
-        it_ptr->do_drop = false;
-        return;
-    }
-
-    GAME_TEXT m_name[MAX_NLEN];
-    monster_desc(creature_ptr, m_name, m_ptr, 0);
-    msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
-    set_hostile(creature_ptr, &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[it_ptr->y][it_ptr->x].m_idx]);
-    it_ptr->do_drop = false;
-}
-
 static void display_boomerang_throw(player_type *creature_ptr, it_type *it_ptr)
 {
     if ((it_ptr->back_chance > 37) && !creature_ptr->blind && (it_ptr->item >= 0)) {
@@ -249,7 +220,7 @@ bool ThrowCommand::do_cmd_throw(int mult, bool boomerang, OBJECT_IDX shuriken)
 
     it_ptr->corruption_possibility = (it_ptr->hit_body ? breakage_chance(this->creature_ptr, it_ptr->q_ptr, this->creature_ptr->pclass == CLASS_ARCHER, 0) : 0);
     it_ptr->display_figurine_throw();
-    display_potion_throw(this->creature_ptr, it_ptr);
+    it_ptr->display_potion_throw();
     check_boomerang_throw(this->creature_ptr, it_ptr);
     process_boomerang_back(this->creature_ptr, it_ptr);
     drop_thrown_item(this->creature_ptr, it_ptr);