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 "avatar/avatar.h"
12 #include "cmd-action/cmd-mind.h"
13 #include "cmd-io/cmd-dump.h"
14 #include "core/asking-player.h"
15 #include "core/player-redraw-types.h"
16 #include "core/player-update-types.h"
17 #include "core/stuff-handler.h"
18 #include "core/window-redrawer.h"
19 #include "floor/floor-object.h"
20 #include "game-option/disturbance-options.h"
21 #include "game-option/input-options.h"
22 #include "game-option/text-display-options.h"
23 #include "grid/grid.h"
24 #include "inventory/inventory-slot-types.h"
25 #include "io/command-repeater.h"
26 #include "io/input-key-acceptor.h"
27 #include "io/input-key-requester.h"
28 #include "io/write-diary.h"
29 #include "main/sound-definitions-table.h"
30 #include "main/sound-of-music.h"
31 #include "object-hook/hook-magic.h"
32 #include "object/item-tester-hooker.h"
33 #include "object/item-use-flags.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 uint32_t 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)
121 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
125 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
128 * @return フォーマットに従い整形された文字列
130 concptr info_duration(int base, DICE_SID sides)
132 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
136 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
138 * @return フォーマットに従い整形された文字列
140 concptr info_range(POSITION range)
142 return format(_("範囲:%d", "range %d"), range);
146 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
150 * @return フォーマットに従い整形された文字列
152 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
154 return info_string_dice(_("回復:", "heal "), dice, sides, base);
158 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
161 * @return フォーマットに従い整形された文字列
163 concptr info_delay(int base, DICE_SID sides)
165 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
169 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
171 * @return フォーマットに従い整形された文字列
173 concptr info_multi_damage(HIT_POINT dam)
175 return format(_("損傷:各%d", "dam %d each"), dam);
179 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
182 * @return フォーマットに従い整形された文字列
184 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
186 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
190 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
192 * @return フォーマットに従い整形された文字列
194 concptr info_power(int power)
196 return format(_("効力:%d", "power %d"), power);
200 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
203 * @return フォーマットに従い整形された文字列
206 * Generate power info string such as "power 1d100"
208 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
210 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
214 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
216 * @return フォーマットに従い整形された文字列
218 concptr info_radius(POSITION rad)
220 return format(_("半径:%d", "rad %d"), rad);
224 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
226 * @return フォーマットに従い整形された文字列
228 concptr info_weight(WEIGHT weight)
231 return format("最大重量:%d.%dkg", lbtokg1(weight), lbtokg2(weight));
233 return format("max wgt %d", weight / 10);
238 * @brief 魔法が利用可能かどうかを返す /
239 * Determine if a spell is "okay" for the player to cast or study
240 * The spell must be legible, not forgotten, and also, to cast,
241 * it must be known, and to study, it must not be known.
243 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
244 * @param study_pray 祈りの学習判定目的ならばTRUE
245 * @param use_realm 魔法領域ID
248 static bool spell_okay(player_type *caster_ptr, int spell, bool learned, bool study_pray, int use_realm)
250 const magic_type *s_ptr;
252 /* Access the spell */
253 if (!is_magic(use_realm)) {
254 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
256 s_ptr = &mp_ptr->info[use_realm - 1][spell];
259 /* Spell is illegal */
260 if (s_ptr->slevel > caster_ptr->lev)
263 /* Spell is forgotten */
264 if ((use_realm == caster_ptr->realm2) ? (caster_ptr->spell_forgotten2 & (1UL << spell)) : (caster_ptr->spell_forgotten1 & (1UL << spell))) {
269 if (caster_ptr->pclass == CLASS_SORCERER)
271 if (caster_ptr->pclass == CLASS_RED_MAGE)
274 /* Spell is learned */
275 if ((use_realm == caster_ptr->realm2) ? (caster_ptr->spell_learned2 & (1UL << spell)) : (caster_ptr->spell_learned1 & (1UL << spell))) {
277 return (!study_pray);
280 /* Okay to study, not to cast */
285 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
286 * Allow user to choose a spell/prayer from the given book.
287 * @param sn 選択した魔法IDを返す参照ポインタ
288 * @param prompt 魔法を利用する際の動詞表記
289 * @param sval 魔道書のsval
290 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
291 * @param use_realm 魔法領域ID
294 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
295 * If the user hits escape, returns FALSE, and set '*sn' to -1
296 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
297 * The "prompt" should be "cast", "recite", or "study"
298 * The "known" should be TRUE for cast/pray, FALSE for study
301 static int get_spell(player_type *caster_ptr, SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, REALM_IDX use_realm)
304 SPELL_IDX spell = -1;
307 MANA_POINT need_mana;
308 SPELL_IDX spells[64];
309 bool flag, redraw, okay;
311 const magic_type *s_ptr;
318 int menu_line = (use_menu ? 1 : 0);
320 /* Get the spell, if available */
321 if (repeat_pull(&code)) {
322 *sn = (SPELL_IDX)code;
323 /* Verify the spell */
324 if (spell_okay(caster_ptr, *sn, learned, false, use_realm)) {
330 p = spell_category_name(mp_ptr->spell_book);
333 for (spell = 0; spell < 32; spell++) {
334 /* Check for this spell */
335 if ((fake_spell_flags[sval] & (1UL << 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++) {
349 /* Look for "okay" spells */
350 if (spell_okay(caster_ptr, spells[i], learned, false, use_realm))
354 /* No "okay" spells */
357 if (((use_realm) != caster_ptr->realm1) && ((use_realm) != caster_ptr->realm2) && (caster_ptr->pclass != CLASS_SORCERER)
358 && (caster_ptr->pclass != CLASS_RED_MAGE))
360 if (((caster_ptr->pclass == CLASS_SORCERER) || (caster_ptr->pclass == CLASS_RED_MAGE)) && !is_magic(use_realm))
362 if ((caster_ptr->pclass == CLASS_RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1))
365 /* Assume cancelled */
371 caster_ptr->window_flags |= (PW_SPELL);
372 handle_stuff(caster_ptr);
374 /* Build a prompt (accept all spells) */
376 jverb(prompt, jverb_buf, JVERB_AND);
377 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ", p, I2A(0), I2A(num - 1), p, jverb_buf);
379 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ", p, I2A(0), I2A(num - 1), prompt, p);
382 choice = (always_show_list || use_menu) ? ESCAPE : 1;
384 if (choice == ESCAPE)
386 else if (!get_com(out_val, &choice, true))
389 if (use_menu && choice != ' ') {
399 menu_line += (num - 1);
421 /* Display a list of spells */
422 print_spells(caster_ptr, menu_line, spells, num, 1, 15, use_realm);
427 if ((choice == ' ') || (choice == '*') || (choice == '?')) {
433 /* Display a list of spells */
434 print_spells(caster_ptr, menu_line, spells, num, 1, 15, use_realm);
452 ask = (isupper(choice));
456 choice = (char)tolower(choice);
458 /* Extract request */
459 i = (islower(choice) ? A2I(choice) : -1);
462 /* Totally Illegal */
463 if ((i < 0) || (i >= num)) {
468 /* Save the spell index */
471 /* Require "okay" spells */
472 if (!spell_okay(caster_ptr, spell, learned, false, use_realm)) {
475 msg_format("その%sを%sことはできません。", p, prompt);
477 msg_format("You may not %s that %s.", prompt, p);
487 /* Access the spell */
488 if (!is_magic(use_realm)) {
489 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
491 s_ptr = &mp_ptr->info[use_realm - 1][spell];
494 /* Extract mana consumption rate */
495 if (use_realm == REALM_HISSATSU) {
496 need_mana = s_ptr->smana;
498 need_mana = mod_need_mana(caster_ptr, s_ptr->smana, spell, use_realm);
503 jverb(prompt, jverb_buf, JVERB_AND);
505 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ", exe_spell(caster_ptr, use_realm, spell, SPELL_NAME), need_mana,
506 spell_chance(caster_ptr, spell, use_realm), jverb_buf);
508 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ", prompt, exe_spell(caster_ptr, use_realm, spell, SPELL_NAME), need_mana,
509 spell_chance(caster_ptr, spell, use_realm));
512 /* Belay that order */
513 if (!get_check(tmp_val))
524 caster_ptr->window_flags |= (PW_SPELL);
525 handle_stuff(caster_ptr);
527 /* Abort if needed */
531 /* Save the choice */
534 repeat_push((COMMAND_CODE)spell);
541 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
542 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
543 * @return 魔道書を一冊も持っていないならTRUEを返す
545 static void confirm_use_force(player_type *caster_ptr, bool browse_only)
550 /* Get the item index */
551 if (repeat_pull(&code) && (code == INVEN_FORCE)) {
552 browse_only ? do_cmd_mind_browse(caster_ptr) : do_cmd_mind(caster_ptr);
556 /* Show the prompt */
557 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
565 else if (which == 'w') {
566 repeat_push(INVEN_FORCE);
571 /* Clear the prompt line */
575 browse_only ? do_cmd_mind_browse(caster_ptr) : do_cmd_mind(caster_ptr);
580 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
581 * Peruse the spells/prayers in a book
584 * Note that *all* spells in the book are listed
586 * Note that browsing is allowed while confused or blind,
587 * and in the dark, primarily to allow browsing in stores.
590 void do_cmd_browse(player_type *caster_ptr)
593 OBJECT_SUBTYPE_VALUE sval;
594 REALM_IDX use_realm = 0;
596 SPELL_IDX spell = -1;
599 SPELL_IDX spells[64];
605 tval_type tval = TV_NONE;
607 /* Warriors are illiterate */
608 if (!(caster_ptr->realm1 || caster_ptr->realm2) && (caster_ptr->pclass != CLASS_SORCERER) && (caster_ptr->pclass != CLASS_RED_MAGE)) {
609 msg_print(_("本を読むことができない!", "You cannot read books!"));
613 if (caster_ptr->special_defense & KATA_MUSOU) {
614 set_action(caster_ptr, ACTION_NONE);
617 if (caster_ptr->pclass == CLASS_FORCETRAINER) {
618 if (player_has_no_spellbooks(caster_ptr)) {
619 confirm_use_force(caster_ptr, true);
624 /* Restrict choices to "useful" books */
625 if (caster_ptr->realm2 == REALM_NONE)
626 tval = mp_ptr->spell_book;
628 item_tester_hook = item_tester_learn_spell;
630 q = _("どの本を読みますか? ", "Browse which book? ");
631 s = _("読める本がない。", "You have no books that you can read.");
633 o_ptr = choose_object(caster_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | (caster_ptr->pclass == CLASS_FORCETRAINER ? USE_FORCE : 0)), tval);
635 item_tester_hook = NULL;
637 if (item == INVEN_FORCE) /* the_force */
639 do_cmd_mind_browse(caster_ptr);
645 /* Access the item's sval */
648 use_realm = tval2realm(o_ptr->tval);
650 /* Track the object kind */
651 object_kind_track(caster_ptr, o_ptr->k_idx);
652 handle_stuff(caster_ptr);
655 for (spell = 0; spell < 32; spell++) {
656 /* Check for this spell */
657 if ((fake_spell_flags[sval] & (1UL << spell))) {
658 /* Collect this spell */
659 spells[num++] = spell;
666 /* Keep browsing spells. Exit browsing on cancel. */
668 /* Ask for a spell, allow cancel */
669 if (!get_spell(caster_ptr, &spell, _("読む", "browse"), o_ptr->sval, true, use_realm)) {
670 /* If cancelled, leave immediately. */
674 /* Display a list of spells */
675 print_spells(caster_ptr, 0, spells, num, 1, 15, use_realm);
677 /* Notify that there's nothing to see, and wait. */
678 if (use_realm == REALM_HISSATSU)
679 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
681 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
689 /* Clear lines, position cursor (really should use strlen here) */
690 term_erase(14, 14, 255);
691 term_erase(14, 13, 255);
692 term_erase(14, 12, 255);
693 term_erase(14, 11, 255);
695 shape_buffer(exe_spell(caster_ptr, use_realm, spell, SPELL_DESC), 62, temp, sizeof(temp));
697 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j])) {
698 prt(&temp[j], line, 15);
706 * @brief プレイヤーの第二魔法領域を変更する /
707 * @param caster_ptr プレーヤーへの参照ポインタ
708 * @param next_realm 変更先の魔法領域ID
710 static void change_realm2(player_type *caster_ptr, REALM_IDX next_realm)
715 for (i = 0; i < 64; i++) {
716 caster_ptr->spell_order[j] = caster_ptr->spell_order[i];
717 if (caster_ptr->spell_order[i] < 32)
721 caster_ptr->spell_order[j] = 99;
723 for (i = 32; i < 64; i++) {
724 caster_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
726 caster_ptr->spell_learned2 = 0L;
727 caster_ptr->spell_worked2 = 0L;
728 caster_ptr->spell_forgotten2 = 0L;
730 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "changed magic realm from %s to %s."), realm_names[caster_ptr->realm2], realm_names[next_realm]);
731 exe_write_diary(caster_ptr, DIARY_DESCRIPTION, 0, tmp);
732 caster_ptr->old_realm |= 1U << (caster_ptr->realm2 - 1);
733 caster_ptr->realm2 = next_realm;
735 caster_ptr->update |= (PU_REORDER);
736 caster_ptr->update |= (PU_SPELLS);
737 handle_stuff(caster_ptr);
739 /* Load an autopick preference file */
740 autopick_load_pref(caster_ptr, false);
744 * @brief 魔法を学習するコマンドのメインルーチン /
745 * Study a book to gain a new spell/prayer
747 void do_cmd_study(player_type *caster_ptr)
751 OBJECT_SUBTYPE_VALUE sval;
753 bool learned = false;
755 /* Spells of realm2 will have an increment of +32 */
756 SPELL_IDX spell = -1;
757 concptr p = spell_category_name(mp_ptr->spell_book);
760 tval_type tval = TV_NONE;
762 if (!caster_ptr->realm1) {
763 msg_print(_("本を読むことができない!", "You cannot read books!"));
767 if (cmd_limit_blind(caster_ptr))
769 if (cmd_limit_confused(caster_ptr))
772 if (!(caster_ptr->new_spells)) {
773 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
777 if (caster_ptr->special_defense & KATA_MUSOU) {
778 set_action(caster_ptr, ACTION_NONE);
782 if (caster_ptr->new_spells < 10) {
783 msg_format("あと %d つの%sを学べる。", caster_ptr->new_spells, p);
785 msg_format("あと %d 個の%sを学べる。", caster_ptr->new_spells, p);
788 msg_format("You can learn %d new %s%s.", caster_ptr->new_spells, p, (caster_ptr->new_spells == 1 ? "" : "s"));
793 /* Restrict choices to "useful" books */
794 if (caster_ptr->realm2 == REALM_NONE)
795 tval = mp_ptr->spell_book;
797 item_tester_hook = item_tester_learn_spell;
799 q = _("どの本から学びますか? ", "Study which book? ");
800 s = _("読める本がない。", "You have no books that you can read.");
802 o_ptr = choose_object(caster_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), tval);
807 /* Access the item's sval */
810 if (o_ptr->tval == get_realm2_book(caster_ptr))
812 else if (o_ptr->tval != get_realm1_book(caster_ptr)) {
813 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? ")))
815 change_realm2(caster_ptr, tval2realm(o_ptr->tval));
819 /* Track the object kind */
820 object_kind_track(caster_ptr, o_ptr->k_idx);
821 handle_stuff(caster_ptr);
823 /* Mage -- Learn a selected spell */
824 if (mp_ptr->spell_book != TV_LIFE_BOOK) {
825 /* Ask for a spell, allow cancel */
826 if (!get_spell(caster_ptr, &spell, _("学ぶ", "study"), sval, false, o_ptr->tval - TV_LIFE_BOOK + 1) && (spell == -1))
830 /* Priest -- Learn a random prayer */
836 for (spell = 0; spell < 32; spell++) {
837 /* Check spells in the book */
838 if ((fake_spell_flags[sval] & (1UL << spell))) {
839 /* Skip non "okay" prayers */
840 if (!spell_okay(caster_ptr, spell, false, true, (increment ? caster_ptr->realm2 : caster_ptr->realm1)))
843 /* Hack -- Prepare the randomizer */
846 /* Hack -- Apply the randomizer */
856 /* Nothing to study */
858 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
867 /* Learn the spell */
869 if (caster_ptr->spell_learned1 & (1UL << spell))
872 caster_ptr->spell_learned1 |= (1UL << spell);
874 if (caster_ptr->spell_learned2 & (1UL << (spell - 32)))
877 caster_ptr->spell_learned2 |= (1UL << (spell - 32));
881 int max_exp = (spell < 32) ? SPELL_EXP_MASTER : SPELL_EXP_EXPERT;
882 int old_exp = caster_ptr->spell_exp[spell];
883 int new_rank = EXP_LEVEL_UNSKILLED;
884 concptr name = exe_spell(caster_ptr, increment ? caster_ptr->realm2 : caster_ptr->realm1, spell % 32, SPELL_NAME);
886 if (old_exp >= max_exp) {
887 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
891 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
893 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
897 } else if (old_exp >= SPELL_EXP_EXPERT) {
898 caster_ptr->spell_exp[spell] = SPELL_EXP_MASTER;
899 new_rank = EXP_LEVEL_MASTER;
900 } else if (old_exp >= SPELL_EXP_SKILLED) {
902 caster_ptr->spell_exp[spell] = SPELL_EXP_EXPERT;
904 caster_ptr->spell_exp[spell] += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
905 new_rank = EXP_LEVEL_EXPERT;
906 } else if (old_exp >= SPELL_EXP_BEGINNER) {
907 caster_ptr->spell_exp[spell] = SPELL_EXP_SKILLED + (old_exp - SPELL_EXP_BEGINNER) * 2 / 3;
908 new_rank = EXP_LEVEL_SKILLED;
910 caster_ptr->spell_exp[spell] = SPELL_EXP_BEGINNER + old_exp / 3;
911 new_rank = EXP_LEVEL_BEGINNER;
913 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, exp_level_str[new_rank]);
915 /* Find the next open entry in "caster_ptr->spell_order[]" */
916 for (i = 0; i < 64; i++) {
917 /* Stop at the first empty space */
918 if (caster_ptr->spell_order[i] == 99)
922 /* Add the spell to the known list */
923 caster_ptr->spell_order[i++] = spell;
925 /* Mention the result */
928 if (mp_ptr->spell_book == TV_MUSIC_BOOK) {
929 msg_format("%sを学んだ。", exe_spell(caster_ptr, increment ? caster_ptr->realm2 : caster_ptr->realm1, spell % 32, SPELL_NAME));
931 msg_format("%sの%sを学んだ。", exe_spell(caster_ptr, increment ? caster_ptr->realm2 : caster_ptr->realm1, spell % 32, SPELL_NAME), p);
934 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));
938 PlayerEnergy(caster_ptr).set_player_turn_energy(100);
940 switch (mp_ptr->spell_book) {
942 chg_virtue(caster_ptr, V_FAITH, 1);
945 chg_virtue(caster_ptr, V_UNLIFE, 1);
948 chg_virtue(caster_ptr, V_NATURE, 1);
951 chg_virtue(caster_ptr, V_KNOWLEDGE, 1);
957 /* One less spell available */
958 caster_ptr->learned_spells++;
961 caster_ptr->update |= (PU_SPELLS);
962 update_creature(caster_ptr);
964 /* Redraw object recall */
965 caster_ptr->window_flags |= (PW_OBJECT);
969 * @brief 魔法を詠唱するコマンドのメインルーチン /
971 * @param caster_ptr プレーヤーへの参照ポインタ
974 bool do_cmd_cast(player_type *caster_ptr)
977 OBJECT_SUBTYPE_VALUE sval;
983 MANA_POINT need_mana;
987 const magic_type *s_ptr;
990 bool over_exerted = false;
992 /* Require spell ability */
993 if (!caster_ptr->realm1 && (caster_ptr->pclass != CLASS_SORCERER) && (caster_ptr->pclass != CLASS_RED_MAGE)) {
994 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
998 if (caster_ptr->blind || no_lite(caster_ptr)) {
999 if (caster_ptr->pclass == CLASS_FORCETRAINER)
1000 confirm_use_force(caster_ptr, false);
1002 msg_print(_("目が見えない!", "You cannot see!"));
1008 if (cmd_limit_confused(caster_ptr))
1011 if (caster_ptr->realm1 == REALM_HEX) {
1012 if (hex_spell_fully(caster_ptr)) {
1014 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not cast more spells."));
1016 if (caster_ptr->lev >= 35)
1017 flag = stop_hex_spell(caster_ptr);
1023 if (caster_ptr->pclass == CLASS_FORCETRAINER) {
1024 if (player_has_no_spellbooks(caster_ptr)) {
1025 confirm_use_force(caster_ptr, false);
1026 return true; //!< 錬気キャンセル時の処理がない
1030 prayer = spell_category_name(mp_ptr->spell_book);
1032 q = _("どの呪文書を使いますか? ", "Use which book? ");
1033 s = _("呪文書がない!", "You have no spell books!");
1035 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);
1037 if (item == INVEN_FORCE) /* the_force */
1039 do_cmd_mind(caster_ptr);
1040 return true; //!< 錬気キャンセル時の処理がない
1045 /* Access the item's sval */
1048 if ((caster_ptr->pclass != CLASS_SORCERER) && (caster_ptr->pclass != CLASS_RED_MAGE) && (o_ptr->tval == get_realm2_book(caster_ptr)))
1051 /* Track the object kind */
1052 object_kind_track(caster_ptr, o_ptr->k_idx);
1053 handle_stuff(caster_ptr);
1055 if ((caster_ptr->pclass == CLASS_SORCERER) || (caster_ptr->pclass == CLASS_RED_MAGE))
1056 realm = o_ptr->tval - TV_LIFE_BOOK + 1;
1058 realm = caster_ptr->realm2;
1060 realm = caster_ptr->realm1;
1062 /* Ask for a spell */
1064 if (!get_spell(caster_ptr, &spell,
1065 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する"
1066 : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "歌う"
1068 sval, true, realm)) {
1070 msg_format("その本には知っている%sがない。", prayer);
1074 if (!get_spell(caster_ptr, &spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"), sval, true, realm)) {
1076 msg_format("You don't know any %ss in that book.", prayer);
1081 use_realm = tval2realm(o_ptr->tval);
1082 if (use_realm == REALM_HEX) {
1083 if (hex_spelling(caster_ptr, spell)) {
1084 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1089 if (!is_magic(use_realm)) {
1090 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1092 s_ptr = &mp_ptr->info[realm - 1][spell];
1095 /* Extract mana consumption rate */
1096 need_mana = mod_need_mana(caster_ptr, s_ptr->smana, spell, realm);
1098 /* Verify "dangerous" spells */
1099 if (need_mana > caster_ptr->csp) {
1105 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1106 ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "詠唱する"
1107 : (mp_ptr->spell_book == TV_LIFE_BOOK) ? "歌う"
1110 msg_format("You do not have enough mana to %s this %s.", ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"), prayer);
1117 if (!get_check_strict(caster_ptr, _("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL))
1121 /* Spell failure chance */
1122 chance = spell_chance(caster_ptr, spell, use_realm);
1124 /* Sufficient mana */
1125 if (need_mana <= caster_ptr->csp) {
1127 caster_ptr->csp -= need_mana;
1129 over_exerted = true;
1130 caster_ptr->redraw |= (PR_MANA);
1133 if (randint0(100) < chance) {
1137 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1142 if (randint1(100) < chance)
1143 chg_virtue(caster_ptr, V_VITALITY, -1);
1146 if (randint1(100) < chance)
1147 chg_virtue(caster_ptr, V_UNLIFE, -1);
1150 if (randint1(100) < chance)
1151 chg_virtue(caster_ptr, V_NATURE, -1);
1154 if (randint1(100) < chance)
1155 chg_virtue(caster_ptr, V_JUSTICE, 1);
1158 if (randint1(100) < chance)
1159 chg_virtue(caster_ptr, V_JUSTICE, -1);
1162 if (randint1(100) < chance)
1163 chg_virtue(caster_ptr, V_COMPASSION, -1);
1166 if (randint1(100) < chance)
1167 chg_virtue(caster_ptr, V_KNOWLEDGE, -1);
1171 /* Failure casting may activate some side effect */
1172 exe_spell(caster_ptr, realm, spell, SPELL_FAIL);
1174 if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell)) {
1175 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1176 wild_magic(caster_ptr, spell);
1177 } else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell)) {
1178 if ((sval == 3) && one_in_(2)) {
1179 sanity_blast(caster_ptr, 0, true);
1181 msg_print(_("痛い!", "It hurts!"));
1182 take_hit(caster_ptr, DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"));
1184 if ((spell > 15) && one_in_(6) && !caster_ptr->hold_exp)
1185 lose_exp(caster_ptr, spell * 250);
1187 } else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell)) {
1188 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1189 aggravate_monsters(caster_ptr, 0);
1191 if (randint1(100) >= chance)
1192 chg_virtue(caster_ptr, V_CHANCE, -1);
1197 /* Canceled spells cost neither a turn nor mana */
1198 if (!exe_spell(caster_ptr, realm, spell, SPELL_CAST))
1201 if (randint1(100) < chance)
1202 chg_virtue(caster_ptr, V_CHANCE, 1);
1204 /* A spell was cast */
1205 if (!(increment ? (caster_ptr->spell_worked2 & (1UL << spell)) : (caster_ptr->spell_worked1 & (1UL << spell))) && (caster_ptr->pclass != CLASS_SORCERER)
1206 && (caster_ptr->pclass != CLASS_RED_MAGE)) {
1207 int e = s_ptr->sexp;
1209 /* The spell worked */
1210 if (realm == caster_ptr->realm1) {
1211 caster_ptr->spell_worked1 |= (1UL << spell);
1213 caster_ptr->spell_worked2 |= (1UL << spell);
1216 gain_exp(caster_ptr, e * s_ptr->slevel);
1217 caster_ptr->window_flags |= (PW_OBJECT);
1221 chg_virtue(caster_ptr, V_TEMPERANCE, 1);
1222 chg_virtue(caster_ptr, V_COMPASSION, 1);
1223 chg_virtue(caster_ptr, V_VITALITY, 1);
1224 chg_virtue(caster_ptr, V_DILIGENCE, 1);
1227 chg_virtue(caster_ptr, V_UNLIFE, 1);
1228 chg_virtue(caster_ptr, V_JUSTICE, -1);
1229 chg_virtue(caster_ptr, V_FAITH, -1);
1230 chg_virtue(caster_ptr, V_VITALITY, -1);
1233 chg_virtue(caster_ptr, V_JUSTICE, -1);
1234 chg_virtue(caster_ptr, V_FAITH, -1);
1235 chg_virtue(caster_ptr, V_HONOUR, -1);
1236 chg_virtue(caster_ptr, V_TEMPERANCE, -1);
1239 chg_virtue(caster_ptr, V_FAITH, 1);
1240 chg_virtue(caster_ptr, V_JUSTICE, 1);
1241 chg_virtue(caster_ptr, V_SACRIFICE, 1);
1242 chg_virtue(caster_ptr, V_HONOUR, 1);
1245 chg_virtue(caster_ptr, V_NATURE, 1);
1246 chg_virtue(caster_ptr, V_HARMONY, 1);
1249 chg_virtue(caster_ptr, V_JUSTICE, -1);
1250 chg_virtue(caster_ptr, V_FAITH, -1);
1251 chg_virtue(caster_ptr, V_HONOUR, -1);
1252 chg_virtue(caster_ptr, V_COMPASSION, -1);
1255 chg_virtue(caster_ptr, V_KNOWLEDGE, 1);
1261 if (randint1(100 + caster_ptr->lev) < need_mana)
1262 chg_virtue(caster_ptr, V_TEMPERANCE, 1);
1263 if (randint1(100 + caster_ptr->lev) < need_mana)
1264 chg_virtue(caster_ptr, V_COMPASSION, 1);
1265 if (randint1(100 + caster_ptr->lev) < need_mana)
1266 chg_virtue(caster_ptr, V_VITALITY, 1);
1267 if (randint1(100 + caster_ptr->lev) < need_mana)
1268 chg_virtue(caster_ptr, V_DILIGENCE, 1);
1271 if (randint1(100 + caster_ptr->lev) < need_mana)
1272 chg_virtue(caster_ptr, V_UNLIFE, 1);
1273 if (randint1(100 + caster_ptr->lev) < need_mana)
1274 chg_virtue(caster_ptr, V_JUSTICE, -1);
1275 if (randint1(100 + caster_ptr->lev) < need_mana)
1276 chg_virtue(caster_ptr, V_FAITH, -1);
1277 if (randint1(100 + caster_ptr->lev) < need_mana)
1278 chg_virtue(caster_ptr, V_VITALITY, -1);
1281 if (randint1(100 + caster_ptr->lev) < need_mana)
1282 chg_virtue(caster_ptr, V_JUSTICE, -1);
1283 if (randint1(100 + caster_ptr->lev) < need_mana)
1284 chg_virtue(caster_ptr, V_FAITH, -1);
1285 if (randint1(100 + caster_ptr->lev) < need_mana)
1286 chg_virtue(caster_ptr, V_HONOUR, -1);
1287 if (randint1(100 + caster_ptr->lev) < need_mana)
1288 chg_virtue(caster_ptr, V_TEMPERANCE, -1);
1291 if (randint1(100 + caster_ptr->lev) < need_mana)
1292 chg_virtue(caster_ptr, V_FAITH, 1);
1293 if (randint1(100 + caster_ptr->lev) < need_mana)
1294 chg_virtue(caster_ptr, V_JUSTICE, 1);
1295 if (randint1(100 + caster_ptr->lev) < need_mana)
1296 chg_virtue(caster_ptr, V_SACRIFICE, 1);
1297 if (randint1(100 + caster_ptr->lev) < need_mana)
1298 chg_virtue(caster_ptr, V_HONOUR, 1);
1301 if (randint1(100 + caster_ptr->lev) < need_mana)
1302 chg_virtue(caster_ptr, V_NATURE, 1);
1303 if (randint1(100 + caster_ptr->lev) < need_mana)
1304 chg_virtue(caster_ptr, V_HARMONY, 1);
1307 if (randint1(100 + caster_ptr->lev) < need_mana)
1308 chg_virtue(caster_ptr, V_JUSTICE, -1);
1309 if (randint1(100 + caster_ptr->lev) < need_mana)
1310 chg_virtue(caster_ptr, V_FAITH, -1);
1311 if (randint1(100 + caster_ptr->lev) < need_mana)
1312 chg_virtue(caster_ptr, V_HONOUR, -1);
1313 if (randint1(100 + caster_ptr->lev) < need_mana)
1314 chg_virtue(caster_ptr, V_COMPASSION, -1);
1317 if (any_bits(mp_ptr->spell_xtra, extra_magic_gain_exp)) {
1318 int16_t cur_exp = caster_ptr->spell_exp[(increment ? 32 : 0) + spell];
1319 int16_t exp_gain = 0;
1321 if (cur_exp < SPELL_EXP_BEGINNER)
1323 else if (cur_exp < SPELL_EXP_SKILLED) {
1324 if ((caster_ptr->current_floor_ptr->dun_level > 4) && ((caster_ptr->current_floor_ptr->dun_level + 10) > caster_ptr->lev))
1326 } else if (cur_exp < SPELL_EXP_EXPERT) {
1327 if (((caster_ptr->current_floor_ptr->dun_level + 5) > caster_ptr->lev) && ((caster_ptr->current_floor_ptr->dun_level + 5) > s_ptr->slevel))
1329 } else if ((cur_exp < SPELL_EXP_MASTER) && !increment) {
1330 if (((caster_ptr->current_floor_ptr->dun_level + 5) > caster_ptr->lev) && (caster_ptr->current_floor_ptr->dun_level > s_ptr->slevel))
1333 caster_ptr->spell_exp[(increment ? 32 : 0) + spell] += exp_gain;
1337 PlayerEnergy(caster_ptr).set_player_turn_energy(100);
1339 /* Over-exert the player */
1341 int oops = need_mana;
1344 caster_ptr->csp = 0;
1345 caster_ptr->csp_frac = 0;
1347 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1349 /* Hack -- Bypass free action */
1350 (void)set_paralyzed(caster_ptr, caster_ptr->paralyzed + randint1(5 * oops + 1));
1354 chg_virtue(caster_ptr, V_VITALITY, -10);
1357 chg_virtue(caster_ptr, V_UNLIFE, -10);
1360 chg_virtue(caster_ptr, V_JUSTICE, 10);
1363 chg_virtue(caster_ptr, V_NATURE, -10);
1366 chg_virtue(caster_ptr, V_JUSTICE, -10);
1369 chg_virtue(caster_ptr, V_COMPASSION, 10);
1372 chg_virtue(caster_ptr, V_KNOWLEDGE, -10);
1376 /* Damage CON (possibly permanently) */
1377 if (randint0(100) < 50) {
1378 bool perm = (randint0(100) < 25);
1380 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1382 /* Reduce constitution */
1383 (void)dec_stat(caster_ptr, A_CON, 15 + randint1(10), perm);
1387 caster_ptr->window_flags |= (PW_PLAYER);
1388 caster_ptr->window_flags |= (PW_SPELL);
1390 return true; //!< @note 詠唱した