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"
40 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
45 * @return フォーマットに従い整形された文字列
47 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
51 return format("%s%d", str, base);
55 return format("%s%dd%d", str, dice, sides);
57 /* Dice plus base value */
59 return format("%s%dd%d%+d", str, dice, sides, base);
64 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
68 * @return フォーマットに従い整形された文字列
70 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
72 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
76 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
79 * @return フォーマットに従い整形された文字列
81 concptr info_duration(int base, DICE_SID sides)
83 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
87 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
89 * @return フォーマットに従い整形された文字列
91 concptr info_range(POSITION range)
93 return format(_("範囲:%d", "range %d"), range);
97 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
101 * @return フォーマットに従い整形された文字列
103 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
105 return info_string_dice(_("回復:", "heal "), dice, sides, base);
109 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
112 * @return フォーマットに従い整形された文字列
114 concptr info_delay(int base, DICE_SID sides)
116 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
121 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
123 * @return フォーマットに従い整形された文字列
125 concptr info_multi_damage(HIT_POINT dam)
127 return format(_("損傷:各%d", "dam %d each"), dam);
132 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
135 * @return フォーマットに従い整形された文字列
137 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
139 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
143 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
145 * @return フォーマットに従い整形された文字列
147 concptr info_power(int power)
149 return format(_("効力:%d", "power %d"), power);
154 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
157 * @return フォーマットに従い整形された文字列
160 * Generate power info string such as "power 1d100"
162 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
164 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
169 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
171 * @return フォーマットに従い整形された文字列
173 concptr info_radius(POSITION rad)
175 return format(_("半径:%d", "rad %d"), rad);
180 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
182 * @return フォーマットに従い整形された文字列
184 concptr info_weight(WEIGHT weight)
187 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
189 return format("max wgt %d", weight/10);
194 * @brief 魔法が利用可能かどうかを返す /
195 * Determine if a spell is "okay" for the player to cast or study
196 * The spell must be legible, not forgotten, and also, to cast,
197 * it must be known, and to study, it must not be known.
199 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
200 * @param study_pray 祈りの学習判定目的ならばTRUE
201 * @param use_realm 魔法領域ID
204 static bool spell_okay(int spell, bool learned, bool study_pray, int use_realm)
206 const magic_type *s_ptr;
208 /* Access the spell */
209 if (!is_magic(use_realm))
211 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
215 s_ptr = &mp_ptr->info[use_realm - 1][spell];
218 /* Spell is illegal */
219 if (s_ptr->slevel > p_ptr->lev) return (FALSE);
221 /* Spell is forgotten */
222 if ((use_realm == p_ptr->realm2) ?
223 (p_ptr->spell_forgotten2 & (1L << spell)) :
224 (p_ptr->spell_forgotten1 & (1L << spell)))
230 if (p_ptr->pclass == CLASS_SORCERER) return (TRUE);
231 if (p_ptr->pclass == CLASS_RED_MAGE) return (TRUE);
233 /* Spell is learned */
234 if ((use_realm == p_ptr->realm2) ?
235 (p_ptr->spell_learned2 & (1L << spell)) :
236 (p_ptr->spell_learned1 & (1L << spell)))
239 return (!study_pray);
242 /* Okay to study, not to cast */
248 * @brief 魔法処理のメインルーチン
249 * @param realm 魔法領域のID
250 * @param spell 各領域の魔法ID
252 * @return 各領域魔法に各種テキストを求めた場合は文字列参照ポインタ、そうでない場合はNULLポインタを返す。
254 concptr do_spell(REALM_IDX realm, SPELL_IDX spell, BIT_FLAGS mode)
258 case REALM_LIFE: return do_life_spell(spell, mode);
259 case REALM_SORCERY: return do_sorcery_spell(spell, mode);
260 case REALM_NATURE: return do_nature_spell(spell, mode);
261 case REALM_CHAOS: return do_chaos_spell(spell, mode);
262 case REALM_DEATH: return do_death_spell(spell, mode);
263 case REALM_TRUMP: return do_trump_spell(spell, mode);
264 case REALM_ARCANE: return do_arcane_spell(spell, mode);
265 case REALM_CRAFT: return do_craft_spell(spell, mode);
266 case REALM_DAEMON: return do_daemon_spell(spell, mode);
267 case REALM_CRUSADE: return do_crusade_spell(spell, mode);
268 case REALM_MUSIC: return do_music_spell(spell, mode);
269 case REALM_HISSATSU: return do_hissatsu_spell(spell, mode);
270 case REALM_HEX: return do_hex_spell(spell, mode);
278 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
279 * Allow user to choose a spell/prayer from the given book.
280 * @param sn 選択した魔法IDを返す参照ポインタ
281 * @param prompt 魔法を利用する際の動詞表記
282 * @param sval 魔道書のsval
283 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
284 * @param use_realm 魔法領域ID
287 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
288 * If the user hits escape, returns FALSE, and set '*sn' to -1
289 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
290 * The "prompt" should be "cast", "recite", or "study"
291 * The "known" should be TRUE for cast/pray, FALSE for study
294 static int get_spell(SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
297 SPELL_IDX spell = -1;
300 MANA_POINT need_mana;
301 SPELL_IDX spells[64];
302 bool flag, redraw, okay;
304 const magic_type *s_ptr;
311 int menu_line = (use_menu ? 1 : 0);
313 /* Get the spell, if available */
314 if (repeat_pull(&code))
316 *sn = (SPELL_IDX)code;
317 /* Verify the spell */
318 if (spell_okay(*sn, learned, FALSE, use_realm))
325 p = spell_category_name(mp_ptr->spell_book);
328 for (spell = 0; spell < 32; spell++)
330 /* Check for this spell */
331 if ((fake_spell_flags[sval] & (1L << spell)))
333 /* Collect this spell */
334 spells[num++] = spell;
338 /* Assume no usable spells */
341 /* Assume no spells available */
344 /* Check for "okay" spells */
345 for (i = 0; i < num; i++)
347 /* Look for "okay" spells */
348 if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
351 /* No "okay" spells */
352 if (!okay) return (FALSE);
353 if (((use_realm) != p_ptr->realm1) && ((use_realm) != p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE)) return FALSE;
354 if (((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm)) return FALSE;
355 if ((p_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) return FALSE;
357 /* Assume cancelled */
360 /* Nothing chosen yet */
366 p_ptr->window |= (PW_SPELL);
369 /* Build a prompt (accept all spells) */
371 jverb(prompt, jverb_buf, JVERB_AND);
372 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
373 p, I2A(0), I2A(num - 1), p, jverb_buf);
375 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
376 p, I2A(0), I2A(num - 1), prompt, p);
379 choice = (always_show_list || use_menu) ? ESCAPE : 1;
382 if (choice == ESCAPE) choice = ' ';
383 else if (!get_com(out_val, &choice, TRUE))break;
385 if (use_menu && choice != ' ')
399 menu_line += (num - 1);
421 if (menu_line > num) menu_line -= num;
422 /* Display a list of spells */
423 print_spells(menu_line, spells, num, 1, 15, use_realm);
429 if ((choice == ' ') || (choice == '*') || (choice == '?'))
437 /* Display a list of spells */
438 print_spells(menu_line, spells, num, 1, 15, use_realm);
444 if (use_menu) continue;
457 ask = (isupper(choice));
460 if (ask) choice = (char)tolower(choice);
462 /* Extract request */
463 i = (islower(choice) ? A2I(choice) : -1);
466 /* Totally Illegal */
467 if ((i < 0) || (i >= num))
473 /* Save the spell index */
476 /* Require "okay" spells */
477 if (!spell_okay(spell, learned, FALSE, use_realm))
481 msg_format("その%sを%sことはできません。", p, prompt);
483 msg_format("You may not %s that %s.", prompt, p);
494 /* Access the spell */
495 if (!is_magic(use_realm))
497 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
501 s_ptr = &mp_ptr->info[use_realm - 1][spell];
504 /* Extract mana consumption rate */
505 if (use_realm == REALM_HISSATSU)
507 need_mana = s_ptr->smana;
511 need_mana = mod_need_mana(s_ptr->smana, spell, use_realm);
516 jverb(prompt, jverb_buf, JVERB_AND);
518 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
519 do_spell(use_realm, spell, SPELL_NAME), need_mana,
520 spell_chance(spell, use_realm), jverb_buf);
522 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
523 prompt, do_spell(use_realm, spell, SPELL_NAME), need_mana,
524 spell_chance(spell, use_realm));
528 /* Belay that order */
529 if (!get_check(tmp_val)) continue;
536 if (redraw) screen_load();
538 p_ptr->window |= (PW_SPELL);
541 /* Abort if needed */
542 if (!flag) return FALSE;
544 /* Save the choice */
547 repeat_push((COMMAND_CODE)spell);
554 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
555 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
556 * @return 魔道書を一冊も持っていないならTRUEを返す
558 static void confirm_use_force(bool browse_only)
563 /* Get the item index */
564 if (repeat_pull(&code) && (code == INVEN_FORCE))
566 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
570 /* Show the prompt */
571 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
578 if (which == ESCAPE) break;
579 else if (which == 'w')
581 repeat_push(INVEN_FORCE);
586 /* Clear the prompt line */
591 browse_only ? do_cmd_mind_browse() : do_cmd_mind();
597 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
598 * Peruse the spells/prayers in a book
602 * Note that *all* spells in the book are listed
604 * Note that browsing is allowed while confused or blind,
605 * and in the dark, primarily to allow browsing in stores.
608 void do_cmd_browse(void)
611 OBJECT_SUBTYPE_VALUE sval;
612 REALM_IDX use_realm = 0;
614 SPELL_IDX spell = -1;
617 SPELL_IDX spells[64];
624 /* Warriors are illiterate */
625 if (!(p_ptr->realm1 || p_ptr->realm2) && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
627 msg_print(_("本を読むことができない!", "You cannot read books!"));
631 if (p_ptr->special_defense & KATA_MUSOU)
633 set_action(ACTION_NONE);
636 if (p_ptr->pclass == CLASS_FORCETRAINER)
638 if (player_has_no_spellbooks())
640 confirm_use_force(TRUE);
645 /* Restrict choices to "useful" books */
646 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
647 else item_tester_hook = item_tester_learn_spell;
649 q = _("どの本を読みますか? ", "Browse which book? ");
650 s = _("読める本がない。", "You have no books that you can read.");
652 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
655 if (item == INVEN_FORCE) /* the_force */
657 do_cmd_mind_browse();
663 /* Access the item's sval */
666 use_realm = tval2realm(o_ptr->tval);
668 /* Track the object kind */
669 object_kind_track(o_ptr->k_idx);
673 for (spell = 0; spell < 32; spell++)
675 /* Check for this spell */
676 if ((fake_spell_flags[sval] & (1L << spell)))
678 /* Collect this spell */
679 spells[num++] = spell;
686 /* Keep browsing spells. Exit browsing on cancel. */
689 /* Ask for a spell, allow cancel */
690 if (!get_spell(&spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm))
692 /* If cancelled, leave immediately. */
693 if (spell == -1) break;
695 /* Display a list of spells */
696 print_spells(0, spells, num, 1, 15, use_realm);
698 /* Notify that there's nothing to see, and wait. */
699 if (use_realm == REALM_HISSATSU)
700 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
702 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
710 /* Clear lines, position cursor (really should use strlen here) */
711 Term_erase(14, 14, 255);
712 Term_erase(14, 13, 255);
713 Term_erase(14, 12, 255);
714 Term_erase(14, 11, 255);
716 roff_to_buf(do_spell(use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
718 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j]))
720 prt(&temp[j], line, 15);
728 * @brief プレイヤーの第二魔法領域を変更する /
729 * @param next_realm 変更先の魔法領域ID
732 static void change_realm2(CHARACTER_IDX next_realm)
737 for (i = 0; i < 64; i++)
739 p_ptr->spell_order[j] = p_ptr->spell_order[i];
740 if (p_ptr->spell_order[i] < 32) j++;
743 p_ptr->spell_order[j] = 99;
745 for (i = 32; i < 64; i++)
747 p_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
749 p_ptr->spell_learned2 = 0L;
750 p_ptr->spell_worked2 = 0L;
751 p_ptr->spell_forgotten2 = 0L;
753 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "change magic realm from %s to %s."), realm_names[p_ptr->realm2], realm_names[next_realm]);
754 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
755 p_ptr->old_realm |= 1 << (p_ptr->realm2 - 1);
756 p_ptr->realm2 = next_realm;
758 p_ptr->update |= (PU_REORDER);
759 p_ptr->update |= (PU_SPELLS);
762 /* Load an autopick preference file */
763 autopick_load_pref(FALSE);
768 * @brief 魔法を学習するコマンドのメインルーチン /
769 * Study a book to gain a new spell/prayer
772 void do_cmd_study(void)
776 OBJECT_SUBTYPE_VALUE sval;
778 bool learned = FALSE;
780 /* Spells of realm2 will have an increment of +32 */
781 SPELL_IDX spell = -1;
783 concptr p = spell_category_name(mp_ptr->spell_book);
791 msg_print(_("本を読むことができない!", "You cannot read books!"));
795 if (p_ptr->blind || no_lite())
797 msg_print(_("目が見えない!", "You cannot see!"));
801 if (cmd_limit_confused(p_ptr)) return;
803 if (!(p_ptr->new_spells))
805 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
809 if (p_ptr->special_defense & KATA_MUSOU)
811 set_action(ACTION_NONE);
815 if (p_ptr->new_spells < 10) {
816 msg_format("あと %d つの%sを学べる。", p_ptr->new_spells, p);
819 msg_format("あと %d 個の%sを学べる。", p_ptr->new_spells, p);
822 msg_format("You can learn %d new %s%s.", p_ptr->new_spells, p,
823 (p_ptr->new_spells == 1 ? "" : "s"));
829 /* Restrict choices to "useful" books */
830 if (p_ptr->realm2 == REALM_NONE) item_tester_tval = mp_ptr->spell_book;
831 else item_tester_hook = item_tester_learn_spell;
833 q = _("どの本から学びますか? ", "Study which book? ");
834 s = _("読める本がない。", "You have no books that you can read.");
836 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
839 /* Access the item's sval */
842 if (o_ptr->tval == REALM2_BOOK) increment = 32;
843 else if (o_ptr->tval != REALM1_BOOK)
845 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) return;
846 change_realm2(tval2realm(o_ptr->tval));
850 /* Track the object kind */
851 object_kind_track(o_ptr->k_idx);
854 /* Mage -- Learn a selected spell */
855 if (mp_ptr->spell_book != TV_LIFE_BOOK)
857 /* Ask for a spell, allow cancel */
858 if (!get_spell(&spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1)) return;
861 /* Priest -- Learn a random prayer */
868 for (spell = 0; spell < 32; spell++)
870 /* Check spells in the book */
871 if ((fake_spell_flags[sval] & (1L << spell)))
873 /* Skip non "okay" prayers */
874 if (!spell_okay(spell, FALSE, TRUE,
875 (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
877 /* Hack -- Prepare the randomizer */
880 /* Hack -- Apply the randomizer */
881 if (one_in_(k)) gift = spell;
889 /* Nothing to study */
892 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
898 if (increment) spell += increment;
900 /* Learn the spell */
903 if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
904 else p_ptr->spell_learned1 |= (1L << spell);
908 if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
909 else p_ptr->spell_learned2 |= (1L << (spell - 32));
914 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
915 int old_exp = p_ptr->spell_exp[spell];
916 int new_rank = EXP_LEVEL_UNSKILLED;
917 concptr name = do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME);
919 if (old_exp >= max_exp)
921 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
925 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
927 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
932 else if (old_exp >= SPELL_EXP_EXPERT)
934 p_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
935 new_rank = EXP_LEVEL_MASTER;
937 else if (old_exp >= SPELL_EXP_SKILLED)
939 if (spell >= 32) p_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
940 else p_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
941 new_rank = EXP_LEVEL_EXPERT;
943 else if (old_exp >= SPELL_EXP_BEGINNER)
945 p_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
946 new_rank = EXP_LEVEL_SKILLED;
950 p_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
951 new_rank = EXP_LEVEL_BEGINNER;
953 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
957 /* Find the next open entry in "p_ptr->spell_order[]" */
958 for (i = 0; i < 64; i++)
960 /* Stop at the first empty space */
961 if (p_ptr->spell_order[i] == 99) break;
964 /* Add the spell to the known list */
965 p_ptr->spell_order[i++] = spell;
967 /* Mention the result */
970 if (mp_ptr->spell_book == TV_MUSIC_BOOK)
972 msg_format("%sを学んだ。",
973 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
977 msg_format("%sの%sを学んだ。",
978 do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME), p);
981 msg_format("You have learned the %s of %s.",
982 p, do_spell(increment ? p_ptr->realm2 : p_ptr->realm1, spell % 32, SPELL_NAME));
986 take_turn(p_ptr, 100);
988 switch (mp_ptr->spell_book)
991 chg_virtue(V_FAITH, 1);
994 chg_virtue(V_UNLIFE, 1);
997 chg_virtue(V_NATURE, 1);
1000 chg_virtue(V_KNOWLEDGE, 1);
1006 /* One less spell available */
1007 p_ptr->learned_spells++;
1010 p_ptr->update |= (PU_SPELLS);
1011 update_creature(p_ptr);
1013 /* Redraw object recall */
1014 p_ptr->window |= (PW_OBJECT);
1019 * @brief 魔法を詠唱するコマンドのメインルーチン /
1023 void do_cmd_cast(void)
1026 OBJECT_SUBTYPE_VALUE sval;
1031 REALM_IDX use_realm;
1032 MANA_POINT need_mana;
1036 const magic_type *s_ptr;
1039 bool over_exerted = FALSE;
1041 /* Require spell ability */
1042 if (!p_ptr->realm1 && (p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE))
1044 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
1049 if (p_ptr->blind || no_lite())
1051 if (p_ptr->pclass == CLASS_FORCETRAINER) confirm_use_force(FALSE);
1054 msg_print(_("目が見えない!", "You cannot see!"));
1060 if (cmd_limit_confused(p_ptr)) return;
1063 if (p_ptr->realm1 == REALM_HEX)
1065 if (hex_spell_fully())
1068 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not spell new spells more."));
1070 if (p_ptr->lev >= 35) flag = stop_hex_spell();
1075 if (p_ptr->pclass == CLASS_FORCETRAINER)
1077 if (player_has_no_spellbooks())
1079 confirm_use_force(FALSE);
1084 prayer = spell_category_name(mp_ptr->spell_book);
1086 /* Restrict choices to spell books */
1087 item_tester_tval = mp_ptr->spell_book;
1089 q = _("どの呪文書を使いますか? ", "Use which book? ");
1090 s = _("呪文書がない!", "You have no spell books!");
1092 o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR | (p_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)));
1095 if (item == INVEN_FORCE) /* the_force */
1103 /* Access the item's sval */
1106 if ((p_ptr->pclass != CLASS_SORCERER) && (p_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == REALM2_BOOK)) increment = 32;
1108 /* Track the object kind */
1109 object_kind_track(o_ptr->k_idx);
1112 if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
1113 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1114 else if (increment) realm = p_ptr->realm2;
1115 else realm = p_ptr->realm1;
1117 /* Ask for a spell */
1119 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"),
1122 if (spell == -2) msg_format("その本には知っている%sがない。", prayer);
1126 if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1130 msg_format("You don't know any %ss in that book.", prayer);
1136 use_realm = tval2realm(o_ptr->tval);
1139 if (use_realm == REALM_HEX)
1141 if (hex_spelling(spell))
1143 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1148 if (!is_magic(use_realm))
1150 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1154 s_ptr = &mp_ptr->info[realm - 1][spell];
1157 /* Extract mana consumption rate */
1158 need_mana = mod_need_mana(s_ptr->smana, spell, realm);
1160 /* Verify "dangerous" spells */
1161 if (need_mana > p_ptr->csp)
1163 if (flush_failure) flush();
1167 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1168 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1170 msg_format("You do not have enough mana to %s this %s.",
1171 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
1176 if (!over_exert) return;
1179 if (!get_check_strict(_("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) return;
1182 /* Spell failure chance */
1183 chance = spell_chance(spell, use_realm);
1185 /* Sufficient mana */
1186 if (need_mana <= p_ptr->csp)
1189 p_ptr->csp -= need_mana;
1191 else over_exerted = TRUE;
1192 p_ptr->redraw |= (PR_MANA);
1195 if (randint0(100) < chance)
1197 if (flush_failure) flush();
1199 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1205 if (randint1(100) < chance) chg_virtue(V_VITALITY, -1);
1208 if (randint1(100) < chance) chg_virtue(V_UNLIFE, -1);
1211 if (randint1(100) < chance) chg_virtue(V_NATURE, -1);
1214 if (randint1(100) < chance) chg_virtue(V_JUSTICE, 1);
1217 if (randint1(100) < chance) chg_virtue(V_JUSTICE, -1);
1220 if (randint1(100) < chance) chg_virtue(V_COMPASSION, -1);
1223 if (randint1(100) < chance) chg_virtue(V_KNOWLEDGE, -1);
1227 /* Failure casting may activate some side effect */
1228 do_spell(realm, spell, SPELL_FAIL);
1231 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
1233 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1236 else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
1238 if ((sval == 3) && one_in_(2))
1240 sanity_blast(0, TRUE);
1244 msg_print(_("痛い!", "It hurts!"));
1245 take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"), -1);
1247 if ((spell > 15) && one_in_(6) && !p_ptr->hold_exp)
1248 lose_exp(spell * 250);
1251 else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
1253 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1254 aggravate_monsters(0);
1256 if (randint1(100) >= chance)
1257 chg_virtue(V_CHANCE, -1);
1263 /* Canceled spells cost neither a current_world_ptr->game_turn nor mana */
1264 if (!do_spell(realm, spell, SPELL_CAST)) return;
1266 if (randint1(100) < chance)
1267 chg_virtue(V_CHANCE, 1);
1269 /* A spell was cast */
1271 (p_ptr->spell_worked2 & (1L << spell)) :
1272 (p_ptr->spell_worked1 & (1L << spell)))
1273 && (p_ptr->pclass != CLASS_SORCERER)
1274 && (p_ptr->pclass != CLASS_RED_MAGE))
1276 int e = s_ptr->sexp;
1278 /* The spell worked */
1279 if (realm == p_ptr->realm1)
1281 p_ptr->spell_worked1 |= (1L << spell);
1285 p_ptr->spell_worked2 |= (1L << spell);
1288 /* Gain experience */
1289 gain_exp(e * s_ptr->slevel);
1291 /* Redraw object recall */
1292 p_ptr->window |= (PW_OBJECT);
1297 chg_virtue(V_TEMPERANCE, 1);
1298 chg_virtue(V_COMPASSION, 1);
1299 chg_virtue(V_VITALITY, 1);
1300 chg_virtue(V_DILIGENCE, 1);
1303 chg_virtue(V_UNLIFE, 1);
1304 chg_virtue(V_JUSTICE, -1);
1305 chg_virtue(V_FAITH, -1);
1306 chg_virtue(V_VITALITY, -1);
1309 chg_virtue(V_JUSTICE, -1);
1310 chg_virtue(V_FAITH, -1);
1311 chg_virtue(V_HONOUR, -1);
1312 chg_virtue(V_TEMPERANCE, -1);
1315 chg_virtue(V_FAITH, 1);
1316 chg_virtue(V_JUSTICE, 1);
1317 chg_virtue(V_SACRIFICE, 1);
1318 chg_virtue(V_HONOUR, 1);
1321 chg_virtue(V_NATURE, 1);
1322 chg_virtue(V_HARMONY, 1);
1325 chg_virtue(V_JUSTICE, -1);
1326 chg_virtue(V_FAITH, -1);
1327 chg_virtue(V_HONOUR, -1);
1328 chg_virtue(V_COMPASSION, -1);
1331 chg_virtue(V_KNOWLEDGE, 1);
1338 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, 1);
1339 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, 1);
1340 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, 1);
1341 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_DILIGENCE, 1);
1344 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_UNLIFE, 1);
1345 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1346 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1347 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_VITALITY, -1);
1350 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1351 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1352 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1353 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_TEMPERANCE, -1);
1356 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, 1);
1357 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, 1);
1358 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_SACRIFICE, 1);
1359 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, 1);
1362 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_NATURE, 1);
1363 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HARMONY, 1);
1366 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_JUSTICE, -1);
1367 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_FAITH, -1);
1368 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_HONOUR, -1);
1369 if (randint1(100 + p_ptr->lev) < need_mana) chg_virtue(V_COMPASSION, -1);
1372 if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
1374 s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0) + spell];
1377 if (cur_exp < SPELL_EXP_BEGINNER)
1379 else if (cur_exp < SPELL_EXP_SKILLED)
1381 if ((current_floor_ptr->dun_level > 4) && ((current_floor_ptr->dun_level + 10) > p_ptr->lev))
1384 else if (cur_exp < SPELL_EXP_EXPERT)
1386 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && ((current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1389 else if ((cur_exp < SPELL_EXP_MASTER) && !increment)
1391 if (((current_floor_ptr->dun_level + 5) > p_ptr->lev) && (current_floor_ptr->dun_level > s_ptr->slevel))
1394 p_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1398 take_turn(p_ptr, 100);
1401 /* Over-exert the player */
1404 int oops = need_mana;
1408 p_ptr->csp_frac = 0;
1410 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1412 /* Hack -- Bypass free action */
1413 (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
1418 chg_virtue(V_VITALITY, -10);
1421 chg_virtue(V_UNLIFE, -10);
1424 chg_virtue(V_JUSTICE, 10);
1427 chg_virtue(V_NATURE, -10);
1430 chg_virtue(V_JUSTICE, -10);
1433 chg_virtue(V_COMPASSION, 10);
1436 chg_virtue(V_KNOWLEDGE, -10);
1440 /* Damage CON (possibly permanently) */
1441 if (randint0(100) < 50)
1443 bool perm = (randint0(100) < 25);
1445 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1447 /* Reduce constitution */
1448 (void)dec_stat(A_CON, 15 + randint1(10), perm);
1452 p_ptr->window |= (PW_PLAYER);
1453 p_ptr->window |= (PW_SPELL);