OSDN Git Service

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