3 @brief 魔法のインターフェイスと発動 / Purpose: Do everything for each spell
6 2013 Deskull rearranged comment for Doxygen.
15 #include "spells-summon.h"
17 #include "realm-arcane.h"
18 #include "realm-chaos.h"
19 #include "realm-craft.h"
20 #include "realm-crusade.h"
21 #include "realm-daemon.h"
22 #include "realm-death.h"
23 #include "realm-hex.h"
24 #include "realm-hissatsu.h"
25 #include "realm-life.h"
26 #include "realm-nature.h"
27 #include "realm-song.h"
28 #include "realm-sorcery.h"
29 #include "realm-trump.h"
32 #include "player-status.h"
33 #include "player-effects.h"
34 #include "player-skill.h"
35 #include "player-class.h"
36 #include "object-hook.h"
37 #include "cmd-basic.h"
38 #include "view-mainwindow.h"
44 * Zangband uses this array instead of the spell flags table, as there
45 * are 5 realms of magic, each with 4 spellbooks and 8 spells per book -- TY
47 const u32b fake_spell_flags[4] =
57 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
62 * @return フォーマットに従い整形された文字列
64 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
68 return format("%s%d", str, base);
72 return format("%s%dd%d", str, dice, sides);
74 /* Dice plus base value */
76 return format("%s%dd%d%+d", str, dice, sides, base);
81 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
85 * @return フォーマットに従い整形された文字列
87 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
89 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
93 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
96 * @return フォーマットに従い整形された文字列
98 concptr info_duration(int base, DICE_SID sides)
100 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
104 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
106 * @return フォーマットに従い整形された文字列
108 concptr info_range(POSITION range)
110 return format(_("範囲:%d", "range %d"), range);
114 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
118 * @return フォーマットに従い整形された文字列
120 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
122 return info_string_dice(_("回復:", "heal "), dice, sides, base);
126 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
129 * @return フォーマットに従い整形された文字列
131 concptr info_delay(int base, DICE_SID sides)
133 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
138 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
140 * @return フォーマットに従い整形された文字列
142 concptr info_multi_damage(HIT_POINT dam)
144 return format(_("損傷:各%d", "dam %d each"), dam);
149 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
152 * @return フォーマットに従い整形された文字列
154 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
156 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
160 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
162 * @return フォーマットに従い整形された文字列
164 concptr info_power(int power)
166 return format(_("効力:%d", "power %d"), power);
171 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
174 * @return フォーマットに従い整形された文字列
177 * Generate power info string such as "power 1d100"
179 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
181 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
186 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
188 * @return フォーマットに従い整形された文字列
190 concptr info_radius(POSITION rad)
192 return format(_("半径:%d", "rad %d"), rad);
197 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
199 * @return フォーマットに従い整形された文字列
201 concptr info_weight(WEIGHT weight)
204 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
206 return format("max wgt %d", weight/10);
211 * @brief 魔法が利用可能かどうかを返す /
212 * Determine if a spell is "okay" for the player to cast or study
213 * The spell must be legible, not forgotten, and also, to cast,
214 * it must be known, and to study, it must not be known.
216 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
217 * @param study_pray 祈りの学習判定目的ならばTRUE
218 * @param use_realm 魔法領域ID
221 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
223 const magic_type *s_ptr;
225 /* Access the spell */
226 if (!is_magic(use_realm))
228 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
232 s_ptr = &mp_ptr->info[use_realm - 1][spell];
235 /* Spell is illegal */
236 if (s_ptr->slevel > p_ptr->lev) return (FALSE);
238 /* Spell is forgotten */
239 if ((use_realm == p_ptr->realm2) ?
240 (p_ptr->spell_forgotten2 & (1L << spell)) :
241 (p_ptr->spell_forgotten1 & (1L << spell)))
247 if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
248 if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
250 /* Spell is learned */
251 if ((use_realm == p_ptr->realm2) ?
252 (p_ptr->spell_learned2 & (1L << spell)) :
253 (p_ptr->spell_learned1 & (1L << spell)))
256 return (!study_pray);
259 /* Okay to study, not to cast */
265 * @brief 魔法処理のメインルーチン
266 * @param realm 魔法領域のID
267 * @param spell 各領域の魔法ID
269 * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
271 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
275 case REALM_LIFE: return do_life_spell(spell, mode);
276 case REALM_SORCERY: return do_sorcery_spell(spell, mode);
277 case REALM_NATURE: return do_nature_spell(spell, mode);
278 case REALM_CHAOS: return do_chaos_spell(spell, mode);
279 case REALM_DEATH: return do_death_spell(spell, mode);
280 case REALM_TRUMP: return do_trump_spell(spell, mode);
281 case REALM_ARCANE: return do_arcane_spell(spell, mode);
282 case REALM_CRAFT: return do_craft_spell(spell, mode);
283 case REALM_DAEMON: return do_daemon_spell(spell, mode);
284 case REALM_CRUSADE: return do_crusade_spell(spell, mode);
285 case REALM_MUSIC: return do_music_spell(spell, mode);
286 case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
287 case REALM_HEX: return do_hex_spell(spell, mode);
295 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
296 * Allow user to choose a spell/prayer from the given book.
297 * @param sn 選択した魔法IDを返す参照ポインタ
298 * @param prompt 魔法を利用する際の動詞表記
299 * @param sval 魔道書のsval
300 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
301 * @param use_realm 魔法領域ID
304 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
305 * If the user hits escape, returns FALSE, and set '*sn' to -1
306 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
307 * The "prompt" should be "cast", "recite", or "study"
308 * The "known" should be TRUE for cast/pray, FALSE for study
311 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
314 SPELL_IDX spell = -1;
317 MANA_POINT need_mana;
318 SPELL_IDX spells[64];
319 bool flag, redraw, okay;
321 const magic_type *s_ptr;
328 int menu_line = (use_menu ? 1 : 0);
330 /* Get the spell, if available */
331 if (repeat_pull(&code))
333 *sn = (SPELL_IDX)code;
334 /* Verify the spell */
335 if (spell_okay(*sn, learned, FALSE, use_realm))
342 p = spell_category_name(mp_ptr->spell_book);
345 for (spell = 0; spell < 32; spell++)
347 /* Check for this spell */
348 if ((fake_spell_flags[sval] & (1L << spell)))
350 /* Collect this spell */
351 spells[num++] = spell;
355 /* Assume no usable spells */
358 /* Assume no spells available */
361 /* Check for "okay" spells */
362 for (i = 0; i < num; i++)
364 /* Look for "okay" spells */
365 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
368 /* No "okay" spells */
369 if (!okay) return (FALSE);
370 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
371 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
372 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
374 /* Assume cancelled */
377 /* Nothing chosen yet */
383 p_ptr->window |= (PW_SPELL);
386 /* Build a prompt (accept all spells) */
388 jverb(prompt, jverb_buf, JVERB_AND);
389 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
390 p, I2A(0), I2A(num - 1), p, jverb_buf);
392 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
393 p, I2A(0), I2A(num - 1), prompt, p);
396 choice = (always_show_list || use_menu) ? ESCAPE : 1;
399 if (choice == ESCAPE) choice = ' ';
400 else if (!get_com(out_val, &choice, TRUE))break;
402 if (use_menu && choice != ' ')
416 menu_line += (num - 1);
438 if (menu_line > num) menu_line -= num;
439 /* Display a list of spells */
440 print_spells(menu_line, spells, num, 1, 15, use_realm);
446 if ((choice == ' ') || (choice == '*') || (choice == '?'))
454 /* Display a list of spells */
455 print_spells(menu_line, spells, num, 1, 15, use_realm);
461 if (use_menu) continue;
474 ask = (isupper(choice));
477 if (ask) choice = (char)tolower(choice);
479 /* Extract request */
480 i = (islower(choice) ? A2I(choice) : -1);
483 /* Totally Illegal */
484 if ((i < 0) || (i >= num))
490 /* Save the spell index */
493 /* Require "okay" spells */
494 if (!spell_okay(spell, learned, FALSE, use_realm))
498 msg_format("その%sを%sことはできません。", p, prompt);
500 msg_format("You may not %s that %s.", prompt, p);
511 /* Access the spell */
512 if (!is_magic(use_realm))
514 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
518 s_ptr = &mp_ptr->info[use_realm - 1][spell];
521 /* Extract mana consumption rate */
522 if (use_realm == REALM_HISSATSU)
524 need_mana = s_ptr->smana;
528 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
533 jverb(prompt, jverb_buf, JVERB_AND);
535 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
536 do_spell(use_realm, spell, SPELL_NAME), need_mana,
537 spell_chance(spell, use_realm), jverb_buf);
539 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
540 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
541 spell_chance(spell, use_realm));
545 /* Belay that order */
546 if (!get_check(tmp_val)) continue;
553 if (redraw) screen_load();
555 p_ptr->window |= (PW_SPELL);
558 /* Abort if needed */
559 if (!flag) return FALSE;
561 /* Save the choice */
564 repeat_push((COMMAND_CODE)spell);
571 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
572 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
573 * @return 魔道書を一冊も持っていないならTRUEを返す
575 static void confirm_use_force(bool browse_only)
580 /* Get the item index */
581 if (repeat_pull(&code) && (code == INVEN_FORCE))
583 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
587 /* Show the prompt */
588 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
595 if (which == ESCAPE) break;
596 else if (which == 'w')
598 repeat_push(INVEN_FORCE);
603 /* Clear the prompt line */
608 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
614 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
615 * Peruse the spells/prayers in a book
619 * Note that *all* spells in the book are listed
621 * Note that browsing is allowed while confused or blind,
622 * and in the dark, primarily to allow browsing in stores.
625 void do_cmd_browse(void)
628 OBJECT_SUBTYPE_VALUE sval;
629 REALM_IDX use_realm = 0;
631 SPELL_IDX spell = -1;
634 SPELL_IDX spells[64];
641 /* Warriors are illiterate */
642 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
644 msg_print(_("本を読むことができない!", "You cannot read books!"));
648 if (p_ptr->special_defense & KATA_MUSOU)
650 set_action(ACTION_NONE);
653 if (p_ptr->pclass == CLASS_FORCETRAINER)
655 if (player_has_no_spellbooks())
657 confirm_use_force(TRUE);
662 /* Restrict choices to "useful" books */
663 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
664 else item_tester_hook = item_tester_learn_spell;
666 q = _("どの本を読みますか? ", "Browse which book? ");
667 s = _("読める本がない。", "You have no books that you can read.");
669 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
672 if (item == INVEN_FORCE) /* the_force */
674 do_cmd_mind_browse();
680 /* Access the item's sval */
683 use_realm = tval2realm(o_ptr->tval);
685 /* Track the object kind */
686 object_kind_track(o_ptr->k_idx);
690 for (spell = 0; spell < 32; spell++)
692 /* Check for this spell */
693 if ((fake_spell_flags[sval] & (1L << spell)))
695 /* Collect this spell */
696 spells[num++] = spell;
703 /* Keep browsing spells. Exit browsing on cancel. */
706 /* Ask for a spell, allow cancel */
707 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
709 /* If cancelled, leave immediately. */
710 if (spell == -1) break;
712 /* Display a list of spells */
713 print_spells(0, spells, num, 1, 15, use_realm);
715 /* Notify that there's nothing to see, and wait. */
716 if (use_realm == REALM_HISSATSU)
717 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
719 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
727 /* Clear lines, position cursor (really should use strlen here) */
728 Term_erase(14, 14, 255);
729 Term_erase(14, 13, 255);
730 Term_erase(14, 12, 255);
731 Term_erase(14, 11, 255);
733 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
735 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
737 prt(&temp[j], line, 15);
745 * @brief プレイヤーの第二魔法領域を変更する /
746 * @param next_realm 変更先の魔法領域ID
749 static void change_realm2(CHARACTER_IDX next_realm)
754 for (i = 0; i < 64; i++)
756 p_ptr->spell_order[j] = p_ptr->spell_order[i];
757 if (p_ptr->spell_order[i] < 32) j++;
760 p_ptr->spell_order[j] = 99;
762 for (i = 32; i < 64; i++)
764 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
766 p_ptr->spell_learned2 = 0L;
767 p_ptr->spell_worked2 = 0L;
768 p_ptr->spell_forgotten2 = 0L;
770 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
771 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
772 p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
773 p_ptr->realm2 = next_realm;
775 p_ptr->update |= (PU_REORDER);
776 p_ptr->update |= (PU_SPELLS);
779 /* Load an autopick preference file */
780 autopick_load_pref(FALSE);
785 * @brief 魔法を学習するコマンドのメインルーチン /
786 * Study a book to gain a new spell/prayer
789 void do_cmd_study(void)
793 OBJECT_SUBTYPE_VALUE sval;
795 bool learned = FALSE;
797 /* Spells of realm2 will have an increment of +32 */
798 SPELL_IDX spell = -1;
800 concptr p = spell_category_name(mp_ptr->spell_book);
808 msg_print(_("本を読むことができない!", "You cannot read books!"));
812 if (p_ptr->blind || no_lite())
814 msg_print(_("目が見えない!", "You cannot see!"));
818 if (cmd_limit_confused(p_ptr)) return;
820 if (!(p_ptr->new_spells))
822 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
826 if (p_ptr->special_defense & KATA_MUSOU)
828 set_action(ACTION_NONE);
832 if (p_ptr->new_spells < 10) {
833 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
836 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
839 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
840 (p_ptr->new_spells == 1 ? "" : "s"));
846 /* Restrict choices to "useful" books */
847 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
848 else item_tester_hook = item_tester_learn_spell;
850 q = _("どの本から学びますか? ", "Study which book? ");
851 s = _("読める本がない。", "You have no books that you can read.");
853 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
856 /* Access the item's sval */
859 if (o_ptr->tval == REALM2_BOOK) increment = 32;
860 else if (o_ptr->tval != REALM1_BOOK)
862 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
863 change_realm2(tval2realm(o_ptr->tval));
867 /* Track the object kind */
868 object_kind_track(o_ptr->k_idx);
871 /* Mage -- Learn a selected spell */
872 if (mp_ptr->spell_book != TV_LIFE_BOOK)
874 /* Ask for a spell, allow cancel */
875 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
878 /* Priest -- Learn a random prayer */
885 for (spell = 0; spell < 32; spell++)
887 /* Check spells in the book */
888 if ((fake_spell_flags[sval] & (1L << spell)))
890 /* Skip non "okay" prayers */
891 if (!spell_okay(spell, FALSE, TRUE,
892 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
894 /* Hack -- Prepare the randomizer */
897 /* Hack -- Apply the randomizer */
898 if (one_in_(k)) gift = spell;
906 /* Nothing to study */
909 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
915 if (increment) spell += increment;
917 /* Learn the spell */
920 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
921 else p_ptr->spell_learned1 |= (1L << spell);
925 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
926 else p_ptr->spell_learned2 |= (1L << (spell - 32));
931 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
932 int old_exp = p_ptr->spell_exp[spell];
933 int new_rank = EXP_LEVEL_UNSKILLED;
934 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
936 if (old_exp >= max_exp)
938 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
942 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
944 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
949 else if (old_exp >= SPELL_EXP_EXPERT)
951 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
952 new_rank = EXP_LEVEL_MASTER;
954 else if (old_exp >= SPELL_EXP_SKILLED)
956 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
957 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
958 new_rank = EXP_LEVEL_EXPERT;
960 else if (old_exp >= SPELL_EXP_BEGINNER)
962 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
963 new_rank = EXP_LEVEL_SKILLED;
967 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
968 new_rank = EXP_LEVEL_BEGINNER;
970 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
974 /* Find the next open entry in "p_ptr->spell_order[]" */
975 for (i = 0; i < 64; i++)
977 /* Stop at the first empty space */
978 if (p_ptr->spell_order[i] == 99) break;
981 /* Add the spell to the known list */
982 p_ptr->spell_order[i++] = spell;
984 /* Mention the result */
987 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
989 msg_format("%sを学んだ。",
990 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
994 msg_format("%sの%sを学んだ。",
995 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
998 msg_format("You have learned the %s of %s.",
999 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
1003 take_turn(p_ptr, 100);
1005 switch (mp_ptr->spell_book)
1008 chg_virtue(V_FAITH, 1);
1011 chg_virtue(V_UNLIFE, 1);
1013 case TV_NATURE_BOOK:
1014 chg_virtue(V_NATURE, 1);
1017 chg_virtue(V_KNOWLEDGE, 1);
1023 /* One less spell available */
1024 p_ptr->learned_spells++;
1027 p_ptr->update |= (PU_SPELLS);
1028 update_creature(p_ptr);
1030 /* Redraw object recall */
1031 p_ptr->window |= (PW_OBJECT);
1036 * @brief 魔法を詠唱するコマンドのメインルーチン /
1040 void do_cmd_cast(void)
1043 OBJECT_SUBTYPE_VALUE sval;
1048 REALM_IDX use_realm;
1049 MANA_POINT need_mana;
1053 const magic_type *s_ptr;
1056 bool over_exerted = FALSE;
1058 /* Require spell ability */
1059 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1061 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1066 if (p_ptr->blind || no_lite())
1068 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1071 msg_print(_("目が見えない!", "You cannot see!"));
1077 if (cmd_limit_confused(p_ptr)) return;
1080 if (p_ptr->realm1 == REALM_HEX)
1082 if (hex_spell_fully())
1085 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1087 if (p_ptr->lev >= 35) flag = stop_hex_spell();
1092 if (p_ptr->pclass == CLASS_FORCETRAINER)
1094 if (player_has_no_spellbooks())
1096 confirm_use_force(FALSE);
1101 prayer = spell_category_name(mp_ptr->spell_book);
1103 /* Restrict choices to spell books */
1104 item_tester_tval = mp_ptr->spell_book;
1106 q = _("どの呪文書を使いますか? ", "Use which book? ");
1107 s = _("呪文書がない!", "You have no spell books!");
1109 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
1112 if (item == INVEN_FORCE) /* the_force */
1120 /* Access the item's sval */
1123 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1125 /* Track the object kind */
1126 object_kind_track(o_ptr->k_idx);
1129 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1130 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1131 else if (increment) realm = p_ptr->realm2;
1132 else realm = p_ptr->realm1;
1134 /* Ask for a spell */
1136 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1139 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1143 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1147 msg_format("You don't know any %ss in that book.", prayer);
1153 use_realm = tval2realm(o_ptr->tval);
1156 if (use_realm == REALM_HEX)
1158 if (hex_spelling(spell))
1160 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1165 if (!is_magic(use_realm))
1167 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1171 s_ptr = &mp_ptr->info[realm - 1][spell];
1174 /* Extract mana consumption rate */
1175 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1177 /* Verify "dangerous" spells */
1178 if (need_mana > p_ptr->csp)
1180 if (flush_failure) flush();
1184 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1185 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1187 msg_format("You do not have enough mana to %s this %s.",
1188 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1193 if (!over_exert) return;
1196 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1199 /* Spell failure chance */
1200 chance = spell_chance(spell, use_realm);
1202 /* Sufficient mana */
1203 if (need_mana <= p_ptr->csp)
1206 p_ptr->csp -= need_mana;
1208 else over_exerted = TRUE;
1209 p_ptr->redraw |= (PR_MANA);
1212 if (randint0(100) < chance)
1214 if (flush_failure) flush();
1216 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1222 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1225 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1228 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1231 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1234 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1237 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1240 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1244 /* Failure casting may activate some side effect */
1245 do_spell(realm, spell, SPELL_FAIL);
1248 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1250 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1253 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1255 if ((sval == 3) && one_in_(2))
1257 sanity_blast(0, TRUE);
1261 msg_print(_("痛い!", "It hurts!"));
1262 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1264 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1265 lose_exp(spell * 250);
1268 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1270 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1271 aggravate_monsters(0);
1273 if (randint1(100) >= chance)
1274 chg_virtue(V_CHANCE, -1);
1280 /* Canceled spells cost neither a current_world_ptr->game_turn nor mana */
1281 if (!do_spell(realm, spell, SPELL_CAST)) return;
1283 if (randint1(100) < chance)
1284 chg_virtue(V_CHANCE, 1);
1286 /* A spell was cast */
1288 (p_ptr->spell_worked2 & (1L << spell)) :
1289 (p_ptr->spell_worked1 & (1L << spell)))
1290 && (p_ptr->pclass != CLASS_SORCERER)
1291 && (p_ptr->pclass != CLASS_RED_MAGE))
1293 int e = s_ptr->sexp;
1295 /* The spell worked */
1296 if (realm == p_ptr->realm1)
1298 p_ptr->spell_worked1 |= (1L << spell);
1302 p_ptr->spell_worked2 |= (1L << spell);
1305 /* Gain experience */
1306 gain_exp(e * s_ptr->slevel);
1308 /* Redraw object recall */
1309 p_ptr->window |= (PW_OBJECT);
1314 chg_virtue(V_TEMPERANCE, 1);
1315 chg_virtue(V_COMPASSION, 1);
1316 chg_virtue(V_VITALITY, 1);
1317 chg_virtue(V_DILIGENCE, 1);
1320 chg_virtue(V_UNLIFE, 1);
1321 chg_virtue(V_JUSTICE, -1);
1322 chg_virtue(V_FAITH, -1);
1323 chg_virtue(V_VITALITY, -1);
1326 chg_virtue(V_JUSTICE, -1);
1327 chg_virtue(V_FAITH, -1);
1328 chg_virtue(V_HONOUR, -1);
1329 chg_virtue(V_TEMPERANCE, -1);
1332 chg_virtue(V_FAITH, 1);
1333 chg_virtue(V_JUSTICE, 1);
1334 chg_virtue(V_SACRIFICE, 1);
1335 chg_virtue(V_HONOUR, 1);
1338 chg_virtue(V_NATURE, 1);
1339 chg_virtue(V_HARMONY, 1);
1342 chg_virtue(V_JUSTICE, -1);
1343 chg_virtue(V_FAITH, -1);
1344 chg_virtue(V_HONOUR, -1);
1345 chg_virtue(V_COMPASSION, -1);
1348 chg_virtue(V_KNOWLEDGE, 1);
1355 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1356 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1357 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1358 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1361 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1362 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1363 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1364 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1367 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1368 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1369 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1370 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1373 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1374 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1375 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1376 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1379 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1380 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1383 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1384 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1385 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1386 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1389 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1391 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0) + spell];
1394 if (cur_exp < SPELL_EXP_BEGINNER)
1396 else if (cur_exp < SPELL_EXP_SKILLED)
1398 if ((current_floor_ptr->dun_level > 4) && ((current_floor_ptr->dun_level + 10) > p_ptr->lev))
1401 else if (cur_exp < SPELL_EXP_EXPERT)
1403 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && ((current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1406 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1408 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && (current_floor_ptr->dun_level > s_ptr->slevel))
1411 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1415 take_turn(p_ptr, 100);
1418 /* Over-exert the player */
1421 int oops = need_mana;
1425 p_ptr->csp_frac = 0;
1427 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1429 /* Hack -- Bypass free action */
1430 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1435 chg_virtue(V_VITALITY, -10);
1438 chg_virtue(V_UNLIFE, -10);
1441 chg_virtue(V_JUSTICE, 10);
1444 chg_virtue(V_NATURE, -10);
1447 chg_virtue(V_JUSTICE, -10);
1450 chg_virtue(V_COMPASSION, 10);
1453 chg_virtue(V_KNOWLEDGE, -10);
1457 /* Damage CON (possibly permanently) */
1458 if (randint0(100) < 50)
1460 bool perm = (randint0(100) < 25);
1462 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1464 /* Reduce constitution */
1465 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1469 p_ptr->window |= (PW_PLAYER);
1470 p_ptr->window |= (PW_SPELL);