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 */
763 for (spell = 0; spell < 32; spell++)
765 /* Check spells in the book */
766 if ((fake_spell_flags[sval] & (1L << spell)))
768 /* Skip non "okay" prayers */
769 if (!spell_okay(spell, FALSE, TRUE,
770 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
772 /* Hack -- Prepare the randomizer */
775 /* Hack -- Apply the randomizer */
776 if (one_in_(k)) gift = spell;
784 /* Nothing to study */
788 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
795 if (increment) spell += increment;
797 /* Learn the spell */
800 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
801 else p_ptr->spell_learned1 |= (1L << spell);
805 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
806 else p_ptr->spell_learned2 |= (1L << (spell - 32));
811 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
812 int old_exp = p_ptr->spell_exp[spell];
813 int new_rank = EXP_LEVEL_UNSKILLED;
814 cptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell%32, SPELL_NAME);
816 if (old_exp >= max_exp)
818 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
822 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
824 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
829 else if (old_exp >= SPELL_EXP_EXPERT)
831 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
832 new_rank = EXP_LEVEL_MASTER;
834 else if (old_exp >= SPELL_EXP_SKILLED)
836 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
837 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
838 new_rank = EXP_LEVEL_EXPERT;
840 else if (old_exp >= SPELL_EXP_BEGINNER)
842 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
843 new_rank = EXP_LEVEL_SKILLED;
847 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
848 new_rank = EXP_LEVEL_BEGINNER;
850 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
854 /* Find the next open entry in "p_ptr->spell_order[]" */
855 for (i = 0; i < 64; i++)
857 /* Stop at the first empty space */
858 if (p_ptr->spell_order[i] == 99) break;
861 /* Add the spell to the known list */
862 p_ptr->spell_order[i++] = spell;
864 /* Mention the result */
867 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
869 msg_format("%sを学んだ。",
870 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
874 msg_format("%sの%sを学んだ。",
875 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME) ,p);
878 msg_format("You have learned the %s of %s.",
879 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
884 p_ptr->energy_use = 100;
886 switch (mp_ptr->spell_book)
889 chg_virtue(V_FAITH, 1);
892 chg_virtue(V_UNLIFE, 1);
895 chg_virtue(V_NATURE, 1);
898 chg_virtue(V_KNOWLEDGE, 1);
905 /* One less spell available */
906 p_ptr->learned_spells++;
909 p_ptr->update |= (PU_SPELLS);
912 /* Redraw object recall */
913 p_ptr->window |= (PW_OBJECT);
918 * @brief 魔法を詠唱するコマンドのメインルーチン /
922 void do_cmd_cast(void)
925 OBJECT_SUBTYPE_VALUE sval;
931 MANA_POINT need_mana;
935 const magic_type *s_ptr;
938 bool over_exerted = FALSE;
940 /* Require spell ability */
941 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
943 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
948 if (p_ptr->blind || no_lite())
950 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
953 msg_print(_("目が見えない!", "You cannot see!"));
959 /* Not when confused */
962 msg_print(_("混乱していて唱えられない!", "You are too confused!"));
968 if (p_ptr->realm1 == REALM_HEX)
970 if (hex_spell_fully())
973 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
975 if (p_ptr->lev >= 35) flag = stop_hex_spell();
980 if (p_ptr->pclass == CLASS_FORCETRAINER)
982 if (player_has_no_spellbooks())
984 confirm_use_force(FALSE);
987 select_the_force = TRUE;
990 prayer = spell_category_name(mp_ptr->spell_book);
992 /* Restrict choices to spell books */
993 item_tester_tval = mp_ptr->spell_book;
996 q = _("どの呪文書を使いますか? ", "Use which book? ");
997 s = _("呪文書がない!", "You have no spell books!");
999 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR)))
1001 select_the_force = FALSE;
1004 select_the_force = FALSE;
1006 if (item == INVEN_FORCE) /* the_force */
1012 /* Get the item (in the pack) */
1015 o_ptr = &inventory[item];
1018 /* Get the item (on the floor) */
1021 o_ptr = &o_list[0 - item];
1024 /* Access the item's sval */
1027 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1030 /* Track the object kind */
1031 object_kind_track(o_ptr->k_idx);
1033 /* Hack -- Handle stuff */
1036 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1037 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1038 else if (increment) realm = p_ptr->realm2;
1039 else realm = p_ptr->realm1;
1041 /* Ask for a spell */
1043 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1046 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1050 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1054 msg_format("You don't know any %ss in that book.", prayer);
1060 use_realm = tval2realm(o_ptr->tval);
1063 if (use_realm == REALM_HEX)
1065 if (hex_spelling(spell))
1067 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1072 if (!is_magic(use_realm))
1074 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1078 s_ptr = &mp_ptr->info[realm - 1][spell];
1081 /* Extract mana consumption rate */
1082 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1084 /* Verify "dangerous" spells */
1085 if (need_mana > p_ptr->csp)
1087 if (flush_failure) flush();
1091 msg_format("その%sを%sのに十分なマジックポイントがない。",prayer,
1092 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1094 msg_format("You do not have enough mana to %s this %s.",
1095 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1100 if (!over_exert) return;
1103 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1106 /* Spell failure chance */
1107 chance = spell_chance(spell, use_realm);
1109 /* Sufficient mana */
1110 if (need_mana <= p_ptr->csp)
1113 p_ptr->csp -= need_mana;
1115 else over_exerted = TRUE;
1118 p_ptr->redraw |= (PR_MANA);
1121 if (randint0(100) < chance)
1123 if (flush_failure) flush();
1125 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1131 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1134 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1137 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1140 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1143 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1146 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1149 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1153 /* Failure casting may activate some side effect */
1154 do_spell(realm, spell, SPELL_FAIL);
1157 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1159 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1162 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1164 if ((sval == 3) && one_in_(2))
1166 sanity_blast(0, TRUE);
1170 msg_print(_("痛い!", "It hurts!"));
1171 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1173 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1174 lose_exp(spell * 250);
1177 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1179 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1180 aggravate_monsters(0);
1182 if (randint1(100) >= chance)
1183 chg_virtue(V_CHANCE,-1);
1189 /* Canceled spells cost neither a turn nor mana */
1190 if (!do_spell(realm, spell, SPELL_CAST)) return;
1192 if (randint1(100) < chance)
1193 chg_virtue(V_CHANCE,1);
1195 /* A spell was cast */
1197 (p_ptr->spell_worked2 & (1L << spell)) :
1198 (p_ptr->spell_worked1 & (1L << spell)))
1199 && (p_ptr->pclass != CLASS_SORCERER)
1200 && (p_ptr->pclass != CLASS_RED_MAGE))
1202 int e = s_ptr->sexp;
1204 /* The spell worked */
1205 if (realm == p_ptr->realm1)
1207 p_ptr->spell_worked1 |= (1L << spell);
1211 p_ptr->spell_worked2 |= (1L << spell);
1214 /* Gain experience */
1215 gain_exp(e * s_ptr->slevel);
1217 /* Redraw object recall */
1218 p_ptr->window |= (PW_OBJECT);
1223 chg_virtue(V_TEMPERANCE, 1);
1224 chg_virtue(V_COMPASSION, 1);
1225 chg_virtue(V_VITALITY, 1);
1226 chg_virtue(V_DILIGENCE, 1);
1229 chg_virtue(V_UNLIFE, 1);
1230 chg_virtue(V_JUSTICE, -1);
1231 chg_virtue(V_FAITH, -1);
1232 chg_virtue(V_VITALITY, -1);
1235 chg_virtue(V_JUSTICE, -1);
1236 chg_virtue(V_FAITH, -1);
1237 chg_virtue(V_HONOUR, -1);
1238 chg_virtue(V_TEMPERANCE, -1);
1241 chg_virtue(V_FAITH, 1);
1242 chg_virtue(V_JUSTICE, 1);
1243 chg_virtue(V_SACRIFICE, 1);
1244 chg_virtue(V_HONOUR, 1);
1247 chg_virtue(V_NATURE, 1);
1248 chg_virtue(V_HARMONY, 1);
1251 chg_virtue(V_JUSTICE, -1);
1252 chg_virtue(V_FAITH, -1);
1253 chg_virtue(V_HONOUR, -1);
1254 chg_virtue(V_COMPASSION, -1);
1257 chg_virtue(V_KNOWLEDGE, 1);
1264 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1265 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1266 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1267 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1270 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1271 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1272 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1273 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1276 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1277 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1278 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1279 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1282 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1283 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1284 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1285 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1288 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1289 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1292 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1293 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1294 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1295 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1298 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1300 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0)+spell];
1303 if (cur_exp < SPELL_EXP_BEGINNER)
1305 else if (cur_exp < SPELL_EXP_SKILLED)
1307 if ((dun_level > 4) && ((dun_level + 10) > p_ptr->lev))
1310 else if (cur_exp < SPELL_EXP_EXPERT)
1312 if (((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel))
1315 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1317 if (((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel))
1320 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1325 p_ptr->energy_use = 100;
1328 /* Over-exert the player */
1331 int oops = need_mana;
1335 p_ptr->csp_frac = 0;
1338 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1340 /* Hack -- Bypass free action */
1341 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1346 chg_virtue(V_VITALITY, -10);
1349 chg_virtue(V_UNLIFE, -10);
1352 chg_virtue(V_JUSTICE, 10);
1355 chg_virtue(V_NATURE, -10);
1358 chg_virtue(V_JUSTICE, -10);
1361 chg_virtue(V_COMPASSION, 10);
1364 chg_virtue(V_KNOWLEDGE, -10);
1368 /* Damage CON (possibly permanently) */
1369 if (randint0(100) < 50)
1371 bool perm = (randint0(100) < 25);
1374 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1376 /* Reduce constitution */
1377 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1382 p_ptr->window |= (PW_PLAYER);
1383 p_ptr->window |= (PW_SPELL);