2 * @brief 魔法のインターフェイスと発動 / Purpose: Do everything for each spell
5 * 2013 Deskull rearranged comment for Doxygen.
8 #include "cmd-action/cmd-spell.h"
9 #include "action/action-limited.h"
10 #include "autopick/autopick-reader-writer.h"
11 #include "cmd-action/cmd-mind.h"
12 #include "cmd-io/cmd-dump.h"
13 #include "core/asking-player.h"
14 #include "core/player-redraw-types.h"
15 #include "core/player-update-types.h"
16 #include "core/stuff-handler.h"
17 #include "core/window-redrawer.h"
18 #include "floor/floor-object.h"
19 #include "game-option/disturbance-options.h"
20 #include "game-option/input-options.h"
21 #include "game-option/text-display-options.h"
22 #include "grid/grid.h"
23 #include "inventory/inventory-slot-types.h"
24 #include "io/command-repeater.h"
25 #include "io/input-key-acceptor.h"
26 #include "io/input-key-requester.h"
27 #include "io/write-diary.h"
28 #include "main/sound-definitions-table.h"
29 #include "main/sound-of-music.h"
30 #include "object-hook/hook-magic.h"
31 #include "object/item-tester-hooker.h"
32 #include "object/item-use-flags.h"
33 #include "player-info/avatar.h"
34 #include "player-info/self-info.h"
35 #include "player-status/player-energy.h"
36 #include "player/attack-defense-types.h"
37 #include "player/eldritch-horror.h"
38 #include "player/player-class.h"
39 #include "player/player-damage.h"
40 #include "player/player-realm.h"
41 #include "player/player-skill.h"
42 #include "player/player-status.h"
43 #include "player/special-defense-types.h"
44 #include "realm/realm-names-table.h"
45 #include "spell-kind/spells-random.h"
46 #include "spell-kind/spells-sight.h"
47 #include "spell-realm/spells-hex.h"
48 #include "spell/range-calc.h"
49 #include "spell/spell-info.h"
50 #include "spell/spells-describer.h"
51 #include "spell/spells-execution.h"
52 #include "spell/spells-summon.h"
53 #include "spell/technic-info-table.h"
54 #include "status/action-setter.h"
55 #include "status/bad-status-setter.h"
56 #include "status/base-status.h"
57 #include "status/experience.h"
58 #include "system/floor-type-definition.h"
59 #include "system/object-type-definition.h"
60 #include "system/player-type-definition.h"
61 #include "term/screen-processor.h"
62 #include "util/bit-flags-calculator.h"
63 #include "util/buffer-shaper.h"
64 #include "util/int-char-converter.h"
65 #include "view/display-messages.h"
67 #include "locale/japanese.h"
70 static const int extra_magic_gain_exp = 4;
72 concptr KWD_DAM = _("損傷:", "dam ");
73 concptr KWD_RANGE = _("射程:", "rng ");
74 concptr KWD_DURATION = _("期間:", "dur ");
75 concptr KWD_SPHERE = _("範囲:", "range ");
76 concptr KWD_HEAL = _("回復:", "heal ");
77 concptr KWD_MANA = _("MP回復:", "heal SP ");
78 concptr KWD_POWER _("効力:", "power ");
79 concptr KWD_RANDOM = _("ランダム", "random");
83 * Zangband uses this array instead of the spell flags table, as there
84 * are 5 realms of magic, each with 4 spellbooks and 8 spells per book -- TY
86 const u32b fake_spell_flags[4] = { 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
90 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
95 * @return フォーマットに従い整形された文字列
97 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
101 return format("%s%d", str, base);
105 return format("%s%dd%d", str, dice, sides);
107 /* Dice plus base value */
109 return format("%s%dd%d%+d", str, dice, sides, base);
113 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
117 * @return フォーマットに従い整形された文字列
119 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base) { return info_string_dice(_("損傷:", "dam "), dice, sides, base); }
122 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
125 * @return フォーマットに従い整形された文字列
127 concptr info_duration(int base, DICE_SID sides) { return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides); }
130 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
132 * @return フォーマットに従い整形された文字列
134 concptr info_range(POSITION range) { return format(_("範囲:%d", "range %d"), range); }
137 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
141 * @return フォーマットに従い整形された文字列
143 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base) { return info_string_dice(_("回復:", "heal "), dice, sides, base); }
146 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
149 * @return フォーマットに従い整形された文字列
151 concptr info_delay(int base, DICE_SID sides) { return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides); }
154 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
156 * @return フォーマットに従い整形された文字列
158 concptr info_multi_damage(HIT_POINT dam) { return format(_("損傷:各%d", "dam %d each"), dam); }
161 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
164 * @return フォーマットに従い整形された文字列
166 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides) { return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides); }
169 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
171 * @return フォーマットに従い整形された文字列
173 concptr info_power(int power) { return format(_("効力:%d", "power %d"), power); }
176 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
179 * @return フォーマットに従い整形された文字列
182 * Generate power info string such as "power 1d100"
184 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides) { return format(_("効力:%dd%d", "power %dd%d"), dice, sides); }
187 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
189 * @return フォーマットに従い整形された文字列
191 concptr info_radius(POSITION rad) { return format(_("半径:%d", "rad %d"), rad); }
194 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
196 * @return フォーマットに従い整形された文字列
198 concptr info_weight(WEIGHT weight)
201 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
203 return format("max wgt %d", weight / 10);
208 * @brief 魔法が利用可能かどうかを返す /
209 * Determine if a spell is "okay" for the player to cast or study
210 * The spell must be legible, not forgotten, and also, to cast,
211 * it must be known, and to study, it must not be known.
213 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
214 * @param study_pray 祈りの学習判定目的ならばTRUE
215 * @param use_realm 魔法領域ID
218 static bool spell_okay(player_type *caster_ptr, int spell, bool learned, bool study_pray, int use_realm)
220 const magic_type *s_ptr;
222 /* Access the spell */
223 if (!is_magic(use_realm)) {
224 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
226 s_ptr = &mp_ptr->info[use_realm - 1][spell];
229 /* Spell is illegal */
230 if (s_ptr->slevel > caster_ptr->lev)
233 /* Spell is forgotten */
234 if ((use_realm == caster_ptr->realm2) ? (caster_ptr->spell_forgotten2 & (1UL << spell)) : (caster_ptr->spell_forgotten1 & (1UL << spell))) {
239 if (caster_ptr->pclass == CLASS_SORCERER)
241 if (caster_ptr->pclass == CLASS_RED_MAGE)
244 /* Spell is learned */
245 if ((use_realm == caster_ptr->realm2) ? (caster_ptr->spell_learned2 & (1UL << spell)) : (caster_ptr->spell_learned1 & (1UL << spell))) {
247 return (!study_pray);
250 /* Okay to study, not to cast */
255 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
256 * Allow user to choose a spell/prayer from the given book.
257 * @param sn 選択した魔法IDを返す参照ポインタ
258 * @param prompt 魔法を利用する際の動詞表記
259 * @param sval 魔道書のsval
260 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
261 * @param use_realm 魔法領域ID
264 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
265 * If the user hits escape, returns FALSE, and set '*sn' to -1
266 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
267 * The "prompt" should be "cast", "recite", or "study"
268 * The "known" should be TRUE for cast/pray, FALSE for study
271 static int get_spell(player_type *caster_ptr, SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
274 SPELL_IDX spell = -1;
277 MANA_POINT need_mana;
278 SPELL_IDX spells[64];
279 bool flag, redraw, okay;
281 const magic_type *s_ptr;
288 int menu_line = (use_menu ? 1 : 0);
290 /* Get the spell, if available */
291 if (repeat_pull(&code)) {
292 *sn = (SPELL_IDX)code;
293 /* Verify the spell */
294 if (spell_okay(caster_ptr, *sn, learned, FALSE, use_realm)) {
300 p = spell_category_name(mp_ptr->spell_book);
303 for (spell = 0; spell < 32; spell++) {
304 /* Check for this spell */
305 if ((fake_spell_flags[sval] & (1UL << spell))) {
306 /* Collect this spell */
307 spells[num++] = spell;
311 /* Assume no usable spells */
314 /* Assume no spells available */
317 /* Check for "okay" spells */
318 for (i = 0; i < num; i++) {
319 /* Look for "okay" spells */
320 if (spell_okay(caster_ptr, spells[i], learned, FALSE, use_realm))
324 /* No "okay" spells */
327 if (((use_realm) != caster_ptr->realm1) && ((use_realm) != caster_ptr->realm2) && (caster_ptr->pclass != CLASS_SORCERER)
328 && (caster_ptr->pclass != CLASS_RED_MAGE))
330 if (((caster_ptr->pclass == CLASS_SORCERER) || (caster_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm))
332 if ((caster_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1))
335 /* Assume cancelled */
341 caster_ptr->window_flags |= (PW_SPELL);
342 handle_stuff(caster_ptr);
344 /* Build a prompt (accept all spells) */
346 jverb(prompt, jverb_buf, JVERB_AND);
347 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ", p, I2A(0), I2A(num - 1), p, jverb_buf);
349 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ", p, I2A(0), I2A(num - 1), prompt, p);
352 choice = (always_show_list || use_menu) ? ESCAPE : 1;
354 if (choice == ESCAPE)
356 else if (!get_com(out_val, &choice, TRUE))
359 if (use_menu && choice != ' ') {
369 menu_line += (num - 1);
391 /* Display a list of spells */
392 print_spells(caster_ptr, menu_line, spells, num, 1, 15, use_realm);
397 if ((choice == ' ') || (choice == '*') || (choice == '?')) {
403 /* Display a list of spells */
404 print_spells(caster_ptr, menu_line, spells, num, 1, 15, use_realm);
422 ask = (isupper(choice));
426 choice = (char)tolower(choice);
428 /* Extract request */
429 i = (islower(choice) ? A2I(choice) : -1);
432 /* Totally Illegal */
433 if ((i < 0) || (i >= num)) {
438 /* Save the spell index */
441 /* Require "okay" spells */
442 if (!spell_okay(caster_ptr, spell, learned, FALSE, use_realm)) {
445 msg_format("その%sを%sことはできません。", p, prompt);
447 msg_format("You may not %s that %s.", prompt, p);
457 /* Access the spell */
458 if (!is_magic(use_realm)) {
459 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
461 s_ptr = &mp_ptr->info[use_realm - 1][spell];
464 /* Extract mana consumption rate */
465 if (use_realm == REALM_HISSATSU) {
466 need_mana = s_ptr->smana;
468 need_mana = mod_need_mana(caster_ptr, s_ptr->smana, spell, use_realm);
473 jverb(prompt, jverb_buf, JVERB_AND);
475 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ", exe_spell(caster_ptr, use_realm, spell, SPELL_NAME), need_mana,
476 spell_chance(caster_ptr, spell, use_realm), jverb_buf);
478 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ", prompt, exe_spell(caster_ptr, use_realm, spell, SPELL_NAME), need_mana,
479 spell_chance(caster_ptr, spell, use_realm));
482 /* Belay that order */
483 if (!get_check(tmp_val))
494 caster_ptr->window_flags |= (PW_SPELL);
495 handle_stuff(caster_ptr);
497 /* Abort if needed */
501 /* Save the choice */
504 repeat_push((COMMAND_CODE)spell);
511 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
512 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
513 * @return 魔道書を一冊も持っていないならTRUEを返す
515 static void confirm_use_force(player_type *caster_ptr, bool browse_only)
520 /* Get the item index */
521 if (repeat_pull(&code) && (code == INVEN_FORCE)) {
522 browse_only ? do_cmd_mind_browse(caster_ptr) : do_cmd_mind(caster_ptr);
526 /* Show the prompt */
527 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
535 else if (which == 'w') {
536 repeat_push(INVEN_FORCE);
541 /* Clear the prompt line */
545 browse_only ? do_cmd_mind_browse(caster_ptr) : do_cmd_mind(caster_ptr);
550 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
551 * Peruse the spells/prayers in a book
554 * Note that *all* spells in the book are listed
556 * Note that browsing is allowed while confused or blind,
557 * and in the dark, primarily to allow browsing in stores.
560 void do_cmd_browse(player_type *caster_ptr)
563 OBJECT_SUBTYPE_VALUE sval;
564 REALM_IDX use_realm = 0;
566 SPELL_IDX spell = -1;
569 SPELL_IDX spells[64];
575 tval_type tval = TV_NONE;
577 /* Warriors are illiterate */
578 if (!(caster_ptr->realm1 || caster_ptr->realm2) && (caster_ptr->pclass != CLASS_SORCERER) && (caster_ptr->pclass != CLASS_RED_MAGE)) {
579 msg_print(_("本を読むことができない!", "You cannot read books!"));
583 if (caster_ptr->special_defense & KATA_MUSOU) {
584 set_action(caster_ptr, ACTION_NONE);
587 if (caster_ptr->pclass == CLASS_FORCETRAINER) {
588 if (player_has_no_spellbooks(caster_ptr)) {
589 confirm_use_force(caster_ptr, TRUE);
594 /* Restrict choices to "useful" books */
595 if (caster_ptr->realm2 == REALM_NONE)
596 tval = mp_ptr->spell_book;
598 item_tester_hook = item_tester_learn_spell;
600 q = _("どの本を読みますか? ", "Browse which book? ");
601 s = _("読める本がない。", "You have no books that you can read.");
603 o_ptr = choose_object(caster_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | (caster_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)), tval);
605 item_tester_hook = NULL;
607 if (item == INVEN_FORCE) /* the_force */
609 do_cmd_mind_browse(caster_ptr);
615 /* Access the item's sval */
618 use_realm = tval2realm(o_ptr->tval);
620 /* Track the object kind */
621 object_kind_track(caster_ptr, o_ptr->k_idx);
622 handle_stuff(caster_ptr);
625 for (spell = 0; spell < 32; spell++) {
626 /* Check for this spell */
627 if ((fake_spell_flags[sval] & (1UL << spell))) {
628 /* Collect this spell */
629 spells[num++] = spell;
636 /* Keep browsing spells. Exit browsing on cancel. */
638 /* Ask for a spell, allow cancel */
639 if (!get_spell(caster_ptr, &spell, _("読む", "browse"), o_ptr->sval, TRUE, use_realm)) {
640 /* If cancelled, leave immediately. */
644 /* Display a list of spells */
645 print_spells(caster_ptr, 0, spells, num, 1, 15, use_realm);
647 /* Notify that there's nothing to see, and wait. */
648 if (use_realm == REALM_HISSATSU)
649 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
651 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
659 /* Clear lines, position cursor (really should use strlen here) */
660 term_erase(14, 14, 255);
661 term_erase(14, 13, 255);
662 term_erase(14, 12, 255);
663 term_erase(14, 11, 255);
665 shape_buffer(exe_spell(caster_ptr, use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
667 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j])) {
668 prt(&temp[j], line, 15);
676 * @brief プレイヤーの第二魔法領域を変更する /
677 * @param caster_ptr プレーヤーへの参照ポインタ
678 * @param next_realm 変更先の魔法領域ID
680 static void change_realm2(player_type *caster_ptr, REALM_IDX next_realm)
685 for (i = 0; i < 64; i++) {
686 caster_ptr->spell_order[j] = caster_ptr->spell_order[i];
687 if (caster_ptr->spell_order[i] < 32)
691 caster_ptr->spell_order[j] = 99;
693 for (i = 32; i < 64; i++) {
694 caster_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
696 caster_ptr->spell_learned2 = 0L;
697 caster_ptr->spell_worked2 = 0L;
698 caster_ptr->spell_forgotten2 = 0L;
700 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "changed magic realm from %s to %s."), realm_names[caster_ptr->realm2], realm_names[next_realm]);
701 exe_write_diary(caster_ptr, DIARY_DESCRIPTION, 0, tmp);
702 caster_ptr->old_realm |= 1U << (caster_ptr->realm2 - 1);
703 caster_ptr->realm2 = next_realm;
705 caster_ptr->update |= (PU_REORDER);
706 caster_ptr->update |= (PU_SPELLS);
707 handle_stuff(caster_ptr);
709 /* Load an autopick preference file */
710 autopick_load_pref(caster_ptr, FALSE);
714 * @brief 魔法を学習するコマンドのメインルーチン /
715 * Study a book to gain a new spell/prayer
717 void do_cmd_study(player_type *caster_ptr)
721 OBJECT_SUBTYPE_VALUE sval;
723 bool learned = FALSE;
725 /* Spells of realm2 will have an increment of +32 */
726 SPELL_IDX spell = -1;
727 concptr p = spell_category_name(mp_ptr->spell_book);
730 tval_type tval = TV_NONE;
732 if (!caster_ptr->realm1) {
733 msg_print(_("本を読むことができない!", "You cannot read books!"));
737 if (cmd_limit_blind(caster_ptr))
739 if (cmd_limit_confused(caster_ptr))
742 if (!(caster_ptr->new_spells)) {
743 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
747 if (caster_ptr->special_defense & KATA_MUSOU) {
748 set_action(caster_ptr, ACTION_NONE);
752 if (caster_ptr->new_spells < 10) {
753 msg_format("あと %d つの%sを学べる。", caster_ptr->new_spells, p);
755 msg_format("あと %d 個の%sを学べる。", caster_ptr->new_spells, p);
758 msg_format("You can learn %d new %s%s.", caster_ptr->new_spells, p, (caster_ptr->new_spells == 1 ? "" : "s"));
763 /* Restrict choices to "useful" books */
764 if (caster_ptr->realm2 == REALM_NONE)
765 tval = mp_ptr->spell_book;
767 item_tester_hook = item_tester_learn_spell;
769 q = _("どの本から学びますか? ", "Study which book? ");
770 s = _("読める本がない。", "You have no books that you can read.");
772 o_ptr = choose_object(caster_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), tval);
777 /* Access the item's sval */
780 if (o_ptr->tval == get_realm2_book(caster_ptr))
782 else if (o_ptr->tval != get_realm1_book(caster_ptr)) {
783 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? ")))
785 change_realm2(caster_ptr, tval2realm(o_ptr->tval));
789 /* Track the object kind */
790 object_kind_track(caster_ptr, o_ptr->k_idx);
791 handle_stuff(caster_ptr);
793 /* Mage -- Learn a selected spell */
794 if (mp_ptr->spell_book != TV_LIFE_BOOK) {
795 /* Ask for a spell, allow cancel */
796 if (!get_spell(caster_ptr, &spell, _("学ぶ", "study"), sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1))
800 /* Priest -- Learn a random prayer */
806 for (spell = 0; spell < 32; spell++) {
807 /* Check spells in the book */
808 if ((fake_spell_flags[sval] & (1UL << spell))) {
809 /* Skip non "okay" prayers */
810 if (!spell_okay(caster_ptr, spell, FALSE, TRUE, (increment ? caster_ptr->realm2 : caster_ptr->realm1)))
813 /* Hack -- Prepare the randomizer */
816 /* Hack -- Apply the randomizer */
826 /* Nothing to study */
828 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
837 /* Learn the spell */
839 if (caster_ptr->spell_learned1 & (1UL << spell))
842 caster_ptr->spell_learned1 |= (1UL << spell);
844 if (caster_ptr->spell_learned2 & (1UL << (spell - 32)))
847 caster_ptr->spell_learned2 |= (1UL << (spell - 32));
851 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
852 int old_exp = caster_ptr->spell_exp[spell];
853 int new_rank = EXP_LEVEL_UNSKILLED;
854 concptr name = exe_spell(caster_ptr, increment ? caster_ptr->realm2 : caster_ptr->realm1, spell % 32, SPELL_NAME);
856 if (old_exp >= max_exp) {
857 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
861 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
863 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
867 } else if (old_exp >= SPELL_EXP_EXPERT) {
868 caster_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
869 new_rank = EXP_LEVEL_MASTER;
870 } else if (old_exp >= SPELL_EXP_SKILLED) {
872 caster_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
874 caster_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
875 new_rank = EXP_LEVEL_EXPERT;
876 } else if (old_exp >= SPELL_EXP_BEGINNER) {
877 caster_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
878 new_rank = EXP_LEVEL_SKILLED;
880 caster_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
881 new_rank = EXP_LEVEL_BEGINNER;
883 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
885 /* Find the next open entry in "caster_ptr->spell_order[]" */
886 for (i = 0; i < 64; i++) {
887 /* Stop at the first empty space */
888 if (caster_ptr->spell_order[i] == 99)
892 /* Add the spell to the known list */
893 caster_ptr->spell_order[i++] = spell;
895 /* Mention the result */
898 if (mp_ptr->spell_book == TV_MUSIC_BOOK) {
899 msg_format("%sを学んだ。", exe_spell(caster_ptr, increment ? caster_ptr->realm2 : caster_ptr->realm1, spell % 32, SPELL_NAME));
901 msg_format("%sの%sを学んだ。", exe_spell(caster_ptr, increment ? caster_ptr->realm2 : caster_ptr->realm1, spell % 32, SPELL_NAME), p);
904 msg_format("You have learned the %s of %s.", p, exe_spell(caster_ptr, increment ? caster_ptr->realm2 : caster_ptr->realm1, spell % 32, SPELL_NAME));
908 PlayerEnergy(caster_ptr).set_player_turn_energy(100);
910 switch (mp_ptr->spell_book) {
912 chg_virtue(caster_ptr, V_FAITH, 1);
915 chg_virtue(caster_ptr, V_UNLIFE, 1);
918 chg_virtue(caster_ptr, V_NATURE, 1);
921 chg_virtue(caster_ptr, V_KNOWLEDGE, 1);
927 /* One less spell available */
928 caster_ptr->learned_spells++;
931 caster_ptr->update |= (PU_SPELLS);
932 update_creature(caster_ptr);
934 /* Redraw object recall */
935 caster_ptr->window_flags |= (PW_OBJECT);
939 * @brief 魔法を詠唱するコマンドのメインルーチン /
941 * @param caster_ptr プレーヤーへの参照ポインタ
944 bool do_cmd_cast(player_type *caster_ptr)
947 OBJECT_SUBTYPE_VALUE sval;
953 MANA_POINT need_mana;
957 const magic_type *s_ptr;
960 bool over_exerted = FALSE;
962 /* Require spell ability */
963 if (!caster_ptr->realm1 && (caster_ptr->pclass != CLASS_SORCERER) && (caster_ptr->pclass != CLASS_RED_MAGE)) {
964 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
968 if (caster_ptr->blind || no_lite(caster_ptr)) {
969 if (caster_ptr->pclass == CLASS_FORCETRAINER)
970 confirm_use_force(caster_ptr, FALSE);
972 msg_print(_("目が見えない!", "You cannot see!"));
978 if (cmd_limit_confused(caster_ptr))
981 if (caster_ptr->realm1 == REALM_HEX) {
982 if (hex_spell_fully(caster_ptr)) {
984 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not cast more spells."));
986 if (caster_ptr->lev >= 35)
987 flag = stop_hex_spell(caster_ptr);
993 if (caster_ptr->pclass == CLASS_FORCETRAINER) {
994 if (player_has_no_spellbooks(caster_ptr)) {
995 confirm_use_force(caster_ptr, FALSE);
996 return true; //!< 錬気キャンセル時の処理がない
1000 prayer = spell_category_name(mp_ptr->spell_book);
1002 q = _("どの呪文書を使いますか? ", "Use which book? ");
1003 s = _("呪文書がない!", "You have no spell books!");
1005 o_ptr = choose_object(caster_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | (caster_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)), mp_ptr->spell_book);
1007 if (item == INVEN_FORCE) /* the_force */
1009 do_cmd_mind(caster_ptr);
1010 return true; //!< 錬気キャンセル時の処理がない
1015 /* Access the item's sval */
1018 if ((caster_ptr->pclass != CLASS_SORCERER) && (caster_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == get_realm2_book(caster_ptr)))
1021 /* Track the object kind */
1022 object_kind_track(caster_ptr, o_ptr->k_idx);
1023 handle_stuff(caster_ptr);
1025 if ((caster_ptr->pclass == CLASS_SORCERER) || (caster_ptr->pclass == CLASS_RED_MAGE))
1026 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1028 realm = caster_ptr->realm2;
1030 realm = caster_ptr->realm1;
1032 /* Ask for a spell */
1034 if (!get_spell(caster_ptr, &spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う" : "唱える"), sval,
1037 msg_format("その本には知っている%sがない。", prayer);
1041 if (!get_spell(caster_ptr, &spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"), sval, TRUE, realm)) {
1043 msg_format("You don't know any %ss in that book.", prayer);
1048 use_realm = tval2realm(o_ptr->tval);
1049 if (use_realm == REALM_HEX) {
1050 if (hex_spelling(caster_ptr, spell)) {
1051 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1056 if (!is_magic(use_realm)) {
1057 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1059 s_ptr = &mp_ptr->info[realm - 1][spell];
1062 /* Extract mana consumption rate */
1063 need_mana = mod_need_mana(caster_ptr, s_ptr->smana, spell, realm);
1065 /* Verify "dangerous" spells */
1066 if (need_mana > caster_ptr->csp) {
1072 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1073 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する" : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う" : "唱える"));
1075 msg_format("You do not have enough mana to %s this %s.", ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"), prayer);
1082 if (!get_check_strict(caster_ptr, _("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL))
1086 /* Spell failure chance */
1087 chance = spell_chance(caster_ptr, spell, use_realm);
1089 /* Sufficient mana */
1090 if (need_mana <= caster_ptr->csp) {
1092 caster_ptr->csp -= need_mana;
1094 over_exerted = TRUE;
1095 caster_ptr->redraw |= (PR_MANA);
1098 if (randint0(100) < chance) {
1102 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1107 if (randint1(100) < chance)
1108 chg_virtue(caster_ptr, V_VITALITY, -1);
1111 if (randint1(100) < chance)
1112 chg_virtue(caster_ptr, V_UNLIFE, -1);
1115 if (randint1(100) < chance)
1116 chg_virtue(caster_ptr, V_NATURE, -1);
1119 if (randint1(100) < chance)
1120 chg_virtue(caster_ptr, V_JUSTICE, 1);
1123 if (randint1(100) < chance)
1124 chg_virtue(caster_ptr, V_JUSTICE, -1);
1127 if (randint1(100) < chance)
1128 chg_virtue(caster_ptr, V_COMPASSION, -1);
1131 if (randint1(100) < chance)
1132 chg_virtue(caster_ptr, V_KNOWLEDGE, -1);
1136 /* Failure casting may activate some side effect */
1137 exe_spell(caster_ptr, realm, spell, SPELL_FAIL);
1139 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell)) {
1140 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1141 wild_magic(caster_ptr, spell);
1142 } else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell)) {
1143 if ((sval == 3) && one_in_(2)) {
1144 sanity_blast(caster_ptr, 0, TRUE);
1146 msg_print(_("痛い!", "It hurts!"));
1147 take_hit(caster_ptr, DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"));
1149 if ((spell > 15) && one_in_(6) && !caster_ptr->hold_exp)
1150 lose_exp(caster_ptr, spell * 250);
1152 } else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell)) {
1153 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1154 aggravate_monsters(caster_ptr, 0);
1156 if (randint1(100) >= chance)
1157 chg_virtue(caster_ptr, V_CHANCE, -1);
1162 /* Canceled spells cost neither a turn nor mana */
1163 if (!exe_spell(caster_ptr, realm, spell, SPELL_CAST))
1166 if (randint1(100) < chance)
1167 chg_virtue(caster_ptr, V_CHANCE, 1);
1169 /* A spell was cast */
1170 if (!(increment ? (caster_ptr->spell_worked2 & (1UL << spell)) : (caster_ptr->spell_worked1 & (1UL << spell))) && (caster_ptr->pclass != CLASS_SORCERER)
1171 && (caster_ptr->pclass != CLASS_RED_MAGE)) {
1172 int e = s_ptr->sexp;
1174 /* The spell worked */
1175 if (realm == caster_ptr->realm1) {
1176 caster_ptr->spell_worked1 |= (1UL << spell);
1178 caster_ptr->spell_worked2 |= (1UL << spell);
1181 gain_exp(caster_ptr, e * s_ptr->slevel);
1182 caster_ptr->window_flags |= (PW_OBJECT);
1186 chg_virtue(caster_ptr, V_TEMPERANCE, 1);
1187 chg_virtue(caster_ptr, V_COMPASSION, 1);
1188 chg_virtue(caster_ptr, V_VITALITY, 1);
1189 chg_virtue(caster_ptr, V_DILIGENCE, 1);
1192 chg_virtue(caster_ptr, V_UNLIFE, 1);
1193 chg_virtue(caster_ptr, V_JUSTICE, -1);
1194 chg_virtue(caster_ptr, V_FAITH, -1);
1195 chg_virtue(caster_ptr, V_VITALITY, -1);
1198 chg_virtue(caster_ptr, V_JUSTICE, -1);
1199 chg_virtue(caster_ptr, V_FAITH, -1);
1200 chg_virtue(caster_ptr, V_HONOUR, -1);
1201 chg_virtue(caster_ptr, V_TEMPERANCE, -1);
1204 chg_virtue(caster_ptr, V_FAITH, 1);
1205 chg_virtue(caster_ptr, V_JUSTICE, 1);
1206 chg_virtue(caster_ptr, V_SACRIFICE, 1);
1207 chg_virtue(caster_ptr, V_HONOUR, 1);
1210 chg_virtue(caster_ptr, V_NATURE, 1);
1211 chg_virtue(caster_ptr, V_HARMONY, 1);
1214 chg_virtue(caster_ptr, V_JUSTICE, -1);
1215 chg_virtue(caster_ptr, V_FAITH, -1);
1216 chg_virtue(caster_ptr, V_HONOUR, -1);
1217 chg_virtue(caster_ptr, V_COMPASSION, -1);
1220 chg_virtue(caster_ptr, V_KNOWLEDGE, 1);
1226 if (randint1(100 + caster_ptr->lev) < need_mana)
1227 chg_virtue(caster_ptr, V_TEMPERANCE, 1);
1228 if (randint1(100 + caster_ptr->lev) < need_mana)
1229 chg_virtue(caster_ptr, V_COMPASSION, 1);
1230 if (randint1(100 + caster_ptr->lev) < need_mana)
1231 chg_virtue(caster_ptr, V_VITALITY, 1);
1232 if (randint1(100 + caster_ptr->lev) < need_mana)
1233 chg_virtue(caster_ptr, V_DILIGENCE, 1);
1236 if (randint1(100 + caster_ptr->lev) < need_mana)
1237 chg_virtue(caster_ptr, V_UNLIFE, 1);
1238 if (randint1(100 + caster_ptr->lev) < need_mana)
1239 chg_virtue(caster_ptr, V_JUSTICE, -1);
1240 if (randint1(100 + caster_ptr->lev) < need_mana)
1241 chg_virtue(caster_ptr, V_FAITH, -1);
1242 if (randint1(100 + caster_ptr->lev) < need_mana)
1243 chg_virtue(caster_ptr, V_VITALITY, -1);
1246 if (randint1(100 + caster_ptr->lev) < need_mana)
1247 chg_virtue(caster_ptr, V_JUSTICE, -1);
1248 if (randint1(100 + caster_ptr->lev) < need_mana)
1249 chg_virtue(caster_ptr, V_FAITH, -1);
1250 if (randint1(100 + caster_ptr->lev) < need_mana)
1251 chg_virtue(caster_ptr, V_HONOUR, -1);
1252 if (randint1(100 + caster_ptr->lev) < need_mana)
1253 chg_virtue(caster_ptr, V_TEMPERANCE, -1);
1256 if (randint1(100 + caster_ptr->lev) < need_mana)
1257 chg_virtue(caster_ptr, V_FAITH, 1);
1258 if (randint1(100 + caster_ptr->lev) < need_mana)
1259 chg_virtue(caster_ptr, V_JUSTICE, 1);
1260 if (randint1(100 + caster_ptr->lev) < need_mana)
1261 chg_virtue(caster_ptr, V_SACRIFICE, 1);
1262 if (randint1(100 + caster_ptr->lev) < need_mana)
1263 chg_virtue(caster_ptr, V_HONOUR, 1);
1266 if (randint1(100 + caster_ptr->lev) < need_mana)
1267 chg_virtue(caster_ptr, V_NATURE, 1);
1268 if (randint1(100 + caster_ptr->lev) < need_mana)
1269 chg_virtue(caster_ptr, V_HARMONY, 1);
1272 if (randint1(100 + caster_ptr->lev) < need_mana)
1273 chg_virtue(caster_ptr, V_JUSTICE, -1);
1274 if (randint1(100 + caster_ptr->lev) < need_mana)
1275 chg_virtue(caster_ptr, V_FAITH, -1);
1276 if (randint1(100 + caster_ptr->lev) < need_mana)
1277 chg_virtue(caster_ptr, V_HONOUR, -1);
1278 if (randint1(100 + caster_ptr->lev) < need_mana)
1279 chg_virtue(caster_ptr, V_COMPASSION, -1);
1282 if (any_bits(mp_ptr->spell_xtra, extra_magic_gain_exp)) {
1283 s16b cur_exp = caster_ptr->spell_exp[(increment ? 32 : 0) + spell];
1286 if (cur_exp < SPELL_EXP_BEGINNER)
1288 else if (cur_exp < SPELL_EXP_SKILLED) {
1289 if ((caster_ptr->current_floor_ptr->dun_level > 4) && ((caster_ptr->current_floor_ptr->dun_level + 10) > caster_ptr->lev))
1291 } else if (cur_exp < SPELL_EXP_EXPERT) {
1292 if (((caster_ptr->current_floor_ptr->dun_level + 5) > caster_ptr->lev) && ((caster_ptr->current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1294 } else if ((cur_exp < SPELL_EXP_MASTER) && !increment) {
1295 if (((caster_ptr->current_floor_ptr->dun_level + 5) > caster_ptr->lev) && (caster_ptr->current_floor_ptr->dun_level > s_ptr->slevel))
1298 caster_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1302 PlayerEnergy(caster_ptr).set_player_turn_energy(100);
1304 /* Over-exert the player */
1306 int oops = need_mana;
1309 caster_ptr->csp = 0;
1310 caster_ptr->csp_frac = 0;
1312 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1314 /* Hack -- Bypass free action */
1315 (void)set_paralyzed(caster_ptr, caster_ptr->paralyzed + randint1(5 * oops + 1));
1319 chg_virtue(caster_ptr, V_VITALITY, -10);
1322 chg_virtue(caster_ptr, V_UNLIFE, -10);
1325 chg_virtue(caster_ptr, V_JUSTICE, 10);
1328 chg_virtue(caster_ptr, V_NATURE, -10);
1331 chg_virtue(caster_ptr, V_JUSTICE, -10);
1334 chg_virtue(caster_ptr, V_COMPASSION, 10);
1337 chg_virtue(caster_ptr, V_KNOWLEDGE, -10);
1341 /* Damage CON (possibly permanently) */
1342 if (randint0(100) < 50) {
1343 bool perm = (randint0(100) < 25);
1345 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1347 /* Reduce constitution */
1348 (void)dec_stat(caster_ptr, A_CON, 15 + randint1(10), perm);
1352 caster_ptr->window_flags |= (PW_PLAYER);
1353 caster_ptr->window_flags |= (PW_SPELL);
1355 return true; //!< @note 詠唱した