OSDN Git Service

[Refactor] #3286 Removed player-redraw-types.h
[hengbandforosx/hengbandosx.git] / src / mind / mind-blue-mage.cpp
1 #include "mind/mind-blue-mage.h"
2 #include "action/action-limited.h"
3 #include "avatar/avatar.h"
4 #include "blue-magic/blue-magic-caster.h"
5 #include "blue-magic/learnt-power-getter.h"
6 #include "core/asking-player.h"
7 #include "core/window-redrawer.h"
8 #include "game-option/disturbance-options.h"
9 #include "game-option/input-options.h"
10 #include "main/sound-definitions-table.h"
11 #include "main/sound-of-music.h"
12 #include "monster-race/race-ability-mask.h"
13 #include "mspell/monster-power-table.h"
14 #include "player-status/player-energy.h"
15 #include "player/player-status-table.h"
16 #include "realm/realm-types.h"
17 #include "spell/spell-info.h"
18 #include "status/bad-status-setter.h"
19 #include "status/base-status.h"
20 #include "system/player-type-definition.h"
21 #include "system/redrawing-flags-updater.h"
22 #include "term/screen-processor.h"
23 #include "timed-effect/player-stun.h"
24 #include "timed-effect/timed-effects.h"
25 #include "view/display-messages.h"
26
27 /*!
28  * @brief 青魔法コマンドのメインルーチン /
29  * do_cmd_cast calls this function if the player's class is 'Blue-Mage'.
30  * @return 処理を実行したらTRUE、キャンセルした場合FALSEを返す。
31  */
32 bool do_cmd_cast_learned(PlayerType *player_ptr)
33 {
34     if (cmd_limit_confused(player_ptr)) {
35         return false;
36     }
37
38     auto selected_spell = get_learned_power(player_ptr);
39     if (!selected_spell.has_value()) {
40         return false;
41     }
42
43     const auto &spell = monster_powers.at(selected_spell.value());
44     const auto need_mana = mod_need_mana(player_ptr, spell.smana, 0, REALM_NONE);
45     if (need_mana > player_ptr->csp) {
46         msg_print(_("MPが足りません。", "You do not have enough mana to use this power."));
47         if (!over_exert) {
48             return false;
49         }
50
51         if (!get_check(_("それでも挑戦しますか? ", "Attempt it anyway? "))) {
52             return false;
53         }
54     }
55
56     const auto chance = calculate_blue_magic_failure_probability(player_ptr, spell, need_mana);
57
58     if (randint0(100) < chance) {
59         if (flush_failure) {
60             flush();
61         }
62
63         msg_print(_("魔法をうまく唱えられなかった。", "You failed to concentrate hard enough!"));
64         sound(SOUND_FAIL);
65         if (RF_ABILITY_SUMMON_MASK.has(selected_spell.value())) {
66             cast_learned_spell(player_ptr, selected_spell.value(), false);
67         }
68     } else {
69         sound(SOUND_ZAP);
70         if (!cast_learned_spell(player_ptr, selected_spell.value(), true)) {
71             return false;
72         }
73     }
74
75     if (need_mana <= player_ptr->csp) {
76         player_ptr->csp -= need_mana;
77     } else {
78         int oops = need_mana;
79         player_ptr->csp = 0;
80         player_ptr->csp_frac = 0;
81         msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
82         (void)BadStatusSetter(player_ptr).mod_paralysis(randint1(5 * oops + 1));
83         chg_virtue(player_ptr, Virtue::KNOWLEDGE, -10);
84         if (randint0(100) < 50) {
85             bool perm = (randint0(100) < 25);
86             msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
87             (void)dec_stat(player_ptr, A_CON, 15 + randint1(10), perm);
88         }
89     }
90
91     PlayerEnergy(player_ptr).set_player_turn_energy(100);
92     auto &rfu = RedrawingFlagsUpdater::get_instance();
93     rfu.set_flag(MainWindowRedrawingFlag::MP);
94     player_ptr->window_flags |= PW_PLAYER | PW_SPELL;
95     return true;
96 }