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 "player-class.h"
34 #include "object-hook.h"
35 #include "cmd-basic.h"
36 #include "view-mainwindow.h"
41 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
46 * @return フォーマットに従い整形された文字列
48 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
52 return format("%s%d", str, base);
56 return format("%s%dd%d", str, dice, sides);
58 /* Dice plus base value */
60 return format("%s%dd%d%+d", str, dice, sides, base);
65 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
69 * @return フォーマットに従い整形された文字列
71 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
73 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
77 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
80 * @return フォーマットに従い整形された文字列
82 concptr info_duration(int base, DICE_SID sides)
84 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
88 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
90 * @return フォーマットに従い整形された文字列
92 concptr info_range(POSITION range)
94 return format(_("範囲:%d", "range %d"), range);
98 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
102 * @return フォーマットに従い整形された文字列
104 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
106 return info_string_dice(_("回復:", "heal "), dice, sides, base);
110 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
113 * @return フォーマットに従い整形された文字列
115 concptr info_delay(int base, DICE_SID sides)
117 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
122 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
124 * @return フォーマットに従い整形された文字列
126 concptr info_multi_damage(HIT_POINT dam)
128 return format(_("損傷:各%d", "dam %d each"), dam);
133 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
136 * @return フォーマットに従い整形された文字列
138 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
140 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
144 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
146 * @return フォーマットに従い整形された文字列
148 concptr info_power(int power)
150 return format(_("効力:%d", "power %d"), power);
155 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
158 * @return フォーマットに従い整形された文字列
161 * Generate power info string such as "power 1d100"
163 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
165 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
170 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
172 * @return フォーマットに従い整形された文字列
174 concptr info_radius(POSITION rad)
176 return format(_("半径:%d", "rad %d"), rad);
181 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
183 * @return フォーマットに従い整形された文字列
185 concptr info_weight(WEIGHT weight)
188 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
190 return format("max wgt %d", weight/10);
195 * @brief 魔法が利用可能かどうかを返す /
196 * Determine if a spell is "okay" for the player to cast or study
197 * The spell must be legible, not forgotten, and also, to cast,
198 * it must be known, and to study, it must not be known.
200 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
201 * @param study_pray 祈りの学習判定目的ならばTRUE
202 * @param use_realm 魔法領域ID
205 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
207 const magic_type *s_ptr;
209 /* Access the spell */
210 if (!is_magic(use_realm))
212 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
216 s_ptr = &mp_ptr->info[use_realm - 1][spell];
219 /* Spell is illegal */
220 if (s_ptr->slevel > p_ptr->lev) return (FALSE);
222 /* Spell is forgotten */
223 if ((use_realm == p_ptr->realm2) ?
224 (p_ptr->spell_forgotten2 & (1L << spell)) :
225 (p_ptr->spell_forgotten1 & (1L << spell)))
231 if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
232 if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
234 /* Spell is learned */
235 if ((use_realm == p_ptr->realm2) ?
236 (p_ptr->spell_learned2 & (1L << spell)) :
237 (p_ptr->spell_learned1 & (1L << spell)))
240 return (!study_pray);
243 /* Okay to study, not to cast */
249 * @brief 魔法処理のメインルーチン
250 * @param realm 魔法領域のID
251 * @param spell 各領域の魔法ID
253 * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
255 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
259 case REALM_LIFE: return do_life_spell(spell, mode);
260 case REALM_SORCERY: return do_sorcery_spell(spell, mode);
261 case REALM_NATURE: return do_nature_spell(spell, mode);
262 case REALM_CHAOS: return do_chaos_spell(spell, mode);
263 case REALM_DEATH: return do_death_spell(spell, mode);
264 case REALM_TRUMP: return do_trump_spell(spell, mode);
265 case REALM_ARCANE: return do_arcane_spell(spell, mode);
266 case REALM_CRAFT: return do_craft_spell(spell, mode);
267 case REALM_DAEMON: return do_daemon_spell(spell, mode);
268 case REALM_CRUSADE: return do_crusade_spell(spell, mode);
269 case REALM_MUSIC: return do_music_spell(spell, mode);
270 case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
271 case REALM_HEX: return do_hex_spell(spell, mode);
279 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
280 * Allow user to choose a spell/prayer from the given book.
281 * @param sn 選択した魔法IDを返す参照ポインタ
282 * @param prompt 魔法を利用する際の動詞表記
283 * @param sval 魔道書のsval
284 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
285 * @param use_realm 魔法領域ID
288 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
289 * If the user hits escape, returns FALSE, and set '*sn' to -1
290 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
291 * The "prompt" should be "cast", "recite", or "study"
292 * The "known" should be TRUE for cast/pray, FALSE for study
295 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
298 SPELL_IDX spell = -1;
301 MANA_POINT need_mana;
302 SPELL_IDX spells[64];
303 bool flag, redraw, okay;
305 const magic_type *s_ptr;
312 int menu_line = (use_menu ? 1 : 0);
314 /* Get the spell, if available */
315 if (repeat_pull(&code))
317 *sn = (SPELL_IDX)code;
318 /* Verify the spell */
319 if (spell_okay(*sn, learned, FALSE, use_realm))
326 p = spell_category_name(mp_ptr->spell_book);
329 for (spell = 0; spell < 32; spell++)
331 /* Check for this spell */
332 if ((fake_spell_flags[sval] & (1L << spell)))
334 /* Collect this spell */
335 spells[num++] = spell;
339 /* Assume no usable spells */
342 /* Assume no spells available */
345 /* Check for "okay" spells */
346 for (i = 0; i < num; i++)
348 /* Look for "okay" spells */
349 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
352 /* No "okay" spells */
353 if (!okay) return (FALSE);
354 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
355 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
356 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
358 /* Assume cancelled */
361 /* Nothing chosen yet */
367 p_ptr->window |= (PW_SPELL);
370 /* Build a prompt (accept all spells) */
372 jverb(prompt, jverb_buf, JVERB_AND);
373 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
374 p, I2A(0), I2A(num - 1), p, jverb_buf);
376 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
377 p, I2A(0), I2A(num - 1), prompt, p);
380 choice = (always_show_list || use_menu) ? ESCAPE : 1;
383 if (choice == ESCAPE) choice = ' ';
384 else if (!get_com(out_val, &choice, TRUE))break;
386 if (use_menu && choice != ' ')
400 menu_line += (num - 1);
422 if (menu_line > num) menu_line -= num;
423 /* Display a list of spells */
424 print_spells(menu_line, spells, num, 1, 15, use_realm);
430 if ((choice == ' ') || (choice == '*') || (choice == '?'))
438 /* Display a list of spells */
439 print_spells(menu_line, spells, num, 1, 15, use_realm);
445 if (use_menu) continue;
458 ask = (isupper(choice));
461 if (ask) choice = (char)tolower(choice);
463 /* Extract request */
464 i = (islower(choice) ? A2I(choice) : -1);
467 /* Totally Illegal */
468 if ((i < 0) || (i >= num))
474 /* Save the spell index */
477 /* Require "okay" spells */
478 if (!spell_okay(spell, learned, FALSE, use_realm))
482 msg_format("その%sを%sことはできません。", p, prompt);
484 msg_format("You may not %s that %s.", prompt, p);
495 /* Access the spell */
496 if (!is_magic(use_realm))
498 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
502 s_ptr = &mp_ptr->info[use_realm - 1][spell];
505 /* Extract mana consumption rate */
506 if (use_realm == REALM_HISSATSU)
508 need_mana = s_ptr->smana;
512 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
517 jverb(prompt, jverb_buf, JVERB_AND);
519 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
520 do_spell(use_realm, spell, SPELL_NAME), need_mana,
521 spell_chance(spell, use_realm), jverb_buf);
523 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
524 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
525 spell_chance(spell, use_realm));
529 /* Belay that order */
530 if (!get_check(tmp_val)) continue;
537 if (redraw) screen_load();
539 p_ptr->window |= (PW_SPELL);
542 /* Abort if needed */
543 if (!flag) return FALSE;
545 /* Save the choice */
548 repeat_push((COMMAND_CODE)spell);
555 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
556 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
557 * @return 魔道書を一冊も持っていないならTRUEを返す
559 static void confirm_use_force(bool browse_only)
564 /* Get the item index */
565 if (repeat_pull(&code) && (code == INVEN_FORCE))
567 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
571 /* Show the prompt */
572 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
579 if (which == ESCAPE) break;
580 else if (which == 'w')
582 repeat_push(INVEN_FORCE);
587 /* Clear the prompt line */
592 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
598 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
599 * Peruse the spells/prayers in a book
603 * Note that *all* spells in the book are listed
605 * Note that browsing is allowed while confused or blind,
606 * and in the dark, primarily to allow browsing in stores.
609 void do_cmd_browse(void)
612 OBJECT_SUBTYPE_VALUE sval;
613 REALM_IDX use_realm = 0;
615 SPELL_IDX spell = -1;
618 SPELL_IDX spells[64];
625 /* Warriors are illiterate */
626 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
628 msg_print(_("本を読むことができない!", "You cannot read books!"));
632 if (p_ptr->special_defense & KATA_MUSOU)
634 set_action(ACTION_NONE);
637 if (p_ptr->pclass == CLASS_FORCETRAINER)
639 if (player_has_no_spellbooks())
641 confirm_use_force(TRUE);
646 /* Restrict choices to "useful" books */
647 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
648 else item_tester_hook = item_tester_learn_spell;
650 q = _("どの本を読みますか? ", "Browse which book? ");
651 s = _("読める本がない。", "You have no books that you can read.");
653 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
656 if (item == INVEN_FORCE) /* the_force */
658 do_cmd_mind_browse();
664 /* Access the item's sval */
667 use_realm = tval2realm(o_ptr->tval);
669 /* Track the object kind */
670 object_kind_track(o_ptr->k_idx);
674 for (spell = 0; spell < 32; spell++)
676 /* Check for this spell */
677 if ((fake_spell_flags[sval] & (1L << spell)))
679 /* Collect this spell */
680 spells[num++] = spell;
687 /* Keep browsing spells. Exit browsing on cancel. */
690 /* Ask for a spell, allow cancel */
691 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
693 /* If cancelled, leave immediately. */
694 if (spell == -1) break;
696 /* Display a list of spells */
697 print_spells(0, spells, num, 1, 15, use_realm);
699 /* Notify that there's nothing to see, and wait. */
700 if (use_realm == REALM_HISSATSU)
701 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
703 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
711 /* Clear lines, position cursor (really should use strlen here) */
712 Term_erase(14, 14, 255);
713 Term_erase(14, 13, 255);
714 Term_erase(14, 12, 255);
715 Term_erase(14, 11, 255);
717 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
719 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
721 prt(&temp[j], line, 15);
729 * @brief プレイヤーの第二魔法領域を変更する /
730 * @param next_realm 変更先の魔法領域ID
733 static void change_realm2(CHARACTER_IDX next_realm)
738 for (i = 0; i < 64; i++)
740 p_ptr->spell_order[j] = p_ptr->spell_order[i];
741 if (p_ptr->spell_order[i] < 32) j++;
744 p_ptr->spell_order[j] = 99;
746 for (i = 32; i < 64; i++)
748 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
750 p_ptr->spell_learned2 = 0L;
751 p_ptr->spell_worked2 = 0L;
752 p_ptr->spell_forgotten2 = 0L;
754 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
755 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
756 p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
757 p_ptr->realm2 = next_realm;
759 p_ptr->update |= (PU_REORDER);
760 p_ptr->update |= (PU_SPELLS);
763 /* Load an autopick preference file */
764 autopick_load_pref(FALSE);
769 * @brief 魔法を学習するコマンドのメインルーチン /
770 * Study a book to gain a new spell/prayer
773 void do_cmd_study(void)
777 OBJECT_SUBTYPE_VALUE sval;
779 bool learned = FALSE;
781 /* Spells of realm2 will have an increment of +32 */
782 SPELL_IDX spell = -1;
784 concptr p = spell_category_name(mp_ptr->spell_book);
792 msg_print(_("本を読むことができない!", "You cannot read books!"));
796 if (p_ptr->blind || no_lite())
798 msg_print(_("目が見えない!", "You cannot see!"));
802 if (cmd_limit_confused(p_ptr)) return;
804 if (!(p_ptr->new_spells))
806 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
810 if (p_ptr->special_defense & KATA_MUSOU)
812 set_action(ACTION_NONE);
816 if (p_ptr->new_spells < 10) {
817 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
820 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
823 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
824 (p_ptr->new_spells == 1 ? "" : "s"));
830 /* Restrict choices to "useful" books */
831 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
832 else item_tester_hook = item_tester_learn_spell;
834 q = _("どの本から学びますか? ", "Study which book? ");
835 s = _("読める本がない。", "You have no books that you can read.");
837 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
840 /* Access the item's sval */
843 if (o_ptr->tval == REALM2_BOOK) increment = 32;
844 else if (o_ptr->tval != REALM1_BOOK)
846 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
847 change_realm2(tval2realm(o_ptr->tval));
851 /* Track the object kind */
852 object_kind_track(o_ptr->k_idx);
855 /* Mage -- Learn a selected spell */
856 if (mp_ptr->spell_book != TV_LIFE_BOOK)
858 /* Ask for a spell, allow cancel */
859 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
862 /* Priest -- Learn a random prayer */
869 for (spell = 0; spell < 32; spell++)
871 /* Check spells in the book */
872 if ((fake_spell_flags[sval] & (1L << spell)))
874 /* Skip non "okay" prayers */
875 if (!spell_okay(spell, FALSE, TRUE,
876 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
878 /* Hack -- Prepare the randomizer */
881 /* Hack -- Apply the randomizer */
882 if (one_in_(k)) gift = spell;
890 /* Nothing to study */
893 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
899 if (increment) spell += increment;
901 /* Learn the spell */
904 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
905 else p_ptr->spell_learned1 |= (1L << spell);
909 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
910 else p_ptr->spell_learned2 |= (1L << (spell - 32));
915 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
916 int old_exp = p_ptr->spell_exp[spell];
917 int new_rank = EXP_LEVEL_UNSKILLED;
918 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
920 if (old_exp >= max_exp)
922 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
926 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
928 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
933 else if (old_exp >= SPELL_EXP_EXPERT)
935 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
936 new_rank = EXP_LEVEL_MASTER;
938 else if (old_exp >= SPELL_EXP_SKILLED)
940 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
941 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
942 new_rank = EXP_LEVEL_EXPERT;
944 else if (old_exp >= SPELL_EXP_BEGINNER)
946 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
947 new_rank = EXP_LEVEL_SKILLED;
951 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
952 new_rank = EXP_LEVEL_BEGINNER;
954 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
958 /* Find the next open entry in "p_ptr->spell_order[]" */
959 for (i = 0; i < 64; i++)
961 /* Stop at the first empty space */
962 if (p_ptr->spell_order[i] == 99) break;
965 /* Add the spell to the known list */
966 p_ptr->spell_order[i++] = spell;
968 /* Mention the result */
971 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
973 msg_format("%sを学んだ。",
974 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
978 msg_format("%sの%sを学んだ。",
979 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
982 msg_format("You have learned the %s of %s.",
983 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
987 take_turn(p_ptr, 100);
989 switch (mp_ptr->spell_book)
992 chg_virtue(V_FAITH, 1);
995 chg_virtue(V_UNLIFE, 1);
998 chg_virtue(V_NATURE, 1);
1001 chg_virtue(V_KNOWLEDGE, 1);
1007 /* One less spell available */
1008 p_ptr->learned_spells++;
1011 p_ptr->update |= (PU_SPELLS);
1012 update_creature(p_ptr);
1014 /* Redraw object recall */
1015 p_ptr->window |= (PW_OBJECT);
1020 * @brief 魔法を詠唱するコマンドのメインルーチン /
1024 void do_cmd_cast(void)
1027 OBJECT_SUBTYPE_VALUE sval;
1032 REALM_IDX use_realm;
1033 MANA_POINT need_mana;
1037 const magic_type *s_ptr;
1040 bool over_exerted = FALSE;
1042 /* Require spell ability */
1043 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1045 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1050 if (p_ptr->blind || no_lite())
1052 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1055 msg_print(_("目が見えない!", "You cannot see!"));
1061 if (cmd_limit_confused(p_ptr)) return;
1064 if (p_ptr->realm1 == REALM_HEX)
1066 if (hex_spell_fully())
1069 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1071 if (p_ptr->lev >= 35) flag = stop_hex_spell();
1076 if (p_ptr->pclass == CLASS_FORCETRAINER)
1078 if (player_has_no_spellbooks())
1080 confirm_use_force(FALSE);
1085 prayer = spell_category_name(mp_ptr->spell_book);
1087 /* Restrict choices to spell books */
1088 item_tester_tval = mp_ptr->spell_book;
1090 q = _("どの呪文書を使いますか? ", "Use which book? ");
1091 s = _("呪文書がない!", "You have no spell books!");
1093 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
1096 if (item == INVEN_FORCE) /* the_force */
1104 /* Access the item's sval */
1107 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1109 /* Track the object kind */
1110 object_kind_track(o_ptr->k_idx);
1113 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1114 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1115 else if (increment) realm = p_ptr->realm2;
1116 else realm = p_ptr->realm1;
1118 /* Ask for a spell */
1120 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1123 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1127 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1131 msg_format("You don't know any %ss in that book.", prayer);
1137 use_realm = tval2realm(o_ptr->tval);
1140 if (use_realm == REALM_HEX)
1142 if (hex_spelling(spell))
1144 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1149 if (!is_magic(use_realm))
1151 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1155 s_ptr = &mp_ptr->info[realm - 1][spell];
1158 /* Extract mana consumption rate */
1159 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1161 /* Verify "dangerous" spells */
1162 if (need_mana > p_ptr->csp)
1164 if (flush_failure) flush();
1168 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1169 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1171 msg_format("You do not have enough mana to %s this %s.",
1172 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1177 if (!over_exert) return;
1180 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1183 /* Spell failure chance */
1184 chance = spell_chance(spell, use_realm);
1186 /* Sufficient mana */
1187 if (need_mana <= p_ptr->csp)
1190 p_ptr->csp -= need_mana;
1192 else over_exerted = TRUE;
1193 p_ptr->redraw |= (PR_MANA);
1196 if (randint0(100) < chance)
1198 if (flush_failure) flush();
1200 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1206 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1209 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1212 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1215 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1218 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1221 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1224 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1228 /* Failure casting may activate some side effect */
1229 do_spell(realm, spell, SPELL_FAIL);
1232 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1234 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1237 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1239 if ((sval == 3) && one_in_(2))
1241 sanity_blast(0, TRUE);
1245 msg_print(_("痛い!", "It hurts!"));
1246 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1248 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1249 lose_exp(spell * 250);
1252 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1254 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1255 aggravate_monsters(0);
1257 if (randint1(100) >= chance)
1258 chg_virtue(V_CHANCE, -1);
1264 /* Canceled spells cost neither a current_world_ptr->game_turn nor mana */
1265 if (!do_spell(realm, spell, SPELL_CAST)) return;
1267 if (randint1(100) < chance)
1268 chg_virtue(V_CHANCE, 1);
1270 /* A spell was cast */
1272 (p_ptr->spell_worked2 & (1L << spell)) :
1273 (p_ptr->spell_worked1 & (1L << spell)))
1274 && (p_ptr->pclass != CLASS_SORCERER)
1275 && (p_ptr->pclass != CLASS_RED_MAGE))
1277 int e = s_ptr->sexp;
1279 /* The spell worked */
1280 if (realm == p_ptr->realm1)
1282 p_ptr->spell_worked1 |= (1L << spell);
1286 p_ptr->spell_worked2 |= (1L << spell);
1289 /* Gain experience */
1290 gain_exp(e * s_ptr->slevel);
1292 /* Redraw object recall */
1293 p_ptr->window |= (PW_OBJECT);
1298 chg_virtue(V_TEMPERANCE, 1);
1299 chg_virtue(V_COMPASSION, 1);
1300 chg_virtue(V_VITALITY, 1);
1301 chg_virtue(V_DILIGENCE, 1);
1304 chg_virtue(V_UNLIFE, 1);
1305 chg_virtue(V_JUSTICE, -1);
1306 chg_virtue(V_FAITH, -1);
1307 chg_virtue(V_VITALITY, -1);
1310 chg_virtue(V_JUSTICE, -1);
1311 chg_virtue(V_FAITH, -1);
1312 chg_virtue(V_HONOUR, -1);
1313 chg_virtue(V_TEMPERANCE, -1);
1316 chg_virtue(V_FAITH, 1);
1317 chg_virtue(V_JUSTICE, 1);
1318 chg_virtue(V_SACRIFICE, 1);
1319 chg_virtue(V_HONOUR, 1);
1322 chg_virtue(V_NATURE, 1);
1323 chg_virtue(V_HARMONY, 1);
1326 chg_virtue(V_JUSTICE, -1);
1327 chg_virtue(V_FAITH, -1);
1328 chg_virtue(V_HONOUR, -1);
1329 chg_virtue(V_COMPASSION, -1);
1332 chg_virtue(V_KNOWLEDGE, 1);
1339 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1340 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1341 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1342 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1345 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 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_VITALITY, -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_FAITH, -1);
1353 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1354 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1357 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1358 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1359 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1360 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_NATURE, 1);
1364 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1367 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1368 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1369 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1370 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1373 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1375 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0) + spell];
1378 if (cur_exp < SPELL_EXP_BEGINNER)
1380 else if (cur_exp < SPELL_EXP_SKILLED)
1382 if ((current_floor_ptr->dun_level > 4) && ((current_floor_ptr->dun_level + 10) > p_ptr->lev))
1385 else if (cur_exp < SPELL_EXP_EXPERT)
1387 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && ((current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1390 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1392 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && (current_floor_ptr->dun_level > s_ptr->slevel))
1395 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1399 take_turn(p_ptr, 100);
1402 /* Over-exert the player */
1405 int oops = need_mana;
1409 p_ptr->csp_frac = 0;
1411 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1413 /* Hack -- Bypass free action */
1414 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1419 chg_virtue(V_VITALITY, -10);
1422 chg_virtue(V_UNLIFE, -10);
1425 chg_virtue(V_JUSTICE, 10);
1428 chg_virtue(V_NATURE, -10);
1431 chg_virtue(V_JUSTICE, -10);
1434 chg_virtue(V_COMPASSION, 10);
1437 chg_virtue(V_KNOWLEDGE, -10);
1441 /* Damage CON (possibly permanently) */
1442 if (randint0(100) < 50)
1444 bool perm = (randint0(100) < 25);
1446 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1448 /* Reduce constitution */
1449 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1453 p_ptr->window |= (PW_PLAYER);
1454 p_ptr->window |= (PW_SPELL);