3 * @brief プレイヤーの魔法に関するコマンドの実装 / Spell/Prayer commands
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
17 * @brief 領域魔法に応じて技能の名称を返す。
18 * @param tval 魔法書のtval
19 * @return 領域魔法の技能名称を保管した文字列ポインタ
21 cptr spell_category_name(OBJECT_TYPE_VALUE tval)
25 case TV_HISSATSU_BOOK:
26 return _("必殺技", "art");
28 return _("祈り", "prayer");
30 return _("歌", "song");
32 return _("呪文", "spell");
37 bool select_the_force = FALSE;
40 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
41 * Allow user to choose a spell/prayer from the given book.
42 * @param sn 選択した魔法IDを返す参照ポインタ
43 * @param prompt 魔法を利用する際の動詞表記
44 * @param sval 魔道書のsval
45 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
46 * @param use_realm 魔法領域ID
49 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
50 * If the user hits escape, returns FALSE, and set '*sn' to -1
51 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
52 * The "prompt" should be "cast", "recite", or "study"
53 * The "known" should be TRUE for cast/pray, FALSE for study
56 static int get_spell(SPELL_IDX *sn, cptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
64 bool flag, redraw, okay;
66 const magic_type *s_ptr;
73 int menu_line = (use_menu ? 1 : 0);
75 #ifdef ALLOW_REPEAT /* TNB */
77 /* Get the spell, if available */
78 if (repeat_pull(&code))
80 *sn = (SPELL_IDX)code;
81 /* Verify the spell */
82 if (spell_okay(*sn, learned, FALSE, use_realm))
89 #endif /* ALLOW_REPEAT -- TNB */
91 p = spell_category_name(mp_ptr->spell_book);
94 for (spell = 0; spell < 32; spell++)
96 /* Check for this spell */
97 if ((fake_spell_flags[sval] & (1L << spell)))
99 /* Collect this spell */
100 spells[num++] = spell;
104 /* Assume no usable spells */
107 /* Assume no spells available */
110 /* Check for "okay" spells */
111 for (i = 0; i < num; i++)
113 /* Look for "okay" spells */
114 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
117 /* No "okay" spells */
118 if (!okay) return (FALSE);
119 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
120 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
121 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
123 /* Assume cancelled */
126 /* Nothing chosen yet */
133 p_ptr->window |= (PW_SPELL);
138 /* Build a prompt (accept all spells) */
140 jverb( prompt, jverb_buf, JVERB_AND );
141 (void) strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
142 p, I2A(0), I2A(num - 1), p, jverb_buf );
144 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
145 p, I2A(0), I2A(num - 1), prompt, p);
148 /* Get a spell from the user */
150 choice = (always_show_list || use_menu) ? ESCAPE : 1;
153 if (choice == ESCAPE) choice = ' ';
154 else if (!get_com(out_val, &choice, TRUE))break;
156 if (use_menu && choice != ' ')
170 menu_line += (num - 1);
192 if (menu_line > num) menu_line -= num;
193 /* Display a list of spells */
194 print_spells(menu_line, spells, num, 1, 15, use_realm);
200 if ((choice == ' ') || (choice == '*') || (choice == '?'))
208 /* Save the screen */
211 /* Display a list of spells */
212 print_spells(menu_line, spells, num, 1, 15, use_realm);
218 if (use_menu) continue;
223 /* Restore the screen */
233 ask = (isupper(choice));
236 if (ask) choice = (char)tolower(choice);
238 /* Extract request */
239 i = (islower(choice) ? A2I(choice) : -1);
242 /* Totally Illegal */
243 if ((i < 0) || (i >= num))
249 /* Save the spell index */
252 /* Require "okay" spells */
253 if (!spell_okay(spell, learned, FALSE, use_realm))
257 msg_format("その%sを%sことはできません。", p, prompt);
259 msg_format("You may not %s that %s.", prompt, p);
270 /* Access the spell */
271 if (!is_magic(use_realm))
273 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
277 s_ptr = &mp_ptr->info[use_realm - 1][spell];
280 /* Extract mana consumption rate */
281 if (use_realm == REALM_HISSATSU)
283 need_mana = s_ptr->smana;
287 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
292 jverb( prompt, jverb_buf, JVERB_AND );
294 (void) strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
295 do_spell(use_realm, spell, SPELL_NAME), need_mana,
296 spell_chance(spell, use_realm),jverb_buf);
298 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
299 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
300 spell_chance(spell, use_realm));
304 /* Belay that order */
305 if (!get_check(tmp_val)) continue;
313 /* Restore the screen */
314 if (redraw) screen_load();
318 p_ptr->window |= (PW_SPELL);
324 /* Abort if needed */
325 if (!flag) return FALSE;
327 /* Save the choice */
330 #ifdef ALLOW_REPEAT /* TNB */
332 repeat_push((COMMAND_CODE)spell);
334 #endif /* ALLOW_REPEAT -- TNB */
341 * @brief オブジェクトがプレイヤーが使用可能な魔道書かどうかを判定する
342 * @param o_ptr 判定したいオブ会ジェクトの構造体参照ポインタ
343 * @return 学習できる魔道書ならばTRUEを返す
345 static bool item_tester_learn_spell(object_type *o_ptr)
347 s32b choices = realm_choices2[p_ptr->pclass];
349 if (p_ptr->pclass == CLASS_PRIEST)
351 if (is_good_realm(p_ptr->realm1))
353 choices &= ~(CH_DEATH | CH_DAEMON);
357 choices &= ~(CH_LIFE | CH_CRUSADE);
361 if ((o_ptr->tval < TV_LIFE_BOOK) || (o_ptr->tval > (TV_LIFE_BOOK + MAX_REALM - 1))) return (FALSE);
362 if ((o_ptr->tval == TV_MUSIC_BOOK) && (p_ptr->pclass == CLASS_BARD)) return (TRUE);
363 else if (!is_magic(tval2realm(o_ptr->tval))) return FALSE;
364 if ((REALM1_BOOK == o_ptr->tval) || (REALM2_BOOK == o_ptr->tval)) return (TRUE);
365 if (choices & (0x0001 << (tval2realm(o_ptr->tval) - 1))) return (TRUE);
370 * @brief プレイヤーが魔道書を一冊も持っていないかを判定する
371 * @return 魔道書を一冊も持っていないならTRUEを返す
373 static bool player_has_no_spellbooks(void)
378 for (i = 0; i < INVEN_PACK; i++)
380 o_ptr = &inventory[i];
381 if (o_ptr->k_idx && check_book_realm(o_ptr->tval, o_ptr->sval)) return FALSE;
384 for (i = cave[p_ptr->y][p_ptr->x].o_idx; i; i = o_ptr->next_o_idx)
387 if (o_ptr->k_idx && (o_ptr->marked & OM_FOUND) && check_book_realm(o_ptr->tval, o_ptr->sval)) return FALSE;
394 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
395 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
396 * @return 魔道書を一冊も持っていないならTRUEを返す
398 static void confirm_use_force(bool browse_only)
405 /* Get the item index */
406 if (repeat_pull(&code) && (code == INVEN_FORCE))
408 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
412 #endif /* ALLOW_REPEAT */
414 /* Show the prompt */
415 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
422 if (which == ESCAPE) break;
423 else if (which == 'w')
428 repeat_push(INVEN_FORCE);
430 #endif /* ALLOW_REPEAT */
436 /* Clear the prompt line */
441 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
447 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
448 * Peruse the spells/prayers in a book
452 * Note that *all* spells in the book are listed
454 * Note that browsing is allowed while confused or blind,
455 * and in the dark, primarily to allow browsing in stores.
458 void do_cmd_browse(void)
461 OBJECT_SUBTYPE_VALUE sval;
462 REALM_IDX use_realm = 0;
464 SPELL_IDX spell = -1;
467 SPELL_IDX spells[64];
474 /* Warriors are illiterate */
475 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
477 msg_print(_("本を読むことができない!", "You cannot read books!"));
481 if (p_ptr->special_defense & KATA_MUSOU)
483 set_action(ACTION_NONE);
486 if (p_ptr->pclass == CLASS_FORCETRAINER)
488 if (player_has_no_spellbooks())
490 confirm_use_force(TRUE);
493 select_the_force = TRUE;
496 /* Restrict choices to "useful" books */
497 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
498 else item_tester_hook = item_tester_learn_spell;
501 q = _("どの本を読みますか? ", "Browse which book? ");
502 s = _("読める本がない。", "You have no books that you can read.");
504 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
506 select_the_force = FALSE;
509 select_the_force = FALSE;
511 if (item == INVEN_FORCE) /* the_force */
513 do_cmd_mind_browse();
517 /* Get the item (in the pack) */
520 o_ptr = &inventory[item];
523 /* Get the item (on the floor) */
526 o_ptr = &o_list[0 - item];
529 /* Access the item's sval */
532 use_realm = tval2realm(o_ptr->tval);
534 /* Track the object kind */
535 object_kind_track(o_ptr->k_idx);
537 /* Hack -- Handle stuff */
542 for (spell = 0; spell < 32; spell++)
544 /* Check for this spell */
545 if ((fake_spell_flags[sval] & (1L << spell)))
547 /* Collect this spell */
548 spells[num++] = spell;
553 /* Save the screen */
556 /* Clear the top line */
559 /* Keep browsing spells. Exit browsing on cancel. */
562 /* Ask for a spell, allow cancel */
563 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
565 /* If cancelled, leave immediately. */
566 if (spell == -1) break;
568 /* Display a list of spells */
569 print_spells(0, spells, num, 1, 15, use_realm);
571 /* Notify that there's nothing to see, and wait. */
572 if (use_realm == REALM_HISSATSU)
573 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
575 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
579 /* Restore the screen */
585 /* Clear lines, position cursor (really should use strlen here) */
586 Term_erase(14, 14, 255);
587 Term_erase(14, 13, 255);
588 Term_erase(14, 12, 255);
589 Term_erase(14, 11, 255);
591 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
593 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
595 prt(&temp[j], line, 15);
600 /* Restore the screen */
605 * @brief プレイヤーの第二魔法領域を変更する /
606 * @param next_realm 変更先の魔法領域ID
609 static void change_realm2(CHARACTER_IDX next_realm)
614 for (i = 0; i < 64; i++)
616 p_ptr->spell_order[j] = p_ptr->spell_order[i];
617 if (p_ptr->spell_order[i] < 32) j++;
620 p_ptr->spell_order[j] = 99;
622 for (i = 32; i < 64; i++)
624 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
626 p_ptr->spell_learned2 = 0L;
627 p_ptr->spell_worked2 = 0L;
628 p_ptr->spell_forgotten2 = 0L;
630 sprintf(tmp,_("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
631 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
632 p_ptr->old_realm |= 1 << (p_ptr->realm2-1);
633 p_ptr->realm2 = next_realm;
635 p_ptr->notice |= (PN_REORDER);
636 p_ptr->update |= (PU_SPELLS);
639 /* Load an autopick preference file */
640 autopick_load_pref(FALSE);
645 * @brief 魔法を学習するコマンドのメインルーチン /
646 * Study a book to gain a new spell/prayer
649 void do_cmd_study(void)
653 OBJECT_SUBTYPE_VALUE sval;
655 bool learned = FALSE;
657 /* Spells of realm2 will have an increment of +32 */
658 SPELL_IDX spell = -1;
660 cptr p = spell_category_name(mp_ptr->spell_book);
668 msg_print(_("本を読むことができない!", "You cannot read books!"));
672 if (p_ptr->blind || no_lite())
674 msg_print(_("目が見えない!", "You cannot see!"));
680 msg_print(_("混乱していて読めない!", "You are too confused!"));
684 if (!(p_ptr->new_spells))
686 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
690 if (p_ptr->special_defense & KATA_MUSOU)
692 set_action(ACTION_NONE);
696 if( p_ptr->new_spells < 10 ){
697 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
699 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
702 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
703 (p_ptr->new_spells == 1?"":"s"));
709 /* Restrict choices to "useful" books */
710 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
711 else item_tester_hook = item_tester_learn_spell;
714 q = _("どの本から学びますか? ", "Study which book? ");
715 s = _("読める本がない。", "You have no books that you can read.");
717 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
719 /* Get the item (in the pack) */
722 o_ptr = &inventory[item];
725 /* Get the item (on the floor) */
728 o_ptr = &o_list[0 - item];
731 /* Access the item's sval */
734 if (o_ptr->tval == REALM2_BOOK) increment = 32;
735 else if (o_ptr->tval != REALM1_BOOK)
737 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
738 change_realm2(tval2realm(o_ptr->tval));
742 /* Track the object kind */
743 object_kind_track(o_ptr->k_idx);
745 /* Hack -- Handle stuff */
748 /* Mage -- Learn a selected spell */
749 if (mp_ptr->spell_book != TV_LIFE_BOOK)
751 /* Ask for a spell, allow cancel */
752 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
755 /* Priest -- Learn a random prayer */
762 for (spell = 0; spell < 32; spell++)
764 /* Check spells in the book */
765 if ((fake_spell_flags[sval] & (1L << spell)))
767 /* Skip non "okay" prayers */
768 if (!spell_okay(spell, FALSE, TRUE,
769 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
771 /* Hack -- Prepare the randomizer */
774 /* Hack -- Apply the randomizer */
775 if (one_in_(k)) gift = spell;
783 /* Nothing to study */
787 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
793 if (increment) spell += increment;
795 /* Learn the spell */
798 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
799 else p_ptr->spell_learned1 |= (1L << spell);
803 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
804 else p_ptr->spell_learned2 |= (1L << (spell - 32));
809 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
810 int old_exp = p_ptr->spell_exp[spell];
811 int new_rank = EXP_LEVEL_UNSKILLED;
812 cptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell%32, SPELL_NAME);
814 if (old_exp >= max_exp)
816 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
820 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
822 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
827 else if (old_exp >= SPELL_EXP_EXPERT)
829 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
830 new_rank = EXP_LEVEL_MASTER;
832 else if (old_exp >= SPELL_EXP_SKILLED)
834 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
835 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
836 new_rank = EXP_LEVEL_EXPERT;
838 else if (old_exp >= SPELL_EXP_BEGINNER)
840 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
841 new_rank = EXP_LEVEL_SKILLED;
845 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
846 new_rank = EXP_LEVEL_BEGINNER;
848 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
852 /* Find the next open entry in "p_ptr->spell_order[]" */
853 for (i = 0; i < 64; i++)
855 /* Stop at the first empty space */
856 if (p_ptr->spell_order[i] == 99) break;
859 /* Add the spell to the known list */
860 p_ptr->spell_order[i++] = spell;
862 /* Mention the result */
865 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
867 msg_format("%sを学んだ。",
868 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
872 msg_format("%sの%sを学んだ。",
873 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME) ,p);
876 msg_format("You have learned the %s of %s.",
877 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
882 p_ptr->energy_use = 100;
884 switch (mp_ptr->spell_book)
887 chg_virtue(V_FAITH, 1);
890 chg_virtue(V_UNLIFE, 1);
893 chg_virtue(V_NATURE, 1);
896 chg_virtue(V_KNOWLEDGE, 1);
903 /* One less spell available */
904 p_ptr->learned_spells++;
907 p_ptr->update |= (PU_SPELLS);
910 /* Redraw object recall */
911 p_ptr->window |= (PW_OBJECT);
916 * @brief 魔法を詠唱するコマンドのメインルーチン /
920 void do_cmd_cast(void)
923 OBJECT_SUBTYPE_VALUE sval;
929 MANA_POINT need_mana;
933 const magic_type *s_ptr;
936 bool over_exerted = FALSE;
938 /* Require spell ability */
939 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
941 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
946 if (p_ptr->blind || no_lite())
948 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
951 msg_print(_("目が見えない!", "You cannot see!"));
957 /* Not when confused */
960 msg_print(_("混乱していて唱えられない!", "You are too confused!"));
966 if (p_ptr->realm1 == REALM_HEX)
968 if (hex_spell_fully())
971 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
973 if (p_ptr->lev >= 35) flag = stop_hex_spell();
978 if (p_ptr->pclass == CLASS_FORCETRAINER)
980 if (player_has_no_spellbooks())
982 confirm_use_force(FALSE);
985 select_the_force = TRUE;
988 prayer = spell_category_name(mp_ptr->spell_book);
990 /* Restrict choices to spell books */
991 item_tester_tval = mp_ptr->spell_book;
994 q = _("どの呪文書を使いますか? ", "Use which book? ");
995 s = _("呪文書がない!", "You have no spell books!");
997 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
999 select_the_force = FALSE;
1002 select_the_force = FALSE;
1004 if (item == INVEN_FORCE) /* the_force */
1010 /* Get the item (in the pack) */
1013 o_ptr = &inventory[item];
1016 /* Get the item (on the floor) */
1019 o_ptr = &o_list[0 - item];
1022 /* Access the item's sval */
1025 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1028 /* Track the object kind */
1029 object_kind_track(o_ptr->k_idx);
1031 /* Hack -- Handle stuff */
1034 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1035 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1036 else if (increment) realm = p_ptr->realm2;
1037 else realm = p_ptr->realm1;
1039 /* Ask for a spell */
1041 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1044 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1048 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1052 msg_format("You don't know any %ss in that book.", prayer);
1058 use_realm = tval2realm(o_ptr->tval);
1061 if (use_realm == REALM_HEX)
1063 if (hex_spelling(spell))
1065 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1070 if (!is_magic(use_realm))
1072 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1076 s_ptr = &mp_ptr->info[realm - 1][spell];
1079 /* Extract mana consumption rate */
1080 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1082 /* Verify "dangerous" spells */
1083 if (need_mana > p_ptr->csp)
1085 if (flush_failure) flush();
1089 msg_format("その%sを%sのに十分なマジックポイントがない。",prayer,
1090 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1092 msg_format("You do not have enough mana to %s this %s.",
1093 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1098 if (!over_exert) return;
1101 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1104 /* Spell failure chance */
1105 chance = spell_chance(spell, use_realm);
1107 /* Sufficient mana */
1108 if (need_mana <= p_ptr->csp)
1111 p_ptr->csp -= need_mana;
1113 else over_exerted = TRUE;
1116 p_ptr->redraw |= (PR_MANA);
1119 if (randint0(100) < chance)
1121 if (flush_failure) flush();
1123 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1129 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1132 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1135 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1138 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1141 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1144 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1147 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1151 /* Failure casting may activate some side effect */
1152 do_spell(realm, spell, SPELL_FAIL);
1155 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1157 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1160 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1162 if ((sval == 3) && one_in_(2))
1164 sanity_blast(0, TRUE);
1168 msg_print(_("痛い!", "It hurts!"));
1169 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1171 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1172 lose_exp(spell * 250);
1175 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1177 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1178 aggravate_monsters(0);
1180 if (randint1(100) >= chance)
1181 chg_virtue(V_CHANCE,-1);
1187 /* Canceled spells cost neither a turn nor mana */
1188 if (!do_spell(realm, spell, SPELL_CAST)) return;
1190 if (randint1(100) < chance)
1191 chg_virtue(V_CHANCE,1);
1193 /* A spell was cast */
1195 (p_ptr->spell_worked2 & (1L << spell)) :
1196 (p_ptr->spell_worked1 & (1L << spell)))
1197 && (p_ptr->pclass != CLASS_SORCERER)
1198 && (p_ptr->pclass != CLASS_RED_MAGE))
1200 int e = s_ptr->sexp;
1202 /* The spell worked */
1203 if (realm == p_ptr->realm1)
1205 p_ptr->spell_worked1 |= (1L << spell);
1209 p_ptr->spell_worked2 |= (1L << spell);
1212 /* Gain experience */
1213 gain_exp(e * s_ptr->slevel);
1215 /* Redraw object recall */
1216 p_ptr->window |= (PW_OBJECT);
1221 chg_virtue(V_TEMPERANCE, 1);
1222 chg_virtue(V_COMPASSION, 1);
1223 chg_virtue(V_VITALITY, 1);
1224 chg_virtue(V_DILIGENCE, 1);
1227 chg_virtue(V_UNLIFE, 1);
1228 chg_virtue(V_JUSTICE, -1);
1229 chg_virtue(V_FAITH, -1);
1230 chg_virtue(V_VITALITY, -1);
1233 chg_virtue(V_JUSTICE, -1);
1234 chg_virtue(V_FAITH, -1);
1235 chg_virtue(V_HONOUR, -1);
1236 chg_virtue(V_TEMPERANCE, -1);
1239 chg_virtue(V_FAITH, 1);
1240 chg_virtue(V_JUSTICE, 1);
1241 chg_virtue(V_SACRIFICE, 1);
1242 chg_virtue(V_HONOUR, 1);
1245 chg_virtue(V_NATURE, 1);
1246 chg_virtue(V_HARMONY, 1);
1249 chg_virtue(V_JUSTICE, -1);
1250 chg_virtue(V_FAITH, -1);
1251 chg_virtue(V_HONOUR, -1);
1252 chg_virtue(V_COMPASSION, -1);
1255 chg_virtue(V_KNOWLEDGE, 1);
1262 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1263 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1264 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1265 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1268 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1269 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1270 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1271 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1274 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1275 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1276 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1277 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1280 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1281 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1282 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1283 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1286 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1287 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1290 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1291 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1292 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1293 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1296 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1298 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0)+spell];
1301 if (cur_exp < SPELL_EXP_BEGINNER)
1303 else if (cur_exp < SPELL_EXP_SKILLED)
1305 if ((dun_level > 4) && ((dun_level + 10) > p_ptr->lev))
1308 else if (cur_exp < SPELL_EXP_EXPERT)
1310 if (((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel))
1313 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1315 if (((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel))
1318 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1323 p_ptr->energy_use = 100;
1326 /* Over-exert the player */
1329 int oops = need_mana;
1333 p_ptr->csp_frac = 0;
1336 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1338 /* Hack -- Bypass free action */
1339 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1344 chg_virtue(V_VITALITY, -10);
1347 chg_virtue(V_UNLIFE, -10);
1350 chg_virtue(V_JUSTICE, 10);
1353 chg_virtue(V_NATURE, -10);
1356 chg_virtue(V_JUSTICE, -10);
1359 chg_virtue(V_COMPASSION, 10);
1362 chg_virtue(V_KNOWLEDGE, -10);
1366 /* Damage CON (possibly permanently) */
1367 if (randint0(100) < 50)
1369 bool perm = (randint0(100) < 25);
1372 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1374 /* Reduce constitution */
1375 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1380 p_ptr->window |= (PW_PLAYER);
1381 p_ptr->window |= (PW_SPELL);