3 @brief 魔法のインターフェイスと発動 / Purpose: Do everything for each spell
6 2013 Deskull rearranged comment for Doxygen.
14 #include "spells-summon.h"
15 #include "realm-arcane.h"
16 #include "realm-chaos.h"
17 #include "realm-craft.h"
18 #include "realm-crusade.h"
19 #include "realm-daemon.h"
20 #include "realm-death.h"
21 #include "realm-hex.h"
22 #include "realm-hissatsu.h"
23 #include "realm-life.h"
24 #include "realm-nature.h"
25 #include "realm-song.h"
26 #include "realm-sorcery.h"
27 #include "realm-trump.h"
30 #include "player-status.h"
31 #include "player-effects.h"
32 #include "player-skill.h"
33 #include "object-hook.h"
34 #include "cmd-basic.h"
35 #include "view-mainwindow.h"
39 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
44 * @return フォーマットに従い整形された文字列
46 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
50 return format("%s%d", str, base);
54 return format("%s%dd%d", str, dice, sides);
56 /* Dice plus base value */
58 return format("%s%dd%d%+d", str, dice, sides, base);
63 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
67 * @return フォーマットに従い整形された文字列
69 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
71 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
75 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
78 * @return フォーマットに従い整形された文字列
80 concptr info_duration(int base, DICE_SID sides)
82 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
86 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
88 * @return フォーマットに従い整形された文字列
90 concptr info_range(POSITION range)
92 return format(_("範囲:%d", "range %d"), range);
96 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
100 * @return フォーマットに従い整形された文字列
102 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
104 return info_string_dice(_("回復:", "heal "), dice, sides, base);
108 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
111 * @return フォーマットに従い整形された文字列
113 concptr info_delay(int base, DICE_SID sides)
115 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
120 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
122 * @return フォーマットに従い整形された文字列
124 concptr info_multi_damage(HIT_POINT dam)
126 return format(_("損傷:各%d", "dam %d each"), dam);
131 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
134 * @return フォーマットに従い整形された文字列
136 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
138 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
142 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
144 * @return フォーマットに従い整形された文字列
146 concptr info_power(int power)
148 return format(_("効力:%d", "power %d"), power);
153 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
156 * @return フォーマットに従い整形された文字列
159 * Generate power info string such as "power 1d100"
161 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
163 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
168 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
170 * @return フォーマットに従い整形された文字列
172 concptr info_radius(POSITION rad)
174 return format(_("半径:%d", "rad %d"), rad);
179 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
181 * @return フォーマットに従い整形された文字列
183 concptr info_weight(WEIGHT weight)
186 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
188 return format("max wgt %d", weight/10);
193 * @brief 魔法が利用可能かどうかを返す /
194 * Determine if a spell is "okay" for the player to cast or study
195 * The spell must be legible, not forgotten, and also, to cast,
196 * it must be known, and to study, it must not be known.
198 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
199 * @param study_pray 祈りの学習判定目的ならばTRUE
200 * @param use_realm 魔法領域ID
203 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
205 const magic_type *s_ptr;
207 /* Access the spell */
208 if (!is_magic(use_realm))
210 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
214 s_ptr = &mp_ptr->info[use_realm - 1][spell];
217 /* Spell is illegal */
218 if (s_ptr->slevel > p_ptr->lev) return (FALSE);
220 /* Spell is forgotten */
221 if ((use_realm == p_ptr->realm2) ?
222 (p_ptr->spell_forgotten2 & (1L << spell)) :
223 (p_ptr->spell_forgotten1 & (1L << spell)))
229 if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
230 if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
232 /* Spell is learned */
233 if ((use_realm == p_ptr->realm2) ?
234 (p_ptr->spell_learned2 & (1L << spell)) :
235 (p_ptr->spell_learned1 & (1L << spell)))
238 return (!study_pray);
241 /* Okay to study, not to cast */
247 * @brief 魔法処理のメインルーチン
248 * @param realm 魔法領域のID
249 * @param spell 各領域の魔法ID
251 * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
253 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
257 case REALM_LIFE: return do_life_spell(spell, mode);
258 case REALM_SORCERY: return do_sorcery_spell(spell, mode);
259 case REALM_NATURE: return do_nature_spell(spell, mode);
260 case REALM_CHAOS: return do_chaos_spell(spell, mode);
261 case REALM_DEATH: return do_death_spell(spell, mode);
262 case REALM_TRUMP: return do_trump_spell(spell, mode);
263 case REALM_ARCANE: return do_arcane_spell(spell, mode);
264 case REALM_CRAFT: return do_craft_spell(spell, mode);
265 case REALM_DAEMON: return do_daemon_spell(spell, mode);
266 case REALM_CRUSADE: return do_crusade_spell(spell, mode);
267 case REALM_MUSIC: return do_music_spell(spell, mode);
268 case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
269 case REALM_HEX: return do_hex_spell(spell, mode);
277 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
278 * Allow user to choose a spell/prayer from the given book.
279 * @param sn 選択した魔法IDを返す参照ポインタ
280 * @param prompt 魔法を利用する際の動詞表記
281 * @param sval 魔道書のsval
282 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
283 * @param use_realm 魔法領域ID
286 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
287 * If the user hits escape, returns FALSE, and set '*sn' to -1
288 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
289 * The "prompt" should be "cast", "recite", or "study"
290 * The "known" should be TRUE for cast/pray, FALSE for study
293 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
296 SPELL_IDX spell = -1;
299 MANA_POINT need_mana;
300 SPELL_IDX spells[64];
301 bool flag, redraw, okay;
303 const magic_type *s_ptr;
310 int menu_line = (use_menu ? 1 : 0);
312 /* Get the spell, if available */
313 if (repeat_pull(&code))
315 *sn = (SPELL_IDX)code;
316 /* Verify the spell */
317 if (spell_okay(*sn, learned, FALSE, use_realm))
324 p = spell_category_name(mp_ptr->spell_book);
327 for (spell = 0; spell < 32; spell++)
329 /* Check for this spell */
330 if ((fake_spell_flags[sval] & (1L << spell)))
332 /* Collect this spell */
333 spells[num++] = spell;
337 /* Assume no usable spells */
340 /* Assume no spells available */
343 /* Check for "okay" spells */
344 for (i = 0; i < num; i++)
346 /* Look for "okay" spells */
347 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
350 /* No "okay" spells */
351 if (!okay) return (FALSE);
352 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
353 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
354 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
356 /* Assume cancelled */
359 /* Nothing chosen yet */
365 p_ptr->window |= (PW_SPELL);
368 /* Build a prompt (accept all spells) */
370 jverb(prompt, jverb_buf, JVERB_AND);
371 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
372 p, I2A(0), I2A(num - 1), p, jverb_buf);
374 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
375 p, I2A(0), I2A(num - 1), prompt, p);
378 choice = (always_show_list || use_menu) ? ESCAPE : 1;
381 if (choice == ESCAPE) choice = ' ';
382 else if (!get_com(out_val, &choice, TRUE))break;
384 if (use_menu && choice != ' ')
398 menu_line += (num - 1);
420 if (menu_line > num) menu_line -= num;
421 /* Display a list of spells */
422 print_spells(menu_line, spells, num, 1, 15, use_realm);
428 if ((choice == ' ') || (choice == '*') || (choice == '?'))
436 /* Display a list of spells */
437 print_spells(menu_line, spells, num, 1, 15, use_realm);
443 if (use_menu) continue;
456 ask = (isupper(choice));
459 if (ask) choice = (char)tolower(choice);
461 /* Extract request */
462 i = (islower(choice) ? A2I(choice) : -1);
465 /* Totally Illegal */
466 if ((i < 0) || (i >= num))
472 /* Save the spell index */
475 /* Require "okay" spells */
476 if (!spell_okay(spell, learned, FALSE, use_realm))
480 msg_format("その%sを%sことはできません。", p, prompt);
482 msg_format("You may not %s that %s.", prompt, p);
493 /* Access the spell */
494 if (!is_magic(use_realm))
496 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
500 s_ptr = &mp_ptr->info[use_realm - 1][spell];
503 /* Extract mana consumption rate */
504 if (use_realm == REALM_HISSATSU)
506 need_mana = s_ptr->smana;
510 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
515 jverb(prompt, jverb_buf, JVERB_AND);
517 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
518 do_spell(use_realm, spell, SPELL_NAME), need_mana,
519 spell_chance(spell, use_realm), jverb_buf);
521 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
522 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
523 spell_chance(spell, use_realm));
527 /* Belay that order */
528 if (!get_check(tmp_val)) continue;
535 if (redraw) screen_load();
537 p_ptr->window |= (PW_SPELL);
540 /* Abort if needed */
541 if (!flag) return FALSE;
543 /* Save the choice */
546 repeat_push((COMMAND_CODE)spell);
553 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
554 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
555 * @return 魔道書を一冊も持っていないならTRUEを返す
557 static void confirm_use_force(bool browse_only)
562 /* Get the item index */
563 if (repeat_pull(&code) && (code == INVEN_FORCE))
565 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
569 /* Show the prompt */
570 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
577 if (which == ESCAPE) break;
578 else if (which == 'w')
580 repeat_push(INVEN_FORCE);
585 /* Clear the prompt line */
590 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
596 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
597 * Peruse the spells/prayers in a book
601 * Note that *all* spells in the book are listed
603 * Note that browsing is allowed while confused or blind,
604 * and in the dark, primarily to allow browsing in stores.
607 void do_cmd_browse(void)
610 OBJECT_SUBTYPE_VALUE sval;
611 REALM_IDX use_realm = 0;
613 SPELL_IDX spell = -1;
616 SPELL_IDX spells[64];
623 /* Warriors are illiterate */
624 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
626 msg_print(_("本を読むことができない!", "You cannot read books!"));
630 if (p_ptr->special_defense & KATA_MUSOU)
632 set_action(ACTION_NONE);
635 if (p_ptr->pclass == CLASS_FORCETRAINER)
637 if (player_has_no_spellbooks())
639 confirm_use_force(TRUE);
644 /* Restrict choices to "useful" books */
645 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
646 else item_tester_hook = item_tester_learn_spell;
648 q = _("どの本を読みますか? ", "Browse which book? ");
649 s = _("読める本がない。", "You have no books that you can read.");
651 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
654 if (item == INVEN_FORCE) /* the_force */
656 do_cmd_mind_browse();
662 /* Access the item's sval */
665 use_realm = tval2realm(o_ptr->tval);
667 /* Track the object kind */
668 object_kind_track(o_ptr->k_idx);
672 for (spell = 0; spell < 32; spell++)
674 /* Check for this spell */
675 if ((fake_spell_flags[sval] & (1L << spell)))
677 /* Collect this spell */
678 spells[num++] = spell;
685 /* Keep browsing spells. Exit browsing on cancel. */
688 /* Ask for a spell, allow cancel */
689 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
691 /* If cancelled, leave immediately. */
692 if (spell == -1) break;
694 /* Display a list of spells */
695 print_spells(0, spells, num, 1, 15, use_realm);
697 /* Notify that there's nothing to see, and wait. */
698 if (use_realm == REALM_HISSATSU)
699 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
701 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
709 /* Clear lines, position cursor (really should use strlen here) */
710 Term_erase(14, 14, 255);
711 Term_erase(14, 13, 255);
712 Term_erase(14, 12, 255);
713 Term_erase(14, 11, 255);
715 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
717 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
719 prt(&temp[j], line, 15);
727 * @brief プレイヤーの第二魔法領域を変更する /
728 * @param next_realm 変更先の魔法領域ID
731 static void change_realm2(CHARACTER_IDX next_realm)
736 for (i = 0; i < 64; i++)
738 p_ptr->spell_order[j] = p_ptr->spell_order[i];
739 if (p_ptr->spell_order[i] < 32) j++;
742 p_ptr->spell_order[j] = 99;
744 for (i = 32; i < 64; i++)
746 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
748 p_ptr->spell_learned2 = 0L;
749 p_ptr->spell_worked2 = 0L;
750 p_ptr->spell_forgotten2 = 0L;
752 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
753 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
754 p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
755 p_ptr->realm2 = next_realm;
757 p_ptr->update |= (PU_REORDER);
758 p_ptr->update |= (PU_SPELLS);
761 /* Load an autopick preference file */
762 autopick_load_pref(FALSE);
767 * @brief 魔法を学習するコマンドのメインルーチン /
768 * Study a book to gain a new spell/prayer
771 void do_cmd_study(void)
775 OBJECT_SUBTYPE_VALUE sval;
777 bool learned = FALSE;
779 /* Spells of realm2 will have an increment of +32 */
780 SPELL_IDX spell = -1;
782 concptr p = spell_category_name(mp_ptr->spell_book);
790 msg_print(_("本を読むことができない!", "You cannot read books!"));
794 if (p_ptr->blind || no_lite())
796 msg_print(_("目が見えない!", "You cannot see!"));
800 if (cmd_limit_confused(p_ptr)) return;
802 if (!(p_ptr->new_spells))
804 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
808 if (p_ptr->special_defense & KATA_MUSOU)
810 set_action(ACTION_NONE);
814 if (p_ptr->new_spells < 10) {
815 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
818 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
821 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
822 (p_ptr->new_spells == 1 ? "" : "s"));
828 /* Restrict choices to "useful" books */
829 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
830 else item_tester_hook = item_tester_learn_spell;
832 q = _("どの本から学びますか? ", "Study which book? ");
833 s = _("読める本がない。", "You have no books that you can read.");
835 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
838 /* Access the item's sval */
841 if (o_ptr->tval == REALM2_BOOK) increment = 32;
842 else if (o_ptr->tval != REALM1_BOOK)
844 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
845 change_realm2(tval2realm(o_ptr->tval));
849 /* Track the object kind */
850 object_kind_track(o_ptr->k_idx);
853 /* Mage -- Learn a selected spell */
854 if (mp_ptr->spell_book != TV_LIFE_BOOK)
856 /* Ask for a spell, allow cancel */
857 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
860 /* Priest -- Learn a random prayer */
867 for (spell = 0; spell < 32; spell++)
869 /* Check spells in the book */
870 if ((fake_spell_flags[sval] & (1L << spell)))
872 /* Skip non "okay" prayers */
873 if (!spell_okay(spell, FALSE, TRUE,
874 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
876 /* Hack -- Prepare the randomizer */
879 /* Hack -- Apply the randomizer */
880 if (one_in_(k)) gift = spell;
888 /* Nothing to study */
891 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
897 if (increment) spell += increment;
899 /* Learn the spell */
902 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
903 else p_ptr->spell_learned1 |= (1L << spell);
907 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
908 else p_ptr->spell_learned2 |= (1L << (spell - 32));
913 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
914 int old_exp = p_ptr->spell_exp[spell];
915 int new_rank = EXP_LEVEL_UNSKILLED;
916 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
918 if (old_exp >= max_exp)
920 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
924 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
926 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
931 else if (old_exp >= SPELL_EXP_EXPERT)
933 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
934 new_rank = EXP_LEVEL_MASTER;
936 else if (old_exp >= SPELL_EXP_SKILLED)
938 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
939 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
940 new_rank = EXP_LEVEL_EXPERT;
942 else if (old_exp >= SPELL_EXP_BEGINNER)
944 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
945 new_rank = EXP_LEVEL_SKILLED;
949 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
950 new_rank = EXP_LEVEL_BEGINNER;
952 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
956 /* Find the next open entry in "p_ptr->spell_order[]" */
957 for (i = 0; i < 64; i++)
959 /* Stop at the first empty space */
960 if (p_ptr->spell_order[i] == 99) break;
963 /* Add the spell to the known list */
964 p_ptr->spell_order[i++] = spell;
966 /* Mention the result */
969 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
971 msg_format("%sを学んだ。",
972 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
976 msg_format("%sの%sを学んだ。",
977 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
980 msg_format("You have learned the %s of %s.",
981 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
985 take_turn(p_ptr, 100);
987 switch (mp_ptr->spell_book)
990 chg_virtue(V_FAITH, 1);
993 chg_virtue(V_UNLIFE, 1);
996 chg_virtue(V_NATURE, 1);
999 chg_virtue(V_KNOWLEDGE, 1);
1005 /* One less spell available */
1006 p_ptr->learned_spells++;
1009 p_ptr->update |= (PU_SPELLS);
1010 update_creature(p_ptr);
1012 /* Redraw object recall */
1013 p_ptr->window |= (PW_OBJECT);
1018 * @brief 魔法を詠唱するコマンドのメインルーチン /
1022 void do_cmd_cast(void)
1025 OBJECT_SUBTYPE_VALUE sval;
1030 REALM_IDX use_realm;
1031 MANA_POINT need_mana;
1035 const magic_type *s_ptr;
1038 bool over_exerted = FALSE;
1040 /* Require spell ability */
1041 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1043 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1048 if (p_ptr->blind || no_lite())
1050 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1053 msg_print(_("目が見えない!", "You cannot see!"));
1059 if (cmd_limit_confused(p_ptr)) return;
1062 if (p_ptr->realm1 == REALM_HEX)
1064 if (hex_spell_fully())
1067 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1069 if (p_ptr->lev >= 35) flag = stop_hex_spell();
1074 if (p_ptr->pclass == CLASS_FORCETRAINER)
1076 if (player_has_no_spellbooks())
1078 confirm_use_force(FALSE);
1083 prayer = spell_category_name(mp_ptr->spell_book);
1085 /* Restrict choices to spell books */
1086 item_tester_tval = mp_ptr->spell_book;
1088 q = _("どの呪文書を使いますか? ", "Use which book? ");
1089 s = _("呪文書がない!", "You have no spell books!");
1091 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
1094 if (item == INVEN_FORCE) /* the_force */
1102 /* Access the item's sval */
1105 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1107 /* Track the object kind */
1108 object_kind_track(o_ptr->k_idx);
1111 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1112 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1113 else if (increment) realm = p_ptr->realm2;
1114 else realm = p_ptr->realm1;
1116 /* Ask for a spell */
1118 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1121 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1125 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1129 msg_format("You don't know any %ss in that book.", prayer);
1135 use_realm = tval2realm(o_ptr->tval);
1138 if (use_realm == REALM_HEX)
1140 if (hex_spelling(spell))
1142 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1147 if (!is_magic(use_realm))
1149 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1153 s_ptr = &mp_ptr->info[realm - 1][spell];
1156 /* Extract mana consumption rate */
1157 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1159 /* Verify "dangerous" spells */
1160 if (need_mana > p_ptr->csp)
1162 if (flush_failure) flush();
1166 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1167 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1169 msg_format("You do not have enough mana to %s this %s.",
1170 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1175 if (!over_exert) return;
1178 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1181 /* Spell failure chance */
1182 chance = spell_chance(spell, use_realm);
1184 /* Sufficient mana */
1185 if (need_mana <= p_ptr->csp)
1188 p_ptr->csp -= need_mana;
1190 else over_exerted = TRUE;
1191 p_ptr->redraw |= (PR_MANA);
1194 if (randint0(100) < chance)
1196 if (flush_failure) flush();
1198 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1204 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1207 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1210 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1213 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1216 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1219 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1222 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1226 /* Failure casting may activate some side effect */
1227 do_spell(realm, spell, SPELL_FAIL);
1230 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1232 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1235 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1237 if ((sval == 3) && one_in_(2))
1239 sanity_blast(0, TRUE);
1243 msg_print(_("痛い!", "It hurts!"));
1244 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1246 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1247 lose_exp(spell * 250);
1250 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1252 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1253 aggravate_monsters(0);
1255 if (randint1(100) >= chance)
1256 chg_virtue(V_CHANCE, -1);
1262 /* Canceled spells cost neither a current_world_ptr->game_turn nor mana */
1263 if (!do_spell(realm, spell, SPELL_CAST)) return;
1265 if (randint1(100) < chance)
1266 chg_virtue(V_CHANCE, 1);
1268 /* A spell was cast */
1270 (p_ptr->spell_worked2 & (1L << spell)) :
1271 (p_ptr->spell_worked1 & (1L << spell)))
1272 && (p_ptr->pclass != CLASS_SORCERER)
1273 && (p_ptr->pclass != CLASS_RED_MAGE))
1275 int e = s_ptr->sexp;
1277 /* The spell worked */
1278 if (realm == p_ptr->realm1)
1280 p_ptr->spell_worked1 |= (1L << spell);
1284 p_ptr->spell_worked2 |= (1L << spell);
1287 /* Gain experience */
1288 gain_exp(e * s_ptr->slevel);
1290 /* Redraw object recall */
1291 p_ptr->window |= (PW_OBJECT);
1296 chg_virtue(V_TEMPERANCE, 1);
1297 chg_virtue(V_COMPASSION, 1);
1298 chg_virtue(V_VITALITY, 1);
1299 chg_virtue(V_DILIGENCE, 1);
1302 chg_virtue(V_UNLIFE, 1);
1303 chg_virtue(V_JUSTICE, -1);
1304 chg_virtue(V_FAITH, -1);
1305 chg_virtue(V_VITALITY, -1);
1308 chg_virtue(V_JUSTICE, -1);
1309 chg_virtue(V_FAITH, -1);
1310 chg_virtue(V_HONOUR, -1);
1311 chg_virtue(V_TEMPERANCE, -1);
1314 chg_virtue(V_FAITH, 1);
1315 chg_virtue(V_JUSTICE, 1);
1316 chg_virtue(V_SACRIFICE, 1);
1317 chg_virtue(V_HONOUR, 1);
1320 chg_virtue(V_NATURE, 1);
1321 chg_virtue(V_HARMONY, 1);
1324 chg_virtue(V_JUSTICE, -1);
1325 chg_virtue(V_FAITH, -1);
1326 chg_virtue(V_HONOUR, -1);
1327 chg_virtue(V_COMPASSION, -1);
1330 chg_virtue(V_KNOWLEDGE, 1);
1337 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1338 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1339 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1340 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1343 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 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_VITALITY, -1);
1349 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -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_HONOUR, -1);
1352 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1355 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1356 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1357 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1358 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1361 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1362 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1365 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1366 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1367 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1368 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1371 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1373 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0) + spell];
1376 if (cur_exp < SPELL_EXP_BEGINNER)
1378 else if (cur_exp < SPELL_EXP_SKILLED)
1380 if ((current_floor_ptr->dun_level > 4) && ((current_floor_ptr->dun_level + 10) > p_ptr->lev))
1383 else if (cur_exp < SPELL_EXP_EXPERT)
1385 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && ((current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1388 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1390 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && (current_floor_ptr->dun_level > s_ptr->slevel))
1393 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1397 take_turn(p_ptr, 100);
1400 /* Over-exert the player */
1403 int oops = need_mana;
1407 p_ptr->csp_frac = 0;
1409 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1411 /* Hack -- Bypass free action */
1412 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1417 chg_virtue(V_VITALITY, -10);
1420 chg_virtue(V_UNLIFE, -10);
1423 chg_virtue(V_JUSTICE, 10);
1426 chg_virtue(V_NATURE, -10);
1429 chg_virtue(V_JUSTICE, -10);
1432 chg_virtue(V_COMPASSION, 10);
1435 chg_virtue(V_KNOWLEDGE, -10);
1439 /* Damage CON (possibly permanently) */
1440 if (randint0(100) < 50)
1442 bool perm = (randint0(100) < 25);
1444 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1446 /* Reduce constitution */
1447 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1451 p_ptr->window |= (PW_PLAYER);
1452 p_ptr->window |= (PW_SPELL);