OSDN Git Service

[Refactor] #39963 Separated effect_player_elements() from switch_effects_player()
authorHourier <hourier@users.sourceforge.jp>
Sun, 3 May 2020 05:31:36 +0000 (14:31 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sun, 3 May 2020 05:33:29 +0000 (14:33 +0900)
src/effect/effect-player-switcher.c

index 4e7252e..66d1c83 100644 (file)
 #include "mutation.h"
 #include "object-curse.h"
 
+// \93Å\82ð\8f\9c\82­4\8c³\91f.
+void effect_player_elements(player_type *target_ptr, effect_player_type *ep_ptr, concptr attack_message,
+       HIT_POINT(*damage_func)(player_type*, HIT_POINT, concptr, int, bool))
+{
+       if (target_ptr->blind) msg_print(attack_message);
+
+       ep_ptr->get_damage = (*damage_func)(target_ptr, ep_ptr->dam, ep_ptr->killer, ep_ptr->monspell, FALSE);
+}
+
+
 /*!
  * @brief \96\82\96@\82Ì\8cø\89Ê\82É\82æ\82Á\82Ä\97l\81X\82È\83\81\83b\83Z\81[\82ð\8fo\97Í\82µ\82½\82è\97^\82¦\82é\83_\83\81\81[\83W\82Ì\91\9d\8c¸\82ð\8ds\82Á\82½\82è\82·\82é
  * @param target_ptr \83v\83\8c\81[\83\84\81[\82Ö\82Ì\8eQ\8fÆ\83|\83C\83\93\83^
@@ -24,33 +34,17 @@ void switch_effects_player(player_type *target_ptr, effect_player_type *ep_ptr)
        switch (ep_ptr->effect_type)
        {
        case GF_ACID:
-       {
-               if (target_ptr->blind) msg_print(_("\8e_\82Å\8dU\8c\82\82³\82ê\82½\81I", "You are hit by acid!"));
-
-               ep_ptr->get_damage = acid_dam(target_ptr, ep_ptr->dam, ep_ptr->killer, ep_ptr->monspell, FALSE);
-               break;
-       }
+               effect_player_elements(target_ptr, ep_ptr, _("\8e_\82Å\8dU\8c\82\82³\82ê\82½\81I", "You are hit by acid!"), acid_dam);
+               return;
        case GF_FIRE:
-       {
-               if (target_ptr->blind) msg_print(_("\89Î\89\8a\82Å\8dU\8c\82\82³\82ê\82½\81I", "You are hit by fire!"));
-
-               ep_ptr->get_damage = fire_dam(target_ptr, ep_ptr->dam, ep_ptr->killer, ep_ptr->monspell, FALSE);
-               break;
-       }
+               effect_player_elements(target_ptr, ep_ptr, _("\89Î\89\8a\82Å\8dU\8c\82\82³\82ê\82½\81I", "You are hit by fire!"), fire_dam);
+               return;
        case GF_COLD:
-       {
-               if (target_ptr->blind) msg_print(_("\97â\8bC\82Å\8dU\8c\82\82³\82ê\82½\81I", "You are hit by cold!"));
-
-               ep_ptr->get_damage = cold_dam(target_ptr, ep_ptr->dam, ep_ptr->killer, ep_ptr->monspell, FALSE);
-               break;
-       }
+               effect_player_elements(target_ptr, ep_ptr, _("\97â\8bC\82Å\8dU\8c\82\82³\82ê\82½\81I", "You are hit by cold!"), cold_dam);
+               return;
        case GF_ELEC:
-       {
-               if (target_ptr->blind) msg_print(_("\93d\8c\82\82Å\8dU\8c\82\82³\82ê\82½\81I", "You are hit by lightning!"));
-
-               ep_ptr->get_damage = elec_dam(target_ptr, ep_ptr->dam, ep_ptr->killer, ep_ptr->monspell, FALSE);
-               break;
-       }
+               effect_player_elements(target_ptr, ep_ptr, _("\93d\8c\82\82Å\8dU\8c\82\82³\82ê\82½\81I", "You are hit by lightning!"), elec_dam);
+               return;
        case GF_POIS:
        {
                bool double_resist = is_oppose_pois(target_ptr);