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.
16 #include "player-status.h"
17 #include "object-hook.h"
20 * @brief 領域魔法に応じて技能の名称を返す。
21 * @param tval 魔法書のtval
22 * @return 領域魔法の技能名称を保管した文字列ポインタ
24 concptr spell_category_name(OBJECT_TYPE_VALUE tval)
28 case TV_HISSATSU_BOOK:
29 return _("必殺技", "art");
31 return _("祈り", "prayer");
33 return _("歌", "song");
35 return _("呪文", "spell");
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, concptr 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 /* Get the spell, if available */
76 if (repeat_pull(&code))
78 *sn = (SPELL_IDX)code;
79 /* Verify the spell */
80 if (spell_okay(*sn, learned, FALSE, use_realm))
87 p = spell_category_name(mp_ptr->spell_book);
90 for (spell = 0; spell < 32; spell++)
92 /* Check for this spell */
93 if ((fake_spell_flags[sval] & (1L << spell)))
95 /* Collect this spell */
96 spells[num++] = spell;
100 /* Assume no usable spells */
103 /* Assume no spells available */
106 /* Check for "okay" spells */
107 for (i = 0; i < num; i++)
109 /* Look for "okay" spells */
110 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
113 /* No "okay" spells */
114 if (!okay) return (FALSE);
115 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
116 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
117 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
119 /* Assume cancelled */
122 /* Nothing chosen yet */
128 p_ptr->window |= (PW_SPELL);
131 /* Build a prompt (accept all spells) */
133 jverb( prompt, jverb_buf, JVERB_AND );
134 (void) strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
135 p, I2A(0), I2A(num - 1), p, jverb_buf );
137 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
138 p, I2A(0), I2A(num - 1), prompt, p);
141 /* Get a spell from the user */
143 choice = (always_show_list || use_menu) ? ESCAPE : 1;
146 if (choice == ESCAPE) choice = ' ';
147 else if (!get_com(out_val, &choice, TRUE))break;
149 if (use_menu && choice != ' ')
163 menu_line += (num - 1);
185 if (menu_line > num) menu_line -= num;
186 /* Display a list of spells */
187 print_spells(menu_line, spells, num, 1, 15, use_realm);
193 if ((choice == ' ') || (choice == '*') || (choice == '?'))
202 /* Display a list of spells */
203 print_spells(menu_line, spells, num, 1, 15, use_realm);
209 if (use_menu) continue;
222 ask = (isupper(choice));
225 if (ask) choice = (char)tolower(choice);
227 /* Extract request */
228 i = (islower(choice) ? A2I(choice) : -1);
231 /* Totally Illegal */
232 if ((i < 0) || (i >= num))
238 /* Save the spell index */
241 /* Require "okay" spells */
242 if (!spell_okay(spell, learned, FALSE, use_realm))
246 msg_format("その%sを%sことはできません。", p, prompt);
248 msg_format("You may not %s that %s.", prompt, p);
259 /* Access the spell */
260 if (!is_magic(use_realm))
262 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
266 s_ptr = &mp_ptr->info[use_realm - 1][spell];
269 /* Extract mana consumption rate */
270 if (use_realm == REALM_HISSATSU)
272 need_mana = s_ptr->smana;
276 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
281 jverb( prompt, jverb_buf, JVERB_AND );
283 (void) strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
284 do_spell(use_realm, spell, SPELL_NAME), need_mana,
285 spell_chance(spell, use_realm),jverb_buf);
287 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
288 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
289 spell_chance(spell, use_realm));
293 /* Belay that order */
294 if (!get_check(tmp_val)) continue;
301 if (redraw) screen_load();
303 p_ptr->window |= (PW_SPELL);
306 /* Abort if needed */
307 if (!flag) return FALSE;
309 /* Save the choice */
312 repeat_push((COMMAND_CODE)spell);
319 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
320 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
321 * @return 魔道書を一冊も持っていないならTRUEを返す
323 static void confirm_use_force(bool browse_only)
328 /* Get the item index */
329 if (repeat_pull(&code) && (code == INVEN_FORCE))
331 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
335 /* Show the prompt */
336 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
343 if (which == ESCAPE) break;
344 else if (which == 'w')
346 repeat_push(INVEN_FORCE);
351 /* Clear the prompt line */
356 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
362 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
363 * Peruse the spells/prayers in a book
367 * Note that *all* spells in the book are listed
369 * Note that browsing is allowed while confused or blind,
370 * and in the dark, primarily to allow browsing in stores.
373 void do_cmd_browse(void)
376 OBJECT_SUBTYPE_VALUE sval;
377 REALM_IDX use_realm = 0;
379 SPELL_IDX spell = -1;
382 SPELL_IDX spells[64];
389 /* Warriors are illiterate */
390 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
392 msg_print(_("本を読むことができない!", "You cannot read books!"));
396 if (p_ptr->special_defense & KATA_MUSOU)
398 set_action(ACTION_NONE);
401 if (p_ptr->pclass == CLASS_FORCETRAINER)
403 if (player_has_no_spellbooks())
405 confirm_use_force(TRUE);
410 /* Restrict choices to "useful" books */
411 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
412 else item_tester_hook = item_tester_learn_spell;
414 q = _("どの本を読みますか? ", "Browse which book? ");
415 s = _("読める本がない。", "You have no books that you can read.");
417 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
420 if (item == INVEN_FORCE) /* the_force */
422 do_cmd_mind_browse();
428 /* Access the item's sval */
431 use_realm = tval2realm(o_ptr->tval);
433 /* Track the object kind */
434 object_kind_track(o_ptr->k_idx);
438 for (spell = 0; spell < 32; spell++)
440 /* Check for this spell */
441 if ((fake_spell_flags[sval] & (1L << spell)))
443 /* Collect this spell */
444 spells[num++] = spell;
451 /* Keep browsing spells. Exit browsing on cancel. */
454 /* Ask for a spell, allow cancel */
455 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
457 /* If cancelled, leave immediately. */
458 if (spell == -1) break;
460 /* Display a list of spells */
461 print_spells(0, spells, num, 1, 15, use_realm);
463 /* Notify that there's nothing to see, and wait. */
464 if (use_realm == REALM_HISSATSU)
465 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
467 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
475 /* Clear lines, position cursor (really should use strlen here) */
476 Term_erase(14, 14, 255);
477 Term_erase(14, 13, 255);
478 Term_erase(14, 12, 255);
479 Term_erase(14, 11, 255);
481 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
483 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
485 prt(&temp[j], line, 15);
493 * @brief プレイヤーの第二魔法領域を変更する /
494 * @param next_realm 変更先の魔法領域ID
497 static void change_realm2(CHARACTER_IDX next_realm)
502 for (i = 0; i < 64; i++)
504 p_ptr->spell_order[j] = p_ptr->spell_order[i];
505 if (p_ptr->spell_order[i] < 32) j++;
508 p_ptr->spell_order[j] = 99;
510 for (i = 32; i < 64; i++)
512 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
514 p_ptr->spell_learned2 = 0L;
515 p_ptr->spell_worked2 = 0L;
516 p_ptr->spell_forgotten2 = 0L;
518 sprintf(tmp,_("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
519 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
520 p_ptr->old_realm |= 1 << (p_ptr->realm2-1);
521 p_ptr->realm2 = next_realm;
523 p_ptr->update |= (PU_REORDER);
524 p_ptr->update |= (PU_SPELLS);
527 /* Load an autopick preference file */
528 autopick_load_pref(FALSE);
533 * @brief 魔法を学習するコマンドのメインルーチン /
534 * Study a book to gain a new spell/prayer
537 void do_cmd_study(void)
541 OBJECT_SUBTYPE_VALUE sval;
543 bool learned = FALSE;
545 /* Spells of realm2 will have an increment of +32 */
546 SPELL_IDX spell = -1;
548 concptr p = spell_category_name(mp_ptr->spell_book);
556 msg_print(_("本を読むことができない!", "You cannot read books!"));
560 if (p_ptr->blind || no_lite())
562 msg_print(_("目が見えない!", "You cannot see!"));
568 msg_print(_("混乱していて読めない!", "You are too confused!"));
572 if (!(p_ptr->new_spells))
574 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
578 if (p_ptr->special_defense & KATA_MUSOU)
580 set_action(ACTION_NONE);
584 if( p_ptr->new_spells < 10 ){
585 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
587 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
590 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
591 (p_ptr->new_spells == 1?"":"s"));
597 /* Restrict choices to "useful" books */
598 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
599 else item_tester_hook = item_tester_learn_spell;
601 q = _("どの本から学びますか? ", "Study which book? ");
602 s = _("読める本がない。", "You have no books that you can read.");
604 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
607 /* Access the item's sval */
610 if (o_ptr->tval == REALM2_BOOK) increment = 32;
611 else if (o_ptr->tval != REALM1_BOOK)
613 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
614 change_realm2(tval2realm(o_ptr->tval));
618 /* Track the object kind */
619 object_kind_track(o_ptr->k_idx);
622 /* Mage -- Learn a selected spell */
623 if (mp_ptr->spell_book != TV_LIFE_BOOK)
625 /* Ask for a spell, allow cancel */
626 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
629 /* Priest -- Learn a random prayer */
636 for (spell = 0; spell < 32; spell++)
638 /* Check spells in the book */
639 if ((fake_spell_flags[sval] & (1L << spell)))
641 /* Skip non "okay" prayers */
642 if (!spell_okay(spell, FALSE, TRUE,
643 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
645 /* Hack -- Prepare the randomizer */
648 /* Hack -- Apply the randomizer */
649 if (one_in_(k)) gift = spell;
657 /* Nothing to study */
660 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
666 if (increment) spell += increment;
668 /* Learn the spell */
671 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
672 else p_ptr->spell_learned1 |= (1L << spell);
676 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
677 else p_ptr->spell_learned2 |= (1L << (spell - 32));
682 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
683 int old_exp = p_ptr->spell_exp[spell];
684 int new_rank = EXP_LEVEL_UNSKILLED;
685 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell%32, SPELL_NAME);
687 if (old_exp >= max_exp)
689 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
693 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
695 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
700 else if (old_exp >= SPELL_EXP_EXPERT)
702 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
703 new_rank = EXP_LEVEL_MASTER;
705 else if (old_exp >= SPELL_EXP_SKILLED)
707 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
708 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
709 new_rank = EXP_LEVEL_EXPERT;
711 else if (old_exp >= SPELL_EXP_BEGINNER)
713 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
714 new_rank = EXP_LEVEL_SKILLED;
718 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
719 new_rank = EXP_LEVEL_BEGINNER;
721 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
725 /* Find the next open entry in "p_ptr->spell_order[]" */
726 for (i = 0; i < 64; i++)
728 /* Stop at the first empty space */
729 if (p_ptr->spell_order[i] == 99) break;
732 /* Add the spell to the known list */
733 p_ptr->spell_order[i++] = spell;
735 /* Mention the result */
738 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
740 msg_format("%sを学んだ。",
741 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
745 msg_format("%sの%sを学んだ。",
746 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME) ,p);
749 msg_format("You have learned the %s of %s.",
750 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
754 p_ptr->energy_use = 100;
756 switch (mp_ptr->spell_book)
759 chg_virtue(V_FAITH, 1);
762 chg_virtue(V_UNLIFE, 1);
765 chg_virtue(V_NATURE, 1);
768 chg_virtue(V_KNOWLEDGE, 1);
774 /* One less spell available */
775 p_ptr->learned_spells++;
778 p_ptr->update |= (PU_SPELLS);
779 update_creature(p_ptr);
781 /* Redraw object recall */
782 p_ptr->window |= (PW_OBJECT);
787 * @brief 魔法を詠唱するコマンドのメインルーチン /
791 void do_cmd_cast(void)
794 OBJECT_SUBTYPE_VALUE sval;
800 MANA_POINT need_mana;
804 const magic_type *s_ptr;
807 bool over_exerted = FALSE;
809 /* Require spell ability */
810 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
812 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
817 if (p_ptr->blind || no_lite())
819 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
822 msg_print(_("目が見えない!", "You cannot see!"));
828 /* Not when confused */
831 msg_print(_("混乱していて唱えられない!", "You are too confused!"));
837 if (p_ptr->realm1 == REALM_HEX)
839 if (hex_spell_fully())
842 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
844 if (p_ptr->lev >= 35) flag = stop_hex_spell();
849 if (p_ptr->pclass == CLASS_FORCETRAINER)
851 if (player_has_no_spellbooks())
853 confirm_use_force(FALSE);
858 prayer = spell_category_name(mp_ptr->spell_book);
860 /* Restrict choices to spell books */
861 item_tester_tval = mp_ptr->spell_book;
863 q = _("どの呪文書を使いますか? ", "Use which book? ");
864 s = _("呪文書がない!", "You have no spell books!");
866 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
869 if (item == INVEN_FORCE) /* the_force */
877 /* Access the item's sval */
880 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
882 /* Track the object kind */
883 object_kind_track(o_ptr->k_idx);
886 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
887 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
888 else if (increment) realm = p_ptr->realm2;
889 else realm = p_ptr->realm1;
891 /* Ask for a spell */
893 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
896 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
900 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
904 msg_format("You don't know any %ss in that book.", prayer);
910 use_realm = tval2realm(o_ptr->tval);
913 if (use_realm == REALM_HEX)
915 if (hex_spelling(spell))
917 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
922 if (!is_magic(use_realm))
924 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
928 s_ptr = &mp_ptr->info[realm - 1][spell];
931 /* Extract mana consumption rate */
932 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
934 /* Verify "dangerous" spells */
935 if (need_mana > p_ptr->csp)
937 if (flush_failure) flush();
941 msg_format("その%sを%sのに十分なマジックポイントがない。",prayer,
942 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
944 msg_format("You do not have enough mana to %s this %s.",
945 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
950 if (!over_exert) return;
953 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
956 /* Spell failure chance */
957 chance = spell_chance(spell, use_realm);
959 /* Sufficient mana */
960 if (need_mana <= p_ptr->csp)
963 p_ptr->csp -= need_mana;
965 else over_exerted = TRUE;
966 p_ptr->redraw |= (PR_MANA);
969 if (randint0(100) < chance)
971 if (flush_failure) flush();
973 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
979 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
982 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
985 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
988 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
991 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
994 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
997 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1001 /* Failure casting may activate some side effect */
1002 do_spell(realm, spell, SPELL_FAIL);
1005 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1007 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1010 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1012 if ((sval == 3) && one_in_(2))
1014 sanity_blast(0, TRUE);
1018 msg_print(_("痛い!", "It hurts!"));
1019 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1021 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1022 lose_exp(spell * 250);
1025 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1027 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1028 aggravate_monsters(0);
1030 if (randint1(100) >= chance)
1031 chg_virtue(V_CHANCE,-1);
1037 /* Canceled spells cost neither a turn nor mana */
1038 if (!do_spell(realm, spell, SPELL_CAST)) return;
1040 if (randint1(100) < chance)
1041 chg_virtue(V_CHANCE,1);
1043 /* A spell was cast */
1045 (p_ptr->spell_worked2 & (1L << spell)) :
1046 (p_ptr->spell_worked1 & (1L << spell)))
1047 && (p_ptr->pclass != CLASS_SORCERER)
1048 && (p_ptr->pclass != CLASS_RED_MAGE))
1050 int e = s_ptr->sexp;
1052 /* The spell worked */
1053 if (realm == p_ptr->realm1)
1055 p_ptr->spell_worked1 |= (1L << spell);
1059 p_ptr->spell_worked2 |= (1L << spell);
1062 /* Gain experience */
1063 gain_exp(e * s_ptr->slevel);
1065 /* Redraw object recall */
1066 p_ptr->window |= (PW_OBJECT);
1071 chg_virtue(V_TEMPERANCE, 1);
1072 chg_virtue(V_COMPASSION, 1);
1073 chg_virtue(V_VITALITY, 1);
1074 chg_virtue(V_DILIGENCE, 1);
1077 chg_virtue(V_UNLIFE, 1);
1078 chg_virtue(V_JUSTICE, -1);
1079 chg_virtue(V_FAITH, -1);
1080 chg_virtue(V_VITALITY, -1);
1083 chg_virtue(V_JUSTICE, -1);
1084 chg_virtue(V_FAITH, -1);
1085 chg_virtue(V_HONOUR, -1);
1086 chg_virtue(V_TEMPERANCE, -1);
1089 chg_virtue(V_FAITH, 1);
1090 chg_virtue(V_JUSTICE, 1);
1091 chg_virtue(V_SACRIFICE, 1);
1092 chg_virtue(V_HONOUR, 1);
1095 chg_virtue(V_NATURE, 1);
1096 chg_virtue(V_HARMONY, 1);
1099 chg_virtue(V_JUSTICE, -1);
1100 chg_virtue(V_FAITH, -1);
1101 chg_virtue(V_HONOUR, -1);
1102 chg_virtue(V_COMPASSION, -1);
1105 chg_virtue(V_KNOWLEDGE, 1);
1112 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1113 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1114 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1115 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1118 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1119 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1120 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1121 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1124 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1125 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1126 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1127 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1130 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1131 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1132 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1133 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1136 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1137 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1140 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1141 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1142 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1143 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1146 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1148 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0)+spell];
1151 if (cur_exp < SPELL_EXP_BEGINNER)
1153 else if (cur_exp < SPELL_EXP_SKILLED)
1155 if ((dun_level > 4) && ((dun_level + 10) > p_ptr->lev))
1158 else if (cur_exp < SPELL_EXP_EXPERT)
1160 if (((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel))
1163 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1165 if (((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel))
1168 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1172 p_ptr->energy_use = 100;
1175 /* Over-exert the player */
1178 int oops = need_mana;
1182 p_ptr->csp_frac = 0;
1184 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1186 /* Hack -- Bypass free action */
1187 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1192 chg_virtue(V_VITALITY, -10);
1195 chg_virtue(V_UNLIFE, -10);
1198 chg_virtue(V_JUSTICE, 10);
1201 chg_virtue(V_NATURE, -10);
1204 chg_virtue(V_JUSTICE, -10);
1207 chg_virtue(V_COMPASSION, 10);
1210 chg_virtue(V_KNOWLEDGE, -10);
1214 /* Damage CON (possibly permanently) */
1215 if (randint0(100) < 50)
1217 bool perm = (randint0(100) < 25);
1219 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1221 /* Reduce constitution */
1222 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1226 p_ptr->window |= (PW_PLAYER);
1227 p_ptr->window |= (PW_SPELL);