3 @brief 魔法のインターフェイスと発動 / Purpose: Do everything for each spell
6 2013 Deskull rearranged comment for Doxygen.
15 #include "spells-summon.h"
16 #include "realm-arcane.h"
17 #include "realm-chaos.h"
18 #include "realm-craft.h"
19 #include "realm-crusade.h"
20 #include "realm-daemon.h"
21 #include "realm-death.h"
22 #include "realm-hex.h"
23 #include "realm-hissatsu.h"
24 #include "realm-life.h"
25 #include "realm-nature.h"
26 #include "realm-song.h"
27 #include "realm-sorcery.h"
28 #include "realm-trump.h"
31 #include "player-status.h"
32 #include "player-effects.h"
33 #include "player-skill.h"
34 #include "player-class.h"
35 #include "object-hook.h"
36 #include "cmd-basic.h"
37 #include "view-mainwindow.h"
43 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
48 * @return フォーマットに従い整形された文字列
50 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
54 return format("%s%d", str, base);
58 return format("%s%dd%d", str, dice, sides);
60 /* Dice plus base value */
62 return format("%s%dd%d%+d", str, dice, sides, base);
67 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
71 * @return フォーマットに従い整形された文字列
73 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
75 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
79 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
82 * @return フォーマットに従い整形された文字列
84 concptr info_duration(int base, DICE_SID sides)
86 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
90 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
92 * @return フォーマットに従い整形された文字列
94 concptr info_range(POSITION range)
96 return format(_("範囲:%d", "range %d"), range);
100 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
104 * @return フォーマットに従い整形された文字列
106 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
108 return info_string_dice(_("回復:", "heal "), dice, sides, base);
112 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
115 * @return フォーマットに従い整形された文字列
117 concptr info_delay(int base, DICE_SID sides)
119 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
124 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
126 * @return フォーマットに従い整形された文字列
128 concptr info_multi_damage(HIT_POINT dam)
130 return format(_("損傷:各%d", "dam %d each"), dam);
135 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
138 * @return フォーマットに従い整形された文字列
140 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
142 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
146 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
148 * @return フォーマットに従い整形された文字列
150 concptr info_power(int power)
152 return format(_("効力:%d", "power %d"), power);
157 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
160 * @return フォーマットに従い整形された文字列
163 * Generate power info string such as "power 1d100"
165 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
167 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
172 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
174 * @return フォーマットに従い整形された文字列
176 concptr info_radius(POSITION rad)
178 return format(_("半径:%d", "rad %d"), rad);
183 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
185 * @return フォーマットに従い整形された文字列
187 concptr info_weight(WEIGHT weight)
190 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
192 return format("max wgt %d", weight/10);
197 * @brief 魔法が利用可能かどうかを返す /
198 * Determine if a spell is "okay" for the player to cast or study
199 * The spell must be legible, not forgotten, and also, to cast,
200 * it must be known, and to study, it must not be known.
202 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
203 * @param study_pray 祈りの学習判定目的ならばTRUE
204 * @param use_realm 魔法領域ID
207 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
209 const magic_type *s_ptr;
211 /* Access the spell */
212 if (!is_magic(use_realm))
214 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
218 s_ptr = &mp_ptr->info[use_realm - 1][spell];
221 /* Spell is illegal */
222 if (s_ptr->slevel > p_ptr->lev) return (FALSE);
224 /* Spell is forgotten */
225 if ((use_realm == p_ptr->realm2) ?
226 (p_ptr->spell_forgotten2 & (1L << spell)) :
227 (p_ptr->spell_forgotten1 & (1L << spell)))
233 if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
234 if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
236 /* Spell is learned */
237 if ((use_realm == p_ptr->realm2) ?
238 (p_ptr->spell_learned2 & (1L << spell)) :
239 (p_ptr->spell_learned1 & (1L << spell)))
242 return (!study_pray);
245 /* Okay to study, not to cast */
251 * @brief 魔法処理のメインルーチン
252 * @param realm 魔法領域のID
253 * @param spell 各領域の魔法ID
255 * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
257 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
261 case REALM_LIFE: return do_life_spell(spell, mode);
262 case REALM_SORCERY: return do_sorcery_spell(spell, mode);
263 case REALM_NATURE: return do_nature_spell(spell, mode);
264 case REALM_CHAOS: return do_chaos_spell(spell, mode);
265 case REALM_DEATH: return do_death_spell(spell, mode);
266 case REALM_TRUMP: return do_trump_spell(spell, mode);
267 case REALM_ARCANE: return do_arcane_spell(spell, mode);
268 case REALM_CRAFT: return do_craft_spell(spell, mode);
269 case REALM_DAEMON: return do_daemon_spell(spell, mode);
270 case REALM_CRUSADE: return do_crusade_spell(spell, mode);
271 case REALM_MUSIC: return do_music_spell(spell, mode);
272 case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
273 case REALM_HEX: return do_hex_spell(spell, mode);
281 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
282 * Allow user to choose a spell/prayer from the given book.
283 * @param sn 選択した魔法IDを返す参照ポインタ
284 * @param prompt 魔法を利用する際の動詞表記
285 * @param sval 魔道書のsval
286 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
287 * @param use_realm 魔法領域ID
290 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
291 * If the user hits escape, returns FALSE, and set '*sn' to -1
292 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
293 * The "prompt" should be "cast", "recite", or "study"
294 * The "known" should be TRUE for cast/pray, FALSE for study
297 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
300 SPELL_IDX spell = -1;
303 MANA_POINT need_mana;
304 SPELL_IDX spells[64];
305 bool flag, redraw, okay;
307 const magic_type *s_ptr;
314 int menu_line = (use_menu ? 1 : 0);
316 /* Get the spell, if available */
317 if (repeat_pull(&code))
319 *sn = (SPELL_IDX)code;
320 /* Verify the spell */
321 if (spell_okay(*sn, learned, FALSE, use_realm))
328 p = spell_category_name(mp_ptr->spell_book);
331 for (spell = 0; spell < 32; spell++)
333 /* Check for this spell */
334 if ((fake_spell_flags[sval] & (1L << spell)))
336 /* Collect this spell */
337 spells[num++] = spell;
341 /* Assume no usable spells */
344 /* Assume no spells available */
347 /* Check for "okay" spells */
348 for (i = 0; i < num; i++)
350 /* Look for "okay" spells */
351 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
354 /* No "okay" spells */
355 if (!okay) return (FALSE);
356 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
357 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
358 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
360 /* Assume cancelled */
363 /* Nothing chosen yet */
369 p_ptr->window |= (PW_SPELL);
372 /* Build a prompt (accept all spells) */
374 jverb(prompt, jverb_buf, JVERB_AND);
375 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
376 p, I2A(0), I2A(num - 1), p, jverb_buf);
378 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
379 p, I2A(0), I2A(num - 1), prompt, p);
382 choice = (always_show_list || use_menu) ? ESCAPE : 1;
385 if (choice == ESCAPE) choice = ' ';
386 else if (!get_com(out_val, &choice, TRUE))break;
388 if (use_menu && choice != ' ')
402 menu_line += (num - 1);
424 if (menu_line > num) menu_line -= num;
425 /* Display a list of spells */
426 print_spells(menu_line, spells, num, 1, 15, use_realm);
432 if ((choice == ' ') || (choice == '*') || (choice == '?'))
440 /* Display a list of spells */
441 print_spells(menu_line, spells, num, 1, 15, use_realm);
447 if (use_menu) continue;
460 ask = (isupper(choice));
463 if (ask) choice = (char)tolower(choice);
465 /* Extract request */
466 i = (islower(choice) ? A2I(choice) : -1);
469 /* Totally Illegal */
470 if ((i < 0) || (i >= num))
476 /* Save the spell index */
479 /* Require "okay" spells */
480 if (!spell_okay(spell, learned, FALSE, use_realm))
484 msg_format("その%sを%sことはできません。", p, prompt);
486 msg_format("You may not %s that %s.", prompt, p);
497 /* Access the spell */
498 if (!is_magic(use_realm))
500 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
504 s_ptr = &mp_ptr->info[use_realm - 1][spell];
507 /* Extract mana consumption rate */
508 if (use_realm == REALM_HISSATSU)
510 need_mana = s_ptr->smana;
514 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
519 jverb(prompt, jverb_buf, JVERB_AND);
521 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
522 do_spell(use_realm, spell, SPELL_NAME), need_mana,
523 spell_chance(spell, use_realm), jverb_buf);
525 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
526 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
527 spell_chance(spell, use_realm));
531 /* Belay that order */
532 if (!get_check(tmp_val)) continue;
539 if (redraw) screen_load();
541 p_ptr->window |= (PW_SPELL);
544 /* Abort if needed */
545 if (!flag) return FALSE;
547 /* Save the choice */
550 repeat_push((COMMAND_CODE)spell);
557 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
558 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
559 * @return 魔道書を一冊も持っていないならTRUEを返す
561 static void confirm_use_force(bool browse_only)
566 /* Get the item index */
567 if (repeat_pull(&code) && (code == INVEN_FORCE))
569 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
573 /* Show the prompt */
574 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
581 if (which == ESCAPE) break;
582 else if (which == 'w')
584 repeat_push(INVEN_FORCE);
589 /* Clear the prompt line */
594 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
600 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
601 * Peruse the spells/prayers in a book
605 * Note that *all* spells in the book are listed
607 * Note that browsing is allowed while confused or blind,
608 * and in the dark, primarily to allow browsing in stores.
611 void do_cmd_browse(void)
614 OBJECT_SUBTYPE_VALUE sval;
615 REALM_IDX use_realm = 0;
617 SPELL_IDX spell = -1;
620 SPELL_IDX spells[64];
627 /* Warriors are illiterate */
628 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
630 msg_print(_("本を読むことができない!", "You cannot read books!"));
634 if (p_ptr->special_defense & KATA_MUSOU)
636 set_action(ACTION_NONE);
639 if (p_ptr->pclass == CLASS_FORCETRAINER)
641 if (player_has_no_spellbooks())
643 confirm_use_force(TRUE);
648 /* Restrict choices to "useful" books */
649 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
650 else item_tester_hook = item_tester_learn_spell;
652 q = _("どの本を読みますか? ", "Browse which book? ");
653 s = _("読める本がない。", "You have no books that you can read.");
655 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
658 if (item == INVEN_FORCE) /* the_force */
660 do_cmd_mind_browse();
666 /* Access the item's sval */
669 use_realm = tval2realm(o_ptr->tval);
671 /* Track the object kind */
672 object_kind_track(o_ptr->k_idx);
676 for (spell = 0; spell < 32; spell++)
678 /* Check for this spell */
679 if ((fake_spell_flags[sval] & (1L << spell)))
681 /* Collect this spell */
682 spells[num++] = spell;
689 /* Keep browsing spells. Exit browsing on cancel. */
692 /* Ask for a spell, allow cancel */
693 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
695 /* If cancelled, leave immediately. */
696 if (spell == -1) break;
698 /* Display a list of spells */
699 print_spells(0, spells, num, 1, 15, use_realm);
701 /* Notify that there's nothing to see, and wait. */
702 if (use_realm == REALM_HISSATSU)
703 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
705 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
713 /* Clear lines, position cursor (really should use strlen here) */
714 Term_erase(14, 14, 255);
715 Term_erase(14, 13, 255);
716 Term_erase(14, 12, 255);
717 Term_erase(14, 11, 255);
719 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
721 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
723 prt(&temp[j], line, 15);
731 * @brief プレイヤーの第二魔法領域を変更する /
732 * @param next_realm 変更先の魔法領域ID
735 static void change_realm2(CHARACTER_IDX next_realm)
740 for (i = 0; i < 64; i++)
742 p_ptr->spell_order[j] = p_ptr->spell_order[i];
743 if (p_ptr->spell_order[i] < 32) j++;
746 p_ptr->spell_order[j] = 99;
748 for (i = 32; i < 64; i++)
750 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
752 p_ptr->spell_learned2 = 0L;
753 p_ptr->spell_worked2 = 0L;
754 p_ptr->spell_forgotten2 = 0L;
756 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
757 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
758 p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
759 p_ptr->realm2 = next_realm;
761 p_ptr->update |= (PU_REORDER);
762 p_ptr->update |= (PU_SPELLS);
765 /* Load an autopick preference file */
766 autopick_load_pref(FALSE);
771 * @brief 魔法を学習するコマンドのメインルーチン /
772 * Study a book to gain a new spell/prayer
775 void do_cmd_study(void)
779 OBJECT_SUBTYPE_VALUE sval;
781 bool learned = FALSE;
783 /* Spells of realm2 will have an increment of +32 */
784 SPELL_IDX spell = -1;
786 concptr p = spell_category_name(mp_ptr->spell_book);
794 msg_print(_("本を読むことができない!", "You cannot read books!"));
798 if (p_ptr->blind || no_lite())
800 msg_print(_("目が見えない!", "You cannot see!"));
804 if (cmd_limit_confused(p_ptr)) return;
806 if (!(p_ptr->new_spells))
808 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
812 if (p_ptr->special_defense & KATA_MUSOU)
814 set_action(ACTION_NONE);
818 if (p_ptr->new_spells < 10) {
819 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
822 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
825 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
826 (p_ptr->new_spells == 1 ? "" : "s"));
832 /* Restrict choices to "useful" books */
833 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
834 else item_tester_hook = item_tester_learn_spell;
836 q = _("どの本から学びますか? ", "Study which book? ");
837 s = _("読める本がない。", "You have no books that you can read.");
839 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
842 /* Access the item's sval */
845 if (o_ptr->tval == REALM2_BOOK) increment = 32;
846 else if (o_ptr->tval != REALM1_BOOK)
848 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
849 change_realm2(tval2realm(o_ptr->tval));
853 /* Track the object kind */
854 object_kind_track(o_ptr->k_idx);
857 /* Mage -- Learn a selected spell */
858 if (mp_ptr->spell_book != TV_LIFE_BOOK)
860 /* Ask for a spell, allow cancel */
861 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
864 /* Priest -- Learn a random prayer */
871 for (spell = 0; spell < 32; spell++)
873 /* Check spells in the book */
874 if ((fake_spell_flags[sval] & (1L << spell)))
876 /* Skip non "okay" prayers */
877 if (!spell_okay(spell, FALSE, TRUE,
878 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
880 /* Hack -- Prepare the randomizer */
883 /* Hack -- Apply the randomizer */
884 if (one_in_(k)) gift = spell;
892 /* Nothing to study */
895 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
901 if (increment) spell += increment;
903 /* Learn the spell */
906 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
907 else p_ptr->spell_learned1 |= (1L << spell);
911 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
912 else p_ptr->spell_learned2 |= (1L << (spell - 32));
917 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
918 int old_exp = p_ptr->spell_exp[spell];
919 int new_rank = EXP_LEVEL_UNSKILLED;
920 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
922 if (old_exp >= max_exp)
924 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
928 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
930 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
935 else if (old_exp >= SPELL_EXP_EXPERT)
937 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
938 new_rank = EXP_LEVEL_MASTER;
940 else if (old_exp >= SPELL_EXP_SKILLED)
942 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
943 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
944 new_rank = EXP_LEVEL_EXPERT;
946 else if (old_exp >= SPELL_EXP_BEGINNER)
948 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
949 new_rank = EXP_LEVEL_SKILLED;
953 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
954 new_rank = EXP_LEVEL_BEGINNER;
956 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
960 /* Find the next open entry in "p_ptr->spell_order[]" */
961 for (i = 0; i < 64; i++)
963 /* Stop at the first empty space */
964 if (p_ptr->spell_order[i] == 99) break;
967 /* Add the spell to the known list */
968 p_ptr->spell_order[i++] = spell;
970 /* Mention the result */
973 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
975 msg_format("%sを学んだ。",
976 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
980 msg_format("%sの%sを学んだ。",
981 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
984 msg_format("You have learned the %s of %s.",
985 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
989 take_turn(p_ptr, 100);
991 switch (mp_ptr->spell_book)
994 chg_virtue(V_FAITH, 1);
997 chg_virtue(V_UNLIFE, 1);
1000 chg_virtue(V_NATURE, 1);
1003 chg_virtue(V_KNOWLEDGE, 1);
1009 /* One less spell available */
1010 p_ptr->learned_spells++;
1013 p_ptr->update |= (PU_SPELLS);
1014 update_creature(p_ptr);
1016 /* Redraw object recall */
1017 p_ptr->window |= (PW_OBJECT);
1022 * @brief 魔法を詠唱するコマンドのメインルーチン /
1026 void do_cmd_cast(void)
1029 OBJECT_SUBTYPE_VALUE sval;
1034 REALM_IDX use_realm;
1035 MANA_POINT need_mana;
1039 const magic_type *s_ptr;
1042 bool over_exerted = FALSE;
1044 /* Require spell ability */
1045 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1047 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1052 if (p_ptr->blind || no_lite())
1054 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1057 msg_print(_("目が見えない!", "You cannot see!"));
1063 if (cmd_limit_confused(p_ptr)) return;
1066 if (p_ptr->realm1 == REALM_HEX)
1068 if (hex_spell_fully())
1071 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1073 if (p_ptr->lev >= 35) flag = stop_hex_spell();
1078 if (p_ptr->pclass == CLASS_FORCETRAINER)
1080 if (player_has_no_spellbooks())
1082 confirm_use_force(FALSE);
1087 prayer = spell_category_name(mp_ptr->spell_book);
1089 /* Restrict choices to spell books */
1090 item_tester_tval = mp_ptr->spell_book;
1092 q = _("どの呪文書を使いますか? ", "Use which book? ");
1093 s = _("呪文書がない!", "You have no spell books!");
1095 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
1098 if (item == INVEN_FORCE) /* the_force */
1106 /* Access the item's sval */
1109 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1111 /* Track the object kind */
1112 object_kind_track(o_ptr->k_idx);
1115 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1116 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1117 else if (increment) realm = p_ptr->realm2;
1118 else realm = p_ptr->realm1;
1120 /* Ask for a spell */
1122 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1125 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1129 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1133 msg_format("You don't know any %ss in that book.", prayer);
1139 use_realm = tval2realm(o_ptr->tval);
1142 if (use_realm == REALM_HEX)
1144 if (hex_spelling(spell))
1146 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1151 if (!is_magic(use_realm))
1153 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1157 s_ptr = &mp_ptr->info[realm - 1][spell];
1160 /* Extract mana consumption rate */
1161 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1163 /* Verify "dangerous" spells */
1164 if (need_mana > p_ptr->csp)
1166 if (flush_failure) flush();
1170 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1171 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1173 msg_format("You do not have enough mana to %s this %s.",
1174 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1179 if (!over_exert) return;
1182 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1185 /* Spell failure chance */
1186 chance = spell_chance(spell, use_realm);
1188 /* Sufficient mana */
1189 if (need_mana <= p_ptr->csp)
1192 p_ptr->csp -= need_mana;
1194 else over_exerted = TRUE;
1195 p_ptr->redraw |= (PR_MANA);
1198 if (randint0(100) < chance)
1200 if (flush_failure) flush();
1202 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1208 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1211 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1214 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1217 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1220 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1223 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1226 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1230 /* Failure casting may activate some side effect */
1231 do_spell(realm, spell, SPELL_FAIL);
1234 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1236 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1239 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1241 if ((sval == 3) && one_in_(2))
1243 sanity_blast(0, TRUE);
1247 msg_print(_("痛い!", "It hurts!"));
1248 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1250 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1251 lose_exp(spell * 250);
1254 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1256 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1257 aggravate_monsters(0);
1259 if (randint1(100) >= chance)
1260 chg_virtue(V_CHANCE, -1);
1266 /* Canceled spells cost neither a current_world_ptr->game_turn nor mana */
1267 if (!do_spell(realm, spell, SPELL_CAST)) return;
1269 if (randint1(100) < chance)
1270 chg_virtue(V_CHANCE, 1);
1272 /* A spell was cast */
1274 (p_ptr->spell_worked2 & (1L << spell)) :
1275 (p_ptr->spell_worked1 & (1L << spell)))
1276 && (p_ptr->pclass != CLASS_SORCERER)
1277 && (p_ptr->pclass != CLASS_RED_MAGE))
1279 int e = s_ptr->sexp;
1281 /* The spell worked */
1282 if (realm == p_ptr->realm1)
1284 p_ptr->spell_worked1 |= (1L << spell);
1288 p_ptr->spell_worked2 |= (1L << spell);
1291 /* Gain experience */
1292 gain_exp(e * s_ptr->slevel);
1294 /* Redraw object recall */
1295 p_ptr->window |= (PW_OBJECT);
1300 chg_virtue(V_TEMPERANCE, 1);
1301 chg_virtue(V_COMPASSION, 1);
1302 chg_virtue(V_VITALITY, 1);
1303 chg_virtue(V_DILIGENCE, 1);
1306 chg_virtue(V_UNLIFE, 1);
1307 chg_virtue(V_JUSTICE, -1);
1308 chg_virtue(V_FAITH, -1);
1309 chg_virtue(V_VITALITY, -1);
1312 chg_virtue(V_JUSTICE, -1);
1313 chg_virtue(V_FAITH, -1);
1314 chg_virtue(V_HONOUR, -1);
1315 chg_virtue(V_TEMPERANCE, -1);
1318 chg_virtue(V_FAITH, 1);
1319 chg_virtue(V_JUSTICE, 1);
1320 chg_virtue(V_SACRIFICE, 1);
1321 chg_virtue(V_HONOUR, 1);
1324 chg_virtue(V_NATURE, 1);
1325 chg_virtue(V_HARMONY, 1);
1328 chg_virtue(V_JUSTICE, -1);
1329 chg_virtue(V_FAITH, -1);
1330 chg_virtue(V_HONOUR, -1);
1331 chg_virtue(V_COMPASSION, -1);
1334 chg_virtue(V_KNOWLEDGE, 1);
1341 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1342 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1343 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_DILIGENCE, 1);
1347 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1348 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1349 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1350 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -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_FAITH, -1);
1355 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_TEMPERANCE, -1);
1359 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 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_SACRIFICE, 1);
1362 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_NATURE, 1);
1366 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1369 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1370 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1371 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1372 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1375 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1377 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0) + spell];
1380 if (cur_exp < SPELL_EXP_BEGINNER)
1382 else if (cur_exp < SPELL_EXP_SKILLED)
1384 if ((current_floor_ptr->dun_level > 4) && ((current_floor_ptr->dun_level + 10) > p_ptr->lev))
1387 else if (cur_exp < SPELL_EXP_EXPERT)
1389 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && ((current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1392 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1394 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && (current_floor_ptr->dun_level > s_ptr->slevel))
1397 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1401 take_turn(p_ptr, 100);
1404 /* Over-exert the player */
1407 int oops = need_mana;
1411 p_ptr->csp_frac = 0;
1413 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1415 /* Hack -- Bypass free action */
1416 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1421 chg_virtue(V_VITALITY, -10);
1424 chg_virtue(V_UNLIFE, -10);
1427 chg_virtue(V_JUSTICE, 10);
1430 chg_virtue(V_NATURE, -10);
1433 chg_virtue(V_JUSTICE, -10);
1436 chg_virtue(V_COMPASSION, 10);
1439 chg_virtue(V_KNOWLEDGE, -10);
1443 /* Damage CON (possibly permanently) */
1444 if (randint0(100) < 50)
1446 bool perm = (randint0(100) < 25);
1448 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1450 /* Reduce constitution */
1451 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1455 p_ptr->window |= (PW_PLAYER);
1456 p_ptr->window |= (PW_SPELL);