3 @brief 魔法のインターフェイスと発動 / Purpose: Do everything for each spell
6 2013 Deskull rearranged comment for Doxygen.
13 #include "spells-summon.h"
14 #include "realm-arcane.h"
15 #include "realm-chaos.h"
16 #include "realm-craft.h"
17 #include "realm-crusade.h"
18 #include "realm-daemon.h"
19 #include "realm-death.h"
20 #include "realm-hex.h"
21 #include "realm-hissatsu.h"
22 #include "realm-life.h"
23 #include "realm-nature.h"
24 #include "realm-song.h"
25 #include "realm-sorcery.h"
26 #include "realm-trump.h"
29 #include "player-status.h"
30 #include "player-effects.h"
31 #include "object-hook.h"
32 #include "cmd-basic.h"
36 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
41 * @return フォーマットに従い整形された文字列
43 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
47 return format("%s%d", str, base);
51 return format("%s%dd%d", str, dice, sides);
53 /* Dice plus base value */
55 return format("%s%dd%d%+d", str, dice, sides, base);
60 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
64 * @return フォーマットに従い整形された文字列
66 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
68 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
72 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
75 * @return フォーマットに従い整形された文字列
77 concptr info_duration(int base, DICE_SID sides)
79 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
83 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
85 * @return フォーマットに従い整形された文字列
87 concptr info_range(POSITION range)
89 return format(_("範囲:%d", "range %d"), range);
93 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
97 * @return フォーマットに従い整形された文字列
99 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
101 return info_string_dice(_("回復:", "heal "), dice, sides, base);
105 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
108 * @return フォーマットに従い整形された文字列
110 concptr info_delay(int base, DICE_SID sides)
112 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
117 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
119 * @return フォーマットに従い整形された文字列
121 concptr info_multi_damage(HIT_POINT dam)
123 return format(_("損傷:各%d", "dam %d each"), dam);
128 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
131 * @return フォーマットに従い整形された文字列
133 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
135 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
139 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
141 * @return フォーマットに従い整形された文字列
143 concptr info_power(int power)
145 return format(_("効力:%d", "power %d"), power);
150 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
153 * @return フォーマットに従い整形された文字列
156 * Generate power info string such as "power 1d100"
158 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
160 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
165 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
167 * @return フォーマットに従い整形された文字列
169 concptr info_radius(POSITION rad)
171 return format(_("半径:%d", "rad %d"), rad);
176 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
178 * @return フォーマットに従い整形された文字列
180 concptr info_weight(WEIGHT weight)
183 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
185 return format("max wgt %d", weight/10);
190 * @brief 魔法が利用可能かどうかを返す /
191 * Determine if a spell is "okay" for the player to cast or study
192 * The spell must be legible, not forgotten, and also, to cast,
193 * it must be known, and to study, it must not be known.
195 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
196 * @param study_pray 祈りの学習判定目的ならばTRUE
197 * @param use_realm 魔法領域ID
200 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
202 const magic_type *s_ptr;
204 /* Access the spell */
205 if (!is_magic(use_realm))
207 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
211 s_ptr = &mp_ptr->info[use_realm - 1][spell];
214 /* Spell is illegal */
215 if (s_ptr->slevel > p_ptr->lev) return (FALSE);
217 /* Spell is forgotten */
218 if ((use_realm == p_ptr->realm2) ?
219 (p_ptr->spell_forgotten2 & (1L << spell)) :
220 (p_ptr->spell_forgotten1 & (1L << spell)))
226 if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
227 if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
229 /* Spell is learned */
230 if ((use_realm == p_ptr->realm2) ?
231 (p_ptr->spell_learned2 & (1L << spell)) :
232 (p_ptr->spell_learned1 & (1L << spell)))
235 return (!study_pray);
238 /* Okay to study, not to cast */
244 * @brief 魔法処理のメインルーチン
245 * @param realm 魔法領域のID
246 * @param spell 各領域の魔法ID
248 * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
250 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
254 case REALM_LIFE: return do_life_spell(spell, mode);
255 case REALM_SORCERY: return do_sorcery_spell(spell, mode);
256 case REALM_NATURE: return do_nature_spell(spell, mode);
257 case REALM_CHAOS: return do_chaos_spell(spell, mode);
258 case REALM_DEATH: return do_death_spell(spell, mode);
259 case REALM_TRUMP: return do_trump_spell(spell, mode);
260 case REALM_ARCANE: return do_arcane_spell(spell, mode);
261 case REALM_CRAFT: return do_craft_spell(spell, mode);
262 case REALM_DAEMON: return do_daemon_spell(spell, mode);
263 case REALM_CRUSADE: return do_crusade_spell(spell, mode);
264 case REALM_MUSIC: return do_music_spell(spell, mode);
265 case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
266 case REALM_HEX: return do_hex_spell(spell, mode);
274 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
275 * Allow user to choose a spell/prayer from the given book.
276 * @param sn 選択した魔法IDを返す参照ポインタ
277 * @param prompt 魔法を利用する際の動詞表記
278 * @param sval 魔道書のsval
279 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
280 * @param use_realm 魔法領域ID
283 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
284 * If the user hits escape, returns FALSE, and set '*sn' to -1
285 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
286 * The "prompt" should be "cast", "recite", or "study"
287 * The "known" should be TRUE for cast/pray, FALSE for study
290 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
293 SPELL_IDX spell = -1;
296 MANA_POINT need_mana;
297 SPELL_IDX spells[64];
298 bool flag, redraw, okay;
300 const magic_type *s_ptr;
307 int menu_line = (use_menu ? 1 : 0);
309 /* Get the spell, if available */
310 if (repeat_pull(&code))
312 *sn = (SPELL_IDX)code;
313 /* Verify the spell */
314 if (spell_okay(*sn, learned, FALSE, use_realm))
321 p = spell_category_name(mp_ptr->spell_book);
324 for (spell = 0; spell < 32; spell++)
326 /* Check for this spell */
327 if ((fake_spell_flags[sval] & (1L << spell)))
329 /* Collect this spell */
330 spells[num++] = spell;
334 /* Assume no usable spells */
337 /* Assume no spells available */
340 /* Check for "okay" spells */
341 for (i = 0; i < num; i++)
343 /* Look for "okay" spells */
344 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
347 /* No "okay" spells */
348 if (!okay) return (FALSE);
349 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
350 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
351 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
353 /* Assume cancelled */
356 /* Nothing chosen yet */
362 p_ptr->window |= (PW_SPELL);
365 /* Build a prompt (accept all spells) */
367 jverb(prompt, jverb_buf, JVERB_AND);
368 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
369 p, I2A(0), I2A(num - 1), p, jverb_buf);
371 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
372 p, I2A(0), I2A(num - 1), prompt, p);
375 choice = (always_show_list || use_menu) ? ESCAPE : 1;
378 if (choice == ESCAPE) choice = ' ';
379 else if (!get_com(out_val, &choice, TRUE))break;
381 if (use_menu && choice != ' ')
395 menu_line += (num - 1);
417 if (menu_line > num) menu_line -= num;
418 /* Display a list of spells */
419 print_spells(menu_line, spells, num, 1, 15, use_realm);
425 if ((choice == ' ') || (choice == '*') || (choice == '?'))
433 /* Display a list of spells */
434 print_spells(menu_line, spells, num, 1, 15, use_realm);
440 if (use_menu) continue;
453 ask = (isupper(choice));
456 if (ask) choice = (char)tolower(choice);
458 /* Extract request */
459 i = (islower(choice) ? A2I(choice) : -1);
462 /* Totally Illegal */
463 if ((i < 0) || (i >= num))
469 /* Save the spell index */
472 /* Require "okay" spells */
473 if (!spell_okay(spell, learned, FALSE, use_realm))
477 msg_format("その%sを%sことはできません。", p, prompt);
479 msg_format("You may not %s that %s.", prompt, p);
490 /* Access the spell */
491 if (!is_magic(use_realm))
493 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
497 s_ptr = &mp_ptr->info[use_realm - 1][spell];
500 /* Extract mana consumption rate */
501 if (use_realm == REALM_HISSATSU)
503 need_mana = s_ptr->smana;
507 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
512 jverb(prompt, jverb_buf, JVERB_AND);
514 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
515 do_spell(use_realm, spell, SPELL_NAME), need_mana,
516 spell_chance(spell, use_realm), jverb_buf);
518 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
519 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
520 spell_chance(spell, use_realm));
524 /* Belay that order */
525 if (!get_check(tmp_val)) continue;
532 if (redraw) screen_load();
534 p_ptr->window |= (PW_SPELL);
537 /* Abort if needed */
538 if (!flag) return FALSE;
540 /* Save the choice */
543 repeat_push((COMMAND_CODE)spell);
550 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
551 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
552 * @return 魔道書を一冊も持っていないならTRUEを返す
554 static void confirm_use_force(bool browse_only)
559 /* Get the item index */
560 if (repeat_pull(&code) && (code == INVEN_FORCE))
562 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
566 /* Show the prompt */
567 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
574 if (which == ESCAPE) break;
575 else if (which == 'w')
577 repeat_push(INVEN_FORCE);
582 /* Clear the prompt line */
587 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
593 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
594 * Peruse the spells/prayers in a book
598 * Note that *all* spells in the book are listed
600 * Note that browsing is allowed while confused or blind,
601 * and in the dark, primarily to allow browsing in stores.
604 void do_cmd_browse(void)
607 OBJECT_SUBTYPE_VALUE sval;
608 REALM_IDX use_realm = 0;
610 SPELL_IDX spell = -1;
613 SPELL_IDX spells[64];
620 /* Warriors are illiterate */
621 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
623 msg_print(_("本を読むことができない!", "You cannot read books!"));
627 if (p_ptr->special_defense & KATA_MUSOU)
629 set_action(ACTION_NONE);
632 if (p_ptr->pclass == CLASS_FORCETRAINER)
634 if (player_has_no_spellbooks())
636 confirm_use_force(TRUE);
641 /* Restrict choices to "useful" books */
642 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
643 else item_tester_hook = item_tester_learn_spell;
645 q = _("どの本を読みますか? ", "Browse which book? ");
646 s = _("読める本がない。", "You have no books that you can read.");
648 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
651 if (item == INVEN_FORCE) /* the_force */
653 do_cmd_mind_browse();
659 /* Access the item's sval */
662 use_realm = tval2realm(o_ptr->tval);
664 /* Track the object kind */
665 object_kind_track(o_ptr->k_idx);
669 for (spell = 0; spell < 32; spell++)
671 /* Check for this spell */
672 if ((fake_spell_flags[sval] & (1L << spell)))
674 /* Collect this spell */
675 spells[num++] = spell;
682 /* Keep browsing spells. Exit browsing on cancel. */
685 /* Ask for a spell, allow cancel */
686 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
688 /* If cancelled, leave immediately. */
689 if (spell == -1) break;
691 /* Display a list of spells */
692 print_spells(0, spells, num, 1, 15, use_realm);
694 /* Notify that there's nothing to see, and wait. */
695 if (use_realm == REALM_HISSATSU)
696 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
698 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
706 /* Clear lines, position cursor (really should use strlen here) */
707 Term_erase(14, 14, 255);
708 Term_erase(14, 13, 255);
709 Term_erase(14, 12, 255);
710 Term_erase(14, 11, 255);
712 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
714 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
716 prt(&temp[j], line, 15);
724 * @brief プレイヤーの第二魔法領域を変更する /
725 * @param next_realm 変更先の魔法領域ID
728 static void change_realm2(CHARACTER_IDX next_realm)
733 for (i = 0; i < 64; i++)
735 p_ptr->spell_order[j] = p_ptr->spell_order[i];
736 if (p_ptr->spell_order[i] < 32) j++;
739 p_ptr->spell_order[j] = 99;
741 for (i = 32; i < 64; i++)
743 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
745 p_ptr->spell_learned2 = 0L;
746 p_ptr->spell_worked2 = 0L;
747 p_ptr->spell_forgotten2 = 0L;
749 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
750 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
751 p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
752 p_ptr->realm2 = next_realm;
754 p_ptr->update |= (PU_REORDER);
755 p_ptr->update |= (PU_SPELLS);
758 /* Load an autopick preference file */
759 autopick_load_pref(FALSE);
764 * @brief 魔法を学習するコマンドのメインルーチン /
765 * Study a book to gain a new spell/prayer
768 void do_cmd_study(void)
772 OBJECT_SUBTYPE_VALUE sval;
774 bool learned = FALSE;
776 /* Spells of realm2 will have an increment of +32 */
777 SPELL_IDX spell = -1;
779 concptr p = spell_category_name(mp_ptr->spell_book);
787 msg_print(_("本を読むことができない!", "You cannot read books!"));
791 if (p_ptr->blind || no_lite())
793 msg_print(_("目が見えない!", "You cannot see!"));
797 if (cmd_limit_confused(p_ptr)) return;
799 if (!(p_ptr->new_spells))
801 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
805 if (p_ptr->special_defense & KATA_MUSOU)
807 set_action(ACTION_NONE);
811 if (p_ptr->new_spells < 10) {
812 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
815 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
818 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
819 (p_ptr->new_spells == 1 ? "" : "s"));
825 /* Restrict choices to "useful" books */
826 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
827 else item_tester_hook = item_tester_learn_spell;
829 q = _("どの本から学びますか? ", "Study which book? ");
830 s = _("読める本がない。", "You have no books that you can read.");
832 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
835 /* Access the item's sval */
838 if (o_ptr->tval == REALM2_BOOK) increment = 32;
839 else if (o_ptr->tval != REALM1_BOOK)
841 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
842 change_realm2(tval2realm(o_ptr->tval));
846 /* Track the object kind */
847 object_kind_track(o_ptr->k_idx);
850 /* Mage -- Learn a selected spell */
851 if (mp_ptr->spell_book != TV_LIFE_BOOK)
853 /* Ask for a spell, allow cancel */
854 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
857 /* Priest -- Learn a random prayer */
864 for (spell = 0; spell < 32; spell++)
866 /* Check spells in the book */
867 if ((fake_spell_flags[sval] & (1L << spell)))
869 /* Skip non "okay" prayers */
870 if (!spell_okay(spell, FALSE, TRUE,
871 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
873 /* Hack -- Prepare the randomizer */
876 /* Hack -- Apply the randomizer */
877 if (one_in_(k)) gift = spell;
885 /* Nothing to study */
888 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
894 if (increment) spell += increment;
896 /* Learn the spell */
899 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
900 else p_ptr->spell_learned1 |= (1L << spell);
904 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
905 else p_ptr->spell_learned2 |= (1L << (spell - 32));
910 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
911 int old_exp = p_ptr->spell_exp[spell];
912 int new_rank = EXP_LEVEL_UNSKILLED;
913 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
915 if (old_exp >= max_exp)
917 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
921 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
923 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
928 else if (old_exp >= SPELL_EXP_EXPERT)
930 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
931 new_rank = EXP_LEVEL_MASTER;
933 else if (old_exp >= SPELL_EXP_SKILLED)
935 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
936 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
937 new_rank = EXP_LEVEL_EXPERT;
939 else if (old_exp >= SPELL_EXP_BEGINNER)
941 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
942 new_rank = EXP_LEVEL_SKILLED;
946 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
947 new_rank = EXP_LEVEL_BEGINNER;
949 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
953 /* Find the next open entry in "p_ptr->spell_order[]" */
954 for (i = 0; i < 64; i++)
956 /* Stop at the first empty space */
957 if (p_ptr->spell_order[i] == 99) break;
960 /* Add the spell to the known list */
961 p_ptr->spell_order[i++] = spell;
963 /* Mention the result */
966 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
968 msg_format("%sを学んだ。",
969 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
973 msg_format("%sの%sを学んだ。",
974 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
977 msg_format("You have learned the %s of %s.",
978 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
982 take_turn(p_ptr, 100);
984 switch (mp_ptr->spell_book)
987 chg_virtue(V_FAITH, 1);
990 chg_virtue(V_UNLIFE, 1);
993 chg_virtue(V_NATURE, 1);
996 chg_virtue(V_KNOWLEDGE, 1);
1002 /* One less spell available */
1003 p_ptr->learned_spells++;
1006 p_ptr->update |= (PU_SPELLS);
1007 update_creature(p_ptr);
1009 /* Redraw object recall */
1010 p_ptr->window |= (PW_OBJECT);
1015 * @brief 魔法を詠唱するコマンドのメインルーチン /
1019 void do_cmd_cast(void)
1022 OBJECT_SUBTYPE_VALUE sval;
1027 REALM_IDX use_realm;
1028 MANA_POINT need_mana;
1032 const magic_type *s_ptr;
1035 bool over_exerted = FALSE;
1037 /* Require spell ability */
1038 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1040 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1045 if (p_ptr->blind || no_lite())
1047 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1050 msg_print(_("目が見えない!", "You cannot see!"));
1056 if (cmd_limit_confused(p_ptr)) return;
1059 if (p_ptr->realm1 == REALM_HEX)
1061 if (hex_spell_fully())
1064 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1066 if (p_ptr->lev >= 35) flag = stop_hex_spell();
1071 if (p_ptr->pclass == CLASS_FORCETRAINER)
1073 if (player_has_no_spellbooks())
1075 confirm_use_force(FALSE);
1080 prayer = spell_category_name(mp_ptr->spell_book);
1082 /* Restrict choices to spell books */
1083 item_tester_tval = mp_ptr->spell_book;
1085 q = _("どの呪文書を使いますか? ", "Use which book? ");
1086 s = _("呪文書がない!", "You have no spell books!");
1088 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
1091 if (item == INVEN_FORCE) /* the_force */
1099 /* Access the item's sval */
1102 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1104 /* Track the object kind */
1105 object_kind_track(o_ptr->k_idx);
1108 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1109 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1110 else if (increment) realm = p_ptr->realm2;
1111 else realm = p_ptr->realm1;
1113 /* Ask for a spell */
1115 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1118 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1122 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1126 msg_format("You don't know any %ss in that book.", prayer);
1132 use_realm = tval2realm(o_ptr->tval);
1135 if (use_realm == REALM_HEX)
1137 if (hex_spelling(spell))
1139 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1144 if (!is_magic(use_realm))
1146 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1150 s_ptr = &mp_ptr->info[realm - 1][spell];
1153 /* Extract mana consumption rate */
1154 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1156 /* Verify "dangerous" spells */
1157 if (need_mana > p_ptr->csp)
1159 if (flush_failure) flush();
1163 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1164 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1166 msg_format("You do not have enough mana to %s this %s.",
1167 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1172 if (!over_exert) return;
1175 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1178 /* Spell failure chance */
1179 chance = spell_chance(spell, use_realm);
1181 /* Sufficient mana */
1182 if (need_mana <= p_ptr->csp)
1185 p_ptr->csp -= need_mana;
1187 else over_exerted = TRUE;
1188 p_ptr->redraw |= (PR_MANA);
1191 if (randint0(100) < chance)
1193 if (flush_failure) flush();
1195 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1201 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1204 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1207 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1210 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1213 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1216 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1219 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1223 /* Failure casting may activate some side effect */
1224 do_spell(realm, spell, SPELL_FAIL);
1227 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1229 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1232 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1234 if ((sval == 3) && one_in_(2))
1236 sanity_blast(0, TRUE);
1240 msg_print(_("痛い!", "It hurts!"));
1241 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1243 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1244 lose_exp(spell * 250);
1247 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1249 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1250 aggravate_monsters(0);
1252 if (randint1(100) >= chance)
1253 chg_virtue(V_CHANCE, -1);
1259 /* Canceled spells cost neither a current_world_ptr->game_turn nor mana */
1260 if (!do_spell(realm, spell, SPELL_CAST)) return;
1262 if (randint1(100) < chance)
1263 chg_virtue(V_CHANCE, 1);
1265 /* A spell was cast */
1267 (p_ptr->spell_worked2 & (1L << spell)) :
1268 (p_ptr->spell_worked1 & (1L << spell)))
1269 && (p_ptr->pclass != CLASS_SORCERER)
1270 && (p_ptr->pclass != CLASS_RED_MAGE))
1272 int e = s_ptr->sexp;
1274 /* The spell worked */
1275 if (realm == p_ptr->realm1)
1277 p_ptr->spell_worked1 |= (1L << spell);
1281 p_ptr->spell_worked2 |= (1L << spell);
1284 /* Gain experience */
1285 gain_exp(e * s_ptr->slevel);
1287 /* Redraw object recall */
1288 p_ptr->window |= (PW_OBJECT);
1293 chg_virtue(V_TEMPERANCE, 1);
1294 chg_virtue(V_COMPASSION, 1);
1295 chg_virtue(V_VITALITY, 1);
1296 chg_virtue(V_DILIGENCE, 1);
1299 chg_virtue(V_UNLIFE, 1);
1300 chg_virtue(V_JUSTICE, -1);
1301 chg_virtue(V_FAITH, -1);
1302 chg_virtue(V_VITALITY, -1);
1305 chg_virtue(V_JUSTICE, -1);
1306 chg_virtue(V_FAITH, -1);
1307 chg_virtue(V_HONOUR, -1);
1308 chg_virtue(V_TEMPERANCE, -1);
1311 chg_virtue(V_FAITH, 1);
1312 chg_virtue(V_JUSTICE, 1);
1313 chg_virtue(V_SACRIFICE, 1);
1314 chg_virtue(V_HONOUR, 1);
1317 chg_virtue(V_NATURE, 1);
1318 chg_virtue(V_HARMONY, 1);
1321 chg_virtue(V_JUSTICE, -1);
1322 chg_virtue(V_FAITH, -1);
1323 chg_virtue(V_HONOUR, -1);
1324 chg_virtue(V_COMPASSION, -1);
1327 chg_virtue(V_KNOWLEDGE, 1);
1334 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1335 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1336 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1337 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1340 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1341 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1342 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1343 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1346 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1347 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1348 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1349 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1352 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1353 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1354 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1355 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1358 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1359 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 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_HONOUR, -1);
1365 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1368 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1370 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0) + spell];
1373 if (cur_exp < SPELL_EXP_BEGINNER)
1375 else if (cur_exp < SPELL_EXP_SKILLED)
1377 if ((current_floor_ptr->dun_level > 4) && ((current_floor_ptr->dun_level + 10) > p_ptr->lev))
1380 else if (cur_exp < SPELL_EXP_EXPERT)
1382 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && ((current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1385 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1387 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && (current_floor_ptr->dun_level > s_ptr->slevel))
1390 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1394 take_turn(p_ptr, 100);
1397 /* Over-exert the player */
1400 int oops = need_mana;
1404 p_ptr->csp_frac = 0;
1406 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1408 /* Hack -- Bypass free action */
1409 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1414 chg_virtue(V_VITALITY, -10);
1417 chg_virtue(V_UNLIFE, -10);
1420 chg_virtue(V_JUSTICE, 10);
1423 chg_virtue(V_NATURE, -10);
1426 chg_virtue(V_JUSTICE, -10);
1429 chg_virtue(V_COMPASSION, 10);
1432 chg_virtue(V_KNOWLEDGE, -10);
1436 /* Damage CON (possibly permanently) */
1437 if (randint0(100) < 50)
1439 bool perm = (randint0(100) < 25);
1441 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1443 /* Reduce constitution */
1444 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1448 p_ptr->window |= (PW_PLAYER);
1449 p_ptr->window |= (PW_SPELL);