3 @brief 魔法のインターフェイスと発動 / Purpose: Do everything for each spell
6 2013 Deskull rearranged comment for Doxygen.
11 #include "spells-summon.h"
12 #include "realm-arcane.h"
13 #include "realm-chaos.h"
14 #include "realm-craft.h"
15 #include "realm-crusade.h"
16 #include "realm-daemon.h"
17 #include "realm-death.h"
18 #include "realm-hex.h"
19 #include "realm-hissatsu.h"
20 #include "realm-life.h"
21 #include "realm-nature.h"
22 #include "realm-song.h"
23 #include "realm-sorcery.h"
24 #include "realm-trump.h"
27 #include "player-status.h"
28 #include "player-effects.h"
29 #include "object-hook.h"
30 #include "cmd-basic.h"
34 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
39 * @return フォーマットに従い整形された文字列
41 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
45 return format("%s%d", str, base);
49 return format("%s%dd%d", str, dice, sides);
51 /* Dice plus base value */
53 return format("%s%dd%d%+d", str, dice, sides, base);
58 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
62 * @return フォーマットに従い整形された文字列
64 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
66 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
70 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
73 * @return フォーマットに従い整形された文字列
75 concptr info_duration(int base, DICE_SID sides)
77 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
81 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
83 * @return フォーマットに従い整形された文字列
85 concptr info_range(POSITION range)
87 return format(_("範囲:%d", "range %d"), range);
91 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
95 * @return フォーマットに従い整形された文字列
97 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
99 return info_string_dice(_("回復:", "heal "), dice, sides, base);
103 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
106 * @return フォーマットに従い整形された文字列
108 concptr info_delay(int base, DICE_SID sides)
110 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
115 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
117 * @return フォーマットに従い整形された文字列
119 concptr info_multi_damage(HIT_POINT dam)
121 return format(_("損傷:各%d", "dam %d each"), dam);
126 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
129 * @return フォーマットに従い整形された文字列
131 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
133 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
137 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
139 * @return フォーマットに従い整形された文字列
141 concptr info_power(int power)
143 return format(_("効力:%d", "power %d"), power);
148 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
151 * @return フォーマットに従い整形された文字列
154 * Generate power info string such as "power 1d100"
156 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
158 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
163 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
165 * @return フォーマットに従い整形された文字列
167 concptr info_radius(POSITION rad)
169 return format(_("半径:%d", "rad %d"), rad);
174 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
176 * @return フォーマットに従い整形された文字列
178 concptr info_weight(WEIGHT weight)
181 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
183 return format("max wgt %d", weight/10);
188 * @brief 魔法が利用可能かどうかを返す /
189 * Determine if a spell is "okay" for the player to cast or study
190 * The spell must be legible, not forgotten, and also, to cast,
191 * it must be known, and to study, it must not be known.
193 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
194 * @param study_pray 祈りの学習判定目的ならばTRUE
195 * @param use_realm 魔法領域ID
198 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
200 const magic_type *s_ptr;
202 /* Access the spell */
203 if (!is_magic(use_realm))
205 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
209 s_ptr = &mp_ptr->info[use_realm - 1][spell];
212 /* Spell is illegal */
213 if (s_ptr->slevel > p_ptr->lev) return (FALSE);
215 /* Spell is forgotten */
216 if ((use_realm == p_ptr->realm2) ?
217 (p_ptr->spell_forgotten2 & (1L << spell)) :
218 (p_ptr->spell_forgotten1 & (1L << spell)))
224 if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
225 if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
227 /* Spell is learned */
228 if ((use_realm == p_ptr->realm2) ?
229 (p_ptr->spell_learned2 & (1L << spell)) :
230 (p_ptr->spell_learned1 & (1L << spell)))
233 return (!study_pray);
236 /* Okay to study, not to cast */
242 * @brief 魔法処理のメインルーチン
243 * @param realm 魔法領域のID
244 * @param spell 各領域の魔法ID
246 * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
248 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
252 case REALM_LIFE: return do_life_spell(spell, mode);
253 case REALM_SORCERY: return do_sorcery_spell(spell, mode);
254 case REALM_NATURE: return do_nature_spell(spell, mode);
255 case REALM_CHAOS: return do_chaos_spell(spell, mode);
256 case REALM_DEATH: return do_death_spell(spell, mode);
257 case REALM_TRUMP: return do_trump_spell(spell, mode);
258 case REALM_ARCANE: return do_arcane_spell(spell, mode);
259 case REALM_CRAFT: return do_craft_spell(spell, mode);
260 case REALM_DAEMON: return do_daemon_spell(spell, mode);
261 case REALM_CRUSADE: return do_crusade_spell(spell, mode);
262 case REALM_MUSIC: return do_music_spell(spell, mode);
263 case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
264 case REALM_HEX: return do_hex_spell(spell, mode);
272 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
273 * Allow user to choose a spell/prayer from the given book.
274 * @param sn 選択した魔法IDを返す参照ポインタ
275 * @param prompt 魔法を利用する際の動詞表記
276 * @param sval 魔道書のsval
277 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
278 * @param use_realm 魔法領域ID
281 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
282 * If the user hits escape, returns FALSE, and set '*sn' to -1
283 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
284 * The "prompt" should be "cast", "recite", or "study"
285 * The "known" should be TRUE for cast/pray, FALSE for study
288 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
291 SPELL_IDX spell = -1;
294 MANA_POINT need_mana;
295 SPELL_IDX spells[64];
296 bool flag, redraw, okay;
298 const magic_type *s_ptr;
305 int menu_line = (use_menu ? 1 : 0);
307 /* Get the spell, if available */
308 if (repeat_pull(&code))
310 *sn = (SPELL_IDX)code;
311 /* Verify the spell */
312 if (spell_okay(*sn, learned, FALSE, use_realm))
319 p = spell_category_name(mp_ptr->spell_book);
322 for (spell = 0; spell < 32; spell++)
324 /* Check for this spell */
325 if ((fake_spell_flags[sval] & (1L << spell)))
327 /* Collect this spell */
328 spells[num++] = spell;
332 /* Assume no usable spells */
335 /* Assume no spells available */
338 /* Check for "okay" spells */
339 for (i = 0; i < num; i++)
341 /* Look for "okay" spells */
342 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
345 /* No "okay" spells */
346 if (!okay) return (FALSE);
347 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
348 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
349 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
351 /* Assume cancelled */
354 /* Nothing chosen yet */
360 p_ptr->window |= (PW_SPELL);
363 /* Build a prompt (accept all spells) */
365 jverb(prompt, jverb_buf, JVERB_AND);
366 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
367 p, I2A(0), I2A(num - 1), p, jverb_buf);
369 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
370 p, I2A(0), I2A(num - 1), prompt, p);
373 choice = (always_show_list || use_menu) ? ESCAPE : 1;
376 if (choice == ESCAPE) choice = ' ';
377 else if (!get_com(out_val, &choice, TRUE))break;
379 if (use_menu && choice != ' ')
393 menu_line += (num - 1);
415 if (menu_line > num) menu_line -= num;
416 /* Display a list of spells */
417 print_spells(menu_line, spells, num, 1, 15, use_realm);
423 if ((choice == ' ') || (choice == '*') || (choice == '?'))
431 /* Display a list of spells */
432 print_spells(menu_line, spells, num, 1, 15, use_realm);
438 if (use_menu) continue;
451 ask = (isupper(choice));
454 if (ask) choice = (char)tolower(choice);
456 /* Extract request */
457 i = (islower(choice) ? A2I(choice) : -1);
460 /* Totally Illegal */
461 if ((i < 0) || (i >= num))
467 /* Save the spell index */
470 /* Require "okay" spells */
471 if (!spell_okay(spell, learned, FALSE, use_realm))
475 msg_format("その%sを%sことはできません。", p, prompt);
477 msg_format("You may not %s that %s.", prompt, p);
488 /* Access the spell */
489 if (!is_magic(use_realm))
491 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
495 s_ptr = &mp_ptr->info[use_realm - 1][spell];
498 /* Extract mana consumption rate */
499 if (use_realm == REALM_HISSATSU)
501 need_mana = s_ptr->smana;
505 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
510 jverb(prompt, jverb_buf, JVERB_AND);
512 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
513 do_spell(use_realm, spell, SPELL_NAME), need_mana,
514 spell_chance(spell, use_realm), jverb_buf);
516 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
517 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
518 spell_chance(spell, use_realm));
522 /* Belay that order */
523 if (!get_check(tmp_val)) continue;
530 if (redraw) screen_load();
532 p_ptr->window |= (PW_SPELL);
535 /* Abort if needed */
536 if (!flag) return FALSE;
538 /* Save the choice */
541 repeat_push((COMMAND_CODE)spell);
548 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
549 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
550 * @return 魔道書を一冊も持っていないならTRUEを返す
552 static void confirm_use_force(bool browse_only)
557 /* Get the item index */
558 if (repeat_pull(&code) && (code == INVEN_FORCE))
560 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
564 /* Show the prompt */
565 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
572 if (which == ESCAPE) break;
573 else if (which == 'w')
575 repeat_push(INVEN_FORCE);
580 /* Clear the prompt line */
585 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
591 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
592 * Peruse the spells/prayers in a book
596 * Note that *all* spells in the book are listed
598 * Note that browsing is allowed while confused or blind,
599 * and in the dark, primarily to allow browsing in stores.
602 void do_cmd_browse(void)
605 OBJECT_SUBTYPE_VALUE sval;
606 REALM_IDX use_realm = 0;
608 SPELL_IDX spell = -1;
611 SPELL_IDX spells[64];
618 /* Warriors are illiterate */
619 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
621 msg_print(_("本を読むことができない!", "You cannot read books!"));
625 if (p_ptr->special_defense & KATA_MUSOU)
627 set_action(ACTION_NONE);
630 if (p_ptr->pclass == CLASS_FORCETRAINER)
632 if (player_has_no_spellbooks())
634 confirm_use_force(TRUE);
639 /* Restrict choices to "useful" books */
640 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
641 else item_tester_hook = item_tester_learn_spell;
643 q = _("どの本を読みますか? ", "Browse which book? ");
644 s = _("読める本がない。", "You have no books that you can read.");
646 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
649 if (item == INVEN_FORCE) /* the_force */
651 do_cmd_mind_browse();
657 /* Access the item's sval */
660 use_realm = tval2realm(o_ptr->tval);
662 /* Track the object kind */
663 object_kind_track(o_ptr->k_idx);
667 for (spell = 0; spell < 32; spell++)
669 /* Check for this spell */
670 if ((fake_spell_flags[sval] & (1L << spell)))
672 /* Collect this spell */
673 spells[num++] = spell;
680 /* Keep browsing spells. Exit browsing on cancel. */
683 /* Ask for a spell, allow cancel */
684 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
686 /* If cancelled, leave immediately. */
687 if (spell == -1) break;
689 /* Display a list of spells */
690 print_spells(0, spells, num, 1, 15, use_realm);
692 /* Notify that there's nothing to see, and wait. */
693 if (use_realm == REALM_HISSATSU)
694 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
696 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
704 /* Clear lines, position cursor (really should use strlen here) */
705 Term_erase(14, 14, 255);
706 Term_erase(14, 13, 255);
707 Term_erase(14, 12, 255);
708 Term_erase(14, 11, 255);
710 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
712 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
714 prt(&temp[j], line, 15);
722 * @brief プレイヤーの第二魔法領域を変更する /
723 * @param next_realm 変更先の魔法領域ID
726 static void change_realm2(CHARACTER_IDX next_realm)
731 for (i = 0; i < 64; i++)
733 p_ptr->spell_order[j] = p_ptr->spell_order[i];
734 if (p_ptr->spell_order[i] < 32) j++;
737 p_ptr->spell_order[j] = 99;
739 for (i = 32; i < 64; i++)
741 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
743 p_ptr->spell_learned2 = 0L;
744 p_ptr->spell_worked2 = 0L;
745 p_ptr->spell_forgotten2 = 0L;
747 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
748 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
749 p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
750 p_ptr->realm2 = next_realm;
752 p_ptr->update |= (PU_REORDER);
753 p_ptr->update |= (PU_SPELLS);
756 /* Load an autopick preference file */
757 autopick_load_pref(FALSE);
762 * @brief 魔法を学習するコマンドのメインルーチン /
763 * Study a book to gain a new spell/prayer
766 void do_cmd_study(void)
770 OBJECT_SUBTYPE_VALUE sval;
772 bool learned = FALSE;
774 /* Spells of realm2 will have an increment of +32 */
775 SPELL_IDX spell = -1;
777 concptr p = spell_category_name(mp_ptr->spell_book);
785 msg_print(_("本を読むことができない!", "You cannot read books!"));
789 if (p_ptr->blind || no_lite())
791 msg_print(_("目が見えない!", "You cannot see!"));
795 if (cmd_limit_confused(p_ptr)) return;
797 if (!(p_ptr->new_spells))
799 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
803 if (p_ptr->special_defense & KATA_MUSOU)
805 set_action(ACTION_NONE);
809 if (p_ptr->new_spells < 10) {
810 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
813 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
816 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
817 (p_ptr->new_spells == 1 ? "" : "s"));
823 /* Restrict choices to "useful" books */
824 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
825 else item_tester_hook = item_tester_learn_spell;
827 q = _("どの本から学びますか? ", "Study which book? ");
828 s = _("読める本がない。", "You have no books that you can read.");
830 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
833 /* Access the item's sval */
836 if (o_ptr->tval == REALM2_BOOK) increment = 32;
837 else if (o_ptr->tval != REALM1_BOOK)
839 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
840 change_realm2(tval2realm(o_ptr->tval));
844 /* Track the object kind */
845 object_kind_track(o_ptr->k_idx);
848 /* Mage -- Learn a selected spell */
849 if (mp_ptr->spell_book != TV_LIFE_BOOK)
851 /* Ask for a spell, allow cancel */
852 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
855 /* Priest -- Learn a random prayer */
862 for (spell = 0; spell < 32; spell++)
864 /* Check spells in the book */
865 if ((fake_spell_flags[sval] & (1L << spell)))
867 /* Skip non "okay" prayers */
868 if (!spell_okay(spell, FALSE, TRUE,
869 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
871 /* Hack -- Prepare the randomizer */
874 /* Hack -- Apply the randomizer */
875 if (one_in_(k)) gift = spell;
883 /* Nothing to study */
886 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
892 if (increment) spell += increment;
894 /* Learn the spell */
897 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
898 else p_ptr->spell_learned1 |= (1L << spell);
902 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
903 else p_ptr->spell_learned2 |= (1L << (spell - 32));
908 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
909 int old_exp = p_ptr->spell_exp[spell];
910 int new_rank = EXP_LEVEL_UNSKILLED;
911 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
913 if (old_exp >= max_exp)
915 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
919 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
921 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
926 else if (old_exp >= SPELL_EXP_EXPERT)
928 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
929 new_rank = EXP_LEVEL_MASTER;
931 else if (old_exp >= SPELL_EXP_SKILLED)
933 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
934 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
935 new_rank = EXP_LEVEL_EXPERT;
937 else if (old_exp >= SPELL_EXP_BEGINNER)
939 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
940 new_rank = EXP_LEVEL_SKILLED;
944 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
945 new_rank = EXP_LEVEL_BEGINNER;
947 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
951 /* Find the next open entry in "p_ptr->spell_order[]" */
952 for (i = 0; i < 64; i++)
954 /* Stop at the first empty space */
955 if (p_ptr->spell_order[i] == 99) break;
958 /* Add the spell to the known list */
959 p_ptr->spell_order[i++] = spell;
961 /* Mention the result */
964 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
966 msg_format("%sを学んだ。",
967 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
971 msg_format("%sの%sを学んだ。",
972 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
975 msg_format("You have learned the %s of %s.",
976 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
980 take_turn(p_ptr, 100);
982 switch (mp_ptr->spell_book)
985 chg_virtue(V_FAITH, 1);
988 chg_virtue(V_UNLIFE, 1);
991 chg_virtue(V_NATURE, 1);
994 chg_virtue(V_KNOWLEDGE, 1);
1000 /* One less spell available */
1001 p_ptr->learned_spells++;
1004 p_ptr->update |= (PU_SPELLS);
1005 update_creature(p_ptr);
1007 /* Redraw object recall */
1008 p_ptr->window |= (PW_OBJECT);
1013 * @brief 魔法を詠唱するコマンドのメインルーチン /
1017 void do_cmd_cast(void)
1020 OBJECT_SUBTYPE_VALUE sval;
1025 REALM_IDX use_realm;
1026 MANA_POINT need_mana;
1030 const magic_type *s_ptr;
1033 bool over_exerted = FALSE;
1035 /* Require spell ability */
1036 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1038 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1043 if (p_ptr->blind || no_lite())
1045 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1048 msg_print(_("目が見えない!", "You cannot see!"));
1054 if (cmd_limit_confused(p_ptr)) return;
1057 if (p_ptr->realm1 == REALM_HEX)
1059 if (hex_spell_fully())
1062 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1064 if (p_ptr->lev >= 35) flag = stop_hex_spell();
1069 if (p_ptr->pclass == CLASS_FORCETRAINER)
1071 if (player_has_no_spellbooks())
1073 confirm_use_force(FALSE);
1078 prayer = spell_category_name(mp_ptr->spell_book);
1080 /* Restrict choices to spell books */
1081 item_tester_tval = mp_ptr->spell_book;
1083 q = _("どの呪文書を使いますか? ", "Use which book? ");
1084 s = _("呪文書がない!", "You have no spell books!");
1086 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
1089 if (item == INVEN_FORCE) /* the_force */
1097 /* Access the item's sval */
1100 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1102 /* Track the object kind */
1103 object_kind_track(o_ptr->k_idx);
1106 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1107 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1108 else if (increment) realm = p_ptr->realm2;
1109 else realm = p_ptr->realm1;
1111 /* Ask for a spell */
1113 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1116 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1120 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1124 msg_format("You don't know any %ss in that book.", prayer);
1130 use_realm = tval2realm(o_ptr->tval);
1133 if (use_realm == REALM_HEX)
1135 if (hex_spelling(spell))
1137 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1142 if (!is_magic(use_realm))
1144 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1148 s_ptr = &mp_ptr->info[realm - 1][spell];
1151 /* Extract mana consumption rate */
1152 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1154 /* Verify "dangerous" spells */
1155 if (need_mana > p_ptr->csp)
1157 if (flush_failure) flush();
1161 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1162 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1164 msg_format("You do not have enough mana to %s this %s.",
1165 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1170 if (!over_exert) return;
1173 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1176 /* Spell failure chance */
1177 chance = spell_chance(spell, use_realm);
1179 /* Sufficient mana */
1180 if (need_mana <= p_ptr->csp)
1183 p_ptr->csp -= need_mana;
1185 else over_exerted = TRUE;
1186 p_ptr->redraw |= (PR_MANA);
1189 if (randint0(100) < chance)
1191 if (flush_failure) flush();
1193 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1199 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1202 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1205 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1208 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1211 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1214 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1217 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1221 /* Failure casting may activate some side effect */
1222 do_spell(realm, spell, SPELL_FAIL);
1225 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1227 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1230 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1232 if ((sval == 3) && one_in_(2))
1234 sanity_blast(0, TRUE);
1238 msg_print(_("痛い!", "It hurts!"));
1239 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1241 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1242 lose_exp(spell * 250);
1245 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1247 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1248 aggravate_monsters(0);
1250 if (randint1(100) >= chance)
1251 chg_virtue(V_CHANCE, -1);
1257 /* Canceled spells cost neither a current_world_ptr->game_turn nor mana */
1258 if (!do_spell(realm, spell, SPELL_CAST)) return;
1260 if (randint1(100) < chance)
1261 chg_virtue(V_CHANCE, 1);
1263 /* A spell was cast */
1265 (p_ptr->spell_worked2 & (1L << spell)) :
1266 (p_ptr->spell_worked1 & (1L << spell)))
1267 && (p_ptr->pclass != CLASS_SORCERER)
1268 && (p_ptr->pclass != CLASS_RED_MAGE))
1270 int e = s_ptr->sexp;
1272 /* The spell worked */
1273 if (realm == p_ptr->realm1)
1275 p_ptr->spell_worked1 |= (1L << spell);
1279 p_ptr->spell_worked2 |= (1L << spell);
1282 /* Gain experience */
1283 gain_exp(e * s_ptr->slevel);
1285 /* Redraw object recall */
1286 p_ptr->window |= (PW_OBJECT);
1291 chg_virtue(V_TEMPERANCE, 1);
1292 chg_virtue(V_COMPASSION, 1);
1293 chg_virtue(V_VITALITY, 1);
1294 chg_virtue(V_DILIGENCE, 1);
1297 chg_virtue(V_UNLIFE, 1);
1298 chg_virtue(V_JUSTICE, -1);
1299 chg_virtue(V_FAITH, -1);
1300 chg_virtue(V_VITALITY, -1);
1303 chg_virtue(V_JUSTICE, -1);
1304 chg_virtue(V_FAITH, -1);
1305 chg_virtue(V_HONOUR, -1);
1306 chg_virtue(V_TEMPERANCE, -1);
1309 chg_virtue(V_FAITH, 1);
1310 chg_virtue(V_JUSTICE, 1);
1311 chg_virtue(V_SACRIFICE, 1);
1312 chg_virtue(V_HONOUR, 1);
1315 chg_virtue(V_NATURE, 1);
1316 chg_virtue(V_HARMONY, 1);
1319 chg_virtue(V_JUSTICE, -1);
1320 chg_virtue(V_FAITH, -1);
1321 chg_virtue(V_HONOUR, -1);
1322 chg_virtue(V_COMPASSION, -1);
1325 chg_virtue(V_KNOWLEDGE, 1);
1332 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1333 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1334 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1335 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1338 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1339 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1340 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1341 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1344 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1345 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1346 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1347 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1350 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1351 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1352 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1353 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1356 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1357 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1360 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1361 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1362 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1363 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1366 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1368 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0) + spell];
1371 if (cur_exp < SPELL_EXP_BEGINNER)
1373 else if (cur_exp < SPELL_EXP_SKILLED)
1375 if ((current_floor_ptr->dun_level > 4) && ((current_floor_ptr->dun_level + 10) > p_ptr->lev))
1378 else if (cur_exp < SPELL_EXP_EXPERT)
1380 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && ((current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1383 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1385 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && (current_floor_ptr->dun_level > s_ptr->slevel))
1388 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1392 take_turn(p_ptr, 100);
1395 /* Over-exert the player */
1398 int oops = need_mana;
1402 p_ptr->csp_frac = 0;
1404 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1406 /* Hack -- Bypass free action */
1407 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1412 chg_virtue(V_VITALITY, -10);
1415 chg_virtue(V_UNLIFE, -10);
1418 chg_virtue(V_JUSTICE, 10);
1421 chg_virtue(V_NATURE, -10);
1424 chg_virtue(V_JUSTICE, -10);
1427 chg_virtue(V_COMPASSION, 10);
1430 chg_virtue(V_KNOWLEDGE, -10);
1434 /* Damage CON (possibly permanently) */
1435 if (randint0(100) < 50)
1437 bool perm = (randint0(100) < 25);
1439 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1441 /* Reduce constitution */
1442 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1446 p_ptr->window |= (PW_PLAYER);
1447 p_ptr->window |= (PW_SPELL);