OSDN Git Service

[Refactor] #3230 PlayerType::update に関わる処理を、RedrawingFlagsUpdaterに集約した
[hengbandforosx/hengbandosx.git] / src / mspell / mspell-dispel.cpp
1 #include "mspell/mspell-dispel.h"
2 #include "blue-magic/blue-magic-checker.h"
3 #include "core/player-redraw-types.h"
4 #include "core/player-update-types.h"
5 #include "core/speed-table.h"
6 #include "core/window-redrawer.h"
7 #include "mind/mind-force-trainer.h"
8 #include "mind/mind-magic-resistance.h"
9 #include "mind/mind-mirror-master.h"
10 #include "monster/monster-info.h"
11 #include "monster/monster-status-setter.h"
12 #include "monster/monster-status.h"
13 #include "mspell/mspell-result.h"
14 #include "mspell/mspell-util.h"
15 #include "player-info/race-info.h"
16 #include "player/attack-defense-types.h"
17 #include "player/player-status.h"
18 #include "realm/realm-song-numbers.h"
19 #include "spell-realm/spells-craft.h"
20 #include "spell-realm/spells-crusade.h"
21 #include "spell-realm/spells-demon.h"
22 #include "spell-realm/spells-hex.h"
23 #include "spell-realm/spells-song.h"
24 #include "status/bad-status-setter.h"
25 #include "status/body-improvement.h"
26 #include "status/buff-setter.h"
27 #include "status/element-resistance.h"
28 #include "status/shape-changer.h"
29 #include "status/sight-setter.h"
30 #include "status/temporary-resistance.h"
31 #include "system/player-type-definition.h"
32 #include "system/redrawing-flags-updater.h"
33 #include "view/display-messages.h"
34
35 /*!
36  * @brief プレイヤーに魔力消去効果を与える。
37  */
38 static void dispel_player(PlayerType *player_ptr)
39 {
40     (void)set_acceleration(player_ptr, 0, true);
41     set_lightspeed(player_ptr, 0, true);
42     (void)BadStatusSetter(player_ptr).set_deceleration(0, true);
43     (void)set_shield(player_ptr, 0, true);
44     (void)set_blessed(player_ptr, 0, true);
45     (void)set_tsuyoshi(player_ptr, 0, true);
46     (void)set_hero(player_ptr, 0, true);
47     (void)set_shero(player_ptr, 0, true);
48     (void)set_protevil(player_ptr, 0, true);
49     (void)set_invuln(player_ptr, 0, true);
50     (void)set_wraith_form(player_ptr, 0, true);
51     (void)set_pass_wall(player_ptr, 0, true);
52     (void)set_tim_res_nether(player_ptr, 0, true);
53     (void)set_tim_res_time(player_ptr, 0, true);
54     (void)set_tim_reflect(player_ptr, 0, true);
55     (void)set_multishadow(player_ptr, 0, true);
56     (void)set_dustrobe(player_ptr, 0, true);
57
58     (void)set_tim_invis(player_ptr, 0, true);
59     (void)set_tim_infra(player_ptr, 0, true);
60     (void)set_tim_esp(player_ptr, 0, true);
61     (void)set_tim_regen(player_ptr, 0, true);
62     (void)set_tim_stealth(player_ptr, 0, true);
63     (void)set_tim_levitation(player_ptr, 0, true);
64     (void)set_tim_sh_force(player_ptr, 0, true);
65     (void)set_tim_sh_fire(player_ptr, 0, true);
66     (void)set_tim_sh_holy(player_ptr, 0, true);
67     (void)set_tim_eyeeye(player_ptr, 0, true);
68     (void)set_magicdef(player_ptr, 0, true);
69     (void)set_resist_magic(player_ptr, 0, true);
70     (void)set_oppose_acid(player_ptr, 0, true);
71     (void)set_oppose_elec(player_ptr, 0, true);
72     (void)set_oppose_fire(player_ptr, 0, true);
73     (void)set_oppose_cold(player_ptr, 0, true);
74     (void)set_oppose_pois(player_ptr, 0, true);
75     (void)set_ultimate_res(player_ptr, 0, true);
76     (void)set_mimic(player_ptr, 0, MimicKindType::NONE, true);
77     (void)set_ele_attack(player_ptr, 0, 0);
78     (void)set_ele_immune(player_ptr, 0, 0);
79
80     if (player_ptr->special_attack & ATTACK_CONFUSE) {
81         player_ptr->special_attack &= ~(ATTACK_CONFUSE);
82         msg_print(_("手の輝きがなくなった。", "Your hands stop glowing."));
83     }
84
85     auto song_interruption = music_singing_any(player_ptr);
86     auto spellhex_interruption = SpellHex(player_ptr).is_spelling_any();
87
88     if (song_interruption || spellhex_interruption) {
89         if (song_interruption) {
90             set_interrupting_song_effect(player_ptr, get_singing_song_effect(player_ptr));
91             set_singing_song_effect(player_ptr, MUSIC_NONE);
92             msg_print(_("歌が途切れた。", "Your singing is interrupted."));
93         }
94         if (spellhex_interruption) {
95             SpellHex(player_ptr).interrupt_spelling();
96             msg_print(_("呪文が途切れた。", "Your casting is interrupted."));
97         }
98
99         player_ptr->action = ACTION_NONE;
100         auto &rfu = RedrawingFlagsUpdater::get_instance();
101         const auto flags_srf = {
102             StatusRedrawingFlag::BONUS,
103             StatusRedrawingFlag::HP,
104             StatusRedrawingFlag::MONSTER_STATUSES,
105         };
106         rfu.set_flags(flags_srf);
107         player_ptr->redraw |= (PR_MAP | PR_TIMED_EFFECT | PR_ACTION);
108         player_ptr->window_flags |= (PW_OVERHEAD | PW_DUNGEON);
109         player_ptr->energy_need += ENERGY_NEED();
110     }
111 }
112
113 /*!
114  * @brief RF4_DISPELの処理。魔力消去。 /
115  * @param m_idx 呪文を唱えるモンスターID
116  * @param player_ptr プレイヤーへの参照ポインタ
117  * @param t_idx 呪文を受けるモンスターID。プレイヤーの場合はdummyで0とする。
118  * @param target_type プレイヤーを対象とする場合MONSTER_TO_PLAYER、モンスターを対象とする場合MONSTER_TO_MONSTER
119  *
120  * プレイヤーが対象ならラーニング可。
121  */
122 MonsterSpellResult spell_RF4_DISPEL(MONSTER_IDX m_idx, PlayerType *player_ptr, MONSTER_IDX t_idx, int target_type)
123 {
124     auto res = MonsterSpellResult::make_valid();
125     res.learnable = target_type == MONSTER_TO_PLAYER;
126
127     mspell_cast_msg_blind msg(_("%s^が何かを力強くつぶやいた。", "%s^ mumbles powerfully."),
128         _("%s^が魔力消去の呪文を念じた。", "%s^ invokes a dispel magic."), _("%s^が%sに対して魔力消去の呪文を念じた。", "%s^ invokes a dispel magic at %s."));
129
130     monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
131
132     if (target_type == MONSTER_TO_PLAYER) {
133         dispel_player(player_ptr);
134         if (player_ptr->riding) {
135             dispel_monster_status(player_ptr, player_ptr->riding);
136         }
137
138         if (is_echizen(player_ptr)) {
139             msg_print(_("やりやがったな!", ""));
140         } else if (is_chargeman(player_ptr)) {
141             if (randint0(2) == 0) {
142                 msg_print(_("ジュラル星人め!", ""));
143             } else {
144                 msg_print(_("弱い者いじめは止めるんだ!", ""));
145             }
146         }
147
148         return res;
149     }
150
151     if (target_type == MONSTER_TO_MONSTER) {
152         if (t_idx == player_ptr->riding) {
153             dispel_player(player_ptr);
154         }
155
156         dispel_monster_status(player_ptr, t_idx);
157     }
158
159     return res;
160 }