OSDN Git Service

e629c35e6dbd1054cd0814fc32a07e436f2781e2
[hengbandforosx/hengbandosx.git] / src / cmd-action / cmd-spell.cpp
1 /*!
2  * @brief 魔法のインターフェイスと発動 / Purpose: Do everything for each spell
3  * @date 2013/12/31
4  * @author
5  * 2013 Deskull rearranged comment for Doxygen.
6  */
7
8 #include "cmd-action/cmd-spell.h"
9 #include "action/action-limited.h"
10 #include "autopick/autopick-reader-writer.h"
11 #include "avatar/avatar.h"
12 #include "cmd-action/cmd-mind.h"
13 #include "cmd-io/cmd-dump.h"
14 #include "core/asking-player.h"
15 #include "core/player-redraw-types.h"
16 #include "core/player-update-types.h"
17 #include "core/stuff-handler.h"
18 #include "core/window-redrawer.h"
19 #include "floor/floor-object.h"
20 #include "game-option/disturbance-options.h"
21 #include "game-option/input-options.h"
22 #include "game-option/text-display-options.h"
23 #include "grid/grid.h"
24 #include "inventory/inventory-slot-types.h"
25 #include "io/command-repeater.h"
26 #include "io/input-key-acceptor.h"
27 #include "io/input-key-requester.h"
28 #include "io/write-diary.h"
29 #include "locale/japanese.h"
30 #include "main/sound-definitions-table.h"
31 #include "main/sound-of-music.h"
32 #include "object-hook/hook-magic.h"
33 #include "object/item-tester-hooker.h"
34 #include "object/item-use-flags.h"
35 #include "object/object-info.h"
36 #include "player-base/player-class.h"
37 #include "player-info/class-info.h"
38 #include "player-info/samurai-data-type.h"
39 #include "player-info/self-info.h"
40 #include "player-status/player-energy.h"
41 #include "player/attack-defense-types.h"
42 #include "player/eldritch-horror.h"
43 #include "player/player-damage.h"
44 #include "player/player-realm.h"
45 #include "player/player-skill.h"
46 #include "player/player-status.h"
47 #include "player/special-defense-types.h"
48 #include "realm/realm-names-table.h"
49 #include "spell-kind/spells-random.h"
50 #include "spell-kind/spells-sight.h"
51 #include "spell-realm/spells-hex.h"
52 #include "spell/range-calc.h"
53 #include "spell/spell-info.h"
54 #include "spell/spells-describer.h"
55 #include "spell/spells-execution.h"
56 #include "spell/spells-summon.h"
57 #include "status/action-setter.h"
58 #include "status/bad-status-setter.h"
59 #include "status/base-status.h"
60 #include "status/experience.h"
61 #include "system/baseitem-info.h"
62 #include "system/floor-type-definition.h"
63 #include "system/item-entity.h"
64 #include "system/player-type-definition.h"
65 #include "system/redrawing-flags-updater.h"
66 #include "term/screen-processor.h"
67 #include "term/z-form.h"
68 #include "timed-effect/player-blindness.h"
69 #include "timed-effect/timed-effects.h"
70 #include "util/bit-flags-calculator.h"
71 #include "util/int-char-converter.h"
72 #include "view/display-messages.h"
73 #include "view/display-util.h"
74
75 static const int extra_magic_gain_exp = 4;
76
77 concptr KWD_DAM = _("損傷:", "dam ");
78 concptr KWD_RANGE = _("射程:", "rng ");
79 concptr KWD_DURATION = _("期間:", "dur ");
80 concptr KWD_SPHERE = _("範囲:", "range ");
81 concptr KWD_HEAL = _("回復:", "heal ");
82 concptr KWD_MANA = _("MP回復:", "heal SP ");
83 concptr KWD_POWER _("効力:", "power ");
84 concptr KWD_RANDOM = _("ランダム", "random");
85
86 /*!
87  * 魔法領域フラグ管理テーブル /
88  * Zangband uses this array instead of the spell flags table, as there
89  * are 5 realms of magic, each with 4 spellbooks and 8 spells per book -- TY
90  */
91 const uint32_t fake_spell_flags[4] = { 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
92
93 /*!
94  * @brief
95  * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
96  * @param str キャプション
97  * @param dice ダイス数
98  * @param sides ダイス目
99  * @param base 固定値
100  * @return フォーマットに従い整形された文字列
101  */
102 std::string info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
103 {
104     /* Fix value */
105     if (!dice) {
106         return format("%s%d", str, base);
107     }
108
109     /* Dice only */
110     else if (!base) {
111         return format("%s%dd%d", str, dice, sides);
112     }
113
114     /* Dice plus base value */
115     else {
116         return format("%s%dd%d%+d", str, dice, sides, base);
117     }
118 }
119
120 /*!
121  * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
122  * @param dice ダイス数
123  * @param sides ダイス目
124  * @param base 固定値
125  * @return フォーマットに従い整形された文字列
126  */
127 std::string info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
128 {
129     return info_string_dice(_("損傷:", "dam "), dice, sides, base);
130 }
131
132 /*!
133  * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
134  * @param base 固定値
135  * @param sides ダイス目
136  * @return フォーマットに従い整形された文字列
137  */
138 std::string info_duration(int base, DICE_SID sides)
139 {
140     return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
141 }
142
143 /*!
144  * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
145  * @param range 効果範囲
146  * @return フォーマットに従い整形された文字列
147  */
148 std::string info_range(POSITION range)
149 {
150     return format(_("範囲:%d", "range %d"), range);
151 }
152
153 /*!
154  * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
155  * @param dice ダイス数
156  * @param sides ダイス目
157  * @param base 固定値
158  * @return フォーマットに従い整形された文字列
159  */
160 std::string info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
161 {
162     return info_string_dice(_("回復:", "heal "), dice, sides, base);
163 }
164
165 /*!
166  * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
167  * @param base 固定値
168  * @param sides ダイス目
169  * @return フォーマットに従い整形された文字列
170  */
171 std::string info_delay(int base, DICE_SID sides)
172 {
173     return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
174 }
175
176 /*!
177  * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
178  * @param dam 固定値
179  * @return フォーマットに従い整形された文字列
180  */
181 std::string info_multi_damage(int dam)
182 {
183     return format(_("損傷:各%d", "dam %d each"), dam);
184 }
185
186 /*!
187  * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
188  * @param dice ダイス数
189  * @param sides ダイス目
190  * @return フォーマットに従い整形された文字列
191  */
192 std::string info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
193 {
194     return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
195 }
196
197 /*!
198  * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
199  * @param power 固定値
200  * @return フォーマットに従い整形された文字列
201  */
202 std::string info_power(int power)
203 {
204     return format(_("効力:%d", "power %d"), power);
205 }
206
207 /*!
208  * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
209  * @param dice ダイス数
210  * @param sides ダイス目
211  * @return フォーマットに従い整形された文字列
212  */
213 /*
214  * Generate power info string such as "power 1d100"
215  */
216 std::string info_power_dice(DICE_NUMBER dice, DICE_SID sides)
217 {
218     return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
219 }
220
221 /*!
222  * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
223  * @param rad 効果半径
224  * @return フォーマットに従い整形された文字列
225  */
226 std::string info_radius(POSITION rad)
227 {
228     return format(_("半径:%d", "rad %d"), rad);
229 }
230
231 /*!
232  * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
233  * @param weight 最大重量
234  * @return フォーマットに従い整形された文字列
235  */
236 std::string info_weight(WEIGHT weight)
237 {
238 #ifdef JP
239     return format("最大重量:%d.%dkg", lb_to_kg_integer(weight), lb_to_kg_fraction(weight));
240 #else
241     return format("max wgt %d", weight / 10);
242 #endif
243 }
244
245 /*!
246  * @brief 魔法が利用可能かどうかを返す /
247  * Determine if a spell is "okay" for the player to cast or study
248  * The spell must be legible, not forgotten, and also, to cast,
249  * it must be known, and to study, it must not be known.
250  * @param spell 呪文ID
251  * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
252  * @param study_pray 祈りの学習判定目的ならばTRUE
253  * @param use_realm 魔法領域ID
254  * @return 失敗率(%)
255  */
256 static bool spell_okay(PlayerType *player_ptr, int spell, bool learned, bool study_pray, int use_realm)
257 {
258     const magic_type *s_ptr;
259
260     /* Access the spell */
261     if (!is_magic(use_realm)) {
262         s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
263     } else {
264         s_ptr = &mp_ptr->info[use_realm - 1][spell];
265     }
266
267     /* Spell is illegal */
268     if (s_ptr->slevel > player_ptr->lev) {
269         return false;
270     }
271
272     /* Spell is forgotten */
273     if ((use_realm == player_ptr->realm2) ? (player_ptr->spell_forgotten2 & (1UL << spell)) : (player_ptr->spell_forgotten1 & (1UL << spell))) {
274         /* Never okay */
275         return false;
276     }
277
278     if (PlayerClass(player_ptr).is_every_magic()) {
279         return true;
280     }
281
282     /* Spell is learned */
283     if ((use_realm == player_ptr->realm2) ? (player_ptr->spell_learned2 & (1UL << spell)) : (player_ptr->spell_learned1 & (1UL << spell))) {
284         /* Always true */
285         return !study_pray;
286     }
287
288     /* Okay to study, not to cast */
289     return !learned;
290 }
291
292 /*!
293  * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
294  * Allow user to choose a spell/prayer from the given book.
295  * @param sn 選択した魔法IDを返す参照ポインタ
296  * @param prompt 魔法を利用する際の動詞表記
297  * @param sval 魔道書のsval
298  * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
299  * @param use_realm 魔法領域ID
300  * @return
301  * <pre>
302  * If a valid spell is chosen, saves it in '*sn' and returns TRUE
303  * If the user hits escape, returns FALSE, and set '*sn' to -1
304  * If there are no legal choices, returns FALSE, and sets '*sn' to -2
305  * The "prompt" should be "cast", "recite", or "study"
306  * The "known" should be TRUE for cast/pray, FALSE for study
307  * </pre>
308  */
309 static int get_spell(PlayerType *player_ptr, SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, int16_t use_realm)
310 {
311     int i;
312     SPELL_IDX spell = -1;
313     int num = 0;
314     SPELL_IDX spells[64];
315     bool flag, redraw, okay;
316     char choice;
317     char out_val[160];
318     concptr p;
319     COMMAND_CODE code;
320     int menu_line = (use_menu ? 1 : 0);
321
322     /* Get the spell, if available */
323     if (repeat_pull(&code)) {
324         *sn = (SPELL_IDX)code;
325         /* Verify the spell */
326         if (spell_okay(player_ptr, *sn, learned, false, use_realm)) {
327             /* Success */
328             return true;
329         }
330     }
331
332     p = spell_category_name(mp_ptr->spell_book);
333
334     /* Extract spells */
335     for (spell = 0; spell < 32; spell++) {
336         /* Check for this spell */
337         if ((fake_spell_flags[sval] & (1UL << spell))) {
338             /* Collect this spell */
339             spells[num++] = spell;
340         }
341     }
342
343     /* Assume no usable spells */
344     okay = false;
345
346     /* Assume no spells available */
347     (*sn) = -2;
348
349     /* Check for "okay" spells */
350     for (i = 0; i < num; i++) {
351         /* Look for "okay" spells */
352         if (spell_okay(player_ptr, spells[i], learned, false, use_realm)) {
353             okay = true;
354         }
355     }
356
357     /* No "okay" spells */
358     if (!okay) {
359         return false;
360     }
361
362     PlayerClass pc(player_ptr);
363     auto is_every_magic = pc.is_every_magic();
364     if (((use_realm) != player_ptr->realm1) && ((use_realm) != player_ptr->realm2) && !is_every_magic) {
365         return false;
366     }
367     if (is_every_magic && !is_magic(use_realm)) {
368         return false;
369     }
370     if (pc.equals(PlayerClassType::RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) {
371         return false;
372     }
373
374     /* Assume cancelled */
375     *sn = (-1);
376
377     flag = false;
378     redraw = false;
379
380     player_ptr->window_flags |= (PW_SPELL);
381     handle_stuff(player_ptr);
382
383     /* Build a prompt (accept all spells) */
384 #ifdef JP
385     const auto verb = conjugate_jverb(prompt, JVerbConjugationType::AND);
386     (void)strnfmt(out_val, 78, "(%s^:%c-%c, '*'で一覧, ESCで中断) どの%sを%s^ますか? ", p, I2A(0), I2A(num - 1), p, verb.data());
387 #else
388     (void)strnfmt(out_val, 78, "(%s^s %c-%c, *=List, ESC=exit) %s^ which %s? ", p, I2A(0), I2A(num - 1), prompt, p);
389 #endif
390
391     choice = (always_show_list || use_menu) ? ESCAPE : 1;
392     while (!flag) {
393         if (choice == ESCAPE) {
394             choice = ' ';
395         } else if (!get_com(out_val, &choice, true)) {
396             break;
397         }
398
399         auto should_redraw_cursor = true;
400         if (use_menu && choice != ' ') {
401             switch (choice) {
402             case '0': {
403                 screen_load();
404                 return false;
405             }
406
407             case '8':
408             case 'k':
409             case 'K': {
410                 menu_line += (num - 1);
411                 break;
412             }
413
414             case '2':
415             case 'j':
416             case 'J': {
417                 menu_line++;
418                 break;
419             }
420
421             case 'x':
422             case 'X':
423             case '\r':
424             case '\n': {
425                 i = menu_line - 1;
426                 should_redraw_cursor = false;
427                 break;
428             }
429             }
430             if (menu_line > num) {
431                 menu_line -= num;
432             }
433             /* Display a list of spells */
434             print_spells(player_ptr, menu_line, spells, num, 1, 15, use_realm);
435             if (should_redraw_cursor) {
436                 continue;
437             }
438         } else {
439             /* Request redraw */
440             if ((choice == ' ') || (choice == '*') || (choice == '?')) {
441                 /* Show the list */
442                 if (!redraw) {
443                     redraw = true;
444                     screen_save();
445
446                     /* Display a list of spells */
447                     print_spells(player_ptr, menu_line, spells, num, 1, 15, use_realm);
448                 }
449
450                 /* Hide the list */
451                 else {
452                     if (use_menu) {
453                         continue;
454                     }
455
456                     /* Hide list */
457                     redraw = false;
458                     screen_load();
459                 }
460
461                 /* Redo asking */
462                 continue;
463             }
464
465             i = A2I(choice);
466         }
467
468         /* Totally Illegal */
469         if ((i < 0) || (i >= num)) {
470             bell();
471             continue;
472         }
473
474         /* Save the spell index */
475         spell = spells[i];
476
477         /* Require "okay" spells */
478         if (!spell_okay(player_ptr, spell, learned, false, use_realm)) {
479             bell();
480 #ifdef JP
481             msg_format("その%sを%sことはできません。", p, prompt);
482 #else
483             msg_format("You may not %s that %s.", prompt, p);
484 #endif
485
486             continue;
487         }
488
489         /* Stop the loop */
490         flag = true;
491     }
492
493     if (redraw) {
494         screen_load();
495     }
496
497     player_ptr->window_flags |= (PW_SPELL);
498     handle_stuff(player_ptr);
499
500     /* Abort if needed */
501     if (!flag) {
502         return false;
503     }
504
505     /* Save the choice */
506     (*sn) = spell;
507
508     repeat_push((COMMAND_CODE)spell);
509
510     /* Success */
511     return true;
512 }
513
514 /*!
515  * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
516  * @param browse_only 魔法と技能の閲覧を行うならばTRUE
517  * @return 魔道書を一冊も持っていないならTRUEを返す
518  */
519 static void confirm_use_force(PlayerType *player_ptr, bool browse_only)
520 {
521     char which;
522     COMMAND_CODE code;
523
524     /* Get the item index */
525     if (repeat_pull(&code) && (code == INVEN_FORCE)) {
526         browse_only ? do_cmd_mind_browse(player_ptr) : do_cmd_mind(player_ptr);
527         return;
528     }
529
530     /* Show the prompt */
531     prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
532
533     while (true) {
534         /* Get a key */
535         which = inkey();
536
537         if (which == ESCAPE) {
538             break;
539         } else if (which == 'w') {
540             repeat_push(INVEN_FORCE);
541             break;
542         }
543     }
544
545     /* Clear the prompt line */
546     prt("", 0, 0);
547
548     if (which == 'w') {
549         browse_only ? do_cmd_mind_browse(player_ptr) : do_cmd_mind(player_ptr);
550     }
551 }
552
553 static FuncItemTester get_castable_spellbook_tester(PlayerType *player_ptr)
554 {
555     return FuncItemTester([](auto p_ptr, auto o_ptr) { return check_book_realm(p_ptr, o_ptr->bi_key); }, player_ptr);
556 }
557
558 static FuncItemTester get_learnable_spellbook_tester(PlayerType *player_ptr)
559 {
560     if (player_ptr->realm2 == REALM_NONE) {
561         return get_castable_spellbook_tester(player_ptr);
562     } else {
563         return FuncItemTester(item_tester_learn_spell, player_ptr);
564     }
565 }
566
567 /*!
568  * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
569  * Peruse the spells/prayers in a book
570  * @details
571  * <pre>
572  * Note that *all* spells in the book are listed
573  *
574  * Note that browsing is allowed while confused or blind,
575  * and in the dark, primarily to allow browsing in stores.
576  * </pre>
577  */
578 void do_cmd_browse(PlayerType *player_ptr)
579 {
580     OBJECT_IDX item;
581     SPELL_IDX spell = -1;
582     int num = 0;
583
584     SPELL_IDX spells[64];
585
586     /* Warriors are illiterate */
587     PlayerClass pc(player_ptr);
588     if (!(player_ptr->realm1 || player_ptr->realm2) && !pc.is_every_magic()) {
589         msg_print(_("本を読むことができない!", "You cannot read books!"));
590         return;
591     }
592
593     pc.break_samurai_stance({ SamuraiStanceType::MUSOU });
594
595     if (pc.equals(PlayerClassType::FORCETRAINER)) {
596         if (player_has_no_spellbooks(player_ptr)) {
597             confirm_use_force(player_ptr, true);
598             return;
599         }
600     }
601
602     /* Restrict choices to "useful" books */
603     auto item_tester = get_learnable_spellbook_tester(player_ptr);
604
605     constexpr auto q = _("どの本を読みますか? ", "Browse which book? ");
606     constexpr auto s = _("読める本がない。", "You have no books that you can read.");
607     constexpr auto options = USE_INVEN | USE_FLOOR;
608     const auto *o_ptr = choose_object(player_ptr, &item, q, s, options | (pc.equals(PlayerClassType::FORCETRAINER) ? USE_FORCE : 0), item_tester);
609     if (o_ptr == nullptr) {
610         if (item == INVEN_FORCE) /* the_force */
611         {
612             do_cmd_mind_browse(player_ptr);
613             return;
614         }
615         return;
616     }
617
618     /* Access the item's sval */
619     const auto tval = o_ptr->bi_key.tval();
620     const auto sval = o_ptr->bi_key.sval().value();
621     short use_realm = tval2realm(tval);
622
623     /* Track the object kind */
624     object_kind_track(player_ptr, o_ptr->bi_id);
625     handle_stuff(player_ptr);
626
627     /* Extract spells */
628     for (spell = 0; spell < 32; spell++) {
629         /* Check for this spell */
630         if ((fake_spell_flags[sval] & (1UL << spell))) {
631             /* Collect this spell */
632             spells[num++] = spell;
633         }
634     }
635
636     screen_save();
637     prt("", 0, 0);
638
639     /* Keep browsing spells.  Exit browsing on cancel. */
640     while (true) {
641         /* Ask for a spell, allow cancel */
642         if (!get_spell(player_ptr, &spell, _("読む", "browse"), sval, true, use_realm)) {
643             /* If cancelled, leave immediately. */
644             if (spell == -1) {
645                 break;
646             }
647
648             /* Display a list of spells */
649             print_spells(player_ptr, 0, spells, num, 1, 15, use_realm);
650
651             /* Notify that there's nothing to see, and wait. */
652             if (use_realm == REALM_HISSATSU) {
653                 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
654             } else {
655                 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
656             }
657             (void)inkey();
658
659             screen_load();
660
661             return;
662         }
663
664         /* Clear lines, position cursor  (really should use strlen here) */
665         term_erase(14, 14, 255);
666         term_erase(14, 13, 255);
667         term_erase(14, 12, 255);
668         term_erase(14, 11, 255);
669
670         const auto spell_desc = exe_spell(player_ptr, use_realm, spell, SpellProcessType::DESCRIPTION);
671         display_wrap_around(spell_desc.value(), 62, 11, 15);
672     }
673     screen_load();
674 }
675
676 /*!
677  * @brief プレイヤーの第二魔法領域を変更する /
678  * @param player_ptr プレイヤーへの参照ポインタ
679  * @param next_realm 変更先の魔法領域ID
680  */
681 static void change_realm2(PlayerType *player_ptr, int16_t next_realm)
682 {
683     int i, j = 0;
684     char tmp[80];
685
686     for (i = 0; i < 64; i++) {
687         player_ptr->spell_order[j] = player_ptr->spell_order[i];
688         if (player_ptr->spell_order[i] < 32) {
689             j++;
690         }
691     }
692     for (; j < 64; j++) {
693         player_ptr->spell_order[j] = 99;
694     }
695
696     for (i = 32; i < 64; i++) {
697         player_ptr->spell_exp[i] = PlayerSkill::spell_exp_at(PlayerSkillRank::UNSKILLED);
698     }
699     player_ptr->spell_learned2 = 0L;
700     player_ptr->spell_worked2 = 0L;
701     player_ptr->spell_forgotten2 = 0L;
702
703     constexpr auto mes = _("魔法の領域を%sから%sに変更した。", "changed magic realm from %s to %s.");
704     strnfmt(tmp, sizeof(tmp), mes, realm_names[player_ptr->realm2], realm_names[next_realm]);
705     exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, tmp);
706     player_ptr->old_realm |= 1U << (player_ptr->realm2 - 1);
707     player_ptr->realm2 = next_realm;
708
709     const auto flags = {
710         StatusRedrawingFlag::REORDER,
711         StatusRedrawingFlag::SPELLS,
712     };
713     RedrawingFlagsUpdater::get_instance().set_flags(flags);
714     handle_stuff(player_ptr);
715
716     /* Load an autopick preference file */
717     autopick_load_pref(player_ptr, false);
718 }
719
720 /*!
721  * @brief 魔法を学習するコマンドのメインルーチン /
722  * Study a book to gain a new spell/prayer
723  */
724 void do_cmd_study(PlayerType *player_ptr)
725 {
726     auto increment = 0;
727     auto learned = false;
728
729     /* Spells of realm2 will have an increment of +32 */
730     SPELL_IDX spell = -1;
731     const auto p = spell_category_name(mp_ptr->spell_book);
732     if (!player_ptr->realm1) {
733         msg_print(_("本を読むことができない!", "You cannot read books!"));
734         return;
735     }
736
737     if (cmd_limit_blind(player_ptr) || cmd_limit_confused(player_ptr)) {
738         return;
739     }
740
741     if (player_ptr->new_spells == 0) {
742         msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
743         return;
744     }
745
746     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
747
748 #ifdef JP
749     if (player_ptr->new_spells < 10) {
750         msg_format("あと %d つの%sを学べる。", player_ptr->new_spells, p);
751     } else {
752         msg_format("あと %d 個の%sを学べる。", player_ptr->new_spells, p);
753     }
754 #else
755     msg_format("You can learn %d new %s%s.", player_ptr->new_spells, p, (player_ptr->new_spells == 1 ? "" : "s"));
756 #endif
757
758     msg_print(nullptr);
759
760     /* Restrict choices to "useful" books */
761     auto item_tester = get_learnable_spellbook_tester(player_ptr);
762
763     const auto q = _("どの本から学びますか? ", "Study which book? ");
764     const auto s = _("読める本がない。", "You have no books that you can read.");
765
766     short item;
767     const auto *o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), item_tester);
768     if (o_ptr == nullptr) {
769         return;
770     }
771
772     const auto tval = o_ptr->bi_key.tval();
773     const auto sval = o_ptr->bi_key.sval().value();
774     if (tval == get_realm2_book(player_ptr)) {
775         increment = 32;
776     } else if (tval != get_realm1_book(player_ptr)) {
777         if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) {
778             return;
779         }
780
781         change_realm2(player_ptr, tval2realm(tval));
782         increment = 32;
783     }
784
785     /* Track the object kind */
786     object_kind_track(player_ptr, o_ptr->bi_id);
787     handle_stuff(player_ptr);
788
789     /* Mage -- Learn a selected spell */
790     if (mp_ptr->spell_book != ItemKindType::LIFE_BOOK) {
791         /* Ask for a spell, allow cancel */
792         if (!get_spell(player_ptr, &spell, _("学ぶ", "study"), sval, false, tval2realm(tval)) && (spell == -1)) {
793             return;
794         }
795     }
796
797     /* Priest -- Learn a random prayer */
798     else {
799         int k = 0;
800         int gift = -1;
801
802         /* Extract spells */
803         for (spell = 0; spell < 32; spell++) {
804             /* Check spells in the book */
805             if ((fake_spell_flags[sval] & (1UL << spell))) {
806                 /* Skip non "okay" prayers */
807                 if (!spell_okay(player_ptr, spell, false, true, (increment ? player_ptr->realm2 : player_ptr->realm1))) {
808                     continue;
809                 }
810
811                 /* Hack -- Prepare the randomizer */
812                 k++;
813
814                 /* Hack -- Apply the randomizer */
815                 if (one_in_(k)) {
816                     gift = spell;
817                 }
818             }
819         }
820
821         /* Accept gift */
822         spell = gift;
823     }
824
825     /* Nothing to study */
826     if (spell < 0) {
827         msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
828
829         /* Abort */
830         return;
831     }
832
833     if (increment) {
834         spell += increment;
835     }
836
837     /* Learn the spell */
838     if (spell < 32) {
839         if (player_ptr->spell_learned1 & (1UL << spell)) {
840             learned = true;
841         } else {
842             player_ptr->spell_learned1 |= (1UL << spell);
843         }
844     } else {
845         if (player_ptr->spell_learned2 & (1UL << (spell - 32))) {
846             learned = true;
847         } else {
848             player_ptr->spell_learned2 |= (1UL << (spell - 32));
849         }
850     }
851
852     if (learned) {
853         auto max_exp = PlayerSkill::spell_exp_at((spell < 32) ? PlayerSkillRank::MASTER : PlayerSkillRank::EXPERT);
854         const auto old_exp = player_ptr->spell_exp[spell];
855         const auto realm = increment ? player_ptr->realm2 : player_ptr->realm1;
856         const auto spell_name = exe_spell(player_ptr, realm, spell % 32, SpellProcessType::NAME);
857
858         if (old_exp >= max_exp) {
859             msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
860             return;
861         }
862 #ifdef JP
863         if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", spell_name->data(), p)))
864 #else
865         if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, spell_name->data())))
866 #endif
867         {
868             return;
869         }
870
871         auto new_rank = PlayerSkill(player_ptr).gain_spell_skill_exp_over_learning(spell);
872         auto new_rank_str = PlayerSkill::skill_rank_str(new_rank);
873         msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), spell_name->data(), new_rank_str);
874     } else {
875         /* Find the next open entry in "player_ptr->spell_order[]" */
876         int i;
877         for (i = 0; i < 64; i++) {
878             /* Stop at the first empty space */
879             if (player_ptr->spell_order[i] == 99) {
880                 break;
881             }
882         }
883
884         /* Add the spell to the known list */
885         player_ptr->spell_order[i++] = spell;
886
887         /* Mention the result */
888         const auto realm = increment ? player_ptr->realm2 : player_ptr->realm1;
889         const auto spell_name = exe_spell(player_ptr, realm, spell % 32, SpellProcessType::NAME);
890 #ifdef JP
891         if (mp_ptr->spell_book == ItemKindType::MUSIC_BOOK) {
892             msg_format("%sを学んだ。", spell_name->data());
893         } else {
894             msg_format("%sの%sを学んだ。", spell_name->data(), p);
895         }
896 #else
897         msg_format("You have learned the %s of %s.", p, spell_name->data());
898 #endif
899     }
900
901     PlayerEnergy(player_ptr).set_player_turn_energy(100);
902
903     switch (mp_ptr->spell_book) {
904     case ItemKindType::LIFE_BOOK:
905         chg_virtue(player_ptr, Virtue::FAITH, 1);
906         break;
907     case ItemKindType::DEATH_BOOK:
908         chg_virtue(player_ptr, Virtue::UNLIFE, 1);
909         break;
910     case ItemKindType::NATURE_BOOK:
911         chg_virtue(player_ptr, Virtue::NATURE, 1);
912         break;
913     default:
914         chg_virtue(player_ptr, Virtue::KNOWLEDGE, 1);
915         break;
916     }
917
918     sound(SOUND_STUDY);
919
920     /* One less spell available */
921     player_ptr->learned_spells++;
922
923     auto &rfu = RedrawingFlagsUpdater::get_instance();
924     rfu.set_flag(StatusRedrawingFlag::SPELLS);
925     update_creature(player_ptr);
926
927     /* Redraw object recall */
928     player_ptr->window_flags |= (PW_ITEM_KNOWLEDGTE);
929 }
930
931 /*!
932  * @brief 魔法を詠唱するコマンドのメインルーチン /
933  * Cast a spell
934  * @param player_ptr プレイヤーへの参照ポインタ
935  * @return 詠唱したらtrue
936  */
937 bool do_cmd_cast(PlayerType *player_ptr)
938 {
939     SPELL_IDX spell;
940     int16_t realm;
941     int chance;
942     auto increment = 0;
943     int16_t use_realm;
944     MANA_POINT need_mana;
945
946     const magic_type *s_ptr;
947     auto over_exerted = false;
948
949     /* Require spell ability */
950     PlayerClass pc(player_ptr);
951     auto is_every_magic = pc.is_every_magic();
952     if (!player_ptr->realm1 && !is_every_magic) {
953         msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
954         return false;
955     }
956
957     if (player_ptr->effects()->blindness()->is_blind() || no_lite(player_ptr)) {
958         if (pc.equals(PlayerClassType::FORCETRAINER)) {
959             confirm_use_force(player_ptr, false);
960         } else {
961             msg_print(_("目が見えない!", "You cannot see!"));
962             flush();
963         }
964
965         return false;
966     }
967
968     if (cmd_limit_confused(player_ptr)) {
969         return false;
970     }
971
972     if (player_ptr->realm1 == REALM_HEX) {
973         if (SpellHex(player_ptr).is_casting_full_capacity()) {
974             auto flag = false;
975             msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not cast more spells."));
976             flush();
977             if (player_ptr->lev >= 35) {
978                 flag = SpellHex(player_ptr).stop_spells_with_selection();
979             }
980
981             if (!flag) {
982                 return false;
983             }
984         }
985     }
986
987     if (pc.equals(PlayerClassType::FORCETRAINER)) {
988         if (player_has_no_spellbooks(player_ptr)) {
989             confirm_use_force(player_ptr, false);
990             return true; //!< 錬気キャンセル時の処理がない
991         }
992     }
993
994     const auto prayer = spell_category_name(mp_ptr->spell_book);
995     const auto q = _("どの呪文書を使いますか? ", "Use which book? ");
996     const auto s = _("呪文書がない!", "You have no spell books!");
997     auto item_tester = get_castable_spellbook_tester(player_ptr);
998     const auto options = USE_INVEN | USE_FLOOR | (pc.equals(PlayerClassType::FORCETRAINER) ? USE_FORCE : 0);
999     short item;
1000     const auto *o_ptr = choose_object(player_ptr, &item, q, s, options, item_tester);
1001     if (o_ptr == nullptr) {
1002         if (item == INVEN_FORCE) {
1003             do_cmd_mind(player_ptr);
1004             return true; //!< 錬気キャンセル時の処理がない
1005         }
1006
1007         return false;
1008     }
1009
1010     const auto tval = o_ptr->bi_key.tval();
1011     const auto sval = o_ptr->bi_key.sval().value();
1012     if (!is_every_magic && (tval == get_realm2_book(player_ptr))) {
1013         increment = 32;
1014     }
1015
1016     /* Track the object kind */
1017     object_kind_track(player_ptr, o_ptr->bi_id);
1018     handle_stuff(player_ptr);
1019
1020     if (is_every_magic) {
1021         realm = tval2realm(tval);
1022     } else if (increment) {
1023         realm = player_ptr->realm2;
1024     } else {
1025         realm = player_ptr->realm1;
1026     }
1027
1028     /* Ask for a spell */
1029 #ifdef JP
1030     if (!get_spell(player_ptr, &spell,
1031             ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK)       ? "詠唱する"
1032                 : (mp_ptr->spell_book == ItemKindType::MUSIC_BOOK) ? "歌う"
1033                                                                    : "唱える"),
1034             sval, true, realm)) {
1035         if (spell == -2) {
1036             msg_format("その本には知っている%sがない。", prayer);
1037         }
1038         return false;
1039     }
1040 #else
1041     if (!get_spell(player_ptr, &spell, ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "recite" : "cast"), sval, true, realm)) {
1042         if (spell == -2) {
1043             msg_format("You don't know any %ss in that book.", prayer);
1044         }
1045         return false;
1046     }
1047 #endif
1048
1049     use_realm = tval2realm(tval);
1050     if (use_realm == REALM_HEX) {
1051         if (SpellHex(player_ptr).is_spelling_specific(spell)) {
1052             msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1053             return false;
1054         }
1055     }
1056
1057     if (!is_magic(use_realm)) {
1058         s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1059     } else {
1060         s_ptr = &mp_ptr->info[realm - 1][spell];
1061     }
1062
1063     /* Extract mana consumption rate */
1064     need_mana = mod_need_mana(player_ptr, s_ptr->smana, spell, realm);
1065
1066     /* Verify "dangerous" spells */
1067     if (need_mana > player_ptr->csp) {
1068         if (flush_failure) {
1069             flush();
1070         }
1071
1072         /* Warning */
1073 #ifdef JP
1074         msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1075             ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK)      ? "詠唱する"
1076                 : (mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "歌う"
1077                                                                   : "唱える"));
1078 #else
1079         msg_format("You do not have enough mana to %s this %s.", ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "recite" : "cast"), prayer);
1080 #endif
1081
1082         if (!over_exert) {
1083             return false;
1084         }
1085
1086         /* Verify */
1087         if (!get_check_strict(player_ptr, _("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) {
1088             return false;
1089         }
1090     }
1091
1092     /* Spell failure chance */
1093     chance = spell_chance(player_ptr, spell, use_realm);
1094
1095     /* Failed spell */
1096     if (randint0(100) < chance) {
1097         if (flush_failure) {
1098             flush();
1099         }
1100
1101         msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1102         sound(SOUND_FAIL);
1103
1104         switch (realm) {
1105         case REALM_LIFE:
1106             if (randint1(100) < chance) {
1107                 chg_virtue(player_ptr, Virtue::VITALITY, -1);
1108             }
1109             break;
1110         case REALM_DEATH:
1111             if (randint1(100) < chance) {
1112                 chg_virtue(player_ptr, Virtue::UNLIFE, -1);
1113             }
1114             break;
1115         case REALM_NATURE:
1116             if (randint1(100) < chance) {
1117                 chg_virtue(player_ptr, Virtue::NATURE, -1);
1118             }
1119             break;
1120         case REALM_DAEMON:
1121             if (randint1(100) < chance) {
1122                 chg_virtue(player_ptr, Virtue::JUSTICE, 1);
1123             }
1124             break;
1125         case REALM_CRUSADE:
1126             if (randint1(100) < chance) {
1127                 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1128             }
1129             break;
1130         case REALM_HEX:
1131             if (randint1(100) < chance) {
1132                 chg_virtue(player_ptr, Virtue::COMPASSION, -1);
1133             }
1134             break;
1135         default:
1136             if (randint1(100) < chance) {
1137                 chg_virtue(player_ptr, Virtue::KNOWLEDGE, -1);
1138             }
1139             break;
1140         }
1141
1142         /* Failure casting may activate some side effect */
1143         exe_spell(player_ptr, realm, spell, SpellProcessType::FAIL);
1144
1145         if ((tval == ItemKindType::CHAOS_BOOK) && (randint1(100) < spell)) {
1146             msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1147             wild_magic(player_ptr, spell);
1148         } else if ((tval == ItemKindType::DEATH_BOOK) && (randint1(100) < spell)) {
1149             if ((sval == 3) && one_in_(2)) {
1150                 sanity_blast(player_ptr, 0, true);
1151             } else {
1152                 msg_print(_("痛い!", "It hurts!"));
1153                 take_hit(player_ptr, DAMAGE_LOSELIFE, damroll(sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"));
1154
1155                 if ((spell > 15) && one_in_(6) && !player_ptr->hold_exp) {
1156                     lose_exp(player_ptr, spell * 250);
1157                 }
1158             }
1159         } else if ((tval == ItemKindType::MUSIC_BOOK) && (randint1(200) < spell)) {
1160             msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1161             aggravate_monsters(player_ptr, 0);
1162         }
1163         if (randint1(100) >= chance) {
1164             chg_virtue(player_ptr, Virtue::CHANCE, -1);
1165         }
1166     }
1167
1168     /* Process spell */
1169     else {
1170         /* Canceled spells cost neither a turn nor mana */
1171         if (!exe_spell(player_ptr, realm, spell, SpellProcessType::CAST)) {
1172             return false;
1173         }
1174
1175         if (randint1(100) < chance) {
1176             chg_virtue(player_ptr, Virtue::CHANCE, 1);
1177         }
1178
1179         /* A spell was cast */
1180         if (!(increment ? (player_ptr->spell_worked2 & (1UL << spell)) : (player_ptr->spell_worked1 & (1UL << spell))) && !is_every_magic) {
1181             int e = s_ptr->sexp;
1182
1183             /* The spell worked */
1184             if (realm == player_ptr->realm1) {
1185                 player_ptr->spell_worked1 |= (1UL << spell);
1186             } else {
1187                 player_ptr->spell_worked2 |= (1UL << spell);
1188             }
1189
1190             gain_exp(player_ptr, e * s_ptr->slevel);
1191             player_ptr->window_flags |= (PW_ITEM_KNOWLEDGTE);
1192
1193             switch (realm) {
1194             case REALM_LIFE:
1195                 chg_virtue(player_ptr, Virtue::TEMPERANCE, 1);
1196                 chg_virtue(player_ptr, Virtue::COMPASSION, 1);
1197                 chg_virtue(player_ptr, Virtue::VITALITY, 1);
1198                 chg_virtue(player_ptr, Virtue::DILIGENCE, 1);
1199                 break;
1200             case REALM_DEATH:
1201                 chg_virtue(player_ptr, Virtue::UNLIFE, 1);
1202                 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1203                 chg_virtue(player_ptr, Virtue::FAITH, -1);
1204                 chg_virtue(player_ptr, Virtue::VITALITY, -1);
1205                 break;
1206             case REALM_DAEMON:
1207                 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1208                 chg_virtue(player_ptr, Virtue::FAITH, -1);
1209                 chg_virtue(player_ptr, Virtue::HONOUR, -1);
1210                 chg_virtue(player_ptr, Virtue::TEMPERANCE, -1);
1211                 break;
1212             case REALM_CRUSADE:
1213                 chg_virtue(player_ptr, Virtue::FAITH, 1);
1214                 chg_virtue(player_ptr, Virtue::JUSTICE, 1);
1215                 chg_virtue(player_ptr, Virtue::SACRIFICE, 1);
1216                 chg_virtue(player_ptr, Virtue::HONOUR, 1);
1217                 break;
1218             case REALM_NATURE:
1219                 chg_virtue(player_ptr, Virtue::NATURE, 1);
1220                 chg_virtue(player_ptr, Virtue::HARMONY, 1);
1221                 break;
1222             case REALM_HEX:
1223                 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1224                 chg_virtue(player_ptr, Virtue::FAITH, -1);
1225                 chg_virtue(player_ptr, Virtue::HONOUR, -1);
1226                 chg_virtue(player_ptr, Virtue::COMPASSION, -1);
1227                 break;
1228             default:
1229                 chg_virtue(player_ptr, Virtue::KNOWLEDGE, 1);
1230                 break;
1231             }
1232         }
1233         switch (realm) {
1234         case REALM_LIFE:
1235             if (randint1(100 + player_ptr->lev) < need_mana) {
1236                 chg_virtue(player_ptr, Virtue::TEMPERANCE, 1);
1237             }
1238             if (randint1(100 + player_ptr->lev) < need_mana) {
1239                 chg_virtue(player_ptr, Virtue::COMPASSION, 1);
1240             }
1241             if (randint1(100 + player_ptr->lev) < need_mana) {
1242                 chg_virtue(player_ptr, Virtue::VITALITY, 1);
1243             }
1244             if (randint1(100 + player_ptr->lev) < need_mana) {
1245                 chg_virtue(player_ptr, Virtue::DILIGENCE, 1);
1246             }
1247             break;
1248         case REALM_DEATH:
1249             if (randint1(100 + player_ptr->lev) < need_mana) {
1250                 chg_virtue(player_ptr, Virtue::UNLIFE, 1);
1251             }
1252             if (randint1(100 + player_ptr->lev) < need_mana) {
1253                 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1254             }
1255             if (randint1(100 + player_ptr->lev) < need_mana) {
1256                 chg_virtue(player_ptr, Virtue::FAITH, -1);
1257             }
1258             if (randint1(100 + player_ptr->lev) < need_mana) {
1259                 chg_virtue(player_ptr, Virtue::VITALITY, -1);
1260             }
1261             break;
1262         case REALM_DAEMON:
1263             if (randint1(100 + player_ptr->lev) < need_mana) {
1264                 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1265             }
1266             if (randint1(100 + player_ptr->lev) < need_mana) {
1267                 chg_virtue(player_ptr, Virtue::FAITH, -1);
1268             }
1269             if (randint1(100 + player_ptr->lev) < need_mana) {
1270                 chg_virtue(player_ptr, Virtue::HONOUR, -1);
1271             }
1272             if (randint1(100 + player_ptr->lev) < need_mana) {
1273                 chg_virtue(player_ptr, Virtue::TEMPERANCE, -1);
1274             }
1275             break;
1276         case REALM_CRUSADE:
1277             if (randint1(100 + player_ptr->lev) < need_mana) {
1278                 chg_virtue(player_ptr, Virtue::FAITH, 1);
1279             }
1280             if (randint1(100 + player_ptr->lev) < need_mana) {
1281                 chg_virtue(player_ptr, Virtue::JUSTICE, 1);
1282             }
1283             if (randint1(100 + player_ptr->lev) < need_mana) {
1284                 chg_virtue(player_ptr, Virtue::SACRIFICE, 1);
1285             }
1286             if (randint1(100 + player_ptr->lev) < need_mana) {
1287                 chg_virtue(player_ptr, Virtue::HONOUR, 1);
1288             }
1289             break;
1290         case REALM_NATURE:
1291             if (randint1(100 + player_ptr->lev) < need_mana) {
1292                 chg_virtue(player_ptr, Virtue::NATURE, 1);
1293             }
1294             if (randint1(100 + player_ptr->lev) < need_mana) {
1295                 chg_virtue(player_ptr, Virtue::HARMONY, 1);
1296             }
1297             break;
1298         case REALM_HEX:
1299             if (randint1(100 + player_ptr->lev) < need_mana) {
1300                 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1301             }
1302             if (randint1(100 + player_ptr->lev) < need_mana) {
1303                 chg_virtue(player_ptr, Virtue::FAITH, -1);
1304             }
1305             if (randint1(100 + player_ptr->lev) < need_mana) {
1306                 chg_virtue(player_ptr, Virtue::HONOUR, -1);
1307             }
1308             if (randint1(100 + player_ptr->lev) < need_mana) {
1309                 chg_virtue(player_ptr, Virtue::COMPASSION, -1);
1310             }
1311             break;
1312         }
1313         if (any_bits(mp_ptr->spell_xtra, extra_magic_gain_exp)) {
1314             PlayerSkill(player_ptr).gain_spell_skill_exp(realm, spell);
1315         }
1316     }
1317
1318     PlayerEnergy(player_ptr).set_player_turn_energy(100);
1319
1320     /* Sufficient mana */
1321     if (need_mana <= player_ptr->csp) {
1322         /* Use some mana */
1323         player_ptr->csp -= need_mana;
1324     } else {
1325         over_exerted = true;
1326     }
1327     player_ptr->redraw |= (PR_MP);
1328
1329     /* Over-exert the player */
1330     if (over_exerted) {
1331         int oops = need_mana;
1332         player_ptr->csp = 0;
1333         player_ptr->csp_frac = 0;
1334         msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1335         (void)BadStatusSetter(player_ptr).mod_paralysis(randint1(5 * oops + 1));
1336         switch (realm) {
1337         case REALM_LIFE:
1338             chg_virtue(player_ptr, Virtue::VITALITY, -10);
1339             break;
1340         case REALM_DEATH:
1341             chg_virtue(player_ptr, Virtue::UNLIFE, -10);
1342             break;
1343         case REALM_DAEMON:
1344             chg_virtue(player_ptr, Virtue::JUSTICE, 10);
1345             break;
1346         case REALM_NATURE:
1347             chg_virtue(player_ptr, Virtue::NATURE, -10);
1348             break;
1349         case REALM_CRUSADE:
1350             chg_virtue(player_ptr, Virtue::JUSTICE, -10);
1351             break;
1352         case REALM_HEX:
1353             chg_virtue(player_ptr, Virtue::COMPASSION, 10);
1354             break;
1355         default:
1356             chg_virtue(player_ptr, Virtue::KNOWLEDGE, -10);
1357             break;
1358         }
1359
1360         /* Damage CON (possibly permanently) */
1361         if (randint0(100) < 50) {
1362             bool perm = (randint0(100) < 25);
1363
1364             msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1365
1366             /* Reduce constitution */
1367             (void)dec_stat(player_ptr, A_CON, 15 + randint1(10), perm);
1368         }
1369     }
1370
1371     player_ptr->window_flags |= (PW_PLAYER);
1372     player_ptr->window_flags |= (PW_SPELL);
1373
1374     return true; //!< @note 詠唱した
1375 }